Skip to content

Commit df36ddf

Browse files
author
MarcoFalke
committed
Merge #15504: fuzz: Link BasicTestingSetup (shared with unit tests)
faa9b88 fuzz: Link BasicTestingSetup (shared with unit tests) (MarcoFalke) fa85468 test: Move main_tests to validation_tests (MarcoFalke) fa02b22 test: Remove useless test_bitcoin_main.cpp (MarcoFalke) fab2daa test: Add missing LIBBITCOIN_ZMQ to test_test_bitcoin_LDADD (MarcoFalke) Pull request description: Link against BasicTestingSetup in the fuzz tests, so we can fuzz against validation. Also include a commit to remove test_bitcoin_main.cpp. That file may or may not overwrite globals in the link stage depending on the link order. This is confusing and useless anyway: The unit tests should never `std::exit` in the middle of the run (especially with success as exit code), since it will skip all test modules afterward. Also include a commit to remove some unused forward declarations and move the main_tests to validation_tests, since main was long ago split into net_processing and validation. Tree-SHA512: bdd34c87505450ec106d632f6664aadcbdac7c198172a77da55fab75b274f869ae1a8d06573ba2aff4cb186be9c7a34b7697894ab6f9c82b392f769c9135f36c
2 parents 4952a95 + faa9b88 commit df36ddf

File tree

8 files changed

+83
-325
lines changed

8 files changed

+83
-325
lines changed

build_msvc/test_bitcoin/test_bitcoin.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<ClCompile Include="..\..\src\test\gen\*_gen.cpp" />
2626
<ClCompile Include="..\..\src\wallet\test\*_tests.cpp" />
2727
<ClCompile Include="..\..\src\test\test_bitcoin.cpp" />
28-
<ClCompile Include="..\..\src\test\test_bitcoin_main.cpp" />
28+
<ClCompile Include="..\..\src\test\main.cpp" />
2929
<ClCompile Include="..\..\src\wallet\test\*_fixture.cpp" />
3030
</ItemGroup>
3131
<ItemGroup>

src/Makefile.test.include

Lines changed: 42 additions & 255 deletions
Large diffs are not rendered by default.

src/test/fuzz/fuzz.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#include <vector>
1111

1212

13-
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
14-
1513
void test_one_input(std::vector<uint8_t> buffer);
1614

1715
#endif // BITCOIN_TEST_FUZZ_FUZZ_H

src/test/main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright (c) 2011-2019 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+
5+
#define BOOST_TEST_MODULE Bitcoin Core Test Suite
6+
7+
#include <boost/test/unit_test.hpp>

src/test/test_bitcoin.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -66,36 +66,36 @@ TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(cha
6666
{
6767
SetDataDir("tempdir");
6868
const CChainParams& chainparams = Params();
69-
// Ideally we'd move all the RPC tests to the functional testing framework
70-
// instead of unit tests, but for now we need these here.
71-
72-
RegisterAllCoreRPCCommands(tableRPC);
73-
ClearDatadirCache();
74-
75-
// We have to run a scheduler thread to prevent ActivateBestChain
76-
// from blocking due to queue overrun.
77-
threadGroup.create_thread(std::bind(&CScheduler::serviceQueue, &scheduler));
78-
GetMainSignals().RegisterBackgroundSignalScheduler(scheduler);
79-
80-
mempool.setSanityCheck(1.0);
81-
pblocktree.reset(new CBlockTreeDB(1 << 20, true));
82-
pcoinsdbview.reset(new CCoinsViewDB(1 << 23, true));
83-
pcoinsTip.reset(new CCoinsViewCache(pcoinsdbview.get()));
84-
if (!LoadGenesisBlock(chainparams)) {
85-
throw std::runtime_error("LoadGenesisBlock failed.");
86-
}
87-
{
88-
CValidationState state;
89-
if (!ActivateBestChain(state, chainparams)) {
90-
throw std::runtime_error(strprintf("ActivateBestChain failed. (%s)", FormatStateMessage(state)));
91-
}
92-
}
93-
nScriptCheckThreads = 3;
94-
for (int i=0; i < nScriptCheckThreads-1; i++)
95-
threadGroup.create_thread(&ThreadScriptCheck);
96-
97-
g_banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", nullptr, DEFAULT_MISBEHAVING_BANTIME);
98-
g_connman = MakeUnique<CConnman>(0x1337, 0x1337); // Deterministic randomness for tests.
69+
// Ideally we'd move all the RPC tests to the functional testing framework
70+
// instead of unit tests, but for now we need these here.
71+
72+
RegisterAllCoreRPCCommands(tableRPC);
73+
ClearDatadirCache();
74+
75+
// We have to run a scheduler thread to prevent ActivateBestChain
76+
// from blocking due to queue overrun.
77+
threadGroup.create_thread(std::bind(&CScheduler::serviceQueue, &scheduler));
78+
GetMainSignals().RegisterBackgroundSignalScheduler(scheduler);
79+
80+
mempool.setSanityCheck(1.0);
81+
pblocktree.reset(new CBlockTreeDB(1 << 20, true));
82+
pcoinsdbview.reset(new CCoinsViewDB(1 << 23, true));
83+
pcoinsTip.reset(new CCoinsViewCache(pcoinsdbview.get()));
84+
if (!LoadGenesisBlock(chainparams)) {
85+
throw std::runtime_error("LoadGenesisBlock failed.");
86+
}
87+
88+
CValidationState state;
89+
if (!ActivateBestChain(state, chainparams)) {
90+
throw std::runtime_error(strprintf("ActivateBestChain failed. (%s)", FormatStateMessage(state)));
91+
}
92+
93+
nScriptCheckThreads = 3;
94+
for (int i = 0; i < nScriptCheckThreads - 1; i++)
95+
threadGroup.create_thread(&ThreadScriptCheck);
96+
97+
g_banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", nullptr, DEFAULT_MISBEHAVING_BANTIME);
98+
g_connman = MakeUnique<CConnman>(0x1337, 0x1337); // Deterministic randomness for tests.
9999
}
100100

101101
TestingSetup::~TestingSetup()

src/test/test_bitcoin.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ struct BasicTestingSetup {
7171
/** Testing setup that configures a complete environment.
7272
* Included are data directory, coins database, script check threads setup.
7373
*/
74-
class CConnman;
75-
class CNode;
76-
77-
class PeerLogicValidation;
7874
struct TestingSetup : public BasicTestingSetup {
7975
boost::thread_group threadGroup;
8076
CScheduler scheduler;

src/test/test_bitcoin_main.cpp

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/test/main_tests.cpp renamed to src/test/validation_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
// Copyright (c) 2014-2018 The Bitcoin Core developers
1+
// Copyright (c) 2014-2019 The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <chainparams.h>
6-
#include <validation.h>
76
#include <net.h>
7+
#include <validation.h>
88

99
#include <test/test_bitcoin.h>
1010

1111
#include <boost/signals2/signal.hpp>
1212
#include <boost/test/unit_test.hpp>
1313

14-
BOOST_FIXTURE_TEST_SUITE(main_tests, TestingSetup)
14+
BOOST_FIXTURE_TEST_SUITE(validation_tests, TestingSetup)
1515

1616
static void TestBlockSubsidyHalvings(const Consensus::Params& consensusParams)
1717
{

0 commit comments

Comments
 (0)