示例#1
0
 def test_allow_broken_fuzz_targets_percentage(self, mocked_docker_run):
     """Tests that ALLOWED_BROKEN_TARGETS_PERCENTAGE is set when running
 docker if passed to check_fuzzer_build."""
     mocked_docker_run.return_value = 0
     test_fuzzer_dir = os.path.join(TEST_FILES_PATH, 'out')
     build_fuzzers.check_fuzzer_build(test_fuzzer_dir,
                                      allowed_broken_targets_percentage='0')
     self.assertIn('-e ALLOWED_BROKEN_TARGETS_PERCENTAGE=0',
                   ' '.join(mocked_docker_run.call_args[0][0]))
示例#2
0
 def test_allow_broken_fuzz_targets_percentage(self, mocked_execute):
     """Tests that ALLOWED_BROKEN_TARGETS_PERCENTAGE is set when running
 docker if passed to check_fuzzer_build."""
     percentage = '0'
     self.config.allowed_broken_targets_percentage = percentage
     build_fuzzers.check_fuzzer_build(self.config)
     self.assertEqual(
         mocked_execute.call_args[1]['env']
         ['ALLOWED_BROKEN_TARGETS_PERCENTAGE'], percentage)
示例#3
0
 def test_allow_broken_fuzz_targets_percentage(self, mocked_docker_run):
     """Tests that ALLOWED_BROKEN_TARGETS_PERCENTAGE is set when running
 docker if passed to check_fuzzer_build."""
     mocked_docker_run.return_value = 0
     build_fuzzers.check_fuzzer_build(self.workspace,
                                      self.SANITIZER,
                                      self.LANGUAGE,
                                      allowed_broken_targets_percentage='0')
     self.assertIn('-e ALLOWED_BROKEN_TARGETS_PERCENTAGE=0',
                   ' '.join(mocked_docker_run.call_args[0][0]))
示例#4
0
def main():
    """Build OSS-Fuzz project's fuzzers for CI tools.
  This script is used to kick off the Github Actions CI tool. It is the
  entrypoint of the Dockerfile in this directory. This action can be added to
  any OSS-Fuzz project's workflow that uses Github.

  Note: The resulting clusterfuzz binaries of this build are placed in
  the directory: ${GITHUB_WORKSPACE}/out

  Required environment variables:
    OSS_FUZZ_PROJECT_NAME: The name of OSS-Fuzz project.
    GITHUB_REPOSITORY: The name of the Github repo that called this script.
    GITHUB_SHA: The commit SHA that triggered this script.
    GITHUB_EVENT_NAME: The name of the hook event that triggered this script.
    GITHUB_EVENT_PATH:
      The path to the file containing the POST payload of the webhook:
      https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners#filesystems-on-github-hosted-runners
    GITHUB_WORKSPACE: The shared volume directory where input artifacts are.
    DRY_RUN: If true, no failures will surface.
    SANITIZER: The sanitizer to use when running fuzzers.

  Returns:
    0 on success or 1 on failure.
  """
    config = config_utils.BuildFuzzersConfig()

    if config.dry_run:
        # Sets the default return code on error to success.
        returncode = 0
    else:
        # The default return code when an error occurs.
        returncode = 1

    if not config.workspace:
        logging.error('This script needs to be run within Github actions.')
        return returncode

    if not build_fuzzers.build_fuzzers(config):
        logging.error(
            'Error building fuzzers for project %s (commit: %s, pr_ref: %s).',
            config.project_name, config.commit_sha, config.pr_ref)
        return returncode

    out_dir = os.path.join(config.workspace, 'out')

    if not config.bad_build_check:
        # If we've gotten to this point and we don't need to do bad_build_check,
        # then the build has succeeded.
        returncode = 0
    # yapf: disable
    elif build_fuzzers.check_fuzzer_build(
        out_dir,
        config.sanitizer,
        config.language,
        allowed_broken_targets_percentage=config.allowed_broken_targets_percentage
    ):
        # yapf: enable
        returncode = 0

    return returncode
示例#5
0
 def test_no_valid_fuzzers(self):
     """Tests that False is returned when an empty directory is given."""
     with tempfile.TemporaryDirectory() as tmp_dir:
         workspace = test_helpers.create_workspace(tmp_dir)
     self.assertFalse(
         build_fuzzers.check_fuzzer_build(workspace, self.SANITIZER,
                                          self.LANGUAGE))
示例#6
0
def build_fuzzers_entrypoint():
    """Builds OSS-Fuzz project's fuzzers for CI tools."""
    config = config_utils.BuildFuzzersConfig()

    if config.dry_run:
        # Sets the default return code on error to success.
        returncode = 0
    else:
        # The default return code when an error occurs.
        returncode = 1

    if not build_fuzzers.build_fuzzers(config):
        logging.error('Error building fuzzers for (commit: %s, pr_ref: %s).',
                      config.commit_sha, config.pr_ref)
        return returncode

    if not config.bad_build_check:
        # If we've gotten to this point and we don't need to do bad_build_check,
        # then the build has succeeded.
        returncode = 0
    # yapf: disable
    elif build_fuzzers.check_fuzzer_build(
        config_utils.Workspace(config),
        config.sanitizer,
        config.language,
        allowed_broken_targets_percentage=config.allowed_broken_targets_percentage
    ):
        # yapf: enable
        returncode = 0

    return returncode
示例#7
0
def build_fuzzers_entrypoint():
    """Builds OSS-Fuzz project's fuzzers for CI tools."""
    config = config_utils.BuildFuzzersConfig()

    if config.dry_run:
        # Sets the default return code on error to success.
        returncode = 0
    else:
        # The default return code when an error occurs.
        returncode = 1

    if not build_fuzzers.build_fuzzers(config):
        logging.error('Error building fuzzers for (commit: %s, pr_ref: %s).',
                      config.commit_sha, config.pr_ref)
        return returncode

    if not config.bad_build_check:
        # If we've gotten to this point and we don't need to do bad_build_check,
        # then the build has succeeded.
        returncode = 0
    elif build_fuzzers.check_fuzzer_build(config):
        returncode = 0

    return returncode
示例#8
0
 def test_not_a_valid_path(self):
     """Tests that False is returned when a nonexistent path is given."""
     workspace = test_helpers.create_workspace('not/a/valid/path')
     self.assertFalse(
         build_fuzzers.check_fuzzer_build(workspace, self.SANITIZER,
                                          self.LANGUAGE))
示例#9
0
 def test_correct_fuzzer_build(self):
     """Checks check_fuzzer_build function returns True for valid fuzzers."""
     self.assertTrue(
         build_fuzzers.check_fuzzer_build(self.workspace, self.SANITIZER,
                                          self.LANGUAGE))
示例#10
0
 def test_no_valid_fuzzers(self):
     """Tests that False is returned when an empty directory is given."""
     with tempfile.TemporaryDirectory() as tmp_dir:
         self.config.workspace = tmp_dir
         os.mkdir(os.path.join(self.config.workspace, 'build-out'))
         self.assertFalse(build_fuzzers.check_fuzzer_build(self.config))
示例#11
0
 def test_not_a_valid_path(self):
     """Tests that False is returned when a nonexistent path is given."""
     self.config.workspace = 'not/a/valid/path'
     self.assertFalse(build_fuzzers.check_fuzzer_build(self.config))
示例#12
0
 def test_correct_fuzzer_build(self):
     """Checks check_fuzzer_build function returns True for valid fuzzers."""
     self.assertTrue(build_fuzzers.check_fuzzer_build(self.config))
示例#13
0
 def test_not_a_valid_fuzzer(self):
     """Checks a directory that exists but does not have fuzzers is False."""
     self.assertFalse(
         build_fuzzers.check_fuzzer_build(self.test_files_path,
                                          self.SANITIZER, self.LANGUAGE))
示例#14
0
 def test_not_a_valid_fuzz_path(self):
     """Tests that False is returned when a bad path is given."""
     self.assertFalse(
         build_fuzzers.check_fuzzer_build('not/a/valid/path',
                                          self.SANITIZER, self.LANGUAGE))
示例#15
0
 def test_correct_fuzzer_build(self):
     """Checks check_fuzzer_build function returns True for valid fuzzers."""
     test_fuzzer_dir = os.path.join(self.test_files_path, 'out')
     self.assertTrue(
         build_fuzzers.check_fuzzer_build(test_fuzzer_dir, self.SANITIZER,
                                          self.LANGUAGE))