22// Distributed under the MIT software license, see the accompanying
33// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44
5- #include < config/bitcoin-config.h> // IWYU pragma: keep
6-
75#include < test/util/setup_common.h>
86
97#include < addrman.h>
@@ -75,6 +73,7 @@ using node::VerifyLoadedChainstate;
7573
7674const std::function<std::string(const char *)> G_TRANSLATION_FUN = nullptr ;
7775
76+ constexpr inline auto TEST_DIR_PATH_ELEMENT{" test_common bitcoin" }; // Includes a space to catch possible path escape issues.
7877/* * Random context to get unique temp data dirs. Separate from m_rng, which can be seeded from a const env var */
7978static FastRandomContext g_rng_temp_path;
8079
@@ -108,7 +107,7 @@ static NetworkSetup g_networksetup_instance;
108107/* * Register test-only arguments */
109108static void SetupUnitTestArgs (ArgsManager& argsman)
110109{
111- argsman.AddArg (" -testdatadir" , strprintf (" Custom data directory (default: %s<random_string>)" , fs::PathToString (fs::temp_directory_path () / " test_common_ " PACKAGE_NAME / " " )),
110+ argsman.AddArg (" -testdatadir" , strprintf (" Custom data directory (default: %s<random_string>)" , fs::PathToString (fs::temp_directory_path () / TEST_DIR_PATH_ELEMENT / " " )),
112111 ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
113112}
114113
@@ -159,7 +158,7 @@ BasicTestingSetup::BasicTestingSetup(const ChainType chainType, TestOpts opts)
159158 if (!m_node.args ->IsArgSet (" -testdatadir" )) {
160159 // By default, the data directory has a random name
161160 const auto rand_str{g_rng_temp_path.rand256 ().ToString ()};
162- m_path_root = fs::temp_directory_path () / " test_common_ " PACKAGE_NAME / rand_str;
161+ m_path_root = fs::temp_directory_path () / TEST_DIR_PATH_ELEMENT / rand_str;
163162 TryCreateDirectories (m_path_root);
164163 } else {
165164 // Custom data directory
@@ -169,7 +168,7 @@ BasicTestingSetup::BasicTestingSetup(const ChainType chainType, TestOpts opts)
169168
170169 root_dir = fs::absolute (root_dir);
171170 const std::string test_path{G_TEST_GET_FULL_NAME ? G_TEST_GET_FULL_NAME () : " " };
172- m_path_lock = root_dir / " test_common_ " PACKAGE_NAME / fs::PathFromString (test_path);
171+ m_path_lock = root_dir / TEST_DIR_PATH_ELEMENT / fs::PathFromString (test_path);
173172 m_path_root = m_path_lock / " datadir" ;
174173
175174 // Try to obtain the lock; if unsuccessful don't disturb the existing test.
0 commit comments