lib/test/run.ww: fork+wait4 runner; each @test runs in its own child, abort/SEGV/FPE decoded from wait-status, failures recorded and the run continues; exit = fail count. Tests are hermetic: module globals do not persist test-to-test (fresh fork image; sanctioned divergence from harec's shared-process __test_main, no setjmp/signal layer needed). -T synth (both stages) emits a module-global (str,*fn() void) table + return run(table) instead of straight-line calls. Driver twins bundle lib/test under test mode and gain ww test -c/-o (go test -c) so the byte-id gates diff the same artifact the real path builds. Gates 989/910/997 rewired onto it; new 911 pins record-and-continue across all three fault classes; 949 +3 rows. (#17-team commit-2)
122 lines
4.2 KiB
C
122 lines
4.2 KiB
C
/*
|
|
* 949_driver_flagargs — task #15 B2: the ww driver's flag-argument error
|
|
* branches, pinned across BOTH driver twins (cstage `ww` and wwstage
|
|
* `ww_ww`). The branches under test:
|
|
* build/run — a lone -I/-L/-l/-o (flag with no following argument) is a
|
|
* hard error "ww <cmd>: -X needs an argument" (rc 2), not a
|
|
* silently-swallowed positional.
|
|
* test — -I/-c/-o carry meaning; -l/-L and any unknown flag are
|
|
* rejected with "ww test: unknown flag" (rc 2); a lone -I/-o
|
|
* is "ww test: -X needs an argument" (rc 2); -c/-o without a
|
|
* single test file is "ww test: -c/-o need a single test file"
|
|
* (rc 2, #17).
|
|
* Each row asserts the expected rc + stderr substring AND that the two
|
|
* drivers are byte-identical (rule 10): the cstage parse_build_flags /
|
|
* do_test must match the wwstage main.ww dobuild/dorun/dotest verbatim.
|
|
*
|
|
* All rows error during flag parsing, before any compile, so there are no
|
|
* build intermediates to redirect (rule 14: light driver test, any NNN).
|
|
* Sibling of 949_missingpkg (driver enforcement) and 993_ww_ww (twin parity).
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <sys/wait.h>
|
|
|
|
struct row {
|
|
const char *args; /* argv tail after the driver path */
|
|
int rc; /* expected exit code */
|
|
const char *sub; /* expected stderr substring */
|
|
};
|
|
|
|
static const struct row rows[] = {
|
|
{ "build -o", 2, "ww build: -o needs an argument" },
|
|
{ "build -I", 2, "ww build: -I needs an argument" },
|
|
{ "build -L", 2, "ww build: -L needs an argument" },
|
|
{ "build -l", 2, "ww build: -l needs an argument" },
|
|
{ "run -o", 2, "ww run: -o needs an argument" },
|
|
{ "run -l", 2, "ww run: -l needs an argument" },
|
|
{ "test -l", 2, "ww test: unknown flag" },
|
|
{ "test -zz", 2, "ww test: unknown flag" },
|
|
{ "test -I", 2, "ww test: -I needs an argument" },
|
|
/* #17: -c (compile-only) + -o are now meaningful for `test`; a lone -o
|
|
* needs an arg, and -c/-o require a single test file (not the default
|
|
* "." directory enumeration). */
|
|
{ "test -o", 2, "ww test: -o needs an argument" },
|
|
{ "test -o x", 2, "ww test: -c/-o need a single test file" },
|
|
{ "test -c", 2, "ww test: -c/-o need a single test file" },
|
|
};
|
|
|
|
/* Run "<bin>/<drv> <args>" capturing rc + stderr text into err (NUL-
|
|
* terminated). Returns the child's exit code (or -1 on spawn failure). */
|
|
static int
|
|
run_drv(const char *bin, const char *drv, const char *args,
|
|
char *err, size_t errsz)
|
|
{
|
|
int pid = getpid();
|
|
char errf[64], cmd[2048];
|
|
snprintf(errf, sizeof errf, "/tmp/dfa949_%d.err", pid);
|
|
snprintf(cmd, sizeof cmd, "%s/%s %s >/dev/null 2>%s", bin, drv, args, errf);
|
|
int rc = system(cmd);
|
|
if (rc == -1) { unlink(errf); return -1; }
|
|
rc = WIFEXITED(rc) ? WEXITSTATUS(rc) : 1;
|
|
err[0] = '\0';
|
|
FILE *f = fopen(errf, "r");
|
|
if (f) {
|
|
size_t got = fread(err, 1, errsz - 1, f);
|
|
err[got] = '\0';
|
|
fclose(f);
|
|
}
|
|
unlink(errf);
|
|
return rc;
|
|
}
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
const char *bin = getenv("BIN");
|
|
if (!bin) bin = "out/bin";
|
|
char absbin[1024];
|
|
if (bin[0] != '/') {
|
|
char cwd[1024];
|
|
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
|
|
snprintf(absbin, sizeof absbin, "%s/%s", cwd, bin);
|
|
bin = absbin;
|
|
}
|
|
|
|
int fail = 0;
|
|
size_t n = sizeof rows / sizeof rows[0];
|
|
for (size_t i = 0; i < n; i++) {
|
|
char cerr[4096], werr[4096];
|
|
int crc = run_drv(bin, "ww", rows[i].args, cerr, sizeof cerr);
|
|
int wrc = run_drv(bin, "ww_ww", rows[i].args, werr, sizeof werr);
|
|
|
|
if (crc != rows[i].rc) {
|
|
fprintf(stderr, "949 FAIL: ww %s rc=%d want=%d\n",
|
|
rows[i].args, crc, rows[i].rc);
|
|
fail = 1;
|
|
}
|
|
if (!strstr(cerr, rows[i].sub)) {
|
|
fprintf(stderr, "949 FAIL: ww %s stderr missing '%s' (got '%s')\n",
|
|
rows[i].args, rows[i].sub, cerr);
|
|
fail = 1;
|
|
}
|
|
/* twin parity: ww_ww must match ww exactly (rc + stderr). */
|
|
if (wrc != crc) {
|
|
fprintf(stderr, "949 FAIL: %s ww_ww rc=%d != ww rc=%d\n",
|
|
rows[i].args, wrc, crc);
|
|
fail = 1;
|
|
}
|
|
if (strcmp(werr, cerr) != 0) {
|
|
fprintf(stderr, "949 FAIL: %s ww_ww stderr '%s' != ww '%s'\n",
|
|
rows[i].args, werr, cerr);
|
|
fail = 1;
|
|
}
|
|
}
|
|
|
|
if (fail) return 1;
|
|
printf("driver flag-argument error branches: %zu rows, ww==ww_ww pinned\n", n);
|
|
return 0;
|
|
}
|