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:
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* 976_stat_run — execute the lib/os stat fixture under the C-side
|
||||
* `ww run` driver and assert exit 0.
|
||||
* `ww test` driver and assert exit 0.
|
||||
*
|
||||
* Workflow (mirrors 975_dirs_run's mkdtemp + setenv + rm-rf shape):
|
||||
* Workflow (mirrors 975_dirs_run's mkdtemp + exact-cleanup shape):
|
||||
* 1. mkdtemp /tmp/wwstat-XXXXXX — fresh per run, no parallel-test
|
||||
* contention.
|
||||
* 2. Populate the scratch tree:
|
||||
@@ -12,15 +12,15 @@
|
||||
* 3. setenv WW_TEST_STAT_REGFILE / SYMLINK / SUBDIR / NOENT with
|
||||
* the absolute paths; lib/os/stattest.ww reads them via
|
||||
* os.getenv and exercises stat/lstat/fstat/exists.
|
||||
* 4. exec `ww run lib/os/stattest.ww`.
|
||||
* 5. system("rm -rf <tmp>") regardless of pass/fail.
|
||||
* 4. exec `ww test lib/os/stattest.ww`.
|
||||
* 5. Remove the exact children and then the mkdtemp-owned root.
|
||||
*
|
||||
* Same wrapper shape as 970-975; cleanup-on-failure is rm-rf'd so a
|
||||
* regression never leaves residue under /tmp.
|
||||
* Same wrapper shape as 970-975; cleanup runs on success and failure.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -62,46 +62,51 @@ main(void)
|
||||
snprintf(symlink_path, sizeof symlink_path, "%s/symlink", tmpl);
|
||||
snprintf(subdir, sizeof subdir, "%s/subdir", tmpl);
|
||||
snprintf(noent, sizeof noent, "%s/does-not-exist", tmpl);
|
||||
const char *src = "lib/os/stattest.ww";
|
||||
int fail = 0, subdir_owned = 0;
|
||||
|
||||
/* Populate. */
|
||||
int fd = open(regfile, O_WRONLY | O_CREAT | O_EXCL, 0644);
|
||||
if (fd < 0) { perror("open regfile"); goto cleanup_fail; }
|
||||
if (fd < 0) { perror("open regfile"); fail = 1; goto cleanup; }
|
||||
if (write(fd, "hello world", 11) != 11) {
|
||||
perror("write regfile"); close(fd); goto cleanup_fail;
|
||||
perror("write regfile"); close(fd); fail = 1; goto cleanup;
|
||||
}
|
||||
close(fd);
|
||||
if (symlink("./regfile", symlink_path) != 0) {
|
||||
perror("symlink"); goto cleanup_fail;
|
||||
perror("symlink"); fail = 1; goto cleanup;
|
||||
}
|
||||
if (mkdir(subdir, 0700) != 0) {
|
||||
perror("mkdir subdir"); goto cleanup_fail;
|
||||
perror("mkdir subdir"); fail = 1; goto cleanup;
|
||||
}
|
||||
subdir_owned = 1;
|
||||
|
||||
setenv("WW_TEST_STAT_REGFILE", regfile, 1);
|
||||
setenv("WW_TEST_STAT_SYMLINK", symlink_path, 1);
|
||||
setenv("WW_TEST_STAT_SUBDIR", subdir, 1);
|
||||
setenv("WW_TEST_STAT_NOENT", noent, 1);
|
||||
|
||||
const char *src = "lib/os/stattest.ww";
|
||||
char path[1024], cmd[2048];
|
||||
snprintf(path, sizeof path, "%s/%s", cwd, src);
|
||||
snprintf(cmd, sizeof cmd, "%s/ww test %s", bin, path);
|
||||
int rc = runwait(cmd);
|
||||
|
||||
char rmcmd[256];
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpl);
|
||||
(void)system(rmcmd);
|
||||
|
||||
if (rc != 0) {
|
||||
fprintf(stderr, "stat_run FAIL: %s exited %d\n", src, rc);
|
||||
return 1;
|
||||
fail = 1;
|
||||
}
|
||||
|
||||
cleanup: {
|
||||
int cleanbad = 0;
|
||||
if (unlink(symlink_path) != 0 && errno != ENOENT) cleanbad = 1;
|
||||
if (unlink(regfile) != 0 && errno != ENOENT) cleanbad = 1;
|
||||
if (subdir_owned && rmdir(subdir) != 0) cleanbad = 1;
|
||||
if (rmdir(tmpl) != 0) cleanbad = 1;
|
||||
if (cleanbad) {
|
||||
fprintf(stderr, "stat_run FAIL: temporary cleanup failed\n");
|
||||
fail = 1;
|
||||
}
|
||||
}
|
||||
if (fail) return 1;
|
||||
printf("stat_run: %s ok\n", src);
|
||||
return 0;
|
||||
|
||||
cleanup_fail: {
|
||||
char rmcmd[256];
|
||||
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpl);
|
||||
(void)system(rmcmd);
|
||||
return 1;
|
||||
} }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user