Skip to content

Commit 74cec61

Browse files
committed
[libFuzzer] Merge: print feature coverage number as well.
Summary: feature coverage is a useful signal that is available during the merge process, but was not printed previously. Output example: ``` $ ./fuzzer -use_value_profile=1 -merge=1 new_corpus/ seed_corpus/ INFO: Seed: 1676551929 INFO: Loaded 1 modules (2380 inline 8-bit counters): 2380 [0x90d180, 0x90dacc), INFO: Loaded 1 PC tables (2380 PCs): 2380 [0x684018,0x68d4d8), MERGE-OUTER: 180 files, 78 in the initial corpus MERGE-OUTER: attempt 1 INFO: Seed: 1676574577 INFO: Loaded 1 modules (2380 inline 8-bit counters): 2380 [0x90d180, 0x90dacc), INFO: Loaded 1 PC tables (2380 PCs): 2380 [0x684018,0x68d4d8), INFO: -max_len is not provided; libFuzzer will not generate inputs larger than 1048576 bytes MERGE-INNER: using the control file '/tmp/libFuzzerTemp.111754.txt' MERGE-INNER: 180 total files; 0 processed earlier; will process 180 files now #1 pulse cov: 134 ft: 330 exec/s: 0 rss: 37Mb #2 pulse cov: 142 ft: 462 exec/s: 0 rss: 38Mb #4 pulse cov: 152 ft: 651 exec/s: 0 rss: 38Mb #8 pulse cov: 152 ft: 943 exec/s: 0 rss: 38Mb #16 pulse cov: 520 ft: 2783 exec/s: 0 rss: 39Mb #32 pulse cov: 552 ft: 3280 exec/s: 0 rss: 41Mb #64 pulse cov: 576 ft: 3641 exec/s: 0 rss: 50Mb #78 LOADED cov: 602 ft: 3936 exec/s: 0 rss: 88Mb #128 pulse cov: 611 ft: 3996 exec/s: 0 rss: 93Mb #180 DONE cov: 611 ft: 4016 exec/s: 0 rss: 155Mb MERGE-OUTER: succesfull in 1 attempt(s) MERGE-OUTER: the control file has 39741 bytes MERGE-OUTER: consumed 0Mb (37Mb rss) to parse the control file MERGE-OUTER: 9 new files with 80 new features added; 9 new coverage edges ``` Reviewers: hctim, morehouse Reviewed By: morehouse Subscribers: delcypher, #sanitizers, llvm-commits, kcc Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D66030 llvm-svn: 368617
1 parent 532e724 commit 74cec61

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

compiler-rt/lib/fuzzer/FuzzerInternal.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ class Fuzzer {
9898
void ReportNewCoverage(InputInfo *II, const Unit &U);
9999
void PrintPulseAndReportSlowInput(const uint8_t *Data, size_t Size);
100100
void WriteUnitToFileWithPrefix(const Unit &U, const char *Prefix);
101-
void PrintStats(const char *Where, const char *End = "\n", size_t Units = 0);
101+
void PrintStats(const char *Where, const char *End = "\n", size_t Units = 0,
102+
size_t Features = 0);
102103
void PrintStatusForNewUnit(const Unit &U, const char *Text);
103104
void CheckExitOnSrcPosOrItem();
104105

compiler-rt/lib/fuzzer/FuzzerLoop.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,15 @@ void Fuzzer::RssLimitCallback() {
319319
_Exit(Options.OOMExitCode); // Stop right now.
320320
}
321321

322-
void Fuzzer::PrintStats(const char *Where, const char *End, size_t Units) {
322+
void Fuzzer::PrintStats(const char *Where, const char *End, size_t Units,
323+
size_t Features) {
323324
size_t ExecPerSec = execPerSec();
324325
if (!Options.Verbosity)
325326
return;
326327
Printf("#%zd\t%s", TotalNumberOfRuns, Where);
327328
if (size_t N = TPC.GetTotalPCCoverage())
328329
Printf(" cov: %zd", N);
329-
if (size_t N = Corpus.NumFeatures())
330+
if (size_t N = Features ? Features : Corpus.NumFeatures())
330331
Printf(" ft: %zd", N);
331332
if (!Corpus.empty()) {
332333
Printf(" corp: %zd", Corpus.NumActiveUnits());

compiler-rt/lib/fuzzer/FuzzerMerge.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ void Fuzzer::CrashResistantMergeInternalStep(const std::string &CFPath) {
210210

211211
std::ofstream OF(CFPath, std::ofstream::out | std::ofstream::app);
212212
Set<size_t> AllFeatures;
213+
auto PrintStatsWrapper = [this, &AllFeatures](const char* Where) {
214+
this->PrintStats(Where, "\n", 0, AllFeatures.size());
215+
};
213216
Set<const TracePC::PCTableEntry *> AllPCs;
214217
for (size_t i = M.FirstNotProcessedFile; i < M.Files.size(); i++) {
215218
Fuzzer::MaybeExitGracefully();
@@ -238,9 +241,9 @@ void Fuzzer::CrashResistantMergeInternalStep(const std::string &CFPath) {
238241
TPC.UpdateObservedPCs();
239242
// Show stats.
240243
if (!(TotalNumberOfRuns & (TotalNumberOfRuns - 1)))
241-
PrintStats("pulse ");
244+
PrintStatsWrapper("pulse ");
242245
if (TotalNumberOfRuns == M.NumFilesInFirstCorpus)
243-
PrintStats("LOADED");
246+
PrintStatsWrapper("LOADED");
244247
// Write the post-run marker and the coverage.
245248
OF << "FT " << i;
246249
for (size_t F : UniqFeatures)
@@ -254,7 +257,7 @@ void Fuzzer::CrashResistantMergeInternalStep(const std::string &CFPath) {
254257
OF << "\n";
255258
OF.flush();
256259
}
257-
PrintStats("DONE ");
260+
PrintStatsWrapper("DONE ");
258261
}
259262

260263
static void WriteNewControlFile(const std::string &CFPath,

0 commit comments

Comments
 (0)