Skip to content

Commit dc7f8d2

Browse files
authored
Convert adapters to Python (#48)
1 parent e5bcece commit dc7f8d2

File tree

9 files changed

+70
-98
lines changed

9 files changed

+70
-98
lines changed

.github/workflows/daily-runtime-validation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
continue-on-error: true
5252
run: |
5353
python3 test-runner/wasi_test_runner.py \
54-
-r ./adapters/${{ matrix.runtime }}.sh \
54+
-r ./adapters/${{ matrix.runtime }}.py \
5555
--json-output-location results.json \
5656
-t tests/assemblyscript/testsuite \
5757
-t tests/c/testsuite

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ python3 -m pip install -r test-runner/requirements.txt
3535
python3 test-runner/wasi_test_runner.py \
3636
-t ./tests/assemblyscript/testsuite/ `# path to folders containing .wasm test files` \
3737
./tests/c/testsuite/ \
38-
-r adapters/wasmtime.sh # path to a runtime adapter
38+
-r adapters/wasmtime.py # path to a runtime adapter
3939
```
4040

4141
Optionally you can specify test cases to skip with the `--exclude-filter` option.
@@ -45,7 +45,7 @@ python3 test-runner/wasi_test_runner.py
4545
-t ./tests/assemblyscript/testsuite/ `# path to folders containing .wasm test files` \
4646
./tests/c/testsuite/ \
4747
--exclude-filter examples/skip.json \
48-
-r adapters/wasmtime.sh # path to a runtime adapter
48+
-r adapters/wasmtime.py # path to a runtime adapter
4949
```
5050

5151
The default executable in the adapter used for test execution can be
@@ -55,7 +55,7 @@ overridden using `TEST_RUNTIME_EXE` variable. This only works with adapters defi
5555
```bash
5656
TEST_RUNTIME_EXE="wasmtime --wasm-features all" python3 test-runner/wasi_test_runner.py \
5757
-t ./tests/assemblyscript/testsuite/ \
58-
-r adapters/wasmtime.sh
58+
-r adapters/wasmtime.py
5959
```
6060

6161
## Contributing

adapters/wasm-micro-runtime.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import argparse
2+
import subprocess
3+
import sys
4+
import os
5+
import shlex
6+
7+
# shlex.split() splits according to shell quoting rules
8+
IWASM = shlex.split(os.getenv("TEST_RUNTIME_EXE", "iwasm"))
9+
10+
parser = argparse.ArgumentParser()
11+
parser.add_argument("--version", action="store_true")
12+
parser.add_argument("--test-file", action="store")
13+
parser.add_argument("--arg", action="append", default=[])
14+
parser.add_argument("--env", action="append", default=[])
15+
parser.add_argument("--dir", action="append", default=[])
16+
17+
args = parser.parse_args()
18+
19+
if args.version:
20+
subprocess.run(IWASM + ["--version"])
21+
sys.exit(0)
22+
23+
TEST_FILE = args.test_file
24+
PROG_ARGS = args.arg
25+
ENV_ARGS = [f"--env={i}" for i in args.env]
26+
DIR_ARGS = [f"--dir={i}" for i in args.dir]
27+
28+
r = subprocess.run(IWASM + ENV_ARGS + DIR_ARGS + [TEST_FILE] + PROG_ARGS)
29+
sys.exit(r.returncode)

adapters/wasm-micro-runtime.sh

Lines changed: 0 additions & 47 deletions
This file was deleted.

adapters/wasmtime.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import argparse
2+
import subprocess
3+
import sys
4+
import os
5+
import shlex
6+
7+
# shlex.split() splits according to shell quoting rules
8+
WASMTIME = shlex.split(os.getenv("TEST_RUNTIME_EXE", "wasmtime"))
9+
10+
parser = argparse.ArgumentParser()
11+
parser.add_argument("--version", action="store_true")
12+
parser.add_argument("--test-file", action="store")
13+
parser.add_argument("--arg", action="append", default=[])
14+
parser.add_argument("--env", action="append", default=[])
15+
parser.add_argument("--dir", action="append", default=[])
16+
17+
args = parser.parse_args()
18+
19+
if args.version:
20+
# ensure no args when version is queried
21+
subprocess.run(WASMTIME[0:1] + ["--version"])
22+
sys.exit(0)
23+
24+
TEST_FILE = args.test_file
25+
PROG_ARGS = args.arg
26+
ENV_ARGS = [j for i in args.env for j in ["--env", i]]
27+
DIR_ARGS = [j for i in args.dir for j in ["--dir", i]]
28+
29+
r = subprocess.run(WASMTIME + ENV_ARGS + DIR_ARGS + [TEST_FILE] + PROG_ARGS)
30+
sys.exit(r.returncode)

adapters/wasmtime.sh

Lines changed: 0 additions & 42 deletions
This file was deleted.

doc/adapters.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The test runner is designed to support different types of WebAssembly runtimes.
44

55
WASI test runner is designed to support as many WASM runtimes as possible, therefore runtime peculiarities aren't hardcoded in the runner.
66

7-
In order to integrate WASM runtime with a test runner, the user has to provide a `runtime adapter`. It's an executable file that takes command-line arguments and translates them to a runtime call.
7+
In order to integrate WASM runtime with a test runner, the user has to provide a `runtime adapter`. It's a *Python script* that takes command-line arguments and translates them to a runtime call. The reason for using a Python script over a generic "she-bang" executable, is to ensure cross-platform compatibility, such an executable is expected to be a python a script.
88

99
## Interface
1010
The adapter executable must accept the following command line parameters and execute actions associated with those parameters:
@@ -37,14 +37,14 @@ and check if the exit code is equal to `13`. There are also two test cases in As
3737
Print runtime version:
3838

3939
```bash
40-
$ ./adapter.sh --version
40+
$ ./adapter.py --version
4141
wasmtime-cli 1.0.1
4242
```
4343

4444
Run WASM module:
4545

4646
```bash
47-
$ ./adapter.sh --arg a1 --arg a2 --env E1=env1 --env E2=env2 --test-file test.wasm
47+
$ ./adapter.py --arg a1 --arg a2 --env E1=env1 --env E2=env2 --test-file test.wasm
4848
# Expected to start test.wasm module with E1=env1 and E2=env2
4949
# environment variables defined and arguments a1, a2 passed to
5050
# the module.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
colorama==0.4.3
1+
colorama>=0.4.3

test-runner/wasi_test_runner/runtime_adapter.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import subprocess
2+
import sys
23
from pathlib import Path
34
from typing import Dict, NamedTuple, List
45

@@ -16,7 +17,7 @@ def __init__(self, adapter_path: str) -> None:
1617

1718
def get_version(self) -> RuntimeVersion:
1819
output = (
19-
subprocess.check_output([self._adapter_path, "--version"], encoding="UTF-8")
20+
subprocess.check_output([sys.executable, self._adapter_path, "--version"], encoding="UTF-8")
2021
.strip()
2122
.split(" ")
2223
)
@@ -31,6 +32,7 @@ def run_test(
3132
) -> Output:
3233
args = (
3334
[
35+
sys.executable,
3436
self._adapter_path,
3537
"--test-file",
3638
self._abs(test_path),

0 commit comments

Comments
 (0)