-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathtest.py
executable file
·101 lines (75 loc) · 2.78 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python3
# SPDX-FileCopyrightText: Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES.
# All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations
import os
import sys
from pathlib import Path
try:
# imported for effect
import legate # noqa: F401
except ModuleNotFoundError:
from scripts.get_legate_dir import get_legate_dir
sys.path.insert(0, str(Path(get_legate_dir()) / "src" / "python"))
from legate.tester.args import parser
from legate.tester.config import Config
from legate.tester.project import Project
from legate.tester.test_plan import TestPlan
from legate.tester.test_system import TestSystem
def _find_tests(prefix: Path) -> tuple[Path, list[Path]] | None:
tests_dir = prefix / "cpp" / "tests"
tests_bin = [
tests_dir / "bin" / "tests_with_runtime",
tests_dir / "bin" / "tests_wo_runtime",
tests_dir / "bin" / "tests_non_reentrant_with_runtime",
tests_dir / "bin" / "tests_non_reentrant_wo_runtime",
]
if all(p.exists() for p in tests_bin):
return tests_dir, tests_bin
return None
def _find_latest_cpp_test_dir() -> tuple[Path, list[Path]] | tuple[None, None]:
if not (LEGATE_ARCH := os.environ.get("LEGATE_ARCH", "").strip()):
try:
from scripts.get_legate_arch import ( # type: ignore[import-not-found, unused-ignore]
get_legate_arch,
)
except ModuleNotFoundError:
# User hasn't run configure yet, can't do anything
return None, None
LEGATE_ARCH = get_legate_arch()
from scripts.get_legate_dir import get_legate_dir
legate_arch_dir = Path(get_legate_dir()) / LEGATE_ARCH
cpp_ret = _find_tests(legate_arch_dir / "cmake_build")
py_ret = _find_tests(
legate_arch_dir / "skbuild_core" / "python" / "legate_cpp"
)
if cpp_ret and py_ret:
cpp_build_is_newer = all(
cpp_bin_exe.stat().st_mtime > py_bin_exe.stat().st_mtime
for cpp_bin_exe, py_bin_exe in zip(cpp_ret[1], py_ret[1])
)
if cpp_build_is_newer:
return cpp_ret
return py_ret
if cpp_ret:
return cpp_ret
if py_ret:
return py_ret
return None, None
class LegateProject(Project):
pass
def main() -> int: # noqa: D103
GTEST_TESTS_DIR, GTEST_TESTS_BIN = _find_latest_cpp_test_dir()
parser.set_defaults(
gtest_files=GTEST_TESTS_BIN,
mpi_output_filename=(
GTEST_TESTS_DIR / "mpi_result" if GTEST_TESTS_DIR else None
),
)
config = Config(sys.argv, project=LegateProject())
system = TestSystem(dry_run=config.dry_run)
plan = TestPlan(config, system)
return plan.execute()
if __name__ == "__main__":
sys.exit(main())