summaryrefslogtreecommitdiff
path: root/test/monkey9p.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/monkey9p.zig')
-rw-r--r--test/monkey9p.zig25
1 files changed, 18 insertions, 7 deletions
diff --git a/test/monkey9p.zig b/test/monkey9p.zig
index 03c42f2a..45c5d12f 100644
--- a/test/monkey9p.zig
+++ b/test/monkey9p.zig
@@ -588,7 +588,9 @@ fn removeFile(a: Allocator, dir: []const u8, name: []const u8) void {
fn serialsOf(a: Allocator, index: []const u8) ![]u32 {
var out: std.ArrayList(u32) = .empty;
- var lines = std.mem.tokenizeScalar(u8, index, '\n');
+ if (index.len == 0) return out.items;
+ // A blank line is unparsable too, as Python's splitlines saw it.
+ var lines = std.mem.splitScalar(u8, if (index[index.len - 1] == '\n') index[0 .. index.len - 1] else index, '\n');
while (lines.next()) |line| {
var it = std.mem.tokenizeAny(u8, line, " \t");
try out.append(a, std.fmt.parseInt(u32, it.next() orelse return error.Unparsable, 10) catch return error.Unparsable);
@@ -711,7 +713,7 @@ fn clunk(c: *Ctx, a: Allocator, res: *Res, f: *Fid, path: []const u8) !bool {
/// unended tail of a piece shorter than a Twrite holds, or of one not a
/// multiple of 4096 bytes, as acme takes each write. An upper bound: the
/// tree now waits for the newline whatever a piece's size.
-fn servedLines(a: Allocator, data: []const u8, sizes: []const usize) []const []const u8 {
+fn servedLines(a: Allocator, data: []const u8, sizes: []const usize, room_: usize) []const []const u8 {
var lines: std.ArrayList([]const u8) = .empty;
var pending: []const u8 = "";
var at: usize = 0;
@@ -723,7 +725,7 @@ fn servedLines(a: Allocator, data: []const u8, sizes: []const usize) []const []c
lines.append(a, pending[0..nl]) catch oom();
pending = pending[nl + 1 ..];
}
- if (pending.len > 0 and piece.len < room and piece.len % 4096 != 0) {
+ if (pending.len > 0 and piece.len < room_ and piece.len % 4096 != 0) {
lines.append(a, pending) catch oom();
pending = "";
}
@@ -738,8 +740,11 @@ fn selfCheck(a: Allocator) void {
.{ "ab\n", &[_]usize{ 1, 1, 1 }, &[_][]const u8{ "a", "b", "" } },
.{ "ab\ncd", &[_]usize{ 3, 2 }, &[_][]const u8{ "ab", "cd" } },
};
+ // A piece that fills its Twrite goes on into the next.
+ const full = servedLines(a, "abcd", &.{ 2, 2 }, 2);
+ if (full.len != 1 or !std.mem.eql(u8, full[0], "abcd")) @panic("servedLines");
inline for (cases) |case| {
- const got = servedLines(a, case[0], case[1]);
+ const got = servedLines(a, case[0], case[1], room);
if (got.len != case[2].len) @panic("servedLines");
for (got, case[2]) |g, w| if (!std.mem.eql(u8, g, w)) @panic("servedLines");
}
@@ -751,7 +756,7 @@ fn selfCheck(a: Allocator) void {
/// Edit block whose text never ended runs, and fails, at the close.
fn allowances(a: Allocator, res: *Res, path: []const u8, data: []const u8, sizes: []const usize) void {
const b = base(path);
- const served = servedLines(a, data, sizes);
+ const served = servedLines(a, data, sizes, room);
var n: usize = 0;
var lines: usize = 0;
for (served) |line| {
@@ -1539,7 +1544,7 @@ fn spawn(gpa: Allocator, seed: u64, steps: usize, only: ?[]const usize, verbose:
else
null;
if (lost) |why| {
- if (!quiet) std.debug.print("{s}[seed {d} step {d}] FAIL {s}\n", .{ if (sig != 0) said.items else "", seed, last_step, why });
+ if (!quiet) std.debug.print("{s}[seed {d} step {d}] FAIL {s}\n", .{ if (sig != 0 or code > 1) said.items else "", seed, last_step, why });
try found.append(gpa, .{ .step = last_step, .sig = try gpa.dupe(u8, why) });
}
return found.toOwnedSlice(gpa);
@@ -1647,7 +1652,13 @@ pub fn main(init: std.process.Init) !void {
var check: std.heap.ArenaAllocator = .init(gpa);
selfCheck(check.allocator());
check.deinit();
- std.process.exit(try fuzz(gpa, if (seeds.items.len > 0) seeds.items[0] else 1, steps orelse 1000, only, verbose, std.mem.span(root)));
+ // An error out of the run (a fresh session's /index unparsable, its
+ // log refusing `follow new`) is a harness failure, not exit 1 with no
+ // failure line, which the parent would take for a clean run.
+ std.process.exit(fuzz(gpa, if (seeds.items.len > 0) seeds.items[0] else 1, steps orelse 1000, only, verbose, std.mem.span(root)) catch |err| {
+ std.debug.print("mky error {t}\n", .{err});
+ std.process.exit(3);
+ });
}
if (smoke) {
// A short fixed-seed run that fails on any failure.