summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Fuzzer/FuzzerDriver.cpp
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2016-02-02 03:03:47 +0000
committerKostya Serebryany <kcc@google.com>2016-02-02 03:03:47 +0000
commitbfbe7fc4044dc6d96b52ba41c38437e0905ab1b9 (patch)
treeec31822f26537c0903669f65aa5e4720ac328141 /llvm/lib/Fuzzer/FuzzerDriver.cpp
parent74937fcd0059a159871eaf6f194bde0ef0523475 (diff)
downloadbcm5719-llvm-bfbe7fc4044dc6d96b52ba41c38437e0905ab1b9.tar.gz
bcm5719-llvm-bfbe7fc4044dc6d96b52ba41c38437e0905ab1b9.zip
[libFuzzer] allow passing 1 or more files as individual inputs
llvm-svn: 259459
Diffstat (limited to 'llvm/lib/Fuzzer/FuzzerDriver.cpp')
-rw-r--r--llvm/lib/Fuzzer/FuzzerDriver.cpp30
1 files changed, 28 insertions, 2 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerDriver.cpp b/llvm/lib/Fuzzer/FuzzerDriver.cpp
index e73feaf5cd8..8c81c9d54e8 100644
--- a/llvm/lib/Fuzzer/FuzzerDriver.cpp
+++ b/llvm/lib/Fuzzer/FuzzerDriver.cpp
@@ -70,8 +70,14 @@ static std::vector<std::string> *Inputs;
static std::string *ProgName;
static void PrintHelp() {
- Printf("Usage: %s [-flag1=val1 [-flag2=val2 ...] ] [dir1 [dir2 ...] ]\n",
- ProgName->c_str());
+ Printf("Usage:\n");
+ auto Prog = ProgName->c_str();
+ Printf("\nTo run fuzzing pass 0 or more directories.\n");
+ Printf("%s [-flag1=val1 [-flag2=val2 ...] ] [dir1 [dir2 ...] ]\n", Prog);
+
+ Printf("\nTo run individual tests without fuzzing pass 1 or more files:\n");
+ Printf("%s [-flag1=val1 [-flag2=val2 ...] ] file1 [file2 ...]\n", Prog);
+
Printf("\nFlags: (strictly in form -flag=value)\n");
size_t MaxFlagLen = 0;
for (size_t F = 0; F < kNumFlags; F++)
@@ -227,6 +233,14 @@ int RunOneTest(Fuzzer *F, const char *InputFilePath) {
return 0;
}
+static bool AllInputsAreFiles() {
+ if (Inputs->empty()) return false;
+ for (auto &Path : *Inputs)
+ if (!IsFile(Path))
+ return false;
+ return true;
+}
+
int FuzzerDriver(int argc, char **argv, UserCallback Callback) {
FuzzerRandom_mt19937 Rand(0);
SimpleUserSuppliedFuzzer SUSF(&Rand, Callback);
@@ -320,6 +334,18 @@ int FuzzerDriver(const std::vector<std::string> &Args,
exit(0);
}
+ if (AllInputsAreFiles()) {
+ Printf("%s: Running %zd inputs.\n", ProgName->c_str(), Inputs->size());
+ for (auto &Path : *Inputs) {
+ auto StartTime = system_clock::now();
+ RunOneTest(&F, Path.c_str());
+ auto StopTime = system_clock::now();
+ auto MS = duration_cast<milliseconds>(StopTime - StartTime).count();
+ Printf("%s: %zd ms\n", Path.c_str(), (long)MS);
+ }
+ exit(0);
+ }
+
if (Flags.save_minimized_corpus) {
Printf("The flag -save_minimized_corpus is deprecated; use -merge=1\n");
exit(1);
OpenPOWER on IntegriCloud