Merge #13663: tests: Avoid read/write to default datadir

fa43a4138b bench_bitcoin: Avoid read/write to default datadir (MarcoFalke)
ea80b81e2e test_bitcoin: Avoid read/write to default datadir (MarcoFalke)

Pull request description:

  tests should never read or write and potentially corrupt the default datadir, so try to avoid it.

Tree-SHA512: ee446ff4bf59da2aed38c2e4758581d6103e9d4c35a118497e9ec21d566ba33d913e160c2d7ba2ea6f937f000343ecea3816154bd87ee47f64f5b0cf9e88f6e0
pull/13687/head
MarcoFalke 6 years ago
commit cbc9b50734
No known key found for this signature in database
GPG Key ID: D2EA4850E7528B25

@ -38,6 +38,14 @@ static void SetupBenchArgs()
gArgs.AddArg("-help", "", false, OptionsCategory::HIDDEN);
}
static fs::path SetDataDir()
{
fs::path ret = fs::temp_directory_path() / "bench_bitcoin" / fs::unique_path();
fs::create_directories(ret);
gArgs.ForceSetArg("-datadir", ret.string());
return ret;
}
int main(int argc, char** argv)
{
SetupBenchArgs();
@ -53,6 +61,9 @@ int main(int argc, char** argv)
return EXIT_SUCCESS;
}
// Set the datadir after parsing the bench options
const fs::path bench_datadir{SetDataDir()};
SHA256AutoDetect();
RandomInit();
ECC_Start();
@ -80,6 +91,8 @@ int main(int argc, char** argv)
benchmark::BenchRunner::RunAll(*printer, evaluations, scaling_factor, regex_filter, is_list_only);
fs::remove_all(bench_datadir);
ECC_Stop();
return EXIT_SUCCESS;

@ -89,6 +89,7 @@ BOOST_AUTO_TEST_CASE(cnode_listen_port)
BOOST_AUTO_TEST_CASE(caddrdb_read)
{
SetDataDir("caddrdb_read");
CAddrManUncorrupted addrmanUncorrupted;
addrmanUncorrupted.MakeDeterministic();
@ -134,6 +135,7 @@ BOOST_AUTO_TEST_CASE(caddrdb_read)
BOOST_AUTO_TEST_CASE(caddrdb_read_corrupted)
{
SetDataDir("caddrdb_read_corrupted");
CAddrManCorrupted addrmanCorrupted;
addrmanCorrupted.MakeDeterministic();

Loading…
Cancel
Save