From fb6ec25d413abb26bfb897f7cd70037d838bdcdd Mon Sep 17 00:00:00 2001 From: "Elwazir, Ammar" Date: Mon, 23 Jun 2025 16:53:17 -0500 Subject: [PATCH] Adding Integration tests for later building option (#126) * Adding Integeration tests for later building option * Update CMakeLists.txt --------- Co-authored-by: Ammar ELWazir [ROCm/aqlprofile commit: e4bb0df9d5595bc9412a13ea439a8bd02981f199] --- projects/aqlprofile/CMakeLists.txt | 23 ++++++++++++++----- projects/aqlprofile/src/CMakeLists.txt | 2 +- projects/aqlprofile/src/core/aql_profile.cpp | 2 +- projects/aqlprofile/src/core/aql_profile.hpp | 2 +- projects/aqlprofile/src/core/counters.cpp | 2 +- .../src/core/include/CMakeLists.txt | 2 +- .../{ => aqlprofile-sdk}/aql_profile_v2.h | 0 .../aqlprofile/src/core/memorymanager.hpp | 2 +- projects/aqlprofile/src/core/pm4_factory.h | 2 +- .../aqlprofile/src/core/tests/CMakeLists.txt | 3 +++ .../src/core/tests/counter_tests.cpp | 10 ++++---- projects/aqlprofile/src/core/threadtrace.cpp | 2 +- projects/aqlprofile/test/CMakeLists.txt | 8 +++++-- projects/aqlprofile/test/app/test.cpp | 2 +- .../test/integration/CMakeLists.txt | 2 ++ .../aqlprofile/test/integration/agent.hpp | 3 +-- .../aqlprofile/test/integration/counter.hpp | 2 +- 17 files changed, 44 insertions(+), 25 deletions(-) rename projects/aqlprofile/src/core/include/{ => aqlprofile-sdk}/aql_profile_v2.h (100%) diff --git a/projects/aqlprofile/CMakeLists.txt b/projects/aqlprofile/CMakeLists.txt index 413a1fe2da..5f60a1b99f 100644 --- a/projects/aqlprofile/CMakeLists.txt +++ b/projects/aqlprofile/CMakeLists.txt @@ -12,9 +12,9 @@ include(GNUInstallDirs) ## Adding default path cmake modules list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules" ) ## Include common cmake modules -include ( utils ) +include (utils) ## Set build environment -include ( env ) +include (env) set(CMAKE_INSTALL_LIBDIR "lib" CACHE STRING "Library install directory") @@ -65,6 +65,13 @@ set ( TEST_BINARY_DIR ${PROJECT_BINARY_DIR}/test ) add_subdirectory ( ${TEST_DIR} ${TEST_BINARY_DIR} ) endif() +if(AQLPROFILE_INSTALL_TESTS) + # Install Integration Tests + install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test/integration/ + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/tests/integration + COMPONENT tests) +endif() + ## Add the install directives for the runtime library. set ( DEST_NAME ${AQLPROFILE_NAME} ) install ( TARGETS ${AQLPROFILE_TARGET} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT runtime ) @@ -72,12 +79,16 @@ install ( TARGETS ${AQLPROFILE_TARGET} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDI ## Add the packaging directives for the runtime library. if ( ENABLE_ASAN_PACKAGING ) - set ( CPACK_PACKAGE_NAME ${AQLPROFILE_NAME}-asan ) + set (CPACK_PACKAGE_NAME ${AQLPROFILE_NAME}-asan) # ASAN Package requires only asan component with libraries and license file - set ( CPACK_COMPONENTS_ALL asan ) + set (CPACK_COMPONENTS_ALL asan ) else() - set ( CPACK_PACKAGE_NAME ${AQLPROFILE_NAME} ) - set ( CPACK_COMPONENTS_ALL runtime tests ) + set (CPACK_PACKAGE_NAME ${AQLPROFILE_NAME}) + set (CPACK_COMPONENTS_ALL runtime) + # Add tests component if INSTALL_TESTS is enabled + if(AQLPROFILE_INSTALL_TESTS) + list(APPEND CPACK_COMPONENTS_ALL tests) + endif() endif() set ( CPACK_PACKAGE_VENDOR "Advanced Micro Devices, Inc." ) set ( CPACK_PACKAGE_VERSION_MAJOR ${BUILD_VERSION_MAJOR} ) diff --git a/projects/aqlprofile/src/CMakeLists.txt b/projects/aqlprofile/src/CMakeLists.txt index 3f7bfee02c..aabea7dd39 100644 --- a/projects/aqlprofile/src/CMakeLists.txt +++ b/projects/aqlprofile/src/CMakeLists.txt @@ -25,7 +25,7 @@ set ( LIB_SRC ) add_library ( ${TARGET_LIB} SHARED ${LIB_SRC} ) -target_include_directories ( ${TARGET_LIB} PRIVATE ${LIB_DIR} ${API_PATH}) +target_include_directories ( ${TARGET_LIB} PRIVATE ${LIB_DIR} ${API_PATH} ${LIB_DIR}/core/include) target_link_libraries( ${TARGET_LIB} PRIVATE pthread hsa-runtime64::hsa-runtime64 ) ## Generating definitions diff --git a/projects/aqlprofile/src/core/aql_profile.cpp b/projects/aqlprofile/src/core/aql_profile.cpp index 31ef56fc38..18251091bf 100644 --- a/projects/aqlprofile/src/core/aql_profile.cpp +++ b/projects/aqlprofile/src/core/aql_profile.cpp @@ -21,7 +21,7 @@ // THE SOFTWARE. #include "core/aql_profile.hpp" -#include "core/include/aql_profile_v2.h" +#include "aqlprofile-sdk/aql_profile_v2.h" #include #include diff --git a/projects/aqlprofile/src/core/aql_profile.hpp b/projects/aqlprofile/src/core/aql_profile.hpp index 60fb3fc70e..9718592616 100644 --- a/projects/aqlprofile/src/core/aql_profile.hpp +++ b/projects/aqlprofile/src/core/aql_profile.hpp @@ -27,7 +27,7 @@ #include #include -#include "include/aql_profile_v2.h" +#include "aqlprofile-sdk/aql_profile_v2.h" #include "core/aql_profile_exception.h" diff --git a/projects/aqlprofile/src/core/counters.cpp b/projects/aqlprofile/src/core/counters.cpp index 395d0f1c0f..36101706cd 100644 --- a/projects/aqlprofile/src/core/counters.cpp +++ b/projects/aqlprofile/src/core/counters.cpp @@ -21,7 +21,7 @@ // THE SOFTWARE. #include "core/aql_profile.hpp" -#include "core/include/aql_profile_v2.h" +#include "aqlprofile-sdk/aql_profile_v2.h" #include #include diff --git a/projects/aqlprofile/src/core/include/CMakeLists.txt b/projects/aqlprofile/src/core/include/CMakeLists.txt index ce60e33004..63dc1e35b0 100644 --- a/projects/aqlprofile/src/core/include/CMakeLists.txt +++ b/projects/aqlprofile/src/core/include/CMakeLists.txt @@ -1,5 +1,5 @@ set(AQLPROFILE_HEADER_FILES - aql_profile_v2.h + aqlprofile-sdk/aql_profile_v2.h ) install( diff --git a/projects/aqlprofile/src/core/include/aql_profile_v2.h b/projects/aqlprofile/src/core/include/aqlprofile-sdk/aql_profile_v2.h similarity index 100% rename from projects/aqlprofile/src/core/include/aql_profile_v2.h rename to projects/aqlprofile/src/core/include/aqlprofile-sdk/aql_profile_v2.h diff --git a/projects/aqlprofile/src/core/memorymanager.hpp b/projects/aqlprofile/src/core/memorymanager.hpp index 5a0f9aadff..881a9691d6 100644 --- a/projects/aqlprofile/src/core/memorymanager.hpp +++ b/projects/aqlprofile/src/core/memorymanager.hpp @@ -26,7 +26,7 @@ #include #include #include -#include "include/aql_profile_v2.h" +#include "aqlprofile-sdk/aql_profile_v2.h" #include #include "pm4/trace_config.h" diff --git a/projects/aqlprofile/src/core/pm4_factory.h b/projects/aqlprofile/src/core/pm4_factory.h index 6f1a866ff5..fcc3c60c4f 100644 --- a/projects/aqlprofile/src/core/pm4_factory.h +++ b/projects/aqlprofile/src/core/pm4_factory.h @@ -34,7 +34,7 @@ #include #include -#include "core/include/aql_profile_v2.h" +#include "aqlprofile-sdk/aql_profile_v2.h" #include "core/aql_profile.hpp" #include "core/aql_profile_exception.h" #include "def/gpu_block_info.h" diff --git a/projects/aqlprofile/src/core/tests/CMakeLists.txt b/projects/aqlprofile/src/core/tests/CMakeLists.txt index 0e0e40831f..9cd6755c95 100644 --- a/projects/aqlprofile/src/core/tests/CMakeLists.txt +++ b/projects/aqlprofile/src/core/tests/CMakeLists.txt @@ -1,3 +1,6 @@ +cmake_minimum_required(VERSION 3.16.0) +project(aqlprofile-sdk-tests) + # write a CMakeLists.txt file for the gfx9_factory_test # that includes the necessary libraries and sets the properties for the test include(GoogleTest) diff --git a/projects/aqlprofile/src/core/tests/counter_tests.cpp b/projects/aqlprofile/src/core/tests/counter_tests.cpp index 9c4d6518f9..261d61b6fb 100644 --- a/projects/aqlprofile/src/core/tests/counter_tests.cpp +++ b/projects/aqlprofile/src/core/tests/counter_tests.cpp @@ -23,7 +23,7 @@ #include #include #include -#include "core/include/aql_profile_v2.h" +#include "aqlprofile-sdk/aql_profile_v2.h" // Mocks and helpers namespace { @@ -94,7 +94,7 @@ TEST(CountersTest, DeletePackets) { hsa_status_t status = aqlprofile_pmc_create_packets( &handle, &packets, profile, mock_alloc, mock_dealloc, mock_memcpy, &mem); - + // Only proceed if creation succeeded if (status == HSA_STATUS_SUCCESS) { // This should not crash or throw @@ -106,13 +106,13 @@ TEST(CountersTest, DeletePackets) { TEST(CountersTest, ValidateEvent) { aqlprofile_agent_handle_t agent = {}; agent.handle = 0; - + aqlprofile_pmc_event_t event = {}; event.block_name = HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_GRBM; - + bool result = true; hsa_status_t status = aqlprofile_validate_pmc_event(agent, &event, &result); - + // In a mock environment, we can't guarantee validation, but we can check that it runs EXPECT_TRUE(status == HSA_STATUS_SUCCESS || status == HSA_STATUS_ERROR); } \ No newline at end of file diff --git a/projects/aqlprofile/src/core/threadtrace.cpp b/projects/aqlprofile/src/core/threadtrace.cpp index 1cb22d8a53..e5f96e75a9 100644 --- a/projects/aqlprofile/src/core/threadtrace.cpp +++ b/projects/aqlprofile/src/core/threadtrace.cpp @@ -21,7 +21,7 @@ // THE SOFTWARE. #include "core/aql_profile.hpp" -#include "core/include/aql_profile_v2.h" +#include "aqlprofile-sdk/aql_profile_v2.h" #include #include diff --git a/projects/aqlprofile/test/CMakeLists.txt b/projects/aqlprofile/test/CMakeLists.txt index cc11696395..331051bb50 100644 --- a/projects/aqlprofile/test/CMakeLists.txt +++ b/projects/aqlprofile/test/CMakeLists.txt @@ -7,8 +7,11 @@ if ( NOT DEFINED TEST_DIR ) set ( TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) set ( TEST_BINARY_DIR ${CMAKE_BINARY_DIR} ) project ( ${EXE_NAME} ) + list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake_modules" ) ## Set build environment include ( env ) + enable_testing() + include(CTest) endif () ## Util sources @@ -83,7 +86,8 @@ install(FILES ${TEST_DIR}/run_install.sh RENAME run_tests.sh add_test(NAME legacy-tests COMMAND "${TEST_BINARY_DIR}/run.sh") -if(AQLPROFILE_BUILD_TESTS) +option(AQLPROFILE_BUILD_INTEGERATION_TESTS "Build integration tests" ON) + +if(AQLPROFILE_BUILD_INTEGERATION_TESTS) add_subdirectory(integration) - enable_testing() endif() diff --git a/projects/aqlprofile/test/app/test.cpp b/projects/aqlprofile/test/app/test.cpp index 12260b76c3..16de8c92b7 100644 --- a/projects/aqlprofile/test/app/test.cpp +++ b/projects/aqlprofile/test/app/test.cpp @@ -22,7 +22,7 @@ #include "hsa/hsa_ext_amd.h" -#include "aql_profile_v2.h" +#include "aqlprofile-sdk/aql_profile_v2.h" #include #include diff --git a/projects/aqlprofile/test/integration/CMakeLists.txt b/projects/aqlprofile/test/integration/CMakeLists.txt index 7c620b8acf..a184a3501a 100644 --- a/projects/aqlprofile/test/integration/CMakeLists.txt +++ b/projects/aqlprofile/test/integration/CMakeLists.txt @@ -11,6 +11,8 @@ if(NOT DEFINED AQLPROFILE_TARGET) HINTS /opt/rocm ${CMAKE_INSTALL_PREFIX} PATHS /opt/rocm PATH_SUFFIXES lib) + enable_testing() + include(CTest) endif() find_package( diff --git a/projects/aqlprofile/test/integration/agent.hpp b/projects/aqlprofile/test/integration/agent.hpp index f9017c08a3..fe82a1d5b1 100644 --- a/projects/aqlprofile/test/integration/agent.hpp +++ b/projects/aqlprofile/test/integration/agent.hpp @@ -38,8 +38,7 @@ #include #include #include -//#include "/opt/rocm/include/aqlprofile-sdk/aql_profile_v2.h" -#include "aql_profile_v2.h" +#include "aqlprofile-sdk/aql_profile_v2.h" #define CHECK_HSA(x) if ((x) != HSA_STATUS_SUCCESS) { std::cerr << __FILE__ << " error at " << __LINE__ << std::endl; exit(-1); } diff --git a/projects/aqlprofile/test/integration/counter.hpp b/projects/aqlprofile/test/integration/counter.hpp index ea938dfb2c..689be82e6f 100644 --- a/projects/aqlprofile/test/integration/counter.hpp +++ b/projects/aqlprofile/test/integration/counter.hpp @@ -26,7 +26,7 @@ #include #include #include -#include "aql_profile_v2.h" +#include "aqlprofile-sdk/aql_profile_v2.h" #include #include #include