2
2
// Distributed under the MIT software license, see the accompanying
3
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
4
5
- #include < config/bitcoin-config.h> // IWYU pragma: keep
6
-
7
5
#include < test/util/setup_common.h>
8
6
9
7
#include < addrman.h>
@@ -75,6 +73,7 @@ using node::VerifyLoadedChainstate;
75
73
76
74
const std::function<std::string(const char *)> G_TRANSLATION_FUN = nullptr ;
77
75
76
+ constexpr inline auto TEST_DIR_PATH_ELEMENT{" test_common bitcoin" }; // Includes a space to catch possible path escape issues.
78
77
/* * Random context to get unique temp data dirs. Separate from m_rng, which can be seeded from a const env var */
79
78
static FastRandomContext g_rng_temp_path;
80
79
@@ -108,7 +107,7 @@ static NetworkSetup g_networksetup_instance;
108
107
/* * Register test-only arguments */
109
108
static void SetupUnitTestArgs (ArgsManager& argsman)
110
109
{
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 / " " )),
112
111
ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
113
112
}
114
113
@@ -159,7 +158,7 @@ BasicTestingSetup::BasicTestingSetup(const ChainType chainType, TestOpts opts)
159
158
if (!m_node.args ->IsArgSet (" -testdatadir" )) {
160
159
// By default, the data directory has a random name
161
160
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;
163
162
TryCreateDirectories (m_path_root);
164
163
} else {
165
164
// Custom data directory
@@ -169,7 +168,7 @@ BasicTestingSetup::BasicTestingSetup(const ChainType chainType, TestOpts opts)
169
168
170
169
root_dir = fs::absolute (root_dir);
171
170
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);
173
172
m_path_root = m_path_lock / " datadir" ;
174
173
175
174
// Try to obtain the lock; if unsuccessful don't disturb the existing test.
0 commit comments