fuzz: change fuzz runner test_runner.py to be cwd independent #34169

pull RobinDavid wants to merge 1 commits into bitcoin:master from RobinDavid:test_runner_cwd_independent changing 1 files +4 −2
  1. RobinDavid commented at 11:06 am on December 29, 2025: none

    Dear Maintainers,

    While using test_runner.py that runs fuzz tests and produces coverage results I encountered the following error.

    If not running the script from the project root directory the git grep --function-context [...] does not return the same output which results in the following Python error:

     0../../src/protocol.h-', '../../../src/protocol.h-/** nServices flags */']
     1Traceback (most recent call last):
     2  File "/path/to/bitcoin/build_libfuzzer/test/fuzz/./test_runner.py", line 405, in <module>
     3    main()
     4    ~~~~^^
     5  File "/path/to/bitcoin/build_libfuzzer/test/fuzz/./test_runner.py", line 173, in main
     6    return generate_corpus(
     7        fuzz_pool=fuzz_pool,
     8    ...<3 lines>...
     9        targets=test_list_selection,
    10    )
    11  File "/path/to/bitcoin/build_libfuzzer/test/fuzz/./test_runner.py", line 249, in generate_corpus
    12    targets = transform_process_message_target(targets, Path(src_dir))
    13  File "/path/to/build_libfuzzer/test/fuzz/./test_runner.py", line 218, in transform_process_message_target
    14    assert len(lines)
    15           ~~~^^^^^^^
    16AssertionError
    

    The script is not able to retrieve lines as the filter applied is:

    0lines = [l.split("::", 1)[1].split(",")[0].lower() for l in lines if l.startswith("src/protocol.h-    NetMsgType::")]
    

    Which when running from the root directory returns:

    0[snip]
    1src/protocol.h-    NetMsgType::VERSION,
    2[snip]
    

    but returns a relative path to CWD when run from other directories e.g:

    0../../../src/protocol.h-    NetMsgType::VERSION,
    

    This is very unfortunate as the script rightfully read the config.ini relatively to itself and go fetch BUILDDIR and SRCDIR variables to obtain absolute paths.

    Options are:

    • enforce running the script from bitcoin/ directory (and thus explicitly mentioning it in the doc)
    • make the script independent from where it is being run

    I chose the second option as it was fairly easy to make the script independent from where it is being run.

  2. DrahtBot added the label Scripts and tools on Dec 29, 2025
  3. DrahtBot commented at 11:06 am on December 29, 2025: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34169.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK maflcko

    If your review is incorrectly listed, please copy-paste <!–meta-tag:bot-skip–> into the comment that the bot should ignore.

  4. fanquake added the label Fuzzing on Dec 29, 2025
  5. fanquake requested review from dergoegge on Dec 29, 2025
  6. in test/fuzz/test_runner.py:215 in 23dab9697b
    211@@ -213,7 +212,7 @@ def transform_process_message_target(targets, src_dir):
    212             stdout=subprocess.PIPE,
    213             text=True,
    214         ).stdout.splitlines()
    215-        lines = [l.split("::", 1)[1].split(",")[0].lower() for l in lines if l.startswith("src/protocol.h-    NetMsgType::")]
    216+        lines = [l.split("::", 1)[1].split(",")[0].lower() for l in lines if "src/protocol.h-    NetMsgType::" in l]
    


    maflcko commented at 11:39 am on December 29, 2025:
    this seems like the wrong fix. My preference would be to just pass cwd=src_dir, to the subprocess and keep the more strict parsing here

    RobinDavid commented at 4:33 pm on December 29, 2025:

    I agree. It seem’s like a more elegant way to fix. I will do it.

    For the topic, contributing.md, mention that “test” is for unit-test. Did knew about “fuzz:” it seems more suitable.

  7. maflcko commented at 11:40 am on December 29, 2025: member
    the pull title should probably start with test: or fuzz:, not contrib.
  8. RobinDavid renamed this:
    contrib: change fuzz runner test_runner.py to be cwd independent
    fuzz: change fuzz runner test_runner.py to be cwd independent
    on Dec 29, 2025
  9. maflcko commented at 4:54 pm on December 29, 2025: member
  10. maflcko removed the label Scripts and tools on Dec 29, 2025
  11. maflcko removed the label Fuzzing on Dec 29, 2025
  12. DrahtBot added the label Fuzzing on Dec 29, 2025
  13. RobinDavid force-pushed on Dec 29, 2025
  14. in test/fuzz/test_runner.py:207 in 24d37f3a6c
    203@@ -204,14 +204,14 @@ def main():
    204 def transform_process_message_target(targets, src_dir):
    205     """Add a target per process message, and also keep ("process_message", {}) to allow for
    206     cross-pollination, or unlimited search"""
    207-
    


    maflcko commented at 8:30 am on December 30, 2025:
    nit: The newline should remain, like in the other function? Seems like an unrelated and inconsistent change here.
  15. in test/fuzz/test_runner.py:210 in 24d37f3a6c
    203@@ -204,14 +204,14 @@ def main():
    204 def transform_process_message_target(targets, src_dir):
    205     """Add a target per process message, and also keep ("process_message", {}) to allow for
    206     cross-pollination, or unlimited search"""
    207-
    208     p2p_msg_target = "process_message"
    209     if (p2p_msg_target, {}) in targets:
    210         lines = subprocess.run(
    211             ["git", "grep", "--function-context", "ALL_NET_MESSAGE_TYPES{", src_dir / "src" / "protocol.h"],
    


    maflcko commented at 8:31 am on December 30, 2025:
    0            ["git", "grep", "--function-context", "ALL_NET_MESSAGE_TYPES{", "src" / "protocol.h"],
    

    i guess this could be removed now (here and in the other function)


    RobinDavid commented at 10:23 am on December 30, 2025:
    Ok. I can do. As src_dir is a Path object, I won’t be able to use “/”. Thus I will fold the whole path into one string.
  16. maflcko approved
  17. maflcko commented at 8:32 am on December 30, 2025: member
    lgtm. I think the nits should be addressed before merge
  18. change test_runner.py to be cwd independent by calling subprocess.run with cwd arg. 77c9b3c08f
  19. RobinDavid force-pushed on Dec 30, 2025
  20. maflcko commented at 10:50 am on December 30, 2025: member

    thanks!

    lgtm ACK 77c9b3c08f5f195c9afe8fba2395fbe48068fce0

  21. janb84 commented at 8:26 pm on December 30, 2025: contributor

    ~0 77c9b3c08f5f195c9afe8fba2395fbe48068fce0

    Although the code is fine, I’m not sure if it’s worth the change.


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-12-31 06:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me