fuzzer web ui: add coverage stat

This commit is contained in:
Andrew Kelley 2024-08-04 16:09:14 -07:00
parent f56d113503
commit 6e6164f8a6
3 changed files with 16 additions and 0 deletions

View File

@ -129,6 +129,7 @@
<ul>
<li>Total Runs: <span id="statTotalRuns"></span></li>
<li>Unique Runs: <span id="statUniqueRuns"></span></li>
<li>Coverage: <span id="statCoverage"></span></li>
<li>Lowest Stack: <span id="statLowestStack"></span></li>
</ul>
</div>

View File

@ -5,6 +5,7 @@
const domSourceText = document.getElementById("sourceText");
const domStatTotalRuns = document.getElementById("statTotalRuns");
const domStatUniqueRuns = document.getElementById("statUniqueRuns");
const domStatCoverage = document.getElementById("statCoverage");
const domStatLowestStack = document.getElementById("statLowestStack");
let wasm_promise = fetch("main.wasm");
@ -112,8 +113,11 @@
function renderStats() {
const totalRuns = wasm_exports.totalRuns();
const uniqueRuns = wasm_exports.uniqueRuns();
const totalSourceLocations = wasm_exports.totalSourceLocations();
const coveredSourceLocations = wasm_exports.coveredSourceLocations();
domStatTotalRuns.innerText = totalRuns;
domStatUniqueRuns.innerText = uniqueRuns + " (" + percent(uniqueRuns, totalRuns) + "%)";
domStatCoverage.innerText = coveredSourceLocations + " / " + totalSourceLocations + " (" + percent(coveredSourceLocations, totalSourceLocations) + "%)";
domStatLowestStack.innerText = unwrapString(wasm_exports.lowestStack());
domSectStats.classList.remove("hidden");

View File

@ -110,6 +110,17 @@ export fn lowestStack() String {
return String.init(string_result.items);
}
export fn totalSourceLocations() usize {
return coverage_source_locations.items.len;
}
export fn coveredSourceLocations() usize {
const covered_bits = recent_coverage_update.items[@sizeOf(abi.CoverageUpdateHeader)..];
var count: usize = 0;
for (covered_bits) |byte| count += @popCount(byte);
return count;
}
export fn totalRuns() u64 {
const header: *abi.CoverageUpdateHeader = @ptrCast(recent_coverage_update.items[0..@sizeOf(abi.CoverageUpdateHeader)]);
return header.n_runs;