test/wcc: carrier ownership repair and driver-contract adaptation
Every surviving carrier now owns its artifacts: checked mkdir/mkdtemp/ fopen acquisition, one all-exit cleanup funnel per carrier, ENOENT- tolerant checked unlinks, exact-path deletion (rm -rf only for an owned pid-keyed dir or a .sepwork beneath one), and cleanup failure fails a passing carrier without overwriting its diagnostic. In the same pass the carriers adapt to the driver contract this branch lands: --sep and WW_PKGCACHE are gone, -S and the /tmp/ww_run_<pid> scratch contract are asserted, and rows whose runtime or reject coverage moved to test/wcc/data fixtures or test/lang @test owners are trimmed to the byte/artifact/diagnostic observations only they can make. Repair and adaptation ride together because most files interleave both in the same hunks; splitting would manufacture intermediate carrier states that never existed and cannot run against either driver.
This commit is contained in:
@@ -7,16 +7,17 @@
|
||||
* 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); a 2nd positional (fnmatch name-filter pattern)
|
||||
* is "ww test: -X needs an argument" (rc 2); -o without a
|
||||
* single test file is "ww test: -c/-S/-o need a single test
|
||||
* file" (rc 2, #17); a missing -run argument is rc 2; a 2nd positional
|
||||
* in directory mode is "ww test: pattern needs 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.
|
||||
* This carrier also owns the `-V` output and C/WW-driver version parity.
|
||||
*
|
||||
* All rows error during flag parsing, before any compile, so there are no
|
||||
* All flag rows error during 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).
|
||||
*/
|
||||
@@ -25,6 +26,7 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include "ww.h"
|
||||
|
||||
struct row {
|
||||
const char *args; /* argv tail after the driver path */
|
||||
@@ -37,47 +39,85 @@ static const struct row rows[] = {
|
||||
{ "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" },
|
||||
{ "build -zz", 2, "ww build: unknown flag" },
|
||||
{ "run -o", 2, "ww run: -o needs an argument" },
|
||||
{ "run -l", 2, "ww run: -l needs an argument" },
|
||||
{ "run -zz", 2, "ww run: unknown flag" },
|
||||
{ "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). */
|
||||
/* Package `test -c` is now valid and covered by native package tests. A
|
||||
* lone -o needs an argument, while -o still has no directory contract. */
|
||||
{ "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" },
|
||||
{ "test -o x", 2, "ww test: -c/-S/-o need a single test file" },
|
||||
{ "test -run", 2, "ww test: -run needs an argument" },
|
||||
/* #17: a 2nd positional is a fnmatch name-filter pattern, valid only
|
||||
* for a single test file/module; in directory mode (target ".") it
|
||||
* has no single binary to route to and is rejected (rc 2). */
|
||||
{ "test . zzz", 2, "ww test: pattern needs 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 void
|
||||
read_text(const char *path, char *buf, size_t bufsz)
|
||||
{
|
||||
buf[0] = '\0';
|
||||
FILE *f = fopen(path, "r");
|
||||
if (f == NULL)
|
||||
return;
|
||||
size_t n = fread(buf, 1, bufsz - 1, f);
|
||||
buf[n] = '\0';
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
/* Run "<bin>/<drv> <args>" and capture both output streams. */
|
||||
static int
|
||||
run_drv(const char *bin, const char *drv, const char *args,
|
||||
char *err, size_t errsz)
|
||||
char *out, size_t outsz, char *err, size_t errsz)
|
||||
{
|
||||
int pid = getpid();
|
||||
char errf[64], cmd[2048];
|
||||
char outf[64], errf[64], cmd[2048];
|
||||
snprintf(outf, sizeof outf, "/tmp/dfa949_%d.out", pid);
|
||||
snprintf(errf, sizeof errf, "/tmp/dfa949_%d.err", pid);
|
||||
snprintf(cmd, sizeof cmd, "%s/%s %s >/dev/null 2>%s", bin, drv, args, errf);
|
||||
snprintf(cmd, sizeof cmd, "%s/%s %s >%s 2>%s",
|
||||
bin, drv, args, outf, 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);
|
||||
if (rc == -1) {
|
||||
unlink(outf);
|
||||
unlink(errf);
|
||||
return -1;
|
||||
}
|
||||
rc = WIFEXITED(rc) ? WEXITSTATUS(rc) : 1;
|
||||
read_text(outf, out, outsz);
|
||||
read_text(errf, err, errsz);
|
||||
unlink(outf);
|
||||
unlink(errf);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int
|
||||
test_version(const char *bin)
|
||||
{
|
||||
char cout[128], cerr[128], wout[128], werr[128], want[128];
|
||||
int crc = run_drv(bin, "ww", "-V", cout, sizeof cout,
|
||||
cerr, sizeof cerr);
|
||||
int wrc = run_drv(bin, "ww_ww", "-V", wout, sizeof wout,
|
||||
werr, sizeof werr);
|
||||
int fail = 0;
|
||||
snprintf(want, sizeof want, "ww %s\n", WW_VERSION);
|
||||
if (crc != 0 || strcmp(cout, want) != 0 || cerr[0] != '\0') {
|
||||
fprintf(stderr, "949 FAIL: ww -V rc=%d stdout='%s' stderr='%s'\n",
|
||||
crc, cout, cerr);
|
||||
fail = 1;
|
||||
}
|
||||
if (wrc != crc || strcmp(wout, cout) != 0 || strcmp(werr, cerr) != 0) {
|
||||
fprintf(stderr, "949 FAIL: ww_ww -V rc=%d stdout='%s' stderr='%s' "
|
||||
"!= ww rc=%d stdout='%s' stderr='%s'\n",
|
||||
wrc, wout, werr, crc, cout, cerr);
|
||||
fail = 1;
|
||||
}
|
||||
return fail;
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
@@ -91,12 +131,14 @@ main(void)
|
||||
bin = absbin;
|
||||
}
|
||||
|
||||
int fail = 0;
|
||||
int fail = test_version(bin);
|
||||
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);
|
||||
char cout[256], cerr[4096], wout[256], werr[4096];
|
||||
int crc = run_drv(bin, "ww", rows[i].args,
|
||||
cout, sizeof cout, cerr, sizeof cerr);
|
||||
int wrc = run_drv(bin, "ww_ww", rows[i].args,
|
||||
wout, sizeof wout, werr, sizeof werr);
|
||||
|
||||
if (crc != rows[i].rc) {
|
||||
fprintf(stderr, "949 FAIL: ww %s rc=%d want=%d\n",
|
||||
@@ -119,9 +161,15 @@ main(void)
|
||||
rows[i].args, werr, cerr);
|
||||
fail = 1;
|
||||
}
|
||||
if (strcmp(wout, cout) != 0) {
|
||||
fprintf(stderr, "949 FAIL: %s ww_ww stdout '%s' != ww '%s'\n",
|
||||
rows[i].args, wout, cout);
|
||||
fail = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (fail) return 1;
|
||||
printf("driver flag-argument error branches: %zu rows, ww==ww_ww pinned\n", n);
|
||||
printf("driver version + flag-argument errors: %zu rows, ww==ww_ww pinned\n",
|
||||
n);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user