Captain Bob's CI directive (2026-11-17) and the design he ruled point by point (docs/v4.0.0/plans/2026-11-17-emergency-diagnostic-build.md). - v4/system/dump.c, v4/include/v4/dump.h: what a node was doing when it stopped -- the fault's kind, address and count; P A B; the data stack, T first; the return stack, R first, each entry named by the word it falls in (the backtrace; ROM and below-every-word said so); the running line. Bounded dictionary walk; no C library. Ruled: every build, on a stop only (a handled fault keeps its line). - kernel/src/v4/sk_v4.c: the dump before each of the three halts (not started; POST's blocks not let go; a node stopped on a fault) -- Hera and any stopped node. kernel/Makefile links dump.o. - scripts/nightly.sh diagnose [<stage>]: after a failed stage, that configuration built again with EMERGENCY_CONSOLE_ENABLED=1 -- build only, nothing booted (ruled) -- its artifacts kept in logs/<TS>/diagnose/ only from a build that passed, with a README saying how to launch it with --log-level=debug. Always exits 0: evidence, never a result. The protocol runs it after a failed stage and still exits with that stage's code; acceptance.yml, nightly.yml and release.yml run it `if: failure()`, before the logs are kept. Any failed stage triggers it (ruled). - capsules/BLOCK_MAP.md: as the build writes it -- the v4:physics.4th row, missing since28ffed8f(ruled: commit the regenerated map). - Test first: test_dump.c failed with no dump.c (logs/20261117-dump), then 15 checks at both widths and under ASan+UBSan. The diagnose stage: a real EMERGENCY amd64 build; a failing build exits 0 and keeps no artifacts (a defect found and fixed this way); the protocol path keeps the stage's exit. - Also the write-up of the regression at046ce0be, for ruling. Not yet: acceptance on a clean tree (the next run); the kernel's stop wiring is compile-tested only -- no boot reaches a stop on purpose. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
122 lines
5.0 KiB
C
122 lines
5.0 KiB
C
/* SPDX-License-Identifier: LicenseRef-Starship-1.0
|
|
* Copyright (c) 2023-2026 Robert A. James
|
|
*/
|
|
/* test_dump.c -- the fault dump of a node that stopped (v4/dump.h;
|
|
* docs/v4.0.0/plans/2026-11-17-emergency-diagnostic-build.md, ruled by Captain Bob 2026-11-17:
|
|
* every build, on a stop only).
|
|
*
|
|
* A node is set by hand to a known state: registers, both stacks, a fault, and
|
|
* a dictionary of two words laid out as dict.f18 lays an entry (the name's
|
|
* word address at xt-2, the link at xt-1, the count byte first). The dump
|
|
* must say all of it: the fault's kind, address and count; P, A, B; every
|
|
* value on the data stack, T first; every return-stack entry, R first, each
|
|
* named by the word it falls in (the backtrace), the ROM's as ROM, one below
|
|
* every word as such; and the line that was running.
|
|
*
|
|
* Built and run at both V4_CELL_BITS=32 and 64; see v4/Makefile.
|
|
*/
|
|
#include "v4/dump.h"
|
|
#include "v4/node.h"
|
|
#include "v4/stack.h"
|
|
#include "v4/image.h"
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
static int failures = 0;
|
|
static int checks = 0;
|
|
|
|
#define CHECK(cond, ...) \
|
|
do { \
|
|
checks++; \
|
|
if (!(cond)) { \
|
|
failures++; \
|
|
printf(" FAIL %s:%d: ", __FILE__, __LINE__); \
|
|
printf(__VA_ARGS__); \
|
|
printf("\n"); \
|
|
} \
|
|
} while (0)
|
|
|
|
static char out[8192];
|
|
static size_t used;
|
|
|
|
static void capture(void *self, const char *s, unsigned n)
|
|
{
|
|
(void)self;
|
|
if (used + n >= sizeof out) n = (unsigned)(sizeof out - 1 - used);
|
|
memcpy(out + used, s, n);
|
|
used += n;
|
|
out[used] = 0;
|
|
}
|
|
|
|
static v4_node node;
|
|
|
|
/* an entry as dict.f18 lays one: name at nfa (count byte first, four to a cell, low byte first) */
|
|
static void entry(v4_cell xt, v4_cell nfa, v4_cell link, const char *name)
|
|
{
|
|
unsigned len = (unsigned)strlen(name), i;
|
|
for (i = 0; i <= len; i++) {
|
|
unsigned b = i == 0 ? len : (unsigned char)name[i - 1];
|
|
node.mem[nfa + (v4_cell)(i / 4u)] |= (v4_cell)((v4_ucell)b << (8u * (i % 4u)));
|
|
}
|
|
node.mem[xt - 3] = 0;
|
|
node.mem[xt - 2] = nfa;
|
|
node.mem[xt - 1] = link;
|
|
}
|
|
|
|
static int has(const char *s) { return strstr(out, s) != 0; }
|
|
|
|
int main(void)
|
|
{
|
|
v4_image im;
|
|
|
|
memset(&im, 0, sizeof im);
|
|
v4_node_reset(&node);
|
|
im.latest = 10;
|
|
entry(100, 90, 0, "ALPHA");
|
|
entry(200, 190, 100, "BETA");
|
|
node.mem[im.latest] = 200;
|
|
|
|
node.p = 123; node.a = 7; node.b = 8;
|
|
node.fault_kind = V4_FAULT_DATA_UNDER; node.fault_addr = 0; node.faults = 3; node.stopped = 1;
|
|
v4_dstack_push(&node.ds, 11);
|
|
v4_dstack_push(&node.ds, 22);
|
|
v4_dstack_push(&node.ds, 33);
|
|
v4_rstack_push(&node.rs, 50); /* below every word */
|
|
v4_rstack_push(&node.rs, (v4_cell)V4_ROM_BASE + 5); /* in the ROM */
|
|
v4_rstack_push(&node.rs, 205); /* in BETA */
|
|
v4_rstack_push(&node.rs, 150); /* in ALPHA: R */
|
|
|
|
used = 0; out[0] = 0;
|
|
v4_dump_node(&node, &im, "3 4 SPIN", 8u, capture, 0);
|
|
|
|
CHECK(has("data underflow"), "the fault's kind: %s", out);
|
|
CHECK(has("faults=3"), "the fault count: %s", out);
|
|
CHECK(has("stopped"), "it says the node stopped: %s", out);
|
|
CHECK(has("P=123") && has("A=7") && has("B=8"), "P, A, B: %s", out);
|
|
CHECK(has("data stack depth=3: 33 22 11"), "the data stack, T first: %s", out);
|
|
CHECK(has("return stack depth=4"), "the return stack's depth: %s", out);
|
|
CHECK(has("150 in ALPHA"), "R named by its word: %s", out);
|
|
CHECK(has("205 in BETA"), "the next named: %s", out);
|
|
CHECK(has("in ROM"), "a ROM address said so: %s", out);
|
|
CHECK(has("50 below every word"), "an address below the dictionary said so: %s", out);
|
|
CHECK(strstr(out, "150 in ALPHA") < strstr(out, "205 in BETA"), "R first, then down the stack: %s", out);
|
|
CHECK(has("line: 3 4 SPIN"), "the running line: %s", out);
|
|
|
|
/* an address fault says the address */
|
|
node.fault_kind = V4_FAULT_ADDRESS; node.fault_addr = 99999;
|
|
used = 0; out[0] = 0;
|
|
v4_dump_node(&node, &im, 0, 0u, capture, 0);
|
|
CHECK(has("address fault at 99999"), "the faulting address: %s", out);
|
|
CHECK(!has("line:"), "no line when none was running: %s", out);
|
|
|
|
/* a dictionary whose link goes wild does not run away: the walk is bounded */
|
|
node.mem[100 - 1] = 200; /* ALPHA links back to BETA: a loop */
|
|
used = 0; out[0] = 0;
|
|
v4_dump_node(&node, &im, 0, 0u, capture, 0);
|
|
CHECK(has("return stack depth=4"), "the dump still ends: %s", out);
|
|
|
|
printf("test_dump: %d checks, %d failures\n", checks, failures);
|
|
return failures ? 1 : 0;
|
|
}
|