aboutsummaryrefslogtreecommitdiffhomepage
path: root/infra/cifuzz/run_fuzzers.py
diff options
context:
space:
mode:
authorGravatar jonathanmetzman <31354670+jonathanmetzman@users.noreply.github.com>2021-08-10 11:10:10 -0700
committerGravatar GitHub <noreply@github.com>2021-08-10 11:10:10 -0700
commit94cfc4fe2f0c9743ab7acd19910d6961f2317eeb (patch)
treea4b0b54cd2c6ed7556bad15b31dc7e1f3c046086 /infra/cifuzz/run_fuzzers.py
parente407f54e61a134de43019d69947a72a471bdd7c6 (diff)
[cifuzz] Add pruning task (#6188)
Fixes: #6064
Diffstat (limited to 'infra/cifuzz/run_fuzzers.py')
-rw-r--r--infra/cifuzz/run_fuzzers.py43
1 files changed, 35 insertions, 8 deletions
diff --git a/infra/cifuzz/run_fuzzers.py b/infra/cifuzz/run_fuzzers.py
index 93a30a37..79cf432c 100644
--- a/infra/cifuzz/run_fuzzers.py
+++ b/infra/cifuzz/run_fuzzers.py
@@ -166,6 +166,26 @@ class BaseFuzzTargetRunner:
return bug_found
+class PruneTargetRunner(BaseFuzzTargetRunner):
+ """Runner that prunes corpora."""
+
+ @property
+ def quit_on_bug_found(self):
+ return False
+
+ def run_fuzz_target(self, fuzz_target_obj):
+ """Prunes with |fuzz_target_obj| and returns the result."""
+ result = fuzz_target_obj.prune()
+ logging.debug('Corpus path contents: %s.', os.listdir(result.corpus_path))
+ self.clusterfuzz_deployment.upload_corpus(fuzz_target_obj.target_name,
+ result.corpus_path)
+ return result
+
+ def cleanup_after_fuzz_target_run(self, fuzz_target_obj): # pylint: disable=no-self-use
+ """Cleans up after pruning with |fuzz_target_obj|."""
+ fuzz_target_obj.free_disk_if_needed()
+
+
class CoverageTargetRunner(BaseFuzzTargetRunner):
"""Runner that runs the 'coverage' command."""
@@ -224,8 +244,9 @@ class BatchFuzzTargetRunner(BaseFuzzTargetRunner):
def run_fuzz_target(self, fuzz_target_obj):
"""Fuzzes with |fuzz_target_obj| and returns the result."""
result = fuzz_target_obj.fuzz()
- logging.debug('corpus_path: %s', os.listdir(result.corpus_path))
- self.clusterfuzz_deployment.upload_corpus(fuzz_target_obj.target_name)
+ logging.debug('Corpus path contents: %s.', os.listdir(result.corpus_path))
+ self.clusterfuzz_deployment.upload_corpus(fuzz_target_obj.target_name,
+ result.corpus_path)
return result
def cleanup_after_fuzz_target_run(self, fuzz_target_obj):
@@ -255,15 +276,21 @@ class BatchFuzzTargetRunner(BaseFuzzTargetRunner):
return result
+_RUN_FUZZERS_MODE_RUNNER_MAPPING = {
+ 'batch': BatchFuzzTargetRunner,
+ 'coverage': CoverageTargetRunner,
+ 'prune': PruneTargetRunner,
+ 'ci': CiFuzzTargetRunner,
+}
+
+
def get_fuzz_target_runner(config):
"""Returns a fuzz target runner object based on the run_fuzzers_mode of
|config|."""
- logging.info('RUN_FUZZERS_MODE is: %s', config.run_fuzzers_mode)
- if config.run_fuzzers_mode == 'batch':
- return BatchFuzzTargetRunner(config)
- if config.run_fuzzers_mode == 'coverage':
- return CoverageTargetRunner(config)
- return CiFuzzTargetRunner(config)
+ runner = _RUN_FUZZERS_MODE_RUNNER_MAPPING[config.run_fuzzers_mode](config)
+ logging.info('RUN_FUZZERS_MODE is: %s. Runner: %s.', config.run_fuzzers_mode,
+ runner)
+ return runner
def run_fuzzers(config): # pylint: disable=too-many-locals