aboutsummaryrefslogtreecommitdiff
path: root/infra
diff options
context:
space:
mode:
authorjonathanmetzman <31354670+jonathanmetzman@users.noreply.github.com>2021-08-03 17:58:20 -0700
committerGitHub <noreply@github.com>2021-08-03 17:58:20 -0700
commit432105a31af3f7bfbcf2c0d1a26d4e65f8e98571 (patch)
treef4f4846436bd7d6d9b068fa6a0eb92aeda8ea453 /infra
parent264c160e3a09ca90bb5bcabf3a733c2be3b41901 (diff)
downloadoss-fuzz-432105a31af3f7bfbcf2c0d1a26d4e65f8e98571.tar.gz
[cifuzz][NFC] Move Workspace to workspace_utils. (#6158)
In hindsight, it doesn't have a lot to do with the rest of config_utils. And config_utils is getting crowded.
Diffstat (limited to 'infra')
-rw-r--r--infra/cifuzz/affected_fuzz_targets_test.py4
-rw-r--r--infra/cifuzz/build_fuzzers.py4
-rw-r--r--infra/cifuzz/build_fuzzers_entrypoint.py3
-rw-r--r--infra/cifuzz/clusterfuzz_deployment_test.py7
-rw-r--r--infra/cifuzz/config_utils.py49
-rw-r--r--infra/cifuzz/docker_test.py4
-rw-r--r--infra/cifuzz/fuzz_target_test.py4
-rw-r--r--infra/cifuzz/run_fuzzers.py4
-rw-r--r--infra/cifuzz/test_helpers.py3
-rw-r--r--infra/cifuzz/workspace_utils.py65
10 files changed, 83 insertions, 64 deletions
diff --git a/infra/cifuzz/affected_fuzz_targets_test.py b/infra/cifuzz/affected_fuzz_targets_test.py
index 34e51b977..121e0d881 100644
--- a/infra/cifuzz/affected_fuzz_targets_test.py
+++ b/infra/cifuzz/affected_fuzz_targets_test.py
@@ -22,8 +22,8 @@ import parameterized
import affected_fuzz_targets
import clusterfuzz_deployment
-import config_utils
import test_helpers
+import workspace_utils
# pylint: disable=protected-access
@@ -64,7 +64,7 @@ class RemoveUnaffectedFuzzTargets(unittest.TestCase):
is_github=True,
oss_fuzz_project_name=EXAMPLE_PROJECT,
workspace='/workspace')
- workspace = config_utils.Workspace(config)
+ workspace = workspace_utils.Workspace(config)
deployment = clusterfuzz_deployment.get_clusterfuzz_deployment(
config, workspace)
# We can't use fakefs in this test because this test executes
diff --git a/infra/cifuzz/build_fuzzers.py b/infra/cifuzz/build_fuzzers.py
index 3941c592a..ec820cd12 100644
--- a/infra/cifuzz/build_fuzzers.py
+++ b/infra/cifuzz/build_fuzzers.py
@@ -20,9 +20,9 @@ import sys
import affected_fuzz_targets
import clusterfuzz_deployment
-import config_utils
import continuous_integration
import docker
+import workspace_utils
# pylint: disable=wrong-import-position,import-error
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@@ -52,7 +52,7 @@ class Builder: # pylint: disable=too-many-instance-attributes
def __init__(self, config, ci_system):
self.config = config
self.ci_system = ci_system
- self.workspace = config_utils.Workspace(config)
+ self.workspace = workspace_utils.Workspace(config)
self.workspace.initialize_dir(self.workspace.out)
self.workspace.initialize_dir(self.workspace.work)
self.clusterfuzz_deployment = (
diff --git a/infra/cifuzz/build_fuzzers_entrypoint.py b/infra/cifuzz/build_fuzzers_entrypoint.py
index c191ca38e..5aed2e615 100644
--- a/infra/cifuzz/build_fuzzers_entrypoint.py
+++ b/infra/cifuzz/build_fuzzers_entrypoint.py
@@ -17,6 +17,7 @@ import sys
import build_fuzzers
import config_utils
+import workspace_utils
# pylint: disable=c-extension-no-member
# pylint gets confused because of the relative import of cifuzz.
@@ -48,7 +49,7 @@ def build_fuzzers_entrypoint():
returncode = 0
# yapf: disable
elif build_fuzzers.check_fuzzer_build(
- config_utils.Workspace(config),
+ workspace_utils.Workspace(config),
config.sanitizer,
config.language,
allowed_broken_targets_percentage=config.allowed_broken_targets_percentage
diff --git a/infra/cifuzz/clusterfuzz_deployment_test.py b/infra/cifuzz/clusterfuzz_deployment_test.py
index 832379604..36ab60228 100644
--- a/infra/cifuzz/clusterfuzz_deployment_test.py
+++ b/infra/cifuzz/clusterfuzz_deployment_test.py
@@ -23,6 +23,7 @@ from pyfakefs import fake_filesystem_unittest
import clusterfuzz_deployment
import config_utils
import test_helpers
+import workspace_utils
# NOTE: This integration test relies on
# https://github.com/google/oss-fuzz/tree/master/projects/example project.
@@ -53,7 +54,7 @@ def _create_config(**kwargs):
def _create_deployment(**kwargs):
config = _create_config(**kwargs)
- workspace = config_utils.Workspace(config)
+ workspace = workspace_utils.Workspace(config)
return clusterfuzz_deployment.get_clusterfuzz_deployment(config, workspace)
@@ -189,7 +190,7 @@ class NoClusterFuzzDeploymentTest(fake_filesystem_unittest.TestCase):
config = test_helpers.create_run_config(build_integration_path='/',
workspace=WORKSPACE,
is_github=False)
- workspace = config_utils.Workspace(config)
+ workspace = workspace_utils.Workspace(config)
self.deployment = clusterfuzz_deployment.get_clusterfuzz_deployment(
config, workspace)
@@ -241,7 +242,7 @@ class GetClusterFuzzDeploymentTest(unittest.TestCase):
new_callable=mock.PropertyMock):
with mock.patch('filestore_utils.get_filestore', return_value=None):
config = _create_config()
- workspace = config_utils.Workspace(config)
+ workspace = workspace_utils.Workspace(config)
self.assertIsInstance(
clusterfuzz_deployment.get_clusterfuzz_deployment(
diff --git a/infra/cifuzz/config_utils.py b/infra/cifuzz/config_utils.py
index 121a68b80..0b244a1f4 100644
--- a/infra/cifuzz/config_utils.py
+++ b/infra/cifuzz/config_utils.py
@@ -236,52 +236,3 @@ class BuildFuzzersConfig(BaseConfig):
# Not from a commit or PR.
(not self.base_ref and not self.base_commit) or
environment.get_bool('KEEP_UNAFFECTED_FUZZERS'))
-
-
-class Workspace:
- """Class representing the workspace directory."""
-
- def __init__(self, config):
- self.workspace = config.workspace
-
- def initialize_dir(self, directory): # pylint: disable=no-self-use
- """Creates directory if it doesn't already exist, otherwise does nothing."""
- os.makedirs(directory, exist_ok=True)
-
- @property
- def out(self):
- """The out directory used for storing the fuzzer build built by
- build_fuzzers."""
- # Don't use 'out' because it needs to be used by artifacts.
- return os.path.join(self.workspace, 'build-out')
-
- @property
- def work(self):
- """The directory used as the work directory for the fuzzer build/run."""
- return os.path.join(self.workspace, 'work')
-
- @property
- def artifacts(self):
- """The directory used to store artifacts for download by CI-system users."""
- # This is hardcoded by a lot of clients, so we need to use this.
- return os.path.join(self.workspace, 'out', 'artifacts')
-
- @property
- def clusterfuzz_build(self):
- """The directory where builds from ClusterFuzz are stored."""
- return os.path.join(self.workspace, 'cifuzz-prev-build')
-
- @property
- def clusterfuzz_coverage(self):
- """The directory where builds from ClusterFuzz are stored."""
- return os.path.join(self.workspace, 'cifuzz-prev-coverage')
-
- @property
- def coverage_report(self):
- """The directory where coverage reports generated by cifuzz are put."""
- return os.path.join(self.workspace, 'cifuzz-coverage')
-
- @property
- def corpora(self):
- """The directory where corpora from ClusterFuzz are stored."""
- return os.path.join(self.workspace, 'cifuzz-corpus')
diff --git a/infra/cifuzz/docker_test.py b/infra/cifuzz/docker_test.py
index 8f46da3fb..16a0f94e7 100644
--- a/infra/cifuzz/docker_test.py
+++ b/infra/cifuzz/docker_test.py
@@ -15,15 +15,15 @@
import unittest
from unittest import mock
-import config_utils
import docker
import test_helpers
+import workspace_utils
CONTAINER_NAME = 'example-container'
config = test_helpers.create_run_config(oss_fuzz_project_name='project',
workspace='/workspace')
config.workspace = '/workspace'
-WORKSPACE = config_utils.Workspace(config)
+WORKSPACE = workspace_utils.Workspace(config)
SANITIZER = 'example-sanitizer'
LANGUAGE = 'example-language'
diff --git a/infra/cifuzz/fuzz_target_test.py b/infra/cifuzz/fuzz_target_test.py
index acc61bbb8..1ff01e266 100644
--- a/infra/cifuzz/fuzz_target_test.py
+++ b/infra/cifuzz/fuzz_target_test.py
@@ -23,9 +23,9 @@ import parameterized
from pyfakefs import fake_filesystem_unittest
import clusterfuzz_deployment
-import config_utils
import fuzz_target
import test_helpers
+import workspace_utils
# NOTE: This integration test relies on
# https://github.com/google/oss-fuzz/tree/master/projects/example project.
@@ -59,7 +59,7 @@ def _create_config(**kwargs):
def _create_deployment(**kwargs):
config = _create_config(**kwargs)
- workspace = config_utils.Workspace(config)
+ workspace = workspace_utils.Workspace(config)
return clusterfuzz_deployment.get_clusterfuzz_deployment(config, workspace)
diff --git a/infra/cifuzz/run_fuzzers.py b/infra/cifuzz/run_fuzzers.py
index ce2dfb856..93a30a373 100644
--- a/infra/cifuzz/run_fuzzers.py
+++ b/infra/cifuzz/run_fuzzers.py
@@ -20,10 +20,10 @@ import sys
import time
import clusterfuzz_deployment
-import config_utils
import fuzz_target
import generate_coverage_report
import stack_parser
+import workspace_utils
# pylint: disable=wrong-import-position,import-error
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@@ -43,7 +43,7 @@ class BaseFuzzTargetRunner:
def __init__(self, config):
self.config = config
- self.workspace = config_utils.Workspace(config)
+ self.workspace = workspace_utils.Workspace(config)
self.clusterfuzz_deployment = (
clusterfuzz_deployment.get_clusterfuzz_deployment(
self.config, self.workspace))
diff --git a/infra/cifuzz/test_helpers.py b/infra/cifuzz/test_helpers.py
index 705657958..5be0ee962 100644
--- a/infra/cifuzz/test_helpers.py
+++ b/infra/cifuzz/test_helpers.py
@@ -20,6 +20,7 @@ import tempfile
from unittest import mock
import config_utils
+import workspace_utils
@mock.patch('config_utils._is_dry_run', return_value=True)
@@ -52,7 +53,7 @@ def create_workspace(workspace_path='/workspace'):
"""Returns a workspace located at |workspace_path| ('/workspace' by
default)."""
config = create_run_config(workspace=workspace_path)
- return config_utils.Workspace(config)
+ return workspace_utils.Workspace(config)
def patch_environ(testcase_obj, env=None):
diff --git a/infra/cifuzz/workspace_utils.py b/infra/cifuzz/workspace_utils.py
new file mode 100644
index 000000000..d6a686652
--- /dev/null
+++ b/infra/cifuzz/workspace_utils.py
@@ -0,0 +1,65 @@
+# Copyright 2021 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 permissions and
+# limitations under the License.
+"""Module for representing the workspace directory which CIFuzz uses."""
+
+import os
+
+
+class Workspace:
+ """Class representing the workspace directory."""
+
+ def __init__(self, config):
+ self.workspace = config.workspace
+
+ def initialize_dir(self, directory): # pylint: disable=no-self-use
+ """Creates directory if it doesn't already exist, otherwise does nothing."""
+ os.makedirs(directory, exist_ok=True)
+
+ @property
+ def out(self):
+ """The out directory used for storing the fuzzer build built by
+ build_fuzzers."""
+ # Don't use 'out' because it needs to be used by artifacts.
+ return os.path.join(self.workspace, 'build-out')
+
+ @property
+ def work(self):
+ """The directory used as the work directory for the fuzzer build/run."""
+ return os.path.join(self.workspace, 'work')
+
+ @property
+ def artifacts(self):
+ """The directory used to store artifacts for download by CI-system users."""
+ # This is hardcoded by a lot of clients, so we need to use this.
+ return os.path.join(self.workspace, 'out', 'artifacts')
+
+ @property
+ def clusterfuzz_build(self):
+ """The directory where builds from ClusterFuzz are stored."""
+ return os.path.join(self.workspace, 'cifuzz-prev-build')
+
+ @property
+ def clusterfuzz_coverage(self):
+ """The directory where builds from ClusterFuzz are stored."""
+ return os.path.join(self.workspace, 'cifuzz-prev-coverage')
+
+ @property
+ def coverage_report(self):
+ """The directory where coverage reports generated by cifuzz are put."""
+ return os.path.join(self.workspace, 'cifuzz-coverage')
+
+ @property
+ def corpora(self):
+ """The directory where corpora from ClusterFuzz are stored."""
+ return os.path.join(self.workspace, 'cifuzz-corpus')