Skip to content

Commit dc46f32

Browse files
author
Jan Philipp Hafer
committed
add files for presentation at next stage2 meeting.
1 parent cae796a commit dc46f32

File tree

3 files changed

+68
-9
lines changed

3 files changed

+68
-9
lines changed

example.zig

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const std = @import("std");
2+
3+
// PROTOTYPE intended for presentation
4+
5+
const panic_runner = @import("lib/panic_runner.zig");
6+
test "testme1" {
7+
std.debug.assert(true);
8+
panic_runner.writeExpectedPanicMsg("test123");
9+
@panic("test123");
10+
}
11+
test "testme2" {
12+
std.debug.assert(true);
13+
}
14+
// test "testme4" {
15+
// panic_runner.writeExpectedPanicMsg("bruh");
16+
// @panic("wrongmsg");
17+
// }
18+
19+
// test "testme4" {
20+
// @panic("no_expected_panic_msg");
21+
// }
22+
23+
// tradeoffs:
24+
// + simple and works with current routines
25+
// - only 1 panic inside a test block and must be last item
26+
// - requires process spawning and IPC (separates embedded and hosted environments)
27+
//
28+
// my opinion:
29+
// - feels like a hacky workaround (like Kernel spawn APIs I needed to modify)
30+
// - more elegant solution would be copying complete program state with a
31+
// bespoke debugging api + let user define store + load points for programs:
32+
// ```
33+
// test "testme" {
34+
// var i: u32 = 0;
35+
// @storeProgramState
36+
// panic_runner.writeExpectedPanicMsg("test123");
37+
// while (i < 100): (i+=1) {
38+
// if (i == 77) {
39+
// panic_runner.writeExpectedPanicMsg("test77");
40+
// @panic("test123");
41+
// }
42+
// }
43+
// @loadProgramState
44+
// i = 100;
45+
// @storeProgramState
46+
// panic_runner.writeExpectedPanicMsg("test123");
47+
// while (i < 200): (i+=1) {
48+
// if (i == 177) {
49+
// panic_runner.writeExpectedPanicMsg("test177");
50+
// @panic("test123");
51+
// }
52+
// }
53+
// @loadProgramState
54+
// ```
55+

lib/panic_runner.zig

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
7979
msg_wr.writeIntNative(usize, global.failed) catch unreachable;
8080

8181
if (std.mem.eql(u8, message, global.buf_panic_msg[0..global.buf_panic_msg_fill])) {
82-
std.debug.print("execpted panic\n", .{});
82+
// std.debug.print("execpted panic\n", .{});
8383
msg_wr.writeByte(@intCast(u8, @enumToInt(PanicT.expected_panic))) catch unreachable;
8484
msg_pipe_file.close(); // workaround process.exit
8585
std.process.exit(0);
8686
} else {
87-
std.debug.print("unexecpted panic\n", .{});
87+
// std.debug.print("unexecpted panic\n", .{});
8888
msg_wr.writeByte(@intCast(u8, @enumToInt(PanicT.unexpected_panic))) catch unreachable;
8989
msg_pipe_file.close(); // workaround process.exit
9090
std.debug.panic("{s}", .{message});
@@ -130,12 +130,12 @@ fn processArgs(static_alloc: std.mem.Allocator) Cli {
130130

131131
cli.state = .Worker;
132132
cli.test_nr = std.fmt.parseUnsigned(u64, args[1], 10) catch unreachable;
133-
std.debug.print("test worker (exe_path test_nr handle: ", .{});
134-
std.debug.print("{s} {s} {s}\n", .{ args[0], args[1], args[2] });
133+
// std.debug.print("test worker (exe_path test_nr handle: ", .{});
134+
// std.debug.print("{s} {s} {s}\n", .{ args[0], args[1], args[2] });
135135
} else {
136136
cli.state = .Control;
137137
cli.test_nr = 0;
138-
std.debug.print("test control: {s}\n", .{args[0]});
138+
// std.debug.print("test control: {s}\n", .{args[0]});
139139
}
140140
cli.test_runner_exe_path = args[0];
141141
return cli;
@@ -174,7 +174,7 @@ pub fn main() !void {
174174
try child_proc.spawn();
175175
}
176176
const ret_term = try child_proc.wait();
177-
std.debug.print("ret_term: {any}\n", .{ret_term.Exited});
177+
// std.debug.print("ret_term: {any}\n", .{ret_term.Exited});
178178
if (ret_term.Exited != @enumToInt(ChildProcess.Term.Exited)) {
179179
@panic("TODO: handle printing message for exit reason.");
180180
}
@@ -187,11 +187,11 @@ pub fn main() !void {
187187
};
188188
const file_rd = file.reader();
189189
const ret_passed = try file_rd.readIntNative(usize);
190-
std.debug.print("ctrl passed: {d}\n", .{ret_passed});
190+
// std.debug.print("ctrl passed: {d}\n", .{ret_passed});
191191
const ret_skipped = try file_rd.readIntNative(usize);
192-
std.debug.print("ctrl skipped: {d}\n", .{ret_skipped});
192+
// std.debug.print("ctrl skipped: {d}\n", .{ret_skipped});
193193
const ret_failed = try file_rd.readIntNative(usize);
194-
std.debug.print("ctrl fail: {d}\n", .{ret_failed});
194+
// std.debug.print("ctrl fail: {d}\n", .{ret_failed});
195195
global.passed += ret_passed;
196196
global.skipped += ret_skipped;
197197
global.failed += ret_failed;

t.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
#set -e
3+
./rel/bin/zig test --test-runner lib/panic_runner.zig example.zig
4+
echo "exit status: $?"

0 commit comments

Comments
 (0)