about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChris Ball <chris@printf.net>2023-11-14 09:47:47 -0800
committerChris Ball <chris@printf.net>2023-11-14 09:47:47 -0800
commitafb9b8a961db898c37ef387fee70af09b0351a20 (patch)
tree3811a5c533120d5ebb0b4fcf956e2e2d1915bdae
parent26045831a23ceef70834c7a7be4d17d436a4cf8e (diff)
downloadafl++-afb9b8a961db898c37ef387fee70af09b0351a20.tar.gz
benchmark: disallow duplicate entries for the same CPU in COMPARISON
-rw-r--r--benchmark/benchmark.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/benchmark/benchmark.py b/benchmark/benchmark.py
index 1510acb6..d352a95b 100644
--- a/benchmark/benchmark.py
+++ b/benchmark/benchmark.py
@@ -93,7 +93,7 @@ results = Results(config=None, hardware=None, targets={
 debug = lambda text: args.debug and print(blue(text))
 if Mode.multicore in chosen_modes:
     print(blue(f" [*] Using {args.fuzzers} fuzzers for multicore fuzzing "), end="")
-    print(blue("(use --fuzzers to override)" if args.fuzzers == cpu_count else f"(the default is {cpu_count})"))
+    print(blue("(use --fuzzers to override)." if args.fuzzers == cpu_count else f"(the default is {cpu_count})"))
 
 async def clean_up_tempfiles() -> None:
     shutil.rmtree(f"{args.basedir}/in")
@@ -192,13 +192,16 @@ async def save_benchmark_results() -> None:
     with open("benchmark-results.jsonl", "a") as jsonfile:
         json.dump(asdict(results), jsonfile, sort_keys=True)
         jsonfile.write("\n")
-        print(blue(f" [*] Results have been written to {jsonfile.name}"))
-    with open("COMPARISON", "a") as comparisonfile:
+        print(blue(f" [*] Results have been written to the {jsonfile.name} file."))
+    with open("COMPARISON", "r+") as comparisonfile:
         described_config = await describe_afl_config()
         aflconfig = described_config.ljust(12)
         if results.hardware is None:
             return
         cpu_model = results.hardware.cpu_model.ljust(51)
+        if cpu_model in comparisonfile.read():
+            print(blue(f" [*] Results have not been written to the COMPARISON file; this CPU is already present."))
+            return
         cpu_mhz = str(round(results.hardware.cpu_fastest_core_mhz)).ljust(5)
         if "test-instr-persist-shmem" in results.targets and "multicore" in results.targets["test-instr-persist-shmem"]:
             if results.targets["test-instr-persist-shmem"]["singlecore"] is None or \
@@ -208,6 +211,7 @@ async def save_benchmark_results() -> None:
             multi = str(round(results.targets["test-instr-persist-shmem"]["multicore"].afl_execs_per_sec)).ljust(9)
             cores = str(args.fuzzers).ljust(7)
             comparisonfile.write(f"{cpu_model} | {cpu_mhz} | {cores} | {single} | {multi} | {aflconfig} |\n")
+            print(blue(f" [*] Results have been written to the COMPARISON file."))
     with open("COMPARISON", "r") as comparisonfile:
         print(comparisonfile.read())