2019-07-19 13:20:14 -04:00
|
|
|
"""The libfuzzertest.TestCase for C++ libfuzzer tests."""
|
|
|
|
|
|
|
|
|
|
import datetime
|
2020-06-17 17:41:54 +03:00
|
|
|
import os
|
2024-05-14 11:07:04 -07:00
|
|
|
from typing import Optional
|
2019-07-19 13:20:14 -04:00
|
|
|
|
2024-05-14 11:07:04 -07:00
|
|
|
from buildscripts.resmokelib import core, logging, utils
|
2020-06-17 17:41:54 +03:00
|
|
|
from buildscripts.resmokelib.testing.testcases import interface
|
2019-07-19 13:20:14 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class CPPLibfuzzerTestCase(interface.ProcessTestCase):
|
|
|
|
|
"""A C++ libfuzzer test to execute."""
|
|
|
|
|
|
|
|
|
|
REGISTERED_NAME = "cpp_libfuzzer_test"
|
|
|
|
|
DEFAULT_TIMEOUT = datetime.timedelta(hours=1)
|
|
|
|
|
|
2024-05-16 18:00:17 -04:00
|
|
|
def __init__(
|
|
|
|
|
self,
|
|
|
|
|
logger: logging.Logger,
|
|
|
|
|
program_executables: list[str],
|
|
|
|
|
program_options: Optional[dict] = None,
|
|
|
|
|
runs: int = 1000000,
|
|
|
|
|
corpus_directory_stem="corpora",
|
|
|
|
|
):
|
2019-07-19 13:20:14 -04:00
|
|
|
"""Initialize the CPPLibfuzzerTestCase with the executable to run."""
|
|
|
|
|
|
2024-05-14 11:07:04 -07:00
|
|
|
assert len(program_executables) == 1
|
2024-05-16 18:00:17 -04:00
|
|
|
interface.ProcessTestCase.__init__(
|
|
|
|
|
self, logger, "C++ libfuzzer test", program_executables[0]
|
|
|
|
|
)
|
2019-07-19 13:20:14 -04:00
|
|
|
|
2024-05-14 11:07:04 -07:00
|
|
|
self.program_executable = program_executables[0]
|
2019-07-19 13:20:14 -04:00
|
|
|
self.program_options = utils.default_if_none(program_options, {}).copy()
|
2021-03-10 19:42:36 +00:00
|
|
|
|
|
|
|
|
self.runs = runs
|
|
|
|
|
|
|
|
|
|
self.corpus_directory = f"{corpus_directory_stem}/corpus-{self.short_name()}"
|
|
|
|
|
self.merged_corpus_directory = f"{corpus_directory_stem}-merged/corpus-{self.short_name()}"
|
2019-07-19 13:20:14 -04:00
|
|
|
|
|
|
|
|
os.makedirs(self.corpus_directory, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
def _make_process(self):
|
|
|
|
|
default_args = [
|
2021-03-10 19:42:36 +00:00
|
|
|
self.program_executable,
|
|
|
|
|
"-max_len=100000",
|
|
|
|
|
"-rss_limit_mb=5000",
|
2021-04-23 13:16:18 -04:00
|
|
|
"-max_total_time=3600", # 1 hour is the maximum amount of time to allow a fuzzer to run
|
2021-03-10 19:42:36 +00:00
|
|
|
f"-runs={self.runs}",
|
|
|
|
|
self.corpus_directory,
|
2019-07-19 13:20:14 -04:00
|
|
|
]
|
|
|
|
|
return core.programs.make_process(self.logger, default_args, **self.program_options)
|