1# Copyright (c) 2013-2016 The Bitcoin Core developers
2# Distributed under the MIT software license, see the accompanying
3# file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5if ENABLE_FUZZ_BINARY
6noinst_PROGRAMS += test/fuzz/fuzz
7endif
8
9if !ENABLE_FUZZ
10bin_PROGRAMS += test/test_bitcoin
11endif
12
13TEST_SRCDIR = test
14TEST_BINARY=test/test_bitcoin$(EXEEXT)
15FUZZ_BINARY=test/fuzz/fuzz$(EXEEXT)
16
17JSON_TEST_FILES = \
18  test/data/script_tests.json \
19  test/data/base58_encode_decode.json \
20  test/data/blockfilters.json \
21  test/data/key_io_valid.json \
22  test/data/key_io_invalid.json \
23  test/data/script_tests.json \
24  test/data/sighash.json \
25  test/data/tx_invalid.json \
26  test/data/tx_valid.json
27
28RAW_TEST_FILES = \
29  test/data/asmap.raw
30
31GENERATED_TEST_FILES = $(JSON_TEST_FILES:.json=.json.h) $(RAW_TEST_FILES:.raw=.raw.h)
32
33BITCOIN_TEST_SUITE = \
34  test/main.cpp \
35  $(TEST_UTIL_H)
36
37FUZZ_SUITE_LD_COMMON = \
38 $(LIBTEST_UTIL) \
39 $(LIBTEST_FUZZ) \
40 $(LIBBITCOIN_SERVER) \
41 $(LIBBITCOIN_WALLET) \
42 $(LIBBITCOIN_COMMON) \
43 $(LIBBITCOIN_UTIL) \
44 $(LIBBITCOIN_CONSENSUS) \
45 $(LIBBITCOIN_CRYPTO) \
46 $(LIBBITCOIN_CLI) \
47 $(LIBUNIVALUE) \
48 $(LIBLEVELDB) \
49 $(LIBLEVELDB_SSE42) \
50 $(BOOST_LIBS) \
51 $(LIBMEMENV) \
52 $(LIBSECP256K1) \
53 $(EVENT_LIBS) \
54 $(EVENT_PTHREADS_LIBS)
55
56if USE_UPNP
57FUZZ_SUITE_LD_COMMON += $(MINIUPNPC_LIBS)
58endif
59
60if USE_NATPMP
61FUZZ_SUITE_LD_COMMON += $(NATPMP_LIBS)
62endif
63
64# test_bitcoin binary #
65BITCOIN_TESTS =\
66  test/arith_uint256_tests.cpp \
67  test/scriptnum10.h \
68  test/addrman_tests.cpp \
69  test/amount_tests.cpp \
70  test/allocator_tests.cpp \
71  test/base32_tests.cpp \
72  test/base58_tests.cpp \
73  test/base64_tests.cpp \
74  test/bech32_tests.cpp \
75  test/bip32_tests.cpp \
76  test/blockchain_tests.cpp \
77  test/blockencodings_tests.cpp \
78  test/blockfilter_tests.cpp \
79  test/blockfilter_index_tests.cpp \
80  test/bloom_tests.cpp \
81  test/bswap_tests.cpp \
82  test/checkqueue_tests.cpp \
83  test/coins_tests.cpp \
84  test/coinstatsindex_tests.cpp \
85  test/compilerbug_tests.cpp \
86  test/compress_tests.cpp \
87  test/crypto_tests.cpp \
88  test/cuckoocache_tests.cpp \
89  test/denialofservice_tests.cpp \
90  test/descriptor_tests.cpp \
91  test/flatfile_tests.cpp \
92  test/fs_tests.cpp \
93  test/getarg_tests.cpp \
94  test/hash_tests.cpp \
95  test/i2p_tests.cpp \
96  test/interfaces_tests.cpp \
97  test/key_io_tests.cpp \
98  test/key_tests.cpp \
99  test/logging_tests.cpp \
100  test/dbwrapper_tests.cpp \
101  test/validation_tests.cpp \
102  test/mempool_tests.cpp \
103  test/merkle_tests.cpp \
104  test/merkleblock_tests.cpp \
105  test/miner_tests.cpp \
106  test/multisig_tests.cpp \
107  test/net_peer_eviction_tests.cpp \
108  test/net_tests.cpp \
109  test/netbase_tests.cpp \
110  test/pmt_tests.cpp \
111  test/policy_fee_tests.cpp \
112  test/policyestimator_tests.cpp \
113  test/pow_tests.cpp \
114  test/prevector_tests.cpp \
115  test/raii_event_tests.cpp \
116  test/random_tests.cpp \
117  test/reverselock_tests.cpp \
118  test/rpc_tests.cpp \
119  test/sanity_tests.cpp \
120  test/scheduler_tests.cpp \
121  test/script_p2sh_tests.cpp \
122  test/script_tests.cpp \
123  test/script_standard_tests.cpp \
124  test/scriptnum_tests.cpp \
125  test/serfloat_tests.cpp \
126  test/serialize_tests.cpp \
127  test/settings_tests.cpp \
128  test/sighash_tests.cpp \
129  test/sigopcount_tests.cpp \
130  test/skiplist_tests.cpp \
131  test/sock_tests.cpp \
132  test/streams_tests.cpp \
133  test/sync_tests.cpp \
134  test/system_tests.cpp \
135  test/util_threadnames_tests.cpp \
136  test/timedata_tests.cpp \
137  test/torcontrol_tests.cpp \
138  test/transaction_tests.cpp \
139  test/txindex_tests.cpp \
140  test/txrequest_tests.cpp \
141  test/txvalidation_tests.cpp \
142  test/txvalidationcache_tests.cpp \
143  test/uint256_tests.cpp \
144  test/util_tests.cpp \
145  test/validation_block_tests.cpp \
146  test/validation_chainstate_tests.cpp \
147  test/validation_chainstatemanager_tests.cpp \
148  test/validation_flush_tests.cpp \
149  test/validationinterface_tests.cpp \
150  test/versionbits_tests.cpp
151
152if ENABLE_WALLET
153BITCOIN_TESTS += \
154  wallet/test/psbt_wallet_tests.cpp \
155  wallet/test/wallet_tests.cpp \
156  wallet/test/walletdb_tests.cpp \
157  wallet/test/wallet_crypto_tests.cpp \
158  wallet/test/coinselector_tests.cpp \
159  wallet/test/init_tests.cpp \
160  wallet/test/ismine_tests.cpp \
161  wallet/test/scriptpubkeyman_tests.cpp
162
163FUZZ_SUITE_LD_COMMON +=\
164 $(SQLITE_LIBS) \
165 $(BDB_LIBS)
166
167if USE_BDB
168BITCOIN_TESTS += wallet/test/db_tests.cpp
169endif
170
171
172BITCOIN_TEST_SUITE += \
173  wallet/test/wallet_test_fixture.cpp \
174  wallet/test/wallet_test_fixture.h \
175  wallet/test/init_test_fixture.cpp \
176  wallet/test/init_test_fixture.h
177endif
178
179test_test_bitcoin_SOURCES = $(BITCOIN_TEST_SUITE) $(BITCOIN_TESTS) $(JSON_TEST_FILES) $(RAW_TEST_FILES)
180test_test_bitcoin_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(TESTDEFS) $(EVENT_CFLAGS)
181test_test_bitcoin_LDADD = $(LIBTEST_UTIL)
182if ENABLE_WALLET
183test_test_bitcoin_LDADD += $(LIBBITCOIN_WALLET)
184endif
185
186test_test_bitcoin_LDADD += $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) \
187  $(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) $(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1) $(EVENT_LIBS) $(EVENT_PTHREADS_LIBS)
188test_test_bitcoin_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
189
190test_test_bitcoin_LDADD += $(BDB_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(SQLITE_LIBS)
191test_test_bitcoin_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS) -static
192
193if ENABLE_ZMQ
194test_test_bitcoin_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
195FUZZ_SUITE_LD_COMMON += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
196endif
197
198FUZZ_SUITE_LDFLAGS_COMMON = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS)
199
200if ENABLE_FUZZ_BINARY
201test_fuzz_fuzz_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
202test_fuzz_fuzz_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
203test_fuzz_fuzz_LDADD = $(FUZZ_SUITE_LD_COMMON)
204test_fuzz_fuzz_LDFLAGS = $(FUZZ_SUITE_LDFLAGS_COMMON)
205test_fuzz_fuzz_SOURCES = \
206 test/fuzz/addition_overflow.cpp \
207 test/fuzz/addrdb.cpp \
208 test/fuzz/addrman.cpp \
209 test/fuzz/asmap.cpp \
210 test/fuzz/asmap_direct.cpp \
211 test/fuzz/autofile.cpp \
212 test/fuzz/banman.cpp \
213 test/fuzz/base_encode_decode.cpp \
214 test/fuzz/bech32.cpp \
215 test/fuzz/block.cpp \
216 test/fuzz/block_header.cpp \
217 test/fuzz/blockfilter.cpp \
218 test/fuzz/bloom_filter.cpp \
219 test/fuzz/buffered_file.cpp \
220 test/fuzz/chain.cpp \
221 test/fuzz/checkqueue.cpp \
222 test/fuzz/coins_view.cpp \
223 test/fuzz/connman.cpp \
224 test/fuzz/crypto.cpp \
225 test/fuzz/crypto_aes256.cpp \
226 test/fuzz/crypto_aes256cbc.cpp \
227 test/fuzz/crypto_chacha20.cpp \
228 test/fuzz/crypto_chacha20_poly1305_aead.cpp \
229 test/fuzz/crypto_common.cpp \
230 test/fuzz/crypto_hkdf_hmac_sha256_l32.cpp \
231 test/fuzz/crypto_poly1305.cpp \
232 test/fuzz/cuckoocache.cpp \
233 test/fuzz/data_stream.cpp \
234 test/fuzz/decode_tx.cpp \
235 test/fuzz/descriptor_parse.cpp \
236 test/fuzz/deserialize.cpp \
237 test/fuzz/eval_script.cpp \
238 test/fuzz/fee_rate.cpp \
239 test/fuzz/fees.cpp \
240 test/fuzz/flatfile.cpp \
241 test/fuzz/float.cpp \
242 test/fuzz/golomb_rice.cpp \
243 test/fuzz/hex.cpp \
244 test/fuzz/http_request.cpp \
245 test/fuzz/i2p.cpp \
246 test/fuzz/integer.cpp \
247 test/fuzz/key.cpp \
248 test/fuzz/key_io.cpp \
249 test/fuzz/kitchen_sink.cpp \
250 test/fuzz/load_external_block_file.cpp \
251 test/fuzz/locale.cpp \
252 test/fuzz/merkleblock.cpp \
253 test/fuzz/message.cpp \
254 test/fuzz/muhash.cpp \
255 test/fuzz/multiplication_overflow.cpp \
256 test/fuzz/net.cpp \
257 test/fuzz/net_permissions.cpp \
258 test/fuzz/netaddress.cpp \
259 test/fuzz/netbase_dns_lookup.cpp \
260 test/fuzz/node_eviction.cpp \
261 test/fuzz/p2p_transport_serialization.cpp \
262 test/fuzz/parse_hd_keypath.cpp \
263 test/fuzz/parse_iso8601.cpp \
264 test/fuzz/parse_numbers.cpp \
265 test/fuzz/parse_script.cpp \
266 test/fuzz/parse_univalue.cpp \
267 test/fuzz/policy_estimator.cpp \
268 test/fuzz/policy_estimator_io.cpp \
269 test/fuzz/pow.cpp \
270 test/fuzz/prevector.cpp \
271 test/fuzz/primitives_transaction.cpp \
272 test/fuzz/process_message.cpp \
273 test/fuzz/process_messages.cpp \
274 test/fuzz/protocol.cpp \
275 test/fuzz/psbt.cpp \
276 test/fuzz/random.cpp \
277 test/fuzz/rbf.cpp \
278 test/fuzz/rolling_bloom_filter.cpp \
279 test/fuzz/rpc.cpp \
280 test/fuzz/script.cpp \
281 test/fuzz/script_assets_test_minimizer.cpp \
282 test/fuzz/script_bitcoin_consensus.cpp \
283 test/fuzz/script_descriptor_cache.cpp \
284 test/fuzz/script_flags.cpp \
285 test/fuzz/script_interpreter.cpp \
286 test/fuzz/script_ops.cpp \
287 test/fuzz/script_sigcache.cpp \
288 test/fuzz/script_sign.cpp \
289 test/fuzz/scriptnum_ops.cpp \
290 test/fuzz/secp256k1_ec_seckey_import_export_der.cpp \
291 test/fuzz/secp256k1_ecdsa_signature_parse_der_lax.cpp \
292 test/fuzz/signature_checker.cpp \
293 test/fuzz/signet.cpp \
294 test/fuzz/socks5.cpp \
295 test/fuzz/span.cpp \
296 test/fuzz/spanparsing.cpp \
297 test/fuzz/string.cpp \
298 test/fuzz/strprintf.cpp \
299 test/fuzz/system.cpp \
300 test/fuzz/timedata.cpp \
301 test/fuzz/torcontrol.cpp \
302 test/fuzz/transaction.cpp \
303 test/fuzz/tx_in.cpp \
304 test/fuzz/tx_out.cpp \
305 test/fuzz/tx_pool.cpp \
306 test/fuzz/txrequest.cpp \
307 test/fuzz/utxo_snapshot.cpp \
308 test/fuzz/validation_load_mempool.cpp \
309 test/fuzz/versionbits.cpp
310endif # ENABLE_FUZZ_BINARY
311
312nodist_test_test_bitcoin_SOURCES = $(GENERATED_TEST_FILES)
313
314$(BITCOIN_TESTS): $(GENERATED_TEST_FILES)
315
316CLEAN_BITCOIN_TEST = test/*.gcda test/*.gcno test/fuzz/*.gcda test/fuzz/*.gcno test/util/*.gcda test/util/*.gcno $(GENERATED_TEST_FILES) $(BITCOIN_TESTS:=.log)
317
318CLEANFILES += $(CLEAN_BITCOIN_TEST)
319
320if TARGET_WINDOWS
321bitcoin_test: $(TEST_BINARY)
322else
323if ENABLE_BENCH
324bitcoin_test: $(TEST_BINARY) $(BENCH_BINARY)
325else
326bitcoin_test: $(TEST_BINARY)
327endif
328endif
329
330bitcoin_test_check: $(TEST_BINARY) FORCE
331	$(MAKE) check-TESTS TESTS=$^
332
333bitcoin_test_clean : FORCE
334	rm -f $(CLEAN_BITCOIN_TEST) $(test_test_bitcoin_OBJECTS) $(TEST_BINARY)
335
336check-local: $(BITCOIN_TESTS:.cpp=.cpp.test)
337if BUILD_BITCOIN_TX
338	@echo "Running test/util/bitcoin-util-test.py..."
339	$(PYTHON) $(top_builddir)/test/util/bitcoin-util-test.py
340endif
341	@echo "Running test/util/rpcauth-test.py..."
342	$(PYTHON) $(top_builddir)/test/util/rpcauth-test.py
343if TARGET_WINDOWS
344else
345if ENABLE_BENCH
346	@echo "Running bench/bench_bitcoin ..."
347	$(BENCH_BINARY) > /dev/null
348endif
349endif
350	$(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C secp256k1 check
351if EMBEDDED_UNIVALUE
352	$(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C univalue check
353endif
354
355%.cpp.test: %.cpp
356	@echo Running tests: `cat $< | grep -E "(BOOST_FIXTURE_TEST_SUITE\\(|BOOST_AUTO_TEST_SUITE\\()" | cut -d '(' -f 2 | cut -d ',' -f 1 | cut -d ')' -f 1` from $<
357	$(AM_V_at)$(TEST_BINARY) --catch_system_errors=no -l test_suite -t "`cat $< | grep -E "(BOOST_FIXTURE_TEST_SUITE\\(|BOOST_AUTO_TEST_SUITE\\()" | cut -d '(' -f 2 | cut -d ',' -f 1 | cut -d ')' -f 1`" -- DEBUG_LOG_OUT > $<.log 2>&1 || (cat $<.log && false)
358
359%.json.h: %.json
360	@$(MKDIR_P) $(@D)
361	@{ \
362	 echo "namespace json_tests{" && \
363	 echo "static unsigned const char $(*F)[] = {" && \
364	 $(HEXDUMP) -v -e '8/1 "0x%02x, "' -e '"\n"' $< | $(SED) -e 's/0x  ,//g' && \
365	 echo "};};"; \
366	} > "$@.new" && mv -f "$@.new" "$@"
367	@echo "Generated $@"
368
369%.raw.h: %.raw
370	@$(MKDIR_P) $(@D)
371	@{ \
372	 echo "static unsigned const char $(*F)_raw[] = {" && \
373	 $(HEXDUMP) -v -e '8/1 "0x%02x, "' -e '"\n"' $< | $(SED) -e 's/0x  ,//g' && \
374	 echo "};"; \
375	} > "$@.new" && mv -f "$@.new" "$@"
376	@echo "Generated $@"
377