e48d6aadf9aeb8f5503fb25545161d0efe587536
[apps/agl-service-can-low-level.git] / tests / alltypes_pointer / SConscript
1 # Encode the AllTypes message using pointers for all fields, and verify the
2 # output against the normal AllTypes test case.
3
4 Import("env")
5
6 # We need our own pb_decode.o for the malloc support
7 env = env.Clone()
8 env.Append(CPPDEFINES = {'PB_ENABLE_MALLOC': 1});
9
10 # Disable libmudflap, because it will confuse valgrind
11 # and other memory leak detection tools.
12 if '-fmudflap' in env["CCFLAGS"]:
13     env["CCFLAGS"].remove("-fmudflap")
14     env["LINKFLAGS"].remove("-fmudflap")
15     env["LIBS"].remove("mudflap")
16
17 strict = env.Clone()
18 strict.Append(CFLAGS = strict['CORECFLAGS'])
19 strict.Object("pb_decode_with_malloc.o", "$NANOPB/pb_decode.c")
20 strict.Object("pb_encode_with_malloc.o", "$NANOPB/pb_encode.c")
21
22 c = Copy("$TARGET", "$SOURCE")
23 env.Command("alltypes.proto", "#alltypes/alltypes.proto", c)
24
25 env.NanopbProto(["alltypes", "alltypes.options"])
26 enc = env.Program(["encode_alltypes_pointer.c", "alltypes.pb.c", "pb_encode_with_malloc.o"])
27 dec = env.Program(["decode_alltypes_pointer.c", "alltypes.pb.c", "pb_decode_with_malloc.o"])
28
29 # Encode and compare results to non-pointer alltypes test case
30 env.RunTest(enc)
31 env.Compare(["encode_alltypes_pointer.output", "$BUILD/alltypes/encode_alltypes.output"])
32
33 # Decode (under valgrind if available)
34 valgrind = env.WhereIs('valgrind')
35 kwargs = {}
36 if valgrind:
37     kwargs['COMMAND'] = valgrind
38     kwargs['ARGS'] = ["-q", dec[0].abspath]
39
40 env.RunTest("decode_alltypes.output", [dec, "encode_alltypes_pointer.output"], **kwargs)
41
42 # Do the same thing with the optional fields present
43 env.RunTest("optionals.output", enc, ARGS = ['1'])
44 env.Compare(["optionals.output", "$BUILD/alltypes/optionals.output"])
45
46 kwargs['ARGS'] = kwargs.get('ARGS', []) + ['1']
47 env.RunTest("optionals.decout", [dec, "optionals.output"], **kwargs)
48