Skip to content

Commit 5447097

Browse files
author
MarcoFalke
committed
Merge #18571: fuzz: Disable debug log file
fa69f88 fuzz: Disable debug log file (MarcoFalke) fa0cbd4 test: Add optional extra_args to testing setup (MarcoFalke) fad4fa7 node: Add args alias for gArgs global (MarcoFalke) Pull request description: There are several issues with writing to a debug log file when fuzzing: * Disk access is slow, but fuzzing should be fast (Note: I could not verify this claim with data) * Disks have a limited size and will eventually run out of space, but fuzzing should run continuous Fix both issues by disabling the debug log file for fuzz tests ACKs for top commit: practicalswift: ACK fa69f88 -- patch looks correct Tree-SHA512: f61beb6c94a9ab664deb191685fcad601e228b77bb1c43db6ec40616ae393c9dd35c51474f1b0759ac0bc29b5ca8456a329906a3695bd0f18fa4372210c8b54a
2 parents e84a5f0 + fa69f88 commit 5447097

File tree

10 files changed

+55
-15
lines changed

10 files changed

+55
-15
lines changed

src/bench/bench_bitcoin.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ int main(int argc, char** argv)
7373
gArgs.GetArg("-plot-height", DEFAULT_PLOT_HEIGHT)));
7474
}
7575

76+
gArgs.ClearArgs(); // gArgs no longer needed. Clear it here to avoid interactions with the testing setup in the benches
77+
7678
benchmark::BenchRunner::RunAll(*printer, evaluations, scaling_factor, regex_filter, is_list_only);
7779

7880
return EXIT_SUCCESS;

src/bitcoind.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static bool AppInit(int argc, char* argv[])
5353
// Parameters
5454
//
5555
// If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main()
56-
SetupServerArgs();
56+
SetupServerArgs(node);
5757
std::string error;
5858
if (!gArgs.ParseParameters(argc, argv, error)) {
5959
return InitError(strprintf("Error parsing command line arguments: %s\n", error));

src/init.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ void Shutdown(NodeContext& node)
297297
GetMainSignals().UnregisterBackgroundSignalScheduler();
298298
globalVerifyHandle.reset();
299299
ECC_Stop();
300+
node.args = nullptr;
300301
if (node.mempool) node.mempool = nullptr;
301302
node.scheduler.reset();
302303

@@ -360,8 +361,11 @@ static void OnRPCStopped()
360361
LogPrint(BCLog::RPC, "RPC stopped.\n");
361362
}
362363

363-
void SetupServerArgs()
364+
void SetupServerArgs(NodeContext& node)
364365
{
366+
assert(!node.args);
367+
node.args = &gArgs;
368+
365369
SetupHelpOptions(gArgs);
366370
gArgs.AddArg("-help-debug", "Print help message with debugging options and exit", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); // server-only for now
367371

src/init.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ bool AppInitLockDataDirectory();
5454
bool AppInitMain(NodeContext& node);
5555

5656
/**
57-
* Setup the arguments for gArgs
57+
* Register all arguments with the ArgsManager
5858
*/
59-
void SetupServerArgs();
59+
void SetupServerArgs(NodeContext& node);
6060

6161
/** Returns licensing information (for -version) */
6262
std::string LicenseInfo();

src/interfaces/node.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class NodeImpl : public Node
9797
StopMapPort();
9898
}
9999
}
100-
void setupServerArgs() override { return SetupServerArgs(); }
100+
void setupServerArgs() override { return SetupServerArgs(m_context); }
101101
bool getProxy(Network net, proxyType& proxy_info) override { return GetProxy(net, proxy_info); }
102102
size_t getNodeCount(CConnman::NumConnections flags) override
103103
{

src/node/context.h

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

11+
class ArgsManager;
1112
class BanMan;
1213
class CConnman;
1314
class CScheduler;
@@ -33,6 +34,7 @@ struct NodeContext {
3334
CTxMemPool* mempool{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
3435
std::unique_ptr<PeerLogicValidation> peer_logic;
3536
std::unique_ptr<BanMan> banman;
37+
ArgsManager* args{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
3638
std::unique_ptr<interfaces::Chain> chain;
3739
std::vector<std::unique_ptr<interfaces::ChainClient>> chain_clients;
3840
std::unique_ptr<CScheduler> scheduler;

src/test/fuzz/process_message.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,17 @@ const std::map<std::string, std::set<std::string>> EXPECTED_DESERIALIZATION_EXCE
5757
{"Unknown transaction optional data: iostream error", {"block", "blocktxn", "cmpctblock", "tx"}},
5858
};
5959

60-
const RegTestingSetup* g_setup;
60+
const TestingSetup* g_setup;
6161
} // namespace
6262

6363
void initialize()
6464
{
65-
static RegTestingSetup setup{};
65+
static TestingSetup setup{
66+
CBaseChainParams::REGTEST,
67+
{
68+
"-nodebuglogfile",
69+
},
70+
};
6671
g_setup = &setup;
6772

6873
for (int i = 0; i < 2 * COINBASE_MATURITY; i++) {

src/test/fuzz/process_messages.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@
1616
#include <validation.h>
1717
#include <validationinterface.h>
1818

19-
const RegTestingSetup* g_setup;
19+
const TestingSetup* g_setup;
2020

2121
void initialize()
2222
{
23-
static RegTestingSetup setup{};
23+
static TestingSetup setup{
24+
CBaseChainParams::REGTEST,
25+
{
26+
"-nodebuglogfile",
27+
},
28+
};
2429
g_setup = &setup;
2530

2631
for (int i = 0; i < 2 * COINBASE_MATURITY; i++) {

src/test/util/setup_common.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <util/time.h>
2929
#include <util/translation.h>
3030
#include <util/url.h>
31+
#include <util/vector.h>
3132
#include <validation.h>
3233
#include <validationinterface.h>
3334

@@ -65,17 +66,34 @@ std::ostream& operator<<(std::ostream& os, const uint256& num)
6566
return os;
6667
}
6768

68-
BasicTestingSetup::BasicTestingSetup(const std::string& chainName)
69+
BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::vector<const char*>& extra_args)
6970
: m_path_root{fs::temp_directory_path() / "test_common_" PACKAGE_NAME / g_insecure_rand_ctx_temp_path.rand256().ToString()}
7071
{
72+
const std::vector<const char*> arguments = Cat(
73+
{
74+
"dummy",
75+
"-printtoconsole=0",
76+
"-logtimemicros",
77+
"-debug",
78+
"-debugexclude=libevent",
79+
"-debugexclude=leveldb",
80+
},
81+
extra_args);
7182
fs::create_directories(m_path_root);
7283
gArgs.ForceSetArg("-datadir", m_path_root.string());
7384
ClearDatadirCache();
85+
{
86+
SetupServerArgs(m_node);
87+
std::string error;
88+
const bool success{m_node.args->ParseParameters(arguments.size(), arguments.data(), error)};
89+
assert(success);
90+
assert(error.empty());
91+
}
7492
SelectParams(chainName);
7593
SeedInsecureRand();
76-
gArgs.ForceSetArg("-printtoconsole", "0");
7794
if (G_TEST_LOG_FUN) LogInstance().PushBackCallback(G_TEST_LOG_FUN);
7895
InitLogging();
96+
AppInitParameterInteraction();
7997
LogInstance().StartLogging();
8098
SHA256AutoDetect();
8199
ECC_Start();
@@ -95,10 +113,12 @@ BasicTestingSetup::~BasicTestingSetup()
95113
{
96114
LogInstance().DisconnectTestLogger();
97115
fs::remove_all(m_path_root);
116+
gArgs.ClearArgs();
98117
ECC_Stop();
99118
}
100119

101-
TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(chainName)
120+
TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const char*>& extra_args)
121+
: BasicTestingSetup(chainName, extra_args)
102122
{
103123
const CChainParams& chainparams = Params();
104124
// Ideally we'd move all the RPC tests to the functional testing framework
@@ -159,6 +179,7 @@ TestingSetup::~TestingSetup()
159179
g_rpc_node = nullptr;
160180
m_node.connman.reset();
161181
m_node.banman.reset();
182+
m_node.args = nullptr;
162183
m_node.mempool = nullptr;
163184
m_node.scheduler.reset();
164185
UnloadBlockIndex();

src/test/util/setup_common.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ static constexpr CAmount CENT{1000000};
7373
*/
7474
struct BasicTestingSetup {
7575
ECCVerifyHandle globalVerifyHandle;
76+
NodeContext m_node;
7677

77-
explicit BasicTestingSetup(const std::string& chainName = CBaseChainParams::MAIN);
78+
explicit BasicTestingSetup(const std::string& chainName = CBaseChainParams::MAIN, const std::vector<const char*>& extra_args = {});
7879
~BasicTestingSetup();
80+
7981
private:
8082
const fs::path m_path_root;
8183
};
@@ -84,10 +86,9 @@ struct BasicTestingSetup {
8486
* Included are coins database, script check threads setup.
8587
*/
8688
struct TestingSetup : public BasicTestingSetup {
87-
NodeContext m_node;
8889
boost::thread_group threadGroup;
8990

90-
explicit TestingSetup(const std::string& chainName = CBaseChainParams::MAIN);
91+
explicit TestingSetup(const std::string& chainName = CBaseChainParams::MAIN, const std::vector<const char*>& extra_args = {});
9192
~TestingSetup();
9293
};
9394

0 commit comments

Comments
 (0)