[{"id":32276,"web_url":"https://patchwork.libcamera.org/comment/32276/","msgid":"<87mshvfo9x.fsf@redhat.com>","date":"2024-11-19T11:36:58","subject":"Re: [PATCH v3 11/17] test: libipa: Add Vector class test","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Hi Laurent,\n\nthank you, it works for me now.\n\nLaurent Pinchart <laurent.pinchart@ideasonboard.com> writes:\n\n> Add a unit test to exercize the API of the ipa::Vector class.\n>\n> The test binary being called 'vector', implicit includes cause the\n> binary to be picked by '#include <vector>', causing builds to fail. Set\n> implicit_include_directories to false to avoid this, as done in commit\n> 6cd849125888 (\"test: Don't add current build directory to include\n> path\").\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\n\n> ---\n> Changes since v2:\n>\n> - Fix initialization of 'v1' variable\n> ---\n>  test/ipa/libipa/meson.build |   2 +\n>  test/ipa/libipa/vector.cpp  | 100 ++++++++++++++++++++++++++++++++++++\n>  2 files changed, 102 insertions(+)\n>  create mode 100644 test/ipa/libipa/vector.cpp\n>\n> diff --git a/test/ipa/libipa/meson.build b/test/ipa/libipa/meson.build\n> index 4d2427dbd4e7..f9b3c46d000f 100644\n> --- a/test/ipa/libipa/meson.build\n> +++ b/test/ipa/libipa/meson.build\n> @@ -2,11 +2,13 @@\n>  \n>  libipa_test = [\n>      {'name': 'interpolator', 'sources': ['interpolator.cpp']},\n> +    {'name': 'vector', 'sources': ['vector.cpp']},\n>  ]\n>  \n>  foreach test : libipa_test\n>      exe = executable(test['name'], test['sources'],\n>                       dependencies : [libcamera_private, libipa_dep],\n> +                     implicit_include_directories : false,\n>                       link_with : [test_libraries],\n>                       include_directories : [test_includes_internal,\n>                                              '../../../src/ipa/libipa/'])\n> diff --git a/test/ipa/libipa/vector.cpp b/test/ipa/libipa/vector.cpp\n> new file mode 100644\n> index 000000000000..8e4ec77d7820\n> --- /dev/null\n> +++ b/test/ipa/libipa/vector.cpp\n> @@ -0,0 +1,100 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * Copyright (C) 2024, Ideas on Board Oy\n> + *\n> + * Vector tests\n> + */\n> +\n> +#include \"../src/ipa/libipa/vector.h\"\n> +\n> +#include <cmath>\n> +#include <iostream>\n> +\n> +#include \"test.h\"\n> +\n> +using namespace libcamera::ipa;\n> +\n> +#define ASSERT_EQ(a, b)\t\t\t\t\t\t\t\\\n> +if ((a) != (b)) {\t\t\t\t\t\t\t\\\n> +\tstd::cout << #a \" != \" #b << \" (line \" << __LINE__ << \")\"\t\\\n> +\t\t  << std::endl;\t\t\t\t\t\t\\\n> +\treturn TestFail;\t\t\t\t\t\t\\\n> +}\n> +\n> +class VectorTest : public Test\n> +{\n> +protected:\n> +\tint run()\n> +\t{\n> +\t\tVector<double, 3> v1{ 0.0 };\n> +\n> +\t\tASSERT_EQ(v1[0], 0.0);\n> +\t\tASSERT_EQ(v1[1], 0.0);\n> +\t\tASSERT_EQ(v1[2], 0.0);\n> +\n> +\t\tASSERT_EQ(v1.length(), 0.0);\n> +\t\tASSERT_EQ(v1.length2(), 0.0);\n> +\n> +\t\tVector<double, 3> v2{{ 1.0, 4.0, 8.0 }};\n> +\n> +\t\tASSERT_EQ(v2[0], 1.0);\n> +\t\tASSERT_EQ(v2[1], 4.0);\n> +\t\tASSERT_EQ(v2[2], 8.0);\n> +\n> +\t\tASSERT_EQ(v2.x(), 1.0);\n> +\t\tASSERT_EQ(v2.y(), 4.0);\n> +\t\tASSERT_EQ(v2.z(), 8.0);\n> +\n> +\t\tASSERT_EQ(v2.r(), 1.0);\n> +\t\tASSERT_EQ(v2.g(), 4.0);\n> +\t\tASSERT_EQ(v2.b(), 8.0);\n> +\n> +\t\tASSERT_EQ(v2.length2(), 81.0);\n> +\t\tASSERT_EQ(v2.length(), 9.0);\n> +\t\tASSERT_EQ(v2.sum(), 13.0);\n> +\n> +\t\tVector<double, 3> v3{ v2 };\n> +\n> +\t\tASSERT_EQ(v2, v3);\n> +\n> +\t\tv3 = Vector<double, 3>{{ 4.0, 4.0, 4.0 }};\n> +\n> +\t\tASSERT_EQ(v2 + v3, (Vector<double, 3>{{ 5.0, 8.0, 12.0 }}));\n> +\t\tASSERT_EQ(v2 + 4.0, (Vector<double, 3>{{ 5.0, 8.0, 12.0 }}));\n> +\t\tASSERT_EQ(v2 - v3, (Vector<double, 3>{{ -3.0, 0.0, 4.0 }}));\n> +\t\tASSERT_EQ(v2 - 4.0, (Vector<double, 3>{{ -3.0, 0.0, 4.0 }}));\n> +\t\tASSERT_EQ(v2 * v3, (Vector<double, 3>{{ 4.0, 16.0, 32.0 }}));\n> +\t\tASSERT_EQ(v2 * 4.0, (Vector<double, 3>{{ 4.0, 16.0, 32.0 }}));\n> +\t\tASSERT_EQ(v2 / v3, (Vector<double, 3>{{ 0.25, 1.0, 2.0 }}));\n> +\t\tASSERT_EQ(v2 / 4.0, (Vector<double, 3>{{ 0.25, 1.0, 2.0 }}));\n> +\n> +\t\tASSERT_EQ(v2.min(v3), (Vector<double, 3>{{ 1.0, 4.0, 4.0 }}));\n> +\t\tASSERT_EQ(v2.min(4.0), (Vector<double, 3>{{ 1.0, 4.0, 4.0 }}));\n> +\t\tASSERT_EQ(v2.max(v3), (Vector<double, 3>{{ 4.0, 4.0, 8.0 }}));\n> +\t\tASSERT_EQ(v2.max(4.0), (Vector<double, 3>{{ 4.0, 4.0, 8.0 }}));\n> +\n> +\t\tASSERT_EQ(v2.dot(v3), 52.0);\n> +\n> +\t\tv2 += v3;\n> +\t\tASSERT_EQ(v2, (Vector<double, 3>{{ 5.0, 8.0, 12.0 }}));\n> +\t\tv2 -= v3;\n> +\t\tASSERT_EQ(v2, (Vector<double, 3>{{ 1.0, 4.0, 8.0 }}));\n> +\t\tv2 *= v3;\n> +\t\tASSERT_EQ(v2, (Vector<double, 3>{{ 4.0, 16.0, 32.0 }}));\n> +\t\tv2 /= v3;\n> +\t\tASSERT_EQ(v2, (Vector<double, 3>{{ 1.0, 4.0, 8.0 }}));\n> +\n> +\t\tv2 += 4.0;\n> +\t\tASSERT_EQ(v2, (Vector<double, 3>{{ 5.0, 8.0, 12.0 }}));\n> +\t\tv2 -= 4.0;\n> +\t\tASSERT_EQ(v2, (Vector<double, 3>{{ 1.0, 4.0, 8.0 }}));\n> +\t\tv2 *= 4.0;\n> +\t\tASSERT_EQ(v2, (Vector<double, 3>{{ 4.0, 16.0, 32.0 }}));\n> +\t\tv2 /= 4.0;\n> +\t\tASSERT_EQ(v2, (Vector<double, 3>{{ 1.0, 4.0, 8.0 }}));\n> +\n> +\t\treturn TestPass;\n> +\t}\n> +};\n> +\n> +TEST_REGISTER(VectorTest)","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 69B87C32F1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 19 Nov 2024 11:37:08 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 481E865F0B;\n\tTue, 19 Nov 2024 12:37:07 +0100 (CET)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8256565F03\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 19 Nov 2024 12:37:05 +0100 (CET)","from mail-wr1-f70.google.com (mail-wr1-f70.google.com\n\t[209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-530-IYv5NvsSNjCFqN0RWgW7ZA-1; Tue, 19 Nov 2024 06:37:03 -0500","by mail-wr1-f70.google.com with SMTP id\n\tffacd0b85a97d-382428c2564so1358715f8f.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 19 Nov 2024 03:37:03 -0800 (PST)","from nuthatch ([2a00:102a:400a:489a:34bf:5bf1:e776:7185])\n\tby smtp.gmail.com with ESMTPSA id\n\tffacd0b85a97d-38248b74ec6sm5464108f8f.38.2024.11.19.03.37.00\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 19 Nov 2024 03:37:00 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"ds60Nmt6\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1732016224;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=m0cvA1d9Q5nq3svtBplgJiibILNemg9udV+F5FwbwFk=;\n\tb=ds60Nmt6R3EbPSiUUkpEDztxp7Ei4ixnQE3Y/nPz0ficFidcTf6zcy3eIo6YgjQAzheU1N\n\tKZ2/xx4H5aSzk1HT7cuWisl9CyTMOFqFCFV5Wv1FtvEUvckwwdazOCl15ucZK+OuRKAO03\n\tKIIxmk65xWRmirqK9T9NmpdBgy5uXSI=","X-MC-Unique":"IYv5NvsSNjCFqN0RWgW7ZA-1","X-Mimecast-MFC-AGG-ID":"IYv5NvsSNjCFqN0RWgW7ZA","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1732016221; x=1732621021;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=m0cvA1d9Q5nq3svtBplgJiibILNemg9udV+F5FwbwFk=;\n\tb=l4fSXYp5x1U7L9niW55i8g/P/VKKagaCDtvyBdtQ7K7Jq1c7pTtL+ckhbOBGGZxKqg\n\t92d5iJKgoH34+gPXR04Q7Z4iiApM6K4YfQ/qUjQVGXtfB9c0uMNYmAbddoaVBVTGDBOz\n\teNQn6rDjYGCKkRf3T93D7s+vNA2er3eEpgOJLslfCNRnfqfYWPjIBJIruBdrd5Z5c0Py\n\t/UNIivOyrHOdybphFr7OD31x4s2zWA0QsI00UmRMTKWhzbwP8jC4JzsnOVhm47+Q3kKy\n\tNGGHjfxrP14vzQAAH19K48jQbIWk7+5fFqWQR/1lT1Df8QZz+FhAb0l1sxEKVfulygT8\n\t50Tw==","X-Gm-Message-State":"AOJu0Yxn3YpJJfn8CcGLcUYEj0pJTnkhfIDqWZ+SZLEjwMXIlwXJsYuV\n\tRrEV8trbwkOc1ni0bIhW6ubcHnBzk5w+UyqKXPezuyXt6Lf4npXVexmkmVvX7djCFKIVRn+CKIr\n\tBP2B+ts6O62EyEOXwzZuXo32MtuzxPgmJJJ34C2EdZLfnThlF4Qs5c8LgJDQ0KOPGsQ3KKgswsi\n\tgh6vf7SUIgAlA78R+ozVbBv82uE/cwBlfX4386Hl/vzVzMfCb4TDCz+Yw=","X-Received":["by 2002:a05:6000:1ac7:b0:382:42c3:83e4 with SMTP id\n\tffacd0b85a97d-38242c3873dmr5677729f8f.33.1732016221540; \n\tTue, 19 Nov 2024 03:37:01 -0800 (PST)","by 2002:a05:6000:1ac7:b0:382:42c3:83e4 with SMTP id\n\tffacd0b85a97d-38242c3873dmr5677711f8f.33.1732016221126; \n\tTue, 19 Nov 2024 03:37:01 -0800 (PST)"],"X-Google-Smtp-Source":"AGHT+IHUWp8UqDwQ2q9CqXgOX7yjuyfuIm9tDrQnmP5EJZiI1rnInQa6ArllsDSFrdoY3BgVC0fp/A==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v3 11/17] test: libipa: Add Vector class test","In-Reply-To":"<20241118221618.13953-12-laurent.pinchart@ideasonboard.com>\n\t(Laurent Pinchart's message of \"Tue, 19 Nov 2024 00:16:12 +0200\")","References":"<20241118221618.13953-1-laurent.pinchart@ideasonboard.com>\n\t<20241118221618.13953-12-laurent.pinchart@ideasonboard.com>","Date":"Tue, 19 Nov 2024 12:36:58 +0100","Message-ID":"<87mshvfo9x.fsf@redhat.com>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"aOV84XzMvQopXJeeWJj6qJbA-8mnXsP0VAIWMEAV4eg_1732016222","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]