Tune congestion control parameters.
[tor.git] / scripts / codegen / fuzzing_include_am.py
blobd5d5cb01543d27786663dc63b7925903ce8e984d
1 #!/usr/bin/env python
3 # Future imports for Python 2.7, mandatory in 3.0
4 from __future__ import division
5 from __future__ import print_function
6 from __future__ import unicode_literals
8 FUZZERS = """
9 address
10 addressPTR
11 consensus
12 descriptor
13 diff
14 diff-apply
15 extrainfo
16 hsdescv3
17 hsdescv3-inner
18 hsdescv3-middle
19 http
20 http-connect
21 microdesc
22 socks
23 strops
24 vrs
25 """
28 PREAMBLE = r"""
29 FUZZING_CPPFLAGS = \
30 $(src_test_AM_CPPFLAGS) $(TEST_CPPFLAGS)
31 FUZZING_CFLAGS = \
32 $(AM_CFLAGS) $(TEST_CFLAGS)
33 FUZZING_LDFLAG = \
34 @TOR_LDFLAGS_zlib@ $(TOR_LDFLAGS_CRYPTLIB) @TOR_LDFLAGS_libevent@
35 FUZZING_LIBS = \
36 src/test/libtor-testing.a \
37 @TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ \
38 @TOR_LIBEVENT_LIBS@ $(TOR_LIBS_CRYPTLIB) \
39 @TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_SHLWAPI@ @TOR_LIB_GDI@ @TOR_LIB_USERENV@ @CURVE25519_LIBS@ \
40 @TOR_SYSTEMD_LIBS@ \
41 @TOR_LZMA_LIBS@ \
42 @TOR_ZSTD_LIBS@ \
43 @TOR_TRACE_LIBS@
45 oss-fuzz-prereqs: \
46 src/test/libtor-testing.a
48 noinst_HEADERS += \
49 src/test/fuzz/fuzzing.h
51 LIBFUZZER_CPPFLAGS = $(FUZZING_CPPFLAGS) -DLLVM_FUZZ
52 LIBFUZZER_CFLAGS = $(FUZZING_CFLAGS)
53 LIBFUZZER_LDFLAG = $(FUZZING_LDFLAG) -fsanitize=fuzzer
54 LIBFUZZER_LIBS = $(FUZZING_LIBS) -lstdc++
56 LIBOSS_FUZZ_CPPFLAGS = $(FUZZING_CPPFLAGS) -DLLVM_FUZZ
57 LIBOSS_FUZZ_CFLAGS = $(FUZZING_CFLAGS)
58 """
60 POSTAMBLE = r"""
61 noinst_PROGRAMS += $(FUZZERS) $(LIBFUZZER_FUZZERS)
62 noinst_LIBRARIES += $(OSS_FUZZ_FUZZERS)
63 oss-fuzz-fuzzers: oss-fuzz-prereqs $(OSS_FUZZ_FUZZERS)
64 fuzzers: $(FUZZERS) $(LIBFUZZER_FUZZERS)
66 test-fuzz-corpora: $(FUZZERS)
67 $(top_srcdir)/src/test/fuzz_static_testcases.sh
68 """
70 ########### No user serviceable parts will follow.
72 PREAMBLE = PREAMBLE.strip()
73 POSTAMBLE = POSTAMBLE.strip() # If I use it, it's a word!
74 FUZZERS = FUZZERS.split()
75 FUZZERS.sort()
77 WARNING = """
78 # This file was generated by fuzzing_include_am.py; do not hand-edit unless
79 # you enjoy having your changes erased.
80 """.strip()
82 print(WARNING)
84 print(PREAMBLE)
86 print("\n# ===== AFL fuzzers")
88 def get_id_name(s):
89 return s.replace("-", "_")
91 for fuzzer in FUZZERS:
92 idname = get_id_name(fuzzer)
93 print("""\
94 if UNITTESTS_ENABLED
95 src_test_fuzz_fuzz_{name}_SOURCES = \\
96 src/test/fuzz/fuzzing_common.c \\
97 src/test/fuzz/fuzz_{name}.c
98 src_test_fuzz_fuzz_{name}_CPPFLAGS = $(FUZZING_CPPFLAGS)
99 src_test_fuzz_fuzz_{name}_CFLAGS = $(FUZZING_CFLAGS)
100 src_test_fuzz_fuzz_{name}_LDFLAGS = $(FUZZING_LDFLAG)
101 src_test_fuzz_fuzz_{name}_LDADD = $(FUZZING_LIBS)
102 endif
103 """.format(name=idname))
105 print("if UNITTESTS_ENABLED")
106 print("FUZZERS = \\")
107 print(" \\\n".join("\tsrc/test/fuzz/fuzz-{name}".format(name=fuzzer)
108 for fuzzer in FUZZERS))
109 print("endif")
111 print("\n# ===== libfuzzer")
112 print("\nif LIBFUZZER_ENABLED")
114 for fuzzer in FUZZERS:
115 idname = get_id_name(fuzzer)
116 print("""\
117 if UNITTESTS_ENABLED
118 src_test_fuzz_lf_fuzz_{name}_SOURCES = \\
119 $(src_test_fuzz_fuzz_{name}_SOURCES)
120 src_test_fuzz_lf_fuzz_{name}_CPPFLAGS = $(LIBFUZZER_CPPFLAGS)
121 src_test_fuzz_lf_fuzz_{name}_CFLAGS = $(LIBFUZZER_CFLAGS)
122 src_test_fuzz_lf_fuzz_{name}_LDFLAGS = $(LIBFUZZER_LDFLAG)
123 src_test_fuzz_lf_fuzz_{name}_LDADD = $(LIBFUZZER_LIBS)
124 endif
125 """.format(name=idname))
127 print("LIBFUZZER_FUZZERS = \\")
128 print(" \\\n".join("\tsrc/test/fuzz/lf-fuzz-{name}".format(name=fuzzer)
129 for fuzzer in FUZZERS))
131 print("""
132 else
133 LIBFUZZER_FUZZERS =
134 endif""")
136 print("\n# ===== oss-fuzz\n")
137 print("if OSS_FUZZ_ENABLED")
139 for fuzzer in FUZZERS:
140 idname = get_id_name(fuzzer)
141 print("""\
142 if UNITTESTS_ENABLED
143 src_test_fuzz_liboss_fuzz_{name}_a_SOURCES = \\
144 $(src_test_fuzz_fuzz_{name}_SOURCES)
145 src_test_fuzz_liboss_fuzz_{name}_a_CPPFLAGS = $(LIBOSS_FUZZ_CPPFLAGS)
146 src_test_fuzz_liboss_fuzz_{name}_a_CFLAGS = $(LIBOSS_FUZZ_CFLAGS)
147 endif
148 """.format(name=idname))
150 print("OSS_FUZZ_FUZZERS = \\")
151 print(" \\\n".join("\tsrc/test/fuzz/liboss-fuzz-{name}.a".format(name=fuzzer)
152 for fuzzer in FUZZERS))
154 print("""
155 else
156 OSS_FUZZ_FUZZERS =
157 endif""")
159 print("")
161 print(POSTAMBLE)