diff --git a/lib/fuzzer/index.html b/lib/fuzzer/index.html index 0753bcae67..fc3f1fe4d2 100644 --- a/lib/fuzzer/index.html +++ b/lib/fuzzer/index.html @@ -125,6 +125,13 @@
Loading JavaScript...
+
diff --git a/lib/fuzzer/main.js b/lib/fuzzer/main.js
index 6fed056a5e..fa90d4c8dd 100644
--- a/lib/fuzzer/main.js
+++ b/lib/fuzzer/main.js
@@ -1,7 +1,11 @@
(function() {
const domStatus = document.getElementById("status");
const domSectSource = document.getElementById("sectSource");
+ const domSectStats = document.getElementById("sectStats");
const domSourceText = document.getElementById("sourceText");
+ const domStatTotalRuns = document.getElementById("statTotalRuns");
+ const domStatUniqueRuns = document.getElementById("statUniqueRuns");
+ const domStatLowestStack = document.getElementById("statLowestStack");
let wasm_promise = fetch("main.wasm");
let sources_promise = fetch("sources.tar").then(function(response) {
@@ -94,7 +98,7 @@
}
function onCoverageUpdate() {
- console.log("coverage update");
+ renderStats();
}
function render() {
@@ -105,6 +109,20 @@
renderSource("/home/andy/dev/zig/lib/std/zig/tokenizer.zig");
}
+ function renderStats() {
+ const totalRuns = wasm_exports.totalRuns();
+ const uniqueRuns = wasm_exports.uniqueRuns();
+ domStatTotalRuns.innerText = totalRuns;
+ domStatUniqueRuns.innerText = uniqueRuns + " (" + percent(uniqueRuns, totalRuns) + "%)";
+ domStatLowestStack.innerText = unwrapString(wasm_exports.lowestStack());
+
+ domSectStats.classList.remove("hidden");
+ }
+
+ function percent(a, b) {
+ return ((Number(a) / Number(b)) * 100).toFixed(1);
+ }
+
function renderSource(path) {
const decl_index = findFileRoot(path);
if (decl_index == null) throw new Error("file not found: " + path);
diff --git a/lib/fuzzer/wasm/main.zig b/lib/fuzzer/wasm/main.zig
index fd785d5723..adbe3e5646 100644
--- a/lib/fuzzer/wasm/main.zig
+++ b/lib/fuzzer/wasm/main.zig
@@ -103,6 +103,23 @@ export fn decl_source_html(decl_index: Decl.Index) String {
return String.init(string_result.items);
}
+export fn lowestStack() String {
+ const header: *abi.CoverageUpdateHeader = @ptrCast(recent_coverage_update.items[0..@sizeOf(abi.CoverageUpdateHeader)]);
+ string_result.clearRetainingCapacity();
+ string_result.writer(gpa).print("0x{d}", .{header.lowest_stack}) catch @panic("OOM");
+ return String.init(string_result.items);
+}
+
+export fn totalRuns() u64 {
+ const header: *abi.CoverageUpdateHeader = @ptrCast(recent_coverage_update.items[0..@sizeOf(abi.CoverageUpdateHeader)]);
+ return header.n_runs;
+}
+
+export fn uniqueRuns() u64 {
+ const header: *abi.CoverageUpdateHeader = @ptrCast(recent_coverage_update.items[0..@sizeOf(abi.CoverageUpdateHeader)]);
+ return header.unique_runs;
+}
+
const String = Slice(u8);
fn Slice(T: type) type {