Re-enable test metrics

Both the durations and allocations will be _much_ higher with the new htmlRunner
which, for example, does 2 HTTP requests per test (html, testing.js).

https://github.com/lightpanda-io/browser/issues/1057
This commit is contained in:
Karl Seguin
2025-09-18 19:55:37 +08:00
parent 36ce227bf6
commit 346f538c3b
2 changed files with 16 additions and 4 deletions

View File

@@ -35,7 +35,7 @@ pub const std_options = std.Options{
};
pub var js_runner_duration: usize = 0;
pub var tracking_allocator = TrackingAllocator.init(std.testing.allocator);
pub var tracking_allocator: Allocator = undefined;
pub fn main() !void {
var mem: [8192]u8 = undefined;
@@ -52,6 +52,12 @@ pub fn main() !void {
var args = try std.process.argsWithAllocator(allocator);
defer args.deinit();
var tracking_arena = std.heap.ArenaAllocator.init(std.heap.c_allocator);
defer tracking_arena.deinit();
var ta = TrackingAllocator.init(tracking_arena.allocator());
tracking_allocator = ta.allocator();
// ignore the exec name.
_ = args.next();
var json_stats = false;
@@ -82,6 +88,7 @@ pub fn main() !void {
if (isSetup(t) or isTeardown(t)) {
continue;
}
defer _ = tracking_arena.reset(.retain_capacity);
var status = Status.pass;
slowest.startTiming();
@@ -175,7 +182,7 @@ pub fn main() !void {
if (json_stats) {
var stdout = std.fs.File.stdout();
var writer = stdout.writer(&.{});
const stats = tracking_allocator.stats();
const stats = ta.stats();
try std.json.Stringify.value(&.{
.{ .name = "browser", .bench = .{
.duration = js_runner_duration,

View File

@@ -360,8 +360,6 @@ fn isJsonValue(a: std.json.Value, b: std.json.Value) bool {
}
}
pub const tracking_allocator = @import("root").tracking_allocator.allocator();
var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
pub var test_app: *App = undefined;
pub var test_browser: Browser = undefined;
@@ -387,9 +385,14 @@ pub fn shutdown() void {
pub fn htmlRunner(file: []const u8) !void {
defer _ = arena_instance.reset(.retain_capacity);
const start = try std.time.Instant.now();
const page = try test_session.createPage();
defer test_session.removePage();
page.arena = @import("root").tracking_allocator;
const js_context = page.main_context;
var try_catch: Env.TryCatch = undefined;
try_catch.init(js_context);
@@ -399,6 +402,8 @@ pub fn htmlRunner(file: []const u8) !void {
try page.navigate(url, .{});
_ = page.wait(2000);
@import("root").js_runner_duration += std.time.Instant.since(try std.time.Instant.now(), start);
const value = js_context.exec("testing.getStatus()", "testing.getStatus()") catch |err| {
const msg = try_catch.err(arena_allocator) catch @errorName(err) orelse "unknown";
std.debug.print("{s}: test failure\nError: {s}\n", .{ file, msg });