2
0
Ficheiros

Ignorando as revisões em .git-blame-ignore-revs. Clique aqui para contornar e ver a vista normal de responsabilização.

182 linhas
6.1 KiB
Python

2025-08-01 10:14:39 -06:00
##############################################################################
2025-06-12 12:02:58 -04:00
# MIT License
#
# Copyright (c) 2025 Advanced Micro Devices, Inc. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
2025-08-01 10:14:39 -06:00
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
2025-06-12 12:02:58 -04:00
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2025-08-01 10:14:39 -06:00
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2025-06-12 12:02:58 -04:00
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2025-08-01 10:14:39 -06:00
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
##############################################################################
2025-09-24 10:31:20 -04:00
import os
import subprocess
import sys
from importlib.machinery import SourceFileLoader
2025-09-24 10:31:20 -04:00
from pathlib import Path
from unittest.mock import patch
2025-02-20 17:51:57 -05:00
import pytest
ROOT = os.path.dirname(os.path.dirname(__file__))
SRC = os.path.join(ROOT, "src")
if SRC not in sys.path:
sys.path.insert(0, SRC)
try:
rocprof_compute = SourceFileLoader(
"rocprof-compute", "src/rocprof-compute"
).load_module()
except Exception:
rocprof_compute = SourceFileLoader(
"rocprof-compute", "rocprof-compute"
).load_module()
2025-02-20 17:51:57 -05:00
def pytest_addoption(parser):
parser.addoption(
"--call-binary",
action="store_true",
default=False,
help="Call standalone binary instead of main function during tests",
)
parser.addoption(
"--rocprofiler-sdk-tool-path",
type=str,
2025-09-24 10:31:20 -04:00
default=str(
Path(os.getenv("ROCM_PATH", "/opt/rocm"))
/ "lib/rocprofiler-sdk/librocprofiler-sdk-tool.so"
2025-09-24 10:31:20 -04:00
),
help="Path to the rocprofiler-sdk tool",
)
@pytest.fixture
def binary_handler_profile_rocprof_compute(request):
2025-04-02 20:32:13 -04:00
def _handler(
2025-08-08 15:32:30 -04:00
config,
workload_dir,
options=[],
check_success=True,
roof=False,
app_name="app_1",
2025-09-23 13:17:08 -04:00
attach_detach_para=None,
2025-04-02 20:32:13 -04:00
):
if request.config.getoption("--rocprofiler-sdk-tool-path"):
options.extend(
[
"--rocprofiler-sdk-tool-path",
request.config.getoption("--rocprofiler-sdk-tool-path"),
],
)
if request.config.getoption("--call-binary"):
baseline_opts = [
"build/rocprof-compute.bin",
"profile",
"-n",
2025-04-02 20:32:13 -04:00
app_name,
"-VVV",
]
if not roof:
baseline_opts.append("--no-roof")
2025-09-23 13:17:08 -04:00
command_rocprof_compute = baseline_opts + options + ["--path", workload_dir]
if not attach_detach_para:
command_rocprof_compute = (
command_rocprof_compute + ["--"] + config[app_name]
)
else:
command_rocprof_compute = command_rocprof_compute + [
"--attach-pid",
str(attach_detach_para["attach_pid"]),
]
if attach_detach_para["attach-duration-msec"]:
command_rocprof_compute = command_rocprof_compute + [
"--attach-duration-msec",
str(attach_detach_para["attach-duration-msec"]),
]
process = subprocess.run(
2025-09-23 13:17:08 -04:00
command_rocprof_compute,
text=True,
)
# verify run status
if check_success:
assert process.returncode == 0
return process.returncode
else:
baseline_opts = [
"rocprof-compute",
"profile",
"-n",
app_name,
"-VVV",
]
if not roof:
baseline_opts.append("--no-roof")
2025-09-23 13:17:08 -04:00
command_rocprof_compute = baseline_opts + options + ["--path", workload_dir]
if not attach_detach_para:
command_rocprof_compute = (
command_rocprof_compute + ["--"] + config[app_name]
)
else:
command_rocprof_compute = command_rocprof_compute + [
"--attach-pid",
str(attach_detach_para["attach_pid"]),
]
if attach_detach_para["attach-duration-msec"]:
command_rocprof_compute = command_rocprof_compute + [
"--attach-duration-msec",
str(attach_detach_para["attach-duration-msec"]),
]
with pytest.raises(SystemExit) as e:
with patch(
"sys.argv",
2025-09-23 13:17:08 -04:00
command_rocprof_compute,
):
rocprof_compute.main()
# verify run status
if check_success:
assert e.value.code == 0
return e.value.code
return _handler
@pytest.fixture
def binary_handler_analyze_rocprof_compute(request):
def _handler(arguments):
if request.config.getoption("--call-binary"):
process = subprocess.run(
["build/rocprof-compute.bin", *arguments],
text=True,
)
return process.returncode
else:
with pytest.raises(SystemExit) as e:
with patch(
"sys.argv",
["rocprof-compute", *arguments],
):
rocprof_compute.main()
return e.value.code
return _handler