test: require diagnostic on reject rows, close crash-vacuity (#20)

Reject helpers checked only rc!=0, so a SEGFAULT (exit 139, or the
driver's "w6c failed" exit 1) counted as a clean reject -- a wwstage
crash could pass vacuously (it did, latently, on bodied bare-... pre
#11). Every reject row now captures stderr and requires the actual
diagnostic substring (rc!=0 AND strstr) across all 16 reject tests; a
crash emits no diagnostic, so it now fails. This is the
differential-reject backstop (#15): both stages must cleanly reject
with the expected message.

Two genuine cstage/wwstage diagnostic-body divergences are documented
inline via per-stage substrings, not papered over (845 tuple parse,
catA_f2 tuple arity); catalogued in #21.
This commit is contained in:
2026-06-21 13:04:59 +09:00
parent 1f1efb273a
commit e8ef1e061c
16 changed files with 631 additions and 179 deletions

View File

@@ -121,6 +121,15 @@ static const char *neg[] = {
"};\n",
};
/* Per-neg expected diagnostic body (parallel to neg[]); all four rows hit
* the same "no field 'cap' on a fixed-size array" path on both stages. */
static const char *neg_diag[] = {
"no field 'cap' on a fixed-size array",
"no field 'cap' on a fixed-size array",
"no field 'cap' on a fixed-size array",
"no field 'cap' on a fixed-size array",
};
static int
run_driver(const char *driver, const struct row *r, int i)
{
@@ -155,14 +164,30 @@ run_driver(const char *driver, const struct row *r, int i)
return got;
}
/* build_should_fail — `.cap` on an array must error on `driver`; returns 0
* when the build correctly FAILS, non-zero when it wrongly succeeded. */
static int
build_should_fail(const char *driver, const char *src, int i)
filehas(const char *path, const char *needle)
{
char s[64], tmpdir[64], cmd[1024];
char buf[8192];
FILE *f = fopen(path, "rb");
if (!f) return 0;
size_t n = fread(buf, 1, sizeof buf - 1, f);
fclose(f);
buf[n] = '\0';
return strstr(buf, needle) != NULL;
}
/* build_should_fail — `.cap` on an array must error on `driver`; returns 0
* when the build FAILS *and* emits `diag`. A crash (segfault) wraps as a
* nonzero "w6c failed" with no diagnostic, so the substring distinguishes
* it from a clean reject (#20). */
static int
build_should_fail(const char *driver, const char *src, const char *diag,
int i)
{
char s[64], tmpdir[64], cmd[1024], errf[64];
snprintf(s, sizeof s, "/tmp/acrn_%d_%d.ww", getpid(), i);
snprintf(tmpdir, sizeof tmpdir, "/tmp/acrn_%d_d_%d", getpid(), i);
snprintf(errf, sizeof errf, "/tmp/acrn_%d_e_%d.txt", getpid(), i);
FILE *f = fopen(s, "wb");
if (!f) return -1;
@@ -170,10 +195,12 @@ build_should_fail(const char *driver, const char *src, int i)
fclose(f);
mkdir(tmpdir, 0755);
snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null",
tmpdir, driver, s);
snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s",
tmpdir, driver, s, errf);
int rc = runwait(cmd);
int hasmsg = filehas(errf, diag);
unlink(s);
unlink(errf);
/* clean any emitted binary */
const char *base = strrchr(s, '/');
base = base ? base + 1 : s;
@@ -183,7 +210,8 @@ build_should_fail(const char *driver, const char *src, int i)
if (dot && strcmp(dot, ".ww") == 0) *dot = '\0';
unlink(outbin);
rmdir(tmpdir);
return rc == 0 ? -1 : 0; /* build must NOT succeed */
/* build must NOT succeed AND must emit its diagnostic. */
return (rc != 0 && hasmsg) ? 0 : -1;
}
/* asm_byte_identical — w6c vs w6c_ww .s for the same source must match. */
@@ -286,7 +314,7 @@ main(void)
for (int i = 0; i < nn; i++) {
total++;
if (build_should_fail(drivers[d].path, neg[i],
100 + i) != 0) {
neg_diag[i], 100 + i) != 0) {
fprintf(stderr,
"arr_cap_reject[%s][neg%d]: built ok, "
"expected a loud error\n",