aboutsummaryrefslogtreecommitdiff
path: root/infra/cifuzz/build_fuzzers_test.py
diff options
context:
space:
mode:
authorjonathanmetzman <31354670+jonathanmetzman@users.noreply.github.com>2021-05-26 09:45:22 -0700
committerGitHub <noreply@github.com>2021-05-26 09:45:22 -0700
commit8c4ad095e93d2d2909a762ed920b174926700177 (patch)
treed9308c318c5fc50cae6a8df650a697468c72949a /infra/cifuzz/build_fuzzers_test.py
parent8d313798ab2a2ae4d1388fd2cbcbe38028b69b67 (diff)
downloadoss-fuzz-8c4ad095e93d2d2909a762ed920b174926700177.tar.gz
[CIFuzz] Refactor in preparation for filestore (#5841)
1. Moving the _create_config and create_config functions from build_fuzzers_test.py and run_fuzzers_test.py into test_helpers.py (which is now part of cifuzz instead of infra) and share code between them. 2. Rename artifacts_dir to crashes_dir in run_fuzzers.py. "artifacts" is ambiguous. 3. Make some small changes to pytest.ini to improve debugging.
Diffstat (limited to 'infra/cifuzz/build_fuzzers_test.py')
-rw-r--r--infra/cifuzz/build_fuzzers_test.py126
1 files changed, 56 insertions, 70 deletions
diff --git a/infra/cifuzz/build_fuzzers_test.py b/infra/cifuzz/build_fuzzers_test.py
index ea52b2ca2..5dfe4f0f8 100644
--- a/infra/cifuzz/build_fuzzers_test.py
+++ b/infra/cifuzz/build_fuzzers_test.py
@@ -28,7 +28,6 @@ sys.path.append(INFRA_DIR)
OSS_FUZZ_DIR = os.path.dirname(INFRA_DIR)
import build_fuzzers
-import config_utils
import continuous_integration
import repo_manager
import test_helpers
@@ -57,22 +56,6 @@ EXAMPLE_BUILD_FUZZER = 'do_stuff_fuzzer'
# pylint: disable=no-self-use,protected-access,too-few-public-methods
-def create_config(**kwargs):
- """Creates a config object and then sets every attribute that is a key in
- |kwargs| to the corresponding value. Asserts that each key in |kwargs| is an
- attribute of Config."""
- with mock.patch('os.path.basename', return_value=None), mock.patch(
- 'config_utils.get_project_src_path',
- return_value=None), mock.patch('config_utils._is_dry_run',
- return_value=True):
- config = config_utils.BuildFuzzersConfig()
-
- for key, value in kwargs.items():
- assert hasattr(config, key), 'Config doesn\'t have attribute: ' + key
- setattr(config, key, value)
- return config
-
-
class BuildFuzzersTest(unittest.TestCase):
"""Unit tests for build_fuzzers."""
@@ -86,10 +69,10 @@ class BuildFuzzersTest(unittest.TestCase):
with tempfile.TemporaryDirectory() as tmp_dir:
build_fuzzers.build_fuzzers(
- create_config(project_name=EXAMPLE_PROJECT,
- project_repo_name=EXAMPLE_PROJECT,
- workspace=tmp_dir,
- pr_ref='refs/pull/1757/merge'))
+ test_helpers.create_build_config(project_name=EXAMPLE_PROJECT,
+ project_repo_name=EXAMPLE_PROJECT,
+ workspace=tmp_dir,
+ pr_ref='refs/pull/1757/merge'))
docker_run_command = mocked_docker_run.call_args_list[0][0][0]
def command_has_env_var_arg(command, env_var_arg):
@@ -114,13 +97,14 @@ class InternalGithubBuildTest(unittest.TestCase):
def _create_builder(self, tmp_dir):
"""Creates an InternalGithubBuilder and returns it."""
- config = create_config(project_name=self.PROJECT_NAME,
- project_repo_name=self.PROJECT_REPO_NAME,
- workspace=tmp_dir,
- sanitizer=self.SANITIZER,
- commit_sha=self.COMMIT_SHA,
- pr_ref=self.PR_REF,
- is_github=True)
+ config = test_helpers.create_build_config(
+ project_name=self.PROJECT_NAME,
+ project_repo_name=self.PROJECT_REPO_NAME,
+ workspace=tmp_dir,
+ sanitizer=self.SANITIZER,
+ commit_sha=self.COMMIT_SHA,
+ pr_ref=self.PR_REF,
+ is_github=True)
ci_system = continuous_integration.get_ci(config)
return build_fuzzers.Builder(config, ci_system)
@@ -164,14 +148,15 @@ class BuildFuzzersIntegrationTest(unittest.TestCase):
git_url = 'https://github.com/jonathanmetzman/cifuzz-external-example.git'
# This test is dependant on the state of
# github.com/jonathanmetzman/cifuzz-external-example.
- config = create_config(project_name=project_name,
- project_repo_name=project_name,
- workspace=self.workspace,
- build_integration_path=build_integration_path,
- git_url=git_url,
- commit_sha='HEAD',
- is_github=True,
- base_commit='HEAD^1')
+ config = test_helpers.create_build_config(
+ project_name=project_name,
+ project_repo_name=project_name,
+ workspace=self.workspace,
+ build_integration_path=build_integration_path,
+ git_url=git_url,
+ commit_sha='HEAD',
+ is_github=True,
+ base_commit='HEAD^1')
self.assertTrue(build_fuzzers.build_fuzzers(config))
self.assertTrue(
os.path.exists(os.path.join(self.out_dir, EXAMPLE_BUILD_FUZZER)))
@@ -187,21 +172,22 @@ class BuildFuzzersIntegrationTest(unittest.TestCase):
'https://github.com/jonathanmetzman/cifuzz-external-example',
self.tmp_dir_obj.name)
project_src_path = manager.repo_dir
- config = create_config(project_name=project_name,
- project_repo_name=project_name,
- workspace=self.workspace,
- build_integration_path=build_integration_path,
- git_url=git_url,
- commit_sha='HEAD',
- project_src_path=project_src_path,
- base_commit='HEAD^1')
+ config = test_helpers.create_build_config(
+ project_name=project_name,
+ project_repo_name=project_name,
+ workspace=self.workspace,
+ build_integration_path=build_integration_path,
+ git_url=git_url,
+ commit_sha='HEAD',
+ project_src_path=project_src_path,
+ base_commit='HEAD^1')
self.assertTrue(build_fuzzers.build_fuzzers(config))
self.assertTrue(
os.path.exists(os.path.join(self.out_dir, EXAMPLE_BUILD_FUZZER)))
def test_valid_commit(self):
"""Tests building fuzzers with valid inputs."""
- config = create_config(
+ config = test_helpers.create_build_config(
project_name=EXAMPLE_PROJECT,
project_repo_name='oss-fuzz',
workspace=self.workspace,
@@ -215,29 +201,29 @@ class BuildFuzzersIntegrationTest(unittest.TestCase):
def test_valid_pull_request(self):
"""Tests building fuzzers with valid pull request."""
# TODO(metzman): What happens when this branch closes?
- config = create_config(project_name=EXAMPLE_PROJECT,
- project_repo_name='oss-fuzz',
- workspace=self.workspace,
- pr_ref='refs/pull/1757/merge',
- base_ref='master',
- is_github=True)
+ config = test_helpers.create_build_config(project_name=EXAMPLE_PROJECT,
+ project_repo_name='oss-fuzz',
+ workspace=self.workspace,
+ pr_ref='refs/pull/1757/merge',
+ base_ref='master',
+ is_github=True)
self.assertTrue(build_fuzzers.build_fuzzers(config))
self.assertTrue(
os.path.exists(os.path.join(self.out_dir, EXAMPLE_BUILD_FUZZER)))
def test_invalid_pull_request(self):
"""Tests building fuzzers with invalid pull request."""
- config = create_config(project_name=EXAMPLE_PROJECT,
- project_repo_name='oss-fuzz',
- workspace=self.workspace,
- pr_ref='ref-1/merge',
- base_ref='master',
- is_github=True)
+ config = test_helpers.create_build_config(project_name=EXAMPLE_PROJECT,
+ project_repo_name='oss-fuzz',
+ workspace=self.workspace,
+ pr_ref='ref-1/merge',
+ base_ref='master',
+ is_github=True)
self.assertTrue(build_fuzzers.build_fuzzers(config))
def test_invalid_project_name(self):
"""Tests building fuzzers with invalid project name."""
- config = create_config(
+ config = test_helpers.create_build_config(
project_name='not_a_valid_project',
project_repo_name='oss-fuzz',
workspace=self.workspace,
@@ -246,7 +232,7 @@ class BuildFuzzersIntegrationTest(unittest.TestCase):
def test_invalid_repo_name(self):
"""Tests building fuzzers with invalid repo name."""
- config = create_config(
+ config = test_helpers.create_build_config(
project_name=EXAMPLE_PROJECT,
project_repo_name='not-real-repo',
workspace=self.workspace,
@@ -255,17 +241,17 @@ class BuildFuzzersIntegrationTest(unittest.TestCase):
def test_invalid_commit_sha(self):
"""Tests building fuzzers with invalid commit SHA."""
- config = create_config(project_name=EXAMPLE_PROJECT,
- project_repo_name='oss-fuzz',
- workspace=self.workspace,
- commit_sha='',
- is_github=True)
+ config = test_helpers.create_build_config(project_name=EXAMPLE_PROJECT,
+ project_repo_name='oss-fuzz',
+ workspace=self.workspace,
+ commit_sha='',
+ is_github=True)
with self.assertRaises(AssertionError):
build_fuzzers.build_fuzzers(config)
def test_invalid_workspace(self):
"""Tests building fuzzers with invalid workspace."""
- config = create_config(
+ config = test_helpers.create_build_config(
project_name=EXAMPLE_PROJECT,
project_repo_name='oss-fuzz',
workspace=os.path.join(self.workspace, 'not', 'a', 'dir'),
@@ -329,11 +315,11 @@ class BuildSantizerIntegrationTest(unittest.TestCase):
@classmethod
def _create_config(cls, tmp_dir, sanitizer):
- return create_config(project_name=cls.PROJECT_NAME,
- project_repo_name=cls.PROJECT_NAME,
- workspace=tmp_dir,
- pr_ref=cls.PR_REF,
- sanitizer=sanitizer)
+ return test_helpers.create_build_config(project_name=cls.PROJECT_NAME,
+ project_repo_name=cls.PROJECT_NAME,
+ workspace=tmp_dir,
+ pr_ref=cls.PR_REF,
+ sanitizer=sanitizer)
@parameterized.parameterized.expand([('memory',), ('undefined',)])
def test_valid_project_curl(self, sanitizer):