Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ add_subdirectory(attach-twice)
add_subdirectory(attach-tree)
add_subdirectory(attach-once-att)
add_subdirectory(attach-roctx-pause-resume)
add_subdirectory(attach-detach)
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#
# rocprofv3 interactive attachment detach tests
#
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)

project(
rocprofiler-sdk-tests-rocprofv3-attachment-attach-detach
LANGUAGES CXX
VERSION 0.0.0)

find_package(rocprofiler-sdk REQUIRED)

# Disable under sanitizers — attach tests do not play well with them
set(ROCPROFILER_MEMCHECK_TYPES "AddressSanitizer" "UndefinedBehaviorSanitizer"
"ThreadSanitizer" "LeakSanitizer")

if(ROCPROFILER_MEMCHECK AND ROCPROFILER_MEMCHECK IN_LIST ROCPROFILER_MEMCHECK_TYPES)
set(IS_DISABLED ON)
else()
set(IS_DISABLED OFF)
endif()

if(ROCPROFILER_MEMCHECK STREQUAL "LeakSanitizer")
set(LOG_LEVEL "warning") # info produces memory leak
else()
set(LOG_LEVEL "info")
endif()

set(attachment-env
"LD_LIBRARY_PATH=$<TARGET_FILE_DIR:rocprofiler-sdk::rocprofiler-sdk-shared-library>:$ENV{LD_LIBRARY_PATH}"
)

# cmake-format: off
# add_attach_detach_test(<mode>)
#
# Registers the execute/validate pair for one interactive detach mechanism. Both
# omit --attach-duration-msec, which is what selects the interactive path:
# enter - a newline on rocprofv3's stdin answers the "Press Enter to detach" prompt
# sigint - SIGINT is delivered to rocprofv3 itself, not to the profiled application
# cmake-format: on
function(add_attach_detach_test MODE)
set(_name rocprofv3-test-attachment-attach-detach-${MODE})
set(_outdir ${CMAKE_CURRENT_BINARY_DIR}/attachment-detach-${MODE}-output)

rocprofiler_add_integration_execute_test(
${_name}
COMMAND
${CMAKE_CURRENT_SOURCE_DIR}/run_attachment_detach_test.sh
$<TARGET_FILE:attachment-test> $<TARGET_FILE:rocprofiler-sdk::rocprofv3>
${CMAKE_CURRENT_BINARY_DIR} ${LOG_LEVEL} out ${MODE}
DEPENDS rocprofiler-sdk::rocprofv3
TIMEOUT 90
LABELS "attachment"
DISABLED ${IS_DISABLED}
PRELOAD "${ROCPROFILER_MEMCHECK_PRELOAD_ENV_VALUE}"
ENVIRONMENT "${attachment-env}"
FAIL_REGULAR_EXPRESSION
"ERROR|FATAL|Skipping output generation|${ROCPROFILER_DEFAULT_FAIL_REGEX}"
SKIP_REGULAR_EXPRESSION "This test is skipped."
FIXTURES_SETUP ${_name})

rocprofiler_add_integration_validate_test(
${_name}
TEST_PATHS validate.py
COPY conftest.py
CONFIG pytest.ini
TIMEOUT 30
LABELS "attachment"
DISABLED ${IS_DISABLED}
SKIP_REGULAR_EXPRESSION "SKIPPED"
FIXTURES_REQUIRED ${_name}
ARGS --json-input ${_outdir}/out_results.json --skip-if ${_outdir}/skipped)
endfunction()

add_attach_detach_test(enter)
add_attach_detach_test(sigint)
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python3

# 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:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

import json
import pytest
import os

from rocprofiler_sdk.pytest_utils.dotdict import dotdict
from rocprofiler_sdk.pytest_utils import collapse_dict_list


def pytest_addoption(parser):
parser.addoption("--json-input", action="store", help="Path to JSON output file")
parser.addoption("--skip-if", action="store", help="Skip test if file exists")


def _skip_if(request):
skip_file = request.config.getoption("--skip-if")
if skip_file and os.path.exists(skip_file):
pytest.skip("Attach tests unavailable due to insufficient ptrace permissions")


@pytest.fixture
def json_data(request):
_skip_if(request)
filename = request.config.getoption("--json-input")
if not filename:
pytest.skip("--json-input not provided")
with open(filename, "r") as inp:
return dotdict(collapse_dict_list(json.load(inp)))
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

[pytest]
addopts = --durations=20 -rA -s
testpaths = validate.py
pythonpath = @ROCPROFILER_SDK_TESTS_BINARY_DIR@/pytest-packages
Loading
Loading