Files
ww/test/wwc/000_smoke.c
Hojun-Cho 1657bdeda3 ww: import toolchain — C bootstrap + ww-side self-host (phases 0-10)
C bootstrap (phases 0-9):
  cmd/wwc, cmd/6c, cmd/6a, cmd/6l, cmd/ww, rt, lib/*.

ww-side self-host (phase 10):
  selfhost/cmd/wwc — ww-cgen frontend; bootstrap fixed point.
  selfhost/cmd/6a  — assembler; byte-identical to C 6a (test 991).
  selfhost/cmd/6l  — linker w/ archive (.a) support; byte-identical
                     to C 6l (test 992).
  selfhost/cmd/ww  — driver (build/run/version); byte-identical to
                     C ww (test 993).

make test: 15/15. make bootstrap: ww2.s == ww3.s, ww2.o == ww3.o,
ww2 == ww3 byte-identical, with the full ww-tooled chain.
2026-05-11 02:17:47 +09:00

88 lines
1.7 KiB
C

/*
* 000_smoke — Phase 0 smoke test.
*
* Asserts:
* - libwwc symbols (newarena/amalloc/freearena, fatal/errorf/warnf)
* are linkable.
* - `ww -V` exits 0 and prints the configured version.
*/
#include "ww.h"
#include <stdlib.h>
#include <string.h>
static void
test_arena(void)
{
Arena *a = newarena();
if (a == NULL) {
fprintf(stderr, "smoke: newarena returned NULL\n");
exit(1);
}
int *p = amalloc(a, sizeof *p);
*p = 42;
if (*p != 42) {
fprintf(stderr, "smoke: arena alloc bad\n");
exit(1);
}
/* force several growths */
for (int i = 0; i < 10000; i++) {
char *s = aprintf(a, "hello-%d", i);
if (s == NULL || strncmp(s, "hello-", 6) != 0) {
fprintf(stderr, "smoke: aprintf bad\n");
exit(1);
}
}
freearena(a);
}
static void
test_version(void)
{
if (WW_VERSION == NULL || WW_VERSION[0] == '\0') {
fprintf(stderr, "smoke: empty WW_VERSION\n");
exit(1);
}
}
static void
test_ww_minus_v(void)
{
const char *bin = getenv("BIN");
if (bin == NULL)
bin = "out/bin";
char cmd[512];
snprintf(cmd, sizeof cmd, "%s/ww -V", bin);
FILE *p = popen(cmd, "r");
if (p == NULL) {
fprintf(stderr, "smoke: popen %s\n", cmd);
exit(1);
}
char buf[128];
size_t n = fread(buf, 1, sizeof buf - 1, p);
buf[n] = '\0';
int rc = pclose(p);
if (rc != 0) {
fprintf(stderr, "smoke: ww -V exit %d\n", rc);
exit(1);
}
if (strstr(buf, "ww ") != buf) {
fprintf(stderr, "smoke: ww -V output not 'ww ...': %s\n", buf);
exit(1);
}
if (strstr(buf, WW_VERSION) == NULL) {
fprintf(stderr, "smoke: ww -V missing version %s in: %s\n",
WW_VERSION, buf);
exit(1);
}
}
int
main(void)
{
test_arena();
test_version();
test_ww_minus_v();
puts("smoke: ok");
return 0;
}