#!/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]+" match = re.search(gfx_pattern, tool_memory_load[1]) assert match != None gpu_name = match.group(0) 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:]] 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 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]) break assert found == True if __name__ == "__main__": exit_code = pytest.main(["-x", __file__] + sys.argv[1:]) sys.exit(exit_code)