Пример #1
0
def test_replace_dir_file_source(fs):
    """Test that replace_dir raises an exception if asked to use a file as a
    source directory."""
    filename = 'file'
    fs.create_file(filename)
    with pytest.raises(NotADirectoryError):
        filesystem.replace_dir(filename, 'dst')
Пример #2
0
def test_replace_dir_copy(fs):
    """Test that replace_dir will move the source to directory to destination
    when instructed."""
    _create_source_dir(SOURCE_DIR, fs)
    os.mkdir(DESTINATION_DIR)
    filesystem.replace_dir(SOURCE_DIR, DESTINATION_DIR, move=False)
    _assert_has_source_dir_contents(DESTINATION_DIR)
    assert os.path.exists(SOURCE_DIR)
Пример #3
0
def measure_snapshot_coverage(fuzzer: str, benchmark: str, trial_num: int,
                              cycle: int) -> models.Snapshot:
    """Measure coverage of the snapshot for |cycle| for |trial_num| of |fuzzer|
    and |benchmark|."""
    snapshot_logger = logs.Logger('measurer',
                                  default_extras={
                                      'fuzzer': fuzzer,
                                      'benchmark': benchmark,
                                      'trial_id': str(trial_num),
                                      'cycle': str(cycle),
                                  })
    snapshot_measurer = SnapshotMeasurer(fuzzer, benchmark, trial_num,
                                         snapshot_logger)
    if not os.path.exists(snapshot_measurer.trial_dir):
        snapshot_logger.warning('Trial dir: %s does not exist yet.',
                                snapshot_measurer.trial_dir)
        return None

    this_time = cycle * experiment_utils.SNAPSHOT_PERIOD
    if snapshot_measurer.is_cycle_unchanged(cycle):
        snapshot_logger.info('Cycle: %d is unchanged.', cycle)

        current_pcs = snapshot_measurer.get_current_pcs()
        return models.Snapshot(time=this_time,
                               trial_id=trial_num,
                               edges_covered=len(current_pcs))

    snapshot_measurer.initialize_measurement_dirs()

    if not snapshot_measurer.extract_cycle_corpus(cycle):
        return None

    # Get the coverage of the new corpus units.
    snapshot_measurer.run_cov_new_units()
    all_pcs = snapshot_measurer.merge_new_pcs()
    snapshot = models.Snapshot(time=this_time,
                               trial_id=trial_num,
                               edges_covered=len(all_pcs))

    # Save the new corpus.
    filesystem.replace_dir(snapshot_measurer.corpus_dir,
                           snapshot_measurer.prev_corpus_dir)

    # Archive crashes directory.
    snapshot_measurer.archive_crashes(cycle)

    snapshot_logger.info('Measured cycle: %d.', cycle)
    return snapshot
Пример #4
0
def test_replace_dir_nonexistent_source(fs):
    """Test that replace_dir raises an exception if asked to use a nonexistent
    directory as a source."""
    with pytest.raises(NotADirectoryError):
        filesystem.replace_dir('fake-src', 'dst')