mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-30 15:41:48 +00:00
wpt: move safe run in its own func
This commit is contained in:
120
src/main_wpt.zig
120
src/main_wpt.zig
@@ -90,62 +90,7 @@ pub fn main() !void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (safe) {
|
if (safe) {
|
||||||
for (list.items) |tc| {
|
return try runSafe(alloc, execname, summary, list.items, filter.items);
|
||||||
if (!shouldRun(filter.items, tc)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO use std.ChildProcess.run after next zig upgrade.
|
|
||||||
var child = std.ChildProcess.init(&.{ execname, tc }, alloc);
|
|
||||||
child.stdin_behavior = .Ignore;
|
|
||||||
child.stdout_behavior = .Pipe;
|
|
||||||
child.stderr_behavior = .Pipe;
|
|
||||||
|
|
||||||
var stdout = std.ArrayList(u8).init(alloc);
|
|
||||||
var stderr = std.ArrayList(u8).init(alloc);
|
|
||||||
defer {
|
|
||||||
stdout.deinit();
|
|
||||||
stderr.deinit();
|
|
||||||
}
|
|
||||||
|
|
||||||
try child.spawn();
|
|
||||||
try child.collectOutput(&stdout, &stderr, 1024 * 1024);
|
|
||||||
const term = try child.wait();
|
|
||||||
|
|
||||||
const Result = enum {
|
|
||||||
pass,
|
|
||||||
fail,
|
|
||||||
crash,
|
|
||||||
};
|
|
||||||
|
|
||||||
var result: Result = undefined;
|
|
||||||
switch (term) {
|
|
||||||
.Exited => |v| {
|
|
||||||
if (v == 0) {
|
|
||||||
result = .pass;
|
|
||||||
} else {
|
|
||||||
result = .fail;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
.Signal => result = .crash,
|
|
||||||
.Stopped => result = .crash,
|
|
||||||
.Unknown => result = .crash,
|
|
||||||
}
|
|
||||||
|
|
||||||
if (summary) {
|
|
||||||
switch (result) {
|
|
||||||
.pass => std.debug.print("Pass", .{}),
|
|
||||||
.fail => std.debug.print("Fail", .{}),
|
|
||||||
.crash => std.debug.print("Crash", .{}),
|
|
||||||
}
|
|
||||||
std.debug.print("\t{s}\n", .{tc});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
std.debug.print("{s}\n", .{stderr.items});
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var results = std.ArrayList(Suite).init(alloc);
|
var results = std.ArrayList(Suite).init(alloc);
|
||||||
@@ -286,3 +231,66 @@ fn shouldRun(filter: [][]const u8, tc: []const u8) bool {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn runSafe(
|
||||||
|
alloc: std.mem.Allocator,
|
||||||
|
execname: []const u8,
|
||||||
|
summary: bool,
|
||||||
|
testcases: [][]const u8,
|
||||||
|
filter: [][]const u8,
|
||||||
|
) !void {
|
||||||
|
const Result = enum {
|
||||||
|
pass,
|
||||||
|
fail,
|
||||||
|
crash,
|
||||||
|
};
|
||||||
|
|
||||||
|
for (testcases) |tc| {
|
||||||
|
if (!shouldRun(filter, tc)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO use std.ChildProcess.run after next zig upgrade.
|
||||||
|
var child = std.ChildProcess.init(&.{ execname, tc }, alloc);
|
||||||
|
child.stdin_behavior = .Ignore;
|
||||||
|
child.stdout_behavior = .Pipe;
|
||||||
|
child.stderr_behavior = .Pipe;
|
||||||
|
|
||||||
|
var stdout = std.ArrayList(u8).init(alloc);
|
||||||
|
var stderr = std.ArrayList(u8).init(alloc);
|
||||||
|
defer {
|
||||||
|
stdout.deinit();
|
||||||
|
stderr.deinit();
|
||||||
|
}
|
||||||
|
|
||||||
|
try child.spawn();
|
||||||
|
try child.collectOutput(&stdout, &stderr, 1024 * 1024);
|
||||||
|
const term = try child.wait();
|
||||||
|
|
||||||
|
var result: Result = undefined;
|
||||||
|
switch (term) {
|
||||||
|
.Exited => |v| {
|
||||||
|
if (v == 0) {
|
||||||
|
result = .pass;
|
||||||
|
} else {
|
||||||
|
result = .fail;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
.Signal => result = .crash,
|
||||||
|
.Stopped => result = .crash,
|
||||||
|
.Unknown => result = .crash,
|
||||||
|
}
|
||||||
|
|
||||||
|
if (summary) {
|
||||||
|
switch (result) {
|
||||||
|
.pass => std.debug.print("Pass", .{}),
|
||||||
|
.fail => std.debug.print("Fail", .{}),
|
||||||
|
.crash => std.debug.print("Crash", .{}),
|
||||||
|
}
|
||||||
|
std.debug.print("\t{s}\n", .{tc});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
std.debug.print("{s}\n", .{stderr.items});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user