Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: document how a test executor works #74

Merged
merged 8 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 43 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,53 @@
# WASI tests
# `wasi-testsuite`

This repository contains tests for WebAssembly System Interface (WASI) and a test executor for running WASI tests on a selected WebAssembly runtime.
This repository contains tests for WebAssembly System Interface (WASI) and a test executor for running WASI tests against a selected WebAssembly runtime.

WASI is a modular collection of standardized APIs. Currently, WASI has not reached a v1 with a defined set of APIs.
However, a snapshot of experimental APIs exists ([`wasi_snapshot_preview1`](https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md)).
The repository only holds tests of APIs included in this snapshot. It does not include tests for other in-progress proposals or other experimental APIs.
WASI is a modular collection of standardized APIs. Currently, WASI has not reached version 1.0
stability but a snapshot of experimental APIs does exist ([`wasi_snapshot_preview1`]). This
repository only holds tests of APIs included in this snapshot. It does not include tests for other
in-progress proposals or other experimental APIs, though the test executor can run tests from other repositories (e.g., see the [wasi-threads] tests).

The test executor included in the repository can however be used to run tests defined for proposals along with tests defined in this repository.
[`wasi_snapshot_preview1`]: https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md
[wasi-threads]: https://github.com/WebAssembly/wasi-threads/tree/main/test

## Getting started
The test executor matches execution output against a JSON specification. Writing your own test
executor is quite simple; see the [specification] document for the details.
abrown marked this conversation as resolved.
Show resolved Hide resolved

1. Clone repository
Use `prod/testsuite-base` branch as it already includes precompiled test binaries (see [Branch structure](#branch-structure) paragraph).
[specification]: doc/specification.md

```bash
git clone --branch prod/testsuite-base [email protected]:WebAssembly/wasi-testsuite.git
```
## Getting started

1. Clone the repository; use the `prod/testsuite-base` branch as it already includes precompiled
test binaries (see [branch structure](#branch-structure)):

2. Make sure there's already an adapter for the runtime in the [`adapters`](adapters) directory; if not, create one (see [the doc](doc/adapters.md) for details).
3. Install python3
1. Ubuntu
```bash
git clone --branch prod/testsuite-base [email protected]:WebAssembly/wasi-testsuite.git
abrown marked this conversation as resolved.
Show resolved Hide resolved
```
$ sudo apt install python3 python3-pip

2. Make sure there is already an adapter for the runtime in the [`adapters`](adapters) directory; if
not, create one (see [the doc](doc/adapters.md) for details).

3. Install `python3` (e.g., on Ubuntu):

```bash
sudo apt install python3 python3-pip
```
4. Install test runner dependencies:

```bash
python3 -m pip install -r test-runner/requirements.txt
```
4. Install the test runner dependencies:

5. Execute test suites from this repository
```bash
python3 -m pip install -r test-runner/requirements.txt
```

```bash
python3 test-runner/wasi_test_runner.py \
-t ./tests/assemblyscript/testsuite/ `# path to folders containing .wasm test files` \
./tests/c/testsuite/ \
./tests/rust/testsuite/ \
-r adapters/wasmtime.py # path to a runtime adapter
```
5. Execute the test suites from this repository:

```bash
python3 test-runner/wasi_test_runner.py \
-t ./tests/assemblyscript/testsuite/ `# path to folders containing .wasm test files` \
./tests/c/testsuite/ \
./tests/rust/testsuite/ \
-r adapters/wasmtime.py # path to a runtime adapter
```

Optionally you can specify test cases to skip with the `--exclude-filter` option.

Expand Down Expand Up @@ -83,7 +93,11 @@ Here is some additional information for developers who are willing to contribute

### Cleaning up temporary resources

Some of the tests (e.g. [pwrite-with-access](./tests/c/testsuite/pwrite-with-access.c)) generate output artifacts and their existence can affect consecutive test executions. Tests should clean up the artifacts they generate, but there might be cases where the test fails early. Test runner will automatically delete all the files and directories in the test suite directory with the `.cleanup` suffix.
Some of the tests (e.g. [pwrite-with-access](./tests/c/testsuite/pwrite-with-access.c)) generate
output artifacts and their existence can affect consecutive test executions. Tests should clean up
the artifacts they generate, but there might be cases where the test fails early. The test runner
will automatically delete all the files and directories in the test suite directory with the
`.cleanup` suffix.

### Programming languages for tests

Expand All @@ -95,8 +109,6 @@ The repository currently consists of tests implemented in the following language

The list of supported languages can be extended if needed.

### Test

### Branch structure

Apart from development branches for various features, we identify the following branches as critical (i.e. they won't be removed or force-updated):
Expand Down
52 changes: 52 additions & 0 deletions doc/specification.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Test Specification

This document describes how to use the JSON test specifications to write your own test executor for
[`wasi-testsuite`](..). The test executor included in this project provides a completely-usable
reference implementation, but projects with other requirements may want to run the tests in their
abrown marked this conversation as resolved.
Show resolved Hide resolved
own way (e.g., no Python dependency). The JSON test specifications provide a simple way to verify
that the tests indeed passed.

### Configuration

Before executing anything, a test executor is expected to:
- find all `*.wasm` and `*.wat` files in a given subdirectory — these are the _test cases_
abrown marked this conversation as resolved.
Show resolved Hide resolved
- for each test case, look for a `.json` file in the same directory matching the base name (e.g.,
`foo.json` for `foo.wasm`) — parse this _specification_
- if no `.json` file is present, use a default specification; a (conceptual) default specification
would look like:

```json
{
"args": [],
"dirs": [],
"env": {},
"exit_code": 0,
"stderr": "",
"stdout": ""
}
```

- if the specification is missing fields, use default values
abrown marked this conversation as resolved.
Show resolved Hide resolved

### Execution

To execute the tests, the test executor is expected to:
- `env`: construct an environment from each key-value pair in `env`; the environment should only
contain these keys and otherwise should be empty (note that this environment is the WASI
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this something from the wasi spec?
note that some of runtimes have some environment variables set by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think one of the tests sets three keys and then checks that the environment has exactly three keys, so I don't know what those other runtimes will do. The implication of that test seems to be that the environment is empty otherwise.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess the test should be relaxed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(out of curiosity) what are the runtimes that already add additional variables? Do they also provide a mechanism to remove those variables?

If WASI spec doesn't define that the environment should be empty, than I agree we need to update the test and the documentation. I've created an issue to not forget about it: #77

environment, whether the engine inherits the shell environment or explicitly configures it via
`--env` parameters)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the --env option is runtime-specific i guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the parenthetical is giving an example.

- `dir`: add each path listed in `dir` as WASI preopen directories (some engines use a `--dir`
flag)
- `args`: pass each argument in order to the WASI program (most CLI engines allow appending these
after the module path)

The test executor runs the WebAssembly test case with the above context and records its results.

### Checking

With the execution results in hand, the test executor is expected to:
- `exit_code`: check that the WASI exit code matches `exit_code`, or `0` if none was provided
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right now we don't distinguish wasi exit code and other errors.
cf. #39

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is a different issue. What I noticed running the wasi-threads tests was that they failed if the exit code did not line up with the JSON specification, which is what I'm documenting here. Unfortunately, there are some problems with this but the issue to reference for that is WebAssembly/wasi-cli#11.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is a different issue. What I noticed running the wasi-threads tests was that they failed if the exit code did not line up with the JSON specification, which is what I'm documenting here. Unfortunately, there are some problems with this but the issue to reference for that is WebAssembly/wasi-cli#11.

how is it a different issue?

Copy link
Collaborator

@loganek loganek May 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest continuing the discussion in #39, I think the documentation here describes the existing behavior.

- `stderr`: if a `stderr` field is provided, check that the bytes printed to `stderr` match it
- `stdout`: if a `stdout` field is provided, check that the bytes printed to `stdout` match it

A test case _passes_ if all of the checks are true.