[lib/Fuzzer] guess the right number of workers if -jobs=N is given but -workers=M is not. Update the docs.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237163 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Kostya Serebryany 2015-05-12 18:51:57 +00:00
parent 7fb69bc395
commit eaba2dd2f1
5 changed files with 22 additions and 7 deletions

View File

@ -156,13 +156,11 @@ You may run ``N`` independent fuzzer jobs in parallel on ``M`` CPUs::
N=100; M=4; ./pcre_fuzzer ./CORPUS -jobs=$N -workers=$M N=100; M=4; ./pcre_fuzzer ./CORPUS -jobs=$N -workers=$M
This is useful when you already have an exhaustive test corpus. By default (``-reload=1``) the fuzzer processes will periodically scan the CORPUS directory
If you've just started fuzzing with no good corpus running independent and reload any new tests. This way the test inputs found by one process will be picked up
jobs will create a corpus with too many duplicates. by all others.
One way to avoid this and still use all of your CPUs is to use the flag ``-exit_on_first=1``
which will cause the fuzzer to exit on the first new synthesised input::
N=100; M=4; ./pcre_fuzzer ./CORPUS -jobs=$N -workers=$M -exit_on_first=1 If ``-workers=$M`` is not supplied, ``min($N,NumberOfCpuCore/2)`` will be used.
Heartbleed Heartbleed
---------- ----------

View File

@ -203,6 +203,12 @@ int FuzzerDriver(int argc, char **argv, UserCallback Callback) {
return 0; return 0;
} }
if (Flags.jobs > 0 && Flags.workers == 0) {
Flags.workers = std::min(NumberOfCpuCores() / 2, Flags.jobs);
if (Flags.workers > 1)
std::cerr << "Running " << Flags.workers << " workers\n";
}
if (Flags.workers > 0 && Flags.jobs > 0) if (Flags.workers > 0 && Flags.jobs > 0)
return RunInMultipleProcesses(argc, argv, Flags.workers, Flags.jobs); return RunInMultipleProcesses(argc, argv, Flags.workers, Flags.jobs);

View File

@ -44,7 +44,8 @@ FUZZER_FLAG_INT(jobs, 0, "Number of jobs to run. If jobs >= 1 we spawn"
" this number of jobs in separate worker processes" " this number of jobs in separate worker processes"
" with stdout/stderr redirected to fuzz-JOB.log.") " with stdout/stderr redirected to fuzz-JOB.log.")
FUZZER_FLAG_INT(workers, 0, FUZZER_FLAG_INT(workers, 0,
"Number of simultaneous worker processes to run the jobs.") "Number of simultaneous worker processes to run the jobs."
" If zero, \"min(jobs,NumberOfCpuCores()/2)\" is used.")
FUZZER_FLAG_INT(reload, 1, FUZZER_FLAG_INT(reload, 1,
"Reload the main corpus periodically to get new units" "Reload the main corpus periodically to get new units"
"discovered by other processes.") "discovered by other processes.")

View File

@ -44,6 +44,8 @@ std::string Hash(const Unit &U);
void SetTimer(int Seconds); void SetTimer(int Seconds);
void PrintFileAsBase64(const std::string &Path); void PrintFileAsBase64(const std::string &Path);
int NumberOfCpuCores();
class Fuzzer { class Fuzzer {
public: public:
struct FuzzingOptions { struct FuzzingOptions {

View File

@ -61,4 +61,12 @@ void SetTimer(int Seconds) {
assert(Res == 0); assert(Res == 0);
} }
int NumberOfCpuCores() {
FILE *F = popen("nproc", "r");
int N = 0;
fscanf(F, "%d", &N);
fclose(F);
return N;
}
} // namespace fuzzer } // namespace fuzzer