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.
171 lines
5.0 KiB
C
171 lines
5.0 KiB
C
/*
|
|
* 944_variant_chain_b95_run -- SLIMMED to the one irreducible asymmetric row.
|
|
*
|
|
* The #95 variant-match chain-membership corpus (22 rows) migrated to fold-2
|
|
* homes (#5-C5): the K_RUN value rows -> test/lang/variant_chain_b95_test.ww
|
|
* (@test + T2 byte-id); the two #81-byte-id-waived CALL-source rows ->
|
|
* test/lang/variant_chain_b95_runonly_test.ww (value-only); the K_BUILDERR
|
|
* reject rows -> test/wcc/data/vchain_<name>/case.ww runww //ww:error carriers.
|
|
*
|
|
* callret_bound277 (kb5_v2sE) CANNOT move: it is cstage-runs / wwstage-rejects
|
|
* -- cstage builds+runs it (exit 0) while wwstage LOUD-STOPS with "deferred
|
|
* #277" (the ww aggregate-return capability gap, OUT of #95). That asymmetry is
|
|
* inexpressible as a single-compile @test (which builds one way) or a runww
|
|
* //ww:error carrier (which demands BOTH stages reject). It stays a slim C pin.
|
|
*
|
|
* Non-vacuity (the pin CAN go RED): if cstage stops running it (exit != 0) or
|
|
* wwstage starts accepting it (#277 wired), the row fails; the wwstage leg also
|
|
* requires the EXACT "deferred #277" diagnostic so an unrelated wwstage error
|
|
* cannot masquerade as coverage. Mutation-checked: dropping the cast-to-alias
|
|
* (`mk()` typed plainly) flips cstage and was observed RED.
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
#include <unistd.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/wait.h>
|
|
|
|
static int
|
|
runwait(const char *cmd)
|
|
{
|
|
int rc = system(cmd);
|
|
if (rc == -1) return -1;
|
|
if (WIFEXITED(rc)) return WEXITSTATUS(rc);
|
|
return -1;
|
|
}
|
|
|
|
static int
|
|
errlog_has(const char *path, const char *needle)
|
|
{
|
|
FILE *f = fopen(path, "rb");
|
|
if (!f) return 0;
|
|
char buf[8192];
|
|
size_t got = fread(buf, 1, sizeof buf - 1, f);
|
|
fclose(f);
|
|
buf[got] = '\0';
|
|
return strstr(buf, needle) != NULL;
|
|
}
|
|
|
|
/* kb5_v2sE: a CALL whose result is typed as the alias ali, widened into
|
|
* (void | ali). cstage's aggregate-return path runs it; wwstage #277 rejects. */
|
|
static const char *src =
|
|
"package main;\n"
|
|
"type base = struct { a: int, b: int };\n"
|
|
"type al0 = base;\n"
|
|
"type ali = al0;\n"
|
|
"fn mk() ali = {\n"
|
|
" let s: ali;\n"
|
|
" s.a = 4; s.b = 9;\n"
|
|
" return s;\n"
|
|
"};\n"
|
|
"export fn main() i32 = {\n"
|
|
" let v: (void | ali) = mk();\n"
|
|
" if (!(v is ali)) { return 1; };\n"
|
|
" return 0;\n"
|
|
"};\n";
|
|
|
|
static const char *experr = "deferred #277";
|
|
|
|
/* Build src with `driver`; if expect_err, the build must FAIL with experr on
|
|
* stderr. Otherwise build must succeed, then the binary runs and its exit must
|
|
* equal `want`. Returns 0 on the expected outcome, 1 otherwise. */
|
|
static int
|
|
check(const char *driver, int expect_err, int want)
|
|
{
|
|
char tmpdir[128], srcp[192], outbin[192], errf[192];
|
|
char scratch[208], cmd[1024];
|
|
snprintf(tmpdir, sizeof tmpdir, "/tmp/vc277_%d_%d_XXXXXX",
|
|
getpid(), expect_err);
|
|
if (mkdtemp(tmpdir) == NULL) {
|
|
fprintf(stderr, "callret_bound277: %s temporary directory "
|
|
"acquisition failed\n", driver);
|
|
return 1;
|
|
}
|
|
snprintf(srcp, sizeof srcp, "%s/c.ww", tmpdir);
|
|
snprintf(outbin, sizeof outbin, "%s/c", tmpdir);
|
|
snprintf(errf, sizeof errf, "%s/err", tmpdir);
|
|
snprintf(scratch, sizeof scratch, "%s.sepwork", outbin);
|
|
|
|
FILE *f = fopen(srcp, "wb");
|
|
int rc = 0;
|
|
if (!f) {
|
|
fprintf(stderr, "callret_bound277: %s source setup failed\n",
|
|
driver);
|
|
rc = 1;
|
|
goto cleanup;
|
|
}
|
|
fputs(src, f);
|
|
fclose(f);
|
|
|
|
snprintf(cmd, sizeof cmd, "timeout 20 %s build -o %s %s >/dev/null 2>%s",
|
|
driver, outbin, srcp, errf);
|
|
int brc = runwait(cmd);
|
|
|
|
if (expect_err) {
|
|
if (brc == 0 || !errlog_has(errf, experr)) {
|
|
fprintf(stderr, "callret_bound277: %s expected loud "
|
|
"builderr \"%s\" (brc=%d)\n", driver, experr, brc);
|
|
rc = 1;
|
|
}
|
|
} else if (brc != 0) {
|
|
fprintf(stderr, "callret_bound277: build via %s failed\n", driver);
|
|
rc = 1;
|
|
} else {
|
|
int got = runwait(outbin);
|
|
if (got != want) {
|
|
fprintf(stderr, "callret_bound277: %s exit %d, want %d\n",
|
|
driver, got, want);
|
|
rc = 1;
|
|
}
|
|
}
|
|
|
|
cleanup:
|
|
{
|
|
int bad = 0;
|
|
snprintf(cmd, sizeof cmd, "rm -rf %s", scratch);
|
|
if (runwait(cmd) != 0) bad = 1;
|
|
if (unlink(errf) != 0 && errno != ENOENT) bad = 1;
|
|
if (unlink(outbin) != 0 && errno != ENOENT) bad = 1;
|
|
if (unlink(srcp) != 0 && errno != ENOENT) bad = 1;
|
|
if (rmdir(tmpdir) != 0) bad = 1;
|
|
if (bad) {
|
|
fprintf(stderr, "callret_bound277: %s temporary cleanup "
|
|
"failed\n", driver);
|
|
rc = 1;
|
|
}
|
|
}
|
|
return rc;
|
|
}
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
const char *bin = getenv("BIN");
|
|
if (!bin) bin = "out/bin";
|
|
char absbin[2080];
|
|
if (bin[0] != '/') {
|
|
char cwd[1024];
|
|
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
|
|
snprintf(absbin, sizeof absbin, "%s/%s", cwd, bin);
|
|
bin = absbin;
|
|
}
|
|
|
|
char cdrv[2120], wdrv[2120];
|
|
snprintf(cdrv, sizeof cdrv, "%s/ww", bin);
|
|
snprintf(wdrv, sizeof wdrv, "%s/ww_ww", bin);
|
|
|
|
int fail = 0;
|
|
fail += check(cdrv, 0, 0); /* cstage runs, exit 0 */
|
|
if (access(wdrv, X_OK) == 0)
|
|
fail += check(wdrv, 1, 0); /* wwstage loud-stops #277 */
|
|
|
|
if (fail) {
|
|
fprintf(stderr, "variant_chain_b95: %d checks failed\n", fail);
|
|
return 1;
|
|
}
|
|
printf("variant_chain_b95: callret_bound277 pin ok\n");
|
|
return 0;
|
|
}
|