milestone 18: collapse duplicated infrastructure into shared listener core, crud list helper, resource shells, transport race, name and line helpers, ui modules
This commit is contained in:
@@ -30,7 +30,9 @@
|
||||
|
||||
const std = @import("std");
|
||||
const core = @import("core");
|
||||
const smith_encode = @import("smith_encode.zig");
|
||||
|
||||
const sliceInput = smith_encode.sliceInput;
|
||||
const compiler = core.compiler;
|
||||
const Smith = std.testing.Smith;
|
||||
|
||||
@@ -132,11 +134,10 @@ fn expectConsistent(counts: compiler.Counts, bytes: []const u8) !void {
|
||||
// corpus
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// `Smith` does not consume a corpus entry as raw input. It reads a byte stream
|
||||
// in which a slice is a little-endian `u32` length followed by that many bytes,
|
||||
// so every entry below is length-prefixed. An entry that carries only the slice
|
||||
// leaves the format index and the reader-buffer length at the low end of their
|
||||
// ranges, which is the 64-byte buffer that makes `error.StreamTooLong` the
|
||||
// `Smith` does not consume a corpus entry as raw input, so every entry below
|
||||
// goes through the `smith_encode.zig` encoder. An entry that carries only the
|
||||
// slice leaves the format index and the reader-buffer length at the low end of
|
||||
// their ranges, which is the 64-byte buffer that makes `error.StreamTooLong` the
|
||||
// common case.
|
||||
|
||||
/// Past `compiler.max_line_len`, so the discard arm at compiler.zig:72 replays
|
||||
@@ -148,18 +149,6 @@ const long_line = "a" ** 5000 ++ ".example.com";
|
||||
const long_line_unterminated = "0.0.0.0 kept.example.com\n" ++ long_line;
|
||||
const long_line_terminated = long_line_unterminated ++ "\n0.0.0.0 after.example.com\n";
|
||||
|
||||
/// Encodes `bytes` as a single `Smith.slice` value.
|
||||
fn sliceInput(comptime bytes: []const u8) *const [4 + bytes.len]u8 {
|
||||
return &struct {
|
||||
const value: [4 + bytes.len]u8 = blk: {
|
||||
var buf: [4 + bytes.len]u8 = undefined;
|
||||
std.mem.writeInt(u32, buf[0..4], @intCast(bytes.len), .little);
|
||||
buf[4..].* = bytes[0..bytes.len].*;
|
||||
break :blk buf;
|
||||
};
|
||||
}.value;
|
||||
}
|
||||
|
||||
const corpus = [_][]const u8{
|
||||
sliceInput(long_line_unterminated),
|
||||
sliceInput(long_line_terminated),
|
||||
@@ -173,12 +162,3 @@ test "the unterminated corpus entry ends on an over-long line" {
|
||||
const last = std.mem.findScalarLast(u8, long_line_unterminated, '\n').? + 1;
|
||||
try std.testing.expect(long_line_unterminated.len - last > compiler.max_line_len);
|
||||
}
|
||||
|
||||
test "a corpus entry carries its own length" {
|
||||
const encoded = sliceInput(long_line);
|
||||
try std.testing.expectEqual(
|
||||
@as(u32, long_line.len),
|
||||
std.mem.readInt(u32, encoded[0..4], .little),
|
||||
);
|
||||
try std.testing.expectEqualSlices(u8, long_line, encoded[4..]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user