[infra][NFC] Use "testcase" instead of test_case for consistency. (#6159)

This commit is contained in:
jonathanmetzman 2021-08-03 18:05:00 -07:00 committed by GitHub
parent 0ea44bb355
commit 6f0238764e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 33 deletions

View File

@ -105,7 +105,7 @@ def main():
architecture=args.architecture)
result = bisect(args.type, args.old_commit, args.new_commit,
args.test_case_path, args.fuzz_target, build_data)
args.testcase_path, args.fuzz_target, build_data)
if not result.commit:
logging.error('No error was found in commit range %s:%s', args.old_commit,
args.new_commit)
@ -131,7 +131,7 @@ def _get_dedup_token(output):
return None
def _check_for_crash(project_name, fuzz_target, test_case_path):
def _check_for_crash(project_name, fuzz_target, testcase_path):
"""Check for crash."""
def docker_run(args):
@ -145,7 +145,7 @@ def _check_for_crash(project_name, fuzz_target, test_case_path):
out, err, return_code = helper.reproduce_impl(project_name,
fuzz_target,
False, [], [],
test_case_path,
testcase_path,
run_function=docker_run,
err_result=(None, None, None))
if return_code is None:
@ -167,7 +167,7 @@ def _check_for_crash(project_name, fuzz_target, test_case_path):
# pylint: disable=too-many-locals
# pylint: disable=too-many-arguments
# pylint: disable=too-many-statements
def _bisect(bisect_type, old_commit, new_commit, test_case_path, fuzz_target,
def _bisect(bisect_type, old_commit, new_commit, testcase_path, fuzz_target,
build_data):
"""Perform the bisect."""
# pylint: disable=too-many-branches
@ -212,7 +212,7 @@ def _bisect(bisect_type, old_commit, new_commit, test_case_path, fuzz_target,
raise BisectError('Invalid bisect type ' + bisect_type, repo_url)
expected_error = _check_for_crash(build_data.project_name, fuzz_target,
test_case_path)
testcase_path)
logging.info('new_commit result = %s', expected_error)
if not should_crash and expected_error:
@ -231,7 +231,7 @@ def _bisect(bisect_type, old_commit, new_commit, test_case_path, fuzz_target,
raise BisectError('Failed to build old_commit', repo_url)
if _check_for_crash(build_data.project_name, fuzz_target,
test_case_path) == expected_error:
testcase_path) == expected_error:
logging.warning('old_commit %s had same result as new_commit %s',
old_commit, new_commit)
# Try again on an slightly older commit.
@ -266,7 +266,7 @@ def _bisect(bisect_type, old_commit, new_commit, test_case_path, fuzz_target,
continue
current_error = _check_for_crash(build_data.project_name, fuzz_target,
test_case_path)
testcase_path)
logging.info('Current result = %s', current_error)
if expected_error == current_error:
new_idx = curr_idx
@ -277,16 +277,16 @@ def _bisect(bisect_type, old_commit, new_commit, test_case_path, fuzz_target,
# pylint: disable=too-many-locals
# pylint: disable=too-many-arguments
def bisect(bisect_type, old_commit, new_commit, test_case_path, fuzz_target,
def bisect(bisect_type, old_commit, new_commit, testcase_path, fuzz_target,
build_data):
"""From a commit range, this function caluclates which introduced a
specific error from a fuzz test_case_path.
specific error from a fuzz testcase_path.
Args:
bisect_type: The type of the bisect ('regressed' or 'fixed').
old_commit: The oldest commit in the error regression range.
new_commit: The newest commit in the error regression range.
test_case_path: The file path of the test case that triggers the error
testcase_path: The file path of the test case that triggers the error
fuzz_target: The name of the fuzzer to be tested.
build_data: a class holding all of the input parameters for bisection.
@ -297,7 +297,7 @@ def bisect(bisect_type, old_commit, new_commit, test_case_path, fuzz_target,
ValueError: when a repo url can't be determine from the project.
"""
try:
return _bisect(bisect_type, old_commit, new_commit, test_case_path,
return _bisect(bisect_type, old_commit, new_commit, testcase_path,
fuzz_target, build_data)
finally:
# Clean up projects/ as _bisect may have modified it.

View File

@ -45,7 +45,7 @@ class BisectIntegrationTests(unittest.TestCase):
architecture='x86_64')
with self.assertRaises(ValueError):
bisector.bisect(self.BISECT_TYPE, test_repo.old_commit,
test_repo.new_commit, test_repo.test_case_path,
test_repo.new_commit, test_repo.testcase_path,
test_repo.fuzz_target, build_data)
def test_bisect(self):
@ -58,7 +58,7 @@ class BisectIntegrationTests(unittest.TestCase):
sanitizer='address',
architecture='x86_64')
result = bisector.bisect(self.BISECT_TYPE, test_repo.old_commit,
test_repo.new_commit, test_repo.test_case_path,
test_repo.new_commit, test_repo.testcase_path,
test_repo.fuzz_target, build_data)
self.assertEqual(result.commit, test_repo.intro_commit)

View File

@ -27,7 +27,7 @@ import helper
import repo_manager
import test_repos
# Necessary because __file__ changes with os.chdir
# necessary because __file__ changes with os.chdir
TEST_DIR_PATH = os.path.dirname(os.path.realpath(__file__))
@ -45,31 +45,34 @@ class BuildImageIntegrationTest(unittest.TestCase):
should not.
"""
with tempfile.TemporaryDirectory() as tmp_dir:
test_case = test_repos.TEST_REPOS[1]
self.assertTrue(helper.build_image_impl(test_case.project_name))
test_repo = test_repos.TEST_REPOS[1]
self.assertTrue(helper.build_image_impl(test_repo.project_name))
host_src_dir = build_specified_commit.copy_src_from_docker(
test_case.project_name, tmp_dir)
test_repo.project_name, tmp_dir)
test_repo_manager = repo_manager.clone_repo_and_get_manager(
test_case.git_url, host_src_dir, test_case.oss_repo_name)
test_repo.git_url, host_src_dir, test_repo.oss_repo_name)
build_data = build_specified_commit.BuildData(
sanitizer='address',
architecture='x86_64',
engine='libfuzzer',
project_name=test_case.project_name)
project_name=test_repo.project_name)
build_specified_commit.build_fuzzers_from_commit(test_case.old_commit,
build_specified_commit.build_fuzzers_from_commit(test_repo.old_commit,
test_repo_manager,
host_src_dir, build_data)
old_result = helper.reproduce_impl(test_case.project_name,
test_case.fuzz_target, False, [], [],
test_case.test_case_path)
build_specified_commit.build_fuzzers_from_commit(test_case.new_commit,
old_result = helper.reproduce_impl(project_name=test_repo.project_name,
fuzzer_name=test_repo.fuzz_target,
valgrind=False,
env_to_add=[],
fuzzer_args=[],
testcase_path=test_repo.testcase_path)
build_specified_commit.build_fuzzers_from_commit(test_repo.project_name,
test_repo_manager,
host_src_dir, build_data)
new_result = helper.reproduce_impl(test_case.project_name,
test_case.fuzz_target, False, [], [],
test_case.test_case_path)
new_result = helper.reproduce_impl(test_repo.project_name,
test_repo.fuzz_target, False, [], [],
test_repo.testcase_path)
self.assertNotEqual(new_result, old_result)
def test_detect_main_repo_from_commit(self):

View File

@ -27,7 +27,7 @@ import os
ExampleRepo = collections.namedtuple('ExampleRepo', [
'project_name', 'oss_repo_name', 'git_repo_name', 'image_location',
'git_url', 'new_commit', 'old_commit', 'intro_commit', 'fuzz_target',
'test_case_path'
'testcase_path'
])
TEST_DIR_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)),
@ -36,6 +36,8 @@ TEST_DIR_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)),
# WARNING: Tests are dependent upon the following repos existing and the
# specified commits existing.
# TODO(metzman): Fix this problem.
# TODO(metzman): The testcases got deleted here because the test that used them
# was skipped. Probably worth deleting the test.
TEST_REPOS = [
ExampleRepo(project_name='curl',
oss_repo_name='curl',
@ -46,7 +48,7 @@ TEST_REPOS = [
new_commit='dda418266c99ceab368d723facb52069cbb9c8d5',
intro_commit='df26f5f9c36e19cd503c0e462e9f72ad37b84c82',
fuzz_target='curl_fuzzer_ftp',
test_case_path=os.path.join(TEST_DIR_PATH, 'curl_test_data')),
testcase_path=os.path.join(TEST_DIR_PATH, 'curl_test_data')),
ExampleRepo(project_name='libarchive',
oss_repo_name='libarchive',
git_repo_name='libarchive',
@ -56,8 +58,8 @@ TEST_REPOS = [
new_commit='458e49358f17ec58d65ab1c45cf299baaf3c98d1',
intro_commit='840266712006de5e737f8052db920dfea2be4260',
fuzz_target='libarchive_fuzzer',
test_case_path=os.path.join(TEST_DIR_PATH,
'libarchive_test_data')),
testcase_path=os.path.join(TEST_DIR_PATH,
'libarchive_test_data')),
ExampleRepo(project_name='gonids',
oss_repo_name='gonids',
git_repo_name='gonids',
@ -67,7 +69,7 @@ TEST_REPOS = [
new_commit='',
intro_commit='',
fuzz_target='',
test_case_path='')
testcase_path='')
]
INVALID_REPO = ExampleRepo(project_name='notaproj',
@ -79,4 +81,4 @@ INVALID_REPO = ExampleRepo(project_name='notaproj',
new_commit='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
intro_commit='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
fuzz_target='NONEFUZZER',
test_case_path='not/a/path')
testcase_path='not/a/path')