Skip to content

Commit fa84f9d

Browse files
author
MarcoFalke
committed
test: Pin and document TEST_DIR_PATH_ELEMENT
1 parent 2222f7a commit fa84f9d

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/test/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ build/src/test/test_bitcoin --run_test=getarg_tests/doubledash
6363
```
6464

6565
`test_bitcoin` creates a temporary working (data) directory with a randomly
66-
generated pathname within `test_common_Bitcoin Core/`, which in turn is within
66+
generated pathname within `test_common bitcoin/`, which in turn is within
6767
the system's temporary directory (see
6868
[`temp_directory_path`](https://en.cppreference.com/w/cpp/filesystem/temp_directory_path)).
6969
This data directory looks like a simplified form of the standard `bitcoind` data
@@ -73,7 +73,7 @@ have a `debug.log` file, for example.
7373
The location of the temporary data directory can be specified with the
7474
`-testdatadir` option. This can make debugging easier. The directory
7575
path used is the argument path appended with
76-
`/test_common_Bitcoin Core/<test-name>/datadir`.
76+
`/test_common bitcoin/<test-name>/datadir`.
7777
The directory path is created if necessary.
7878
Specifying this argument also causes the data directory
7979
not to be removed after the last test. This is useful for looking at
@@ -83,11 +83,11 @@ so no leftover state is used.)
8383

8484
```bash
8585
$ build/src/test/test_bitcoin --run_test=getarg_tests/doubledash -- -testdatadir=/somewhere/mydatadir
86-
Test directory (will not be deleted): "/somewhere/mydatadir/test_common_Bitcoin Core/getarg_tests/doubledash/datadir"
86+
Test directory (will not be deleted): "/somewhere/mydatadir/test_common bitcoin/getarg_tests/doubledash/datadir"
8787
Running 1 test case...
8888

8989
*** No errors detected
90-
$ ls -l '/somewhere/mydatadir/test_common_Bitcoin Core/getarg_tests/doubledash/datadir'
90+
$ ls -l '/somewhere/mydatadir/test_common bitcoin/getarg_tests/doubledash/datadir'
9191
total 8
9292
drwxrwxr-x 2 admin admin 4096 Nov 27 22:45 blocks
9393
-rw-rw-r-- 1 admin admin 1003 Nov 27 22:45 debug.log

src/test/util/setup_common.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
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

7674
const 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 */
7978
static FastRandomContext g_rng_temp_path;
8079

@@ -108,7 +107,7 @@ static NetworkSetup g_networksetup_instance;
108107
/** Register test-only arguments */
109108
static 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

Comments
 (0)