mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
test: Avoid script check worker threads while fuzzing
Threads may execute their function any time after they are spawned, so coverage could be non-deterministic. Fix this, * for the script check worker threads by disabling them while fuzzing. * for the scheduler thread by waiting for it to fully start and run the service queue.
This commit is contained in:
parent
fa900bb2dc
commit
fa17cdb191
1 changed files with 9 additions and 1 deletions
|
@ -60,6 +60,7 @@
|
|||
#include <walletinitinterface.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <future>
|
||||
#include <functional>
|
||||
#include <stdexcept>
|
||||
|
||||
|
@ -230,6 +231,12 @@ ChainTestingSetup::ChainTestingSetup(const ChainType chainType, TestOpts opts)
|
|||
// Use synchronous task runner while fuzzing to avoid non-determinism
|
||||
G_FUZZING ? std::make_unique<ValidationSignals>(std::make_unique<util::ImmediateTaskRunner>()) :
|
||||
std::make_unique<ValidationSignals>(std::make_unique<SerialTaskRunner>(*m_node.scheduler));
|
||||
{
|
||||
// Ensure deterministic coverage by waiting for m_service_thread to be running
|
||||
std::promise<void> promise;
|
||||
m_node.scheduler->scheduleFromNow([&promise] { promise.set_value(); }, 0ms);
|
||||
promise.get_future().wait();
|
||||
}
|
||||
}
|
||||
|
||||
bilingual_str error{};
|
||||
|
@ -247,7 +254,8 @@ ChainTestingSetup::ChainTestingSetup(const ChainType chainType, TestOpts opts)
|
|||
.check_block_index = 1,
|
||||
.notifications = *m_node.notifications,
|
||||
.signals = m_node.validation_signals.get(),
|
||||
.worker_threads_num = 2,
|
||||
// Use no worker threads while fuzzing to avoid non-determinism
|
||||
.worker_threads_num = G_FUZZING ? 0 : 2,
|
||||
};
|
||||
if (opts.min_validation_cache) {
|
||||
chainman_opts.script_execution_cache_bytes = 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue