aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--infra/cifuzz/cifuzz.py4
-rw-r--r--infra/cifuzz/cifuzz_test.py42
-rw-r--r--infra/cifuzz/fuzz_target.py4
3 files changed, 42 insertions, 8 deletions
diff --git a/infra/cifuzz/cifuzz.py b/infra/cifuzz/cifuzz.py
index b00df6d6..fdb6207b 100644
--- a/infra/cifuzz/cifuzz.py
+++ b/infra/cifuzz/cifuzz.py
@@ -165,6 +165,8 @@ def build_fuzzers( # pylint: disable=too-many-arguments,too-many-locals
'-e',
'ARCHITECTURE=' + DEFAULT_ARCHITECTURE,
'-e',
+ 'CIFUZZ=True',
+ '-e',
'FUZZING_LANGUAGE=c++', # FIXME: Add proper support.
]
container = utils.get_container_name()
@@ -292,6 +294,8 @@ def check_fuzzer_build(out_dir, sanitizer='address'):
'-e',
'ARCHITECTURE=' + DEFAULT_ARCHITECTURE,
'-e',
+ 'CIFUZZ=True',
+ '-e',
'FUZZING_LANGUAGE=c++', # FIXME: Add proper support.
]
diff --git a/infra/cifuzz/cifuzz_test.py b/infra/cifuzz/cifuzz_test.py
index 741c41e0..e7624f54 100644
--- a/infra/cifuzz/cifuzz_test.py
+++ b/infra/cifuzz/cifuzz_test.py
@@ -64,6 +64,36 @@ UNDEFINED_FUZZER = 'curl_fuzzer_undefined'
# pylint: disable=no-self-use
+class BuildFuzzersTest(unittest.TestCase):
+ """Unit tests for build_fuzzers."""
+
+ @mock.patch('build_specified_commit.detect_main_repo',
+ return_value=('example.com', '/path'))
+ @mock.patch('repo_manager.RepoManager', return_value=None)
+ @mock.patch('cifuzz.checkout_specified_commit')
+ @mock.patch('helper.docker_run')
+ def test_cifuzz_env_var(self, mocked_docker_run, _, __, ___):
+ """Tests that the CIFUZZ env var is set."""
+
+ with tempfile.TemporaryDirectory() as tmp_dir:
+ cifuzz.build_fuzzers(EXAMPLE_PROJECT,
+ EXAMPLE_PROJECT,
+ tmp_dir,
+ pr_ref='refs/pull/1757/merge')
+ docker_run_command = mocked_docker_run.call_args_list[0][0][0]
+
+ def command_has_env_var_arg(command, env_var_arg):
+ for idx, element in enumerate(command):
+ if idx == 0:
+ continue
+
+ if element == env_var_arg and command[idx - 1] == '-e':
+ return True
+ return False
+
+ self.assertTrue(command_has_env_var_arg(docker_run_command, 'CIFUZZ=True'))
+
+
class BuildFuzzersIntegrationTest(unittest.TestCase):
"""Integration tests for build_fuzzers."""
@@ -333,11 +363,11 @@ class GetFilesCoveredByTargetTest(unittest.TestCase):
example_fuzzer = 'curl_fuzzer'
def setUp(self):
- with open(os.path.join(TEST_FILES_PATH, self.example_cov_json)
- ) as file_handle:
+ with open(os.path.join(TEST_FILES_PATH,
+ self.example_cov_json)) as file_handle:
self.proj_cov_report_example = json.loads(file_handle.read())
- with open(os.path.join(TEST_FILES_PATH, self.example_fuzzer_cov_json)
- ) as file_handle:
+ with open(os.path.join(TEST_FILES_PATH,
+ self.example_fuzzer_cov_json)) as file_handle:
self.fuzzer_cov_report_example = json.loads(file_handle.read())
def test_valid_target(self):
@@ -349,8 +379,8 @@ class GetFilesCoveredByTargetTest(unittest.TestCase):
file_list = cifuzz.get_files_covered_by_target(
self.proj_cov_report_example, self.example_fuzzer, '/src/curl')
- curl_files_list_path = os.path.join(
- TEST_FILES_PATH, 'example_curl_file_list.json')
+ curl_files_list_path = os.path.join(TEST_FILES_PATH,
+ 'example_curl_file_list.json')
with open(curl_files_list_path) as file_handle:
true_files_list = json.load(file_handle)
self.assertCountEqual(file_list, true_files_list)
diff --git a/infra/cifuzz/fuzz_target.py b/infra/cifuzz/fuzz_target.py
index 176f2308..ae85d49d 100644
--- a/infra/cifuzz/fuzz_target.py
+++ b/infra/cifuzz/fuzz_target.py
@@ -125,8 +125,8 @@ class FuzzTarget:
command += [
'-e', 'FUZZING_ENGINE=libfuzzer', '-e', 'SANITIZER=' + self.sanitizer,
- '-e', 'RUN_FUZZER_MODE=interactive', 'gcr.io/oss-fuzz-base/base-runner',
- 'bash', '-c'
+ '-e', 'CIFUZZ=True', '-e', 'RUN_FUZZER_MODE=interactive',
+ 'gcr.io/oss-fuzz-base/base-runner', 'bash', '-c'
]
run_fuzzer_command = 'run_fuzzer {fuzz_target} {options}'.format(