Skip to content

Commit

Permalink
Merge bitcoin#15788: test: Unify testing setups for fuzz, bench, and …
Browse files Browse the repository at this point in the history
…unit tests

faf4000 scripted-diff: Bump copyright headers in test, bench (MarcoFalke)
fa82190 scripted-diff: Rename test_bitcoin to test/setup_common (MarcoFalke)
fa8685d test: Use test_bitcoin setup in bench, Add test utils (MarcoFalke)
666696b test: Have segwit always active in (Basic)TestingSetup (MarcoFalke)

Pull request description:

  Now that the fuzz tests can use the BasicTestingSetup [1], do the same for bench.

  Also move some duplicate code to a common "test/util" module.

  [1]:  fuzz: Link BasicTestingSetup (shared with unit tests) bitcoin#15504

ACKs for commit faf400:
  jonatack:
    ACK bitcoin@faf4000

Tree-SHA512: 8ac5692e72cf50e460958f291643ae6b8bb04d5c1331ed50dce9eb4e9457e5a925144c532c42b360a26707e11eeece74aab27db8c76ab9a429b9dd7167e7cdc4

# Conflicts:
#	build_msvc/bench_bitcoin/bench_bitcoin.vcxproj
#	build_msvc/test_bitcoin/test_bitcoin.vcxproj
#	src/Makefile.bench.include
#	src/Makefile.qttest.include
#	src/Makefile.test.include
#	src/bench/bench.cpp
#	src/bench/bench_bitcoin.cpp
#	src/bench/block_assemble.cpp
#	src/bench/duplicate_inputs.cpp
#	src/qt/test/addressbooktests.cpp
#	src/qt/test/rpcnestedtests.cpp
#	src/qt/test/wallettests.cpp
#	src/test/README.md
#	src/test/addrman_tests.cpp
#	src/test/allocator_tests.cpp
#	src/test/amount_tests.cpp
#	src/test/arith_uint256_tests.cpp
#	src/test/base32_tests.cpp
#	src/test/base58_tests.cpp
#	src/test/base64_tests.cpp
#	src/test/bech32_tests.cpp
#	src/test/bip32_tests.cpp
#	src/test/blockchain_tests.cpp
#	src/test/blockencodings_tests.cpp
#	src/test/blockfilter_tests.cpp
#	src/test/bloom_tests.cpp
#	src/test/bswap_tests.cpp
#	src/test/checkqueue_tests.cpp
#	src/test/coins_tests.cpp
#	src/test/compress_tests.cpp
#	src/test/crypto_tests.cpp
#	src/test/cuckoocache_tests.cpp
#	src/test/dbwrapper_tests.cpp
#	src/test/denialofservice_tests.cpp
#	src/test/descriptor_tests.cpp
#	src/test/flatfile_tests.cpp
#	src/test/fs_tests.cpp
#	src/test/getarg_tests.cpp
#	src/test/hash_tests.cpp
#	src/test/key_io_tests.cpp
#	src/test/key_properties.cpp
#	src/test/key_tests.cpp
#	src/test/limitedmap_tests.cpp
#	src/test/mempool_tests.cpp
#	src/test/merkle_tests.cpp
#	src/test/merkleblock_tests.cpp
#	src/test/miner_tests.cpp
#	src/test/multisig_tests.cpp
#	src/test/net_tests.cpp
#	src/test/netbase_tests.cpp
#	src/test/pmt_tests.cpp
#	src/test/policyestimator_tests.cpp
#	src/test/pow_tests.cpp
#	src/test/prevector_tests.cpp
#	src/test/raii_event_tests.cpp
#	src/test/random_tests.cpp
#	src/test/reverselock_tests.cpp
#	src/test/rpc_tests.cpp
#	src/test/sanity_tests.cpp
#	src/test/scheduler_tests.cpp
#	src/test/script_p2sh_tests.cpp
#	src/test/script_standard_tests.cpp
#	src/test/script_tests.cpp
#	src/test/scriptnum_tests.cpp
#	src/test/serialize_tests.cpp
#	src/test/setup_common.cpp
#	src/test/setup_common.h
#	src/test/sighash_tests.cpp
#	src/test/sigopcount_tests.cpp
#	src/test/skiplist_tests.cpp
#	src/test/streams_tests.cpp
#	src/test/sync_tests.cpp
#	src/test/test_bitcoin.cpp
#	src/test/test_bitcoin.h
#	src/test/test_dash.cpp
#	src/test/test_dash.h
#	src/test/timedata_tests.cpp
#	src/test/torcontrol_tests.cpp
#	src/test/transaction_tests.cpp
#	src/test/txindex_tests.cpp
#	src/test/txvalidation_tests.cpp
#	src/test/txvalidationcache_tests.cpp
#	src/test/uint256_tests.cpp
#	src/test/util_tests.cpp
#	src/test/validation_block_tests.cpp
#	src/test/validation_tests.cpp
#	src/test/versionbits_tests.cpp
#	src/wallet/test/coinselector_tests.cpp
#	src/wallet/test/db_tests.cpp
#	src/wallet/test/init_test_fixture.h
#	src/wallet/test/init_tests.cpp
#	src/wallet/test/psbt_wallet_tests.cpp
#	src/wallet/test/wallet_crypto_tests.cpp
#	src/wallet/test/wallet_test_fixture.h
#	src/wallet/test/wallet_tests.cpp
  • Loading branch information
MarcoFalke authored and Munkybooty committed Oct 7, 2021
1 parent 2a1ae63 commit 77ed0cb
Show file tree
Hide file tree
Showing 86 changed files with 314 additions and 148 deletions.
7 changes: 6 additions & 1 deletion src/Makefile.bench.include
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ bench_bench_dash_SOURCES = \
bench/lockedpool.cpp \
bench/poly1305.cpp \
bench/prevector.cpp \
bench/string_cast.cpp
bench/string_cast.cpp\
bench/prevector.cpp \
test/setup_common.h \
test/setup_common.cpp \
test/util.h \
test/util.cpp

nodist_bench_bench_dash_SOURCES = $(GENERATED_BENCH_FILES)

Expand Down
4 changes: 2 additions & 2 deletions src/Makefile.qttest.include
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 12 additions & 1 deletion src/bench/bench.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2015 The Bitcoin Core developers
// Copyright (c) 2015-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

Expand All @@ -7,6 +7,10 @@
#include <chainparams.h>
#include <validation.h>

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <regex>

namespace {
Expand Down Expand Up @@ -47,6 +51,13 @@ void benchmark::BenchRunner::RunAll(const Args& args)

std::vector<ankerl::nanobench::Result> benchmarkResults;
for (const auto& p : benchmarks()) {
TestingSetup test{CBaseChainParams::REGTEST};
{
assert(::chainActive.Height() == 0);
const bool witness_enabled{IsWitnessEnabled(::chainActive.Tip(), Params().GetConsensus())};
assert(witness_enabled);
}

if (!std::regex_match(p.first, baseMatch, reFilter)) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/qt/test/addressbooktests.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <qt/test/addressbooktests.h>
#include <qt/test/util.h>
#include <test/test_dash.h>
#include <test/setup_common.h>

#include <interfaces/node.h>
#include <qt/addressbookpage.h>
Expand Down
2 changes: 1 addition & 1 deletion src/qt/test/rpcnestedtests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <rpc/register.h>
#include <rpc/server.h>
#include <qt/rpcconsole.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <univalue.h>
#include <util/system.h>

Expand Down
2 changes: 1 addition & 1 deletion src/qt/test/wallettests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <qt/transactionview.h>
#include <qt/walletmodel.h>
#include <key_io.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <validation.h>
#include <wallet/wallet.h>
#include <qt/overviewpage.h>
Expand Down
2 changes: 1 addition & 1 deletion src/test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ unit tests as possible).

The build system is setup to compile an executable called `test_dash`
that runs all of the unit tests. The main source file is called
test_dash.cpp. To add a new unit test file to our test suite you need
setup_common.cpp. To add a new unit test file to our test suite you need
to add the file to `src/Makefile.test.include`. The pattern is to create
one test file for each class or source file for which you want to create
unit tests. The file naming convention is `<source_filename>_tests.cpp`
Expand Down
4 changes: 2 additions & 2 deletions src/test/addrman_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) 2012-2015 The Bitcoin Core developers
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <addrman.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <string>
#include <boost/test/unit_test.hpp>
#include <util/asmap.h>
Expand Down
4 changes: 2 additions & 2 deletions src/test/allocator_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) 2012-2015 The Bitcoin Core developers
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <util/system.h>

#include <support/allocators/secure.h>
#include <test/test_dash.h>
#include <test/setup_common.h>

#include <memory>

Expand Down
4 changes: 2 additions & 2 deletions src/test/amount_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) 2016 The Bitcoin Core developers
// Copyright (c) 2016-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <amount.h>
#include <policy/feerate.h>
#include <test/test_dash.h>
#include <test/setup_common.h>

#include <boost/test/unit_test.hpp>

Expand Down
4 changes: 2 additions & 2 deletions src/test/arith_uint256_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2011-2015 The Bitcoin Core developers
// Copyright (c) 2011-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

Expand All @@ -12,7 +12,7 @@
#include <arith_uint256.h>
#include <string>
#include <version.h>
#include <test/test_dash.h>
#include <test/setup_common.h>

BOOST_FIXTURE_TEST_SUITE(arith_uint256_tests, BasicTestingSetup)

Expand Down
4 changes: 2 additions & 2 deletions src/test/base32_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) 2012-2015 The Bitcoin Core developers
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <util/strencodings.h>
#include <test/test_dash.h>
#include <test/setup_common.h>

#include <boost/test/unit_test.hpp>

Expand Down
4 changes: 2 additions & 2 deletions src/test/base58_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) 2011-2015 The Bitcoin Core developers
// Copyright (c) 2011-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <test/data/base58_encode_decode.json.h>

#include <base58.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <util/strencodings.h>

#include <univalue.h>
Expand Down
4 changes: 2 additions & 2 deletions src/test/base64_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) 2011-2015 The Bitcoin Core developers
// Copyright (c) 2011-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <util/strencodings.h>
#include <test/test_dash.h>
#include <test/setup_common.h>

#include <boost/test/unit_test.hpp>

Expand Down
2 changes: 1 addition & 1 deletion src/test/bech32_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <bech32.h>
#include <test/test_dash.h>
#include <test/setup_common.h>

#include <boost/test/unit_test.hpp>

Expand Down
4 changes: 2 additions & 2 deletions src/test/bip32_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2013-2015 The Bitcoin Core developers
// Copyright (c) 2013-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

Expand All @@ -9,7 +9,7 @@
#include <uint256.h>
#include <util/system.h>
#include <util/strencodings.h>
#include <test/test_dash.h>
#include <test/setup_common.h>

#include <string>
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion src/test/blockchain_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <stdlib.h>

#include <rpc/blockchain.h>
#include <test/test_dash.h>
#include <test/setup_common.h>

/* Equality between doubles is imprecise. Comparison should be done
* with a small threshold of tolerance, rather than exact equality.
Expand Down
4 changes: 2 additions & 2 deletions src/test/blockencodings_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2011-2015 The Bitcoin Core developers
// Copyright (c) 2011-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

Expand All @@ -8,7 +8,7 @@
#include <pow.h>
#include <random.h>

#include <test/test_dash.h>
#include <test/setup_common.h>

#include <boost/test/unit_test.hpp>

Expand Down
4 changes: 2 additions & 2 deletions src/test/blockfilter_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) 2018 The Bitcoin Core developers
// Copyright (c) 2018-2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <test/data/blockfilters.json.h>
#include <test/test_dash.h>
#include <test/setup_common.h>

#include <blockfilter.h>
#include <core_io.h>
Expand Down
4 changes: 2 additions & 2 deletions src/test/bloom_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2012-2015 The Bitcoin Core developers
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

Expand All @@ -15,7 +15,7 @@
#include <uint256.h>
#include <util/system.h>
#include <util/strencodings.h>
#include <test/test_dash.h>
#include <test/setup_common.h>

#include <vector>

Expand Down
4 changes: 2 additions & 2 deletions src/test/bswap_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) 2016 The Bitcoin Core developers
// Copyright (c) 2016-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <compat/byteswap.h>
#include <test/test_dash.h>
#include <test/setup_common.h>

#include <boost/test/unit_test.hpp>

Expand Down
4 changes: 2 additions & 2 deletions src/test/checkqueue_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) 2012-2017 The Bitcoin Core developers
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <sync.h>
#include <util/system.h>
#include <util/time.h>

#include <test/test_dash.h>
#include <test/setup_common.h>
#include <checkqueue.h>
#include <boost/test/unit_test.hpp>
#include <boost/thread.hpp>
Expand Down
4 changes: 2 additions & 2 deletions src/test/coins_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) 2014-2015 The Bitcoin Core developers
// Copyright (c) 2014-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <attributes.h>
#include <coins.h>
#include <consensus/validation.h>
#include <script/standard.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <uint256.h>
#include <undo.h>
#include <util/strencodings.h>
Expand Down
4 changes: 2 additions & 2 deletions src/test/compress_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) 2012-2015 The Bitcoin Core developers
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <compressor.h>
#include <util/system.h>
#include <test/test_dash.h>
#include <test/setup_common.h>

#include <stdint.h>

Expand Down
4 changes: 2 additions & 2 deletions src/test/crypto_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2014-2015 The Bitcoin Core developers
// Copyright (c) 2014-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

Expand All @@ -16,7 +16,7 @@
#include <crypto/sha512.h>
#include <random.h>
#include <util/strencodings.h>
#include <test/test_dash.h>
#include <test/setup_common.h>

#include <vector>

Expand Down
4 changes: 2 additions & 2 deletions src/test/cuckoocache_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) 2012-2016 The Bitcoin Core developers
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <cuckoocache.h>
#include <script/sigcache.h>
#include <test/test_dash.h>
#include <test/setup_common.h>
#include <random.h>

#include <boost/test/unit_test.hpp>
Expand Down
4 changes: 2 additions & 2 deletions src/test/dbwrapper_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) 2012-2015 The Bitcoin Core developers
// Copyright (c) 2012-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <dbwrapper.h>
#include <uint256.h>
#include <random.h>
#include <test/test_dash.h>
#include <test/setup_common.h>

#include <memory>

Expand Down
4 changes: 2 additions & 2 deletions src/test/denialofservice_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2011-2015 The Bitcoin Core developers
// Copyright (c) 2011-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

Expand All @@ -15,7 +15,7 @@
#include <util/system.h>
#include <validation.h>

#include <test/test_dash.h>
#include <test/setup_common.h>

#include <stdint.h>

Expand Down
Loading

0 comments on commit 77ed0cb

Please sign in to comment.