refactor: make remote tests write trace files on TRACE=true
This commit is contained in:
parent
e430b209eb
commit
0c66093726
2 changed files with 59 additions and 6 deletions
|
|
@ -18,6 +18,16 @@ const cbor = @import("cbor");
|
|||
const framing = @import("framing");
|
||||
const protocol = @import("protocol");
|
||||
|
||||
var trace_file: ?std.fs.File = null;
|
||||
var trace_buf: [4096]u8 = undefined;
|
||||
var trace_file_writer: std.fs.File.Writer = undefined;
|
||||
|
||||
fn trace_handler(buf: tp.message.c_buffer_type) callconv(.c) void {
|
||||
if (trace_file == null) return;
|
||||
cbor.toJsonWriter(buf.base[0..buf.len], &trace_file_writer.interface, .{}) catch return;
|
||||
trace_file_writer.interface.writeByte('\n') catch return;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// EchoActor (wire ID 2)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
@ -150,8 +160,6 @@ const StdioEndpoint = struct {
|
|||
}
|
||||
|
||||
fn init(args: Args) !void {
|
||||
tp.trace_to_json_file("remote_child_endpoint_trace.json");
|
||||
tp.env.get().enable_all_channels();
|
||||
const fd_stdin = try tp.file_descriptor.init("stdin", 0);
|
||||
const self = try args.allocator.create(@This());
|
||||
self.* = .{
|
||||
|
|
@ -282,6 +290,17 @@ pub fn main() !void {
|
|||
defer _ = gpa.deinit();
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
var initial_env: ?tp.env = null;
|
||||
if (std.posix.getenv("TRACE") != null) {
|
||||
const f = try std.fs.cwd().createFile("remote_child_endpoint_trace.json", .{});
|
||||
trace_file = f;
|
||||
trace_file_writer = f.writer(&trace_buf);
|
||||
var e = tp.env.init();
|
||||
e.on_trace(&trace_handler);
|
||||
e.enable_all_channels();
|
||||
initial_env = e;
|
||||
}
|
||||
|
||||
var ctx = try tp.context.init(allocator);
|
||||
defer ctx.deinit();
|
||||
|
||||
|
|
@ -299,10 +318,17 @@ pub fn main() !void {
|
|||
StdioEndpoint.start,
|
||||
"stdio_endpoint",
|
||||
&exit_handler,
|
||||
null,
|
||||
if (initial_env) |*e| e else null,
|
||||
);
|
||||
|
||||
ctx.run();
|
||||
|
||||
if (initial_env) |e| {
|
||||
trace_file_writer.interface.flush() catch {};
|
||||
trace_file.?.close();
|
||||
trace_file = null;
|
||||
e.deinit();
|
||||
}
|
||||
|
||||
std.process.exit(if (exit_ok) 0 else 1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue