1# Encode the AllTypes message using pointers for all fields, and verify the 2# output against the normal AllTypes test case. 3 4Import("env", "malloc_env") 5 6c = Copy("$TARGET", "$SOURCE") 7env.Command("alltypes.proto", "#alltypes/alltypes.proto", c) 8 9env.NanopbProto(["alltypes", "alltypes.options"]) 10enc = malloc_env.Program(["encode_alltypes_pointer.c", 11 "alltypes.pb.c", 12 "$COMMON/pb_encode_with_malloc.o", 13 "$COMMON/pb_common_with_malloc.o", 14 "$COMMON/malloc_wrappers.o"]) 15dec = malloc_env.Program(["decode_alltypes_pointer.c", 16 "alltypes.pb.c", 17 "$COMMON/pb_decode_with_malloc.o", 18 "$COMMON/pb_common_with_malloc.o", 19 "$COMMON/malloc_wrappers.o"]) 20 21# Encode and compare results to non-pointer alltypes test case 22env.RunTest(enc) 23env.Compare(["encode_alltypes_pointer.output", "$BUILD/alltypes/encode_alltypes.output"]) 24 25# Decode (under valgrind if available) 26kwargs = {} 27if env.get("VALGRIND"): 28 kwargs['COMMAND'] = env['VALGRIND'] 29 kwargs['ARGS'] = ["-q", "--error-exitcode=99", dec[0].abspath] 30 31env.RunTest("decode_alltypes.output", [dec, "encode_alltypes_pointer.output"], **kwargs) 32 33# Do the same thing with the optional fields present 34env.RunTest("optionals.output", enc, ARGS = ['1']) 35env.Compare(["optionals.output", "$BUILD/alltypes/optionals.output"]) 36 37kwargs['ARGS'] = kwargs.get('ARGS', []) + ['1'] 38env.RunTest("optionals.decout", [dec, "optionals.output"], **kwargs) 39 40