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.
197 lines
4.6 KiB
C
197 lines
4.6 KiB
C
/* The canonical package route builds separate regex and regex_test -T roots
|
|
* under one `ww test <dir>` result. This legacy oracle pins the real 15/33
|
|
* split without recreating package discovery itself. */
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <sys/wait.h>
|
|
|
|
static const char *whitebox[] = {
|
|
"thread_shape",
|
|
"newmatch_discriminates",
|
|
"is_consuming_kinds",
|
|
"delete_thread_middle",
|
|
"add_thread_dedup_inherit",
|
|
"add_thread_dup_independence",
|
|
"run_thread_literal_program",
|
|
"run_thread_anchored_route",
|
|
"search_matches",
|
|
"search_early_exit",
|
|
"search_no_match",
|
|
"find_last_groupstart_cases",
|
|
"shift_direct",
|
|
"run_thread_group_arms",
|
|
"parse_repetition_cases",
|
|
};
|
|
|
|
static int
|
|
runwait(const char *cmd)
|
|
{
|
|
int rc;
|
|
|
|
rc = system(cmd);
|
|
if (rc == -1)
|
|
return -1;
|
|
if (WIFEXITED(rc))
|
|
return WEXITSTATUS(rc);
|
|
return 1;
|
|
}
|
|
|
|
static int
|
|
runcapture(const char *cmd, char *out, size_t outsz)
|
|
{
|
|
FILE *p;
|
|
size_t n;
|
|
int ch, overflow, status;
|
|
|
|
p = popen(cmd, "r");
|
|
if (p == NULL)
|
|
return -1;
|
|
n = 0;
|
|
overflow = 0;
|
|
while ((ch = fgetc(p)) != EOF) {
|
|
if (n + 1 < outsz)
|
|
out[n++] = ch;
|
|
else
|
|
overflow = 1;
|
|
}
|
|
out[n] = '\0';
|
|
status = pclose(p);
|
|
if (overflow || status == -1)
|
|
return -1;
|
|
if (WIFEXITED(status))
|
|
return WEXITSTATUS(status);
|
|
return 1;
|
|
}
|
|
|
|
static int
|
|
linecount(const char *out, const char *want)
|
|
{
|
|
const char *p, *end;
|
|
size_t n;
|
|
int count;
|
|
|
|
n = strlen(want);
|
|
count = 0;
|
|
for (p = out; *p != '\0'; p = *end == '\0' ? end : end + 1) {
|
|
end = strchr(p, '\n');
|
|
if (end == NULL)
|
|
end = p + strlen(p);
|
|
if ((size_t)(end - p) == n && memcmp(p, want, n) == 0)
|
|
count++;
|
|
}
|
|
return count;
|
|
}
|
|
|
|
static int
|
|
okcount(const char *out)
|
|
{
|
|
const char *p, *end;
|
|
static const char suffix[] = " ... ok";
|
|
size_t n, slen;
|
|
int count;
|
|
|
|
slen = sizeof suffix - 1;
|
|
count = 0;
|
|
for (p = out; *p != '\0'; p = *end == '\0' ? end : end + 1) {
|
|
end = strchr(p, '\n');
|
|
if (end == NULL)
|
|
end = p + strlen(p);
|
|
n = (size_t)(end - p);
|
|
if (n >= slen && memcmp(end - slen, suffix, slen) == 0)
|
|
count++;
|
|
}
|
|
return count;
|
|
}
|
|
|
|
static int
|
|
checkresult(const char *out)
|
|
{
|
|
char row[256];
|
|
const char *white_account, *external_account;
|
|
int bad;
|
|
|
|
bad = 0;
|
|
white_account = strstr(out,
|
|
"15 discovered, 15 selected, 15 started, 15 completed\n");
|
|
external_account = strstr(out,
|
|
"33 discovered, 33 selected, 33 started, 33 completed\n");
|
|
if (linecount(out,
|
|
"15 passed, 0 failed, 0 skipped, 0 harness errors") != 1
|
|
|| linecount(out,
|
|
"15 discovered, 15 selected, 15 started, 15 completed") != 1
|
|
|| linecount(out,
|
|
"33 passed, 0 failed, 0 skipped, 0 harness errors") != 1
|
|
|| linecount(out,
|
|
"33 discovered, 33 selected, 33 started, 33 completed") != 1
|
|
|| okcount(out) != 48 || white_account == NULL
|
|
|| external_account == NULL || white_account >= external_account
|
|
|| strstr(out, "FAIL") != NULL || strstr(out, "HARNESS") != NULL
|
|
|| strstr(out, "[no tests]") != NULL
|
|
|| strstr(out, "[no matches]") != NULL) {
|
|
fprintf(stderr, "regex_run FAIL: package result was incomplete\n%s",
|
|
out);
|
|
bad = 1;
|
|
}
|
|
for (size_t i = 0; i < sizeof whitebox / sizeof whitebox[0]; i++) {
|
|
snprintf(row, sizeof row, "regex.%s ... ok", whitebox[i]);
|
|
if (linecount(out, row) != 1) {
|
|
fprintf(stderr, "regex_run FAIL: regex.%s did not execute "
|
|
"exactly once\n", whitebox[i]);
|
|
bad = 1;
|
|
}
|
|
}
|
|
return bad ? -1 : 0;
|
|
}
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
const char *bin;
|
|
char absbin[1024], cwd[1024], tmp[] = "/tmp/wwregex.XXXXXX";
|
|
char cmd[4096], output[32768];
|
|
int rc, failed;
|
|
|
|
bin = getenv("BIN");
|
|
if (bin == NULL)
|
|
bin = "out/bin";
|
|
if (bin[0] != '/') {
|
|
if (getcwd(cwd, sizeof cwd) == NULL)
|
|
return 1;
|
|
if (snprintf(absbin, sizeof absbin, "%s/%s", cwd, bin)
|
|
>= (int)sizeof absbin)
|
|
return 1;
|
|
bin = absbin;
|
|
}
|
|
if (getcwd(cwd, sizeof cwd) == NULL)
|
|
return 1;
|
|
if (mkdtemp(tmp) == NULL)
|
|
return 1;
|
|
|
|
failed = 0;
|
|
/* A unique cwd prevents an unrelated local `regex` path from winning;
|
|
* the package coordinator owns both compatible groups in lexical order. */
|
|
if (snprintf(cmd, sizeof cmd,
|
|
"cd '%s' && timeout 180 '%s/ww' "
|
|
"test -I '%s/lib' '%s/lib/regex'",
|
|
tmp, bin, cwd, cwd) >= (int)sizeof cmd) {
|
|
failed = 1;
|
|
} else {
|
|
rc = runcapture(cmd, output, sizeof output);
|
|
if (rc != 0 || checkresult(output) != 0) {
|
|
fprintf(stderr, "regex_run FAIL: package exited %d\n", rc);
|
|
failed = 1;
|
|
} else {
|
|
printf("regex_run: package 15 white-box + 33 external, "
|
|
"48 passed, 0 failed\n");
|
|
}
|
|
}
|
|
|
|
if (rmdir(tmp) != 0) {
|
|
fprintf(stderr, "regex_run FAIL: cannot clean temporary directory\n");
|
|
failed = 1;
|
|
}
|
|
return failed ? 1 : 0;
|
|
}
|