[libFuzzer] add -timeout_exitcode option
llvm-svn: 259265
diff --git a/llvm/lib/Fuzzer/FuzzerDriver.cpp b/llvm/lib/Fuzzer/FuzzerDriver.cpp
index d117681..e73feaf 100644
--- a/llvm/lib/Fuzzer/FuzzerDriver.cpp
+++ b/llvm/lib/Fuzzer/FuzzerDriver.cpp
@@ -269,6 +269,7 @@
Options.MaxLen = Flags.max_len;
Options.UnitTimeoutSec = Flags.timeout;
Options.AbortOnTimeout = Flags.abort_on_timeout;
+ Options.TimeoutExitCode = Flags.timeout_exitcode;
Options.MaxTotalTimeSec = Flags.max_total_time;
Options.DoCrossOver = Flags.cross_over;
Options.MutateDepth = Flags.mutate_depth;
diff --git a/llvm/lib/Fuzzer/FuzzerFlags.def b/llvm/lib/Fuzzer/FuzzerFlags.def
index 7f8d705..a451436 100644
--- a/llvm/lib/Fuzzer/FuzzerFlags.def
+++ b/llvm/lib/Fuzzer/FuzzerFlags.def
@@ -30,6 +30,8 @@
"Timeout in seconds (if positive). "
"If one unit runs more than this number of seconds the process will abort.")
FUZZER_FLAG_INT(abort_on_timeout, 0, "If positive, call abort on timeout.")
+FUZZER_FLAG_INT(timeout_exitcode, 77,
+ "Unless abort_on_timeout is set, use this exitcode on timeout.")
FUZZER_FLAG_INT(max_total_time, 0, "If positive, indicates the maximal total "
"time in seconds to run the fuzzer.")
FUZZER_FLAG_INT(help, 0, "Print help.")
diff --git a/llvm/lib/Fuzzer/FuzzerInternal.h b/llvm/lib/Fuzzer/FuzzerInternal.h
index b2a62dd..d506f8f 100644
--- a/llvm/lib/Fuzzer/FuzzerInternal.h
+++ b/llvm/lib/Fuzzer/FuzzerInternal.h
@@ -175,6 +175,7 @@
int MaxLen = 0;
int UnitTimeoutSec = 300;
bool AbortOnTimeout = false;
+ int TimeoutExitCode = 77;
int MaxTotalTimeSec = 0;
bool DoCrossOver = true;
int MutateDepth = 5;
diff --git a/llvm/lib/Fuzzer/FuzzerLoop.cpp b/llvm/lib/Fuzzer/FuzzerLoop.cpp
index b39860c..56c9c05 100644
--- a/llvm/lib/Fuzzer/FuzzerLoop.cpp
+++ b/llvm/lib/Fuzzer/FuzzerLoop.cpp
@@ -114,7 +114,7 @@
Printf("SUMMARY: libFuzzer: timeout\n");
if (Options.AbortOnTimeout)
abort();
- exit(1);
+ exit(Options.TimeoutExitCode);
}
}
diff --git a/llvm/lib/Fuzzer/test/fuzzer-timeout.test b/llvm/lib/Fuzzer/test/fuzzer-timeout.test
index 8db5f89..2de460d 100644
--- a/llvm/lib/Fuzzer/test/fuzzer-timeout.test
+++ b/llvm/lib/Fuzzer/test/fuzzer-timeout.test
@@ -12,3 +12,4 @@
SingleInputTimeoutTest-NOT: Test unit written to ./timeout-
RUN: ASAN_OPTIONS=handle_abort=0 not --crash LLVMFuzzer-TimeoutTest -timeout=1 -abort_on_timeout=1
+RUN: LLVMFuzzer-TimeoutTest -timeout=1 -timeout_exitcode=0