コード例 #1
0
ファイル: test_runner.py プロジェクト: zayzay00746/fuzzbench
def test_run_fuzzer_log_file(fs):
    """Test that run_fuzzer invokes the fuzzer defined run_fuzzer function as
    expected."""
    max_total_time = 1
    log_filename = '/log.txt'
    os.environ['MAX_TOTAL_TIME'] = str(max_total_time)
    os.environ['SEED_CORPUS_DIR'] = '/out/seeds'
    os.environ['OUTPUT_CORPUS_DIR'] = '/out/corpus'
    os.environ['FUZZ_TARGET'] = '/out/fuzz-target'
    os.environ['RUNNER_NICENESS'] = '-5'
    fs.create_file('/out/fuzz-target')

    with test_utils.mock_popen_ctx_mgr() as mocked_popen:
        runner.run_fuzzer(max_total_time, log_filename)
        assert mocked_popen.commands == [[
            'nice', '-n', '5', 'python3', '-u', '-c', "import fuzzer; "
            "fuzzer.fuzz('/out/seeds', '/out/corpus', '/out/fuzz-target')"
        ]]
    assert os.path.exists(log_filename)
コード例 #2
0
ファイル: test_runner.py プロジェクト: wideglide/fuzzbench
def test_run_fuzzer_log_file(mocked_communicate, fs, environ):
    """Test that run_fuzzer invokes the fuzzer defined run_fuzzer function as
    expected."""
    mocked_communicate.return_value = ('', 0)
    max_total_time = 1
    log_filename = '/log.txt'
    os.environ['MAX_TOTAL_TIME'] = str(max_total_time)
    os.environ['SEED_CORPUS_DIR'] = '/out/seeds'
    os.environ['OUTPUT_CORPUS_DIR'] = '/out/corpus'
    os.environ['FUZZ_TARGET'] = '/out/fuzz-target'
    os.environ['RUNNER_NICENESS'] = '-5'
    os.environ['FUZZER'] = 'afl'
    os.environ['BENCHMARK'] = 'freetype2-2017'
    fs.add_real_directory(benchmark_config.BENCHMARKS_DIR)
    fs.create_file('/out/fuzz-target')

    with test_utils.mock_popen_ctx_mgr() as mocked_popen:
        runner.run_fuzzer(max_total_time, log_filename)
        assert mocked_popen.commands == [[
            'nice', '-n', '5', 'python3', '-u', '-c',
            'from fuzzers.afl import fuzzer; '
            "fuzzer.fuzz('/out/seeds', '/out/corpus', '/out/fuzz-target')"
        ]]
    assert os.path.exists(log_filename)