mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 10:42:39 +01:00
[libFuzzer] add two more variants of FuzzerDriver for convenience
llvm-svn: 247300
This commit is contained in:
parent
405e42472e
commit
0001c18d8c
@ -55,12 +55,12 @@ static FlagDescription FlagDescriptions [] {
|
||||
static const size_t kNumFlags =
|
||||
sizeof(FlagDescriptions) / sizeof(FlagDescriptions[0]);
|
||||
|
||||
static std::vector<std::string> inputs;
|
||||
static const char *ProgName;
|
||||
static std::vector<std::string> *Inputs;
|
||||
static std::string *ProgName;
|
||||
|
||||
static void PrintHelp() {
|
||||
Printf("Usage: %s [-flag1=val1 [-flag2=val2 ...] ] [dir1 [dir2 ...] ]\n",
|
||||
ProgName);
|
||||
ProgName->c_str());
|
||||
Printf("\nFlags: (strictly in form -flag=value)\n");
|
||||
size_t MaxFlagLen = 0;
|
||||
for (size_t F = 0; F < kNumFlags; F++)
|
||||
@ -119,16 +119,17 @@ static bool ParseOneFlag(const char *Param) {
|
||||
}
|
||||
|
||||
// We don't use any library to minimize dependencies.
|
||||
static void ParseFlags(int argc, char **argv) {
|
||||
static void ParseFlags(const std::vector<std::string> &Args) {
|
||||
for (size_t F = 0; F < kNumFlags; F++) {
|
||||
if (FlagDescriptions[F].IntFlag)
|
||||
*FlagDescriptions[F].IntFlag = FlagDescriptions[F].Default;
|
||||
if (FlagDescriptions[F].StrFlag)
|
||||
*FlagDescriptions[F].StrFlag = nullptr;
|
||||
}
|
||||
for (int A = 1; A < argc; A++) {
|
||||
if (ParseOneFlag(argv[A])) continue;
|
||||
inputs.push_back(argv[A]);
|
||||
Inputs = new std::vector<std::string>;
|
||||
for (size_t A = 1; A < Args.size(); A++) {
|
||||
if (ParseOneFlag(Args[A].c_str())) continue;
|
||||
Inputs->push_back(Args[A]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -161,15 +162,15 @@ static void WorkerThread(const std::string &Cmd, std::atomic<int> *Counter,
|
||||
}
|
||||
}
|
||||
|
||||
static int RunInMultipleProcesses(int argc, char **argv, int NumWorkers,
|
||||
int NumJobs) {
|
||||
static int RunInMultipleProcesses(const std::vector<std::string> &Args,
|
||||
int NumWorkers, int NumJobs) {
|
||||
std::atomic<int> Counter(0);
|
||||
std::atomic<bool> HasErrors(false);
|
||||
std::string Cmd;
|
||||
for (int i = 0; i < argc; i++) {
|
||||
if (FlagValue(argv[i], "jobs") || FlagValue(argv[i], "workers")) continue;
|
||||
Cmd += argv[i];
|
||||
Cmd += " ";
|
||||
for (auto &S : Args) {
|
||||
if (FlagValue(S.c_str(), "jobs") || FlagValue(S.c_str(), "workers"))
|
||||
continue;
|
||||
Cmd += S + " ";
|
||||
}
|
||||
std::vector<std::thread> V;
|
||||
std::thread Pulse(PulseThread);
|
||||
@ -208,10 +209,22 @@ int FuzzerDriver(int argc, char **argv, UserCallback Callback) {
|
||||
}
|
||||
|
||||
int FuzzerDriver(int argc, char **argv, UserSuppliedFuzzer &USF) {
|
||||
using namespace fuzzer;
|
||||
std::vector<std::string> Args(argv, argv + argc);
|
||||
return FuzzerDriver(Args, USF);
|
||||
}
|
||||
|
||||
ProgName = argv[0];
|
||||
ParseFlags(argc, argv);
|
||||
int FuzzerDriver(const std::vector<std::string> &Args, UserCallback Callback) {
|
||||
FuzzerRandomLibc Rand(0);
|
||||
SimpleUserSuppliedFuzzer SUSF(&Rand, Callback);
|
||||
return FuzzerDriver(Args, SUSF);
|
||||
}
|
||||
|
||||
int FuzzerDriver(const std::vector<std::string> &Args,
|
||||
UserSuppliedFuzzer &USF) {
|
||||
using namespace fuzzer;
|
||||
assert(!Args.empty());
|
||||
ProgName = new std::string(Args[0]);
|
||||
ParseFlags(Args);
|
||||
if (Flags.help) {
|
||||
PrintHelp();
|
||||
return 0;
|
||||
@ -224,7 +237,7 @@ int FuzzerDriver(int argc, char **argv, UserSuppliedFuzzer &USF) {
|
||||
}
|
||||
|
||||
if (Flags.workers > 0 && Flags.jobs > 0)
|
||||
return RunInMultipleProcesses(argc, argv, Flags.workers, Flags.jobs);
|
||||
return RunInMultipleProcesses(Args, Flags.workers, Flags.jobs);
|
||||
|
||||
Fuzzer::FuzzingOptions Options;
|
||||
Options.Verbosity = Flags.verbosity;
|
||||
@ -245,8 +258,8 @@ int FuzzerDriver(int argc, char **argv, UserSuppliedFuzzer &USF) {
|
||||
Options.TBMWidth = Flags.tbm_width;
|
||||
if (Flags.runs >= 0)
|
||||
Options.MaxNumberOfRuns = Flags.runs;
|
||||
if (!inputs.empty())
|
||||
Options.OutputCorpus = inputs[0];
|
||||
if (!Inputs->empty())
|
||||
Options.OutputCorpus = (*Inputs)[0];
|
||||
if (Flags.sync_command)
|
||||
Options.SyncCommand = Flags.sync_command;
|
||||
Options.SyncTimeout = Flags.sync_timeout;
|
||||
@ -282,7 +295,7 @@ int FuzzerDriver(int argc, char **argv, UserSuppliedFuzzer &USF) {
|
||||
}
|
||||
|
||||
F.RereadOutputCorpus();
|
||||
for (auto &inp : inputs)
|
||||
for (auto &inp : *Inputs)
|
||||
if (inp != Options.OutputCorpus)
|
||||
F.ReadDir(inp, nullptr);
|
||||
|
||||
|
@ -18,6 +18,8 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace fuzzer {
|
||||
|
||||
@ -162,6 +164,10 @@ class UserSuppliedFuzzer {
|
||||
/// Runs the fuzzing with the UserSuppliedFuzzer.
|
||||
int FuzzerDriver(int argc, char **argv, UserSuppliedFuzzer &USF);
|
||||
|
||||
/// More C++-ish interface.
|
||||
int FuzzerDriver(const std::vector<std::string> &Args, UserSuppliedFuzzer &USF);
|
||||
int FuzzerDriver(const std::vector<std::string> &Args, UserCallback Callback);
|
||||
|
||||
} // namespace fuzzer
|
||||
|
||||
#endif // LLVM_FUZZER_INTERFACE_H
|
||||
|
Loading…
Reference in New Issue
Block a user