From dff5f296abcb48ce4e5053e9b29d4a54521d4d9e Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 21 Nov 2024 15:16:57 -0800 Subject: [PATCH 1/7] test: improve test infrastructure This change represents a rather large re-design in how `wasi-libc` builds and runs its tests. Initially, #346 retrieved the `libc-test` repository and built a subset of those tests to give us some amount of test coverage. Later, because there was no way to add custom C tests, #522 added a `smoke` directory which allowed this. But (a) each of these test suites was built and run separately and (b) it was unclear how to add more tests flexibly--some tests should only run on `*p2` targets or `*-threads` targets, e.g. This change reworks all of this so that all tests are built the same way, in the same place. For downloaded tests like those from `libc-test`, I chose to add "stub tests" that `#include` the original version. This not only keeps all enabled tests in one place, it also allows us to add "directives," C comments that the `Makefile` uses to filter out tests for certain targets or add special compile, link or run flags. These rudimentary scripts, along with other Bash logic I moved out of the Makefile now live in the `scripts` directory. Finally, all of this is explained more clearly in an updated `README.md`. The hope with documenting this a bit better is that it would be easier for drive-by contributors to be able to either dump in new C tests for regressions they may find or enable more libc-tests. As of my current count, we only enable 40/75 of libc-test's functional tests, 0/228 math tests, 0/69 regression tests, and 0/79 API tests. Though many of these may not apply to WASI programs, it would be nice to explore how many more of these tests can be enabled to increase wasi-libc's test coverage. This change should explain how to do that and, with directives, make it possible to condition how the tests compile and run. --- test/.gitignore | 3 - test/Makefile | 232 +++++++++--------- test/README.md | 83 ++++++- test/scripts/add-flags.py | 50 ++++ test/scripts/failed-tests.sh | 24 ++ test/scripts/filter.py | 93 +++++++ test/scripts/generate-stubs.sh | 20 ++ test/scripts/run-test.sh | 22 ++ test/smoke/smoke.mk | 35 --- test/src/libc-test/functional/argv.c | 2 + test/src/libc-test/functional/basename.c | 2 + .../libc-test/functional/clocale_mbfuncs.c | 2 + test/src/libc-test/functional/clock_gettime.c | 2 + test/src/libc-test/functional/crypt.c | 2 + test/src/libc-test/functional/dirname.c | 2 + test/src/libc-test/functional/env.c | 2 + test/src/libc-test/functional/fnmatch.c | 2 + test/src/libc-test/functional/iconv_open.c | 2 + test/src/libc-test/functional/mbc.c | 2 + test/src/libc-test/functional/memstream.c | 2 + test/src/libc-test/functional/qsort.c | 2 + test/src/libc-test/functional/random.c | 2 + .../src/libc-test/functional/search_hsearch.c | 2 + test/src/libc-test/functional/search_insque.c | 2 + .../src/libc-test/functional/search_lsearch.c | 2 + .../src/libc-test/functional/search_tsearch.c | 2 + test/src/libc-test/functional/snprintf.c | 2 + test/src/libc-test/functional/sscanf.c | 2 + test/src/libc-test/functional/strftime.c | 2 + test/src/libc-test/functional/string.c | 2 + test/src/libc-test/functional/string_memcpy.c | 2 + test/src/libc-test/functional/string_memmem.c | 2 + test/src/libc-test/functional/string_memset.c | 2 + test/src/libc-test/functional/string_strchr.c | 2 + .../src/libc-test/functional/string_strcspn.c | 2 + test/src/libc-test/functional/string_strstr.c | 2 + test/src/libc-test/functional/strtod.c | 2 + test/src/libc-test/functional/strtod_long.c | 2 + test/src/libc-test/functional/strtod_simple.c | 2 + test/src/libc-test/functional/strtof.c | 2 + test/src/libc-test/functional/strtol.c | 2 + test/src/libc-test/functional/strtold.c | 3 + test/src/libc-test/functional/swprintf.c | 2 + test/src/libc-test/functional/tgmath.c | 2 + test/src/libc-test/functional/udiv.c | 2 + test/src/libc-test/functional/wcsstr.c | 2 + test/src/libc-test/functional/wcstol.c | 2 + test/{smoke/test_fts.c => src/misc/fts.c} | 2 + 48 files changed, 486 insertions(+), 155 deletions(-) create mode 100755 test/scripts/add-flags.py create mode 100755 test/scripts/failed-tests.sh create mode 100755 test/scripts/filter.py create mode 100755 test/scripts/generate-stubs.sh create mode 100755 test/scripts/run-test.sh delete mode 100644 test/smoke/smoke.mk create mode 100644 test/src/libc-test/functional/argv.c create mode 100644 test/src/libc-test/functional/basename.c create mode 100644 test/src/libc-test/functional/clocale_mbfuncs.c create mode 100644 test/src/libc-test/functional/clock_gettime.c create mode 100644 test/src/libc-test/functional/crypt.c create mode 100644 test/src/libc-test/functional/dirname.c create mode 100644 test/src/libc-test/functional/env.c create mode 100644 test/src/libc-test/functional/fnmatch.c create mode 100644 test/src/libc-test/functional/iconv_open.c create mode 100644 test/src/libc-test/functional/mbc.c create mode 100644 test/src/libc-test/functional/memstream.c create mode 100644 test/src/libc-test/functional/qsort.c create mode 100644 test/src/libc-test/functional/random.c create mode 100644 test/src/libc-test/functional/search_hsearch.c create mode 100644 test/src/libc-test/functional/search_insque.c create mode 100644 test/src/libc-test/functional/search_lsearch.c create mode 100644 test/src/libc-test/functional/search_tsearch.c create mode 100644 test/src/libc-test/functional/snprintf.c create mode 100644 test/src/libc-test/functional/sscanf.c create mode 100644 test/src/libc-test/functional/strftime.c create mode 100644 test/src/libc-test/functional/string.c create mode 100644 test/src/libc-test/functional/string_memcpy.c create mode 100644 test/src/libc-test/functional/string_memmem.c create mode 100644 test/src/libc-test/functional/string_memset.c create mode 100644 test/src/libc-test/functional/string_strchr.c create mode 100644 test/src/libc-test/functional/string_strcspn.c create mode 100644 test/src/libc-test/functional/string_strstr.c create mode 100644 test/src/libc-test/functional/strtod.c create mode 100644 test/src/libc-test/functional/strtod_long.c create mode 100644 test/src/libc-test/functional/strtod_simple.c create mode 100644 test/src/libc-test/functional/strtof.c create mode 100644 test/src/libc-test/functional/strtol.c create mode 100644 test/src/libc-test/functional/strtold.c create mode 100644 test/src/libc-test/functional/swprintf.c create mode 100644 test/src/libc-test/functional/tgmath.c create mode 100644 test/src/libc-test/functional/udiv.c create mode 100644 test/src/libc-test/functional/wcsstr.c create mode 100644 test/src/libc-test/functional/wcstol.c rename test/{smoke/test_fts.c => src/misc/fts.c} (99%) diff --git a/test/.gitignore b/test/.gitignore index 469544f61..266ca8d5a 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1,5 +1,2 @@ build -download run - -smoke/*.dir diff --git a/test/Makefile b/test/Makefile index 31ff39f4e..43046fdc2 100644 --- a/test/Makefile +++ b/test/Makefile @@ -9,15 +9,28 @@ # - `run`: execute the benchmarks with a Wasm `$(ENGINE)` of choice (e.g., # Wasmtime) -test: run run_smoke - -# Unlike the `libc-test` directory, we will output all artifacts to the `build` -# directory (keeping with the `wasi-libc` conventions). -OBJDIR ?= $(CURDIR)/build -DOWNDIR ?= $(CURDIR)/download +test: run +# Decide which target to build for and which libc to use. TARGET_TRIPLE ?= wasm32-wasi +# Setup various paths used by the tests. +OBJDIR ?= build/$(TARGET_TRIPLE) +DOWNDIR ?= build/download +SRCDIR ?= src +RUNDIR ?= run/$(TARGET_TRIPLE) + +# We also need to know the location the wasi-libc sysroot we're building +# against. +SYSROOT_DIR ?= ../sysroot +SYSROOT := $(SYSROOT_DIR)/lib/$(TARGET_TRIPLE) +$(SYSROOT): + @echo "No sysroot for $(TARGET_TRIPLE) available at $(SYSROOT_DIR); to build it, e.g.:" + @echo " cd $(dir $(SYSROOT_DIR))" + @echo " make TARGET_TRIPLE=$(TARGET_TRIPLE)" + @exit 1 + + ##### DOWNLOAD ################################################################# LIBC_TEST_URL ?= https://github.com/bytecodealliance/libc-test @@ -25,21 +38,14 @@ LIBC_TEST = $(DOWNDIR)/libc-test LIBRT_URL ?= https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-24/libclang_rt.builtins-wasm32-wasi-24.0.tar.gz LIBRT = $(DOWNDIR)/libclang_rt.builtins-wasm32.a WASMTIME_URL ?= https://github.com/bytecodealliance/wasmtime/releases/download/v26.0.1/wasmtime-v26.0.1-x86_64-linux.tar.xz -WASMTIME = $(DOWNDIR)/$(shell basename $(WASMTIME_URL) .tar.xz)/wasmtime +WASMTIME = $(abspath $(DOWNDIR)/$(shell basename $(WASMTIME_URL) .tar.xz)/wasmtime) WASM_TOOLS_URL ?= https://github.com/bytecodealliance/wasm-tools/releases/download/v1.220.0/wasm-tools-1.220.0-x86_64-linux.tar.gz WASM_TOOLS = $(DOWNDIR)/$(shell basename $(WASM_TOOLS_URL) .tar.gz)/wasm-tools ADAPTER_URL ?= https://github.com/bytecodealliance/wasmtime/releases/download/v26.0.1/wasi_snapshot_preview1.command.wasm ADAPTER = $(DOWNDIR)/wasi_snapshot_preview1.command.wasm -TO_DOWNLOAD = $(LIBC_TEST) $(LIBRT) $(WASMTIME) -ifeq ($(TARGET_TRIPLE), wasm32-wasip2) -TO_DOWNLOAD += $(ADAPTER) $(WASM_TOOLS) -endif - -download: $(TO_DOWNLOAD) - $(DOWNDIR): - mkdir -p download + @mkdir -p $@ $(LIBC_TEST): | $(DOWNDIR) git clone --depth 1 $(LIBC_TEST_URL) $@ @@ -61,151 +67,147 @@ $(WASM_TOOLS): | $(DOWNDIR) $(ADAPTER): | $(DOWNDIR) wget --no-clobber --directory-prefix=$(DOWNDIR) $(ADAPTER_URL) +# Target to download all necessary dependencies. +TO_DOWNLOAD = $(LIBC_TEST) $(LIBRT) $(WASMTIME) +ifeq ($(TARGET_TRIPLE), wasm32-wasip2) +TO_DOWNLOAD += $(ADAPTER) $(WASM_TOOLS) +endif +DOWNLOADED := $(DOWNDIR)/downloaded.stamp +$(DOWNLOADED): $(TO_DOWNLOAD) + touch $@ +download: $(DOWNLOADED) + clean:: rm -rf $(DOWNDIR) -##### BUILD #################################################################### +##### INFRA #################################################################### -# For now, we list out the tests that we can currently build and run. This is -# heavily focused on the functional tests; in the future it would be good to -# fill out the missing tests and also include some `src/api` and `src/math` -# tests (TODO). -TESTS := \ - $(LIBC_TEST)/src/functional/argv.c \ - $(LIBC_TEST)/src/functional/basename.c \ - $(LIBC_TEST)/src/functional/clocale_mbfuncs.c \ - $(LIBC_TEST)/src/functional/clock_gettime.c \ - $(LIBC_TEST)/src/functional/crypt.c \ - $(LIBC_TEST)/src/functional/dirname.c \ - $(LIBC_TEST)/src/functional/env.c \ - $(LIBC_TEST)/src/functional/fnmatch.c \ - $(LIBC_TEST)/src/functional/iconv_open.c \ - $(LIBC_TEST)/src/functional/mbc.c \ - $(LIBC_TEST)/src/functional/memstream.c \ - $(LIBC_TEST)/src/functional/qsort.c \ - $(LIBC_TEST)/src/functional/random.c \ - $(LIBC_TEST)/src/functional/search_hsearch.c \ - $(LIBC_TEST)/src/functional/search_insque.c \ - $(LIBC_TEST)/src/functional/search_lsearch.c \ - $(LIBC_TEST)/src/functional/search_tsearch.c \ - $(LIBC_TEST)/src/functional/snprintf.c \ - $(LIBC_TEST)/src/functional/sscanf.c \ - $(LIBC_TEST)/src/functional/strftime.c \ - $(LIBC_TEST)/src/functional/string.c \ - $(LIBC_TEST)/src/functional/string_memcpy.c \ - $(LIBC_TEST)/src/functional/string_memmem.c \ - $(LIBC_TEST)/src/functional/string_memset.c \ - $(LIBC_TEST)/src/functional/string_strchr.c \ - $(LIBC_TEST)/src/functional/string_strcspn.c \ - $(LIBC_TEST)/src/functional/string_strstr.c \ - $(LIBC_TEST)/src/functional/strtod.c \ - $(LIBC_TEST)/src/functional/strtod_long.c \ - $(LIBC_TEST)/src/functional/strtod_simple.c \ - $(LIBC_TEST)/src/functional/strtof.c \ - $(LIBC_TEST)/src/functional/strtol.c \ - $(LIBC_TEST)/src/functional/swprintf.c \ - $(LIBC_TEST)/src/functional/tgmath.c \ - $(LIBC_TEST)/src/functional/udiv.c \ - $(LIBC_TEST)/src/functional/wcsstr.c \ - $(LIBC_TEST)/src/functional/wcstol.c - -# Part of the problem including more tests is that the `libc-test` -# infrastructure code is not all Wasm-compilable. As we include more tests -# above, this list will also likely need to grow. -COMMON_TEST_INFRA = \ - $(LIBC_TEST)/src/common/path.c \ +INFRA_OBJDIR := $(OBJDIR)/common +$(INFRA_OBJDIR): + mkdir -p $@ + +# Build the common test infrastructure. Part of the problem including more tests +# is that the `libc-test` infrastructure code is not all Wasm-compilable. As we +# include more tests above, this list will also likely need to grow. +INFRA_FILES = $(LIBC_TEST)/src/common/path.c \ $(LIBC_TEST)/src/common/print.c \ $(LIBC_TEST)/src/common/rand.c \ $(LIBC_TEST)/src/common/utf8.c +$(INFRA_FILES): $(DOWNLOADED) +INFRA_WASM_OBJS := $(patsubst $(LIBC_TEST)/src/common/%.c,$(OBJDIR)/common/%.wasm.o,$(INFRA_FILES)) +$(OBJDIR)/common/%.wasm.o: $(LIBC_TEST)/src/common/%.c | $(INFRA_OBJDIR) + $(CC) $(CFLAGS) -c $< -o $@ + +# Also, include the `libc-test` infrastructure headers. +INFRA_HEADERS_DIR := $(LIBC_TEST)/src/common +INFRA_HEADERS := $(shell find $(INFRA_HEADERS_DIR) -name '*.h') +$(INFRA_HEADERS): $(DOWNLOADED) + +##### BUILD #################################################################### # Create various lists containing the various artifacts to be built: mainly, # $(WASM_OBJS) are compiled in the $(OBJDIRS) and then linked together to form # the $(WASMS) tests. -NAMES := $(TESTS:$(LIBC_TEST)/src/%.c=%) -WASMS := $(TESTS:$(LIBC_TEST)/src/%.c=$(OBJDIR)/%.core.wasm) -WASM_OBJS := $(TESTS:$(LIBC_TEST)/src/%.c=$(OBJDIR)/%.wasm.o) -INFRA_WASM_OBJS := $(COMMON_TEST_INFRA:$(LIBC_TEST)/src/%.c=$(OBJDIR)/%.wasm.o) +ALL_TESTS := $(shell find $(SRCDIR) -name '*.c') +TESTS := $(shell TARGET_TRIPLE=$(TARGET_TRIPLE) scripts/filter.py $(ALL_TESTS)) +WASMS := $(TESTS:$(SRCDIR)/%.c=$(OBJDIR)/%.core.wasm) +WASM_OBJS := $(TESTS:$(SRCDIR)/%.c=$(OBJDIR)/%.wasm.o) WASM_OBJS += $(INFRA_WASM_OBJS) -DIRS := $(patsubst $(OBJDIR)/%/,%,$(sort $(dir $(WASM_OBJS)))) -OBJDIRS := $(DIRS:%=$(OBJDIR)/%) -# Allow $(CC) to be set from the command line; ?= doesn't work for CC because -# make has a default value for it. +# Setup the compiler. We allow $(CC) to be set from the command line; ?= doesn't +# work for CC because make has a default value for it. ifeq ($(origin CC), default) CC := clang endif LDFLAGS ?= -CFLAGS ?= --target=$(TARGET_TRIPLE) --sysroot=../sysroot +CFLAGS ?= --target=$(TARGET_TRIPLE) --sysroot=$(SYSROOT_DIR) # Always include the `libc-test` infrastructure headers. -CFLAGS += -I$(LIBC_TEST)/src/common +CFLAGS += -I$(INFRA_HEADERS_DIR) ifneq ($(findstring -threads,$(TARGET_TRIPLE)),) CFLAGS += -pthread endif -# Compile each selected test using Clang. Note that failures here are likely -# due to a missing `libclang_rt.builtins-wasm32.a` in the Clang lib directory. -# This location is system-dependent, but could be fixed by something like: -# $ sudo mkdir /usr/lib64/clang/14.0.5/lib/wasi -# $ sudo cp download/libclang_rt.builtins-wasm32.a /usr/lib64/clang/14.0.5/lib/wasi/ -build: download $(WASMS) +# Build up all the `*.wasm.o` object files; these are the same regardless of +# whether we're building core modules or components. +$(WASM_OBJS): $(INFRA_HEADERS) +$(OBJDIR)/%.wasm.o: $(SRCDIR)/%.c $(DOWNLOADED) $(SYSROOT) + @mkdir -p $(@D) + $(CC) $(CFLAGS) $(shell scripts/add-flags.py CFLAGS $<) -c $< -o $@ -$(WASMS): | $(OBJDIRS) +# Build up all the `*.wasm` files. +#$(WASMS): $(WASM_OBJS) +obj_to_c = $(patsubst $(OBJDIR)/%.wasm.o,$(SRCDIR)/%.c,$1) $(OBJDIR)/%.core.wasm: $(OBJDIR)/%.wasm.o $(INFRA_WASM_OBJS) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ + @mkdir -p $(@D) + $(CC) $(CFLAGS) $(LDFLAGS) $(shell scripts/add-flags.py LDFLAGS $(call obj_to_c,$<)) $^ -o $@ +# For wasip2, we include an additional step to wrap up the core module into +# a component. ifeq ($(TARGET_TRIPLE), wasm32-wasip2) -$(OBJDIR)/%.wasm: $(OBJDIR)/%.core.wasm +$(OBJDIR)/%.component.wasm: $(OBJDIR)/%.core.wasm $(WASM_TOOLS) component new --adapt $(ADAPTER) $< -o $@ endif -$(WASM_OBJS): $(LIBC_TEST)/src/common/test.h | $(OBJDIRS) -$(OBJDIR)/%.wasm.o: $(LIBC_TEST)/src/%.c - $(CC) $(CFLAGS) -c -o $@ $< - -$(OBJDIRS): - mkdir -p $@ +# Compile each selected test using Clang. Note that failures here are likely +# due to a missing `libclang_rt.builtins-wasm32.a` in the Clang lib directory. +# This location is system-dependent, but could be fixed by something like: +# $ sudo mkdir /usr/lib64/clang/14.0.5/lib/wasi +# $ sudo cp download/libclang_rt.builtins-wasm32.a /usr/lib64/clang/14.0.5/lib/wasi/ +build: $(DOWNLOADED) $(WASMS) clean:: rm -rf $(OBJDIR) -##### RUN ###################################################################### +##### GENERATE ################################################################# -ENGINE ?= $(WASMTIME) run -ERRS:=$(WASMS:%.core.wasm=%.wasm.err) +# Not all of the downloaded `libc-test` tests can be built and run with +# `wasi-libc`. Thus, we only include the subset that can be in `src/libc-test` +# as stub files that `#include` the original test files. When we want to add +# more tests, though, the `generate-stubs` target will generate stubs for the +# missing tests which we can delete or alter as needed. -# Use the provided Wasm engine to execute each test, emitting its output into -# a `.err` file. -run: build $(ERRS) - @echo "Tests passed" +STUBDIR := $(SRCDIR)/libc-test +generate-stubs: + FROM_DIR=$(LIBC_TEST) TO_DIR=$(STUBDIR) scripts/generate-stubs.sh -$(ERRS): | $(OBJDIRS) +##### RUN ###################################################################### +ENGINE ?= $(WASMTIME) run ifeq ($(TARGET_TRIPLE), wasm32-wasip2) -%.wasm.err: %.wasm - $(ENGINE) --wasm component-model $< >$@ +ENGINE += --wasm component-model +OBJPAT := $(OBJDIR)%.component.wasm else -%.wasm.err: %.core.wasm - $(ENGINE) $< >$@ +OBJPAT := $(OBJDIR)/%.core.wasm endif -clean:: - rm -rf $(OBJDIR)/*/*.err +# Each Wasm test is run every time, generating a folder containing a `cmd.sh` +# script and an `output.log` file (see `scripts/run-test.sh` for details). The +# `success` file is never generated, which means the test will rerun every time. +# To ignore a test temporarily, `touch .../success:`. +RUNTESTS:=$(WASMS:$(OBJDIR)%.core.wasm=$(RUNDIR)%.c/success) +wasm_to_c = $(patsubst $(OBJPAT),$(SRCDIR)/%.c,$1) +$(RUNDIR)/%.c/success: $(OBJPAT) + @mkdir -p $(@D) + @DIR="$(abspath $(@D))" \ + WASM="$(abspath $<)" \ + ENGINE="$(ENGINE) $(shell scripts/add-flags.py RUN $(call wasm_to_c,$<))" \ + scripts/run-test.sh -##### SMOKE TEST SUITE ######################################################### +# Use the provided Wasm engine to execute each test, emitting its output into +# a `.err` file. +run: build $(RUNTESTS) + @if scripts/failed-tests.sh $(RUNDIR); then \ + echo "Tests passed"; \ + else \ + echo "Tests failed:"; \ + VERBOSE=1 scripts/failed-tests.sh $(RUNDIR); \ + fi -include smoke/smoke.mk +clean:: + rm -rf $(RUNDIR) ##### MISC ##################################################################### # Note: the `clean` target has been built up by all of the previous sections. -debug: - @echo NAMES $(NAMES) - @echo TESTS $(TESTS) - @echo WASMS $(WASMS) - @echo WASM_OBJS $(WASM_OBJS) - @echo ERRS $(ERRS) - @echo DIRS $(DIRS) - @echo OBJDIRS $(OBJDIRS) - -.PHONY: test download build run clean +.PHONY: test download build run generate-stubs clean diff --git a/test/README.md b/test/README.md index 590c2d4d4..0ce3c4e7b 100644 --- a/test/README.md +++ b/test/README.md @@ -1,6 +1,85 @@ # Test -This directory runs a subset of libc-test using the sysroot produced by -`wasi-libc`. +This directory runs C tests compiled to WebAssembly against `wasi-libc` to check +its functionality. It enables a subset of [libc-test] as well as adding custom C +tests; all enabled tests are contained in the [`src`] directory. + +### Pre-requisites + +- Clang +- [`libc-test`] +- `libclang_rt.builtins-wasm32.a` +- a WebAssembly engine +- other WebAssembly tools, especially for `wasm32-wasip2` support (see the + [`Makefile] for a complete list) + +All but Clang are downloaded automatically by the `make download` target. + +### Build and run + +To build and run all tests: + +```sh +$ make TARGET_TRIPLE=... +Tests passed +``` + +Note that `wasm-ld` must be available, so an additional +`CC=/bin/clang` may be necessary. Each test runs in a directory that +looks like (see [`run-test.sh`]): + +```sh +$ ls run/$TARGET_TRIPLE/misc/some-test.c +cmd.sh # the exact command used to run the test +fs # a directory containing any test-created files +output.log # the captured printed output--only for errors +``` + +### Adding tests + +To add a test, create a new C file in [`src/misc`]: + +```c +// filter.py(TARGET_TRIPLE): !wasm32-wasip2 +// add-flags.py(CFLAGS): ... +// add-flags.py(LDFLAGS): ... +// add-flags.py(RUN): ... +void main() { ... } +``` + +- to pass, the `main` function must exit successfully and avoid printing output +- the `filter.py` directive controls when the test builds and runs (e.g., not + for `wasip2`) +- the `add-flags.py` directive adds extra information for building or running + the test (see the [`Makefile`] for precise use). + +### Enabling more [libc-test] tests + +[libc-test] has more tests available that are not yet enabled (e.g., to count +the enabled subset, `find src -name *.c | wc -l`). Each enabled test contains a +stub file in [`src/libc-test`] that `#include`s its downloaded version and adds +various `filter.py` and `add-flags.py` directives. + +To quickly create stub files for not-yet-enabled tests: + +```sh +$ make generate-stubs +$ git status +... +src/libc-test/functional/tls_align.c +src/libc-test/functional/tls_align_dlopen.c +src/libc-test/functional/tls_align_dso.c +src/libc-test/functional/tls_init.c +``` + +Then modify the directives for these new stub files to get the new tests to +compile and successfully run. + + [libc-test]: https://wiki.musl-libc.org/libc-test.html +[`Makefile`]: Makefile +[`run-test.sh`]: scripts/run-test.sh +[`src`]: src +[`src/libc-test`]: src/libc-test +[`src/misc`]: src/misc diff --git a/test/scripts/add-flags.py b/test/scripts/add-flags.py new file mode 100755 index 000000000..8a26c46cc --- /dev/null +++ b/test/scripts/add-flags.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python + +# Find additional compilation flags specified in test files. +# +# This script accepts a single file as an argument and looks for a comment like +# the following: `// add-flags.py(): `. If found, the `` are +# printed to stdout. +# +# Example: +# ``` +# $ head one.c +# // add-flags.py(CFLAGS): -DFOO +# $ ./add-flags.py CFLAGS one.c +# -DFOO + +import sys +import os +import re +import logging + +""" +Match a C comment like the following: `// add-flags.py: `. +""" +PATTERN = re.compile('\\s*//\\s*add-flags\\.py\\(([^)]+)\\):\\s*(.*)') + + +def find_flags(name, file): + with open(file, 'r') as f: + for lineno, line in enumerate(f, start=1): + match = PATTERN.match(line) + pos = f'[{file}:{lineno}]' + if match and match[1] == name: + logging.debug(f'{pos} found flags') + return match[2].strip() + + +def main(name, file): + flags = find_flags(name, file) + if flags: + print(flags) + + +if __name__ == "__main__": + logging.getLogger().name = os.path.basename(__file__) + if os.environ.get('VERBOSE'): + logging.basicConfig(level=logging.DEBUG) + if len(sys.argv) != 3: + print(f'usage: {sys.argv[0]} ') + sys.exit(1) + main(sys.argv[1], sys.argv[2]) diff --git a/test/scripts/failed-tests.sh b/test/scripts/failed-tests.sh new file mode 100755 index 000000000..8fe40efae --- /dev/null +++ b/test/scripts/failed-tests.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +# This script checks for failed tests in the given directory. Failed tests will +# include text in a *.err file. +# +# Usage: failed-tests.sh [TESTDIR] +# +# Optionally set the VERBOSE environment variable to see the list of failed +# tests. + +set -e + +TESTDIR=${1:-.} +FAILED=$(find $TESTDIR -type f -and -name *.log -and -not -size 0) + +if [[ -n "$VERBOSE" ]]; then + for failed in "$FAILED"; do + echo "$failed"; + done +fi + +if [[ -n "$FAILED" ]]; then + exit 1 +fi diff --git a/test/scripts/filter.py b/test/scripts/filter.py new file mode 100755 index 000000000..1fb22573e --- /dev/null +++ b/test/scripts/filter.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python + +# Filter out test files that do not match a configuration variable. +# +# This script accepts a list of files as arguments and looks for a comment like +# the following in each: `// filter.py(): `. The +# `VARIABLE` value is looked up in the environment and compared with the +# expression. An `EXPRESSION` is a comma-separated list of terms: either +# `` or `!`. If the `VARIABLE` value matches the expression, the +# file is printed; otherwise, it is filtered out. +# +# Example: +# ``` +# $ head one.c +# // filter.py(FOO): bar +# $ head two.c +# // filter.py(FOO):!bar, baz +# $ FOO=bar ./filter.py one.c two.c +# one.c +# $ FOO=baz ./filter.py one.c two.c +# two.c +# $ ./filter.py one.c two.c +# one.c two.c +# ``` + +import sys +import os +import re +import logging + + +def parse_expression(expr): + """ + An expression is a comma-separated list of terms: either or + !. + """ + return [s.strip() for s in expr.split(',')] + + +def matches_expression(value, expr, pos): + """ + A value matches an expression if it is in the list of strings or if it is + not explicitly rejected; order matters, because the first term that matches, + wins. + """ + for e in expr: + if e.startswith('!') and value == e[1:]: + logging.debug(f'{pos} {value} != {expr}, REJECTED') + return False + elif value == e: + logging.debug(f'{pos} {value} == {expr}, ALLOWED') + return True + logging.debug(f'{pos} {value} not in {expr}, REJECTED') + return False + + +""" +Match a C comment like the following: `// filter.py(): `. +""" +PATTERN = re.compile('\\s*//\\s*filter\\.py\\(([^)]+)\\):\\s*(.*)') + + +def line_matches(line, env, pos): + match = PATTERN.match(line) + if match: + value = env.get(match[1]) + if value is None: + logging.debug(f'{pos} no value for {match[1]}, ALLOWED') + return True + else: + expr = parse_expression(match[2]) + return matches_expression(value, expr, pos) + return True + + +def file_matches(file, env): + with open(file, 'r') as f: + print = True + for lineno, line in enumerate(f, start=1): + print &= line_matches(line, env, f'[{file}:{lineno}]') + return print + + +def main(env, files): + filtered = [file for file in files if file_matches(file, env)] + print(' '.join(filtered)) + + +if __name__ == "__main__": + logging.getLogger().name = os.path.basename(__file__) + if os.environ.get('VERBOSE'): + logging.basicConfig(level=logging.DEBUG) + main(os.environ, sys.argv[1:]) diff --git a/test/scripts/generate-stubs.sh b/test/scripts/generate-stubs.sh new file mode 100755 index 000000000..42f01423f --- /dev/null +++ b/test/scripts/generate-stubs.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# Create stub tests in `$TO_DIR` that `#include` a test in the `$FROM_DIR` +# directory. If the stub already exists, do not overwrite it. +# +# Usage: FROM_DIR=... TO_DIR=... ./generate-stubs.sh + +FROM_DIR="${FROM_DIR:-build/download/libc-test}" +TO_DIR="${TO_DIR:-src/libc-test}" +# For now, only retrieve the functional tests. +FUNCTIONAL_TESTS=$(find $FROM_DIR/src/math -name '*.c') + +for from in $FUNCTIONAL_TESTS; do + to="${from/"$FROM_DIR/src"/"$TO_DIR"}" + if [ ! -f $to ]; then \ + mkdir -p $(dirname $to) + echo '// add-flags.py(CFLAGS): -I.' > $to + echo "#include \"$from\"" >> $to + fi +done diff --git a/test/scripts/run-test.sh b/test/scripts/run-test.sh new file mode 100755 index 000000000..3a5189b4e --- /dev/null +++ b/test/scripts/run-test.sh @@ -0,0 +1,22 @@ +#/usr/bin/env bash + +# Run a previously built test, generating in `$DIR`: +# - a `cmd.sh` script containing the actual command used to run the test in an +# engine +# - a `fs` directory which the test may have used for file IO +# - an `output.log` file containing the output of the test +# +# Usage: DIR=... WASM=... ENGINE=... ./run-test.sh + +ENGINE="${ENGINE:-wasmtime}" +[ -n "$WASM" ] || (echo "missing WASM variable" && exit 1) +[ -n "$DIR" ] || (echo "missing DIR variable" && exit 1) + +pushd $DIR > /dev/null + mkdir -p fs + echo "$ENGINE $WASM" > cmd.sh + chmod +x cmd.sh + ./cmd.sh &> output.log + [ $? -eq 0 ] || echo "Test failed" >> output.log +popd > /dev/null + diff --git a/test/smoke/smoke.mk b/test/smoke/smoke.mk deleted file mode 100644 index ad9e9b899..000000000 --- a/test/smoke/smoke.mk +++ /dev/null @@ -1,35 +0,0 @@ -# Smoke test suite specific to wasi-libc -# -# This Makefile is included by the parent Makefile - -SMOKE_TESTS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -SMOKE_TESTS := $(wildcard $(SMOKE_TESTS_DIR)/*.c) -SMOKE_OBJDIR := $(OBJDIR)/smoke -SMOKE_WASMS := $(SMOKE_TESTS:$(SMOKE_TESTS_DIR)/%.c=$(SMOKE_OBJDIR)/%.core.wasm) -SMOKE_ERRS := $(SMOKE_WASMS:%.core.wasm=%.wasm.err) - -$(SMOKE_OBJDIR): - mkdir -p $@ - -$(SMOKE_OBJDIR)/%.core.wasm: $(SMOKE_TESTS_DIR)/%.c | $(SMOKE_OBJDIR) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ - -ifeq ($(TARGET_TRIPLE), wasm32-wasip2) -$(SMOKE_OBJDIR)/%.wasm: $(SMOKE_OBJDIR)/%.core.wasm - $(WASM_TOOLS) component new --adapt $(ADAPTER) $< -o $@ -endif - -ifeq ($(TARGET_TRIPLE), wasm32-wasip2) -$(SMOKE_OBJDIR)/%.wasm.err: $(SMOKE_OBJDIR)/%.wasm - rm -rf $(SMOKE_TESTS_DIR)/$*.dir - mkdir -p $(SMOKE_TESTS_DIR)/$*.dir - $(ENGINE) --dir $(SMOKE_TESTS_DIR)/$*.dir::/ --wasm component-model $< >$@ -else -$(SMOKE_OBJDIR)/%.wasm.err: $(SMOKE_OBJDIR)/%.core.wasm - rm -rf $(SMOKE_TESTS_DIR)/$*.dir - mkdir -p $(SMOKE_TESTS_DIR)/$*.dir - $(ENGINE) --dir $(SMOKE_TESTS_DIR)/$*.dir::/ $< >$@ -endif - -run_smoke: $(SMOKE_ERRS) - @echo "Smoke tests passed" diff --git a/test/src/libc-test/functional/argv.c b/test/src/libc-test/functional/argv.c new file mode 100644 index 000000000..741c7bc2a --- /dev/null +++ b/test/src/libc-test/functional/argv.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/argv.c" diff --git a/test/src/libc-test/functional/basename.c b/test/src/libc-test/functional/basename.c new file mode 100644 index 000000000..7549ea45f --- /dev/null +++ b/test/src/libc-test/functional/basename.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/basename.c" diff --git a/test/src/libc-test/functional/clocale_mbfuncs.c b/test/src/libc-test/functional/clocale_mbfuncs.c new file mode 100644 index 000000000..34b8c4c90 --- /dev/null +++ b/test/src/libc-test/functional/clocale_mbfuncs.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/clocale_mbfuncs.c" diff --git a/test/src/libc-test/functional/clock_gettime.c b/test/src/libc-test/functional/clock_gettime.c new file mode 100644 index 000000000..2ef8ac0ba --- /dev/null +++ b/test/src/libc-test/functional/clock_gettime.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/clock_gettime.c" diff --git a/test/src/libc-test/functional/crypt.c b/test/src/libc-test/functional/crypt.c new file mode 100644 index 000000000..d0792772e --- /dev/null +++ b/test/src/libc-test/functional/crypt.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/crypt.c" diff --git a/test/src/libc-test/functional/dirname.c b/test/src/libc-test/functional/dirname.c new file mode 100644 index 000000000..59ba9c755 --- /dev/null +++ b/test/src/libc-test/functional/dirname.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/dirname.c" diff --git a/test/src/libc-test/functional/env.c b/test/src/libc-test/functional/env.c new file mode 100644 index 000000000..1da8f66f2 --- /dev/null +++ b/test/src/libc-test/functional/env.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/env.c" diff --git a/test/src/libc-test/functional/fnmatch.c b/test/src/libc-test/functional/fnmatch.c new file mode 100644 index 000000000..6e1eefebd --- /dev/null +++ b/test/src/libc-test/functional/fnmatch.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/fnmatch.c" diff --git a/test/src/libc-test/functional/iconv_open.c b/test/src/libc-test/functional/iconv_open.c new file mode 100644 index 000000000..ceaedcd1a --- /dev/null +++ b/test/src/libc-test/functional/iconv_open.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/iconv_open.c" diff --git a/test/src/libc-test/functional/mbc.c b/test/src/libc-test/functional/mbc.c new file mode 100644 index 000000000..ef5406753 --- /dev/null +++ b/test/src/libc-test/functional/mbc.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/mbc.c" diff --git a/test/src/libc-test/functional/memstream.c b/test/src/libc-test/functional/memstream.c new file mode 100644 index 000000000..012d33126 --- /dev/null +++ b/test/src/libc-test/functional/memstream.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/memstream.c" diff --git a/test/src/libc-test/functional/qsort.c b/test/src/libc-test/functional/qsort.c new file mode 100644 index 000000000..4ecae8a44 --- /dev/null +++ b/test/src/libc-test/functional/qsort.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/qsort.c" diff --git a/test/src/libc-test/functional/random.c b/test/src/libc-test/functional/random.c new file mode 100644 index 000000000..8c4525734 --- /dev/null +++ b/test/src/libc-test/functional/random.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/random.c" diff --git a/test/src/libc-test/functional/search_hsearch.c b/test/src/libc-test/functional/search_hsearch.c new file mode 100644 index 000000000..8184280b1 --- /dev/null +++ b/test/src/libc-test/functional/search_hsearch.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/search_hsearch.c" diff --git a/test/src/libc-test/functional/search_insque.c b/test/src/libc-test/functional/search_insque.c new file mode 100644 index 000000000..ecc1df24a --- /dev/null +++ b/test/src/libc-test/functional/search_insque.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/search_insque.c" diff --git a/test/src/libc-test/functional/search_lsearch.c b/test/src/libc-test/functional/search_lsearch.c new file mode 100644 index 000000000..f3285a24b --- /dev/null +++ b/test/src/libc-test/functional/search_lsearch.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/search_lsearch.c" diff --git a/test/src/libc-test/functional/search_tsearch.c b/test/src/libc-test/functional/search_tsearch.c new file mode 100644 index 000000000..94bf8a800 --- /dev/null +++ b/test/src/libc-test/functional/search_tsearch.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/search_tsearch.c" diff --git a/test/src/libc-test/functional/snprintf.c b/test/src/libc-test/functional/snprintf.c new file mode 100644 index 000000000..471351ec4 --- /dev/null +++ b/test/src/libc-test/functional/snprintf.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/snprintf.c" diff --git a/test/src/libc-test/functional/sscanf.c b/test/src/libc-test/functional/sscanf.c new file mode 100644 index 000000000..003c1eec2 --- /dev/null +++ b/test/src/libc-test/functional/sscanf.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/sscanf.c" diff --git a/test/src/libc-test/functional/strftime.c b/test/src/libc-test/functional/strftime.c new file mode 100644 index 000000000..7b187804b --- /dev/null +++ b/test/src/libc-test/functional/strftime.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/strftime.c" diff --git a/test/src/libc-test/functional/string.c b/test/src/libc-test/functional/string.c new file mode 100644 index 000000000..1f8bc987c --- /dev/null +++ b/test/src/libc-test/functional/string.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/string.c" diff --git a/test/src/libc-test/functional/string_memcpy.c b/test/src/libc-test/functional/string_memcpy.c new file mode 100644 index 000000000..868da19d2 --- /dev/null +++ b/test/src/libc-test/functional/string_memcpy.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/string_memcpy.c" diff --git a/test/src/libc-test/functional/string_memmem.c b/test/src/libc-test/functional/string_memmem.c new file mode 100644 index 000000000..38f2d3a8f --- /dev/null +++ b/test/src/libc-test/functional/string_memmem.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/string_memmem.c" diff --git a/test/src/libc-test/functional/string_memset.c b/test/src/libc-test/functional/string_memset.c new file mode 100644 index 000000000..a62ca6c0c --- /dev/null +++ b/test/src/libc-test/functional/string_memset.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/string_memset.c" diff --git a/test/src/libc-test/functional/string_strchr.c b/test/src/libc-test/functional/string_strchr.c new file mode 100644 index 000000000..6d20432f0 --- /dev/null +++ b/test/src/libc-test/functional/string_strchr.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/string_strchr.c" diff --git a/test/src/libc-test/functional/string_strcspn.c b/test/src/libc-test/functional/string_strcspn.c new file mode 100644 index 000000000..ab45e8e46 --- /dev/null +++ b/test/src/libc-test/functional/string_strcspn.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/string_strcspn.c" diff --git a/test/src/libc-test/functional/string_strstr.c b/test/src/libc-test/functional/string_strstr.c new file mode 100644 index 000000000..3f03f8437 --- /dev/null +++ b/test/src/libc-test/functional/string_strstr.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/string_strstr.c" diff --git a/test/src/libc-test/functional/strtod.c b/test/src/libc-test/functional/strtod.c new file mode 100644 index 000000000..f4b43be29 --- /dev/null +++ b/test/src/libc-test/functional/strtod.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/strtod.c" diff --git a/test/src/libc-test/functional/strtod_long.c b/test/src/libc-test/functional/strtod_long.c new file mode 100644 index 000000000..a91f4cdd4 --- /dev/null +++ b/test/src/libc-test/functional/strtod_long.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/strtod_long.c" diff --git a/test/src/libc-test/functional/strtod_simple.c b/test/src/libc-test/functional/strtod_simple.c new file mode 100644 index 000000000..b23d469b5 --- /dev/null +++ b/test/src/libc-test/functional/strtod_simple.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/strtod_simple.c" diff --git a/test/src/libc-test/functional/strtof.c b/test/src/libc-test/functional/strtof.c new file mode 100644 index 000000000..cfca95da9 --- /dev/null +++ b/test/src/libc-test/functional/strtof.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/strtof.c" diff --git a/test/src/libc-test/functional/strtol.c b/test/src/libc-test/functional/strtol.c new file mode 100644 index 000000000..f5258fe50 --- /dev/null +++ b/test/src/libc-test/functional/strtol.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/strtol.c" diff --git a/test/src/libc-test/functional/strtold.c b/test/src/libc-test/functional/strtold.c new file mode 100644 index 000000000..7195ef49a --- /dev/null +++ b/test/src/libc-test/functional/strtold.c @@ -0,0 +1,3 @@ +// add-flags.py(CFLAGS): -I. +// add-flags.py(LDFLAGS): -lc-printscan-long-double +#include "build/download/libc-test/src/functional/strtold.c" diff --git a/test/src/libc-test/functional/swprintf.c b/test/src/libc-test/functional/swprintf.c new file mode 100644 index 000000000..a9d448541 --- /dev/null +++ b/test/src/libc-test/functional/swprintf.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/swprintf.c" diff --git a/test/src/libc-test/functional/tgmath.c b/test/src/libc-test/functional/tgmath.c new file mode 100644 index 000000000..3f5f46266 --- /dev/null +++ b/test/src/libc-test/functional/tgmath.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/tgmath.c" diff --git a/test/src/libc-test/functional/udiv.c b/test/src/libc-test/functional/udiv.c new file mode 100644 index 000000000..15233d257 --- /dev/null +++ b/test/src/libc-test/functional/udiv.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/udiv.c" diff --git a/test/src/libc-test/functional/wcsstr.c b/test/src/libc-test/functional/wcsstr.c new file mode 100644 index 000000000..ca84a72cb --- /dev/null +++ b/test/src/libc-test/functional/wcsstr.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/wcsstr.c" diff --git a/test/src/libc-test/functional/wcstol.c b/test/src/libc-test/functional/wcstol.c new file mode 100644 index 000000000..111bd5042 --- /dev/null +++ b/test/src/libc-test/functional/wcstol.c @@ -0,0 +1,2 @@ +// add-flags.py(CFLAGS): -I. +#include "build/download/libc-test/src/functional/wcstol.c" diff --git a/test/smoke/test_fts.c b/test/src/misc/fts.c similarity index 99% rename from test/smoke/test_fts.c rename to test/src/misc/fts.c index 240bb3d17..850c54c66 100644 --- a/test/smoke/test_fts.c +++ b/test/src/misc/fts.c @@ -1,3 +1,5 @@ +// add-flags.py(RUN): --dir fs::/ + /* * We modified musl-fts not to use fchdir() and we made FTS_NOCHDIR * the default behavior. This test is to make sure that the modified From 5795c3c1d43415936ee1536cb01547a8c40da5a2 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 21 Nov 2024 18:50:03 -0800 Subject: [PATCH 2/7] ci: tweak test step To avoid a `Makefile` dependency issue, a previous commit changed the location of the download directory to live inside the build directory; this change propagates that to the CI configuration. Also, it is no longer necessary to clean up anything between runs: both the `build` and `run` directory are subdivided by target triple so repeated builds will not interfere. --- .github/workflows/main.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b7e5c9107..40d5a25ac 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -125,17 +125,13 @@ jobs: export WASIP1_DIR=$(realpath $($CLANG_DIR/clang -print-resource-dir)/lib/wasip1/) export WASIP2_DIR=$(realpath $($CLANG_DIR/clang -print-resource-dir)/lib/wasip2/) mkdir -p $WASI_DIR $WASIP1_DIR $WASIP2_DIR - cp download/libclang_rt.builtins-wasm32.a $WASI_DIR - cp download/libclang_rt.builtins-wasm32.a $WASIP1_DIR - cp download/libclang_rt.builtins-wasm32.a $WASIP2_DIR + cp build/download/libclang_rt.builtins-wasm32.a $WASI_DIR + cp build/download/libclang_rt.builtins-wasm32.a $WASIP1_DIR + cp build/download/libclang_rt.builtins-wasm32.a $WASIP2_DIR TARGET_TRIPLE=wasm32-wasi make test - rm -r build TARGET_TRIPLE=wasm32-wasip1 make test - rm -r build TARGET_TRIPLE=wasm32-wasip2 make test - rm -r build TARGET_TRIPLE=wasm32-wasi-threads make test - rm -r build TARGET_TRIPLE=wasm32-wasip1-threads make test # The older version of Clang does not provide the expected symbol for the # test entrypoints: `undefined symbol: __main_argc_argv`. From 355683d48ae6ca3b8f551f3cda73d8802448e8d2 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 21 Nov 2024 19:43:39 -0800 Subject: [PATCH 3/7] fix: avoid using `pushd` and `popd` --- test/scripts/run-test.sh | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/test/scripts/run-test.sh b/test/scripts/run-test.sh index 3a5189b4e..820b7a260 100755 --- a/test/scripts/run-test.sh +++ b/test/scripts/run-test.sh @@ -12,11 +12,9 @@ ENGINE="${ENGINE:-wasmtime}" [ -n "$WASM" ] || (echo "missing WASM variable" && exit 1) [ -n "$DIR" ] || (echo "missing DIR variable" && exit 1) -pushd $DIR > /dev/null - mkdir -p fs - echo "$ENGINE $WASM" > cmd.sh - chmod +x cmd.sh - ./cmd.sh &> output.log - [ $? -eq 0 ] || echo "Test failed" >> output.log -popd > /dev/null - +cd $DIR +mkdir -p fs +echo "$ENGINE $WASM" > cmd.sh +chmod +x cmd.sh +./cmd.sh &> output.log +[ $? -eq 0 ] || echo "Test failed" >> output.log From 22815af18bca17b8a65410c290ca4e45275bbec1 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 21 Nov 2024 19:46:19 -0800 Subject: [PATCH 4/7] review: update comment from *.err to *.log --- test/scripts/failed-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/scripts/failed-tests.sh b/test/scripts/failed-tests.sh index 8fe40efae..381218a18 100755 --- a/test/scripts/failed-tests.sh +++ b/test/scripts/failed-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # This script checks for failed tests in the given directory. Failed tests will -# include text in a *.err file. +# include text in a *.log file. # # Usage: failed-tests.sh [TESTDIR] # From 86bb7a1a32802394df14d6e1fbcbba7aa9d4b165 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Fri, 22 Nov 2024 14:08:44 -0800 Subject: [PATCH 5/7] review: use //! for directive comments --- test/README.md | 8 ++++---- test/scripts/add-flags.py | 8 ++++---- test/scripts/filter.py | 10 +++++----- test/src/libc-test/functional/argv.c | 2 +- test/src/libc-test/functional/basename.c | 2 +- test/src/libc-test/functional/clocale_mbfuncs.c | 2 +- test/src/libc-test/functional/clock_gettime.c | 2 +- test/src/libc-test/functional/crypt.c | 2 +- test/src/libc-test/functional/dirname.c | 2 +- test/src/libc-test/functional/env.c | 2 +- test/src/libc-test/functional/fnmatch.c | 2 +- test/src/libc-test/functional/iconv_open.c | 2 +- test/src/libc-test/functional/mbc.c | 2 +- test/src/libc-test/functional/memstream.c | 2 +- test/src/libc-test/functional/qsort.c | 2 +- test/src/libc-test/functional/random.c | 2 +- test/src/libc-test/functional/search_hsearch.c | 2 +- test/src/libc-test/functional/search_insque.c | 2 +- test/src/libc-test/functional/search_lsearch.c | 2 +- test/src/libc-test/functional/search_tsearch.c | 2 +- test/src/libc-test/functional/snprintf.c | 2 +- test/src/libc-test/functional/sscanf.c | 2 +- test/src/libc-test/functional/strftime.c | 2 +- test/src/libc-test/functional/string.c | 2 +- test/src/libc-test/functional/string_memcpy.c | 2 +- test/src/libc-test/functional/string_memmem.c | 2 +- test/src/libc-test/functional/string_memset.c | 2 +- test/src/libc-test/functional/string_strchr.c | 2 +- test/src/libc-test/functional/string_strcspn.c | 2 +- test/src/libc-test/functional/string_strstr.c | 2 +- test/src/libc-test/functional/strtod.c | 2 +- test/src/libc-test/functional/strtod_long.c | 2 +- test/src/libc-test/functional/strtod_simple.c | 2 +- test/src/libc-test/functional/strtof.c | 2 +- test/src/libc-test/functional/strtol.c | 2 +- test/src/libc-test/functional/strtold.c | 4 ++-- test/src/libc-test/functional/swprintf.c | 2 +- test/src/libc-test/functional/tgmath.c | 2 +- test/src/libc-test/functional/udiv.c | 2 +- test/src/libc-test/functional/wcsstr.c | 2 +- test/src/libc-test/functional/wcstol.c | 2 +- test/src/misc/fts.c | 2 +- 42 files changed, 53 insertions(+), 53 deletions(-) diff --git a/test/README.md b/test/README.md index 0ce3c4e7b..45e6d22aa 100644 --- a/test/README.md +++ b/test/README.md @@ -40,10 +40,10 @@ output.log # the captured printed output--only for errors To add a test, create a new C file in [`src/misc`]: ```c -// filter.py(TARGET_TRIPLE): !wasm32-wasip2 -// add-flags.py(CFLAGS): ... -// add-flags.py(LDFLAGS): ... -// add-flags.py(RUN): ... +//! filter.py(TARGET_TRIPLE): !wasm32-wasip2 +//! add-flags.py(CFLAGS): ... +//! add-flags.py(LDFLAGS): ... +//! add-flags.py(RUN): ... void main() { ... } ``` diff --git a/test/scripts/add-flags.py b/test/scripts/add-flags.py index 8a26c46cc..643a922b2 100755 --- a/test/scripts/add-flags.py +++ b/test/scripts/add-flags.py @@ -9,7 +9,7 @@ # Example: # ``` # $ head one.c -# // add-flags.py(CFLAGS): -DFOO +# //! add-flags.py(CFLAGS): -DFOO # $ ./add-flags.py CFLAGS one.c # -DFOO @@ -19,17 +19,17 @@ import logging """ -Match a C comment like the following: `// add-flags.py: `. +Match a C comment like the following: `//! add-flags.py: `. """ -PATTERN = re.compile('\\s*//\\s*add-flags\\.py\\(([^)]+)\\):\\s*(.*)') +PATTERN = re.compile('\\s*//\\!\\s*add-flags\\.py\\(([^)]+)\\):\\s*(.*)') def find_flags(name, file): with open(file, 'r') as f: for lineno, line in enumerate(f, start=1): match = PATTERN.match(line) - pos = f'[{file}:{lineno}]' if match and match[1] == name: + pos = f'[{file}:{lineno}]' logging.debug(f'{pos} found flags') return match[2].strip() diff --git a/test/scripts/filter.py b/test/scripts/filter.py index 1fb22573e..6df117173 100755 --- a/test/scripts/filter.py +++ b/test/scripts/filter.py @@ -3,7 +3,7 @@ # Filter out test files that do not match a configuration variable. # # This script accepts a list of files as arguments and looks for a comment like -# the following in each: `// filter.py(): `. The +# the following in each: `//! filter.py(): `. The # `VARIABLE` value is looked up in the environment and compared with the # expression. An `EXPRESSION` is a comma-separated list of terms: either # `` or `!`. If the `VARIABLE` value matches the expression, the @@ -12,9 +12,9 @@ # Example: # ``` # $ head one.c -# // filter.py(FOO): bar +# //! filter.py(FOO): bar # $ head two.c -# // filter.py(FOO):!bar, baz +# //! filter.py(FOO):!bar, baz # $ FOO=bar ./filter.py one.c two.c # one.c # $ FOO=baz ./filter.py one.c two.c @@ -55,9 +55,9 @@ def matches_expression(value, expr, pos): """ -Match a C comment like the following: `// filter.py(): `. +Match a C comment like the following: `//! filter.py(): `. """ -PATTERN = re.compile('\\s*//\\s*filter\\.py\\(([^)]+)\\):\\s*(.*)') +PATTERN = re.compile('\\s*//\\!\\s*filter\\.py\\(([^)]+)\\):\\s*(.*)') def line_matches(line, env, pos): diff --git a/test/src/libc-test/functional/argv.c b/test/src/libc-test/functional/argv.c index 741c7bc2a..41dda8ae4 100644 --- a/test/src/libc-test/functional/argv.c +++ b/test/src/libc-test/functional/argv.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/argv.c" diff --git a/test/src/libc-test/functional/basename.c b/test/src/libc-test/functional/basename.c index 7549ea45f..feb49eef6 100644 --- a/test/src/libc-test/functional/basename.c +++ b/test/src/libc-test/functional/basename.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/basename.c" diff --git a/test/src/libc-test/functional/clocale_mbfuncs.c b/test/src/libc-test/functional/clocale_mbfuncs.c index 34b8c4c90..d2bc57526 100644 --- a/test/src/libc-test/functional/clocale_mbfuncs.c +++ b/test/src/libc-test/functional/clocale_mbfuncs.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/clocale_mbfuncs.c" diff --git a/test/src/libc-test/functional/clock_gettime.c b/test/src/libc-test/functional/clock_gettime.c index 2ef8ac0ba..1744dfb76 100644 --- a/test/src/libc-test/functional/clock_gettime.c +++ b/test/src/libc-test/functional/clock_gettime.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/clock_gettime.c" diff --git a/test/src/libc-test/functional/crypt.c b/test/src/libc-test/functional/crypt.c index d0792772e..a49662cd2 100644 --- a/test/src/libc-test/functional/crypt.c +++ b/test/src/libc-test/functional/crypt.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/crypt.c" diff --git a/test/src/libc-test/functional/dirname.c b/test/src/libc-test/functional/dirname.c index 59ba9c755..df9ea4ef7 100644 --- a/test/src/libc-test/functional/dirname.c +++ b/test/src/libc-test/functional/dirname.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/dirname.c" diff --git a/test/src/libc-test/functional/env.c b/test/src/libc-test/functional/env.c index 1da8f66f2..9dba36a5f 100644 --- a/test/src/libc-test/functional/env.c +++ b/test/src/libc-test/functional/env.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/env.c" diff --git a/test/src/libc-test/functional/fnmatch.c b/test/src/libc-test/functional/fnmatch.c index 6e1eefebd..26ae512e0 100644 --- a/test/src/libc-test/functional/fnmatch.c +++ b/test/src/libc-test/functional/fnmatch.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/fnmatch.c" diff --git a/test/src/libc-test/functional/iconv_open.c b/test/src/libc-test/functional/iconv_open.c index ceaedcd1a..945c5726f 100644 --- a/test/src/libc-test/functional/iconv_open.c +++ b/test/src/libc-test/functional/iconv_open.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/iconv_open.c" diff --git a/test/src/libc-test/functional/mbc.c b/test/src/libc-test/functional/mbc.c index ef5406753..7b353ec2e 100644 --- a/test/src/libc-test/functional/mbc.c +++ b/test/src/libc-test/functional/mbc.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/mbc.c" diff --git a/test/src/libc-test/functional/memstream.c b/test/src/libc-test/functional/memstream.c index 012d33126..c3fccf3ad 100644 --- a/test/src/libc-test/functional/memstream.c +++ b/test/src/libc-test/functional/memstream.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/memstream.c" diff --git a/test/src/libc-test/functional/qsort.c b/test/src/libc-test/functional/qsort.c index 4ecae8a44..ba8debf8a 100644 --- a/test/src/libc-test/functional/qsort.c +++ b/test/src/libc-test/functional/qsort.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/qsort.c" diff --git a/test/src/libc-test/functional/random.c b/test/src/libc-test/functional/random.c index 8c4525734..b6282112f 100644 --- a/test/src/libc-test/functional/random.c +++ b/test/src/libc-test/functional/random.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/random.c" diff --git a/test/src/libc-test/functional/search_hsearch.c b/test/src/libc-test/functional/search_hsearch.c index 8184280b1..9a5eb9adc 100644 --- a/test/src/libc-test/functional/search_hsearch.c +++ b/test/src/libc-test/functional/search_hsearch.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/search_hsearch.c" diff --git a/test/src/libc-test/functional/search_insque.c b/test/src/libc-test/functional/search_insque.c index ecc1df24a..21bf2cde7 100644 --- a/test/src/libc-test/functional/search_insque.c +++ b/test/src/libc-test/functional/search_insque.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/search_insque.c" diff --git a/test/src/libc-test/functional/search_lsearch.c b/test/src/libc-test/functional/search_lsearch.c index f3285a24b..e681fb54a 100644 --- a/test/src/libc-test/functional/search_lsearch.c +++ b/test/src/libc-test/functional/search_lsearch.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/search_lsearch.c" diff --git a/test/src/libc-test/functional/search_tsearch.c b/test/src/libc-test/functional/search_tsearch.c index 94bf8a800..45804c5ab 100644 --- a/test/src/libc-test/functional/search_tsearch.c +++ b/test/src/libc-test/functional/search_tsearch.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/search_tsearch.c" diff --git a/test/src/libc-test/functional/snprintf.c b/test/src/libc-test/functional/snprintf.c index 471351ec4..67f64da34 100644 --- a/test/src/libc-test/functional/snprintf.c +++ b/test/src/libc-test/functional/snprintf.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/snprintf.c" diff --git a/test/src/libc-test/functional/sscanf.c b/test/src/libc-test/functional/sscanf.c index 003c1eec2..ad63e2753 100644 --- a/test/src/libc-test/functional/sscanf.c +++ b/test/src/libc-test/functional/sscanf.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/sscanf.c" diff --git a/test/src/libc-test/functional/strftime.c b/test/src/libc-test/functional/strftime.c index 7b187804b..787f7e907 100644 --- a/test/src/libc-test/functional/strftime.c +++ b/test/src/libc-test/functional/strftime.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/strftime.c" diff --git a/test/src/libc-test/functional/string.c b/test/src/libc-test/functional/string.c index 1f8bc987c..52e181efe 100644 --- a/test/src/libc-test/functional/string.c +++ b/test/src/libc-test/functional/string.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/string.c" diff --git a/test/src/libc-test/functional/string_memcpy.c b/test/src/libc-test/functional/string_memcpy.c index 868da19d2..cfc947847 100644 --- a/test/src/libc-test/functional/string_memcpy.c +++ b/test/src/libc-test/functional/string_memcpy.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/string_memcpy.c" diff --git a/test/src/libc-test/functional/string_memmem.c b/test/src/libc-test/functional/string_memmem.c index 38f2d3a8f..d2362c4cd 100644 --- a/test/src/libc-test/functional/string_memmem.c +++ b/test/src/libc-test/functional/string_memmem.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/string_memmem.c" diff --git a/test/src/libc-test/functional/string_memset.c b/test/src/libc-test/functional/string_memset.c index a62ca6c0c..d5672dac8 100644 --- a/test/src/libc-test/functional/string_memset.c +++ b/test/src/libc-test/functional/string_memset.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/string_memset.c" diff --git a/test/src/libc-test/functional/string_strchr.c b/test/src/libc-test/functional/string_strchr.c index 6d20432f0..c9c2d2690 100644 --- a/test/src/libc-test/functional/string_strchr.c +++ b/test/src/libc-test/functional/string_strchr.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/string_strchr.c" diff --git a/test/src/libc-test/functional/string_strcspn.c b/test/src/libc-test/functional/string_strcspn.c index ab45e8e46..052e1e68d 100644 --- a/test/src/libc-test/functional/string_strcspn.c +++ b/test/src/libc-test/functional/string_strcspn.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/string_strcspn.c" diff --git a/test/src/libc-test/functional/string_strstr.c b/test/src/libc-test/functional/string_strstr.c index 3f03f8437..f0d2dbc76 100644 --- a/test/src/libc-test/functional/string_strstr.c +++ b/test/src/libc-test/functional/string_strstr.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/string_strstr.c" diff --git a/test/src/libc-test/functional/strtod.c b/test/src/libc-test/functional/strtod.c index f4b43be29..9bb36cff5 100644 --- a/test/src/libc-test/functional/strtod.c +++ b/test/src/libc-test/functional/strtod.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/strtod.c" diff --git a/test/src/libc-test/functional/strtod_long.c b/test/src/libc-test/functional/strtod_long.c index a91f4cdd4..5779e277f 100644 --- a/test/src/libc-test/functional/strtod_long.c +++ b/test/src/libc-test/functional/strtod_long.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/strtod_long.c" diff --git a/test/src/libc-test/functional/strtod_simple.c b/test/src/libc-test/functional/strtod_simple.c index b23d469b5..bbd817a1c 100644 --- a/test/src/libc-test/functional/strtod_simple.c +++ b/test/src/libc-test/functional/strtod_simple.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/strtod_simple.c" diff --git a/test/src/libc-test/functional/strtof.c b/test/src/libc-test/functional/strtof.c index cfca95da9..a5682c137 100644 --- a/test/src/libc-test/functional/strtof.c +++ b/test/src/libc-test/functional/strtof.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/strtof.c" diff --git a/test/src/libc-test/functional/strtol.c b/test/src/libc-test/functional/strtol.c index f5258fe50..b874d302b 100644 --- a/test/src/libc-test/functional/strtol.c +++ b/test/src/libc-test/functional/strtol.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/strtol.c" diff --git a/test/src/libc-test/functional/strtold.c b/test/src/libc-test/functional/strtold.c index 7195ef49a..8f467fedb 100644 --- a/test/src/libc-test/functional/strtold.c +++ b/test/src/libc-test/functional/strtold.c @@ -1,3 +1,3 @@ -// add-flags.py(CFLAGS): -I. -// add-flags.py(LDFLAGS): -lc-printscan-long-double +//! add-flags.py(CFLAGS): -I. +//! add-flags.py(LDFLAGS): -lc-printscan-long-double #include "build/download/libc-test/src/functional/strtold.c" diff --git a/test/src/libc-test/functional/swprintf.c b/test/src/libc-test/functional/swprintf.c index a9d448541..278b177db 100644 --- a/test/src/libc-test/functional/swprintf.c +++ b/test/src/libc-test/functional/swprintf.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/swprintf.c" diff --git a/test/src/libc-test/functional/tgmath.c b/test/src/libc-test/functional/tgmath.c index 3f5f46266..3a9d3c333 100644 --- a/test/src/libc-test/functional/tgmath.c +++ b/test/src/libc-test/functional/tgmath.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/tgmath.c" diff --git a/test/src/libc-test/functional/udiv.c b/test/src/libc-test/functional/udiv.c index 15233d257..162b60023 100644 --- a/test/src/libc-test/functional/udiv.c +++ b/test/src/libc-test/functional/udiv.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/udiv.c" diff --git a/test/src/libc-test/functional/wcsstr.c b/test/src/libc-test/functional/wcsstr.c index ca84a72cb..9c5581dd8 100644 --- a/test/src/libc-test/functional/wcsstr.c +++ b/test/src/libc-test/functional/wcsstr.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/wcsstr.c" diff --git a/test/src/libc-test/functional/wcstol.c b/test/src/libc-test/functional/wcstol.c index 111bd5042..04d19dd1a 100644 --- a/test/src/libc-test/functional/wcstol.c +++ b/test/src/libc-test/functional/wcstol.c @@ -1,2 +1,2 @@ -// add-flags.py(CFLAGS): -I. +//! add-flags.py(CFLAGS): -I. #include "build/download/libc-test/src/functional/wcstol.c" diff --git a/test/src/misc/fts.c b/test/src/misc/fts.c index 850c54c66..1126f9b79 100644 --- a/test/src/misc/fts.c +++ b/test/src/misc/fts.c @@ -1,4 +1,4 @@ -// add-flags.py(RUN): --dir fs::/ +//! add-flags.py(RUN): --dir fs::/ /* * We modified musl-fts not to use fchdir() and we made FTS_NOCHDIR From 0626461a3c087f570cc67a279775e9fa304417da Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Fri, 22 Nov 2024 16:10:09 -0800 Subject: [PATCH 6/7] fix: compile wasm32-wasip2 target correctly --- test/Makefile | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/Makefile b/test/Makefile index 43046fdc2..01de02061 100644 --- a/test/Makefile +++ b/test/Makefile @@ -110,9 +110,14 @@ $(INFRA_HEADERS): $(DOWNLOADED) # the $(WASMS) tests. ALL_TESTS := $(shell find $(SRCDIR) -name '*.c') TESTS := $(shell TARGET_TRIPLE=$(TARGET_TRIPLE) scripts/filter.py $(ALL_TESTS)) -WASMS := $(TESTS:$(SRCDIR)/%.c=$(OBJDIR)/%.core.wasm) WASM_OBJS := $(TESTS:$(SRCDIR)/%.c=$(OBJDIR)/%.wasm.o) WASM_OBJS += $(INFRA_WASM_OBJS) +ifeq ($(TARGET_TRIPLE), wasm32-wasip2) +WASMS := $(TESTS:$(SRCDIR)/%.c=$(OBJDIR)/%.component.wasm) +else +WASMS := $(TESTS:$(SRCDIR)/%.c=$(OBJDIR)/%.core.wasm) +endif + # Setup the compiler. We allow $(CC) to be set from the command line; ?= doesn't # work for CC because make has a default value for it. @@ -135,7 +140,6 @@ $(OBJDIR)/%.wasm.o: $(SRCDIR)/%.c $(DOWNLOADED) $(SYSROOT) $(CC) $(CFLAGS) $(shell scripts/add-flags.py CFLAGS $<) -c $< -o $@ # Build up all the `*.wasm` files. -#$(WASMS): $(WASM_OBJS) obj_to_c = $(patsubst $(OBJDIR)/%.wasm.o,$(SRCDIR)/%.c,$1) $(OBJDIR)/%.core.wasm: $(OBJDIR)/%.wasm.o $(INFRA_WASM_OBJS) @mkdir -p $(@D) @@ -143,10 +147,8 @@ $(OBJDIR)/%.core.wasm: $(OBJDIR)/%.wasm.o $(INFRA_WASM_OBJS) # For wasip2, we include an additional step to wrap up the core module into # a component. -ifeq ($(TARGET_TRIPLE), wasm32-wasip2) $(OBJDIR)/%.component.wasm: $(OBJDIR)/%.core.wasm $(WASM_TOOLS) component new --adapt $(ADAPTER) $< -o $@ -endif # Compile each selected test using Clang. Note that failures here are likely # due to a missing `libclang_rt.builtins-wasm32.a` in the Clang lib directory. @@ -175,7 +177,7 @@ generate-stubs: ENGINE ?= $(WASMTIME) run ifeq ($(TARGET_TRIPLE), wasm32-wasip2) ENGINE += --wasm component-model -OBJPAT := $(OBJDIR)%.component.wasm +OBJPAT := $(OBJDIR)/%.component.wasm else OBJPAT := $(OBJDIR)/%.core.wasm endif @@ -184,7 +186,7 @@ endif # script and an `output.log` file (see `scripts/run-test.sh` for details). The # `success` file is never generated, which means the test will rerun every time. # To ignore a test temporarily, `touch .../success:`. -RUNTESTS:=$(WASMS:$(OBJDIR)%.core.wasm=$(RUNDIR)%.c/success) +RUNTESTS:=$(WASMS:$(OBJPAT)=$(RUNDIR)/%/success) wasm_to_c = $(patsubst $(OBJPAT),$(SRCDIR)/%.c,$1) $(RUNDIR)/%.c/success: $(OBJPAT) @mkdir -p $(@D) From bcbd60f1c4abda5f2f8169310c7d49d00000cb98 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Fri, 22 Nov 2024 16:10:57 -0800 Subject: [PATCH 7/7] review: drop the .c suffix on test directories --- test/Makefile | 2 +- test/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Makefile b/test/Makefile index 01de02061..bf656782c 100644 --- a/test/Makefile +++ b/test/Makefile @@ -188,7 +188,7 @@ endif # To ignore a test temporarily, `touch .../success:`. RUNTESTS:=$(WASMS:$(OBJPAT)=$(RUNDIR)/%/success) wasm_to_c = $(patsubst $(OBJPAT),$(SRCDIR)/%.c,$1) -$(RUNDIR)/%.c/success: $(OBJPAT) +$(RUNDIR)/%/success: $(OBJPAT) @mkdir -p $(@D) @DIR="$(abspath $(@D))" \ WASM="$(abspath $<)" \ diff --git a/test/README.md b/test/README.md index 45e6d22aa..2ba40e196 100644 --- a/test/README.md +++ b/test/README.md @@ -29,7 +29,7 @@ Note that `wasm-ld` must be available, so an additional looks like (see [`run-test.sh`]): ```sh -$ ls run/$TARGET_TRIPLE/misc/some-test.c +$ ls run/$TARGET_TRIPLE/misc/some-test cmd.sh # the exact command used to run the test fs # a directory containing any test-created files output.log # the captured printed output--only for errors