diff --git a/projects/rocprofiler-sdk/.cmake-format.yaml b/projects/rocprofiler-sdk/.cmake-format.yaml index cfe16426a5..6c371fa654 100644 --- a/projects/rocprofiler-sdk/.cmake-format.yaml +++ b/projects/rocprofiler-sdk/.cmake-format.yaml @@ -240,6 +240,11 @@ parse: PERFETTO_METRIC: '*' TIMEMORY_FILE: '*' TIMEMORY_METRIC: '*' + rocprofiler_configure_pytest_files: + kwargs: + COPY: '*' + CONFIG: '*' + OUTPUT_DIRECTORY: '*' override_spec: {} vartags: [] proptags: [] diff --git a/projects/rocprofiler-sdk/tests/CMakeLists.txt b/projects/rocprofiler-sdk/tests/CMakeLists.txt index 10408a1229..ad658a6552 100644 --- a/projects/rocprofiler-sdk/tests/CMakeLists.txt +++ b/projects/rocprofiler-sdk/tests/CMakeLists.txt @@ -10,6 +10,8 @@ endif() project(rocprofiler-tests LANGUAGES C CXX) set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "tests") +set(ROCPROFILER_SDK_TESTS_SOURCE_DIR "${PROJECT_SOURCE_DIR}") +set(ROCPROFILER_SDK_TESTS_BINARY_DIR "${PROJECT_BINARY_DIR}") if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE @@ -34,6 +36,9 @@ set(CMAKE_INSTALL_LIBDIR "lib") # needed for validation find_package(Python3 REQUIRED) +# configure python module /rocprofiler_sdk/pytest_utils +add_subdirectory(pytest-packages) + # common utilities add_subdirectory(common) diff --git a/projects/rocprofiler-sdk/tests/async-copy-tracing/CMakeLists.txt b/projects/rocprofiler-sdk/tests/async-copy-tracing/CMakeLists.txt index 07f868e558..6f166dcaf8 100644 --- a/projects/rocprofiler-sdk/tests/async-copy-tracing/CMakeLists.txt +++ b/projects/rocprofiler-sdk/tests/async-copy-tracing/CMakeLists.txt @@ -31,10 +31,8 @@ set_tests_properties( "${async-copy-tracing-env}" FAIL_REGULAR_EXPRESSION "${ROCPROFILER_DEFAULT_FAIL_REGEX}") -foreach(FILENAME validate.py pytest.ini conftest.py) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME} - ${CMAKE_CURRENT_BINARY_DIR}/${FILENAME} COPYONLY) -endforeach() +# copy to binary directory +rocprofiler_configure_pytest_files(COPY validate.py conftest.py CONFIG pytest.ini) add_test(NAME test-async-copy-tracing-validate COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/validate.py --input diff --git a/projects/rocprofiler-sdk/tests/async-copy-tracing/pytest.ini b/projects/rocprofiler-sdk/tests/async-copy-tracing/pytest.ini index eb3f82f5cd..5e1e1c14a0 100644 --- a/projects/rocprofiler-sdk/tests/async-copy-tracing/pytest.ini +++ b/projects/rocprofiler-sdk/tests/async-copy-tracing/pytest.ini @@ -2,3 +2,4 @@ [pytest] addopts = --durations=20 -rA -s -vv testpaths = validate.py +pythonpath = @ROCPROFILER_SDK_TESTS_BINARY_DIR@/pytest-packages diff --git a/projects/rocprofiler-sdk/tests/common/CMakeLists.txt b/projects/rocprofiler-sdk/tests/common/CMakeLists.txt index fd772ba7f2..92dd453a8a 100644 --- a/projects/rocprofiler-sdk/tests/common/CMakeLists.txt +++ b/projects/rocprofiler-sdk/tests/common/CMakeLists.txt @@ -3,6 +3,7 @@ # include(FetchContent) +include(CMakeParseArguments) set(FETCHCONTENT_BASE_DIR ${PROJECT_BINARY_DIR}/external) @@ -131,3 +132,21 @@ if(EXISTS ${EXTERNAL_SUBMODULE_DIR}/filesystem/include/ghc/filesystem.hpp) rocprofiler-tests-common-library SYSTEM INTERFACE $) endif() + +function(rocprofiler_configure_pytest_files) + cmake_parse_arguments(RCPF "" "OUTPUT_DIRECTORY" "COPY;CONFIG" ${ARGN}) + + if(NOT RCPF_OUTPUT_DIRECTORY) + set(RCPF_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + endif() + + foreach(FILENAME ${RCPF_COPY}) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME} + ${RCPF_OUTPUT_DIRECTORY}/${FILENAME} COPYONLY) + endforeach() + + foreach(FILENAME ${RCPF_CONFIG}) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME} + ${RCPF_OUTPUT_DIRECTORY}/${FILENAME} @ONLY) + endforeach() +endfunction() diff --git a/projects/rocprofiler-sdk/tests/counter-collection/CMakeLists.txt b/projects/rocprofiler-sdk/tests/counter-collection/CMakeLists.txt index 75b758ed50..f405f6e18b 100644 --- a/projects/rocprofiler-sdk/tests/counter-collection/CMakeLists.txt +++ b/projects/rocprofiler-sdk/tests/counter-collection/CMakeLists.txt @@ -29,10 +29,8 @@ set_tests_properties( "${counter-collection-env}" FAIL_REGULAR_EXPRESSION "${ROCPROFILER_DEFAULT_FAIL_REGEX}") -foreach(FILENAME validate.py pytest.ini conftest.py) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME} - ${CMAKE_CURRENT_BINARY_DIR}/${FILENAME} COPYONLY) -endforeach() +# copy to binary directory +rocprofiler_configure_pytest_files(COPY validate.py conftest.py CONFIG pytest.ini) add_test(NAME test-counter-collection-validate COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/validate.py --input diff --git a/projects/rocprofiler-sdk/tests/counter-collection/pytest.ini b/projects/rocprofiler-sdk/tests/counter-collection/pytest.ini index 899bc38408..d657f00825 100644 --- a/projects/rocprofiler-sdk/tests/counter-collection/pytest.ini +++ b/projects/rocprofiler-sdk/tests/counter-collection/pytest.ini @@ -2,3 +2,4 @@ [pytest] addopts = --durations=20 -ras -vv testpaths = validate.py +pythonpath = @ROCPROFILER_SDK_TESTS_BINARY_DIR@/pytest-packages diff --git a/projects/rocprofiler-sdk/tests/kernel-tracing/CMakeLists.txt b/projects/rocprofiler-sdk/tests/kernel-tracing/CMakeLists.txt index 56c2a25245..2d5a9d13d2 100644 --- a/projects/rocprofiler-sdk/tests/kernel-tracing/CMakeLists.txt +++ b/projects/rocprofiler-sdk/tests/kernel-tracing/CMakeLists.txt @@ -35,10 +35,8 @@ set_tests_properties( PROPERTIES TIMEOUT 100 LABELS "integration-tests" ENVIRONMENT "${kernel-tracing-env}" FAIL_REGULAR_EXPRESSION "${ROCPROFILER_DEFAULT_FAIL_REGEX}") -foreach(FILENAME validate.py pytest.ini conftest.py) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME} - ${CMAKE_CURRENT_BINARY_DIR}/${FILENAME} COPYONLY) -endforeach() +# copy to binary directory +rocprofiler_configure_pytest_files(COPY validate.py conftest.py CONFIG pytest.ini) add_test( NAME test-kernel-tracing-validate diff --git a/projects/rocprofiler-sdk/tests/kernel-tracing/pytest.ini b/projects/rocprofiler-sdk/tests/kernel-tracing/pytest.ini index eb3f82f5cd..5e1e1c14a0 100644 --- a/projects/rocprofiler-sdk/tests/kernel-tracing/pytest.ini +++ b/projects/rocprofiler-sdk/tests/kernel-tracing/pytest.ini @@ -2,3 +2,4 @@ [pytest] addopts = --durations=20 -rA -s -vv testpaths = validate.py +pythonpath = @ROCPROFILER_SDK_TESTS_BINARY_DIR@/pytest-packages diff --git a/projects/rocprofiler-sdk/tests/page-migration/CMakeLists.txt b/projects/rocprofiler-sdk/tests/page-migration/CMakeLists.txt index accbd909b6..d2b580ac34 100644 --- a/projects/rocprofiler-sdk/tests/page-migration/CMakeLists.txt +++ b/projects/rocprofiler-sdk/tests/page-migration/CMakeLists.txt @@ -40,10 +40,8 @@ set_tests_properties( WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) -foreach(FILENAME validate.py pytest.ini conftest.py) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME} - ${CMAKE_CURRENT_BINARY_DIR}/${FILENAME} COPYONLY) -endforeach() +# copy to binary directory +rocprofiler_configure_pytest_files(COPY validate.py conftest.py CONFIG pytest.ini) add_test(NAME test-page-migration-validate COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/validate.py --input diff --git a/projects/rocprofiler-sdk/tests/page-migration/pytest.ini b/projects/rocprofiler-sdk/tests/page-migration/pytest.ini index eb3f82f5cd..5e1e1c14a0 100644 --- a/projects/rocprofiler-sdk/tests/page-migration/pytest.ini +++ b/projects/rocprofiler-sdk/tests/page-migration/pytest.ini @@ -2,3 +2,4 @@ [pytest] addopts = --durations=20 -rA -s -vv testpaths = validate.py +pythonpath = @ROCPROFILER_SDK_TESTS_BINARY_DIR@/pytest-packages diff --git a/projects/rocprofiler-sdk/tests/pytest-packages/CMakeLists.txt b/projects/rocprofiler-sdk/tests/pytest-packages/CMakeLists.txt new file mode 100644 index 0000000000..7dfa7b7186 --- /dev/null +++ b/projects/rocprofiler-sdk/tests/pytest-packages/CMakeLists.txt @@ -0,0 +1,20 @@ +# +# +# + +set(PACKAGE_OUTPUT_DIR + ${ROCPROFILER_SDK_TESTS_BINARY_DIR}/pytest-packages/rocprofiler_sdk) +set(PYTEST_UTILS_PYTHON_SOURCES __init__.py dotdict.py) + +foreach(_FILE ${PYTEST_UTILS_PYTHON_SOURCES}) + configure_file(${CMAKE_CURRENT_LIST_DIR}/pytest_utils/${_FILE} + ${PACKAGE_OUTPUT_DIR}/pytest_utils/${_FILE} COPYONLY) +endforeach() + +file( + WRITE "${PACKAGE_OUTPUT_DIR}/__init__.py" + " +from __future__ import absolute_import + +from . import pytest_utils +") diff --git a/projects/rocprofiler-sdk/tests/pytest-packages/pytest_utils/__init__.py b/projects/rocprofiler-sdk/tests/pytest-packages/pytest_utils/__init__.py new file mode 100644 index 0000000000..24d26e36c3 --- /dev/null +++ b/projects/rocprofiler-sdk/tests/pytest-packages/pytest_utils/__init__.py @@ -0,0 +1,23 @@ +# MIT License +# +# Copyright (c) 2023 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. + +from __future__ import absolute_import diff --git a/projects/rocprofiler-sdk/tests/pytest-packages/pytest_utils/dotdict.py b/projects/rocprofiler-sdk/tests/pytest-packages/pytest_utils/dotdict.py new file mode 100644 index 0000000000..cd8b59c3a4 --- /dev/null +++ b/projects/rocprofiler-sdk/tests/pytest-packages/pytest_utils/dotdict.py @@ -0,0 +1,40 @@ +# MIT License +# +# Copyright (c) 2023 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. + +from __future__ import absolute_import + + +class dotdict(dict): + """dot.notation access to dictionary attributes""" + + __getattr__ = dict.get + __setattr__ = dict.__setitem__ + __delattr__ = dict.__delitem__ + + def __init__(self, d): + super(dotdict, self).__init__(d) + for k, v in self.items(): + if isinstance(v, dict): + self.__setitem__(k, dotdict(v)) + # print(k) + elif isinstance(v, list): + self.__setitem__(k, [dotdict(i) for i in v]) diff --git a/projects/rocprofiler-sdk/tests/rocprofv3/counter-collection/CMakeLists.txt b/projects/rocprofiler-sdk/tests/rocprofv3/counter-collection/CMakeLists.txt index 04d5e79b50..8aa3baed7a 100644 --- a/projects/rocprofiler-sdk/tests/rocprofv3/counter-collection/CMakeLists.txt +++ b/projects/rocprofiler-sdk/tests/rocprofv3/counter-collection/CMakeLists.txt @@ -2,10 +2,8 @@ # Various counter collection tests # -foreach(FILENAME conftest.py pytest.ini) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME} - ${CMAKE_CURRENT_BINARY_DIR}/${FILENAME} COPYONLY) -endforeach() +# copy to binary directory +rocprofiler_configure_pytest_files(COPY conftest.py CONFIG pytest.ini) add_subdirectory(input1) add_subdirectory(input2) diff --git a/projects/rocprofiler-sdk/tests/rocprofv3/counter-collection/pytest.ini b/projects/rocprofiler-sdk/tests/rocprofv3/counter-collection/pytest.ini index 324df0a4b5..536c02a5b9 100644 --- a/projects/rocprofiler-sdk/tests/rocprofv3/counter-collection/pytest.ini +++ b/projects/rocprofiler-sdk/tests/rocprofv3/counter-collection/pytest.ini @@ -4,3 +4,4 @@ addopts = --durations=20 -rA -s -vv testpaths = input1/validate.py input2/validate.py list_metrics/validate.py +pythonpath = @ROCPROFILER_SDK_TESTS_BINARY_DIR@/pytest-packages diff --git a/projects/rocprofiler-sdk/tests/rocprofv3/tracing-plus-cc/CMakeLists.txt b/projects/rocprofiler-sdk/tests/rocprofv3/tracing-plus-cc/CMakeLists.txt index e4e96f91f4..b238ffbf8a 100644 --- a/projects/rocprofiler-sdk/tests/rocprofv3/tracing-plus-cc/CMakeLists.txt +++ b/projects/rocprofiler-sdk/tests/rocprofv3/tracing-plus-cc/CMakeLists.txt @@ -10,10 +10,9 @@ project( find_package(rocprofiler-sdk REQUIRED) -foreach(FILENAME validate.py conftest.py pytest.ini input.txt) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME} - ${CMAKE_CURRENT_BINARY_DIR}/${FILENAME} COPYONLY) -endforeach() +# copy to binary directory +rocprofiler_configure_pytest_files(COPY validate.py conftest.py input.txt + CONFIG pytest.ini) # pmc3 add_test( diff --git a/projects/rocprofiler-sdk/tests/rocprofv3/tracing-plus-cc/pytest.ini b/projects/rocprofiler-sdk/tests/rocprofv3/tracing-plus-cc/pytest.ini index eb3f82f5cd..5e1e1c14a0 100644 --- a/projects/rocprofiler-sdk/tests/rocprofv3/tracing-plus-cc/pytest.ini +++ b/projects/rocprofiler-sdk/tests/rocprofv3/tracing-plus-cc/pytest.ini @@ -2,3 +2,4 @@ [pytest] addopts = --durations=20 -rA -s -vv testpaths = validate.py +pythonpath = @ROCPROFILER_SDK_TESTS_BINARY_DIR@/pytest-packages diff --git a/projects/rocprofiler-sdk/tests/scratch-memory-tracing/CMakeLists.txt b/projects/rocprofiler-sdk/tests/scratch-memory-tracing/CMakeLists.txt index 56eb4b14a6..b539fcab41 100644 --- a/projects/rocprofiler-sdk/tests/scratch-memory-tracing/CMakeLists.txt +++ b/projects/rocprofiler-sdk/tests/scratch-memory-tracing/CMakeLists.txt @@ -31,10 +31,8 @@ set_tests_properties( "${scratch-memory-tracing-env}" FAIL_REGULAR_EXPRESSION "threw an exception") -foreach(FILENAME validate.py pytest.ini conftest.py) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME} - ${CMAKE_CURRENT_BINARY_DIR}/${FILENAME} COPYONLY) -endforeach() +# copy to binary directory +rocprofiler_configure_pytest_files(COPY validate.py conftest.py CONFIG pytest.ini) add_test(NAME test-scratch-memory-tracing-validate COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/validate.py --input diff --git a/projects/rocprofiler-sdk/tests/scratch-memory-tracing/pytest.ini b/projects/rocprofiler-sdk/tests/scratch-memory-tracing/pytest.ini index eb3f82f5cd..5e1e1c14a0 100644 --- a/projects/rocprofiler-sdk/tests/scratch-memory-tracing/pytest.ini +++ b/projects/rocprofiler-sdk/tests/scratch-memory-tracing/pytest.ini @@ -2,3 +2,4 @@ [pytest] addopts = --durations=20 -rA -s -vv testpaths = validate.py +pythonpath = @ROCPROFILER_SDK_TESTS_BINARY_DIR@/pytest-packages