Plan 9-style w-prefix on the per-arch tools, disambiguating from the
real Plan 9 6c/6a/6l in ref/plan9front/:
cmd/wwc/ → cmd/wcc/ libwwc.a → libwcc.a
cmd/6{c,a,l} → cmd/w6{c,a,l} binary names too
test/wwc/ → test/wcc/ 6 test files w/ w6 prefix
selfhost/cmd mirror in lockstep
bootstrap/amd64/{w6c,w6a,w6l} snapshot binaries (gitignored)
WW_6{C,A,L} → WW_W6{C,A,L} env-var overrides
Plan 9 source-tree refs ("Plan 9 6c shape", ref/plan9front/, etc.)
preserved. Hare-style driver, both C and ww sides:
ww test [path] discover *_test.ww in a directory module, run
each; single-file mode for `ww test foo.ww`
Module-by-name `ww build foo` resolves to foo.ww or foo/foo.ww
via search path (cwd : -I dirs : $WW_LIB)
Default-to-cwd `ww build` / `ww test` build the cwd module
Run pass-through `ww run path arg1 arg2` reaches the program
lib/os: getcwd (79) and getdents64 (217) syscalls power `.` resolution
and directory enumeration on the ww side.
Makefile: wwstage tool deps now include lib/os/os.ww (+ lib/strconv
for wwdump_ww) so lib/* edits force their rebuild instead of leaving
stale binaries — surfaced when test 995 first failed against a stale
w6c_ww built before the lib/os additions.
Test 993 byte-identical parity gate (C-side ww vs ww-side ww_ww on a
build corpus) stays green; all 19 tests pass.
178 lines
4.9 KiB
C
178 lines
4.9 KiB
C
/*
|
|
* 993_ww_ww — phase-10 marker for the ww-side driver port.
|
|
*
|
|
* Diffs the C-built `ww` against the ww-built `ww_ww`. Both drivers
|
|
* orchestrate the same w6c/w6a/w6l, so the resulting binaries must be
|
|
* byte-identical for every program in the corpus. The corpus mixes:
|
|
* - a tiny single-file program (no -I flags)
|
|
* - a multi-import build (selfhost/cmd/wwdump/main.ww), exercising
|
|
* `use` resolution + the -I search path + the libwwrt.a link.
|
|
*
|
|
* Each build runs from a per-driver scratch directory so the
|
|
* intermediate .combined.ww/.s/.o files don't collide.
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.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 const char *
|
|
absbin(void)
|
|
{
|
|
const char *b = getenv("BIN");
|
|
if (!b) b = "out/bin";
|
|
if (b[0] == '/') return b;
|
|
static char buf[2048];
|
|
char cwd[1024];
|
|
if (getcwd(cwd, sizeof cwd) == NULL) return NULL;
|
|
snprintf(buf, sizeof buf, "%s/%s", cwd, b);
|
|
return buf;
|
|
}
|
|
|
|
static int
|
|
slurp_eq(const char *a, const char *b)
|
|
{
|
|
FILE *fa = fopen(a, "rb");
|
|
FILE *fb = fopen(b, "rb");
|
|
if (!fa || !fb) { if (fa) fclose(fa); if (fb) fclose(fb); return -1; }
|
|
int rc = 0;
|
|
for (;;) {
|
|
int ca = fgetc(fa);
|
|
int cb = fgetc(fb);
|
|
if (ca != cb) { rc = -1; break; }
|
|
if (ca == EOF) break;
|
|
}
|
|
fclose(fa); fclose(fb);
|
|
return rc;
|
|
}
|
|
|
|
/* Build `src` via the named driver, expecting output binary `out` in
|
|
* the build directory. Returns 0 on success. */
|
|
static int
|
|
build_via(const char *bin, const char *driver, const char *src,
|
|
const char *workdir, const char *includes_a, const char *includes_b)
|
|
{
|
|
char cmd[4096];
|
|
if (includes_b && includes_b[0]) {
|
|
snprintf(cmd, sizeof cmd,
|
|
"cd %s && %s/%s build -I %s -I %s %s 2>/dev/null",
|
|
workdir, bin, driver, includes_a, includes_b, src);
|
|
} else if (includes_a && includes_a[0]) {
|
|
snprintf(cmd, sizeof cmd,
|
|
"cd %s && %s/%s build -I %s %s 2>/dev/null",
|
|
workdir, bin, driver, includes_a, src);
|
|
} else {
|
|
snprintf(cmd, sizeof cmd,
|
|
"cd %s && %s/%s build %s 2>/dev/null",
|
|
workdir, bin, driver, src);
|
|
}
|
|
return runwait(cmd);
|
|
}
|
|
|
|
static int
|
|
diff_one(const char *bin, const char *cwd, const char *label,
|
|
const char *src, const char *out_basename,
|
|
const char *inc_a, const char *inc_b)
|
|
{
|
|
char dc[64], dw[64];
|
|
snprintf(dc, sizeof dc, "/tmp/ww_d_%d_c", getpid());
|
|
snprintf(dw, sizeof dw, "/tmp/ww_d_%d_w", getpid());
|
|
|
|
char cmd[256];
|
|
snprintf(cmd, sizeof cmd, "rm -rf %s %s && mkdir -p %s %s", dc, dw, dc, dw);
|
|
if (runwait(cmd) != 0) return -1;
|
|
|
|
if (build_via(bin, "ww", src, dc, inc_a, inc_b) != 0) {
|
|
fprintf(stderr, "ww_ww FAIL: C ww errored on %s\n", label);
|
|
return -1;
|
|
}
|
|
if (build_via(bin, "ww_ww", src, dw, inc_a, inc_b) != 0) {
|
|
fprintf(stderr, "ww_ww FAIL: ww ww errored on %s\n", label);
|
|
return -1;
|
|
}
|
|
|
|
char co[1024], wo[1024];
|
|
snprintf(co, sizeof co, "%s/%s", dc, out_basename);
|
|
snprintf(wo, sizeof wo, "%s/%s", dw, out_basename);
|
|
|
|
int rc = 0;
|
|
if (slurp_eq(co, wo) != 0) {
|
|
fprintf(stderr, "ww_ww FAIL: %s — driver outputs differ\n", label);
|
|
rc = -1;
|
|
}
|
|
snprintf(cmd, sizeof cmd, "rm -rf %s %s", dc, dw);
|
|
runwait(cmd);
|
|
(void)cwd;
|
|
return rc;
|
|
}
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
const char *bin = absbin();
|
|
if (!bin) return 1;
|
|
|
|
char cwd[1024];
|
|
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
|
|
|
|
/* Stage a tiny program in a place both drivers can reach. */
|
|
{
|
|
FILE *f = fopen("/tmp/ww_d_hello.ww", "w");
|
|
if (!f) return 1;
|
|
fputs("use os;\n\n"
|
|
"export fn main() i32 = {\n"
|
|
"\tos.write(1, \"hi\\n\".ptr, 3u64);\n"
|
|
"\treturn 0;\n"
|
|
"};\n", f);
|
|
fclose(f);
|
|
}
|
|
|
|
struct {
|
|
const char *label;
|
|
const char *src; /* may be relative to cwd */
|
|
const char *out; /* basename of expected output */
|
|
const char *inc_a;
|
|
const char *inc_b;
|
|
} cases[] = {
|
|
{ "hello", "/tmp/ww_d_hello.ww", "ww_d_hello", "", "" },
|
|
{ "wwdump", NULL, "main", NULL, NULL }, /* filled in below */
|
|
{ NULL, NULL, NULL, NULL, NULL },
|
|
};
|
|
|
|
/* wwdump case: absolute paths so the driver finds the imports
|
|
* regardless of the per-driver workdir. */
|
|
static char wwdump_src[2048], wwdump_inc_a[2048], wwdump_inc_b[2048];
|
|
snprintf(wwdump_src, sizeof wwdump_src, "%s/selfhost/cmd/wwdump/main.ww", cwd);
|
|
snprintf(wwdump_inc_a, sizeof wwdump_inc_a, "%s/selfhost/cmd/wcc", cwd);
|
|
wwdump_inc_b[0] = '\0';
|
|
cases[1].src = wwdump_src;
|
|
cases[1].inc_a = wwdump_inc_a;
|
|
cases[1].inc_b = wwdump_inc_b;
|
|
|
|
int fail = 0;
|
|
int n = 0;
|
|
for (int i = 0; cases[i].label; i++) {
|
|
if (diff_one(bin, cwd, cases[i].label, cases[i].src,
|
|
cases[i].out, cases[i].inc_a, cases[i].inc_b) != 0)
|
|
fail++;
|
|
n++;
|
|
}
|
|
unlink("/tmp/ww_d_hello.ww");
|
|
if (fail) {
|
|
fprintf(stderr, "ww_ww: %d/%d diff(s) failed\n", fail, n);
|
|
return 1;
|
|
}
|
|
printf("ww_ww: byte-identical to C ww on %d corpus builds "
|
|
"(single-file + selfhost/wwdump multi-import)\n", n);
|
|
return 0;
|
|
}
|