Files
bitcoin/test/functional/feature_logging.py
MarcoFalke fac6c4270d ci: Put space and non-ASCII char in scratch dir
Also, add a missing quote around -DCMAKE_INSTALL_PREFIX to avoid word
splitting.
Otherwise, cmake would warn:

```
+ cmake -S /home/runner/work/_temp -B /home/runner/work/_temp/build -DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DBUILD_BENCH=ON -DBUILD_FUZZ_BINARY=ON -DCMAKE_INSTALL_PREFIX=/home/runner/work/_temp/ci/scratch_ ₿🧪_/out -Werror=dev --preset=dev-mode -DSANITIZERS=address,float-divide-by-zero,integer,undefined -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_FLAGS=-ftrivial-auto-var-init=pattern -DCMAKE_CXX_FLAGS=-ftrivial-auto-var-init=pattern -DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=mold -DAPPEND_CXXFLAGS=-std=c++23 '-DAPPEND_CPPFLAGS=-DARENA_DEBUG -DDEBUG_LOCKORDER'
CMake Warning:
  Ignoring extra path from command line:
   "₿🧪_/out"
```

Also, allow spaces in the debug log file regex in a test.
Otherwise, the test would fail:

```
TestFramework (ERROR): Unexpected exception:
Traceback (most recent call last):
  File "./test/functional/test_framework/test_framework.py", line 142, in main
    self.run_test()
    ~~~~~~~~~~~~~^^
  File "./test/functional/feature_logging.py", line 40, in run_test
    self.nodes[0].assert_start_raises_init_error([f"-debuglogfile={invalidname}"], exp_stderr, match=ErrorMatch.FULL_REGEX)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "./test/functional/test_framework/test_node.py", line 743, in assert_start_raises_init_error
    self._raise_assertion_error(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        'Expected message "{}" does not fully match stderr:\n"{}"'.format(expected_msg, stderr))
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "./test/functional/test_framework/test_node.py", line 229, in _raise_assertion_error
    raise AssertionError(self._node_msg(msg))
AssertionError: [node 0] Expected message "Error: Could not open debug log file \S+$" does not fully match stderr:
"Error: Could not open debug log file /Users/runner/work/bitcoin-core-with-ci/bitcoin-core-with-ci/repo_archive/ci/scratch_ ₿🧪_/test_runner/test_runner_₿_🏃_20260218_095938/feature_logging_31/node0/regtest/foo/foo.log"
```

Also, add missing quotes in a test. Otherwise, the test would fail:

```
455/455 - feature_notifications.py failed, Duration: 402 s
stdout:
TestFramework (INFO): Initializing test directory /home/runner/work/_temp/ci/scratch_ ₿🧪_/test_runner/test_runner_₿_🏃_20260218_113529/feature_notifications_128
TestFramework (INFO): test -blocknotify
TestFramework.utils (ERROR): wait_until() failed. Predicate: ''''
        self.wait_until(lambda: len(os.listdir(self.blocknotify_dir)) == block_count, timeout=10)
'''
2026-05-14 13:09:35 +02:00

128 lines
5.3 KiB
Python
Executable File

#!/usr/bin/env python3
# Copyright (c) 2017-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test debug logging."""
import os
from test_framework.test_framework import BitcoinTestFramework
from test_framework.p2p import P2PInterface
from test_framework.test_node import ErrorMatch
class LoggingTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1
self.setup_clean_chain = True
def relative_log_path(self, name):
return os.path.join(self.nodes[0].chain_path, name)
def run_test(self):
# test default log file name
default_log_path = self.relative_log_path("debug.log")
assert os.path.isfile(default_log_path)
# test alternative log file name in datadir
self.restart_node(0, ["-debuglogfile=foo.log"])
assert os.path.isfile(self.relative_log_path("foo.log"))
# test alternative log file name outside datadir
tempname = os.path.join(self.options.tmpdir, "foo.log")
self.restart_node(0, [f"-debuglogfile={tempname}"])
assert os.path.isfile(tempname)
# check that invalid log (relative) will cause error
invdir = self.relative_log_path("foo")
invalidname = os.path.join("foo", "foo.log")
self.stop_node(0)
exp_stderr = "Error: Could not open debug log file "
self.nodes[0].assert_start_raises_init_error([f"-debuglogfile={invalidname}"], exp_stderr, match=ErrorMatch.PARTIAL_REGEX)
assert not os.path.isfile(os.path.join(invdir, "foo.log"))
# check that invalid log (relative) works after path exists
self.stop_node(0)
os.mkdir(invdir)
self.start_node(0, [f"-debuglogfile={invalidname}"])
assert os.path.isfile(os.path.join(invdir, "foo.log"))
# check that invalid log (absolute) will cause error
self.stop_node(0)
invdir = os.path.join(self.options.tmpdir, "foo")
invalidname = os.path.join(invdir, "foo.log")
self.nodes[0].assert_start_raises_init_error([f"-debuglogfile={invalidname}"], exp_stderr, match=ErrorMatch.PARTIAL_REGEX)
assert not os.path.isfile(os.path.join(invdir, "foo.log"))
# check that invalid log (absolute) works after path exists
self.stop_node(0)
os.mkdir(invdir)
self.start_node(0, [f"-debuglogfile={invalidname}"])
assert os.path.isfile(os.path.join(invdir, "foo.log"))
# check that -nodebuglogfile disables logging
self.stop_node(0)
os.unlink(default_log_path)
assert not os.path.isfile(default_log_path)
self.start_node(0, ["-nodebuglogfile"])
assert not os.path.isfile(default_log_path)
# just sanity check no crash here
self.restart_node(0, [f"-debuglogfile={os.devnull}"])
self.log.info("Test -debug and -debugexclude raise when invalid values are passed")
self.stop_node(0)
self.nodes[0].assert_start_raises_init_error(
extra_args=["-debug=abc"],
expected_msg="Error: Unsupported logging category -debug=abc.",
match=ErrorMatch.FULL_REGEX,
)
self.nodes[0].assert_start_raises_init_error(
extra_args=["-debugexclude=abc"],
expected_msg="Error: Unsupported logging category -debugexclude=abc.",
match=ErrorMatch.FULL_REGEX,
)
self.log.info("Test -loglevel raises when invalid values are passed")
self.nodes[0].assert_start_raises_init_error(
extra_args=["-loglevel=abc"],
expected_msg="Error: Unsupported global logging level -loglevel=abc. Valid values: info, debug, trace.",
match=ErrorMatch.FULL_REGEX,
)
self.nodes[0].assert_start_raises_init_error(
extra_args=["-loglevel=net:abc"],
expected_msg="Error: Unsupported category-specific logging level -loglevel=net:abc.",
match=ErrorMatch.PARTIAL_REGEX,
)
self.nodes[0].assert_start_raises_init_error(
extra_args=["-loglevel=net:info:abc"],
expected_msg="Error: Unsupported category-specific logging level -loglevel=net:info:abc.",
match=ErrorMatch.PARTIAL_REGEX,
)
self.log.info("Test that -nodebug,-debug=0,-debug=none clear previously specified debug options")
disable_debug_options = [
'-debug=0',
'-debug=none',
'-nodebug'
]
for disable_debug_opt in disable_debug_options:
# Every category before disable_debug_opt will be ignored, including the invalid 'abc'
self.restart_node(0, ['-debug=http', '-debug=abc', disable_debug_opt, '-debug=rpc', '-debug=net'])
logging = self.nodes[0].logging()
assert not logging['http']
assert 'abc' not in logging
assert logging['rpc']
assert logging['net']
self.log.info("Test -logips formatting in net logs")
self.restart_node(0, ['-debug=net', '-logips=1'])
with self.nodes[0].assert_debug_log(["peer=0, peeraddr="]):
p2p = self.nodes[0].add_p2p_connection(P2PInterface())
p2p.wait_for_verack()
self.nodes[0].disconnect_p2ps()
if __name__ == '__main__':
LoggingTest(__file__).main()