add a simple no fork mode for replay and fuzzing

This commit is contained in:
Alex Groce 2018-12-15 13:28:15 -07:00
parent 939d8998d9
commit b89d7d7073
2 changed files with 7 additions and 2 deletions

View File

@ -66,6 +66,7 @@ DECLARE_bool(abort_on_fail);
DECLARE_bool(verbose_reads); DECLARE_bool(verbose_reads);
DECLARE_bool(fuzz); DECLARE_bool(fuzz);
DECLARE_bool(fuzz_save_passing); DECLARE_bool(fuzz_save_passing);
DECLARE_bool(no_fork);
DECLARE_int(log_level); DECLARE_int(log_level);
DECLARE_int(seed); DECLARE_int(seed);
@ -533,7 +534,7 @@ static void DeepState_RunTest(struct DeepState_TestInfo *test) {
} }
/* Run a test case, but in libFuzzer, so not inside a fork. */ /* Run a test case, but in libFuzzer, so not inside a fork. */
static int DeepState_RunTestLLVM(struct DeepState_TestInfo *test) { static int DeepState_RunTestNoFork(struct DeepState_TestInfo *test) {
/* Run the test. */ /* Run the test. */
if (!setjmp(DeepState_ReturnToRun)) { if (!setjmp(DeepState_ReturnToRun)) {
/* Convert uncaught C++ exceptions into a test failure. */ /* Convert uncaught C++ exceptions into a test failure. */
@ -577,6 +578,9 @@ static int DeepState_RunTestLLVM(struct DeepState_TestInfo *test) {
/* Fork and run `test`. */ /* Fork and run `test`. */
static enum DeepState_TestRunResult static enum DeepState_TestRunResult
DeepState_ForkAndRunTest(struct DeepState_TestInfo *test) { DeepState_ForkAndRunTest(struct DeepState_TestInfo *test) {
if (FLAG_no_fork) {
return DeepState_RunTestNoFork(test);
}
pid_t test_pid = fork(); pid_t test_pid = fork();
if (!test_pid) { if (!test_pid) {
DeepState_RunTest(test); DeepState_RunTest(test);

View File

@ -39,6 +39,7 @@ DEFINE_bool(abort_on_fail, false, "Abort on file replay failure (useful in file
DEFINE_bool(verbose_reads, false, "Report on bytes being read during execution of test."); DEFINE_bool(verbose_reads, false, "Report on bytes being read during execution of test.");
DEFINE_bool(fuzz, false, "Perform brute force unguided fuzzing."); DEFINE_bool(fuzz, false, "Perform brute force unguided fuzzing.");
DEFINE_bool(fuzz_save_passing, false, "Save passing tests during fuzzing."); DEFINE_bool(fuzz_save_passing, false, "Save passing tests during fuzzing.");
DEFINE_bool(no_fork, false, "Don't fork when running a test.")
DEFINE_int(log_level, 0, "Minimum level of logging to output."); DEFINE_int(log_level, 0, "Minimum level of logging to output.");
DEFINE_int(seed, 0, "Seed for brute force fuzzing (uses time if not set)."); DEFINE_int(seed, 0, "Seed for brute force fuzzing (uses time if not set).");
@ -660,7 +661,7 @@ extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
DeepState_Begin(test); DeepState_Begin(test);
enum DeepState_TestRunResult result = DeepState_RunTestLLVM(test); enum DeepState_TestRunResult result = DeepState_RunTestNoFork(test);
const char* abort_check = getenv("LIBFUZZER_ABORT_ON_FAIL"); const char* abort_check = getenv("LIBFUZZER_ABORT_ON_FAIL");
if (abort_check != NULL) { if (abort_check != NULL) {