Skip to content

Commit 89afca6

Browse files
committed
Skipped tests don't need to record their argv
Removes some duplication and complexity. Also, tighten up validation to ensure we use streams (readable or writable pipes, sockets) in an appropriate way.
1 parent 625f567 commit 89afca6

2 files changed

Lines changed: 35 additions & 70 deletions

File tree

test-runner/wasi_test_runner/test_case.py

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
import json
33
from pathlib import Path
4-
from enum import StrEnum
4+
from enum import Enum, StrEnum, auto
55
from typing import List, NamedTuple, TypeVar, Type, Dict, Any, Set, Tuple
66

77
# Top level configuration keys
@@ -237,13 +237,6 @@ def from_file(cls: Type[T], config_file: str) -> T:
237237
proposals=[],
238238
)
239239

240-
def args_env_dirs(self) -> Tuple[List[str], Dict[str, str], List[Tuple[Path, str]]]:
241-
for op in self.operations:
242-
match op:
243-
case Run(args, env, dirs):
244-
return (args, env, dirs)
245-
return ([], {}, [])
246-
247240
def proposals_as_str(self) -> List[str]:
248241
return [p.value for p in self.proposals]
249242

@@ -381,45 +374,57 @@ def run(self) -> Result:
381374
return self.as_result()
382375

383376

377+
class StreamType(Enum):
378+
READABLE_PIPE = auto()
379+
WRITABLE_PIPE = auto()
380+
SOCKET = auto()
381+
382+
384383
class TestCaseValidator(TestCaseRunnerBase):
385384
_config_path: str
386385
_has_proc: bool
387-
_streams: Set[str]
386+
_streams: Dict[str, StreamType]
388387

389388
def __init__(self, config: Config, config_path: str) -> None:
390389
TestCaseRunnerBase.__init__(self, config)
391390
self._config_path = config_path
392391
self._has_proc = False
393-
self._streams = set()
392+
self._streams = {}
394393

395394
def assert_proc(self, op: Any) -> None:
396-
assert self._has_proc, f"{op}: no process running"
395+
assert self._has_proc, \
396+
f"{self._config_path}: {op}: no process running"
397397

398398
def assert_no_proc(self, op: Any) -> None:
399-
assert not self._has_proc, f"{op}: process still running"
399+
assert not self._has_proc, \
400+
f"{self._config_path}: {op}: process still running"
400401

401-
def assert_stream(self, op: Any, name: str) -> None:
402-
assert name in self._streams, f"{op}: no such stream: {name}"
402+
def assert_stream(self, op: Any, name: str, typ: StreamType) -> None:
403+
assert name in self._streams, \
404+
f"{self._config_path}: {op}: no such stream: {name}"
405+
t = self._streams[name]
406+
assert t == typ, \
407+
f"{self._config_path}: {op}: expected {typ}, but got {t}: {name}"
403408

404-
def assert_no_stream(self, op: Any, name: str) -> None:
405-
assert name not in self._streams, f"{op}: stream exists: {name}"
409+
def add_stream(self, op: Any, name: str, typ: StreamType) -> None:
410+
assert name not in self._streams, \
411+
f"{self._config_path}: {op}: stream exists: {name}"
412+
self._streams[name] = typ
406413

407414
def do_run(self, run: Run) -> None:
408415
self.assert_no_proc(run)
416+
self.add_stream(run, "stdin", StreamType.WRITABLE_PIPE)
417+
self.add_stream(run, "stdout", StreamType.READABLE_PIPE)
418+
self.add_stream(run, "stderr", StreamType.READABLE_PIPE)
409419
self._has_proc = True
410420

411421
def do_write(self, write: Write) -> None:
412422
self.assert_proc(write)
413-
match write.id:
414-
case "stdin": pass
415-
case name: self.assert_stream(write, name)
423+
self.assert_stream(write, write.id, StreamType.WRITABLE_PIPE)
416424

417425
def do_read(self, read: Read) -> None:
418426
self.assert_proc(read)
419-
match read.id:
420-
case "stdout": pass
421-
case "stderr": pass
422-
case name: self.assert_stream(read, name)
427+
self.assert_stream(read, read.id, StreamType.READABLE_PIPE)
423428

424429
def do_wait(self, wait: Wait) -> None:
425430
self.assert_proc(wait)
@@ -428,18 +433,17 @@ def do_wait(self, wait: Wait) -> None:
428433

429434
def do_connect(self, conn: Connect) -> None:
430435
self.assert_proc(conn)
431-
self.assert_no_stream(conn, conn.id)
432436
assert conn.protocol_type == ProtocolType.TCP, \
433-
f"{conn}: {conn.protocol_type} not supported"
434-
self._streams.add(conn.id)
437+
f"{self._config_path}: {conn}: {conn.protocol_type} not supported"
438+
self.add_stream(conn, conn.id, StreamType.SOCKET)
435439

436440
def do_send(self, send: Send) -> None:
437441
self.assert_proc(send)
438-
self.assert_stream(send, send.id)
442+
self.assert_stream(send, send.id, StreamType.SOCKET)
439443

440444
def do_recv(self, recv: Recv) -> None:
441445
self.assert_proc(recv)
442-
self.assert_stream(recv, recv.id)
446+
self.assert_stream(recv, recv.id, StreamType.SOCKET)
443447

444448
def do_cleanup(self, successful: bool) -> None:
445449
if successful:

test-runner/wasi_test_runner/test_suite_runner.py

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -28,40 +28,6 @@ class Manifest(NamedTuple):
2828
wasi_version: WasiVersion
2929

3030

31-
class ArgvExtractor(TestCaseRunnerBase):
32-
_test_path: str
33-
_wasi_version: WasiVersion
34-
_runtime: RuntimeAdapter
35-
_argv: List[str]
36-
37-
def __init__(self, config: Config, test_path: str,
38-
wasi_version: WasiVersion, runtime: RuntimeAdapter) -> None:
39-
TestCaseRunnerBase.__init__(self, config)
40-
self._test_path = test_path
41-
self._wasi_version = wasi_version
42-
self._runtime = runtime
43-
self._argv = []
44-
45-
def do_run(self, run: Run) -> None:
46-
proposals = self.config.proposals_as_str()
47-
self._argv = self._runtime.compute_argv(
48-
self._test_path, run.args, run.env, run.dirs, proposals,
49-
self._wasi_version)
50-
51-
# pylint: disable-msg=multiple-statements
52-
def do_read(self, read: Read) -> None: pass
53-
def do_write(self, write: Write) -> None: pass
54-
def do_wait(self, wait: Wait) -> None: pass
55-
def do_connect(self, conn: Connect) -> None: pass
56-
def do_send(self, send: Send) -> None: pass
57-
def do_recv(self, recv: Recv) -> None: pass
58-
def do_cleanup(self, successful: bool) -> None: pass
59-
60-
def extract(self) -> List[str]:
61-
self.run()
62-
return self._argv
63-
64-
6531
class TestCaseRunner(TestCaseRunnerBase):
6632
# pylint: disable-msg=too-many-instance-attributes
6733
_test_path: str
@@ -250,7 +216,7 @@ def run_tests_from_test_suite(
250216
# useful to make reporters report it.
251217
skip, _ = filt.should_skip(meta, test_name)
252218
if skip:
253-
test_case = _skip_single_test(runtime, meta, test_path)
219+
test_case = _skip_single_test(test_path)
254220
break
255221
else:
256222
test_case = _execute_single_test(runtime, meta, test_path)
@@ -268,16 +234,11 @@ def run_tests_from_test_suite(
268234
)
269235

270236

271-
def _skip_single_test(
272-
runtime: RuntimeAdapter, meta: TestSuiteMeta, test_path: str
273-
) -> TestCase:
237+
def _skip_single_test(test_path: str) -> TestCase:
274238
config = _read_test_config(test_path)
275-
argv = ArgvExtractor(
276-
config, test_path, meta.wasi_version, runtime).extract()
277-
278239
return TestCase(
279240
name=os.path.splitext(os.path.basename(test_path))[0],
280-
argv=argv,
241+
argv=[],
281242
config=config,
282243
result=Result(is_executed=False, failures=[]),
283244
duration_s=0,

0 commit comments

Comments
 (0)