aboutsummaryrefslogtreecommitdiffhomepage
path: root/infra/cifuzz/generate_coverage_report_test.py
diff options
context:
space:
mode:
authorGravatar jonathanmetzman <31354670+jonathanmetzman@users.noreply.github.com>2021-06-23 07:30:11 -0700
committerGravatar GitHub <noreply@github.com>2021-06-23 07:30:11 -0700
commit343e1b2d3368fffc341910c7886aa33961590c1a (patch)
tree6279a423292f5202d8698070bb7e20c2d706d6db /infra/cifuzz/generate_coverage_report_test.py
parent1a77d6c33f62c473e919397cad4dfdbc0e463daa (diff)
[CIFuzz] Add coverage report generation. (#5937)
Also: 1. Support coverage builds. 2. Add an integration test for coverage builds and reports. 3. Refactor docker code so that there is less duplication in getting arguments for docker run, in particular when handling container (production) vs no container (testing). 4. Rename coverage.py to get_coverage_report. 5. Add tests for untested functions in docker.py 6. Add a test for get_fuzz_target_runner.
Diffstat (limited to 'infra/cifuzz/generate_coverage_report_test.py')
-rw-r--r--infra/cifuzz/generate_coverage_report_test.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/infra/cifuzz/generate_coverage_report_test.py b/infra/cifuzz/generate_coverage_report_test.py
new file mode 100644
index 00000000..461cd7ca
--- /dev/null
+++ b/infra/cifuzz/generate_coverage_report_test.py
@@ -0,0 +1,60 @@
+# Copyright 2021 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""Tests for generate_coverage_report."""
+
+import unittest
+from unittest import mock
+
+import generate_coverage_report
+import test_helpers
+
+OUT_DIR = '/outdir'
+PROJECT = 'example-project'
+SANITIZER = 'coverage'
+
+
+class TestRunCoverageCommand(unittest.TestCase):
+ """Tests run_coverage_command"""
+
+ @mock.patch('helper.docker_run')
+ def test_run_coverage_command(self, mocked_docker_run): # pylint: disable=no-self-use
+ """Tests that run_coverage_command works as intended."""
+ 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++', '-v',
+ f'{OUT_DIR}:/out', '-e', 'COVERAGE_EXTRA_ARGS=', '-e', 'HTTP_PORT=',
+ '-t', 'gcr.io/oss-fuzz-base/base-runner', 'coverage'
+ ]
+
+ config = test_helpers.create_run_config(project_name=PROJECT,
+ sanitizer=SANITIZER)
+ generate_coverage_report.run_coverage_command(OUT_DIR, config)
+ mocked_docker_run.assert_called_with(expected_docker_args)
+
+
+class DownloadCorporaTest(unittest.TestCase):
+ """Tests for download_corpora."""
+
+ def test_download_corpora(self): # pylint: disable=no-self-use
+ """Tests that download_corpora works as intended."""
+ clusterfuzz_deployment = mock.Mock()
+ fuzz_target_paths = ['/path/to/fuzzer1', '/path/to/fuzzer2']
+ expected_calls = [
+ mock.call('fuzzer1', OUT_DIR),
+ mock.call('fuzzer2', OUT_DIR)
+ ]
+ generate_coverage_report.download_corpora(OUT_DIR, fuzz_target_paths,
+ clusterfuzz_deployment)
+ clusterfuzz_deployment.download_corpus.assert_has_calls(expected_calls)