aboutsummaryrefslogtreecommitdiff
path: root/infra
diff options
context:
space:
mode:
authorjonathanmetzman <31354670+jonathanmetzman@users.noreply.github.com>2020-12-07 10:16:31 -0800
committerGitHub <noreply@github.com>2020-12-07 10:16:31 -0800
commita24cebec02a0c97247bef31963d5f5fadbaa4ebf (patch)
treee613af7a5e765a10fe0494f92fe0b308eba2d6b8 /infra
parent87271d17214a2306df0bd1d83785f0f013d0724a (diff)
downloadoss-fuzz-a24cebec02a0c97247bef31963d5f5fadbaa4ebf.tar.gz
Make test_all.py return nonzero when there are no fuzzers. (#4796)
Make test_all.py return nonzero when there are no fuzzers. This matches the previous behavior. Fixes https://github.com/google/oss-fuzz/issues/4795
Diffstat (limited to 'infra')
-rwxr-xr-xinfra/base-images/base-runner/test_all.py4
-rw-r--r--infra/base-images/base-runner/test_test_all.py40
2 files changed, 44 insertions, 0 deletions
diff --git a/infra/base-images/base-runner/test_all.py b/infra/base-images/base-runner/test_all.py
index 1524483df..dfa38260f 100755
--- a/infra/base-images/base-runner/test_all.py
+++ b/infra/base-images/base-runner/test_all.py
@@ -152,6 +152,10 @@ def test_all(out, fuzzing_language, allowed_broken_targets_percentage):
"""Do bad_build_check on all fuzz targets."""
# TODO(metzman): Refactor so that we can convert test_one to python.
fuzz_targets = find_fuzz_targets(out, fuzzing_language)
+ if not fuzz_targets:
+ print('ERROR: No fuzz targets found.')
+ return False
+
pool = multiprocessing.Pool()
bad_build_results = pool.map(do_bad_build_check, fuzz_targets)
broken_targets = get_broken_fuzz_targets(bad_build_results, fuzz_targets)
diff --git a/infra/base-images/base-runner/test_test_all.py b/infra/base-images/base-runner/test_test_all.py
new file mode 100644
index 000000000..3771ec231
--- /dev/null
+++ b/infra/base-images/base-runner/test_test_all.py
@@ -0,0 +1,40 @@
+# Copyright 2020 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 test_all.py"""
+import unittest
+from unittest import mock
+
+import test_all
+
+
+class TestTestAll(unittest.TestCase):
+ """Tests for the test_all_function."""
+
+ @mock.patch('test_all.find_fuzz_targets', return_value=[])
+ @mock.patch('builtins.print')
+ def test_test_all_no_fuzz_targets(self, mocked_print, _):
+ """Tests that test_all returns False when there are no fuzz targets."""
+ outdir = '/out'
+ fuzzing_language = 'c++'
+ allowed_broken_targets_percentage = 0
+ self.assertFalse(
+ test_all.test_all(outdir, fuzzing_language,
+ allowed_broken_targets_percentage))
+ mocked_print.assert_called_with('ERROR: No fuzz targets found.')
+
+
+if __name__ == '__main__':
+ unittest.main()