From 8eb98e2930b3b258efacb41d6ebd722d912b2ec4 Mon Sep 17 00:00:00 2001
From: Egor Ivkov <e.o.ivkov@gmail.com>
Date: Tue, 27 Feb 2024 17:36:09 +0300
Subject: [PATCH] test/fuzz: batch fuzzing in ci stub

NO_DOC=internal
NO_TEST=internal
NO_CHANGELOG=internal
---
 .gitlab-ci.yml          | 18 ++++++++++++++++++
 test/fuzz/fuzz_until.py |  6 ++----
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index be79f036b1..377b45241c 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -87,6 +87,24 @@ fuzz-check-build:
       - python3 infra/helper.py build_fuzzers --external .. --sanitizer=address
       - python3 infra/helper.py check_build --external .. --sanitizer=address
 
+# Run fuzzers until they satisfy stop criterias
+# XXX: Just a stub for now, it probably needs a custom runner
+# and support for running several fuzzers
+fuzz-run:
+    tags: [shell_p_t]
+    when: manual
+    script:
+      # Clone oss-fuzz instead of adding it as a submodule
+      # as we don't want it to be checked by static analyzers - it's used only for fuzzing
+      - git clone https://github.com/google/oss-fuzz.git
+      - cd oss-fuzz
+      # Checkout a fixed oss-fuzz commit to guarantee reproducible builds
+      - git checkout e8e124996508f1e4ffe566896638c7213ab440d5
+      - python3 infra/helper.py build_image --no-pull --external ..
+      - python3 infra/helper.py build_fuzzers --external .. --sanitizer=address
+      - cd ..
+      - python3 test/fuzz/fuzz_until.py swim_proto_meta_fuzzer
+
 .pack:
   tags:
     - shell_p_t
diff --git a/test/fuzz/fuzz_until.py b/test/fuzz/fuzz_until.py
index 280635b355..fc7ce8b245 100644
--- a/test/fuzz/fuzz_until.py
+++ b/test/fuzz/fuzz_until.py
@@ -72,9 +72,9 @@ class Supervisor:
         self.latest_n_inputs = 0
         self.latest_new_path = self.start_time
 
-    def criterias_satisfied(self) -> bool:
+    def criteria_satisfied(self) -> bool:
         """Indicates whether stopping criteria of the corresponding fuzzer
-        are satisfied. E.g. it was running long enogh and covered paths."""
+        are satisfied. E.g. it was running long enough and covered enough paths."""
 
         # Coverage increased at least twice in comparison with corpus
         cov = False
@@ -164,7 +164,5 @@ class Supervisor:
 # The script takes the fuzzing target name as the first argument.
 # Then it runs the fuzzing target until either stopping criterias are satisfied
 # or fuzzer detects a bug and fails.
-# TODO: support running several fuzzers
 if __name__ == "__main__":
     Supervisor(sys.argv[1]).run()
-    pass
-- 
GitLab