{"id":21952,"url":"https://patchwork.libcamera.org/api/patches/21952/?format=json","web_url":"https://patchwork.libcamera.org/patch/21952/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20241118000738.18977-11-laurent.pinchart@ideasonboard.com>","date":"2024-11-18T00:07:36","name":"[RFC,v2,10/12] test: libipa: Add Vector class test","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"1d06480dbfcb14df0d267868f3a26ccd8cc261fd","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/21952/mbox/","series":[{"id":4796,"url":"https://patchwork.libcamera.org/api/series/4796/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4796","date":"2024-11-18T00:07:26","name":"Improve linear algebra helpers in libipa","version":2,"mbox":"https://patchwork.libcamera.org/series/4796/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/21952/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/21952/checks/","tags":{},"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 5819DC330C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 18 Nov 2024 00:08:12 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C95E6658D1;\n\tMon, 18 Nov 2024 01:08:11 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4FAAD658C4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 18 Nov 2024 01:08:01 +0100 (CET)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E1B4475A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 18 Nov 2024 01:07:44 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"R59YQNtH\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1731888465;\n\tbh=Fz5XuItvBL9UaaL2/Ecb7EvHBPgaedj8P1I2/bjEyhs=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=R59YQNtHJZuhijmukbw1j5wQeTrV1o5FClOd3r8fKfQAET80V94MehbrWfMc7l7XB\n\tjMQ6Vf/s7mHqy8Uvt8GuzZxTXa/WjKg9ANIXBY94y1rW1hRhkJRFe+9Sg/wsfvtB9w\n\tTQnecErEcHpceUPUag8BXulPK2HkVsA6Br1ZSpO4=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Subject":"[RFC PATCH v2 10/12] test: libipa: Add Vector class test","Date":"Mon, 18 Nov 2024 02:07:36 +0200","Message-ID":"<20241118000738.18977-11-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.45.2","In-Reply-To":"<20241118000738.18977-1-laurent.pinchart@ideasonboard.com>","References":"<20241118000738.18977-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","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>"},"content":"Add a unit test to exercize the API of the ipa::Vector class.\n\nThe test binary being called 'vector', implicit includes cause the\nbinary to be picked by '#include <vector>', causing builds to fail. Set\nimplicit_include_directories to false to avoid this, as done in commit\n6cd849125888 (\"test: Don't add current build directory to include\npath\").\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\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","diff":"diff --git a/test/ipa/libipa/meson.build b/test/ipa/libipa/meson.build\nindex 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/'])\ndiff --git a/test/ipa/libipa/vector.cpp b/test/ipa/libipa/vector.cpp\nnew file mode 100644\nindex 000000000000..5279bc8216b3\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;\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)\n","prefixes":["RFC","v2","10/12"]}