Commit Graph

7 Commits

Author SHA1 Message Date
Michal Privoznik
94ded36b3f 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 <fiuczy@linux.ibm.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
2023-11-29 17:16:45 +01:00
Michal Privoznik
dec02f101e rpcgen: tests: Allow running test_demo from anywhere
The test_demo program compares whether XDR encoded data match the
expected output as read from a file. But the file path is not
absolute and thus relative to CWD which means the program can run
only from one specific directory.

Do what we do in the rest of our test suite: define 'abs_srcdir'
macro and prefix the path with it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2023-11-29 14:34:11 +01:00
Daniel P. Berrangé
086fa214bb rpcgen: add g_auto function support
This will eliminate the need to call xdr_free to clear
pointers from data structures.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2023-11-03 14:06:35 -04:00
Daniel P. Berrangé
40cbaa8fbe rpcgen: add test case for XDR serialization
Test the serialization done by libtirpc, so that when we later
switch to our own code, we can prove wire compatibility.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2023-11-03 14:06:35 -04:00
Daniel P. Berrangé
8ec79e5e14 rpcgen: add a C code generator for XDR protocol specs
This implements a C code generator that emits code that is
(almost) identical to the classic 'rpcgen' program. The
key differences are:

 - Skip inlining of calls for struct fields
 - Skip K&R style function prototypes in headers
 - Use int64_t instead of quad_t for OS portability
 - Saner whitespace / indentation

The tests/demo.c and tests/demo.h files were created using
the traditional 'rpcgen' program, and then editted to cut
out the leading boilerplate, and the differences mentioned
above.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2023-11-03 14:06:35 -04:00
Daniel P. Berrangé
ca3f025011 rpcgen: add an XDR protocol parser
This adds a parser capable of handling the XDR protocol files.

The parsing grammar requirements are detailed in

  https://www.rfc-editor.org/rfc/rfc4506#section-6.3

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2023-11-03 14:06:35 -04:00
Daniel P. Berrangé
8c8b97685b rpcgen: add an XDR protocol lexer
This adds a lexer capable of handling the XDR protocol files.

The lexical rquirements are detailed in

  https://www.rfc-editor.org/rfc/rfc4506#section-6.2

pytest is introduced as a build dependancy for testing python
code.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2023-11-03 14:06:35 -04:00