aboutsummaryrefslogtreecommitdiffhomepage
path: root/infra/bisector_test.py
blob: d93ac323980a19b308029e08a3a49d3ec650e749 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# 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.
"""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.

IMPORTANT: This test needs to be run with root privileges.
"""

import os
import unittest

import bisector
import build_specified_commit
import test_repos

# Necessary because __file__ changes with os.chdir
TEST_DIR_PATH = os.path.dirname(os.path.realpath(__file__))


@unittest.skip('Test is too long to be run with presubmit.')
class BisectIntegrationTests(unittest.TestCase):
  """Class to test the functionality of bisection method."""

  BISECT_TYPE = 'regressed'

  def test_bisect_invalid_repo(self):
    """Test the bisection method on a project that does not exist."""
    test_repo = test_repos.INVALID_REPO
    build_data = build_specified_commit.BuildData(
        project_name=test_repo.project_name,
        engine='libfuzzer',
        sanitizer='address',
        architecture='x86_64')
    with self.assertRaises(ValueError):
      bisector.bisect(self.BISECT_TYPE, test_repo.old_commit,
                      test_repo.new_commit, test_repo.testcase_path,
                      test_repo.fuzz_target, build_data)

  def test_bisect(self):
    """Test the bisect method on example projects."""
    for test_repo in test_repos.TEST_REPOS:
      if test_repo.new_commit:
        build_data = build_specified_commit.BuildData(
            project_name=test_repo.project_name,
            engine='libfuzzer',
            sanitizer='address',
            architecture='x86_64')
        result = bisector.bisect(self.BISECT_TYPE, test_repo.old_commit,
                                 test_repo.new_commit, test_repo.testcase_path,
                                 test_repo.fuzz_target, build_data)
        self.assertEqual(result.commit, test_repo.intro_commit)


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()