v4/system/post.c: for each case it empties the node's data stack, sends DECIMAL FORTH DEFINITIONS, sends the case's lines keeping what the node prints, reads the stack, and judges: an error exactly if one is expected, and otherwise the stack and every character printed. A failing case is named with what it printed and left. Nothing of it is on the node. Its tests are in test_host_quit.c, on that test's node: 29 checks of cases that must pass and cases that must fail -- a wrong value, depth, order or output, an error wanted or unwanted, a case of two lines, depth-only cases, the starting state, more printing than is kept, and a line that never comes back. Both widths and the sanitizers. The boot still runs the capsule; that is the next commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
105 lines
3.7 KiB
C
105 lines
3.7 KiB
C
/* post.c -- POST's runner: the kernel feeds a case to the node and judges it
|
|
* from outside. See post.h; docs/v4.0.0/NUCLEUS.md section 6.3.
|
|
*
|
|
* Nothing here uses the C library: the bare-metal kernel links this file.
|
|
*/
|
|
#include "v4/post.h"
|
|
#include "v4/message.h"
|
|
|
|
#define SHOWN_OUT 255u /* how much of a failing case's printing is shown */
|
|
#define SHOWN_STACK 32u /* and how many of the values it left */
|
|
|
|
static const char state_line[] = "DECIMAL FORTH DEFINITIONS";
|
|
|
|
static unsigned length(const char *s)
|
|
{
|
|
unsigned n = 0;
|
|
while (s[n]) n++;
|
|
return n;
|
|
}
|
|
|
|
static void say(const v4_post_host *h, const char *s)
|
|
{
|
|
h->say(h->self, s, length(s));
|
|
}
|
|
|
|
static void say_number(const v4_post_host *h, long long v)
|
|
{
|
|
char text[24];
|
|
unsigned at = sizeof text;
|
|
unsigned long long u = v < 0 ? 0ull - (unsigned long long)v : (unsigned long long)v;
|
|
|
|
do { text[--at] = (char)('0' + u % 10u); u /= 10u; } while (u);
|
|
if (v < 0) text[--at] = '-';
|
|
h->say(h->self, text + at, (unsigned)sizeof text - at);
|
|
}
|
|
|
|
int v4_post_run(const v4_post_host *h, const v4_post_case *cases, unsigned count, v4_post_tally *tally)
|
|
{
|
|
static char out[V4_POST_OUT]; /* what the case being run has printed */
|
|
v4_cell left[SHOWN_STACK]; /* what it left on the stack, the top first */
|
|
unsigned i, k;
|
|
|
|
tally->tests = 0; tally->pass = 0; tally->fail = 0;
|
|
for (i = 0; i < count; i++) {
|
|
const v4_post_case *c = &cases[i];
|
|
unsigned kept = 0, total = 0, len = 0, depth;
|
|
int errored = 0, came_back = 1, ok, how;
|
|
|
|
/* every case starts from the same state */
|
|
v4_dstack_reset(&h->n->ds);
|
|
how = h->line(h->self, state_line, (unsigned)sizeof state_line - 1u, out, 0u, &len);
|
|
if (how != V4_TEXT_COMPLETED) came_back = 0;
|
|
v4_dstack_reset(&h->n->ds);
|
|
|
|
for (k = 0; came_back && k < c->line_count; k++) {
|
|
len = 0;
|
|
how = h->line(h->self, c->lines[k], length(c->lines[k]), out + kept, V4_POST_OUT - kept, &len);
|
|
if (how < 0) { came_back = 0; break; }
|
|
if (how == V4_TEXT_ERROR) errored = 1;
|
|
total += len;
|
|
kept = total < V4_POST_OUT ? total : V4_POST_OUT;
|
|
}
|
|
|
|
/* what it left, read before anything is judged */
|
|
depth = h->n->ds.depth;
|
|
for (k = 0; k < depth; k++) {
|
|
v4_cell v = v4_dstack_pop(&h->n->ds);
|
|
if (k < SHOWN_STACK) left[k] = v;
|
|
}
|
|
v4_dstack_reset(&h->n->ds);
|
|
|
|
if (!came_back) {
|
|
ok = 0;
|
|
} else if (c->expect == V4_POST_ERROR) {
|
|
ok = errored;
|
|
} else if (errored) {
|
|
ok = 0;
|
|
} else {
|
|
ok = depth == c->depth;
|
|
if (ok && c->expect == V4_POST_STACK) {
|
|
if (depth > SHOWN_STACK) ok = 0;
|
|
for (k = 0; ok && k < depth; k++) ok = left[k] == (v4_cell)c->stack[depth - 1u - k];
|
|
}
|
|
if (ok && c->expect != V4_POST_DEPTH) {
|
|
ok = total == c->output_len && total <= V4_POST_OUT;
|
|
for (k = 0; ok && k < total; k++) ok = out[k] == c->output[k];
|
|
}
|
|
}
|
|
|
|
tally->tests++;
|
|
if (ok) { tally->pass++; continue; }
|
|
tally->fail++;
|
|
say(h, "POST FAIL: "); say(h, c->name);
|
|
say(h, " out<"); h->say(h->self, out, kept < SHOWN_OUT ? kept : SHOWN_OUT);
|
|
say(h, "> stack<");
|
|
for (k = depth < SHOWN_STACK ? depth : SHOWN_STACK; k-- > 0; ) { say_number(h, (long long)left[k]); say(h, " "); }
|
|
say(h, ">\n");
|
|
}
|
|
say(h, "PARITY:V4_POST tests="); say_number(h, (long long)tally->tests);
|
|
say(h, " pass="); say_number(h, (long long)tally->pass);
|
|
say(h, " fail="); say_number(h, (long long)tally->fail);
|
|
say(h, "\n");
|
|
return tally->fail == 0;
|
|
}
|