Esempio n. 1
0
def get_fuzzers_changed_since_last():
    """Returns a list of fuzzers that have changed since the last experiment
    stored in the database that has a commit that is in the current branch."""
    # TODO(metzman): Figure out a way of skipping experiments that were stopped
    # early.

    # Loop over experiments since some may have hashes that are not in the
    # current branch.
    with db_utils.session_scope() as session:
        experiments = list(
            session.query(models.Experiment).order_by(
                models.Experiment.time_created.desc()))
    if not experiments:
        raise Exception('No experiments found. Cannot find changed fuzzers.')

    changed_files = None
    for experiment in experiments:
        try:
            changed_files = diff_utils.get_changed_files(experiment.git_hash)
            break
        except diff_utils.DiffError:
            logs.warning('Skipping %s. Commit is not in branch.',
                         experiment.git_hash)

    if changed_files is None:
        raise Exception('No in-branch experiments. '
                        'Cannot find changed fuzzers.')
    return change_utils.get_changed_fuzzers(changed_files)
def do_build(build_type, fuzzer, always_build):
    """Build fuzzer,benchmark pairs for CI."""
    if build_type == 'oss-fuzz':
        benchmarks = OSS_FUZZ_BENCHMARKS
    elif build_type == 'standard':
        benchmarks = STANDARD_BENCHMARKS
    else:
        raise Exception('Invalid build_type: %s' % build_type)

    if always_build:
        # Always do a build if always_build is True.
        return make_builds(benchmarks, fuzzer)

    changed_files = diff_utils.get_changed_files()
    changed_fuzzers = change_utils.get_changed_fuzzers(changed_files)
    if fuzzer in changed_fuzzers:
        # Otherwise if fuzzer is in changed_fuzzers then build it with all
        # benchmarks, the change could have affected any benchmark.
        return make_builds(benchmarks, fuzzer)

    # Otherwise, only build benchmarks that have changed.
    changed_benchmarks = set(
        change_utils.get_changed_benchmarks(changed_files))
    benchmarks = benchmarks.intersection(changed_benchmarks)
    return make_builds(benchmarks, fuzzer)
Esempio n. 3
0
def main() -> int:
    """Check that this branch conforms to the standards of fuzzbench."""
    logs.initialize()
    parser = argparse.ArgumentParser(
        description='Presubmit script for fuzzbench.')
    choices = [
        'format', 'lint', 'typecheck', 'licensecheck',
        'test_changed_integrations'
    ]
    parser.add_argument('command', choices=choices, nargs='?')

    args = parser.parse_args()
    os.chdir(_SRC_ROOT)
    changed_files = [Path(path) for path in diff_utils.get_changed_files()]

    if not args.command:
        success = do_checks(changed_files)
        return bool_to_returncode(success)

    command_check_mapping = {
        'format': yapf,
        'lint': lint,
        'typecheck': pytype,
        'test_changed_integrations': test_changed_integrations
    }

    check = command_check_mapping[args.command]
    if args.command == 'format':
        success = check(changed_files, False)
    else:
        success = check(changed_files)
    if not success:
        print('ERROR: %s failed, see errors above.' % check.__name__)
    return bool_to_returncode(success)
Esempio n. 4
0
def main() -> int:
    """Check that this branch conforms to the standards of fuzzbench."""
    parser = argparse.ArgumentParser(
        description='Presubmit script for fuzzbench.')
    choices = [
        'format', 'lint', 'typecheck', 'licensecheck',
        'test_changed_integrations'
    ]
    parser.add_argument(
        'command',
        choices=choices,
        nargs='?',
        help='The presubmit check to run. Defaults to all of them')
    parser.add_argument('--all-files',
                        action='store_true',
                        help='Run presubmit check(s) on all files',
                        default=False)
    parser.add_argument('-v', '--verbose', action='store_true', default=False)

    args = parser.parse_args()

    os.chdir(_SRC_ROOT)

    if not args.verbose:
        logs.initialize()
    else:
        logs.initialize(log_level=logging.DEBUG)

    if not args.all_files:
        relevant_files = [
            Path(path) for path in diff_utils.get_changed_files()
        ]
    else:
        relevant_files = get_all_files()

    relevant_files = filter_ignored_files(relevant_files)

    logs.debug('Running presubmit check(s) on: %s',
               ' '.join(str(path) for path in relevant_files))

    if not args.command:
        success = do_checks(relevant_files)
        return bool_to_returncode(success)

    command_check_mapping = {
        'format': yapf,
        'lint': lint,
        'typecheck': pytype,
        'test_changed_integrations': test_changed_integrations
    }

    check = command_check_mapping[args.command]
    if args.command == 'format':
        success = check(relevant_files, False)
    else:
        success = check(relevant_files)
    if not success:
        print('ERROR: %s failed, see errors above.' % check.__name__)
    return bool_to_returncode(success)
Esempio n. 5
0
def get_relevant_files(all_files: bool) -> List[Path]:
    """Get the files that should be checked."""
    if not all_files:
        relevant_files = [Path(path) for path in diff_utils.get_changed_files()]
    else:
        relevant_files = get_all_files()

    return filter_ignored_files(relevant_files)