Skip to content

Commit 8ad7197

Browse files
yamtloganek
authored andcommitted
Implement a simple test filter
cf. #29
1 parent 81576bb commit 8ad7197

File tree

9 files changed

+98
-5
lines changed

9 files changed

+98
-5
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ python3 test-runner/wasi_test_runner.py
3838
-r adapters/wasmtime.sh # path to a runtime adapter
3939
```
4040

41+
Optionally you can specify test cases to skip with the `--filter` option.
42+
43+
```bash
44+
python3 test-runner/wasi_test_runner.py \
45+
-t ./tests/assemblyscript/testsuite/ `# path to folders containing .wasm test files` \
46+
./tests/c/testsuite/ \
47+
--filter examples/skip.json \
48+
-r adapters/wasmtime.sh # path to a runtime adapter
49+
```
50+
4151
## Contributing
4252

4353
All contributions are very welcome. Contributors can help with:

examples/skip.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"WASI C tests": {
3+
"stat-dev-ino": "d_ino is known broken in this combination of engine and wasi-sdk version."
4+
}
5+
}

test-runner/.pylintrc

+1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ disable=
33
C0114, # Missing module docstring
44
C0115, # Missing class docstring
55
C0116, # Missing function or method docstring
6+
R0903, # Too few public methods
67
[FORMAT]
78
max-line-length=120

test-runner/tests/test_test_suite_runner.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,12 @@ def test_runner_end_to_end() -> None:
6262

6363
reporters = [Mock(), Mock()]
6464

65+
filt = Mock()
66+
filt.should_skip.return_value = (False, None)
67+
filters = [filt]
68+
6569
with patch("glob.glob", return_value=test_paths):
66-
suite = tsr.run_tests_from_test_suite("my-path", runtime, validators, reporters) # type: ignore
70+
suite = tsr.run_tests_from_test_suite("my-path", runtime, validators, reporters, filters) # type: ignore
6771

6872
# Assert manifest was read correctly
6973
assert suite.name == "test-suite"
@@ -91,9 +95,15 @@ def test_runner_end_to_end() -> None:
9195
for config, output in zip(expected_config, outputs):
9296
validator.assert_any_call(config, output)
9397

98+
# Assert filter calls
99+
for filt in filters:
100+
assert filt.should_skip.call_count == 3
101+
for test_case in expected_test_cases:
102+
filt.should_skip.assert_any_call(suite.name, test_case.name)
103+
94104

95105
@patch("os.path.exists", Mock(return_value=False))
96106
def test_runner_should_use_path_for_name_if_manifest_does_not_exist() -> None:
97-
suite = tsr.run_tests_from_test_suite("my-path", Mock(), [], [])
107+
suite = tsr.run_tests_from_test_suite("my-path", Mock(), [], [], [])
98108

99109
assert suite.name == "my-path"

test-runner/wasi_test_runner/__main__.py

+15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
from .runtime_adapter import RuntimeAdapter
77
from .harness import run_all_tests
8+
from .filters import TestFilter
9+
from .filters import JSONTestFilter
810
from .reporters import TestReporter
911
from .reporters.console import ConsoleTestReporter
1012
from .reporters.json import JSONTestReporter
@@ -23,6 +25,14 @@ def main() -> int:
2325
nargs="+",
2426
help="Locations of suites (directories with *.wasm test files).",
2527
)
28+
parser.add_argument(
29+
"-f",
30+
"--filter",
31+
required=False,
32+
nargs="+",
33+
default=[],
34+
help="Locations of test filters (JSON files).",
35+
)
2636
parser.add_argument(
2737
"-r", "--runtime-adapter", required=True, help="Path to a runtime adapter."
2838
)
@@ -45,11 +55,16 @@ def main() -> int:
4555

4656
validators: List[Validator] = [exit_code_validator, stdout_validator]
4757

58+
filters: List[TestFilter] = []
59+
for filt in options.filter:
60+
filters.append(JSONTestFilter(filt))
61+
4862
return run_all_tests(
4963
RuntimeAdapter(options.runtime_adapter),
5064
options.test_suite,
5165
validators,
5266
reporters,
67+
filters,
5368
)
5469

5570

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from typing import Tuple, Any
2+
from abc import ABC
3+
from abc import abstractmethod
4+
5+
import json
6+
7+
8+
class TestFilter(ABC):
9+
@abstractmethod
10+
def should_skip(self, test_suite_name: str, test_name: str) -> Tuple[bool, Any]:
11+
pass
12+
13+
14+
class JSONTestFilter(TestFilter):
15+
def __init__(self, filename: str) -> None:
16+
with open(filename, encoding="utf-8") as file:
17+
self.filter_dict = json.load(file)
18+
19+
def should_skip(self, test_suite_name: str, test_name: str) -> Tuple[bool, Any]:
20+
test_suite_filter = self.filter_dict.get(test_suite_name)
21+
if test_suite_filter is None:
22+
return False, None
23+
why = test_suite_filter.get(test_name)
24+
return why is not None, why

test-runner/wasi_test_runner/harness.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import List
22

3+
from .filters import TestFilter
34
from .reporters import TestReporter
45
from .test_suite_runner import run_tests_from_test_suite
56
from .runtime_adapter import RuntimeAdapter
@@ -11,12 +12,13 @@ def run_all_tests(
1112
test_suite_paths: List[str],
1213
validators: List[Validator],
1314
reporters: List[TestReporter],
15+
filters: List[TestFilter],
1416
) -> int:
1517
ret = 0
1618

1719
for test_suite_path in test_suite_paths:
1820
test_suite = run_tests_from_test_suite(
19-
test_suite_path, runtime, validators, reporters
21+
test_suite_path, runtime, validators, reporters, filters,
2022
)
2123
for reporter in reporters:
2224
reporter.report_test_suite(test_suite)

test-runner/wasi_test_runner/reporters/console.py

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def finalize(self, version: RuntimeVersion) -> None:
5454
print(f" Total: {suite.test_count}")
5555
self._print_pass(f" Passed: {suite.pass_count}")
5656
self._print_fail(f" Failed: {suite.fail_count}")
57+
self._print_skip(f" Skipped: {suite.skip_count}")
5758
print("")
5859

5960
print(

test-runner/wasi_test_runner/test_suite_runner.py

+27-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from datetime import datetime
99
from typing import List, cast
1010

11+
from .filters import TestFilter
1112
from .runtime_adapter import RuntimeAdapter
1213
from .test_case import (
1314
Result,
@@ -25,28 +26,52 @@ def run_tests_from_test_suite(
2526
runtime: RuntimeAdapter,
2627
validators: List[Validator],
2728
reporters: List[TestReporter],
29+
filters: List[TestFilter],
2830
) -> TestSuite:
2931
test_cases: List[TestCase] = []
3032
test_start = datetime.now()
3133

3234
_cleanup_test_output(test_suite_path)
3335

36+
test_suite_name = _read_manifest(test_suite_path)
37+
3438
for test_path in glob.glob(os.path.join(test_suite_path, "*.wasm")):
35-
test_case = _execute_single_test(runtime, validators, test_path)
39+
test_name = os.path.splitext(os.path.basename(test_path))[0]
40+
for filt in filters:
41+
# for now, just drop the skip reason string. it might be
42+
# useful to make reporters report it.
43+
skip, _ = filt.should_skip(test_suite_name, test_name)
44+
if skip:
45+
test_case = _skip_single_test(runtime, validators, test_path)
46+
break
47+
else:
48+
test_case = _execute_single_test(runtime, validators, test_path)
3649
test_cases.append(test_case)
3750
for reporter in reporters:
3851
reporter.report_test(test_case)
3952

4053
elapsed = (datetime.now() - test_start).total_seconds()
4154

4255
return TestSuite(
43-
name=_read_manifest(test_suite_path),
56+
name=test_suite_name,
4457
time=test_start,
4558
duration_s=elapsed,
4659
test_cases=test_cases,
4760
)
4861

4962

63+
def _skip_single_test(
64+
_runtime: RuntimeAdapter, _validators: List[Validator], test_path: str
65+
) -> TestCase:
66+
config = _read_test_config(test_path)
67+
return TestCase(
68+
name=os.path.splitext(os.path.basename(test_path))[0],
69+
config=config,
70+
result=Result(output=Output(0, "", ""), is_executed=False, failures=[]),
71+
duration_s=0,
72+
)
73+
74+
5075
def _execute_single_test(
5176
runtime: RuntimeAdapter, validators: List[Validator], test_path: str
5277
) -> TestCase:

0 commit comments

Comments
 (0)