1
1
//! Panic test runner
2
+ //! assume: process spawning + IPC capabilities to keep things simple and test behavior = code behavior
2
3
//! Control starts itself as Runner as childprocess as
3
4
//! [test_runner_exe_path, test_nr, msg_pipe handle].
4
5
//! Runner writes
5
6
//! [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.
8
8
9
- // TODO async signal safety => reads can fail
10
- // or be interrupted
9
+ // TODO async signal safety => reads can fail or be interrupted
11
10
const std = @import ("std" );
12
11
const io = std .io ;
13
12
const builtin = @import ("builtin" );
@@ -49,10 +48,6 @@ const PanicT = enum(u8) {
49
48
/// This function is only working correctly inside test blocks. It writes an
50
49
/// expected panic message to a global buffer only available in panic_testrunner.zig,
51
50
/// 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.
56
51
pub fn writeExpectedPanicMsg (panic_msg : []const u8 ) void {
57
52
// do bounds checks for first and last element manually, but omit the others.
58
53
std .debug .assert (panic_msg .len < global .buf_panic_msg .len );
@@ -62,8 +57,11 @@ pub fn writeExpectedPanicMsg(panic_msg: []const u8) void {
62
57
global .buf_panic_msg_fill = panic_msg .len ;
63
58
}
64
59
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
67
65
pub fn panic (message : []const u8 , stack_trace : ? * std.builtin.StackTrace , _ : ? usize ) noreturn {
68
66
@setCold (true );
69
67
_ = stack_trace ;
@@ -173,13 +171,20 @@ pub fn main() !void {
173
171
174
172
try child_proc .spawn ();
175
173
}
174
+ const stderr = std .io .getStdErr ();
176
175
const ret_term = try child_proc .wait ();
177
176
std .debug .print ("ret_term: {any}\n " , .{ret_term .Exited });
178
177
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 );
180
180
}
181
181
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 );
183
188
}
184
189
185
190
var file = std.fs.File {
@@ -213,7 +218,6 @@ pub fn main() !void {
213
218
.unexpected_panic = > {
214
219
// clean exit with writing total count status
215
220
// error message has been already written by child process
216
- const stderr = std .io .getStdErr ();
217
221
stderr .writeAll ("FAIL: unexpected panic: " ) catch {};
218
222
writeInt (stderr , global .passed ) catch {};
219
223
stderr .writeAll (" passed; " ) catch {};
0 commit comments