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.