Skip to content

Commit d050dba

Browse files
committed
SWDEV-561821: rename kernel-duration-ns test to kernel-trace-duration and fix CI formatting
1 parent b071cab commit d050dba

File tree

6 files changed

+64
-30
lines changed

6 files changed

+64
-30
lines changed

projects/rocprofiler-sdk/source/lib/python/rocpd/csv.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ def build_agent_id_string(agent_index_value, prefix=""):
212212
else:
213213
return ""
214214

215+
215216
def get_kernel_csv_query(config) -> str:
216217
agent_id = build_agent_id_string(config.agent_index_value)
217218

projects/rocprofiler-sdk/tests/rocprofv3/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ add_subdirectory(conversion-script)
4848
add_subdirectory(python-bindings)
4949
add_subdirectory(rocpd)
5050
add_subdirectory(rocpd-kernel-rename)
51-
add_subdirectory(kernel-duration-ns)
51+
add_subdirectory(kernel-trace-duration)
5252
add_subdirectory(attachment)
5353
add_subdirectory(rocpd-scratch)
5454
add_subdirectory(att-consecutive-kernels)

projects/rocprofiler-sdk/tests/rocprofv3/kernel-duration-ns/CMakeLists.txt renamed to projects/rocprofiler-sdk/tests/rocprofv3/kernel-trace-duration/CMakeLists.txt

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@ add_test(
3232

3333
set_tests_properties(
3434
rocprofv3-test-kernel-trace-duration-generate
35-
PROPERTIES
36-
TIMEOUT 120
37-
LABELS "integration-tests;kernel-trace-duration"
38-
ENVIRONMENT "${rocprofv3-generate-env}"
39-
FAIL_REGULAR_EXPRESSION "${ROCPROFILER_DEFAULT_FAIL_REGEX}"
40-
FIXTURES_SETUP rocprofv3-test-kernel-trace-duration-data)
35+
PROPERTIES TIMEOUT
36+
120
37+
LABELS
38+
"integration-tests;kernel-trace-duration"
39+
ENVIRONMENT
40+
"${rocprofv3-generate-env}"
41+
FAIL_REGULAR_EXPRESSION
42+
"${ROCPROFILER_DEFAULT_FAIL_REGEX}"
43+
FIXTURES_SETUP
44+
rocprofv3-test-kernel-trace-duration-data)
4145

4246
# Validate: compare rocpd kernel query output with JSON
4347
add_test(
@@ -50,9 +54,13 @@ add_test(
5054

5155
set_tests_properties(
5256
rocprofv3-test-kernel-trace-duration-validation
53-
PROPERTIES
54-
TIMEOUT 120
55-
LABELS "integration-tests;kernel-trace-duration"
56-
ENVIRONMENT "${rocprofv3-validate-env}"
57-
FIXTURES_REQUIRED rocprofv3-test-kernel-trace-duration-data
58-
FAIL_REGULAR_EXPRESSION "${ROCPROFILER_DEFAULT_FAIL_REGEX}")
57+
PROPERTIES TIMEOUT
58+
120
59+
LABELS
60+
"integration-tests;kernel-trace-duration"
61+
ENVIRONMENT
62+
"${rocprofv3-validate-env}"
63+
FIXTURES_REQUIRED
64+
rocprofv3-test-kernel-trace-duration-data
65+
FAIL_REGULAR_EXPRESSION
66+
"${ROCPROFILER_DEFAULT_FAIL_REGEX}")

projects/rocprofiler-sdk/tests/rocprofv3/kernel-duration-ns/conftest.py renamed to projects/rocprofiler-sdk/tests/rocprofv3/kernel-trace-duration/conftest.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python3
2-
31
# MIT License
42
#
53
# Copyright (c) 2024-2025 Advanced Micro Devices,
@@ -25,19 +23,23 @@
2523

2624
import json
2725
import os
26+
2827
import pytest
2928

29+
3030
def pytest_addoption(parser):
3131
parser.addoption("--json-input", action="store", required=True, help="Input JSON")
3232
parser.addoption("--db-input", action="store", required=True, help="Input rocpd DB")
3333

34+
3435
@pytest.fixture
3536
def json_data(request):
3637
path = request.config.getoption("--json-input")
3738
assert os.path.isfile(path), f"missing JSON input: {path}"
38-
with open(path, "r") as f:
39+
with open(path, "r", encoding="utf-8") as f:
3940
return json.load(f)
4041

42+
4143
@pytest.fixture
4244
def db_path(request):
4345
path = request.config.getoption("--db-input")

projects/rocprofiler-sdk/tests/rocprofv3/kernel-duration-ns/pytest.ini renamed to projects/rocprofiler-sdk/tests/rocprofv3/kernel-trace-duration/pytest.ini

File renamed without changes.

projects/rocprofiler-sdk/tests/rocprofv3/kernel-duration-ns/validate.py renamed to projects/rocprofiler-sdk/tests/rocprofv3/kernel-trace-duration/validate.py

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
# THE SOFTWARE.
2323

2424
import sys
25+
2526
import pytest
2627

28+
2729
def extract_json_kernel_records(json_root):
2830
"""Extract kernel dispatch records from JSON output."""
2931
assert "rocprofiler-sdk-tool" in json_root, "missing rocprofiler-sdk-tool in JSON"
@@ -35,14 +37,19 @@ def extract_json_kernel_records(json_root):
3537
buffer_records = tool["buffer_records"]
3638

3739
for key in ("kernel_dispatch", "kernel_trace", "kernel_dispatch_trace"):
38-
if key in buffer_records and isinstance(buffer_records[key], list) and len(buffer_records[key]) > 0:
40+
if (
41+
key in buffer_records
42+
and isinstance(buffer_records[key], list)
43+
and len(buffer_records[key]) > 0
44+
):
3945
return buffer_records[key]
4046

4147
assert False, (
4248
"no kernel dispatch records found in JSON buffer_records keys="
4349
f"{list(buffer_records.keys())}"
4450
)
4551

52+
4653
def _as_int(value, *, field="value"):
4754
assert value is not None, f"missing {field}"
4855
try:
@@ -52,12 +59,14 @@ def _as_int(value, *, field="value"):
5259
f"failed to parse int for {field}: {value!r} ({exc})"
5360
) from exc
5461

62+
5563
def _get_first_present(mapping, *keys):
5664
for key in keys:
5765
if key in mapping and mapping[key] is not None:
5866
return mapping[key]
5967
return None
6068

69+
6170
def _extract_dispatch_id_from_json_record(record):
6271
"""
6372
Prefer dispatch_info.dispatch_id.
@@ -79,6 +88,7 @@ def _extract_dispatch_id_from_json_record(record):
7988

8089
return _as_int(dispatch_id, field="dispatch_id/correlation_id")
8190

91+
8292
def build_json_duration_map(records):
8393
"""
8494
Build map:
@@ -100,6 +110,7 @@ def build_json_duration_map(records):
100110
assert len(result) > 0, "no kernel records extracted from JSON"
101111
return result
102112

113+
103114
def load_kernel_rows_via_rocpd(db_path):
104115
"""
105116
Use rocpd Python API and reuse rocpd.csv kernel query logic directly.
@@ -127,22 +138,33 @@ def load_kernel_rows_via_rocpd(db_path):
127138
assert len(rows) > 0, f"no rows returned from kernel query in db: {db_path}"
128139
return rows
129140

141+
130142
def _extract_dispatch_id_from_db_row(row):
131-
value = _get_first_present(row, "Dispatch_Id", "dispatch_id", "Correlation_Id", "correlation_id")
143+
value = _get_first_present(
144+
row,
145+
"Dispatch_Id",
146+
"dispatch_id",
147+
"Correlation_Id",
148+
"correlation_id",
149+
)
132150
return _as_int(value, field="Dispatch_Id/dispatch_id/Correlation_Id/correlation_id")
133151

152+
134153
def _extract_start_from_db_row(row):
135154
value = _get_first_present(row, "Start_Timestamp", "start_timestamp")
136155
return _as_int(value, field="Start_Timestamp/start_timestamp")
137156

157+
138158
def _extract_end_from_db_row(row):
139159
value = _get_first_present(row, "End_Timestamp", "end_timestamp")
140160
return _as_int(value, field="End_Timestamp/end_timestamp")
141161

162+
142163
def _extract_duration_from_db_row(row):
143164
value = _get_first_present(row, "Duration", "duration")
144165
return _as_int(value, field="Duration/duration")
145166

167+
146168
def test_rocpd_kernel_trace_duration(json_data, db_path):
147169
"""
148170
Validate that kernel trace Duration exists on the rocpd CSV path and matches JSON.
@@ -174,15 +196,15 @@ def test_rocpd_kernel_trace_duration(json_data, db_path):
174196
end = _extract_end_from_db_row(row)
175197
duration = _extract_duration_from_db_row(row)
176198

177-
assert start > 0 and end > 0, (
178-
f"invalid DB timestamps: start={start} end={end} dispatch_id={dispatch_id}"
179-
)
180-
assert end >= start, (
181-
f"DB end before start: start={start} end={end} dispatch_id={dispatch_id}"
182-
)
183-
assert duration >= 0, (
184-
f"negative DB duration: duration={duration} dispatch_id={dispatch_id}"
185-
)
199+
assert (
200+
start > 0 and end > 0
201+
), f"invalid DB timestamps: start={start} end={end} dispatch_id={dispatch_id}"
202+
assert (
203+
end >= start
204+
), f"DB end before start: start={start} end={end} dispatch_id={dispatch_id}"
205+
assert (
206+
duration >= 0
207+
), f"negative DB duration: duration={duration} dispatch_id={dispatch_id}"
186208
assert duration == (end - start), (
187209
f"DB duration mismatch: duration={duration} != end-start={end - start} "
188210
f"dispatch_id={dispatch_id}"
@@ -258,9 +280,10 @@ def test_rocpd_kernel_trace_duration(json_data, db_path):
258280
raise AssertionError("\n".join(lines) + detail)
259281

260282
assert matched_count > 0, "No DB rows matched JSON records"
261-
assert matched_count == total_count, (
262-
f"Only {matched_count}/{total_count} DB rows matched JSON"
263-
)
283+
assert (
284+
matched_count == total_count
285+
), f"Only {matched_count}/{total_count} DB rows matched JSON"
286+
264287

265288
if __name__ == "__main__":
266289
rc = pytest.main(["-x", __file__] + sys.argv[1:])

0 commit comments

Comments
 (0)