[libcamera-devel,v5,5/9] test: generated_serializer: Test Flags that is struct member
diff mbox series

Message ID 20221011105859.457567-6-paul.elder@ideasonboard.com
State Accepted
Headers show
Series
  • utils: ipc: Add support for enums and Flags
Related show

Commit Message

Paul Elder Oct. 11, 2022, 10:58 a.m. UTC
Add fields to the test struct to test serialization/deserialization of
scoped enums and flags that are struct members.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

---
Changes in v5:
- Add scoped enum to the test (basically the enum that the flag is
  created from)
  - This caught something that I missed in v4, which is why there is a
    v5 instead of just being merged...
- Add a TEST_SCOPED_ENUM_EQUALITY macro

No change in v4

Changes in v3:
- add [scopedEnum] to enum ErrorFlags
- s/[Flags]/[flags]/

Changes in v2:
- use new attribute-based mojom definition for Flags
---
 .../generated_serializer_test.cpp             | 21 +++++++++++++++++++
 .../include/libcamera/ipa/test.mojom          |  9 ++++++++
 2 files changed, 30 insertions(+)

Comments

Jacopo Mondi Oct. 12, 2022, 1:39 p.m. UTC | #1
Hi Paul

On Tue, Oct 11, 2022 at 07:58:55PM +0900, Paul Elder via libcamera-devel wrote:
> Add fields to the test struct to test serialization/deserialization of
> scoped enums and flags that are struct members.
>
> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>
> ---
> Changes in v5:
> - Add scoped enum to the test (basically the enum that the flag is
>   created from)
>   - This caught something that I missed in v4, which is why there is a
>     v5 instead of just being merged...
> - Add a TEST_SCOPED_ENUM_EQUALITY macro
>
> No change in v4
>
> Changes in v3:
> - add [scopedEnum] to enum ErrorFlags
> - s/[Flags]/[flags]/
>
> Changes in v2:
> - use new attribute-based mojom definition for Flags
> ---
>  .../generated_serializer_test.cpp             | 21 +++++++++++++++++++
>  .../include/libcamera/ipa/test.mojom          |  9 ++++++++
>  2 files changed, 30 insertions(+)
>
> diff --git a/test/serialization/generated_serializer/generated_serializer_test.cpp b/test/serialization/generated_serializer/generated_serializer_test.cpp
> index a4639a80..4670fe46 100644
> --- a/test/serialization/generated_serializer/generated_serializer_test.cpp
> +++ b/test/serialization/generated_serializer/generated_serializer_test.cpp
> @@ -35,6 +35,13 @@ if (struct1.field != struct2.field) {				\
>  	return TestFail;					\
>  }
>
> +#define TEST_SCOPED_ENUM_EQUALITY(struct1, struct2, field)	\
> +if (struct1.field != struct2.field) {				\
> +	cerr << #field << " field incorrect" << endl;		\
> +	return TestFail;					\
> +}
> +
> +
>  		ipa::test::TestStruct t, u;
>
>  		t.m = {
> @@ -52,6 +59,12 @@ if (struct1.field != struct2.field) {				\
>  		t.s3 = "lorem ipsum";
>  		t.i  = 58527;
>  		t.c = ipa::test::IPAOperationInit;
> +		t.e = ipa::test::ErrorFlags::Error1;
> +
> +		Flags<ipa::test::ErrorFlags> flags;
> +		flags |= ipa::test::ErrorFlags::Error1;
> +		flags |= ipa::test::ErrorFlags::Error2;
> +		t.f = flags;

Or
                t.f = ipa::test::ErrorFlags::Error1
                    | ipa::test::ErrorFlags::Error2;

Minor apart
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>

Thanks
  j

>
>  		std::vector<uint8_t> serialized;
>
> @@ -72,6 +85,8 @@ if (struct1.field != struct2.field) {				\
>  		TEST_FIELD_EQUALITY(t, u, i);
>  		TEST_FIELD_EQUALITY(t, u, c);
>
> +		TEST_SCOPED_ENUM_EQUALITY(t, u, e);
> +		TEST_SCOPED_ENUM_EQUALITY(t, u, f);
>
>  		/* Test vector of generated structs */
>  		std::vector<ipa::test::TestStruct> v = { t, u };
> @@ -96,12 +111,18 @@ if (struct1.field != struct2.field) {				\
>  		TEST_FIELD_EQUALITY(v[0], w[0], i);
>  		TEST_FIELD_EQUALITY(v[0], w[0], c);
>
> +		TEST_SCOPED_ENUM_EQUALITY(v[0], w[0], e);
> +		TEST_SCOPED_ENUM_EQUALITY(v[0], w[0], f);
> +
>  		TEST_FIELD_EQUALITY(v[1], w[1], s1);
>  		TEST_FIELD_EQUALITY(v[1], w[1], s2);
>  		TEST_FIELD_EQUALITY(v[1], w[1], s3);
>  		TEST_FIELD_EQUALITY(v[1], w[1], i);
>  		TEST_FIELD_EQUALITY(v[1], w[1], c);
>
> +		TEST_SCOPED_ENUM_EQUALITY(v[1], w[1], e);
> +		TEST_SCOPED_ENUM_EQUALITY(v[1], w[1], f);
> +
>  		return TestPass;
>  	}
>
> diff --git a/test/serialization/generated_serializer/include/libcamera/ipa/test.mojom b/test/serialization/generated_serializer/include/libcamera/ipa/test.mojom
> index 73081b40..91c31642 100644
> --- a/test/serialization/generated_serializer/include/libcamera/ipa/test.mojom
> +++ b/test/serialization/generated_serializer/include/libcamera/ipa/test.mojom
> @@ -9,6 +9,13 @@ enum IPAOperationCode {
>  	IPAOperationStop,
>  };
>
> +[scopedEnum] enum ErrorFlags {
> +	Error1 = 0x1,
> +	Error2 = 0x2,
> +	Error3 = 0x4,
> +	Error4 = 0x8,
> +};
> +
>  struct IPASettings {};
>
>  struct TestStruct {
> @@ -19,6 +26,8 @@ struct TestStruct {
>  	int32 i;
>  	string s3;
>  	IPAOperationCode c;
> +	ErrorFlags e;
> +	[flags] ErrorFlags f;
>  };
>
>  interface IPATestInterface {
> --
> 2.30.2
>

Patch
diff mbox series

diff --git a/test/serialization/generated_serializer/generated_serializer_test.cpp b/test/serialization/generated_serializer/generated_serializer_test.cpp
index a4639a80..4670fe46 100644
--- a/test/serialization/generated_serializer/generated_serializer_test.cpp
+++ b/test/serialization/generated_serializer/generated_serializer_test.cpp
@@ -35,6 +35,13 @@  if (struct1.field != struct2.field) {				\
 	return TestFail;					\
 }
 
+#define TEST_SCOPED_ENUM_EQUALITY(struct1, struct2, field)	\
+if (struct1.field != struct2.field) {				\
+	cerr << #field << " field incorrect" << endl;		\
+	return TestFail;					\
+}
+
+
 		ipa::test::TestStruct t, u;
 
 		t.m = {
@@ -52,6 +59,12 @@  if (struct1.field != struct2.field) {				\
 		t.s3 = "lorem ipsum";
 		t.i  = 58527;
 		t.c = ipa::test::IPAOperationInit;
+		t.e = ipa::test::ErrorFlags::Error1;
+
+		Flags<ipa::test::ErrorFlags> flags;
+		flags |= ipa::test::ErrorFlags::Error1;
+		flags |= ipa::test::ErrorFlags::Error2;
+		t.f = flags;
 
 		std::vector<uint8_t> serialized;
 
@@ -72,6 +85,8 @@  if (struct1.field != struct2.field) {				\
 		TEST_FIELD_EQUALITY(t, u, i);
 		TEST_FIELD_EQUALITY(t, u, c);
 
+		TEST_SCOPED_ENUM_EQUALITY(t, u, e);
+		TEST_SCOPED_ENUM_EQUALITY(t, u, f);
 
 		/* Test vector of generated structs */
 		std::vector<ipa::test::TestStruct> v = { t, u };
@@ -96,12 +111,18 @@  if (struct1.field != struct2.field) {				\
 		TEST_FIELD_EQUALITY(v[0], w[0], i);
 		TEST_FIELD_EQUALITY(v[0], w[0], c);
 
+		TEST_SCOPED_ENUM_EQUALITY(v[0], w[0], e);
+		TEST_SCOPED_ENUM_EQUALITY(v[0], w[0], f);
+
 		TEST_FIELD_EQUALITY(v[1], w[1], s1);
 		TEST_FIELD_EQUALITY(v[1], w[1], s2);
 		TEST_FIELD_EQUALITY(v[1], w[1], s3);
 		TEST_FIELD_EQUALITY(v[1], w[1], i);
 		TEST_FIELD_EQUALITY(v[1], w[1], c);
 
+		TEST_SCOPED_ENUM_EQUALITY(v[1], w[1], e);
+		TEST_SCOPED_ENUM_EQUALITY(v[1], w[1], f);
+
 		return TestPass;
 	}
 
diff --git a/test/serialization/generated_serializer/include/libcamera/ipa/test.mojom b/test/serialization/generated_serializer/include/libcamera/ipa/test.mojom
index 73081b40..91c31642 100644
--- a/test/serialization/generated_serializer/include/libcamera/ipa/test.mojom
+++ b/test/serialization/generated_serializer/include/libcamera/ipa/test.mojom
@@ -9,6 +9,13 @@  enum IPAOperationCode {
 	IPAOperationStop,
 };
 
+[scopedEnum] enum ErrorFlags {
+	Error1 = 0x1,
+	Error2 = 0x2,
+	Error3 = 0x4,
+	Error4 = 0x8,
+};
+
 struct IPASettings {};
 
 struct TestStruct {
@@ -19,6 +26,8 @@  struct TestStruct {
 	int32 i;
 	string s3;
 	IPAOperationCode c;
+	ErrorFlags e;
+	[flags] ErrorFlags f;
 };
 
 interface IPATestInterface {