From: Michal Privoznik Date: Wed, 29 Nov 2023 11:30:16 +0000 (+0100) Subject: rpcgen: tests: Run cleanly on platforms where char is unsigned X-Git-Tag: v9.10.0~14 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=94ded36b3fdde0c68f47ccfad4afa21fe4996fa5;p=thirdparty%2Flibvirt.git rpcgen: tests: Run cleanly on platforms where char is unsigned There are some platforms where 'char' is unsigned, by default (RPi, s390x to name a few). And because of how test_demo is written we are experiencing some test cases failing there. For instance: /xdr/struct-scalar is failing. This is because in the test (test_struct_scalar()), we have a struct with two chars. One is initialized to 0xca, the other 0xfe (note that both have the MSB set). The XDR encoder (xdr_TestStructScalar()) then calls xdr_char() on both of them. But XDR itself has no notion of char type, so under the hood, it expands it to int [1] and calls xdr_int(). And this is where the problem lies. On platforms where char is signed, the integer expansion results in 0xffffffca, but on platforms where char is unsigned it results in 0x000000ca. Two distinct results. The test then goes and compares the encoded buffer with an expected one (memcmp(), read from the disk earlier). This poses no problem for real life use, because when decoding those chars back, the padding is thrown away. To avoid tickling this issue, use values that don't have the MSB set. 1: https://git.linux-nfs.org/?p=steved/libtirpc.git;a=blob;f=src/xdr.c;h=28d1382cc4853ecf1238d792af5016160435d1e0;hb=HEAD#l487 Fixes: 40cbaa8fbe rpcgen: add test case for XDR serialization Reported-by: Boris Fiuczynski Signed-off-by: Michal Privoznik Reviewed-by: Jiri Denemark Reviewed-by: Boris Fiuczynski --- diff --git a/scripts/rpcgen/tests/test_demo.c b/scripts/rpcgen/tests/test_demo.c index 1cdb9cfb82..a48ceccd58 100644 --- a/scripts/rpcgen/tests/test_demo.c +++ b/scripts/rpcgen/tests/test_demo.c @@ -373,7 +373,7 @@ static void test_enum_variable_array_empty(void) &vorig, &vnew, "enum_variable_array_empty", false); } -#define TEST_STRUCT_INIT (TestStruct) { .c1 = 0xca, .c2 = 0xfe } +#define TEST_STRUCT_INIT (TestStruct) { .c1 = 0x4a, .c2 = 0x7e } #define TEST_STRUCT_INIT_ALT (TestStruct) { .c1 = 0x09, .c2 = 0x07 } static void test_struct_scalar(void) diff --git a/scripts/rpcgen/tests/test_demo_struct_fixed_array.bin b/scripts/rpcgen/tests/test_demo_struct_fixed_array.bin index f0e786ddea..dfa991acbd 100644 Binary files a/scripts/rpcgen/tests/test_demo_struct_fixed_array.bin and b/scripts/rpcgen/tests/test_demo_struct_fixed_array.bin differ diff --git a/scripts/rpcgen/tests/test_demo_struct_pointer_set.bin b/scripts/rpcgen/tests/test_demo_struct_pointer_set.bin index 5728147932..0aa91c2b57 100644 Binary files a/scripts/rpcgen/tests/test_demo_struct_pointer_set.bin and b/scripts/rpcgen/tests/test_demo_struct_pointer_set.bin differ diff --git a/scripts/rpcgen/tests/test_demo_struct_scalar.bin b/scripts/rpcgen/tests/test_demo_struct_scalar.bin index 0e6959d56a..aa46538fb8 100644 Binary files a/scripts/rpcgen/tests/test_demo_struct_scalar.bin and b/scripts/rpcgen/tests/test_demo_struct_scalar.bin differ diff --git a/scripts/rpcgen/tests/test_demo_struct_variable_array_set.bin b/scripts/rpcgen/tests/test_demo_struct_variable_array_set.bin index a9406a21cf..48c2e710e9 100644 Binary files a/scripts/rpcgen/tests/test_demo_struct_variable_array_set.bin and b/scripts/rpcgen/tests/test_demo_struct_variable_array_set.bin differ diff --git a/scripts/rpcgen/tests/test_demo_test_struct_all_types.bin b/scripts/rpcgen/tests/test_demo_test_struct_all_types.bin index 5ee4ee5a6d..660c0e1b9c 100644 Binary files a/scripts/rpcgen/tests/test_demo_test_struct_all_types.bin and b/scripts/rpcgen/tests/test_demo_test_struct_all_types.bin differ