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 @@
5353 }
5454
5555 .l {
56 display: inline-block;
57 background: white;
58 width: 1em;
59 height: 1em;
60 border-radius: 1em;
56 display: inline-block;
57 background: red;
58 width: 1em;
59 height: 1em;
60 border-radius: 1em;
61 }
62 .c {
63 background-color: green;
6164 }
6265
6366 .tok-kw {
......@@ -104,6 +107,12 @@
104107 code a {
105108 color: #ccc;
106109 }
110 .l {
111 background-color: red;
112 }
113 .c {
114 background-color: green;
115 }
107116 .tok-kw {
108117 color: #eee;
109118 }
lib/fuzzer/main.js+15-4
......@@ -172,12 +172,20 @@
172172 }
173173
174174 function renderCoverage() {
175 if (curNavLocation == null) return;
176 const sourceLocationIndex = curNavLocation;
177
175178 for (let i = 0; i < domSourceText.children.length; i += 1) {
176179 const childDom = domSourceText.children[i];
177180 if (childDom.id != null && childDom.id[0] == "l") {
178181 childDom.classList.add("l");
182 childDom.classList.remove("c");
179183 }
180184 }
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 }
181189 }
182190
183191 function resizeDomList(listDom, desiredLen, templateHtml) {
......@@ -203,10 +211,13 @@
203211
204212 domSectSource.classList.remove("hidden");
205213
206 const slDom = document.getElementById("l" + sourceLocationIndex);
207 slDom.scrollIntoView({
208 behavior: "smooth",
209 block: "center",
214 // Empirically, Firefox needs this requestAnimationFrame in order for the scrollIntoView to work.
215 requestAnimationFrame(function() {
216 const slDom = document.getElementById("l" + sourceLocationIndex);
217 slDom.scrollIntoView({
218 behavior: "smooth",
219 block: "center",
220 });
210221 });
211222 }
212223
lib/fuzzer/wasm/main.zig+27
......@@ -395,3 +395,30 @@ export fn sourceLocationFileHtml(sli: SourceLocationIndex) String {
395395 };
396396 return String.init(string_result.items);
397397}
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}