Skip to content

Commit f84e09c

Browse files
author
Jan Philipp Hafer
committed
cleanups
1 parent d956e1a commit f84e09c

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

lib/panic_runner.zig

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
//! Panic test runner
2+
//! assume: process spawning + IPC capabilities to keep things simple and test behavior = code behavior
23
//! Control starts itself as Runner as childprocess as
34
//! [test_runner_exe_path, test_nr, msg_pipe handle].
45
//! Runner writes
56
//! [passed, skipped, failed, panic_type]
6-
//! into msg_pipe to TC.
7-
//! TODO: clarify, if a timeout should be offered as available opt-in functionality.
7+
//! into msg_pipe to Control.
88

9-
// TODO async signal safety => reads can fail
10-
// or be interrupted
9+
// TODO async signal safety => reads can fail or be interrupted
1110
const std = @import("std");
1211
const io = std.io;
1312
const builtin = @import("builtin");
@@ -49,10 +48,6 @@ const PanicT = enum(u8) {
4948
/// This function is only working correctly inside test blocks. It writes an
5049
/// expected panic message to a global buffer only available in panic_testrunner.zig,
5150
/// which is compared by the Runner in the panic handler once it is called.
52-
/// TODO: This has workaround semantics for an always called missing exit handler
53-
/// or set of functions to assert that the panic is always called.
54-
/// This would include catching all signals (SIGSEV etc), but may not be desired
55-
/// by the user, since user may rely on signaling for runtime behavior of tests.
5651
pub fn writeExpectedPanicMsg(panic_msg: []const u8) void {
5752
// do bounds checks for first and last element manually, but omit the others.
5853
std.debug.assert(panic_msg.len < global.buf_panic_msg.len);
@@ -62,8 +57,11 @@ pub fn writeExpectedPanicMsg(panic_msg: []const u8) void {
6257
global.buf_panic_msg_fill = panic_msg.len;
6358
}
6459

65-
// Overwritten panic routine
66-
// TODO: synchronization etc
60+
/// Overwritten panic routine
61+
/// This function handles signals installed for the platform in start.zig and
62+
/// direct calls to `@panic`, but it can be modified by installing and removing
63+
/// signal handler on the platform.
64+
/// TODO: make this signal safe
6765
pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
6866
@setCold(true);
6967
_ = stack_trace;
@@ -173,13 +171,20 @@ pub fn main() !void {
173171

174172
try child_proc.spawn();
175173
}
174+
const stderr = std.io.getStdErr();
176175
const ret_term = try child_proc.wait();
177176
std.debug.print("ret_term: {any}\n", .{ret_term.Exited});
178177
if (ret_term.Exited != @enumToInt(ChildProcess.Term.Exited)) {
179-
@panic("TODO: handle printing message for exit reason.");
178+
try stderr.writeAll("Worker did stop due to other reason than exit");
179+
std.os.exit(1);
180180
}
181181
if (ret_term.Exited != 0) {
182-
@panic("TODO: handle printing message for non-0 return code.");
182+
try stderr.writeAll("Worker did stop with exit code: ");
183+
var exit_buf: [10]u8 = undefined;
184+
const exit_buf_s = std.fmt.bufPrint(&exit_buf, "{d}", .{ret_term.Exited}) catch unreachable;
185+
try stderr.writeAll(exit_buf_s);
186+
try stderr.writeAll("\n");
187+
std.os.exit(1);
183188
}
184189

185190
var file = std.fs.File{
@@ -213,7 +218,6 @@ pub fn main() !void {
213218
.unexpected_panic => {
214219
// clean exit with writing total count status
215220
// error message has been already written by child process
216-
const stderr = std.io.getStdErr();
217221
stderr.writeAll("FAIL: unexpected panic: ") catch {};
218222
writeInt(stderr, global.passed) catch {};
219223
stderr.writeAll(" passed; ") catch {};

0 commit comments

Comments
 (0)