## Runs ParserFuzz (test/net/parser_fuzz.gd) over many malformed messages and fails on ## any engine or script error, or if memory grows by more than 16 MiB past warm-up. ## ## tools/godot.sh --script res://tools/fuzz_parsers.gd -- --messages=N --seed=N ## ## `make fuzz` runs 1,000,000. Prints one JSON line; exits 0 when clean, 1 otherwise. extends SceneTree const MAX_GROWTH_BYTES: int = 16 * 1024 * 1024 func _init() -> void: var count: int = 1000000 var fuzz_seed: int = 1 for arg: String in OS.get_cmdline_user_args(): if arg.begins_with("--messages="): count = arg.get_slice("=", 1).to_int() elif arg.begins_with("--seed="): fuzz_seed = arg.get_slice("=", 1).to_int() var errors: ErrorCounter = ErrorCounter.new() OS.add_logger(errors) var started: int = Time.get_ticks_msec() var fuzz: ParserFuzz = ParserFuzz.new(fuzz_seed) fuzz.run(count) var growth: int = fuzz.memory_end - fuzz.memory_start var ok: bool = errors.count() == 0 and growth <= MAX_GROWTH_BYTES and fuzz.listed() == 0 var report: Dictionary = { "event": "fuzz", "ok": ok, "messages": fuzz.messages, "seeds": fuzz.seeds.size(), "accepted": fuzz.accepted, "errors": errors.count(), "memory_growth_bytes": growth, "memory_peak_bytes": fuzz.memory_peak, "listed": fuzz.listed(), "seed": fuzz_seed, "wall_ms": Time.get_ticks_msec() - started, } if errors.count() > 0: report["first_error"] = errors.first() print(JSON.stringify(report)) OS.remove_logger(errors) quit(0 if ok else 1)