Skip to content

Commit 6ed2cf5

Browse files
committed
Merge bitcoin/bitcoin#34169: fuzz: change fuzz runner test_runner.py to be cwd independent
77c9b3c change test_runner.py to be cwd independent by calling subprocess.run with cwd arg. (Robin David) Pull request description: 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: ``` ../../src/protocol.h-', '../../../src/protocol.h-/** nServices flags */'] Traceback (most recent call last): File "/path/to/bitcoin/build_libfuzzer/test/fuzz/./test_runner.py", line 405, in <module> main() ~~~~^^ File "/path/to/bitcoin/build_libfuzzer/test/fuzz/./test_runner.py", line 173, in main return generate_corpus( fuzz_pool=fuzz_pool, ...<3 lines>... targets=test_list_selection, ) File "/path/to/bitcoin/build_libfuzzer/test/fuzz/./test_runner.py", line 249, in generate_corpus targets = transform_process_message_target(targets, Path(src_dir)) File "/path/to/build_libfuzzer/test/fuzz/./test_runner.py", line 218, in transform_process_message_target assert len(lines) ~~~^^^^^^^ AssertionError ``` The script is not able to retrieve lines as the filter applied is: ```python lines = [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: ``` [snip] src/protocol.h- NetMsgType::VERSION, [snip] ``` but returns a relative path to CWD when run from other directories e.g: ``` ../../../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. ACKs for top commit: maflcko: lgtm ACK 77c9b3c dergoegge: Code review ACK 77c9b3c Tree-SHA512: fbc821c4790dd9ac125046a842498e0d9a48549d1c8ef150bce2193ee62bee9c3bfd4b17ce278411102dd200dc9ad86a176ecae29ca1667bb14d6f90ad67e01d
2 parents fb49d62 + 77c9b3c commit 6ed2cf5

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

test/fuzz/test_runner.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,11 @@ def transform_process_message_target(targets, src_dir):
208208
p2p_msg_target = "process_message"
209209
if (p2p_msg_target, {}) in targets:
210210
lines = subprocess.run(
211-
["git", "grep", "--function-context", "ALL_NET_MESSAGE_TYPES{", src_dir / "src" / "protocol.h"],
211+
["git", "grep", "--function-context", "ALL_NET_MESSAGE_TYPES{", "src/protocol.h"],
212212
check=True,
213213
stdout=subprocess.PIPE,
214214
text=True,
215+
cwd=src_dir,
215216
).stdout.splitlines()
216217
lines = [l.split("::", 1)[1].split(",")[0].lower() for l in lines if l.startswith("src/protocol.h- NetMsgType::")]
217218
assert len(lines)
@@ -226,10 +227,11 @@ def transform_rpc_target(targets, src_dir):
226227
rpc_target = "rpc"
227228
if (rpc_target, {}) in targets:
228229
lines = subprocess.run(
229-
["git", "grep", "--function-context", "RPC_COMMANDS_SAFE_FOR_FUZZING{", src_dir / "src" / "test" / "fuzz" / "rpc.cpp"],
230+
["git", "grep", "--function-context", "RPC_COMMANDS_SAFE_FOR_FUZZING{", "src/test/fuzz/rpc.cpp"],
230231
check=True,
231232
stdout=subprocess.PIPE,
232233
text=True,
234+
cwd=src_dir,
233235
).stdout.splitlines()
234236
lines = [l.split("\"", 1)[1].split("\"")[0] for l in lines if l.startswith("src/test/fuzz/rpc.cpp- \"")]
235237
assert len(lines)

0 commit comments

Comments
 (0)