Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14864930
D5493.id17046.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Subscribers
None
D5493.id17046.diff
View Options
diff --git a/src/Makefile.bench.include b/src/Makefile.bench.include
--- a/src/Makefile.bench.include
+++ b/src/Makefile.bench.include
@@ -31,13 +31,16 @@
bench/util_time.cpp \
bench/base58.cpp \
bench/lockedpool.cpp \
- bench/prevector.cpp
+ bench/prevector.cpp \
+ test/test_bitcoin.h \
+ test/test_bitcoin.cpp
nodist_bench_bench_bitcoin_SOURCES = $(GENERATED_BENCH_FILES)
bench_bench_bitcoin_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CLFAGS) $(EVENT_PTHREADS_CFLAGS) -I$(builddir)/bench/
bench_bench_bitcoin_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
bench_bench_bitcoin_LDADD = \
+ $(LIBBITCOIN_SERVER) \
$(LIBBITCOIN_WALLET) \
$(LIBBITCOIN_SERVER) \
$(LIBBITCOIN_COMMON) \
diff --git a/src/bench/CMakeLists.txt b/src/bench/CMakeLists.txt
--- a/src/bench/CMakeLists.txt
+++ b/src/bench/CMakeLists.txt
@@ -54,6 +54,9 @@
rpc_mempool.cpp
util_time.cpp
+ # TODO: make a test library
+ ../test/test_bitcoin.cpp
+
# Add the generated headers to trigger the conversion command
${BENCH_DATA_GENERATED_HEADERS}
)
diff --git a/src/bench/bench.cpp b/src/bench/bench.cpp
--- a/src/bench/bench.cpp
+++ b/src/bench/bench.cpp
@@ -4,6 +4,11 @@
#include <bench/bench.h>
+#include <chainparams.h>
+#include <validation.h>
+
+#include <test/test_bitcoin.h>
+
#include <algorithm>
#include <cassert>
#include <iomanip>
@@ -110,6 +115,9 @@
printer.header();
for (const auto &p : benchmarks()) {
+ TestingSetup test{CBaseChainParams::REGTEST};
+ assert(::ChainActive().Height() == 0);
+
if (!std::regex_match(p.first, baseMatch, reFilter)) {
continue;
}
diff --git a/src/bench/bench_bitcoin.cpp b/src/bench/bench_bitcoin.cpp
--- a/src/bench/bench_bitcoin.cpp
+++ b/src/bench/bench_bitcoin.cpp
@@ -8,12 +8,9 @@
#include <key.h>
#include <util/strencodings.h>
#include <util/system.h>
-#include <validation.h>
#include <memory>
-const std::function<std::string(const char *)> G_TRANSLATION_FUN = nullptr;
-
static const int64_t DEFAULT_BENCH_EVALUATIONS = 5;
static const char *DEFAULT_BENCH_FILTER = ".*";
static const char *DEFAULT_BENCH_SCALING = "1.0";
@@ -69,14 +66,6 @@
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();
std::string error;
@@ -91,13 +80,6 @@
return EXIT_SUCCESS;
}
- // Set the datadir after parsing the bench options
- const fs::path bench_datadir{SetDataDir()};
-
- SHA256AutoDetect();
- ECC_Start();
- SetupEnvironment();
-
int64_t evaluations = gArgs.GetArg("-evals", DEFAULT_BENCH_EVALUATIONS);
std::string regex_filter = gArgs.GetArg("-filter", DEFAULT_BENCH_FILTER);
std::string scaling_str = gArgs.GetArg("-scaling", DEFAULT_BENCH_SCALING);
@@ -123,9 +105,5 @@
benchmark::BenchRunner::RunAll(*printer, evaluations, scaling_factor,
regex_filter, is_list_only);
- fs::remove_all(bench_datadir);
-
- ECC_Stop();
-
return EXIT_SUCCESS;
}
diff --git a/src/bench/duplicate_inputs.cpp b/src/bench/duplicate_inputs.cpp
--- a/src/bench/duplicate_inputs.cpp
+++ b/src/bench/duplicate_inputs.cpp
@@ -12,46 +12,18 @@
#include <miner.h>
#include <policy/policy.h>
#include <pow.h>
-#include <scheduler.h>
#include <script/scriptcache.h>
-#include <txdb.h>
#include <txmempool.h>
-#include <util/time.h>
#include <validation.h>
#include <validationinterface.h>
-#include <boost/thread.hpp>
-
#include <list>
#include <vector>
static void DuplicateInputs(benchmark::State &state) {
const CScript SCRIPT_PUB{CScript(OP_TRUE)};
- // Switch to regtest so we can mine faster
- SelectParams(CBaseChainParams::REGTEST);
- const Config &config = GetConfig();
-
- InitScriptExecutionCache();
-
- boost::thread_group thread_group;
- CScheduler scheduler;
- const CChainParams &chainparams = config.GetChainParams();
- {
- LOCK(cs_main);
- ::pblocktree.reset(new CBlockTreeDB(1 << 20, true));
- ::pcoinsdbview.reset(new CCoinsViewDB(1 << 23, true));
- ::pcoinsTip.reset(new CCoinsViewCache(pcoinsdbview.get()));
- }
- {
- thread_group.create_thread(
- std::bind(&CScheduler::serviceQueue, &scheduler));
- GetMainSignals().RegisterBackgroundSignalScheduler(scheduler);
- LoadGenesisBlock(chainparams);
- CValidationState cvstate;
- ActivateBestChain(config, cvstate);
- assert(::ChainActive().Tip() != nullptr);
- }
+ const CChainParams &chainparams = Params();
CBlock block{};
CMutableTransaction coinbaseTx{};
@@ -92,16 +64,11 @@
while (state.KeepRunning()) {
CValidationState cvstate{};
assert(!CheckBlock(block, cvstate, chainparams.GetConsensus(),
- BlockValidationOptions(config)
+ BlockValidationOptions(GetConfig())
.withCheckPoW(false)
.withCheckMerkleRoot(false)));
assert(cvstate.GetRejectReason() == "bad-txns-inputs-duplicate");
}
-
- thread_group.interrupt_all();
- thread_group.join_all();
- GetMainSignals().FlushBackgroundCallbacks();
- GetMainSignals().UnregisterBackgroundSignalScheduler();
}
BENCHMARK(DuplicateInputs, 10);
diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp
--- a/src/test/test_bitcoin.cpp
+++ b/src/test/test_bitcoin.cpp
@@ -48,7 +48,7 @@
}
BasicTestingSetup::BasicTestingSetup(const std::string &chainName)
- : m_path_root(fs::temp_directory_path() / "test_bitcoin" /
+ : m_path_root(fs::temp_directory_path() / "test_common_" PACKAGE_NAME /
strprintf("%lu_%i", static_cast<unsigned long>(GetTime()),
int(InsecureRandRange(1 << 30)))) {
SHA256AutoDetect();
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, May 20, 23:24 (10 m, 3 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5864519
Default Alt Text
D5493.id17046.diff (5 KB)
Attached To
D5493: test: Use test_bitcoin setup in bench
Event Timeline
Log In to Comment