Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 9 additions & 10 deletions adapters/jco.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import shlex
import subprocess
from pathlib import Path
from typing import Dict, List, Tuple
from typing import Dict, List, Tuple, Optional


# shlex.split() splits according to shell quoting rules.
Expand Down Expand Up @@ -37,18 +37,17 @@ def get_timeout_seconds() -> float:


def compute_argv(test_path: str,
args_env_dirs: Tuple[List[str], Dict[str, str], List[Tuple[Path, str]]],
args_env_root: Tuple[List[str], Dict[str, str], Optional[str]],
proposals: List[str],
wasi_world: str,
wasi_version: str) -> List[str]:
args, env, dirs = args_env_dirs
preopens = [
{
"guest": guest,
"host": str(host),
}
for host, guest in dirs
]
args, env, root = args_env_root
preopens = []
if root:
preopens.append({
"guest": "/",
"host": str(root),
})

return JCO + [
"--component", test_path,
Expand Down
10 changes: 5 additions & 5 deletions adapters/pywasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import shlex
import sys
from pathlib import Path
from typing import Dict, List, Tuple
from typing import Dict, List, Tuple, Optional
import importlib


Expand Down Expand Up @@ -33,20 +33,20 @@ def get_wasi_worlds() -> List[str]:


def compute_argv(test_path: str,
args_env_dirs: Tuple[List[str], Dict[str, str], List[Tuple[Path, str]]],
args_env_root: Tuple[List[str], Dict[str, str], Optional[str]],
proposals: List[str],
wasi_world: str,
wasi_version: str) -> List[str]:

argv = []
argv += [str(RUN_PYWASM)]
args, env, dirs = args_env_dirs
args, env, root = args_env_root

for k, v in env.items():
argv += ["--env", f"{k}={v}"]

for host, guest in dirs:
argv += ["--dir", f"{host}::{guest}"] # noqa: E231
if root:
argv += ["--dir", f"{root}::/"] # noqa: E231

argv += [test_path]

Expand Down
10 changes: 5 additions & 5 deletions adapters/wasm-micro-runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import shlex
import sys
from pathlib import Path
from typing import Dict, List, Tuple
from typing import Dict, List, Tuple, Optional
import importlib


Expand Down Expand Up @@ -34,20 +34,20 @@ def get_wasi_worlds() -> List[str]:


def compute_argv(test_path: str,
args_env_dirs: Tuple[List[str], Dict[str, str], List[Tuple[Path, str]]],
args_env_root: Tuple[List[str], Dict[str, str], Optional[str]],
proposals: List[str],
wasi_world: str,
wasi_version: str) -> List[str]:

argv = []
argv += IWASM
args, env, dirs = args_env_dirs
args, env, root = args_env_root

for k, v in env.items():
argv += ["--env", f"{k}={v}"]

for host, guest in dirs:
argv += [f"--map-dir={guest}::{host}"] # noqa: E231
if root:
argv += [f"--map-dir=/::{root}"] # noqa: E231

argv += [test_path]

Expand Down
8 changes: 4 additions & 4 deletions adapters/wasmedge.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ def get_wasi_worlds() -> List[str]:


def compute_argv(test_path: str,
args_env_dirs: Tuple[List[str], Dict[str, str], List[Tuple[Path, str]]],
args_env_root: Tuple[List[str], Dict[str, str], List[Tuple[Path, str]]],
proposals: List[str],
wasi_world: str,
wasi_version: str) -> List[str]:

argv = []
argv += WASMEDGE
args, env, dirs = args_env_dirs
args, env, root = args_env_root

for k, v in env.items():
argv += ["--env", f"{k}={v}"]

for host, guest in dirs:
argv += ["--dir", f"{guest}:{host}"]
if root:
argv += ["--dir", f"/:{root}"]

argv += [test_path]

Expand Down
10 changes: 5 additions & 5 deletions adapters/wasmtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import shlex
import subprocess
from pathlib import Path
from typing import Dict, List, Tuple
from typing import Dict, List, Tuple, Optional

# shlex.split() splits according to shell quoting rules
WASMTIME = shlex.split(os.getenv("WASMTIME", "wasmtime"), posix=os.name != "nt")
Expand Down Expand Up @@ -30,20 +30,20 @@ def get_wasi_worlds() -> List[str]:


def compute_argv(test_path: str,
args_env_dirs: Tuple[List[str], Dict[str, str], List[Tuple[Path, str]]],
args_env_root: Tuple[List[str], Dict[str, str], Optional[str]],
proposals: List[str],
wasi_world: str,
wasi_version: str) -> List[str]:

argv = []
argv += WASMTIME
args, env, dirs = args_env_dirs
args, env, root = args_env_root

for k, v in env.items():
argv += ["--env", f"{k}={v}"]

for host, guest in dirs:
argv += ["--dir", f"{host}::{guest}"] # noqa: E231
if root:
argv += ["--dir", f"{root}::/"] # noqa: E231

argv += [test_path]

Expand Down
10 changes: 5 additions & 5 deletions adapters/wazero.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import shlex
import sys
from pathlib import Path
from typing import Dict, List, Tuple
from typing import Dict, List, Tuple, Optional
import importlib


Expand Down Expand Up @@ -36,21 +36,21 @@ def get_wasi_worlds() -> List[str]:


def compute_argv(test_path: str,
args_env_dirs: Tuple[List[str], Dict[str, str], List[Tuple[Path, str]]],
args_env_root: Tuple[List[str], Dict[str, str], Optional[str]],
proposals: List[str],
wasi_world: str,
wasi_version: str) -> List[str]:

argv = []
argv += WAZERO
argv += ["run", "-hostlogging=filesystem"]
args, env, dirs = args_env_dirs
args, env, root = args_env_root

for k, v in env.items():
argv += [f"-env={k}={v}"]

for host, guest in dirs:
argv += [f"-mount={host}:{guest}"]
if root:
argv += [f"-mount={root}:/"]

argv += [test_path]

Expand Down
10 changes: 5 additions & 5 deletions adapters/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import shlex
import sys
from pathlib import Path
from typing import Dict, List, Tuple
from typing import Dict, List, Tuple, Optional
import importlib


Expand Down Expand Up @@ -41,21 +41,21 @@ def get_wasi_worlds() -> List[str]:


def compute_argv(test_path: str,
args_env_dirs: Tuple[List[str], Dict[str, str], List[Tuple[Path, str]]],
args_env_root: Tuple[List[str], Dict[str, str], Optional[str]],
proposals: List[str],
wasi_world: str,
wasi_version: str) -> List[str]:

argv = []
argv += WIZARD
args, env, dirs = args_env_dirs
args, env, root = args_env_root

for k, v in env.items():
argv += [f"--env={k}={v}"]

for host, guest in dirs:
if root:
# FIXME: https://github.com/titzer/wizard-engine/issues/482
argv += [f"--dir={host}"]
argv += [f"--dir={root}"]

argv += [test_path]

Expand Down
11 changes: 6 additions & 5 deletions doc/specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ These are the default values for the legacy configuration specification:
```json
{
"args": [],
"dirs": [],
"root": null,
"env": {},
"exit_code": 0,
"stderr": "",
Expand Down Expand Up @@ -70,15 +70,16 @@ Defines how to start the execution of the test case.
**Fields:**
- `args` (optional): List of command-line arguments to pass to the WASI program
- `env` (optional): Dictionary of environment variables (key-value pairs)
- `dirs` (optional): List of directory paths to preopen
- `root` (optional): Path, relative to the test's directory, of a directory to
preopen as the WASI guest's root filesystem (`/`)

**Default values:**
```json
{
"type": "run",
"args": [],
"env": {},
"dirs": []
"root": null
}
```

Expand Down Expand Up @@ -212,8 +213,8 @@ To execute the tests, the test executor is expected to:
contain these keys and otherwise should be empty (note that this environment is the WASI
environment, whether the engine inherits the shell environment or explicitly configures it via
`--env` parameters)
- `dir`: add each path listed in `dir` as WASI preopen directories (some engines use a `--dir`
flag)
- `root`: if set, preopen this directory as the WASI guest's root filesystem (`/`); some engines
use a `--dir host::/` flag for this
- `args`: pass each argument in order to the WASI program (most CLI engines allow appending these
after the module path)
- `proposals`: pass the right flags to enable each WASI proposal.
Expand Down
14 changes: 7 additions & 7 deletions doc/writing-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ regarding `stat`, for WASIp3, in Rust. Well then you need to add your
and it will be automatically built. (How? We'll come back to that.)

What does your test need? If you are testing `stat`, probably you need
a file, so the WASI module is going to need to start with a preopened
directory. Make the directory, say call it `stat-working-dir`, as a
a file, so the WASI module is going to need to start with a root
filesystem. Make the directory, say call it `stat-working-dir`, as a
subfolder of the directory your test is in. Then create a
`filesystem-stat-subtlety.json` in the test directory:

Expand All @@ -45,19 +45,19 @@ subfolder of the directory your test is in. Then create a
"operations": [
{
"type": "run",
"dirs": ["stat-working-dir"]
"root": "stat-working-dir"
}
]
}
```

A `dirs` declaration in the `run` operation of a test's JSON file adds
a dir to the preopens.
A `root` declaration in the `run` operation of a test's JSON file
preopens that directory as the WASI guest's root filesystem (`/`).

If you need to create a file, name it something that ends with
`.cleanup`, if possible, and ideally have the test case remove it at the
end. But just in case, the test runner will delete files in a test's
`dirs` with names like that, both before and after running the test.
end. But just in case, the test runner will delete files under a test's
`root` with names like that, both before and after running the test.


## Building tests
Expand Down
8 changes: 8 additions & 0 deletions expectations/wamr/linux.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ action = "skip"
[[suite.test]]
name = "environ_sizes_get-multiple-variables"
action = "skip"

[[suite]]
name = "WASI Rust tests [wasm32-wasip1]"

# WAMR differs for this Preview 1 Rust test
[[suite.test]]
name = "symlink_create"
action = "skip"
12 changes: 5 additions & 7 deletions test-runner/tests/test_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_test_config_should_load_defaults_for_empty_json(_mock_file: Mock) -> No
run = config.operations[0]
assert isinstance(run, Run)
assert run.args == []
assert run.dirs == []
assert run.root is None
assert run.env == {}

wait = config.operations[1]
Expand All @@ -41,7 +41,7 @@ def test_test_config_should_load_values_from_json(_mock_file: Mock) -> None:
run = config.operations[0]
assert isinstance(run, Run)
assert run.args == ["a", "b"]
assert run.dirs == []
assert run.root is None
assert run.env == {}

wait = config.operations[1]
Expand Down Expand Up @@ -89,22 +89,20 @@ def test_run_from_config_with_defaults() -> None:

assert run.args == []
assert run.env == {}
assert run.dirs == []
assert run.root is None


def test_run_from_config_with_values() -> None:
config = {
"args": ["arg1", "arg2"],
"env": {"KEY": "value"},
"dirs": [".", "subdir"]
"root": "workdir"
}
run = Run.from_config(Path("/test/path"), config)

assert run.args == ["arg1", "arg2"]
assert run.env == {"KEY": "value"}
assert len(run.dirs) == 2
assert all(isinstance(d, tuple) and len(d) == 2 for d in run.dirs)
assert all(isinstance(d[0], Path) and isinstance(d[1], str) for d in run.dirs)
assert run.root == Path("/test/workdir")


def test_wait_from_config_with_defaults() -> None:
Expand Down
6 changes: 3 additions & 3 deletions test-runner/tests/test_test_suite_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def get_mock_open() -> Mock:
def open_mock(filename: str, *_args: Any, **_kwargs: Any) -> Any:
file_content = {
"my-path/manifest.json": '{"name": "test-suite"}',
"my-path/test1.json": '{"dirs": [".", "deep/dir"]}',
"my-path/test1.json": '{"root": "deep/dir"}',
"my-path/test2.json": '{"exit_code": 1, "args": ["a", "b"]}',
"my-path/test3.json": '{"stdout": "output", "env": {"x": "1"}}',
"my-path/test4.json": (
Expand Down Expand Up @@ -48,7 +48,7 @@ def test_runner_end_to_end() -> None:
test_files = ["test1.wasm", "test2.wasm", "test3.wasm", "test4.wasm"]
test_paths = [Path(test_suite_dir) / f for f in test_files]

test_dirs = [".", "deep/dir"]
test_root = "deep/dir"
runtime_name = "rt1"

expected_argv = [runtime_name, "<test>"]
Expand All @@ -61,7 +61,7 @@ def test_runner_end_to_end() -> None:
expected_config = [
tc.Config(
operations=[
tc.Run(dirs=[(Path(test_suite_dir) / d, d) for d in test_dirs]),
tc.Run(root=Path(test_suite_dir) / test_root),
tc.Wait(exit_code=0)
],
proposals=[],
Expand Down
Loading
Loading