mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 23:23:28 +00:00
wpt: add safe test run in separate process
This commit is contained in:
@@ -17,6 +17,8 @@ const usage =
|
|||||||
\\
|
\\
|
||||||
\\ -h, --help Print this help message and exit.
|
\\ -h, --help Print this help message and exit.
|
||||||
\\ --json result is formatted in JSON.
|
\\ --json result is formatted in JSON.
|
||||||
|
\\ --safe each test is run in a separate process.
|
||||||
|
\\ --summary print a summary result. Incompatible w/ --json
|
||||||
\\
|
\\
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -41,6 +43,8 @@ pub fn main() !void {
|
|||||||
const execname = args.next().?;
|
const execname = args.next().?;
|
||||||
|
|
||||||
var json = false;
|
var json = false;
|
||||||
|
var safe = false;
|
||||||
|
var summary = false;
|
||||||
|
|
||||||
var filter = std.ArrayList([]const u8).init(alloc);
|
var filter = std.ArrayList([]const u8).init(alloc);
|
||||||
defer filter.deinit();
|
defer filter.deinit();
|
||||||
@@ -54,16 +58,26 @@ pub fn main() !void {
|
|||||||
json = true;
|
json = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (std.mem.eql(u8, "--safe", arg)) {
|
||||||
|
safe = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (std.mem.eql(u8, "--summary", arg)) {
|
||||||
|
summary = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
try filter.append(arg[0..]);
|
try filter.append(arg[0..]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize VM JS lib.
|
// both json and summary are incompatible.
|
||||||
const vm = jsruntime.VM.init();
|
if (summary and json) {
|
||||||
defer vm.deinit();
|
try std.io.getStdErr().writer().print("--json and --summary are incompatible\n", .{});
|
||||||
|
std.os.exit(1);
|
||||||
// prepare libraries to load on each test case.
|
}
|
||||||
var loader = FileLoader.init(alloc, wpt_dir);
|
// summary is available in safe mode only.
|
||||||
defer loader.deinit();
|
if (summary) {
|
||||||
|
safe = true;
|
||||||
|
}
|
||||||
|
|
||||||
// browse the dir to get the tests dynamically.
|
// browse the dir to get the tests dynamically.
|
||||||
var list = std.ArrayList([]const u8).init(alloc);
|
var list = std.ArrayList([]const u8).init(alloc);
|
||||||
@@ -75,6 +89,61 @@ pub fn main() !void {
|
|||||||
list.deinit();
|
list.deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (safe) {
|
||||||
|
for (list.items) |tc| {
|
||||||
|
// 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);
|
||||||
defer {
|
defer {
|
||||||
for (results.items) |suite| {
|
for (results.items) |suite| {
|
||||||
@@ -83,6 +152,14 @@ pub fn main() !void {
|
|||||||
results.deinit();
|
results.deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// initialize VM JS lib.
|
||||||
|
const vm = jsruntime.VM.init();
|
||||||
|
defer vm.deinit();
|
||||||
|
|
||||||
|
// prepare libraries to load on each test case.
|
||||||
|
var loader = FileLoader.init(alloc, wpt_dir);
|
||||||
|
defer loader.deinit();
|
||||||
|
|
||||||
var run: usize = 0;
|
var run: usize = 0;
|
||||||
var failures: usize = 0;
|
var failures: usize = 0;
|
||||||
for (list.items) |tc| {
|
for (list.items) |tc| {
|
||||||
|
|||||||
Reference in New Issue
Block a user