Skip to content

Commit fa0cbd4

Browse files
author
MarcoFalke
committed
test: Add optional extra_args to testing setup
1 parent fad4fa7 commit fa0cbd4

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
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/test/util/setup_common.cpp

Lines changed: 23 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

src/test/util/setup_common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct BasicTestingSetup {
7575
ECCVerifyHandle globalVerifyHandle;
7676
NodeContext m_node;
7777

78-
explicit BasicTestingSetup(const std::string& chainName = CBaseChainParams::MAIN);
78+
explicit BasicTestingSetup(const std::string& chainName = CBaseChainParams::MAIN, const std::vector<const char*>& extra_args = {});
7979
~BasicTestingSetup();
8080

8181
private:
@@ -88,7 +88,7 @@ struct BasicTestingSetup {
8888
struct TestingSetup : public BasicTestingSetup {
8989
boost::thread_group threadGroup;
9090

91-
explicit TestingSetup(const std::string& chainName = CBaseChainParams::MAIN);
91+
explicit TestingSetup(const std::string& chainName = CBaseChainParams::MAIN, const std::vector<const char*>& extra_args = {});
9292
~TestingSetup();
9393
};
9494

0 commit comments

Comments
 (0)