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++)
}
// 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]);
}
}
}
}
-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);
}
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;
}
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;
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;
}
F.RereadOutputCorpus();
- for (auto &inp : inputs)
+ for (auto &inp : *Inputs)
if (inp != Options.OutputCorpus)
F.ReadDir(inp, nullptr);