Skip to content

Commit

Permalink
test: Add optional extra_args to testing setup
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoFalke committed Apr 15, 2020
1 parent fad4fa7 commit fa0cbd4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/bench/bench_bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ int main(int argc, char** argv)
gArgs.GetArg("-plot-height", DEFAULT_PLOT_HEIGHT)));
}

gArgs.ClearArgs(); // gArgs no longer needed. Clear it here to avoid interactions with the testing setup in the benches

benchmark::BenchRunner::RunAll(*printer, evaluations, scaling_factor, regex_filter, is_list_only);

return EXIT_SUCCESS;
Expand Down
26 changes: 23 additions & 3 deletions src/test/util/setup_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <util/time.h>
#include <util/translation.h>
#include <util/url.h>
#include <util/vector.h>
#include <validation.h>
#include <validationinterface.h>

Expand Down Expand Up @@ -65,17 +66,34 @@ std::ostream& operator<<(std::ostream& os, const uint256& num)
return os;
}

BasicTestingSetup::BasicTestingSetup(const std::string& chainName)
BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::vector<const char*>& extra_args)
: m_path_root{fs::temp_directory_path() / "test_common_" PACKAGE_NAME / g_insecure_rand_ctx_temp_path.rand256().ToString()}
{
const std::vector<const char*> arguments = Cat(
{
"dummy",
"-printtoconsole=0",
"-logtimemicros",
"-debug",
"-debugexclude=libevent",
"-debugexclude=leveldb",
},
extra_args);
fs::create_directories(m_path_root);
gArgs.ForceSetArg("-datadir", m_path_root.string());
ClearDatadirCache();
{
SetupServerArgs(m_node);
std::string error;
const bool success{m_node.args->ParseParameters(arguments.size(), arguments.data(), error)};
assert(success);
assert(error.empty());
}
SelectParams(chainName);
SeedInsecureRand();
gArgs.ForceSetArg("-printtoconsole", "0");
if (G_TEST_LOG_FUN) LogInstance().PushBackCallback(G_TEST_LOG_FUN);
InitLogging();
AppInitParameterInteraction();
LogInstance().StartLogging();
SHA256AutoDetect();
ECC_Start();
Expand All @@ -95,10 +113,12 @@ BasicTestingSetup::~BasicTestingSetup()
{
LogInstance().DisconnectTestLogger();
fs::remove_all(m_path_root);
gArgs.ClearArgs();
ECC_Stop();
}

TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(chainName)
TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const char*>& extra_args)
: BasicTestingSetup(chainName, extra_args)
{
const CChainParams& chainparams = Params();
// Ideally we'd move all the RPC tests to the functional testing framework
Expand Down
4 changes: 2 additions & 2 deletions src/test/util/setup_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct BasicTestingSetup {
ECCVerifyHandle globalVerifyHandle;
NodeContext m_node;

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

private:
Expand All @@ -88,7 +88,7 @@ struct BasicTestingSetup {
struct TestingSetup : public BasicTestingSetup {
boost::thread_group threadGroup;

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

Expand Down

0 comments on commit fa0cbd4

Please sign in to comment.