1# Copyright 2021 Google LLC 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14"""End-to-End tests for CIFuzz.""" 15import os 16import unittest 17 18import run_cifuzz 19import test_helpers 20 21CIFUZZ_DIR = os.path.dirname(os.path.abspath(__file__)) 22EXTERNAL_PROJECT_PATH = os.path.join(CIFUZZ_DIR, 'test_data', 23 'external-project') 24 25 26# This test will fail if not run as root because the fuzzer build process 27# creates binaries that only root can write to. 28# Use a seperate env var to keep this seperate from integration tests which 29# don't have this annoying property. 30@unittest.skipIf(not os.getenv('END_TO_END_TESTS'), 31 'END_TO_END_TESTS=1 not set') 32class EndToEndTest(unittest.TestCase): 33 """End-to-End tests for CIFuzz.""" 34 35 def setUp(self): 36 test_helpers.patch_environ(self, runner=True) 37 38 def test_simple(self): 39 """Simple end-to-end test using run_cifuzz.main().""" 40 os.environ['REPOSITORY'] = 'external-project' 41 os.environ['PROJECT_SRC_PATH'] = EXTERNAL_PROJECT_PATH 42 43 with test_helpers.docker_temp_dir() as temp_dir: 44 os.environ['WORKSPACE'] = temp_dir 45 # TODO(metzman): Verify the crash, affected fuzzers, and other things. 46 self.assertEqual(run_cifuzz.main(), 1) 47