2025-02-04 04:05:38 -06:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
import pytest
|
|
|
|
|
import re
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_json_data(json_data):
|
|
|
|
|
data = json_data["rocprofiler-sdk-tool"]
|
|
|
|
|
strings = data["strings"]
|
|
|
|
|
assert "att_filenames" in strings.keys()
|
|
|
|
|
att_files = data["strings"]["att_filenames"]
|
|
|
|
|
assert len(att_files) > 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_code_object_memory(code_object_file_path, json_data, output_path):
|
|
|
|
|
|
|
|
|
|
data = json_data["rocprofiler-sdk-tool"]
|
|
|
|
|
tool_memory_load = data["strings"]["code_object_snapshot_filenames"]
|
|
|
|
|
gfx_pattern = "gfx[a-z0-9]+"
|
2025-03-15 02:11:10 +01:00
|
|
|
match = re.search(gfx_pattern, tool_memory_load[1])
|
2025-02-04 04:05:38 -06:00
|
|
|
assert match != None
|
|
|
|
|
gpu_name = match.group(0)
|
2025-03-15 02:11:10 +01:00
|
|
|
|
|
|
|
|
read_bytes = lambda filename: open(os.path.join(output_path, filename), "rb").read()
|
|
|
|
|
# Loads all saved code objects
|
|
|
|
|
tool_memory = [read_bytes(saved) for saved in tool_memory_load[1:]]
|
|
|
|
|
|
2025-02-04 04:05:38 -06:00
|
|
|
found = False
|
|
|
|
|
for hsa_file in code_object_file_path["hsa_memory_load"]:
|
|
|
|
|
|
|
|
|
|
m = re.search(gfx_pattern, hsa_file)
|
|
|
|
|
assert m != None
|
|
|
|
|
gpu = m.group(0)
|
|
|
|
|
|
|
|
|
|
if gpu == gpu_name:
|
|
|
|
|
found = True
|
2025-03-15 02:11:10 +01:00
|
|
|
hsa_memory_bytes = open(hsa_file, "rb").read()
|
|
|
|
|
# Checks if hsa_file is one of the saved code objects
|
|
|
|
|
assert any([hsa_memory_bytes == fs for fs in tool_memory])
|
2025-02-04 04:05:38 -06:00
|
|
|
break
|
|
|
|
|
assert found == True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
exit_code = pytest.main(["-x", __file__] + sys.argv[1:])
|
|
|
|
|
sys.exit(exit_code)
|