aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2023-07-20 10:03:30 +0100
committerfanquake <fanquake@gmail.com>2023-07-20 10:17:08 +0100
commit355bbcba01e1747f2099467b59cd0b438bddee38 (patch)
tree2e5fd4eea4a4eba5ad3ed67d976da1ebaa015fe6 /test
parent04afe55e29002a1d46d1cd9ed117229874840ae6 (diff)
parentfa6245da6061050eb77ad07cd4caf8c596d89dc6 (diff)
downloadbitcoin-355bbcba01e1747f2099467b59cd0b438bddee38.tar.xz
Merge bitcoin/bitcoin#28066: fuzz: Generate process_message targets individually
fa6245da6061050eb77ad07cd4caf8c596d89dc6 fuzz: Generate process_message targets individually (MarcoFalke) fa1471e5754484f997ddf9db70888679dcd1d64a refactor: Remove duplicate allNetMessageTypesVec (MarcoFalke) Pull request description: Now that `LIMIT_TO_MESSAGE_TYPE` is a runtime setting after commit 927b001502a74a7224f04cfe6ffddc9a59409ba1, it shouldn't hurt to also generate each message type individually. Something similar was done for the `rpc` target in commit cf4da5ec29f9e8cd6cc6577e5ecbd87174edba62. ACKs for top commit: stickies-v: re-crACK fa6245da6061050eb77ad07cd4caf8c596d89dc6 brunoerg: reACK fa6245da6061050eb77ad07cd4caf8c596d89dc6 Tree-SHA512: 8f3ec71bab89781f10820a0e027fcde8949f3333eb19a30315aaad6f90f5167028113cea255b2d60b700da817c7eaac20b7b4c92f931052d7f5c2f148d33aa5a
Diffstat (limited to 'test')
-rwxr-xr-xtest/fuzz/test_runner.py49
1 files changed, 37 insertions, 12 deletions
diff --git a/test/fuzz/test_runner.py b/test/fuzz/test_runner.py
index ef1583d446..1ce7c71360 100755
--- a/test/fuzz/test_runner.py
+++ b/test/fuzz/test_runner.py
@@ -193,27 +193,52 @@ def main():
)
-def generate_corpus(*, fuzz_pool, src_dir, build_dir, corpus_dir, targets):
- """Generates new corpus.
+def transform_process_message_target(targets, src_dir):
+ """Add a target per process message, and also keep ("process_message", {}) to allow for
+ cross-pollination, or unlimited search"""
+
+ p2p_msg_target = "process_message"
+ if (p2p_msg_target, {}) in targets:
+ lines = subprocess.run(
+ ["git", "grep", "--function-context", "g_all_net_message_types{", src_dir / "src" / "protocol.cpp"],
+ check=True,
+ stdout=subprocess.PIPE,
+ text=True,
+ ).stdout.splitlines()
+ lines = [l.split("::", 1)[1].split(",")[0].lower() for l in lines if l.startswith("src/protocol.cpp- NetMsgType::")]
+ assert len(lines)
+ targets += [(p2p_msg_target, {"LIMIT_TO_MESSAGE_TYPE": m}) for m in lines]
+ return targets
+
+
+def transform_rpc_target(targets, src_dir):
+ """Add a target per RPC command, and also keep ("rpc", {}) to allow for cross-pollination,
+ or unlimited search"""
- Run {targets} without input, and outputs the generated corpus to
- {corpus_dir}.
- """
- logging.info("Generating corpus to {}".format(corpus_dir))
rpc_target = "rpc"
- has_rpc = rpc_target in targets
- if has_rpc:
- targets.remove(rpc_target)
- targets = [(t, {}) for t in targets]
- if has_rpc:
+ if (rpc_target, {}) in targets:
lines = subprocess.run(
- ["git", "grep", "--function-context", "RPC_COMMANDS_SAFE_FOR_FUZZING{", os.path.join(src_dir, "src", "test", "fuzz", "rpc.cpp")],
+ ["git", "grep", "--function-context", "RPC_COMMANDS_SAFE_FOR_FUZZING{", src_dir / "src" / "test" / "fuzz" / "rpc.cpp"],
check=True,
stdout=subprocess.PIPE,
text=True,
).stdout.splitlines()
lines = [l.split("\"", 1)[1].split("\"")[0] for l in lines if l.startswith("src/test/fuzz/rpc.cpp- \"")]
+ assert len(lines)
targets += [(rpc_target, {"LIMIT_TO_RPC_COMMAND": r}) for r in lines]
+ return targets
+
+
+def generate_corpus(*, fuzz_pool, src_dir, build_dir, corpus_dir, targets):
+ """Generates new corpus.
+
+ Run {targets} without input, and outputs the generated corpus to
+ {corpus_dir}.
+ """
+ logging.info("Generating corpus to {}".format(corpus_dir))
+ targets = [(t, {}) for t in targets] # expand to add dictionary for target-specific env variables
+ targets = transform_process_message_target(targets, Path(src_dir))
+ targets = transform_rpc_target(targets, Path(src_dir))
def job(command, t, t_env):
logging.debug(f"Running '{command}'")