authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-08-05 16:23:30-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-08-07 00:48:32-07:00
log38227e92898a049412ddaab6c8596218d32db650
tree85c9071f6ac4220288df67d6be18f5879fb00469
parent3d48602c995b90e40c6e70ace1e0cdcdeea2eac4

fuzzer web UI: render PCs with red or green depending on coverage


3 files changed, 56 insertions(+), 9 deletions(-)

lib/fuzzer/index.html+14-5
...@@ -53,11 +53,14 @@...@@ -53,11 +53,14 @@
53 }53 }
5454
55 .l {55 .l {
56 display: inline-block;56 display: inline-block;
57 background: white;57 background: red;
58 width: 1em;58 width: 1em;
59 height: 1em;59 height: 1em;
60 border-radius: 1em;60 border-radius: 1em;
61 }
62 .c {
63 background-color: green;
61 }64 }
6265
63 .tok-kw {66 .tok-kw {
...@@ -104,6 +107,12 @@...@@ -104,6 +107,12 @@
104 code a {107 code a {
105 color: #ccc;108 color: #ccc;
106 }109 }
110 .l {
111 background-color: red;
112 }
113 .c {
114 background-color: green;
115 }
107 .tok-kw {116 .tok-kw {
108 color: #eee;117 color: #eee;
109 }118 }
lib/fuzzer/main.js+15-4
...@@ -172,12 +172,20 @@...@@ -172,12 +172,20 @@
172 }172 }
173173
174 function renderCoverage() {174 function renderCoverage() {
175 if (curNavLocation == null) return;
176 const sourceLocationIndex = curNavLocation;
177
175 for (let i = 0; i < domSourceText.children.length; i += 1) {178 for (let i = 0; i < domSourceText.children.length; i += 1) {
176 const childDom = domSourceText.children[i];179 const childDom = domSourceText.children[i];
177 if (childDom.id != null && childDom.id[0] == "l") {180 if (childDom.id != null && childDom.id[0] == "l") {
178 childDom.classList.add("l");181 childDom.classList.add("l");
182 childDom.classList.remove("c");
179 }183 }
180 }184 }
185 const coveredList = unwrapInt32Array(wasm_exports.sourceLocationFileCoveredList(sourceLocationIndex));
186 for (let i = 0; i < coveredList.length; i += 1) {
187 document.getElementById("l" + coveredList[i]).classList.add("c");
188 }
181 }189 }
182190
183 function resizeDomList(listDom, desiredLen, templateHtml) {191 function resizeDomList(listDom, desiredLen, templateHtml) {
...@@ -203,10 +211,13 @@...@@ -203,10 +211,13 @@
203211
204 domSectSource.classList.remove("hidden");212 domSectSource.classList.remove("hidden");
205213
206 const slDom = document.getElementById("l" + sourceLocationIndex);214 // Empirically, Firefox needs this requestAnimationFrame in order for the scrollIntoView to work.
207 slDom.scrollIntoView({215 requestAnimationFrame(function() {
208 behavior: "smooth",216 const slDom = document.getElementById("l" + sourceLocationIndex);
209 block: "center",217 slDom.scrollIntoView({
218 behavior: "smooth",
219 block: "center",
220 });
210 });221 });
211 }222 }
212223
lib/fuzzer/wasm/main.zig+27
...@@ -395,3 +395,30 @@ export fn sourceLocationFileHtml(sli: SourceLocationIndex) String {...@@ -395,3 +395,30 @@ export fn sourceLocationFileHtml(sli: SourceLocationIndex) String {
395 };395 };
396 return String.init(string_result.items);396 return String.init(string_result.items);
397}397}
398
399export fn sourceLocationFileCoveredList(sli_file: SourceLocationIndex) Slice(SourceLocationIndex) {
400 const global = struct {
401 var result: std.ArrayListUnmanaged(SourceLocationIndex) = .{};
402 fn add(i: u32, want_file: Coverage.File.Index) void {
403 const src_loc_index: SourceLocationIndex = @enumFromInt(i);
404 if (src_loc_index.ptr().file == want_file) result.appendAssumeCapacity(src_loc_index);
405 }
406 };
407 const want_file = sli_file.ptr().file;
408 global.result.clearRetainingCapacity();
409 const covered_bits = recent_coverage_update.items[@sizeOf(abi.CoverageUpdateHeader)..];
410 var sli: u32 = 0;
411 for (covered_bits) |byte| {
412 global.result.ensureUnusedCapacity(gpa, 8) catch @panic("OOM");
413 if ((byte & 0b0000_0001) != 0) global.add(sli + 0, want_file);
414 if ((byte & 0b0000_0010) != 0) global.add(sli + 1, want_file);
415 if ((byte & 0b0000_0100) != 0) global.add(sli + 2, want_file);
416 if ((byte & 0b0000_1000) != 0) global.add(sli + 3, want_file);
417 if ((byte & 0b0001_0000) != 0) global.add(sli + 4, want_file);
418 if ((byte & 0b0010_0000) != 0) global.add(sli + 5, want_file);
419 if ((byte & 0b0100_0000) != 0) global.add(sli + 6, want_file);
420 if ((byte & 0b1000_0000) != 0) global.add(sli + 7, want_file);
421 sli += 8;
422 }
423 return Slice(SourceLocationIndex).init(global.result.items);
424}