1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 03:02:36 +01:00

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

llvm-svn: 237163
This commit is contained in:
Kostya Serebryany 2015-05-12 18:51:57 +00:00
parent 6fa936282c
commit 354905a212
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
This is useful when you already have an exhaustive test corpus.
If you've just started fuzzing with no good corpus running independent
jobs will create a corpus with too many duplicates.
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::
By default (``-reload=1``) the fuzzer processes will periodically scan the CORPUS directory
and reload any new tests. This way the test inputs found by one process will be picked up
by all others.
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
----------

View File

@ -203,6 +203,12 @@ int FuzzerDriver(int argc, char **argv, UserCallback Callback) {
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)
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"
" with stdout/stderr redirected to fuzz-JOB.log.")
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,
"Reload the main corpus periodically to get new units"
"discovered by other processes.")

View File

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

View File

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