Hash :
b5300040
Author :
Date :
2025-04-05T17:15:50
[run-fuzzer-tests] Remove duplicate chunksize
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
#!/usr/bin/env python3
import pathlib
import subprocess
import os
import sys
import tempfile
EXE_WRAPPER = os.environ.get("MESON_EXE_WRAPPER")
def run_command(command):
"""
Run a command, capturing potentially large output in a temp file.
Returns (output_string, exit_code).
"""
global EXE_WRAPPER
if EXE_WRAPPER:
command = [EXE_WRAPPER] + command
with tempfile.TemporaryFile() as tempf:
p = subprocess.Popen(command, stdout=tempf, stderr=tempf)
p.wait()
tempf.seek(0)
output = tempf.read().decode("utf-8", errors="replace").strip()
return output, p.returncode
def chunkify(lst, chunk_size=64):
"""
Yield successive chunk_size-sized slices from lst.
"""
for i in range(0, len(lst), chunk_size):
yield lst[i : i + chunk_size]
def main():
assert len(sys.argv) > 2, "Please provide fuzzer binary and fonts directory paths."
fuzzer = pathlib.Path(sys.argv[1])
assert fuzzer.is_file(), f"Fuzzer binary not found: {fuzzer}"
print("Using fuzzer:", fuzzer)
# Gather all test files
files_to_test = []
for fonts_dir in sys.argv[2:]:
fonts_dir = pathlib.Path(fonts_dir)
assert fonts_dir.is_dir(), f"Fonts directory not found: {fonts_dir}"
test_files = [str(f) for f in fonts_dir.iterdir() if f.is_file()]
assert test_files, f"No files found in {fonts_dir}"
files_to_test += test_files
if not files_to_test:
print("No test files found")
sys.exit(0)
fails = 0
batch_index = 0
for chunk in chunkify(files_to_test):
batch_index += 1
cmd_line = [fuzzer] + chunk
output, returncode = run_command(cmd_line)
if output:
print(output)
if returncode != 0:
print(f"Failure in batch #{batch_index}")
fails += 1
if fails > 0:
sys.exit(f"{fails} fuzzer batch(es) failed.")
print("All fuzzer tests passed successfully.")
if __name__ == "__main__":
main()