def test_no_valid_fuzzers(self): """Tests that False is returned when an empty directory is given.""" with tempfile.TemporaryDirectory() as tmp_dir: workspace = test_helpers.create_workspace(tmp_dir) self.assertFalse( build_fuzzers.check_fuzzer_build(workspace, self.SANITIZER, self.LANGUAGE))
def test_download_corpora(self): # pylint: disable=no-self-use """Tests that download_corpora works as intended.""" clusterfuzz_deployment = mock.Mock() clusterfuzz_deployment.workspace = test_helpers.create_workspace() fuzz_target_paths = ['/path/to/fuzzer1', '/path/to/fuzzer2'] expected_calls = [ mock.call('fuzzer1', '/workspace/cifuzz-corpus/fuzzer1'), mock.call('fuzzer2', '/workspace/cifuzz-corpus/fuzzer2') ] generate_coverage_report.download_corpora(fuzz_target_paths, clusterfuzz_deployment) clusterfuzz_deployment.download_corpus.assert_has_calls(expected_calls)
def setUp(self): self.temp_dir_obj = tempfile.TemporaryDirectory() workspace_path = os.path.join(self.temp_dir_obj.name, 'workspace') self.config = test_helpers.create_build_config( oss_fuzz_project_name=EXAMPLE_PROJECT, sanitizer=self.SANITIZER, language=self.LANGUAGE, workspace=workspace_path, pr_ref='refs/pull/1757/merge') self.workspace = test_helpers.create_workspace(workspace_path) shutil.copytree(TEST_DATA_PATH, workspace_path) test_helpers.patch_environ(self, runner=True)
def test_run_coverage_command(self, mocked_docker_run): # pylint: disable=no-self-use """Tests that run_coverage_command works as intended.""" config = test_helpers.create_run_config(project_name=PROJECT, sanitizer=SANITIZER) workspace = test_helpers.create_workspace() expected_docker_args = [ '--cap-add', 'SYS_PTRACE', '-e', 'FUZZING_ENGINE=libfuzzer', '-e', 'ARCHITECTURE=x86_64', '-e', 'CIFUZZ=True', '-e', f'SANITIZER={SANITIZER}', '-e', 'FUZZING_LANGUAGE=c++', '-e', 'OUT=/workspace/build-out', '-v', f'{workspace.workspace}:{workspace.workspace}', '-e', 'COVERAGE_EXTRA_ARGS=', '-e', 'HTTP_PORT=', '-t', 'gcr.io/oss-fuzz-base/base-runner', 'coverage' ] generate_coverage_report.run_coverage_command(workspace, config) mocked_docker_run.assert_called_with(expected_docker_args)
def test_run_coverage_command(self, mock_execute): # pylint: disable=no-self-use """Tests that run_coverage_command works as intended.""" config = test_helpers.create_run_config(oss_fuzz_project_name=PROJECT, sanitizer=SANITIZER) workspace = test_helpers.create_workspace() generate_coverage_report.run_coverage_command(config, workspace) expected_command = 'coverage' expected_env = { 'SANITIZER': config.sanitizer, 'FUZZING_LANGUAGE': config.language, 'OUT': workspace.out, 'CIFUZZ': 'True', 'FUZZING_ENGINE': 'libfuzzer', 'ARCHITECTURE': 'x86_64', 'FUZZER_ARGS': '-rss_limit_mb=2560 -timeout=25', 'HTTP_PORT': '', 'COVERAGE_EXTRA_ARGS': '', 'CORPUS_DIR': workspace.corpora, 'COVERAGE_OUTPUT_DIR': workspace.coverage_report } mock_execute.assert_called_with(expected_command, env=expected_env)
def test_not_a_valid_path(self): """Tests that False is returned when a nonexistent path is given.""" workspace = test_helpers.create_workspace('not/a/valid/path') self.assertFalse( build_fuzzers.check_fuzzer_build(workspace, self.SANITIZER, self.LANGUAGE))
def setUp(self): self.tmp_dir_obj = tempfile.TemporaryDirectory() workspace_path = os.path.join(self.tmp_dir_obj.name, 'workspace') self.workspace = test_helpers.create_workspace(workspace_path) shutil.copytree(TEST_DATA_PATH, workspace_path)