Skip to content

Commit

Permalink
Fixing multi pmc line tests (#848)
Browse files Browse the repository at this point in the history
* Fixing multi pmc line tests

* Fixing cmake-format from commandline locally
  • Loading branch information
bgopesh authored May 9, 2024
1 parent 358c599 commit 5efede4
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 49 deletions.
36 changes: 32 additions & 4 deletions tests/rocprofv3/counter-collection/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@

import json
import pytest
import csv
import pandas as pd


def pytest_addoption(parser):
parser.addoption("--input", action="store", help="Path to csv file.")
parser.addoption("--input-dir", action="store", help="Path to output dir.")
parser.addoption(
"--agent-input",
action="store",
help="Path to agent info CSV file.",
)
parser.addoption(
"--counter-input",
action="store",
help="Path to counter collection CSV file.",
)


@pytest.fixture
Expand All @@ -21,6 +31,24 @@ def input_data(request):


@pytest.fixture
def input_dir(request):
dirname = request.config.getoption("--input-dir")
return dirname
def agent_info_input_data(request):
filename = request.config.getoption("--agent-input")
data = []
with open(filename, "r") as inp:
reader = csv.DictReader(inp)
for row in reader:
data.append(row)

return data


@pytest.fixture
def counter_input_data(request):
filename = request.config.getoption("--counter-input")
data = []
with open(filename, "r") as inp:
reader = csv.DictReader(inp)
for row in reader:
data.append(row)

return data
37 changes: 29 additions & 8 deletions tests/rocprofv3/counter-collection/input2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ add_test(
NAME rocprofv3-test-counter-collection-pmc2-execute
COMMAND
$<TARGET_FILE:rocprofiler-sdk::rocprofv3> -i
${CMAKE_CURRENT_BINARY_DIR}/input.txt -d ${CMAKE_CURRENT_BINARY_DIR}/out_cc_2 -o
pmc2 $<TARGET_FILE:simple-transpose>)
${CMAKE_CURRENT_BINARY_DIR}/input.txt -d ${CMAKE_CURRENT_BINARY_DIR}/%argt%-cc -o
out $<TARGET_FILE:simple-transpose>)

string(REPLACE "LD_PRELOAD=" "ROCPROF_PRELOAD=" PRELOAD_ENV
"${ROCPROFILER_MEMCHECK_PRELOAD_ENV}")
Expand All @@ -39,12 +39,33 @@ set_tests_properties(
PROPERTIES TIMEOUT 45 LABELS "integration-tests" ENVIRONMENT "${cc-env-pmc2}"
FAIL_REGULAR_EXPRESSION "${ROCPROFILER_DEFAULT_FAIL_REGEX}")

add_test(NAME rocprofv3-test-counter-collection-pmc2-validate
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/validate.py
--input-dir "${CMAKE_CURRENT_BINARY_DIR}/out_cc_2")
add_test(
NAME rocprofv3-test-counter-collection-pmc2-validate
COMMAND
${Python3_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/validate.py --agent-input
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-cc/pmc_1/out_agent_info.csv
--counter-input
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-cc/pmc_1/out_counter_collection.csv
--agent-input
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-cc/pmc_2/out_agent_info.csv
--counter-input
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-cc/pmc_2/out_counter_collection.csv)

set(SYS_VALIDATION_FILES
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-cc/pmc_1/out_agent_info.csv
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-cc/pmc_1/out_counter_collection.csv
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-cc/pmc_2/out_agent_info.csv
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-cc/pmc_2/out_counter_collection.csv)

set_tests_properties(
rocprofv3-test-counter-collection-pmc2-validate
PROPERTIES TIMEOUT 45 LABELS "integration-tests" DEPENDS
rocprofv3-test-counter-collection-pmc2-execute FAIL_REGULAR_EXPRESSION
"${ROCPROFILER_DEFAULT_FAIL_REGEX}")
PROPERTIES TIMEOUT
45
LABELS
"integration-tests"
DEPENDS
rocprofv3-test-counter-collection-pmc2-execute
FAIL_REGULAR_EXPRESSION
"${ROCPROFILER_DEFAULT_FAIL_REGEX}"
ATTACHED_FILES_ON_FAIL
"${VALIDATION_FILES}")
76 changes: 39 additions & 37 deletions tests/rocprofv3/counter-collection/input2/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,45 @@
import pytest


def test_validate_counter_collection_pmc2(input_dir: pd.DataFrame):
directory_path = input_dir

# Check if the directory is not empty
assert os.path.isdir(directory_path), f"{directory_path} is not a directory."
assert os.listdir(directory_path), f"{directory_path} is empty."

# Check if there are 2 subdirectories pmc_1 and pmc_2
subdirectories = [
d
for d in os.listdir(directory_path)
if os.path.isdir(os.path.join(directory_path, d))
]
assert (
len(subdirectories) == 2
), f"Expected 2 subdirectories, found {len(subdirectories)}."

# Check if each subdirectory has files
for subdirectory in subdirectories:
subdirectory_path = os.path.join(directory_path, subdirectory)
assert os.listdir(subdirectory_path), f"{subdirectory_path} is empty."

# Check if each file in the subdirectory has some data
for file_name in os.listdir(subdirectory_path):
file_path = os.path.join(subdirectory_path, file_name)
# ignore hidden folders
if os.path.isdir(file_path) and os.path.basename(file_path).startswith("."):
continue
assert os.path.isfile(file_path), f"{file_path} is not a file."

if "agent_info.csv" not in file_path:
with open(file_path, "r") as file:
df = pd.read_csv(file)
# check if kernel-name is present
assert len(df["Kernel_Name"]) > 0
# check if counter value is positive
assert len(df["Counter_Value"]) > 0
def test_agent_info(agent_info_input_data):
logical_node_id = max([int(itr["Logical_Node_Id"]) for itr in agent_info_input_data])

assert logical_node_id + 1 == len(agent_info_input_data)

for row in agent_info_input_data:
agent_type = row["Agent_Type"]
assert agent_type in ("CPU", "GPU")
if agent_type == "CPU":
assert int(row["Cpu_Cores_Count"]) > 0
assert int(row["Simd_Count"]) == 0
assert int(row["Max_Waves_Per_Simd"]) == 0
else:
assert int(row["Cpu_Cores_Count"]) == 0
assert int(row["Simd_Count"]) > 0
assert int(row["Max_Waves_Per_Simd"]) > 0


def test_validate_counter_collection_pmc2(counter_input_data):
counter_names = ["SQ_WAVES", "GRBM_COUNT"]
di_list = []

for row in counter_input_data:
assert int(row["Agent_Id"]) > 0
assert int(row["Queue_Id"]) > 0
assert int(row["Process_Id"]) > 0
assert len(row["Kernel_Name"]) > 0

assert len(row["Counter_Value"]) > 0
# assert row["Counter_Name"].contains("SQ_WAVES").all()
assert row["Counter_Name"] in counter_names
assert int(row["Counter_Value"]) > 0

di_list.append(int(row["Dispatch_Id"]))

# # make sure the dispatch ids are unique and ordered
di_list = list(dict.fromkeys(di_list))
di_expect = [idx + 1 for idx in range(len(di_list))]
assert di_expect == di_list


if __name__ == "__main__":
Expand Down

0 comments on commit 5efede4

Please sign in to comment.