diff options
Diffstat (limited to 'build/kernel.zig')
| -rw-r--r-- | build/kernel.zig | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/build/kernel.zig b/build/kernel.zig index 48c920f..bbed126 100644 --- a/build/kernel.zig +++ b/build/kernel.zig @@ -8,12 +8,14 @@ pub fn add(ctx: Ctx) void { // The tests run these: they get the paths as `@import("targets")`. const paths = b.addOptions(); + var targets: [3]*std.Build.Step.Compile = undefined; inline for (.{ .{ "spin", &.{"kernel_spin.c"} }, .{ "touch", &.{"kernel_touch.c"} }, .{ "usdt", &.{ "kernel_usdt.c", "kernel_usdt_tick.c" } }, - }) |t| { + }, &targets) |t, *target| { const exe = ctx.cTarget("kernel_" ++ t[0], t[1]); + target.* = exe; paths.addOptionPath(t[0], exe.getEmittedBin()); // ... and `zig build` leaves them in zig-out/targets to try things on. b.getInstallStep().dependOn(&b.addInstallArtifact(exe, .{ .dest_dir = .{ .override = .{ .custom = "targets" } } }).step); @@ -25,4 +27,27 @@ pub fn add(ctx: Ctx) void { .imports = &.{ .{ .name = "ztrace", .module = ctx.ztrace }, .{ .name = "targets", .module = paths.createModule() } }, }) }); step.dependOn(&b.addRunArtifact(tests).step); + + // The BPF side for real: this machine's kernel booted in QEMU, where we + // are root. Not part of `test`: it wants qemu, /dev/kvm, cpio and a + // kernel image a user can read. + const vm = b.addSystemCommand(&.{"sh"}); + vm.addFileArg(b.path("build/kernel_vm.sh")); + vm.addArtifactArg(ctx.zigTarget("kernel_vminit", "targets/kernel_vminit.zig")); + vm.addFileArg(b.addWriteFiles().add("commands", + \\/ztrace probe -o /touch.ztrace --syscalls --sched --kprobe do_sys_openat2 --uprobe step --uprobe /usr/lib/libc.so.6:malloc -- /kernel_touch 4 3 + \\/ztrace dump /touch.ztrace + \\/ztrace probe -o /usdt.ztrace --usdt ztrace:start --usdt ztrace:tick --usdt ztrace:done -- /kernel_usdt 4 + \\/ztrace dump /usdt.ztrace + \\ + )); + vm.addArtifactArg(ctx.exe); + for (targets[1..]) |target| vm.addArtifactArg(target); + // Nothing lost; a syscall (clock_nanosleep) and a switch; malloc(1003) + // in libc; step(1002, 2001) in the thread; tick(3, 14) with its semaphore. + for ([_][]const u8{ + "(0 lost)", " syscall_enter ", " aux=230 ", " sched ", + " a=7166cdb822920ddd 3eb ", " a=a02712eb14a9b985 3ea 7d1 ", " a=7f4909df02928d94 3 e ", + }) |expected| vm.expectStdOutMatch(expected); + b.step("test-kernel-vm", "Run the BPF programs as root in a QEMU VM of this kernel").dependOn(&vm.step); } |
