How to run the tests, what the fixtures are, and how to write a test that proves your change. Use it before your first pull request, and whenever a suite skips or fails and you need to know why.

Every test is Common Test, under test/. The suites and the module docs are the authority on behaviour: when a page and a suite disagree, the suite wins.

Run the suites

rebar3 ct                                         # everything
rebar3 ct --suite=test/wasm_spec_SUITE            # one suite
rebar3 ct --suite=test/wasi_SUITE --case=parent_traversal_is_refused

The upstream conformance suites are not vendored. Fetch them once beside the project, at the commits scripts/fetch-suites.sh names; to move to newer ones, change the commits there. A suite that needs one skips when it is absent, so a run without them proves nothing about conformance:

make suites

Find the suites for an area

Where things are has a row for each area of the runtime, with the suites that test it. Suites are named after what they cover, and each opens by saying what that is; the map's last section shows how to search test/ for the suites that call a module.

The suites behind the feature page

These are the suites behind the claims in Features and conformance, and the properties they hold:

SuiteWhat it covers
wasm_spec_SUITEthe official suite, gated per suite against a baseline
wasm_prop_SUITEtotality, atom safety, memory model equivalence, LEB128 round trip
wasm_bench_SUITEthe benchmark tables in test/audit/PERF.md, plus the responsiveness assertion
wasm_worker_SUITElimits actually bound, tested through wasm_instance_worker
wasi_SUITEWASI syscalls, and one case per filesystem escape technique
wasi_nif_SUITEthe native backend, including the symlink-swap race
wasi_net_SUITEthe network grant on its own, with no sockets in it
wasi_sock_SUITEthe four standard socket calls, and readiness
wasi_sock_ext_SUITEthe client extension, layouts built byte by byte
wasi_net_escape_SUITEone case per network escape route
wasm_num_SUITEnumeric edge cases, each naming the rule it enforces
wasm_native_SUITEa clang -O2 module: recursion, memory, indirect calls
wasm_rust_SUITEa real Rust std binary through _start, sandbox included
wasm_lang_SUITEa real 1.8 MB QuickJS build, evaluating JavaScript
wasm_scale_SUITEwhat only breaks at size: big tables, deferred lowering
wasm_examples_SUITEboth worked examples, run as their documentation says

The main properties:

  • Totality. No binary, however hostile, produces anything but {ok, _} or a structured {error, _}. Verified over random binaries and over valid modules mutated at the byte level.
  • No atom creation. Decoding arbitrary input never moves the atom count. The atom table is node-wide and never reclaimed, so one binary_to_atom on module data would let a remote module crash the node.
  • Memory equivalence. Random sequences of store, fill, copy and grow against the atomics backend agree byte for byte with a plain binary model. The same property will validate the optional native backend when it arrives.

Get the fixtures

Most suites build what they run from WAT at test time. The rest read a fixture: a committed file, or one you fetch or build. Fixtures lists every family with its script, the suites that read it and how it is checked. scripts/verify-fixtures.sh checks the language runtimes you have against their recorded hashes.

Know what skips

A suite that cannot find what it needs skips, and a skip is green. Before you read a green run as proof, check the log for skips. These are the suites that need something a fresh clone does not have:

suiteneedswithout it
wasm_spec_SUITEtestsuite/; two cases, which check the encoder's output against another tool, also need wasm-toolsskips; those two cases skip without wasm-tools, as they do on the Tests job
wasm_wast_SUITE, wasm_wat_SUITEtestsuite/ for one case each; two wasm_wat_SUITE cases also need wasm-toolsthose cases skip
wasi_conformance_SUITEwasi-testsuite/skips
wasm_wasi2_testsuite_SUITEwasi-testsuite/ and wasm-toolsskips
wasm_wasi2_adapter_SUITEwasi-testsuite/ and wasm-tools; one case also needs wasmtimeskips
wasm_lang_SUITEtest/fixtures/lang/qjs.wasmskips
wasm_core_SUITE, wasm_annotate_SUITE, wasm_examples_SUITEqjs.wasm for some casesthose cases skip
wasm_module_cache_SUITEqjs.wasm for one casethat case fails
wasm_worker_lang_SUITEqjs.wasm, then qjs_reactor.wasm and lua_reactor.wasm for their groupsskips, or the group skips
wasm_worker_lang_SUITE, the python_* groupspython.wasm or py_reactor.wasm; not in all/0, so run them with --groupnot run
wasm_wasi2_p2_SUITE, wasm_wasi2_serve_SUITE, wasm_wasi2_http_limits_SUITE, wasm_wasi3_p3_SUITE, wasm_wasi2_nn_wasmtime_SUITEwasmtime's programsskips; fails with WASM_REQUIRE_WASMTIME_FIXTURES set
wasm_wasi2_async_SUITEwasmtime's p2_cli_invoke_async programskips, whatever the variables say
wasm_wasi3_p3_SUITE, slow_programsWASM_RUN_SLOW_PROGRAMS=1that case skips
wasm_wasi2_conformance_SUITE, wasm_wasi2_real_SUITE, wasm_component_worker_SUITEwasmtime on the path, for the cases that compare with itthose cases skip
wasm_recipe_SUITEcargo and wasm-tools, for one casethat case skips
wasm_scripts_SUITEmake for the link-line cases, git for the pin casesthat group skips
wasi_nul_path_SUITEthe file NIF built, for the fs_native groupthat group skips
wasi_nif_SUITEthe file NIF builtthe cases about the native backend skip
wasi_durability_SUITEthe file NIF built, for the native run of the six cases that run on each backendthose cases pass on the fallback alone and do not skip; each one's comment in the log says "fallback only"
wasm_docs_SUITEeach block's checker tool and fixturethat block skips; fails under WASM_DOCS_STRICT=1

Set the test environment

These variables change what a suite runs or where it looks. None is needed for a plain rebar3 ct.

variablewhat it doesdefault
WASM_TESTSUITEwhere the specification suite checkout istestsuite/, found by walking up from the working directory
WASI_TESTSUITEwhere the WASI suite checkout iswasi-testsuite/, found the same way
WASM_SPEC_MAX_FAILUREShow many failures wasm_spec_SUITE keeps for each suite; set it to 1000 to see them all25
WASM_REQUIRE_WASMTIME_FIXTURESmakes a missing wasmtime program fail wasm_wasi2_p2_SUITE, wasm_wasi2_serve_SUITE, wasm_wasi2_http_limits_SUITE, wasm_wasi3_p3_SUITE and wasm_wasi2_nn_wasmtime_SUITE instead of skipping; any value but empty or 0unset: they skip
WASM_RUN_SLOW_PROGRAMS1 runs wasm_wasi3_p3_SUITE's slow_programs case, about seven minutesunset: skipped
WASM_DOCS_STRICT1 makes wasm_docs_SUITE fail on a missing checker tool, and run every block whose fixture is declaredunset: those blocks skip
WASM_DOCS_FIXTURESthe fixtures you declare present, by id, comma separated: qjs, python, qjs_reactor, lua_reactor, python_reactornone
WASM_BENCH_FULLadds the one-million sizes to wasm_gc_bench_SUITE's bench groupunset
TMPDIRwhere the WASI 0.2 and 0.3 runners and the test HTTP server put their scratch files/tmp

The build reads a few more. rebar3 ct recompiles, so set them for the test run too:

variablewhat it doesdefault
WASM_NIF_SANITIZEbuilds the NIF under a sanitizer: address or threadunset
WASM_NIF_CFLAGSextra C flags for the NIF, as in CI's check buildnone

The fixture scripts read their own: WASI_SDK, QUICKJS_NG_TAG, LUA_VERSION, CPYTHON_TAG, CPYTHON_XY and WASMTIME_P2_SRC. Each script's header says what it does with them.

Test the documentation

wasm_docs_SUITE reads every fenced block in README.md, the unreleased part of CHANGELOG.md, docs/ and the module docs:

  • every fence names its language, and a block in another language than Erlang is parsed by its own tool when that tool is installed;
  • every Erlang block parses, and every module it names exists;
  • docs/getting-started.md and every page in docs/examples/ run as pasted, in a fresh node, in order.

A block that cannot run as written carries an HTML comment on the line before its fence; the suite's header lists them (<!-- check: parse "reason" -->, <!-- check: needs qjs --> and others). CI runs it strictly, with the fixtures built:

WASM_DOCS_STRICT=1 WASM_DOCS_FIXTURES=qjs,python,qjs_reactor,lua_reactor \
  rebar3 ct --suite=test/wasm_docs_SUITE

wasm_architecture_SUITE checks the maps: the module levels and cycles in Architecture, that every module is named in Where things are, that every function a module doc names exists, and that every module and page is in the ex_doc config.

Write a test that can fail

  1. Write the case before the fix.
  2. Run it against the code without the fix and watch it fail, for the reason you expect.
  3. Then make the change and watch it pass.

Four tests in this repository passed vacuously before anyone noticed; the header of wasm_jit_lifetime_SUITE and test/audit/ATTEMPTS.md say how. Two shapes to avoid:

  • a check over an empty set: [] -- [] is [], so assert the set is not empty first;
  • a threshold loose enough to pass on the broken build.

Ask also what the new assertion forbids: a test that pins today's defect stops someone fixing it.

Use the test support

test/support/ holds what suites share:

  • fake_*_adapter modules, small adapters with one behaviour each, for driving the worker kernel without a real language;
  • wasm_spec_runner and wasm_spec_manifest, the conformance harness;
  • wasm_asm, for building a module from instructions in a test;
  • wasi_p2_runner, wasi_http_server and the WASI test-suite runners.

Run the benchmarks

The measurement suites keep their numbers in a bench group, so a plain rebar3 ct runs only what can fail:

rebar3 bench

Measuring says how to turn a number into a claim.

Read this next

Measuring, if your change claims speed or memory.