[{"id":15297,"web_url":"https://patchwork.libcamera.org/comment/15297/","msgid":"<YDRS8vmUcksA/Z0Q@pendragon.ideasonboard.com>","date":"2021-02-23T00:57:22","subject":"Re: [libcamera-devel] [PATCH v8 4/4] tests: Test IPA serializer\n\tgeneration","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Paul,\n\nThank you for the patch.\n\nOn Sat, Feb 13, 2021 at 01:23:12PM +0900, Paul Elder wrote:\n> Add a test to confirm that serializer and header generation works\n> properly for mojom definition files, and that the serializer works\n> properly.\n> \n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> \n> ---\n> No change in v8\n> \n> Changes in v7:\n> - add test to test serdes of a vector of *generated* structs\n> \n> Changes in v6:\n> - use namespacing in the mojom file, and in the test\n> - add the enum to the test mojom file, as vimc.h no longer exists\n> \n> Changes in v5:\n> - add dummy event to event interface\n> \n> New in v4\n> ---\n>  .../generated_serializer_test.cpp             | 156 ++++++++++++++++++\n>  .../generated_serializer/meson.build          |  49 ++++++\n>  .../generated_serializer/vimc.mojom           |  33 ++++\n>  test/serialization/meson.build                |   2 +\n>  4 files changed, 240 insertions(+)\n>  create mode 100644 test/serialization/generated_serializer/generated_serializer_test.cpp\n>  create mode 100644 test/serialization/generated_serializer/meson.build\n>  create mode 100644 test/serialization/generated_serializer/vimc.mojom\n> \n> diff --git a/test/serialization/generated_serializer/generated_serializer_test.cpp b/test/serialization/generated_serializer/generated_serializer_test.cpp\n> new file mode 100644\n> index 00000000..471d0731\n> --- /dev/null\n> +++ b/test/serialization/generated_serializer/generated_serializer_test.cpp\n> @@ -0,0 +1,156 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * Copyright (C) 2020, Google Inc.\n> + *\n> + * generated_serializer_test.cpp - Test generated serializer\n> + */\n> +\n> +#include <algorithm>\n> +#include <tuple>\n> +#include <vector>\n> +\n> +#include \"test.h\"\n> +\n> +#include \"vimc_test_ipa_interface.h\"\n> +#include \"vimc_test_ipa_serializer.h\"\n> +\n> +using namespace std;\n> +using namespace libcamera;\n> +\n> +class IPAGeneratedSerializerTest : public Test\n> +{\n> +protected:\n> +\tint init() override\n> +\t{\n> +\t\treturn TestPass;\n> +\t}\n> +\n> +\tint run() override\n> +\t{\n> +\n> +#define TEST_FIELD_EQUALITY(struct1, struct2, field)\t\t\\\n> +if (struct1.field != struct2.field) {\t\t\t\t\\\n> +\tcerr << #field << \" field incorrect: expected \\\"\"\t\\\n> +\t     << t.field << \"\\\", got \\\"\" << u.field << \"\\\"\" << endl;\\\n> +\treturn TestFail;\t\t\t\t\t\\\n> +}\n> +\n> +\t\tipa::test::TestStruct t, u;\n> +\n> +\t\tt.m = {\n> +\t\t\t{ \"a\", \"z\" },\n> +\t\t\t{ \"b\", \"z\" },\n> +\t\t\t{ \"c\", \"z\" },\n> +\t\t\t{ \"d\", \"z\" },\n> +\t\t\t{ \"e\", \"z\" },\n> +\t\t};\n> +\n> +\t\tt.a = { \"a\", \"b\", \"c\", \"d\", \"e\" };\n> +\n> +\t\tt.s1 = \"hello world\";\n> +\t\tt.s2 = \"goodbye\";\n> +\t\tt.s3 = \"lorem ipsum\";\n> +\t\tt.i  = 58527;\n> +\n> +\t\tvector<uint8_t> serialized;\n> +\n> +\t\ttie(serialized, ignore) =\n> +\t\t\tIPADataSerializer<ipa::test::TestStruct>::serialize(t);\n> +\n> +\t\tu = IPADataSerializer<ipa::test::TestStruct>::deserialize(serialized);\n> +\n> +\t\tif (!equals(t.m, u.m))\n> +\t\t\treturn TestFail;\n> +\n> +\t\tif (!equals(t.a, u.a))\n> +\t\t\treturn TestFail;\n> +\n> +\t\tTEST_FIELD_EQUALITY(t, u, s1);\n> +\t\tTEST_FIELD_EQUALITY(t, u, s2);\n> +\t\tTEST_FIELD_EQUALITY(t, u, s3);\n> +\t\tTEST_FIELD_EQUALITY(t, u, i);\n> +\n> +\n> +\t\t/* Test vector of generated structs */\n> +\t\tvector<ipa::test::TestStruct> v = { t, u };\n> +\t\tvector<ipa::test::TestStruct> w;\n> +\n> +\t\ttie(serialized, ignore) =\n> +\t\t\tIPADataSerializer<vector<ipa::test::TestStruct>>::serialize(v);\n> +\n> +\t\tw = IPADataSerializer<vector<ipa::test::TestStruct>>::deserialize(serialized);\n> +\n> +\t\tif (!equals(v[0].m, w[0].m) ||\n> +\t\t    !equals(v[1].m, w[1].m))\n> +\t\t\treturn TestFail;\n> +\n> +\t\tif (!equals(v[0].a, w[0].a) ||\n> +\t\t    !equals(v[1].a, w[1].a))\n> +\t\t\treturn TestFail;\n> +\n> +\t\tTEST_FIELD_EQUALITY(v[0], w[0], s1);\n> +\t\tTEST_FIELD_EQUALITY(v[0], w[0], s2);\n> +\t\tTEST_FIELD_EQUALITY(v[0], w[0], s3);\n> +\t\tTEST_FIELD_EQUALITY(v[0], w[0], i);\n> +\n> +\t\tTEST_FIELD_EQUALITY(v[1], w[1], s1);\n> +\t\tTEST_FIELD_EQUALITY(v[1], w[1], s2);\n> +\t\tTEST_FIELD_EQUALITY(v[1], w[1], s3);\n> +\t\tTEST_FIELD_EQUALITY(v[1], w[1], i);\n> +\n> +\t\treturn TestPass;\n> +\t}\n> +\n> +private:\n> +\tbool equals(const map<string, string> &lhs, const map<string, string> &rhs)\n> +\t{\n> +\t\tbool eq = lhs.size() == rhs.size() &&\n> +\t\t\t  equal(lhs.begin(), lhs.end(), rhs.begin(),\n> +\t\t\t\t[](auto &a, auto &b) { return a.first == b.first &&\n> +\t\t\t\t\t\t\t      a.second == b.second; });\n> +\n> +\t\tif (eq)\n> +\t\t\treturn true;\n> +\n> +\t\tcerr << \"lhs:\" << endl;\n> +\t\tfor (const auto &pair : lhs)\n> +\t\t\tcerr << \"- \" << pair.first << \": \"\n> +\t\t\t     << pair.second << endl;\n> +\n> +\t\tcerr << \"rhs:\" << endl;\n> +\t\tfor (const auto &pair : rhs)\n> +\t\t\tcerr << \"- \" << pair.first << \": \"\n> +\t\t\t     << pair.second << endl;\n> +\n> +\t\treturn false;\n> +\t}\n> +\n> +\tbool equals(const vector<string> &lhs, const vector<string> &rhs)\n> +\t{\n> +\t\tbool eq = lhs.size() == rhs.size();\n> +\n> +\t\tif (!eq) {\n> +\t\t\tcerr << \"sizes not equal\" << endl;\n> +\t\t\treturn false;\n> +\t\t}\n> +\n> +\t\tfor (unsigned int i = 0; i < lhs.size(); i++)\n> +\t\t\tif (lhs[i] != rhs[i])\n> +\t\t\t\teq = false;\n> +\n> +\t\tif (eq)\n> +\t\t\treturn true;\n> +\n> +\t\tcerr << \"lhs:\" << endl;\n> +\t\tfor (const auto &str : lhs)\n> +\t\t\tcerr << \"- \" << str << endl;\n> +\n> +\t\tcerr << \"rhs:\" << endl;\n> +\t\tfor (const auto &str : rhs)\n> +\t\t\tcerr << \"- \" << str << endl;\n> +\n> +\t\treturn false;\n> +\t}\n> +};\n> +\n> +TEST_REGISTER(IPAGeneratedSerializerTest)\n> diff --git a/test/serialization/generated_serializer/meson.build b/test/serialization/generated_serializer/meson.build\n> new file mode 100644\n> index 00000000..68bcf23d\n> --- /dev/null\n> +++ b/test/serialization/generated_serializer/meson.build\n> @@ -0,0 +1,49 @@\n> +# SPDX-License-Identifier: CC0-1.0\n> +\n> +# vimc.mojom-module\n> +mojom = custom_target('vimc_test_mojom_module',\n> +                      input : 'vimc.mojom',\n> +                      output : 'vimc.mojom-module',\n> +                      command : [\n> +                          mojom_parser,\n> +                          '--output-root', meson.build_root(),\n> +                          '--input-root', meson.source_root(),\n> +                          '--mojoms', '@INPUT@'\n> +                      ])\n> +\n> +# vimc_test_ipa_interface.h\n> +header = custom_target('vimc_test_ipa_interface_h',\n> +                       input : mojom,\n> +                       output : 'vimc_test_ipa_interface.h',\n> +                       depends : mojom_templates,\n> +                       command : [\n> +                           mojom_generator, 'generate',\n> +                           '-g', 'libcamera',\n> +                           '--bytecode_path', mojom_templates_dir,\n> +                           '--libcamera_generate_header',\n> +                           '--libcamera_output_path=@OUTPUT@',\n> +                           './' +'@INPUT@'\n> +                       ])\n> +\n> +# vimc_test_ipa_serializer.h\n> +serializer = custom_target('vimc_test_ipa_serializer_h',\n> +                           input : mojom,\n> +                           output : 'vimc_test_ipa_serializer.h',\n> +                           depends : mojom_templates,\n> +                           command : [\n> +                               mojom_generator, 'generate',\n> +                               '-g', 'libcamera',\n> +                               '--bytecode_path', mojom_templates_dir,\n> +                               '--libcamera_generate_serializer',\n> +                               '--libcamera_output_path=@OUTPUT@',\n> +                               './' +'@INPUT@'\n> +                           ])\n> +\n> +exe = executable('generated_serializer_test',\n> +                 ['generated_serializer_test.cpp', header, serializer],\n> +                 dependencies : libcamera_dep,\n> +                 link_with : test_libraries,\n> +                 include_directories : test_includes_internal)\n> +\n> +test('generated_serializer_test', exe,\n> +     suite : 'generated_serializer', is_parallel : false)\n> diff --git a/test/serialization/generated_serializer/vimc.mojom b/test/serialization/generated_serializer/vimc.mojom\n> new file mode 100644\n> index 00000000..2fd973e9\n> --- /dev/null\n> +++ b/test/serialization/generated_serializer/vimc.mojom\n\nThis has nothing to do with vimc, maybe test.mojom given that the module\nis called ipa.test ? Same for the interface, it should be renamed.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> @@ -0,0 +1,33 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +\n> +module ipa.test;\n> +\n> +enum IPAOperationCode {\n> +\tIPAOperationNone,\n> +\tIPAOperationInit,\n> +\tIPAOperationStart,\n> +\tIPAOperationStop,\n> +};\n> +\n> +struct IPASettings {};\n> +\n> +struct TestStruct {\n> +\tmap<string, string> m;\n> +\tarray<string> a;\n> +\tstring s1;\n> +\tstring s2;\n> +\tint32 i;\n> +\tstring s3;\n> +};\n> +\n> +interface IPAVimcInterface {\n> +\tinit(IPASettings settings) => (int32 ret);\n> +\tstart() => (int32 ret);\n> +\tstop();\n> +\n> +\ttest(TestStruct s);\n> +};\n> +\n> +interface IPAVimcEventInterface {\n> +\tdummyEvent(uint32 val);\n> +};\n> diff --git a/test/serialization/meson.build b/test/serialization/meson.build\n> index a4636337..60ebf325 100644\n> --- a/test/serialization/meson.build\n> +++ b/test/serialization/meson.build\n> @@ -1,5 +1,7 @@\n>  # SPDX-License-Identifier: CC0-1.0\n>  \n> +subdir('generated_serializer')\n> +\n>  serialization_tests = [\n>      ['control_serialization',     'control_serialization.cpp'],\n>      ['ipa_data_serializer_test',  'ipa_data_serializer_test.cpp'],","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 5C38ABD1F1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 23 Feb 2021 00:57:50 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E014E68A25;\n\tTue, 23 Feb 2021 01:57:49 +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 3A7AD60106\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 23 Feb 2021 01:57:49 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 9B02466;\n\tTue, 23 Feb 2021 01:57:48 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"VQKNkjst\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1614041868;\n\tbh=KyR/E01hlw0nsl98NmRlcnMyfi50G9f5FXQ7ocUkSfI=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=VQKNkjstBiifRFucpyI+9iHYjCcrBE+K4z1x8k7N9x7nGU8xIMItJPe6OpleF5XPI\n\twFpveXp+uagzqfpb9XLrEvNIP3M9s0efmHVxf0P/RR+VZliaovUSBiSRUF7tf4Gd5/\n\tj+BcD8CHqRoJcyuL0bBOl/HxEH8Bmy5e7aV8dPws=","Date":"Tue, 23 Feb 2021 02:57:22 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Paul Elder <paul.elder@ideasonboard.com>","Message-ID":"<YDRS8vmUcksA/Z0Q@pendragon.ideasonboard.com>","References":"<20210213042312.112572-1-paul.elder@ideasonboard.com>\n\t<20210213042312.112572-5-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20210213042312.112572-5-paul.elder@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v8 4/4] tests: Test IPA serializer\n\tgeneration","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>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]