Add runtime testing harness
This commit is contained in:
parent
f8f7e40535
commit
35cfbd1686
9 changed files with 103 additions and 13 deletions
36
build.zig
36
build.zig
|
@ -25,7 +25,9 @@ pub fn build(b: *Builder) void {
|
|||
var build_path = b.option([]const u8, "build-path", "path to build to") orelse "bin";
|
||||
var src_path = b.option([]const u8, "source-path", "path to source") orelse "src";
|
||||
var target = b.option([]const u8, "target", "target to build/run for") orelse "x86";
|
||||
const rt_test = b.option(bool, "rt-test", "enable/disable runtime testing") orelse false;
|
||||
const builtin_target = if (mem.eql(u8, target, "x86")) builtin.Arch.i386 else unreachable;
|
||||
const zig_path = b.option([]const u8, "zig-path", "the path to the zig binary to use for rt testing") orelse "/snap/bin/zig";
|
||||
|
||||
b.makePath(build_path) catch unreachable;
|
||||
var grub_path = concat(b.allocator, build_path, "/iso/boot/grub") catch unreachable;
|
||||
|
@ -60,20 +62,25 @@ pub fn build(b: *Builder) void {
|
|||
b.default_step.dependOn(link_step);
|
||||
for (iso_step.toSlice()) |step| b.default_step.dependOn(step);
|
||||
|
||||
buildRun(b, builtin_target, build_path, iso_path.toSlice(), debug);
|
||||
buildRun(b, builtin_target, build_path, iso_path.toSlice(), debug, rt_test);
|
||||
buildDebug(b);
|
||||
buildTest(b, src_path);
|
||||
buildTest(b, src_path, rt_test, target, zig_path);
|
||||
}
|
||||
|
||||
fn buildTest(b: *Builder, src_path: []const u8) void {
|
||||
const step = b.step("test", "Run all tests");
|
||||
const src_path2 = concat(b.allocator, src_path, "/") catch unreachable;
|
||||
for (src_files.toSlice()) |file| {
|
||||
var file_src = concat(b.allocator, src_path2.toSlice(), file) catch unreachable;
|
||||
file_src.append(".zig") catch unreachable;
|
||||
const tst = b.addTest(file_src.toSlice());
|
||||
tst.setMainPkgPath(".");
|
||||
step.dependOn(&tst.step);
|
||||
fn buildTest(b: *Builder, src_path: []const u8, rt_test: bool, target: []const u8, zig_path: []const u8) void {
|
||||
const step = b.step("test", "Run tests");
|
||||
if (rt_test) {
|
||||
const script = b.addSystemCommand([][]const u8{ "python3", "test/rt-test.py", target, zig_path});
|
||||
step.dependOn(&script.step);
|
||||
} else {
|
||||
const src_path2 = concat(b.allocator, src_path, "/") catch unreachable;
|
||||
for (src_files.toSlice()) |file| {
|
||||
var file_src = concat(b.allocator, src_path2.toSlice(), file) catch unreachable;
|
||||
file_src.append(".zig") catch unreachable;
|
||||
const tst = b.addTest(file_src.toSlice());
|
||||
tst.setMainPkgPath(".");
|
||||
step.dependOn(&tst.step);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,7 +96,7 @@ fn buildDebug(b: *Builder) void {
|
|||
step.dependOn(&cmd.step);
|
||||
}
|
||||
|
||||
fn buildRun(b: *Builder, target: builtin.Arch, build_path: []const u8, iso_path: []const u8, debug: bool) void {
|
||||
fn buildRun(b: *Builder, target: builtin.Arch, build_path: []const u8, iso_path: []const u8, debug: bool, rt_test: bool) void {
|
||||
const step = b.step("run", "Run with qemu");
|
||||
const qemu = if (target == builtin.Arch.i386) "qemu-system-i386" else unreachable;
|
||||
var qemu_flags = ArrayList([]const u8).init(b.allocator);
|
||||
|
@ -107,6 +114,11 @@ fn buildRun(b: *Builder, target: builtin.Arch, build_path: []const u8, iso_path:
|
|||
"-s",
|
||||
"-S",
|
||||
}) catch unreachable;
|
||||
if (rt_test)
|
||||
qemu_flags.appendSlice([][]const u8{
|
||||
"-display",
|
||||
"none"
|
||||
}) catch unreachable;
|
||||
const cmd = b.addSystemCommand(qemu_flags.toSlice());
|
||||
step.dependOn(&cmd.step);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue