Skip to content
Open
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
13 changes: 7 additions & 6 deletions scripts/run_wine_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import time

ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# subprocess uses poll on Linux, whose timeout is a signed int in milliseconds.
MAX_TIMEOUT_SECONDS = (2**31 - 1) // 1_000


def _make_parent(path: str) -> None:
Expand Down Expand Up @@ -395,15 +397,13 @@ def stop_running_tests() -> None:


def positive_seconds(text: str) -> float:
"""--timeout: a finite value greater than 0, so subprocess.run never gets a bad timeout to raise on."""
"""Parse a positive timeout that fits the subprocess wait on all supported hosts."""
try:
value = float(text)
except ValueError:
raise argparse.ArgumentTypeError(f"invalid float value: {text!r}") from None
if not math.isfinite(value):
raise argparse.ArgumentTypeError("must be a finite number")
if value <= 0:
raise argparse.ArgumentTypeError("must be greater than 0")
if not 0 < value <= MAX_TIMEOUT_SECONDS:
raise argparse.ArgumentTypeError(f"must be positive and no greater than {MAX_TIMEOUT_SECONDS} seconds")
return value


Expand Down Expand Up @@ -517,7 +517,8 @@ def main() -> int:
help="Wine command (default: $WINE or wine)")
ap.add_argument("--require", action="append", default=[], help="a test that must pass (repeatable)")
ap.add_argument("--timeout", type=positive_seconds, default=120.0,
help="maximum seconds per test; a shorter CTest TIMEOUT applies (default 120)")
help=f"maximum seconds per test (default 120, upper limit {MAX_TIMEOUT_SECONDS}). "
"A shorter CTest TIMEOUT applies.")
ap.add_argument("--jobs", type=positive_int, default=1,
help="tests run at a time; RUN_SERIAL and RESOURCE_LOCK are kept (default 1)")
ap.add_argument("--summary", help="append a Markdown table to this file (e.g. $GITHUB_STEP_SUMMARY)")
Expand Down
15 changes: 15 additions & 0 deletions tests/test_run_wine_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,21 @@ def test_a_nonfinite_timeout_is_a_usage_error(self):
self.run_main([ctest_entry("ok", self.command("ok.py"))], "--timeout", text)
self.assertEqual(ctx.exception.code, 2)

def test_timeout_over_process_limit_is_rejected_before_launch(self):
entries = [ctest_entry("ok", self.command("ok.py"))]
with mock.patch.object(rwt, "run_test_process", side_effect=AssertionError("test was launched")):
for text in ("2147484", "1e100"):
with self.subTest(text=text):
with self.assertRaises(SystemExit) as ctx:
self.run_main(entries, "--timeout", text)
self.assertEqual(ctx.exception.code, 2)

def test_largest_portable_timeout_runs_a_test(self):
entries = [ctest_entry("ok", self.command("ok.py"))]
code, out, _ = self.run_main(entries, "--timeout", "2147483", "--require", "ok")
self.assertEqual(code, 0, out)
self.assertIn("[PASS] ok", out)

def test_a_blank_wine_is_a_usage_error(self):
with self.assertRaises(SystemExit) as ctx:
self.run_main([ctest_entry("ok", self.command("ok.py"))], "--wine", "")
Expand Down
Loading