aboutsummaryrefslogtreecommitdiff
path: root/lib/fuzzer
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-08-04 15:45:16 -0700
committerAndrew Kelley <andrew@ziglang.org>2024-08-07 00:48:32 -0700
commitf56d11350313d5e45be0679bd8fab2a96892c40c (patch)
tree5edaa66b6b03eb15e39f257f39c71233ca9f2283 /lib/fuzzer
parentdec7e45f7c7e61a3778767bbc7f8e1e9a33b01fa (diff)
downloadzig-f56d11350313d5e45be0679bd8fab2a96892c40c.tar.gz
zig-f56d11350313d5e45be0679bd8fab2a96892c40c.zip
fuzzer web ui: render stats
Diffstat (limited to 'lib/fuzzer')
-rw-r--r--lib/fuzzer/index.html7
-rw-r--r--lib/fuzzer/main.js20
-rw-r--r--lib/fuzzer/wasm/main.zig17
3 files changed, 43 insertions, 1 deletions
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 @@
</head>
<body>
<p id="status">Loading JavaScript...</p>
+ <div id="sectStats" class="hidden">
+ <ul>
+ <li>Total Runs: <span id="statTotalRuns"></span></li>
+ <li>Unique Runs: <span id="statUniqueRuns"></span></li>
+ <li>Lowest Stack: <span id="statLowestStack"></span></li>
+ </ul>
+ </div>
<div id="sectSource" class="hidden">
<h2>Source Code</h2>
<pre><code id="sourceText"></code></pre>
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 {