1# Copyright 2019 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 perepo_managerissions and 13# limitations under the License. 14"""Test the functionality of bisection module: 151) Test a known case where an error appears in a regression range. 162) Bisect can handle incorrect inputs. 17 18IMPORTANT: This test needs to be run with root privileges. 19""" 20 21import os 22import unittest 23 24import bisector 25import build_specified_commit 26import test_repos 27 28# Necessary because __file__ changes with os.chdir 29TEST_DIR_PATH = os.path.dirname(os.path.realpath(__file__)) 30 31 32@unittest.skip('Test is too long to be run with presubmit.') 33class BisectIntegrationTests(unittest.TestCase): 34 """Class to test the functionality of bisection method.""" 35 36 BISECT_TYPE = 'regressed' 37 38 def test_bisect_invalid_repo(self): 39 """Test the bisection method on a project that does not exist.""" 40 test_repo = test_repos.INVALID_REPO 41 build_data = build_specified_commit.BuildData( 42 project_name=test_repo.project_name, 43 engine='libfuzzer', 44 sanitizer='address', 45 architecture='x86_64') 46 with self.assertRaises(ValueError): 47 bisector.bisect(self.BISECT_TYPE, test_repo.old_commit, 48 test_repo.new_commit, test_repo.testcase_path, 49 test_repo.fuzz_target, build_data) 50 51 def test_bisect(self): 52 """Test the bisect method on example projects.""" 53 for test_repo in test_repos.TEST_REPOS: 54 if test_repo.new_commit: 55 build_data = build_specified_commit.BuildData( 56 project_name=test_repo.project_name, 57 engine='libfuzzer', 58 sanitizer='address', 59 architecture='x86_64') 60 result = bisector.bisect(self.BISECT_TYPE, test_repo.old_commit, 61 test_repo.new_commit, test_repo.testcase_path, 62 test_repo.fuzz_target, build_data) 63 self.assertEqual(result.commit, test_repo.intro_commit) 64 65 66if __name__ == '__main__': 67 # Change to oss-fuzz main directory so helper.py runs correctly. 68 if os.getcwd() != os.path.dirname(TEST_DIR_PATH): 69 os.chdir(os.path.dirname(TEST_DIR_PATH)) 70 unittest.main() 71