|
3 | 3 | import shlex |
4 | 4 | import subprocess |
5 | 5 | from pathlib import Path |
6 | | -import glob |
| 6 | +import platform |
7 | 7 | import shutil |
8 | 8 | import json |
9 | 9 | import sys |
10 | 10 | import platform |
11 | 11 |
|
12 | 12 | logging.basicConfig(level=logging.INFO) |
13 | 13 | THEROCK_BIN_DIR_STR = os.getenv("THEROCK_BIN_DIR") |
14 | | -if THEROCK_BIN_DIR_STR is None: |
15 | | - logging.info( |
16 | | - "++ Error: env(THEROCK_BIN_DIR) is not set. Please set it before executing tests." |
17 | | - ) |
18 | | - sys.exit(1) |
19 | 14 | THEROCK_BIN_DIR = Path(THEROCK_BIN_DIR_STR) |
20 | 15 | SCRIPT_DIR = Path(__file__).resolve().parent |
21 | 16 | THEROCK_DIR = SCRIPT_DIR.parent.parent.parent |
22 | | -SHARD_INDEX = os.getenv("SHARD_INDEX", 1) |
23 | | -TOTAL_SHARDS = os.getenv("TOTAL_SHARDS", 1) |
| 17 | +SHARD_INDEX = int(os.getenv("SHARD_INDEX", 1)) - 1 |
| 18 | +TOTAL_SHARDS = int(os.getenv("TOTAL_SHARDS", 1)) |
24 | 19 | AMDGPU_FAMILIES = os.getenv("AMDGPU_FAMILIES") |
25 | 20 | os_type = platform.system().lower() |
26 | 21 | CATCH_TESTS_PATH = str(Path(THEROCK_BIN_DIR).parent / "share" / "hip" / "catch_tests") |
| 22 | + |
| 23 | +# Importing is_asan from github_actions_utils.py |
| 24 | +sys.path.append(str(THEROCK_DIR / "build_tools" / "github_actions")) |
| 25 | +from github_actions_utils import is_asan |
| 26 | + |
| 27 | +env = os.environ.copy() |
| 28 | + |
| 29 | +if THEROCK_BIN_DIR_STR is None: |
| 30 | + logging.info( |
| 31 | + "++ Error: env(THEROCK_BIN_DIR) is not set. Please set it before executing tests." |
| 32 | + ) |
| 33 | + sys.exit(1) |
| 34 | + |
27 | 35 | if not os.path.isdir(CATCH_TESTS_PATH): |
28 | 36 | logging.info(f"++ Error: catch tests not found in {CATCH_TESTS_PATH}") |
29 | 37 | sys.exit(1) |
30 | | -env = os.environ.copy() |
31 | 38 |
|
32 | 39 | # TODO(#3204): Re-enable tests once issues are resolved |
33 | 40 | TEST_TO_IGNORE = { |
|
45 | 52 | } |
46 | 53 |
|
47 | 54 |
|
48 | | -def get_test_count(): |
49 | | - cmd = ["ctest", "--show-only=json-v1"] |
| 55 | +def get_asan_lib_path(): |
| 56 | + arch = platform.machine() |
| 57 | + CLANG_PATH = str(Path(THEROCK_BIN_DIR).parent / "lib" / "llvm" / "bin" / "clang++") |
| 58 | + cmd = [f"{CLANG_PATH}", f"--print-file-name=libclang_rt.asan-{arch}.so"] |
| 59 | + logging.info(f"++ Exec [{CLANG_PATH}]$ {shlex.join(cmd)}") |
50 | 60 | result = subprocess.run( |
51 | 61 | cmd, |
52 | | - cwd=CATCH_TESTS_PATH, |
53 | 62 | check=True, |
| 63 | + text=True, |
54 | 64 | capture_output=True, |
55 | 65 | ) |
56 | | - jdata = json.loads(result.stdout) |
57 | | - tests = jdata["tests"] |
58 | | - return len(tests) |
59 | | - |
60 | | - |
61 | | -def get_test_range_per_shard(total_test_count: int, total_shards, shard_index): |
62 | | - tests_per_shard = int(total_test_count / total_shards) |
63 | | - current_index = (tests_per_shard * (shard_index - 1)) + 1 |
64 | | - end_index = current_index + tests_per_shard - 1 |
65 | | - if shard_index == total_shards: |
66 | | - # Retrieve remaining tests |
67 | | - end_index = total_test_count |
68 | | - logging.info( |
69 | | - f"""++ hip-tests ctest: shard {shard_index} / {total_shards}. Running:{tests_per_shard} tests""" |
70 | | - ) |
71 | | - return [current_index, end_index] |
| 66 | + return result.stdout.strip() |
72 | 67 |
|
73 | 68 |
|
74 | 69 | def copy_dlls_exe_path(): |
@@ -103,24 +98,27 @@ def setup_env(env): |
103 | 98 | env["LD_LIBRARY_PATH"] = f"{HIP_LIB_PATH}:{env['LD_LIBRARY_PATH']}" |
104 | 99 | else: |
105 | 100 | env["LD_LIBRARY_PATH"] = HIP_LIB_PATH |
| 101 | + # For ASAN mode, we preload it for test count query and test running |
| 102 | + if is_asan(): |
| 103 | + env["LD_PRELOAD"] = get_asan_lib_path() |
| 104 | + # TODO: enable this when we have symbolizer patch in |
| 105 | + # env["ASAN_SYMBOLIZER_PATH"] = str(Path(THEROCK_BIN_DIR).parent / "lib" / "llvm" / "bin" / "llvm-symbolizer") |
106 | 106 | else: |
107 | 107 | copy_dlls_exe_path() |
108 | 108 |
|
109 | 109 |
|
110 | 110 | def execute_tests(env): |
111 | | - total_tests = get_test_count() |
112 | | - index_start, index_end = get_test_range_per_shard( |
113 | | - total_tests, int(TOTAL_SHARDS), int(SHARD_INDEX) |
114 | | - ) |
| 111 | + # Allow for more time in ASAN mode to run the tests. |
| 112 | + timeout = 1500 if is_asan() else 600 |
115 | 113 | cmd = [ |
116 | 114 | "ctest", |
117 | | - "-I", |
118 | | - f"{index_start},{index_end}", |
| 115 | + "--tests-information", |
| 116 | + f"{SHARD_INDEX},,{TOTAL_SHARDS}", |
119 | 117 | "--test-dir", |
120 | 118 | CATCH_TESTS_PATH, |
121 | 119 | "--output-on-failure", |
122 | 120 | "--timeout", |
123 | | - "600", |
| 121 | + f"{timeout}", |
124 | 122 | ] |
125 | 123 |
|
126 | 124 | if AMDGPU_FAMILIES in TEST_TO_IGNORE and os_type in TEST_TO_IGNORE[AMDGPU_FAMILIES]: |
|
0 commit comments