MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / BasicTestingSetup

Method BasicTestingSetup

src/test/util/setup_common.cpp:142–249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

140}
141
142BasicTestingSetup::BasicTestingSetup(const ChainType chainType, TestOpts opts)
143 : m_args{}
144{
145 if (!EnableFuzzDeterminism()) {
146 SeedRandomForTest(SeedRand::FIXED_SEED);
147 }
148
149 // Reset globals
150 fDiscover = true;
151 fListen = true;
152 SetRPCWarmupStarting();
153 g_reachable_nets.Reset();
154 ClearLocal();
155
156 m_node.shutdown_signal = &m_interrupt;
157 m_node.shutdown_request = [this]{ return m_interrupt(); };
158 m_node.args = &gArgs;
159 std::vector<const char*> arguments = Cat(
160 {
161 "dummy",
162 "-printtoconsole=0",
163 "-logsourcelocations",
164 "-logtimemicros",
165 "-logthreadnames",
166 "-loglevel=trace",
167 "-debug",
168 "-debugexclude=leveldb",
169 },
170 opts.extra_args);
171 if (G_TEST_COMMAND_LINE_ARGUMENTS) {
172 arguments = Cat(arguments, G_TEST_COMMAND_LINE_ARGUMENTS());
173 }
174 util::ThreadRename("test");
175 gArgs.ClearPathCache();
176 {
177 SetupServerArgs(*m_node.args);
178 SetupCommonTestArgs(*m_node.args);
179 std::string error;
180 if (!m_node.args->ParseParameters(arguments.size(), arguments.data(), error)) {
181 m_node.args->ClearArgs();
182 throw std::runtime_error{error};
183 }
184 }
185
186 const std::string test_name{G_TEST_GET_FULL_NAME ? G_TEST_GET_FULL_NAME() : ""};
187 if (!m_node.args->IsArgSet("-testdatadir")) {
188 // To avoid colliding with a leftover prior datadir, and to allow
189 // tests, such as the fuzz tests to run in several processes at the
190 // same time, add a random element to the path. Keep it small enough to
191 // avoid a MAX_PATH violation on Windows.
192 //
193 // When fuzzing with AFL++, use the shared memory ID for a deterministic
194 // path. This allows for cleanup of leftover directories from timed-out
195 // or crashed iterations, preventing accumulation of stale datadirs.
196 if (const char* shm_id = std::getenv("__AFL_SHM_ID"); shm_id && *shm_id) {
197 m_path_root = fs::temp_directory_path() / TEST_DIR_PATH_ELEMENT / test_name / shm_id;
198 fs::remove_all(m_path_root);
199 } else {

Callers

nothing calls this directly

Calls 15

EnableFuzzDeterminismFunction · 0.85
SetRPCWarmupStartingFunction · 0.85
ClearLocalFunction · 0.85
CatFunction · 0.85
SetupServerArgsFunction · 0.85
SetupCommonTestArgsFunction · 0.85
TryCreateDirectoriesFunction · 0.85
ExitFailureFunction · 0.85
absoluteFunction · 0.85
PathFromStringFunction · 0.85
PathToStringFunction · 0.85
SelectParamsFunction · 0.85

Tested by

no test coverage detected