From e011b04c6b2e31bdc46320e5d8a4f48715681f15 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Wed, 12 Jan 2022 02:58:02 +0100 Subject: libosmo-gtlv: add C code generator for IE structs and arrays Defining a protocol of message types with lists of IEs bears a lot of repetitive, copy-paste-error-prone writing out of data structures. Add a third layer to libosmo-gtlv, which allows helpful code generation. By non-repetitive data structures that briefly describe the protocol's messages and IEs, generate possibly repetitive IE list arrays and decoded-struct definitions automatically, avoiding grunt work errors. I tried C macros for this at first, but it became too convoluted. Generating C code that can be read and grepped makes things easier. A usage example is found in tests/libosmo-gtlv/test_gtlv_gen/. Related: SYS#5599 Change-Id: Ifb3ea54d2797ce060b95834aa117725ec2d6c4cf --- tests/libosmo-gtlv/test_gtlv_gen/gtlv_gen_test.ok | 160 ++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 tests/libosmo-gtlv/test_gtlv_gen/gtlv_gen_test.ok (limited to 'tests/libosmo-gtlv/test_gtlv_gen/gtlv_gen_test.ok') diff --git a/tests/libosmo-gtlv/test_gtlv_gen/gtlv_gen_test.ok b/tests/libosmo-gtlv/test_gtlv_gen/gtlv_gen_test.ok new file mode 100644 index 0000000..e178831 --- /dev/null +++ b/tests/libosmo-gtlv/test_gtlv_gen/gtlv_gen_test.ok @@ -0,0 +1,160 @@ + +=== start t8l8v ordered test_enc_dec[0] +encoded: MOO={ 'FOO'=23 'BAR'="twentythree" } +myproto_msg_enc() rc = 0 +01 01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 . +myproto_msg_dec() rc = 0 +decoded: MOO={ 'FOO'=23 'BAR'="twentythree" } +=== end t8l8v ordered test_enc_dec[0] + +=== start t8l8v ordered test_enc_dec[1] +encoded: MOO={ 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} } +myproto_msg_enc() rc = 0 +01 01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 03 02 89 13 . +myproto_msg_dec() rc = 0 +decoded: MOO={ 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} } +=== end t8l8v ordered test_enc_dec[1] + +=== start t8l8v ordered test_enc_dec[2] +encoded: MOO={ 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } } +myproto_msg_enc() rc = 0 +01 01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 03 02 89 13 04 02 00 01 04 02 00 02 04 02 7f ff . +myproto_msg_dec() rc = 0 +decoded: MOO={ 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } } +=== end t8l8v ordered test_enc_dec[2] + +=== start t8l8v ordered test_enc_dec[3] +encoded: MOO={ 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A}, {1002,false,R_B} } 'MOO_NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } } +myproto_msg_enc() rc = 0 +01 01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 03 02 89 13 04 02 00 01 04 02 00 02 04 02 7f ff 05 03 03 e9 80 05 03 03 ea 01 06 12 01 02 00 2a 02 08 66 6f 72 74 79 74 77 6f 03 02 10 92 . +myproto_msg_dec() rc = 0 +decoded: MOO={ 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A}, {1002,false,R_B} } 'MOO_NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } } +=== end t8l8v ordered test_enc_dec[3] + +=== start t8l8v ordered test_enc_dec[4] +encoded: GOO={ 'FOO'=17 'BAR'="gooei" 'GOO_NEST'={ { 'VAL'=0x123456789abcdef 'MOO_NEST'={ 'FOO'=11 'BAR'="eleven" 'BAZ'={1111,true} } }, { 'MOO_NEST'={ 'FOO'=12 'BAR'="twelve" 'BAZ'={1212,false} } } } } +myproto_msg_enc() rc = 0 +07 01 02 00 11 02 05 67 6f 6f 65 69 08 1c 07 08 01 23 45 67 89 ab cd ef 06 10 01 02 00 0b 02 06 65 6c 65 76 65 6e 03 02 84 57 08 12 06 10 01 02 00 0c 02 06 74 77 65 6c 76 65 03 02 04 bc . +myproto_msg_dec() rc = 0 +decoded: GOO={ 'FOO'=17 'BAR'="gooei" 'GOO_NEST'={ { 'VAL'=0x123456789abcdef 'MOO_NEST'={ 'FOO'=11 'BAR'="eleven" 'BAZ'={1111,true} } }, { 'MOO_NEST'={ 'FOO'=12 'BAR'="twelve" 'BAZ'={1212,false} } } } } +=== end t8l8v ordered test_enc_dec[4] + +=== start t8l8v unordered test_enc_dec[0] +encoded: MOO={ 'FOO'=23 'BAR'="twentythree" } +myproto_msg_enc() rc = 0 +01 01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 . +myproto_msg_dec() rc = 0 +decoded: MOO={ 'FOO'=23 'BAR'="twentythree" } +=== end t8l8v unordered test_enc_dec[0] + +=== start t8l8v unordered test_enc_dec[1] +encoded: MOO={ 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} } +myproto_msg_enc() rc = 0 +01 01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 03 02 89 13 . +myproto_msg_dec() rc = 0 +decoded: MOO={ 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} } +=== end t8l8v unordered test_enc_dec[1] + +=== start t8l8v unordered test_enc_dec[2] +encoded: MOO={ 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } } +myproto_msg_enc() rc = 0 +01 01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 03 02 89 13 04 02 00 01 04 02 00 02 04 02 7f ff . +myproto_msg_dec() rc = 0 +decoded: MOO={ 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } } +=== end t8l8v unordered test_enc_dec[2] + +=== start t8l8v unordered test_enc_dec[3] +encoded: MOO={ 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A}, {1002,false,R_B} } 'MOO_NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } } +myproto_msg_enc() rc = 0 +01 01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 03 02 89 13 04 02 00 01 04 02 00 02 04 02 7f ff 05 03 03 e9 80 05 03 03 ea 01 06 12 01 02 00 2a 02 08 66 6f 72 74 79 74 77 6f 03 02 10 92 . +myproto_msg_dec() rc = 0 +decoded: MOO={ 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A}, {1002,false,R_B} } 'MOO_NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } } +=== end t8l8v unordered test_enc_dec[3] + +=== start t8l8v unordered test_enc_dec[4] +encoded: GOO={ 'FOO'=17 'BAR'="gooei" 'GOO_NEST'={ { 'VAL'=0x123456789abcdef 'MOO_NEST'={ 'FOO'=11 'BAR'="eleven" 'BAZ'={1111,true} } }, { 'MOO_NEST'={ 'FOO'=12 'BAR'="twelve" 'BAZ'={1212,false} } } } } +myproto_msg_enc() rc = 0 +07 01 02 00 11 02 05 67 6f 6f 65 69 08 1c 07 08 01 23 45 67 89 ab cd ef 06 10 01 02 00 0b 02 06 65 6c 65 76 65 6e 03 02 84 57 08 12 06 10 01 02 00 0c 02 06 74 77 65 6c 76 65 03 02 04 bc . +myproto_msg_dec() rc = 0 +decoded: GOO={ 'FOO'=17 'BAR'="gooei" 'GOO_NEST'={ { 'VAL'=0x123456789abcdef 'MOO_NEST'={ 'FOO'=11 'BAR'="eleven" 'BAZ'={1111,true} } }, { 'MOO_NEST'={ 'FOO'=12 'BAR'="twelve" 'BAZ'={1212,false} } } } } +=== end t8l8v unordered test_enc_dec[4] + +=== start t16l16v ordered test_enc_dec[0] +encoded: MOO={ 'FOO'=23 'BAR'="twentythree" } +myproto_msg_enc() rc = 0 +01 00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 . +myproto_msg_dec() rc = 0 +decoded: MOO={ 'FOO'=23 'BAR'="twentythree" } +=== end t16l16v ordered test_enc_dec[0] + +=== start t16l16v ordered test_enc_dec[1] +encoded: MOO={ 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} } +myproto_msg_enc() rc = 0 +01 00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 00 03 00 02 89 13 . +myproto_msg_dec() rc = 0 +decoded: MOO={ 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} } +=== end t16l16v ordered test_enc_dec[1] + +=== start t16l16v ordered test_enc_dec[2] +encoded: MOO={ 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } } +myproto_msg_enc() rc = 0 +01 00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 00 03 00 02 89 13 00 04 00 02 00 01 00 04 00 02 00 02 00 04 00 02 7f ff . +myproto_msg_dec() rc = 0 +decoded: MOO={ 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } } +=== end t16l16v ordered test_enc_dec[2] + +=== start t16l16v ordered test_enc_dec[3] +encoded: MOO={ 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A}, {1002,false,R_B} } 'MOO_NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } } +myproto_msg_enc() rc = 0 +01 00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 00 03 00 02 89 13 00 04 00 02 00 01 00 04 00 02 00 02 00 04 00 02 7f ff 00 05 00 03 03 e9 80 00 05 00 03 03 ea 01 00 06 00 18 00 01 00 02 00 2a 00 02 00 08 66 6f 72 74 79 74 77 6f 00 03 00 02 10 92 . +myproto_msg_dec() rc = 0 +decoded: MOO={ 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A}, {1002,false,R_B} } 'MOO_NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } } +=== end t16l16v ordered test_enc_dec[3] + +=== start t16l16v ordered test_enc_dec[4] +encoded: GOO={ 'FOO'=17 'BAR'="gooei" 'GOO_NEST'={ { 'VAL'=0x123456789abcdef 'MOO_NEST'={ 'FOO'=11 'BAR'="eleven" 'BAZ'={1111,true} } }, { 'MOO_NEST'={ 'FOO'=12 'BAR'="twelve" 'BAZ'={1212,false} } } } } +myproto_msg_enc() rc = 0 +07 00 01 00 02 00 11 00 02 00 05 67 6f 6f 65 69 00 08 00 26 00 07 00 08 01 23 45 67 89 ab cd ef 00 06 00 16 00 01 00 02 00 0b 00 02 00 06 65 6c 65 76 65 6e 00 03 00 02 84 57 00 08 00 1a 00 06 00 16 00 01 00 02 00 0c 00 02 00 06 74 77 65 6c 76 65 00 03 00 02 04 bc . +myproto_msg_dec() rc = 0 +decoded: GOO={ 'FOO'=17 'BAR'="gooei" 'GOO_NEST'={ { 'VAL'=0x123456789abcdef 'MOO_NEST'={ 'FOO'=11 'BAR'="eleven" 'BAZ'={1111,true} } }, { 'MOO_NEST'={ 'FOO'=12 'BAR'="twelve" 'BAZ'={1212,false} } } } } +=== end t16l16v ordered test_enc_dec[4] + +=== start t16l16v unordered test_enc_dec[0] +encoded: MOO={ 'FOO'=23 'BAR'="twentythree" } +myproto_msg_enc() rc = 0 +01 00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 . +myproto_msg_dec() rc = 0 +decoded: MOO={ 'FOO'=23 'BAR'="twentythree" } +=== end t16l16v unordered test_enc_dec[0] + +=== start t16l16v unordered test_enc_dec[1] +encoded: MOO={ 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} } +myproto_msg_enc() rc = 0 +01 00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 00 03 00 02 89 13 . +myproto_msg_dec() rc = 0 +decoded: MOO={ 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} } +=== end t16l16v unordered test_enc_dec[1] + +=== start t16l16v unordered test_enc_dec[2] +encoded: MOO={ 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } } +myproto_msg_enc() rc = 0 +01 00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 00 03 00 02 89 13 00 04 00 02 00 01 00 04 00 02 00 02 00 04 00 02 7f ff . +myproto_msg_dec() rc = 0 +decoded: MOO={ 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } } +=== end t16l16v unordered test_enc_dec[2] + +=== start t16l16v unordered test_enc_dec[3] +encoded: MOO={ 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A}, {1002,false,R_B} } 'MOO_NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } } +myproto_msg_enc() rc = 0 +01 00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 00 03 00 02 89 13 00 04 00 02 00 01 00 04 00 02 00 02 00 04 00 02 7f ff 00 05 00 03 03 e9 80 00 05 00 03 03 ea 01 00 06 00 18 00 01 00 02 00 2a 00 02 00 08 66 6f 72 74 79 74 77 6f 00 03 00 02 10 92 . +myproto_msg_dec() rc = 0 +decoded: MOO={ 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A}, {1002,false,R_B} } 'MOO_NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } } +=== end t16l16v unordered test_enc_dec[3] + +=== start t16l16v unordered test_enc_dec[4] +encoded: GOO={ 'FOO'=17 'BAR'="gooei" 'GOO_NEST'={ { 'VAL'=0x123456789abcdef 'MOO_NEST'={ 'FOO'=11 'BAR'="eleven" 'BAZ'={1111,true} } }, { 'MOO_NEST'={ 'FOO'=12 'BAR'="twelve" 'BAZ'={1212,false} } } } } +myproto_msg_enc() rc = 0 +07 00 01 00 02 00 11 00 02 00 05 67 6f 6f 65 69 00 08 00 26 00 07 00 08 01 23 45 67 89 ab cd ef 00 06 00 16 00 01 00 02 00 0b 00 02 00 06 65 6c 65 76 65 6e 00 03 00 02 84 57 00 08 00 1a 00 06 00 16 00 01 00 02 00 0c 00 02 00 06 74 77 65 6c 76 65 00 03 00 02 04 bc . +myproto_msg_dec() rc = 0 +decoded: GOO={ 'FOO'=17 'BAR'="gooei" 'GOO_NEST'={ { 'VAL'=0x123456789abcdef 'MOO_NEST'={ 'FOO'=11 'BAR'="eleven" 'BAZ'={1111,true} } }, { 'MOO_NEST'={ 'FOO'=12 'BAR'="twelve" 'BAZ'={1212,false} } } } } +=== end t16l16v unordered test_enc_dec[4] -- cgit v1.2.3