summaryrefslogtreecommitdiff
path: root/test/e2e_harness.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/e2e_harness.zig')
-rw-r--r--test/e2e_harness.zig62
1 files changed, 4 insertions, 58 deletions
diff --git a/test/e2e_harness.zig b/test/e2e_harness.zig
index 410c33ae..396de8c5 100644
--- a/test/e2e_harness.zig
+++ b/test/e2e_harness.zig
@@ -80,12 +80,6 @@ pub const Harness = struct {
/// clipboard writes). Capture is bounded explicitly so a runaway child cannot
/// consume unbounded test-runner memory.
raw: *RawCapture,
- /// Another view's terminal of the app this harness started (`view`):
- /// it neither started the app nor kills it.
- view: bool = false,
- /// Every terminal of the app's, this one's too: each wait reads them
- /// all, or the app would block writing a frame to one nobody reads.
- views: []const *Harness = &.{},
pub fn init(gpa: std.mem.Allocator, exe: [*:0]const u8, rows: u16, cols: u16) !Harness {
return initArgs(gpa, exe, rows, cols, null);
@@ -143,36 +137,6 @@ pub const Harness = struct {
};
}
- /// A terminal for another view of the app `pid` (views.zig): a pty of
- /// its own, whose path the app is given (PARDES_TEST_VIEWS) and opens.
- pub fn initView(gpa: std.mem.Allocator, rows: u16, cols: u16, path: *[64]u8) !Harness {
- var master: c_int = undefined;
- var slave: c_int = undefined;
- const ws = posix.winsize{ .row = rows, .col = cols, .xpixel = 0, .ypixel = 0 };
- if (openpty(&master, &slave, null, null, &ws) != 0) return error.NoPty;
- defer _ = libc.close(slave);
- const name = std.mem.span(ttyname(slave) orelse return error.NoPty);
- if (name.len >= path.len) return error.NoPty;
- @memcpy(path[0..name.len], name);
- path[name.len] = 0;
- const term = try gpa.create(ghostty_vt.Terminal);
- errdefer gpa.destroy(term);
- term.* = try ghostty_vt.Terminal.init(std.Io.Threaded.global_single_threaded.io(), gpa, .{
- .cols = cols,
- .rows = rows,
- .max_scrollback_bytes = 1024 * 1024,
- });
- errdefer term.deinit(gpa);
- const raw = try gpa.create(RawCapture);
- raw.* = .{};
- return .{ .gpa = gpa, .master = master, .pid = 0, .term = term, .stream = term.vtStream(), .rows = rows, .cols = cols, .raw = raw, .view = true };
- }
-
- /// What the app wrote to its other terminals, read without waiting.
- fn drainOthers(self: *Harness) void {
- for (self.views) |other| if (other != self) while (other.pumpRead(0)) {};
- }
-
fn pumpRead(self: *Harness, ms: i64) bool {
var fds = [_]posix.pollfd{.{ .fd = self.master, .events = posix.POLL.IN, .revents = 0 }};
const ready = posix.poll(&fds, @intCast(@max(0, ms))) catch 0;
@@ -185,17 +149,8 @@ pub const Harness = struct {
return true;
}
- /// Bytes in every terminal of the app's (`pending`).
- pub fn pendingAll(self: *Harness) usize {
- var n = self.pending();
- for (self.views) |other| if (other != self) {
- n += other.pending();
- };
- return n;
- }
-
pub fn deinit(self: *Harness) void {
- if (!self.view) posix.kill(self.pid, posix.SIG.KILL) catch {};
+ posix.kill(self.pid, posix.SIG.KILL) catch {};
_ = libc.close(self.master);
self.stream.deinit();
self.gpa.destroy(self.raw);
@@ -240,9 +195,8 @@ pub const Harness = struct {
const deadline = nowMs() + ms;
var buf: [4096]u8 = undefined;
while (nowMs() < deadline) {
- self.drainOthers();
var fds = [_]posix.pollfd{.{ .fd = self.master, .events = posix.POLL.IN, .revents = 0 }};
- _ = posix.poll(&fds, if (self.views.len > 1) 5 else 50) catch {};
+ _ = posix.poll(&fds, 50) catch {};
if ((fds[0].revents & posix.POLL.IN) != 0) {
const n = posix.read(self.master, &buf) catch break;
if (n == 0) break;
@@ -259,14 +213,7 @@ pub const Harness = struct {
/// SETTLED grid sleeps in poll until the app actually writes, instead of
/// burning a fixed window per check (see snapshot.zig's waitStable).
pub fn pumpOnce(self: *Harness, ms: i64) !bool {
- if (self.views.len <= 1) return self.pumpRead(ms);
- // Several terminals: each looked at every few milliseconds.
- const deadline = nowMs() + ms;
- while (true) {
- self.drainOthers();
- if (self.pumpRead(@min(5, @max(0, deadline - nowMs())))) return true;
- if (nowMs() >= deadline) return false;
- }
+ return self.pumpRead(ms);
}
/// Bytes sitting in the pty that nobody has picked up — keystrokes the app
@@ -326,9 +273,8 @@ pub const Harness = struct {
const deadline = nowMs() + ms;
var buf: [4096]u8 = undefined;
while (nowMs() < deadline) {
- self.drainOthers();
var fds = [_]posix.pollfd{.{ .fd = self.master, .events = posix.POLL.IN, .revents = 0 }};
- _ = posix.poll(&fds, if (self.views.len > 1) 5 else 50) catch {};
+ _ = posix.poll(&fds, 50) catch {};
if ((fds[0].revents & posix.POLL.IN) != 0) {
const n = posix.read(self.master, &buf) catch break;
if (n == 0) break;