Remove check-tor script
[tor.git] / scripts / codegen / fuzzing_include_am.py
bloba9445844536fedd8ecf38edbc9fb27366e82b8c1
1 #!/usr/bin/python
3 FUZZERS = """
4 consensus
5 descriptor
6 diff
7 diff-apply
8 extrainfo
9 hsdescv2
10 hsdescv3
11 http
12 http-connect
13 iptsv2
14 microdesc
15 socks
16 strops
17 vrs
18 """
21 PREAMBLE = r"""
22 FUZZING_CPPFLAGS = \
23 $(src_test_AM_CPPFLAGS) $(TEST_CPPFLAGS)
24 FUZZING_CFLAGS = \
25 $(AM_CFLAGS) $(TEST_CFLAGS)
26 FUZZING_LDFLAG = \
27 @TOR_LDFLAGS_zlib@ $(TOR_LDFLAGS_CRYPTLIB) @TOR_LDFLAGS_libevent@
28 FUZZING_LIBS = \
29 $(TOR_INTERNAL_TESTING_LIBS) \
30 $(rust_ldadd) \
31 @TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ \
32 @TOR_LIBEVENT_LIBS@ $(TOR_LIBS_CRYPTLIB) \
33 @TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_GDI@ @TOR_LIB_USERENV@ @CURVE25519_LIBS@ \
34 @TOR_SYSTEMD_LIBS@ \
35 @TOR_LZMA_LIBS@ \
36 @TOR_ZSTD_LIBS@
38 oss-fuzz-prereqs: \
39 $(TOR_INTERNAL_TESTING_LIBS)
41 noinst_HEADERS += \
42 src/test/fuzz/fuzzing.h
44 LIBFUZZER = -lFuzzer
45 LIBFUZZER_CPPFLAGS = $(FUZZING_CPPFLAGS) -DLLVM_FUZZ
46 LIBFUZZER_CFLAGS = $(FUZZING_CFLAGS)
47 LIBFUZZER_LDFLAG = $(FUZZING_LDFLAG)
48 LIBFUZZER_LIBS = $(FUZZING_LIBS) $(LIBFUZZER) -lstdc++
50 LIBOSS_FUZZ_CPPFLAGS = $(FUZZING_CPPFLAGS) -DLLVM_FUZZ
51 LIBOSS_FUZZ_CFLAGS = $(FUZZING_CFLAGS)
52 """
54 POSTAMBLE = r"""
55 noinst_PROGRAMS += $(FUZZERS) $(LIBFUZZER_FUZZERS)
56 noinst_LIBRARIES += $(OSS_FUZZ_FUZZERS)
57 oss-fuzz-fuzzers: oss-fuzz-prereqs $(OSS_FUZZ_FUZZERS)
58 fuzzers: $(FUZZERS) $(LIBFUZZER_FUZZERS)
60 test-fuzz-corpora: $(FUZZERS)
61 $(top_srcdir)/src/test/fuzz_static_testcases.sh
62 """
64 ########### No user serviceable parts will follow.
66 PREAMBLE = PREAMBLE.strip()
67 POSTAMBLE = POSTAMBLE.strip() # If I use it, it's a word!
68 FUZZERS = FUZZERS.split()
69 FUZZERS.sort()
71 WARNING = """
72 # This file was generated by fuzzing_include_am.py; do not hand-edit unless
73 # you enjoy having your changes erased.
74 """.strip()
76 print(WARNING)
78 print(PREAMBLE)
80 print("\n# ===== AFL fuzzers")
82 def get_id_name(s):
83 return s.replace("-", "_")
85 for fuzzer in FUZZERS:
86 idname = get_id_name(fuzzer)
87 print("""\
88 if UNITTESTS_ENABLED
89 src_test_fuzz_fuzz_{name}_SOURCES = \\
90 src/test/fuzz/fuzzing_common.c \\
91 src/test/fuzz/fuzz_{name}.c
92 src_test_fuzz_fuzz_{name}_CPPFLAGS = $(FUZZING_CPPFLAGS)
93 src_test_fuzz_fuzz_{name}_CFLAGS = $(FUZZING_CFLAGS)
94 src_test_fuzz_fuzz_{name}_LDFLAGS = $(FUZZING_LDFLAG)
95 src_test_fuzz_fuzz_{name}_LDADD = $(FUZZING_LIBS)
96 endif
97 """.format(name=idname))
99 print("if UNITTESTS_ENABLED")
100 print("FUZZERS = \\")
101 print(" \\\n".join("\tsrc/test/fuzz/fuzz-{name}".format(name=fuzzer)
102 for fuzzer in FUZZERS))
103 print("endif")
105 print("\n# ===== libfuzzer")
106 print("\nif LIBFUZZER_ENABLED")
108 for fuzzer in FUZZERS:
109 idname = get_id_name(fuzzer)
110 print("""\
111 if UNITTESTS_ENABLED
112 src_test_fuzz_lf_fuzz_{name}_SOURCES = \\
113 $(src_test_fuzz_fuzz_{name}_SOURCES)
114 src_test_fuzz_lf_fuzz_{name}_CPPFLAGS = $(LIBFUZZER_CPPFLAGS)
115 src_test_fuzz_lf_fuzz_{name}_CFLAGS = $(LIBFUZZER_CFLAGS)
116 src_test_fuzz_lf_fuzz_{name}_LDFLAGS = $(LIBFUZZER_LDFLAG)
117 src_test_fuzz_lf_fuzz_{name}_LDADD = $(LIBFUZZER_LIBS)
118 endif
119 """.format(name=idname))
121 print("LIBFUZZER_FUZZERS = \\")
122 print(" \\\n".join("\tsrc/test/fuzz/lf-fuzz-{name}".format(name=fuzzer)
123 for fuzzer in FUZZERS))
125 print("""
126 else
127 LIBFUZZER_FUZZERS =
128 endif""")
130 print("\n# ===== oss-fuzz\n")
131 print("if OSS_FUZZ_ENABLED")
133 for fuzzer in FUZZERS:
134 idname = get_id_name(fuzzer)
135 print("""\
136 if UNITTESTS_ENABLED
137 src_test_fuzz_liboss_fuzz_{name}_a_SOURCES = \\
138 $(src_test_fuzz_fuzz_{name}_SOURCES)
139 src_test_fuzz_liboss_fuzz_{name}_a_CPPFLAGS = $(LIBOSS_FUZZ_CPPFLAGS)
140 src_test_fuzz_liboss_fuzz_{name}_a_CFLAGS = $(LIBOSS_FUZZ_CFLAGS)
141 endif
142 """.format(name=idname))
144 print("OSS_FUZZ_FUZZERS = \\")
145 print(" \\\n".join("\tsrc/test/fuzz/liboss-fuzz-{name}.a".format(name=fuzzer)
146 for fuzzer in FUZZERS))
148 print("""
149 else
150 OSS_FUZZ_FUZZERS =
151 endif""")
153 print("")
155 print(POSTAMBLE)