test/wcc: extend carrier ownership to the bootstrap and platform gates

Same contract as the 27 repaired byte/artifact survivors: checked
acquisition, one all-exit cleanup funnel per carrier, ENOENT-tolerant
checked unlinks, exact-path deletion, and cleanup failure fails a
passing carrier without overwriting its diagnostic. Also closes the
vacuous-green channels: empty-artifact pairs no longer byte-compare
equal, capture and staging failures fail their row loudly, 950 requires
a clean checker exit on no-error rows and hard-fails on a missing
wwdump_ww, 992 keys its scratch per invocation so a failed cleanup
cannot leak stale objects into the next tool's compare, and 995 no
longer pre-sweeps a workdir it never created. No assertion is weakened;
990_selfhost is retired in the next commit rather than repaired.
This commit is contained in:
2026-08-07 23:28:49 +09:00
parent a87d931096
commit cdc8bda721
7 changed files with 332 additions and 105 deletions

View File

@@ -9,32 +9,48 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/wait.h>
#include "wwtestpkg.h"
static int
runcap(const char *cmd, char **outerr, size_t *outlen)
runcap(const char *cmd, char **outerr, size_t *outlen, int *outrc)
{
char tmp[256];
snprintf(tmp, sizeof tmp, "/tmp/wwd_sc_%d", getpid());
char full[2048];
snprintf(full, sizeof full, "%s 2>%s 1>/dev/null", cmd, tmp);
int ret = -1;
FILE *f = NULL;
char *b = NULL;
long n = 0;
int rc = system(full);
FILE *f = fopen(tmp, "rb");
if (!f) { unlink(tmp); return -1; }
fseek(f, 0, SEEK_END);
long n = ftell(f);
fseek(f, 0, SEEK_SET);
char *b = malloc((size_t)n + 1);
if (!b) { fclose(f); unlink(tmp); return -1; }
if (fread(b, 1, (size_t)n, f) != (size_t)n) {
free(b); fclose(f); unlink(tmp); return -1;
}
if (rc == -1 || !WIFEXITED(rc)) goto cleanup;
f = fopen(tmp, "rb");
if (!f) { perror(tmp); goto cleanup; }
if (fseek(f, 0, SEEK_END) != 0) { perror(tmp); goto cleanup; }
n = ftell(f);
if (n < 0) { perror(tmp); goto cleanup; }
if (fseek(f, 0, SEEK_SET) != 0) { perror(tmp); goto cleanup; }
b = malloc((size_t)n + 1);
if (!b) goto cleanup;
if (fread(b, 1, (size_t)n, f) != (size_t)n) goto cleanup;
b[n] = '\0';
fclose(f); unlink(tmp);
*outerr = b; *outlen = (size_t)n;
(void)rc;
ret = 0;
cleanup:
/* the shell may never have created tmp (fork failure). */
if (f) fclose(f);
if (unlink(tmp) != 0 && errno != ENOENT) {
perror(tmp);
ret = -1;
}
if (ret != 0) {
free(b);
return -1;
}
*outerr = b; *outlen = (size_t)n; *outrc = WEXITSTATUS(rc);
return 0;
}
@@ -44,7 +60,15 @@ writefile(const char *path, const char *src)
FILE *f = fopen(path, "wb");
if (!f) return -1;
wwtest_fputs(src, f);
fclose(f);
/* wwtest_fputs is void; ferror + fclose's flush surface a short
* write (ENOSPC) that would otherwise compile a truncated fixture. */
int werr = ferror(f) != 0;
if (fclose(f) != 0 || werr) {
perror(path);
if (unlink(path) != 0 && errno != ENOENT)
perror(path);
return -1;
}
return 0;
}
@@ -168,9 +192,15 @@ main(void)
if (!bin) bin = "out/bin";
char wwdump[2048];
snprintf(wwdump, sizeof wwdump, "%s/wwdump_ww", bin);
/* bootstrap gate: a missing selfhost checker must FAIL, not skip. */
if (access(wwdump, X_OK) != 0) {
fprintf(stderr, "selfcheck: %s missing or not executable\n",
wwdump);
return 1;
}
int n = sizeof rows / sizeof rows[0];
int fail = 0;
int fail = 0, cleanfail = 0;
for (int i = 0; i < n; i++) {
char path[64];
snprintf(path, sizeof path, "/tmp/wwd_sc_%d_%d.ww", getpid(), i);
@@ -178,7 +208,12 @@ main(void)
char cmd[2048];
snprintf(cmd, sizeof cmd, "%s -r %s", wwdump, path);
char *err = NULL; size_t elen = 0;
runcap(cmd, &err, &elen);
int xrc = -1;
if (runcap(cmd, &err, &elen, &xrc) != 0) {
fprintf(stderr, "row %d: capture failed\n", i);
fail++;
goto rowcleanup;
}
const char *want = rows[i].expect;
int got_match = (err && want && strstr(err, want) != NULL);
int expected_no_err = (want == NULL);
@@ -201,7 +236,9 @@ main(void)
err_present = err_present || (err && strstr(err,
"return: not assignable") != NULL);
int ok;
if (expected_no_err) ok = !err_present;
/* a checker that dies with empty stderr must not pass a
* no-error row: require a clean exit too. */
if (expected_no_err) ok = !err_present && xrc == 0;
else ok = got_match;
if (!ok) {
fprintf(stderr,
@@ -209,13 +246,21 @@ main(void)
i, want ? want : "(no error)", err ? err : "(empty)");
fail++;
}
rowcleanup:
free(err);
unlink(path);
if (unlink(path) != 0 && errno != ENOENT) {
perror(path);
cleanfail = 1;
}
}
if (fail) {
fprintf(stderr, "%d/%d selfcheck rows failed\n", fail, n);
return 1;
}
if (cleanfail) {
fprintf(stderr, "selfcheck: cleanup failed\n");
return 1;
}
printf("selfcheck: %d/%d ok\n", n, n);
return 0;
}