From e64a00950e7ec505fdcdb53da265828d1263bc22 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 4 Aug 2024 17:48:08 -0700 Subject: [PATCH] fuzzer web ui: introduce entry points so you can have somewhere to start browsing --- lib/compiler/test_runner.zig | 14 ++++++- lib/fuzzer/index.html | 1 + lib/fuzzer/main.js | 32 +++++++++++++--- lib/fuzzer/wasm/main.zig | 26 +++++++++++++ lib/std/Build/Fuzz/WebServer.zig | 64 ++++++++++++++++++++++++++++++-- lib/std/Build/Fuzz/abi.zig | 14 +++++++ lib/std/Build/Step/Run.zig | 19 +++++++++- lib/std/zig/Server.zig | 4 ++ 8 files changed, 163 insertions(+), 11 deletions(-) diff --git a/lib/compiler/test_runner.zig b/lib/compiler/test_runner.zig index 65580fcd3f..4be261912c 100644 --- a/lib/compiler/test_runner.zig +++ b/lib/compiler/test_runner.zig @@ -1,8 +1,10 @@ //! Default test runner for unit tests. const builtin = @import("builtin"); + const std = @import("std"); const io = std.io; const testing = std.testing; +const assert = std.debug.assert; pub const std_options = .{ .logFn = log, @@ -141,7 +143,9 @@ fn mainServer() !void { }); }, .start_fuzzing => { + if (!builtin.fuzz) unreachable; const index = try server.receiveBody_u32(); + var first = true; const test_fn = builtin.test_functions[index]; while (true) { testing.allocator_instance = .{}; @@ -160,6 +164,10 @@ fn mainServer() !void { }; if (!is_fuzz_test) @panic("missed call to std.testing.fuzzInput"); if (log_err_count != 0) @panic("error logs detected"); + if (first) { + first = false; + try server.serveU64Message(.fuzz_start_addr, entry_addr); + } } }, @@ -339,6 +347,7 @@ const FuzzerSlice = extern struct { }; var is_fuzz_test: bool = undefined; +var entry_addr: usize = 0; extern fn fuzzer_next() FuzzerSlice; extern fn fuzzer_init(cache_dir: FuzzerSlice) void; @@ -348,7 +357,10 @@ pub fn fuzzInput(options: testing.FuzzInputOptions) []const u8 { @disableInstrumentation(); if (crippled) return ""; is_fuzz_test = true; - if (builtin.fuzz) return fuzzer_next().toSlice(); + if (builtin.fuzz) { + if (entry_addr == 0) entry_addr = @returnAddress(); + return fuzzer_next().toSlice(); + } if (options.corpus.len == 0) return ""; var prng = std.Random.DefaultPrng.init(testing.random_seed); const random = prng.random(); diff --git a/lib/fuzzer/index.html b/lib/fuzzer/index.html index f4c9753471..7142bf3437 100644 --- a/lib/fuzzer/index.html +++ b/lib/fuzzer/index.html @@ -131,6 +131,7 @@
  • Unique Runs:
  • Coverage:
  • Lowest Stack:
  • +
  • Entry Points: