From ad203019f9d1a10d61f0a80ae5ab27315aaf16ae Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Mon, 25 Oct 2021 21:28:37 +0530 Subject: [PATCH] merge bitcoin#15788: Unify testing setups for fuzz, bench, and unit tests --- src/Makefile.bench.include | 6 +- src/Makefile.qttest.include | 4 +- src/Makefile.test.include | 8 +- src/bench/bench.cpp | 11 +++ src/bench/bench_dash.cpp | 32 -------- src/bench/block_assemble.cpp | 70 +--------------- src/bench/duplicate_inputs.cpp | 35 +------- src/qt/test/addressbooktests.cpp | 2 +- src/qt/test/rpcnestedtests.cpp | 2 +- src/qt/test/wallettests.cpp | 2 +- src/test/README.md | 2 +- src/test/addrman_tests.cpp | 2 +- src/test/allocator_tests.cpp | 2 +- src/test/amount_tests.cpp | 2 +- src/test/arith_uint256_tests.cpp | 2 +- src/test/base32_tests.cpp | 2 +- src/test/base58_tests.cpp | 2 +- src/test/base64_tests.cpp | 2 +- src/test/bech32_tests.cpp | 2 +- src/test/bip32_tests.cpp | 2 +- src/test/bip39_tests.cpp | 2 +- src/test/blockchain_tests.cpp | 2 +- src/test/blockencodings_tests.cpp | 2 +- src/test/blockfilter_index_tests.cpp | 2 +- src/test/blockfilter_tests.cpp | 2 +- src/test/bloom_tests.cpp | 2 +- src/test/bls_tests.cpp | 2 +- src/test/bswap_tests.cpp | 2 +- src/test/cachemap_tests.cpp | 2 +- src/test/cachemultimap_tests.cpp | 2 +- src/test/checkdatasig_tests.cpp | 2 +- src/test/checkqueue_tests.cpp | 2 +- src/test/coins_tests.cpp | 2 +- src/test/compress_tests.cpp | 2 +- src/test/crypto_tests.cpp | 2 +- src/test/cuckoocache_tests.cpp | 2 +- src/test/dbwrapper_tests.cpp | 2 +- src/test/denialofservice_tests.cpp | 2 +- src/test/descriptor_tests.cpp | 2 +- src/test/dip0020opcodes_tests.cpp | 2 +- src/test/evo_deterministicmns_tests.cpp | 2 +- src/test/evo_simplifiedmns_tests.cpp | 2 +- src/test/flatfile_tests.cpp | 2 +- src/test/fs_tests.cpp | 2 +- src/test/getarg_tests.cpp | 2 +- src/test/governance_validators_tests.cpp | 2 +- src/test/hash_tests.cpp | 2 +- src/test/key_io_tests.cpp | 2 +- src/test/key_tests.cpp | 2 +- src/test/limitedmap_tests.cpp | 2 +- src/test/logging_tests.cpp | 2 +- src/test/mempool_tests.cpp | 2 +- src/test/merkle_tests.cpp | 2 +- src/test/merkleblock_tests.cpp | 2 +- src/test/miner_tests.cpp | 2 +- src/test/multisig_tests.cpp | 2 +- src/test/net_tests.cpp | 2 +- src/test/netbase_tests.cpp | 2 +- src/test/pmt_tests.cpp | 2 +- src/test/policyestimator_tests.cpp | 2 +- src/test/pow_tests.cpp | 2 +- src/test/prevector_tests.cpp | 2 +- src/test/raii_event_tests.cpp | 2 +- src/test/random_tests.cpp | 2 +- src/test/ratecheck_tests.cpp | 2 +- src/test/reverselock_tests.cpp | 2 +- src/test/rpc_tests.cpp | 2 +- src/test/sanity_tests.cpp | 2 +- src/test/scheduler_tests.cpp | 2 +- src/test/script_p2pk_tests.cpp | 2 +- src/test/script_p2pkh_tests.cpp | 2 +- src/test/script_p2sh_tests.cpp | 2 +- src/test/script_standard_tests.cpp | 2 +- src/test/script_tests.cpp | 2 +- src/test/scriptnum_tests.cpp | 2 +- src/test/serialize_tests.cpp | 2 +- src/test/{test_dash.cpp => setup_common.cpp} | 10 ++- src/test/{test_dash.h => setup_common.h} | 4 +- src/test/sighash_tests.cpp | 2 +- src/test/sigopcount_tests.cpp | 2 +- src/test/skiplist_tests.cpp | 2 +- src/test/streams_tests.cpp | 2 +- src/test/subsidy_tests.cpp | 2 +- src/test/sync_tests.cpp | 2 +- src/test/timedata_tests.cpp | 2 +- src/test/torcontrol_tests.cpp | 2 +- src/test/transaction_tests.cpp | 2 +- src/test/txindex_tests.cpp | 2 +- src/test/txvalidation_tests.cpp | 2 +- src/test/txvalidationcache_tests.cpp | 2 +- src/test/uint256_tests.cpp | 2 +- src/test/util.cpp | 85 ++++++++++++++++++++ src/test/util.h | 34 ++++++++ src/test/util_tests.cpp | 2 +- src/test/util_threadnames_tests.cpp | 2 +- src/test/validation_block_tests.cpp | 2 +- src/test/validation_flush_tests.cpp | 2 +- src/test/validation_tests.cpp | 2 +- src/test/versionbits_tests.cpp | 2 +- src/wallet/test/coinjoin_tests.cpp | 2 +- src/wallet/test/coinselector_tests.cpp | 2 +- src/wallet/test/db_tests.cpp | 2 +- src/wallet/test/init_test_fixture.h | 2 +- src/wallet/test/init_tests.cpp | 2 +- src/wallet/test/psbt_wallet_tests.cpp | 2 +- src/wallet/test/wallet_crypto_tests.cpp | 2 +- src/wallet/test/wallet_test_fixture.h | 2 +- src/wallet/test/wallet_tests.cpp | 2 +- 108 files changed, 248 insertions(+), 245 deletions(-) rename src/test/{test_dash.cpp => setup_common.cpp} (98%) rename src/test/{test_dash.h => setup_common.h} (98%) create mode 100644 src/test/util.cpp create mode 100644 src/test/util.h diff --git a/src/Makefile.bench.include b/src/Makefile.bench.include index bdeafb3226..fa9a73e910 100644 --- a/src/Makefile.bench.include +++ b/src/Makefile.bench.include @@ -41,7 +41,11 @@ bench_bench_dash_SOURCES = \ bench/lockedpool.cpp \ bench/poly1305.cpp \ bench/prevector.cpp \ - bench/string_cast.cpp + bench/string_cast.cpp \ + test/setup_common.cpp \ + test/setup_common.h \ + test/util.cpp \ + test/util.h nodist_bench_bench_dash_SOURCES = $(GENERATED_BENCH_FILES) diff --git a/src/Makefile.qttest.include b/src/Makefile.qttest.include index 302df388ea..f289671288 100644 --- a/src/Makefile.qttest.include +++ b/src/Makefile.qttest.include @@ -36,10 +36,10 @@ TEST_QT_H = \ qt/test/wallettests.h TEST_BITCOIN_CPP = \ - test/test_dash.cpp + test/setup_common.cpp TEST_BITCOIN_H = \ - test/test_dash.h + test/setup_common.h qt_test_test_dash_qt_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BITCOIN_QT_INCLUDES) \ $(QT_INCLUDES) $(QT_TEST_INCLUDES) $(PROTOBUF_CFLAGS) diff --git a/src/Makefile.test.include b/src/Makefile.test.include index 3779336bbd..dea6ce6f09 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -77,12 +77,12 @@ GENERATED_TEST_FILES = $(JSON_TEST_FILES:.json=.json.h) $(RAW_TEST_FILES:.raw=.r BITCOIN_TEST_SUITE = \ test/main.cpp \ - test/test_dash.h \ - test/test_dash.cpp + test/setup_common.h \ + test/setup_common.cpp FUZZ_SUITE = \ - test/test_dash.h \ - test/test_dash.cpp \ + test/setup_common.h \ + test/setup_common.cpp \ test/fuzz/fuzz.cpp \ test/fuzz/fuzz.h diff --git a/src/bench/bench.cpp b/src/bench/bench.cpp index 413494a42c..85fb14220a 100644 --- a/src/bench/bench.cpp +++ b/src/bench/bench.cpp @@ -5,8 +5,14 @@ #include #include +#include #include +#include +#include +#include +#include +#include #include namespace { @@ -47,6 +53,11 @@ void benchmark::BenchRunner::RunAll(const Args& args) std::vector benchmarkResults; for (const auto& p : benchmarks()) { + TestingSetup test{CBaseChainParams::REGTEST}; + { + assert(::ChainActive().Height() == 0); + } + if (!std::regex_match(p.first, baseMatch, reFilter)) { continue; } diff --git a/src/bench/bench_dash.cpp b/src/bench/bench_dash.cpp index a1439fb6ec..7f4a430b0c 100644 --- a/src/bench/bench_dash.cpp +++ b/src/bench/bench_dash.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include @@ -17,20 +16,11 @@ #include -const std::function G_TRANSLATION_FUN = nullptr; - static const char* DEFAULT_BENCH_FILTER = ".*"; void InitBLSTests(); void CleanupBLSTests(); -static fs::path SetDataDir() -{ - fs::path ret = fs::temp_directory_path() / "bench_dash" / fs::unique_path(); - fs::create_directories(ret); - gArgs.ForceSetArg("-datadir", ret.string()); - return ret; -} static void SetupBenchArgs() { gArgs.AddArg("-?", "Print this help message and exit", false, OptionsCategory::OPTIONS); @@ -72,21 +62,6 @@ int main(int argc, char** argv) return EXIT_SUCCESS; } - // Set the datadir after parsing the bench options - const fs::path bench_datadir{SetDataDir()}; - - SHA256AutoDetect(); - - RegisterPrettySignalHandlers(); - RegisterPrettyTerminateHander(); - - ECC_Start(); - ECCVerifyHandle verifyHandle; - - BLSInit(); - InitBLSTests(); - SetupEnvironment(); - benchmark::Args args; args.regex_filter = gArgs.GetArg("-filter", DEFAULT_BENCH_FILTER); args.is_list_only = gArgs.GetBoolArg("-list", false); @@ -96,12 +71,5 @@ int main(int argc, char** argv) benchmark::BenchRunner::RunAll(args); - fs::remove_all(bench_datadir); - - // need to be called before global destructors kick in (PoolAllocator is needed due to many BLSSecretKeys) - CleanupBLSTests(); - - ECC_Stop(); - return EXIT_SUCCESS; } diff --git a/src/bench/block_assemble.cpp b/src/bench/block_assemble.cpp index b78b376ce2..aa31d3e6fe 100644 --- a/src/bench/block_assemble.cpp +++ b/src/bench/block_assemble.cpp @@ -3,58 +3,18 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include -#include -#include -#include #include #include #include -#include -#include -#include -#include #include