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.
- Clang
- CMake
Before building/running tests wasi-libc must itself be built. For example
make must be run in the root of the repository.
Next tests must be configured with CMake. This can be done like so from the root
of the wasi-libc repository:
$ cmake -S test -B testbuildThis will by default build test for wasm32-wasi and must match the target
found in the sysroot folder of the repository too.
There are a few configuration options you might want to specify to the cmake
command line as well:
-G Ninja- or some other build system, but this configures the default build system that CMake will generate.-DCMAKE_C_COMPILER=clang- specifies which compiler to use when building tests.-DTARGET_TRIPLE=wasm32-wasip1- specify an alternative target to be tested.-DENGINE=engine- override the default usage of Wasmtime to run test with theenginespecified.
This cmake step will create a folder called testbuild which contains the
build system and will have the intermediate artifacts of the tests as well. If
-G Ninja was passed then the tests can then be built as:
$ ninja -C testbuildThis build step is required as the testing/ctest step below will not build
tests. By building tests ahead of time you're ensuring that the latest copy of
tests are available.
Finally tests can be run with:
$ ninja -C testbuild testThis will run all tests with CMake's ctest executable. You can also directly
run ctest for more control over the output. For example:
$ ctest -j4 --output-on-failure --test-dir testbuildCMake's documentation for CTest documents many other options/configurations as well.
To run a test in the browser, use the scripts/browser-test/harness.mjs as ENGINE. The harness uses bjorn3/browser_wasi_shim as a WASI implementation on browser.
$ npm -C scripts/browser-test install
$ npx -C scripts/browser-test playwright install chromium-headless-shell
$ cmake -S test -B testbuild -DENGINE="$PWD/scripts/browser-test/harness.mjs" -DTARGET_TRIPLE=...To add a test, create a new C file in src:
int main() { ... }To pass, the main function must exit successfully.
Next edit [CMakeLists.txt] and use the add_wasilibc_test helper function toa
dd your test. The documentation of register_test shows some options which can
be passed to configuring how a test is built or what it can access at runtime.
Enabling more libc-test tests
libc-test has more tests available that are not yet enabled. Each enabled test
is listed in CMakeLists.txt and is managed with the add_libc_test helper
function. To enable more tests edit the section and add more tests to be
listed.
The cmake configuration step will print out where libc-test is located:
$ cmake -S test -B testbuild
...
-- libc-test source directory: $PWD/testbuild/_deps/libc-test-src
...
You can explore this direcotry to see what tests are available and have not yet been enabled.