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:
@@ -35,6 +35,7 @@
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
@@ -91,17 +92,29 @@ static const struct row rows[] = {
|
||||
0, STAGE_CS | STAGE_WW, 1 },
|
||||
};
|
||||
|
||||
static void
|
||||
/* nonzero on any cleanup failure; ENOENT tolerated because legs that
|
||||
* fail early never create the later artifacts (a -S build also never
|
||||
* produces the base binary / .o / .combined.ww). */
|
||||
static int
|
||||
cleanup_tmp(const char *tmpdir, const char *base)
|
||||
{
|
||||
char p[1024];
|
||||
snprintf(p, sizeof p, "%s/%s", tmpdir, base); unlink(p);
|
||||
snprintf(p, sizeof p, "%s/%s.ww", tmpdir, base); unlink(p);
|
||||
snprintf(p, sizeof p, "rm -rf %s/%s.sepwork %s/pkgc", tmpdir, base, tmpdir);
|
||||
if (system(p)) {} /* best-effort */
|
||||
snprintf(p, sizeof p, "%s/%s.o", tmpdir, base); unlink(p);
|
||||
snprintf(p, sizeof p, "%s/%s.combined.ww", tmpdir, base); unlink(p);
|
||||
rmdir(tmpdir);
|
||||
int bad = 0;
|
||||
snprintf(p, sizeof p, "%s/%s", tmpdir, base);
|
||||
if (unlink(p) != 0 && errno != ENOENT) { perror(p); bad = 1; }
|
||||
snprintf(p, sizeof p, "%s/%s.ww", tmpdir, base);
|
||||
if (unlink(p) != 0 && errno != ENOENT) { perror(p); bad = 1; }
|
||||
snprintf(p, sizeof p, "rm -rf %s/%s.sepwork", tmpdir, base);
|
||||
if (runwait(p) != 0) {
|
||||
fprintf(stderr, "cleanup failed: %s\n", p);
|
||||
bad = 1;
|
||||
}
|
||||
snprintf(p, sizeof p, "%s/%s.o", tmpdir, base);
|
||||
if (unlink(p) != 0 && errno != ENOENT) { perror(p); bad = 1; }
|
||||
snprintf(p, sizeof p, "%s/%s.combined.ww", tmpdir, base);
|
||||
if (unlink(p) != 0 && errno != ENOENT) { perror(p); bad = 1; }
|
||||
if (rmdir(tmpdir) != 0) { perror(tmpdir); bad = 1; }
|
||||
return bad;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -109,8 +122,11 @@ write_source(const char *path, const char *src)
|
||||
{
|
||||
FILE *f = fopen(path, "wb");
|
||||
if (!f) return -1;
|
||||
fputs(src, f);
|
||||
fclose(f);
|
||||
if (fputs(src, f) == EOF) {
|
||||
fclose(f);
|
||||
return -1;
|
||||
}
|
||||
if (fclose(f) != 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -119,34 +135,14 @@ build_via_driver(const char *driver, const char *tmpdir, const char *src)
|
||||
{
|
||||
char cmd[2048];
|
||||
/* #93 sep layout: emit asm to <src-stem>.sepwork/__root.s; pin
|
||||
* WW_PKGCACHE under tmpdir so out/.pkgcache is untouched. */
|
||||
* all outputs stay under tmpdir. */
|
||||
snprintf(cmd, sizeof cmd,
|
||||
"cd %s && b='%s'; WW_PKGCACHE=%s/pkgc timeout 180 %s build --sep "
|
||||
"cd %s && b='%s'; timeout 180 %s build -S "
|
||||
"-o \"${b%%.ww}\" \"$b\" 2>/dev/null",
|
||||
tmpdir, src, tmpdir, driver);
|
||||
tmpdir, src, driver);
|
||||
return runwait(cmd);
|
||||
}
|
||||
|
||||
static int
|
||||
run_row(const char *driver, const struct row *r, int seq)
|
||||
{
|
||||
char tmpdir[256], src[512], base[64], outbin[768];
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/sfsz_%d_d_%d", getpid(), seq);
|
||||
snprintf(base, sizeof base, "main790");
|
||||
snprintf(src, sizeof src, "%s/%s.ww", tmpdir, base);
|
||||
mkdir(tmpdir, 0755);
|
||||
if (write_source(src, r->src) != 0) { cleanup_tmp(tmpdir, base); return -1; }
|
||||
int rc;
|
||||
if (build_via_driver(driver, tmpdir, src) == 0) {
|
||||
snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base);
|
||||
rc = runwait(outbin);
|
||||
} else {
|
||||
rc = -1;
|
||||
}
|
||||
cleanup_tmp(tmpdir, base);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int
|
||||
asm_byte_identical(const char *cdrv, const char *wdrv, const struct row *r,
|
||||
int seq)
|
||||
@@ -155,11 +151,18 @@ asm_byte_identical(const char *cdrv, const char *wdrv, const struct row *r,
|
||||
snprintf(tdc, sizeof tdc, "/tmp/sfsz_%d_c_%d", getpid(), seq);
|
||||
snprintf(tdw, sizeof tdw, "/tmp/sfsz_%d_w_%d", getpid(), seq);
|
||||
snprintf(base, sizeof base, "main790");
|
||||
mkdir(tdc, 0755);
|
||||
mkdir(tdw, 0755);
|
||||
int rc = -1, tdw_owned = 0, cleanfail = 0;
|
||||
if (mkdir(tdc, 0755) != 0) {
|
||||
perror(tdc);
|
||||
return -1;
|
||||
}
|
||||
if (mkdir(tdw, 0755) != 0) {
|
||||
perror(tdw);
|
||||
goto out;
|
||||
}
|
||||
tdw_owned = 1;
|
||||
snprintf(src, sizeof src, "%s/%s.ww", tdc, base);
|
||||
if (write_source(src, r->src) != 0) { cleanup_tmp(tdc, base); cleanup_tmp(tdw, base); return -1; }
|
||||
int rc = -1;
|
||||
if (write_source(src, r->src) != 0) goto out;
|
||||
if (build_via_driver(cdrv, tdc, src) != 0) goto out;
|
||||
snprintf(cs, sizeof cs, "%s/%s.sepwork/__root.s", tdc, base);
|
||||
snprintf(src, sizeof src, "%s/%s.ww", tdw, base);
|
||||
@@ -180,8 +183,13 @@ asm_byte_identical(const char *cdrv, const char *wdrv, const struct row *r,
|
||||
if (fc) fclose(fc);
|
||||
if (fw) fclose(fw);
|
||||
out:
|
||||
cleanup_tmp(tdc, base);
|
||||
cleanup_tmp(tdw, base);
|
||||
cleanfail = cleanup_tmp(tdc, base);
|
||||
if (tdw_owned && cleanup_tmp(tdw, base) != 0)
|
||||
cleanfail = 1;
|
||||
/* a leaked tree fails an otherwise-green row; a real diff result
|
||||
* (rc == -1) is never overwritten (110's cleanfail shape). */
|
||||
if (cleanfail && rc == 0)
|
||||
rc = -1;
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -209,33 +217,14 @@ main(void)
|
||||
for (int i = 0; i < n; i++) {
|
||||
const struct row *r = &rows[i];
|
||||
|
||||
if (r->stage_mask & STAGE_CS) {
|
||||
if (wwpresent && r->byte_id) {
|
||||
total++;
|
||||
int got = run_row(cdrv, r, seq++);
|
||||
if (got != r->want_exit) {
|
||||
fprintf(stderr, "sfsz[cs][%s]: exit=%d want=%d\n",
|
||||
r->label, got, r->want_exit);
|
||||
if (asm_byte_identical(cdrv, wdrv, r, seq++) != 0) {
|
||||
fprintf(stderr, "sfsz[byte-id][%s]: cstage vs wwstage asm differs\n",
|
||||
r->label);
|
||||
fail++;
|
||||
}
|
||||
}
|
||||
|
||||
if (wwpresent && (r->stage_mask & STAGE_WW)) {
|
||||
total++;
|
||||
int got = run_row(wdrv, r, seq++);
|
||||
if (got != r->want_exit) {
|
||||
fprintf(stderr, "sfsz[ww][%s]: exit=%d want=%d\n",
|
||||
r->label, got, r->want_exit);
|
||||
fail++;
|
||||
}
|
||||
if (r->byte_id) {
|
||||
total++;
|
||||
if (asm_byte_identical(cdrv, wdrv, r, seq++) != 0) {
|
||||
fprintf(stderr, "sfsz[byte-id][%s]: cstage vs wwstage asm differs\n",
|
||||
r->label);
|
||||
fail++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fail) {
|
||||
|
||||
Reference in New Issue
Block a user