This backward-compatible change would help with code review, testing, and debugging. When test_bitcoin
runs, it creates a working or data directory within /tmp/test_common_Bitcoin\ Core/
, named as a long random (hex) string.
This small patch does three things:
- If the (new) argument
-testdatadir=<datadir>
is given, use<datadir>/test_temp/<test-name>/datadir
as the working directory - When the test starts, remove
<datadir>/test_temp/<test-name>/datadir
if it exists from an earlier run (currently, it’s presumed not to exist due to the long random string) - Don’t delete the working directory at the end of the test if a custom data directory is being used
Example usage, which will remove, create, use /somewhere/test_temp/getarg_tests/boolarg
, and leave it afterward:
0$ test_bitcoin --run_test=getarg_tests/boolarg -- -testdatadir=/somewhere
1Running 1 test case...
2Test directory (will not be deleted): "/somewhere/test_temp/getarg_tests/boolarg/datadir"
3
4*** No errors detected
5$ ls -l /somewhere/test_temp/getarg_tests/boolarg/datadir
6total 8
7drwxrwxr-x 2 larry larry 4096 Feb 22 10:28 blocks
8-rw-rw-r-- 1 larry larry 1273 Feb 22 10:28 debug.log
(A relative pathname also works.)
This change affects only test_bitcoin
; it could also be applied to test_bitcoin-qt
but that’s slightly more involved so I’m skipping that for now.
The rationale for this change is that, when running the test using the debugger, it’s often useful to watch debug.log
as the test runs and inspect some of the other files (I’ve looked at the generated blknnnn.dat
files for example). Currently, that requires figuring out where the test’s working directory is since it changes on every test run. Tests can be run with -printtoconsole=1
to show debug logging to the terminal, but it’s nice to keep debug.log
continuously open in an editor, for example.
Even if not using a debugger, it’s sometimes helpful to see debug.log
and other artifacts after the test completes.
Similar functionality is already possible with the functional tests using the --tmpdir=
and --nocleanup
arguments.