summaryrefslogtreecommitdiffstats
path: root/tests/fuzztest/SConscript
blob: 6499714f6889d7515fdea17c44464543e77080ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Run a fuzz test to verify robustness against corrupted/malicious data.

Import("env")

# We need our own pb_decode.o for the malloc support
env = env.Clone()
env.Append(CPPDEFINES = {'PB_ENABLE_MALLOC': 1,
                         'PB_SYSTEM_HEADER': '\\"fuzz_syshdr.h\\"'})
env.Append(CPPPATH = ".")

if 'SYSHDR' in env:
    env.Append(CPPDEFINES = {'PB_OLD_SYSHDR': env['SYSHDR']})

# Disable libmudflap, because it will confuse valgrind
# and other memory leak detection tools.
if '-fmudflap' in env["CCFLAGS"]:
    env["CCFLAGS"].remove("-fmudflap")
    env["LINKFLAGS"].remove("-fmudflap")
    env["LIBS"].remove("mudflap")

strict = env.Clone()
strict.Append(CFLAGS = strict['CORECFLAGS'])
strict.Object("pb_decode_with_malloc.o", "$NANOPB/pb_decode.c")
strict.Object("pb_encode_with_malloc.o", "$NANOPB/pb_encode.c")
strict.Object("pb_common_with_malloc.o", "$NANOPB/pb_common.c")

# We want both pointer and static versions of the AllTypes message
env.Command("alltypes_static.proto", "#alltypes/alltypes.proto",
            lambda target, source, env:
                open(str(target[0]), 'w').write("package alltypes_static;\n"
                                                + open(str(source[0])).read()))
env.Command("alltypes_pointer.proto", "#alltypes/alltypes.proto",
            lambda target, source, env:
                open(str(target[0]), 'w').write("package alltypes_pointer;\n"
                                                + open(str(source[0])).read()))

p1 = env.NanopbProto(["alltypes_pointer", "alltypes_pointer.options"])
p2 = env.NanopbProto(["alltypes_static", "alltypes_static.options"])
fuzz = env.Program(["fuzztest.c",
                    "alltypes_pointer.pb.c",
                    "alltypes_static.pb.c",
                    "pb_encode_with_malloc.o",
                    "pb_decode_with_malloc.o",
                    "pb_common_with_malloc.o",
                    "malloc_wrappers.c"])
Depends([p1, p2, fuzz], ["fuzz_syshdr.h", "malloc_wrappers.h"])

env.RunTest(fuzz)

fuzzstub = env.Program(["fuzzstub.c",
                    "alltypes_pointer.pb.c",
                    "alltypes_static.pb.c",
                    "pb_encode_with_malloc.o",
                    "pb_decode_with_malloc.o",
                    "pb_common_with_malloc.o",
                    "malloc_wrappers.c"])