diff options
Diffstat (limited to 'core/root.zig')
| -rw-r--r-- | core/root.zig | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/core/root.zig b/core/root.zig index ae6fc454..c10a2598 100644 --- a/core/root.zig +++ b/core/root.zig @@ -593,3 +593,129 @@ test "nothing of a core is a process global: every container-level var in core/ try std.testing.expect(files > 100); try std.testing.expectEqual(@as(usize, 0), unlisted); } + +/// The lines of each file of core/ that name the machine outside a test: +/// `std.c.`, `libc.`, `std.posix.`, `getenv`, std.Io's File, Dir, net and +/// Threaded (a path's text, `Dir.path`, and `max_path_bytes` are none), and +/// `@import("dev")` and `@import("runtime")`, by file, how many and why. A +/// step's read of its own machine with no tape diverges a far client, and +/// the soak (one machine) never sees it: a new line here makes someone look. +/// The count is a file's, so it cannot tell a step's read from its host +/// half's; the reason says which the file's are. +const machine_lines = [_]struct { []const u8, usize, []const u8 }{ + .{ "Addon.zig", 48, "the process's addon libraries: the start's scan of their directories, dlopen, the crash mark; the host's, never a step's" }, + .{ "Core.zig", 5, "the session's directory read once at its start (taped), a frame log (PARDES_FRAMES), a host_io type" }, + .{ "Db.zig", 18, "the state file every session of the user shares: the authority's (`db`), off in every replica" }, + .{ "Dir.zig", 2, "a directory's listing, the function under tape.site(.dir_listing)" }, + .{ "Effect.zig", 1, "host_io, named for the host entries it performs" }, + .{ "FrameStats.zig", 7, "a frame's clock and log: frames are local, never digested" }, + .{ "Handover.zig", 29, "a window carried to another process over a socket: the session's host" }, + .{ "Kind.zig", 1, "host_io's KindJob: a kind's job is the host's" }, + .{ "Messages.zig", 6, "the message clock, read through tape.value(.clock); PARDES_NOTIME, the tests' (a step's read of the environment: set on one side only it would diverge)" }, + .{ "Output.zig", 2, "the fonts module (Fonts lists them under tape.site(.fonts)) and the build's version line" }, + .{ "Stream.zig", 14, "the disk search's worker: it runs off the step and its batches are inputs" }, + .{ "builtins.zig", 2, "Mount's probe (tape.site(.probe)) and Term's shell check (tape.site(.shell))" }, + .{ "config.zig", 6, "the default shell, read once at the start (taped); the config file read at startup and written by DumpConfig (the session's); the docs check's" }, + .{ "draw.zig", 1, "PARDES_TEST_CLOCK: a frame's, not a step's" }, + .{ "dump.zig", 4, "a dump's clock and the state file's directory (XDG, the process's directory): the session's side (a client's Restore waits)" }, + .{ "echo.zig", 1, "PARDES_REPLICA_TRACE: a trace" }, + .{ "edit_cmd.zig", 1, "Edit's pipe environment (host_io.commandEnv): kept in Pipe.edit_run, `.authority` state, read only by the host's `pipe`, which a client never calls" }, + .{ "exec.zig", 4, "kindOf's stat (tape.site(.kind)) and Shell's check (tape.site(.shell))" }, + .{ "fs.zig", 39, "the file system behind the tape's sites (open, read, write, stat, mkdir, access), the process's home (read once at the start, taped), the 9P transport" }, + .{ "hunks.zig", 1, "a test helper's file read" }, + .{ "look.zig", 6, "openLink's fork (the host's: a view's frontend opens a link) and a remote's error name" }, + .{ "memory.zig", 7, "the memory regions themselves (mmap, madvise, their locks)" }, + .{ "replica.zig", 70, "the client and session engines: sockets, threads, clocks, the blob cache, traces" }, + .{ "rollback.zig", 1, "a test helper's directory" }, + .{ "root.zig", 4, "dev's modules re-exported (host_io, file_watch, glide, fonts)" }, + .{ "selection_pipe.zig", 14, "a pipe's child processes and their files: the host's `pipe` entry" }, + .{ "tape.zig", 10, "the tape's own files and host_io's types: a recording, a replay" }, + .{ "lsp/lsp.zig", 1, "the language server's client (dev): the host's `lsp` entry" }, + .{ "ninep/ctl.zig", 1, "the session's pid in a 9P read: the session's server" }, + .{ "ninep/events.zig", 2, "the 9P event log's clock: the session's server" }, + .{ "ninep/pty.zig", 1, "a 9P exec's shell check (tape.site(.shell))" }, + .{ "ninep/screen.zig", 1, "a 9P address's text type" }, + .{ "ninep/tree.zig", 1, "the daemon's registry (/sessions, tape.site(.sessions))" }, + .{ "term/terminal.zig", 2, "the emulator's image files (TMPDIR) and its Io: the session's emulator (a client's are written by deltas)" }, +}; + +/// The lines of `src` that name the machine (`machine_lines`'s rules). +fn machineLines(src: []const u8, gpa: std.mem.Allocator, out: *std.ArrayList(usize)) !void { + const names = [_][]const u8{ "std.c.", "libc.", "std.posix.", "getenv", "std.Io.File", "std.Io.Dir", "std.Io.net", "std.Io.Threaded", "Io.File", "Io.Dir", "Io.net", "Io.Threaded" }; + const pure = [_][]const u8{ "std.Io.Dir.path.", "Io.Dir.path.", "std.Io.Dir.max_path_bytes", "Io.Dir.max_path_bytes" }; + var open: std.ArrayList(u8) = .empty; + defer open.deinit(gpa); + var tests: usize = 0; + var line: usize = 1; + var i: usize = 0; + while (i < src.len) { + const c = src[i]; + if (c == '\n') line += 1; + const at = src[i..]; + if ((c == '/' or c == '\\') and i + 1 < src.len and src[i + 1] == c) { + i = std.mem.indexOfScalarPos(u8, src, i, '\n') orelse src.len; + } else if (c == '@' and tests == 0 and (std.mem.startsWith(u8, at, "@import(\"dev\")") or std.mem.startsWith(u8, at, "@import(\"runtime\")"))) { + if (out.items.len == 0 or out.getLast() != line) try out.append(gpa, line); + i += 1; + } else if (c == '"' or c == '\'') { + i += 1; + while (i < src.len and src[i] != c) : (i += 1) if (src[i] == '\\') { + i += 1; + }; + i += 1; + } else if (c == '{') { + const kind = braceKind(src[0..i]); + if (kind == 't') tests += 1; + try open.append(gpa, kind); + i += 1; + } else if (c == '}') { + if ((open.pop() orelse 0) == 't') tests -= 1; + i += 1; + } else if (std.ascii.isAlphabetic(c) or c == '_') { + const named = for (names) |n| { + if (std.mem.startsWith(u8, at, n)) break true; + } else false; + const path = for (pure) |n| { + if (std.mem.startsWith(u8, at, n)) break true; + } else false; + if (tests == 0 and named and !path and (out.items.len == 0 or out.getLast() != line)) try out.append(gpa, line); + i = wordEnd(src, i); + } else i += 1; + } +} + +test "what core/ asks of the machine is where the list says, with why: a new line naming libc, std.c, std.posix, getenv, a std.Io file, directory or socket, dev or runtime is named" { + const gpa = std.testing.allocator; + const io = std.testing.io; + var dir = try std.Io.Dir.cwd().openDir(io, "core", .{ .iterate = true }); + defer dir.close(io); + var walker = try dir.walk(gpa); + defer walker.deinit(); + var found: std.ArrayList(usize) = .empty; + defer found.deinit(gpa); + var wrong: usize = 0; + var seen: [machine_lines.len]bool = @splat(false); + while (try walker.next(io)) |e| { + if (e.kind != .file or !std.mem.endsWith(u8, e.basename, ".zig")) continue; + const src = try e.dir.readFileAlloc(io, e.basename, gpa, .limited(16 << 20)); + defer gpa.free(src); + found.clearRetainingCapacity(); + try machineLines(src, gpa, &found); + const listed: usize = for (machine_lines, 0..) |m, k| { + if (std.mem.eql(u8, m[0], e.path)) { + seen[k] = true; + break m[1]; + } + } else 0; + if (found.items.len == listed) continue; + wrong += 1; + std.debug.print("core/{s}: {d} lines name the machine, root.zig's machine_lines says {d}:", .{ e.path, found.items.len, listed }); + for (found.items) |l| std.debug.print(" {d}", .{l}); + std.debug.print("\n a step that reads its own machine with no tape diverges a far client: tape the read (tape.site, tape.value), or count the line with why it is not a step's\n", .{}); + } + for (machine_lines, seen) |m, s| if (!s) { + wrong += 1; + std.debug.print("core/{s}: on machine_lines, and no such file\n", .{m[0]}); + }; + try std.testing.expectEqual(@as(usize, 0), wrong); +} |
