2020-01-06 20:17:26 +00:00
|
|
|
# Copyright 2019 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 perepo_managerissions and
|
|
|
|
# limitations under the License.
|
2020-01-15 21:30:57 +00:00
|
|
|
"""Test the functionality of bisection module:
|
|
|
|
1) Test a known case where an error appears in a regression range.
|
|
|
|
2) Bisect can handle incorrect inputs.
|
2020-01-30 18:27:56 +00:00
|
|
|
|
|
|
|
IMPORTANT: This test needs to be run with root privileges.
|
2020-01-06 20:17:26 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
import bisector
|
2020-01-15 21:30:57 +00:00
|
|
|
import build_specified_commit
|
2020-01-30 18:27:56 +00:00
|
|
|
import test_repos
|
2020-01-06 20:17:26 +00:00
|
|
|
|
|
|
|
# Necessary because __file__ changes with os.chdir
|
|
|
|
TEST_DIR_PATH = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
|
|
|
|
|
2020-01-30 18:27:56 +00:00
|
|
|
class BisectIntegrationTests(unittest.TestCase):
|
2020-01-15 21:30:57 +00:00
|
|
|
"""Class to test the functionality of bisection method."""
|
2020-01-06 20:17:26 +00:00
|
|
|
|
|
|
|
def test_bisect_invalid_repo(self):
|
2020-01-15 21:30:57 +00:00
|
|
|
"""Test the bisection method on a project that does not exist."""
|
2020-01-30 18:27:56 +00:00
|
|
|
test_repo = test_repos.INVALID_REPO
|
2020-01-23 17:48:09 +00:00
|
|
|
build_data = build_specified_commit.BuildData(
|
2020-01-30 18:27:56 +00:00
|
|
|
project_name=test_repo.project_name,
|
2020-01-23 17:48:09 +00:00
|
|
|
engine='libfuzzer',
|
|
|
|
sanitizer='address',
|
|
|
|
architecture='x86_64')
|
2020-01-06 20:17:26 +00:00
|
|
|
with self.assertRaises(ValueError):
|
2020-01-30 18:27:56 +00:00
|
|
|
bisector.bisect(test_repo.old_commit, test_repo.new_commit,
|
|
|
|
test_repo.test_case_path, test_repo.fuzz_target,
|
|
|
|
build_data)
|
2020-01-23 17:48:09 +00:00
|
|
|
|
2020-01-30 18:27:56 +00:00
|
|
|
def test_bisect(self):
|
|
|
|
"""Test the bisect method on example projects."""
|
|
|
|
for test_repo in test_repos.TEST_REPOS:
|
|
|
|
build_data = build_specified_commit.BuildData(
|
|
|
|
project_name=test_repo.project_name,
|
|
|
|
engine='libfuzzer',
|
|
|
|
sanitizer='address',
|
|
|
|
architecture='x86_64')
|
|
|
|
error_sha = bisector.bisect(test_repo.old_commit, test_repo.new_commit,
|
|
|
|
test_repo.test_case_path,
|
|
|
|
test_repo.fuzz_target, build_data)
|
|
|
|
self.assertEqual(error_sha, test_repo.intro_commit)
|
2020-01-06 20:17:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
# Change to oss-fuzz main directory so helper.py runs correctly.
|
|
|
|
if os.getcwd() != os.path.dirname(TEST_DIR_PATH):
|
|
|
|
os.chdir(os.path.dirname(TEST_DIR_PATH))
|
|
|
|
unittest.main()
|