[llvm] r237735 - [lib/Fuzzer] change the meaning of -timeout flag: now timeout is applied to every unit of work separately
Kostya Serebryany
kcc at google.com
Tue May 19 15:12:58 PDT 2015
Author: kcc
Date: Tue May 19 17:12:57 2015
New Revision: 237735
URL: http://llvm.org/viewvc/llvm-project?rev=237735&view=rev
Log:
[lib/Fuzzer] change the meaning of -timeout flag: now timeout is applied to every unit of work separately
Modified:
llvm/trunk/lib/Fuzzer/FuzzerDriver.cpp
llvm/trunk/lib/Fuzzer/FuzzerFlags.def
llvm/trunk/lib/Fuzzer/FuzzerInternal.h
llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp
llvm/trunk/lib/Fuzzer/test/InfiniteTest.cpp
llvm/trunk/lib/Fuzzer/test/fuzzer.test
Modified: llvm/trunk/lib/Fuzzer/FuzzerDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerDriver.cpp?rev=237735&r1=237734&r2=237735&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerDriver.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerDriver.cpp Tue May 19 17:12:57 2015
@@ -215,6 +215,7 @@ int FuzzerDriver(int argc, char **argv,
Fuzzer::FuzzingOptions Options;
Options.Verbosity = Flags.verbosity;
Options.MaxLen = Flags.max_len;
+ Options.UnitTimeoutSec = Flags.timeout;
Options.DoCrossOver = Flags.cross_over;
Options.MutateDepth = Flags.mutate_depth;
Options.ExitOnFirst = Flags.exit_on_first;
@@ -245,7 +246,7 @@ int FuzzerDriver(int argc, char **argv,
// Timer
if (Flags.timeout > 0)
- SetTimer(Flags.timeout);
+ SetTimer(Flags.timeout / 2 + 1);
if (Flags.verbosity >= 2) {
std::cerr << "Tokens: {";
Modified: llvm/trunk/lib/Fuzzer/FuzzerFlags.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerFlags.def?rev=237735&r1=237734&r2=237735&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerFlags.def (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerFlags.def Tue May 19 17:12:57 2015
@@ -27,7 +27,10 @@ FUZZER_FLAG_INT(
" If 0, never do that. If -1, do it sometimes.")
FUZZER_FLAG_INT(exit_on_first, 0,
"If 1, exit after the first new interesting input is found.")
-FUZZER_FLAG_INT(timeout, -1, "Timeout in seconds (if positive).")
+FUZZER_FLAG_INT(
+ timeout, -1,
+ "Timeout in seconds (if positive). "
+ "If one unit runs more than this number of seconds the process will abort.")
FUZZER_FLAG_INT(help, 0, "Print help.")
FUZZER_FLAG_INT(
save_minimized_corpus, 0,
Modified: llvm/trunk/lib/Fuzzer/FuzzerInternal.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerInternal.h?rev=237735&r1=237734&r2=237735&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerInternal.h (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerInternal.h Tue May 19 17:12:57 2015
@@ -56,6 +56,7 @@ class Fuzzer {
struct FuzzingOptions {
int Verbosity = 1;
int MaxLen = 0;
+ int UnitTimeoutSec = 300;
bool DoCrossOver = true;
int MutateDepth = 5;
bool ExitOnFirst = false;
Modified: llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp?rev=237735&r1=237734&r2=237735&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp Tue May 19 17:12:57 2015
@@ -60,16 +60,20 @@ void Fuzzer::StaticAlarmCallback() {
}
void Fuzzer::AlarmCallback() {
+ assert(Options.UnitTimeoutSec > 0);
size_t Seconds =
duration_cast<seconds>(system_clock::now() - UnitStartTime).count();
- std::cerr << "ALARM: working on the last Unit for " << Seconds << " seconds"
- << std::endl;
- if (Seconds >= 3) {
+ if (Seconds == 0) return;
+ if (Options.Verbosity >= 2)
+ std::cerr << "AlarmCallback " << Seconds << "\n";
+ if (Seconds >= (size_t)Options.UnitTimeoutSec) {
+ std::cerr << "ALARM: working on the last Unit for " << Seconds << " seconds"
+ << std::endl;
Print(CurrentUnit, "\n");
PrintUnitInASCIIOrTokens(CurrentUnit, "\n");
WriteToCrash(CurrentUnit, "timeout-");
+ exit(1);
}
- exit(1);
}
void Fuzzer::PrintStats(const char *Where, size_t Cov, const char *End) {
@@ -96,6 +100,8 @@ void Fuzzer::RereadOutputCorpus() {
return;
}
if (!Options.Reload) return;
+ if (Options.Verbosity >= 2)
+ std::cerr << "Reload: read " << AdditionalCorpus.size() << " new units.\n";
for (auto &X : AdditionalCorpus) {
if (X.size() > (size_t)Options.MaxLen)
X.resize(Options.MaxLen);
Modified: llvm/trunk/lib/Fuzzer/test/InfiniteTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/InfiniteTest.cpp?rev=237735&r1=237734&r2=237735&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/InfiniteTest.cpp (original)
+++ llvm/trunk/lib/Fuzzer/test/InfiniteTest.cpp Tue May 19 17:12:57 2015
@@ -6,6 +6,8 @@
static volatile int Sink;
+static volatile int One = 1;
+
extern "C" void LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
if (Size > 0 && Data[0] == 'H') {
Sink = 1;
@@ -13,6 +15,8 @@ extern "C" void LLVMFuzzerTestOneInput(c
Sink = 2;
if (Size > 2 && Data[2] == '!') {
Sink = 2;
+ while (One)
+ ;
}
}
}
Modified: llvm/trunk/lib/Fuzzer/test/fuzzer.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/fuzzer.test?rev=237735&r1=237734&r2=237735&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/fuzzer.test (original)
+++ llvm/trunk/lib/Fuzzer/test/fuzzer.test Tue May 19 17:12:57 2015
@@ -4,7 +4,7 @@ RUN: ./LLVMFuzzer-SimpleTest 2>&1 | File
RUN: not ./LLVMFuzzer-InfiniteTest -timeout=2 2>&1 | FileCheck %s --check-prefix=InfiniteTest
InfiniteTest: ALARM: working on the last Unit for
-InfiniteTest-NOT: CRASHED; file written to timeout
+InfiniteTest: CRASHED; file written to timeout
RUN: not ./LLVMFuzzer-TimeoutTest -timeout=5 2>&1 | FileCheck %s --check-prefix=TimeoutTest
TimeoutTest: ALARM: working on the last Unit for
More information about the llvm-commits
mailing list