Skip to content

Commit 6280066

Browse files
authored
Add ASAN mechanism for hip-tests (#3215)
1 parent 5f60db7 commit 6280066

1 file changed

Lines changed: 33 additions & 35 deletions

File tree

build_tools/github_actions/test_executable_scripts/test_hiptests.py

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,38 @@
33
import shlex
44
import subprocess
55
from pathlib import Path
6-
import glob
6+
import platform
77
import shutil
88
import json
99
import sys
1010
import platform
1111

1212
logging.basicConfig(level=logging.INFO)
1313
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)
1914
THEROCK_BIN_DIR = Path(THEROCK_BIN_DIR_STR)
2015
SCRIPT_DIR = Path(__file__).resolve().parent
2116
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))
2419
AMDGPU_FAMILIES = os.getenv("AMDGPU_FAMILIES")
2520
os_type = platform.system().lower()
2621
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+
2735
if not os.path.isdir(CATCH_TESTS_PATH):
2836
logging.info(f"++ Error: catch tests not found in {CATCH_TESTS_PATH}")
2937
sys.exit(1)
30-
env = os.environ.copy()
3138

3239
# TODO(#3204): Re-enable tests once issues are resolved
3340
TEST_TO_IGNORE = {
@@ -45,30 +52,18 @@
4552
}
4653

4754

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)}")
5060
result = subprocess.run(
5161
cmd,
52-
cwd=CATCH_TESTS_PATH,
5362
check=True,
63+
text=True,
5464
capture_output=True,
5565
)
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()
7267

7368

7469
def copy_dlls_exe_path():
@@ -103,24 +98,27 @@ def setup_env(env):
10398
env["LD_LIBRARY_PATH"] = f"{HIP_LIB_PATH}:{env['LD_LIBRARY_PATH']}"
10499
else:
105100
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")
106106
else:
107107
copy_dlls_exe_path()
108108

109109

110110
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
115113
cmd = [
116114
"ctest",
117-
"-I",
118-
f"{index_start},{index_end}",
115+
"--tests-information",
116+
f"{SHARD_INDEX},,{TOTAL_SHARDS}",
119117
"--test-dir",
120118
CATCH_TESTS_PATH,
121119
"--output-on-failure",
122120
"--timeout",
123-
"600",
121+
f"{timeout}",
124122
]
125123

126124
if AMDGPU_FAMILIES in TEST_TO_IGNORE and os_type in TEST_TO_IGNORE[AMDGPU_FAMILIES]:

0 commit comments

Comments
 (0)