diff --git a/.github/workflows/linux_post_commit.yml b/.github/workflows/linux_post_commit.yml index c47320f3ff55a..25a30d4232d8f 100644 --- a/.github/workflows/linux_post_commit.yml +++ b/.github/workflows/linux_post_commit.yml @@ -67,6 +67,11 @@ jobs: run: | python3 $GITHUB_WORKSPACE/src/buildbot/check.py -w $GITHUB_WORKSPACE \ -s $GITHUB_WORKSPACE/src -o $GITHUB_WORKSPACE/build -t check-llvm-spirv + - name: check-xptifw + if: always() + run: | + python3 $GITHUB_WORKSPACE/src/buildbot/check.py -w $GITHUB_WORKSPACE \ + -s $GITHUB_WORKSPACE/src -o $GITHUB_WORKSPACE/build -t check-xptifw - name: Pack run: tar -czvf llvm_sycl.tar.gz -C $GITHUB_WORKSPACE/build/install . - name: Upload artifacts diff --git a/buildbot/configure.py b/buildbot/configure.py index c8daa90492a4c..bc45743e53b86 100644 --- a/buildbot/configure.py +++ b/buildbot/configure.py @@ -40,6 +40,7 @@ def do_configure(args): llvm_enable_lld = 'OFF' sycl_enable_xpti_tracing = 'ON' + xpti_enable_werror = 'ON' if args.ci_defaults: print("#############################################") @@ -79,6 +80,7 @@ def do_configure(args): if args.no_werror: sycl_werror = 'OFF' + xpti_enable_werror = 'OFF' if args.no_assertions: llvm_enable_assertions = 'OFF' @@ -123,7 +125,8 @@ def do_configure(args): "-DBUILD_SHARED_LIBS={}".format(llvm_build_shared_libs), "-DSYCL_ENABLE_XPTI_TRACING={}".format(sycl_enable_xpti_tracing), "-DLLVM_ENABLE_LLD={}".format(llvm_enable_lld), - "-DSYCL_BUILD_PI_ESIMD_CPU={}".format(sycl_build_pi_esimd_cpu) + "-DSYCL_BUILD_PI_ESIMD_CPU={}".format(sycl_build_pi_esimd_cpu), + "-DXPTI_ENABLE_WERROR={}".format(xpti_enable_werror) ] if args.l0_headers and args.l0_loader: diff --git a/sycl/CMakeLists.txt b/sycl/CMakeLists.txt index 8ca27d106e57f..9cc6c30478425 100644 --- a/sycl/CMakeLists.txt +++ b/sycl/CMakeLists.txt @@ -172,7 +172,7 @@ if (NOT WIN32) endif() if (SYCL_ENABLE_XPTI_TRACING) - set(XPTIFW_LIBS xptifw) + set(XPTIFW_LIBS xpti xptifw) endif() # SYCL toolchain builds all components: compiler, libraries, headers, etc. diff --git a/sycl/source/detail/event_impl.cpp b/sycl/source/detail/event_impl.cpp index 96581cf6a4b54..363bc0f18bd0e 100644 --- a/sycl/source/detail/event_impl.cpp +++ b/sycl/source/detail/event_impl.cpp @@ -18,7 +18,7 @@ #include #ifdef XPTI_ENABLE_INSTRUMENTATION -#include "xpti_trace_framework.hpp" +#include "xpti/xpti_trace_framework.hpp" #include #include #include diff --git a/sycl/source/detail/pi.cpp b/sycl/source/detail/pi.cpp index d7745f148c89c..05ee5647d6ec2 100644 --- a/sycl/source/detail/pi.cpp +++ b/sycl/source/detail/pi.cpp @@ -35,7 +35,7 @@ #ifdef XPTI_ENABLE_INSTRUMENTATION // Include the headers necessary for emitting // traces using the trace framework -#include "xpti_trace_framework.h" +#include "xpti/xpti_trace_framework.h" #endif #define STR(x) #x diff --git a/sycl/source/detail/plugin.hpp b/sycl/source/detail/plugin.hpp index bfd614893f221..1383ceeebe369 100644 --- a/sycl/source/detail/plugin.hpp +++ b/sycl/source/detail/plugin.hpp @@ -18,7 +18,7 @@ #ifdef XPTI_ENABLE_INSTRUMENTATION // Include the headers necessary for emitting traces using the trace framework -#include "xpti_trace_framework.h" +#include "xpti/xpti_trace_framework.h" #endif __SYCL_INLINE_NAMESPACE(cl) { diff --git a/sycl/source/detail/queue_impl.cpp b/sycl/source/detail/queue_impl.cpp index 56cc7a12747c3..25cb28486aa9c 100644 --- a/sycl/source/detail/queue_impl.cpp +++ b/sycl/source/detail/queue_impl.cpp @@ -17,7 +17,7 @@ #include #ifdef XPTI_ENABLE_INSTRUMENTATION -#include "xpti_trace_framework.hpp" +#include "xpti/xpti_trace_framework.hpp" #include #include #endif diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index b37a0a1d93343..fbf35cc65da50 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -43,7 +43,7 @@ #endif #ifdef XPTI_ENABLE_INSTRUMENTATION -#include "xpti_trace_framework.hpp" +#include "xpti/xpti_trace_framework.hpp" #include #endif diff --git a/sycl/source/detail/xpti_registry.hpp b/sycl/source/detail/xpti_registry.hpp index b0c5db3af8cdd..cd721bedd4a7a 100644 --- a/sycl/source/detail/xpti_registry.hpp +++ b/sycl/source/detail/xpti_registry.hpp @@ -14,7 +14,7 @@ #ifdef XPTI_ENABLE_INSTRUMENTATION // Include the headers necessary for emitting // traces using the trace framework -#include "xpti_trace_framework.h" +#include "xpti/xpti_trace_framework.h" #endif __SYCL_INLINE_NAMESPACE(cl) { diff --git a/sycl/tools/pi-trace/pi_trace.cpp b/sycl/tools/pi-trace/pi_trace.cpp index 5a355e407a484..d75b3eebf3bc1 100644 --- a/sycl/tools/pi-trace/pi_trace.cpp +++ b/sycl/tools/pi-trace/pi_trace.cpp @@ -10,7 +10,7 @@ /// A sample XPTI subscriber to demonstrate how to collect PI function call /// arguments. -#include "xpti_trace_framework.h" +#include "xpti/xpti_trace_framework.h" #include "pi_arguments_handler.hpp" diff --git a/xpti/CMakeLists.txt b/xpti/CMakeLists.txt index a47f2567ae580..5ef8c2336f2a3 100644 --- a/xpti/CMakeLists.txt +++ b/xpti/CMakeLists.txt @@ -1,17 +1,28 @@ -cmake_minimum_required(VERSION 2.8.9) +cmake_minimum_required(VERSION 3.8) set(XPTI_VERSION 0.4.1) +project (xpti VERSION "${XPTI_VERSION}" LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 14) + set(XPTI_DIR ${CMAKE_CURRENT_LIST_DIR}) # Setting the same version as SYCL set(CMAKE_CXX_STANDARD 11) +option(XPTI_ENABLE_WERROR OFF) + +if (XPTI_ENABLE_WERROR) + if(MSVC) + set(CMAKE_CXX_FLAGS "/WX ${CMAKE_CXX_FLAGS}") + else() + set(CMAKE_CXX_FLAGS "-Werror ${CMAKE_CXX_FLAGS}") + endif() +endif() + if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) message(STATUS "No build type selected, default to Release") set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type (default Release)" FORCE) endif() -project (xpti) - if (MSVC) # MSVC provides two incompatible build variants for its CRT: release and debug # To avoid potential issues in user code we also need to provide two kinds @@ -63,5 +74,20 @@ set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/lib/${CMAKE_BUILD_TYPE}) set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}) set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}) -include_directories(${CMAKE_SOURCE_DIR}/include) add_subdirectory(src) + +if (LLVM_BINARY_DIR) + add_custom_target(xpti-headers ALL + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMAKE_CURRENT_SOURCE_DIR}/include/xpti + ${LLVM_BINARY_DIR}/include/xpti + COMMENT "Copying XPTI headers..." + ) + add_dependencies(xpti xpti-headers) +endif() + +include(GNUInstallDirs) +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/xpti + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT xpti +) diff --git a/xpti/include/xpti_data_types.h b/xpti/include/xpti/xpti_data_types.h similarity index 100% rename from xpti/include/xpti_data_types.h rename to xpti/include/xpti/xpti_data_types.h diff --git a/xpti/include/xpti_trace_framework.h b/xpti/include/xpti/xpti_trace_framework.h similarity index 99% rename from xpti/include/xpti_trace_framework.h rename to xpti/include/xpti/xpti_trace_framework.h index e6c5cdc72818c..82465daf37e03 100644 --- a/xpti/include/xpti_trace_framework.h +++ b/xpti/include/xpti/xpti_trace_framework.h @@ -6,7 +6,8 @@ // // #pragma once -#include "xpti_data_types.h" + +#include "xpti/xpti_data_types.h" #if defined(XPTI_STATIC_LIBRARY) // If we are building or using the proxy diff --git a/xpti/include/xpti_trace_framework.hpp b/xpti/include/xpti/xpti_trace_framework.hpp similarity index 98% rename from xpti/include/xpti_trace_framework.hpp rename to xpti/include/xpti/xpti_trace_framework.hpp index 24bf75305e513..6e464d32290c9 100644 --- a/xpti/include/xpti_trace_framework.hpp +++ b/xpti/include/xpti/xpti_trace_framework.hpp @@ -6,18 +6,23 @@ // // #pragma once + #include #include #include #include -#include "xpti_data_types.h" -#include "xpti_trace_framework.h" +#include "xpti/xpti_data_types.h" +#include "xpti/xpti_trace_framework.h" #if defined(_WIN32) || defined(_WIN64) #include #include +// Windows.h defines min and max macros, that interfere with C++ std::min and +// std::max. The following definition disables that feature. +#define NOMINMAX #include +#undef NOMINMAX typedef HINSTANCE xpti_plugin_handle_t; typedef FARPROC xpti_plugin_function_t; #define XPTI_PLUGIN_STRING "*.dll" diff --git a/xpti/src/CMakeLists.txt b/xpti/src/CMakeLists.txt index d2d35c126dc76..8d3e1a8b4ec30 100644 --- a/xpti/src/CMakeLists.txt +++ b/xpti/src/CMakeLists.txt @@ -1,18 +1,34 @@ -cmake_minimum_required(VERSION 2.8.9) -project (xpti) -file(GLOB SOURCES *.cpp) -include_directories(${XPTI_DIR}/include) -add_definitions(-DXPTI_STATIC_LIBRARY) -add_library(xpti STATIC ${SOURCES}) +include(GNUInstallDirs) + +macro(add_xpti_lib target_name) + add_library(${target_name} STATIC ${ARGN}) + target_compile_definitions(${target_name} PRIVATE -DXPTI_STATIC_LIBRARY) + target_include_directories(${target_name} PRIVATE ${XPTI_DIR}/include) + + if (MSVC) + target_compile_options(${target_name} PRIVATE /EHsc) + endif() + + # Set the location of the library installation + install(TARGETS ${target_name} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT xpti + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT xpti + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT xpti + ) +endmacro() + +set(SOURCES + xpti_proxy.cpp +) + +add_xpti_lib(xpti ${SOURCES}) # Handle the debug version for the Microsoft compiler as a special case by # creating a debug version of the static library that uses the flags used by # the SYCL runtime if (MSVC) - add_library(xptid STATIC ${SOURCES}) + add_xpti_lib(xptid STATIC ${SOURCES}) target_compile_options(xptid PRIVATE ${XPTI_CXX_FLAGS_DEBUG}) target_compile_options(xpti PRIVATE ${XPTI_CXX_FLAGS_RELEASE}) endif() -# Set the location of the library installation -install(TARGETS xpti DESTINATION ${CMAKE_BINARY_DIR}) diff --git a/xpti/src/xpti_proxy.cpp b/xpti/src/xpti_proxy.cpp index 4d04110d98b2c..8e1439cd24bd5 100644 --- a/xpti/src/xpti_proxy.cpp +++ b/xpti/src/xpti_proxy.cpp @@ -5,7 +5,7 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // // -#include "xpti_trace_framework.hpp" +#include "xpti/xpti_trace_framework.hpp" #include #include diff --git a/xptifw/CMakeLists.txt b/xptifw/CMakeLists.txt index a2bca5b1b64d9..2d0f32f0dad19 100644 --- a/xptifw/CMakeLists.txt +++ b/xptifw/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.8) set(XPTI_VERSION 0.4.1) project (xptifw VERSION "${XPTI_VERSION}" LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 14) set(XPTIFW_DIR ${CMAKE_CURRENT_LIST_DIR}) # The XPTI framework requires the includes from @@ -12,15 +13,24 @@ set(XPTI_DIR ${CMAKE_CURRENT_LIST_DIR}/../xpti) # Create a soft option for enabling the use of TBB option(XPTI_ENABLE_TBB "Enable TBB in the framework" OFF) +option(XPTI_ENABLE_WERROR OFF) + +if (XPTI_ENABLE_WERROR) + if(MSVC) + set(CMAKE_CXX_FLAGS "/WX ${CMAKE_CXX_FLAGS}") + else() + set(CMAKE_CXX_FLAGS "-Werror ${CMAKE_CXX_FLAGS}") + endif() +endif() + if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) message(STATUS "No build type selected, default to Release") set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type (default Release)" FORCE) endif() if(MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") endif() - if (SYCL_USE_LIBCXX) if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")) @@ -38,20 +48,16 @@ set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/lib/${CMAKE_BUILD_TYPE}) set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}) set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}) -include_directories(${CMAKE_SOURCE_DIR}/include ${XPTI_DIR}/include) add_subdirectory(src) -# TODO enable samples and tests back once build problems are resolved. -# Currently builds for unit tests and samples fail mostly with dllimport/dllexport -# mismatch problems: -# syclpi_collector.cpp(32): error C2491: 'xptiTraceInit': definition of dllimport function not allowed -if (0) + +add_custom_target(check-xptifw) + add_subdirectory(unit_test) add_subdirectory(samples/basic_collector) add_subdirectory(samples/syclpi_collector) -endif() # The tests in basic_test are written using TBB, so these tests are enabled # only if TBB has been enabled. -if (0) +if (XPTI_ENABLE_TBB) add_subdirectory(basic_test) endif() diff --git a/xptifw/basic_test/CMakeLists.txt b/xptifw/basic_test/CMakeLists.txt index 1856bed1c519b..39c0e954ebf26 100644 --- a/xptifw/basic_test/CMakeLists.txt +++ b/xptifw/basic_test/CMakeLists.txt @@ -1,22 +1,24 @@ -cmake_minimum_required(VERSION 2.8.9) -project (run_test) - file(GLOB SOURCES *.cpp *.hpp) include_directories(${XPTIFW_DIR}/include) include_directories(${XPTI_DIR}/include) -remove_definitions(-DXPTI_STATIC_LIBRARY) -add_definitions(-DXPTI_API_EXPORTS -g -O3) -add_executable(run_test ${SOURCES}) -add_dependencies(run_test xptifw) -target_link_libraries(run_test PRIVATE xptifw) -if(UNIX) - target_link_libraries(run_test PRIVATE dl) -endif() +add_executable(XPTIFWBasicTests ${SOURCES}) +target_link_libraries(XPTIFWBasicTests PRIVATE xptifw ${CMAKE_DL_LIBS}) -if (XPTI_ENABLE_TBB) - target_link_libraries(run_test PRIVATE tbb) +if (UNIX) + target_compile_definitions(XPTIFWBasicTests PRIVATE -gline-tables-only -O3) endif() -# Set the location of the library installation -install(TARGETS run_test DESTINATION ${CMAKE_BINARY_DIR}) +# There's a XPTI_ENABLE_TBB guard in xptifw/CMakeLists.txt +target_link_libraries(XPTIFWBasicTests PRIVATE tbb) + +# Override default LLVM bin location +set_target_properties(XPTIFWBasicTests + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} +) + +add_custom_target(check-xptifw-basictest COMMAND + $/XPTIFWBasicTests) +add_dependencies(check-xptifw-basictest XPTIFWBasicTests) +add_dependencies(check-xptifw check-xptifw-basictest) diff --git a/xptifw/basic_test/cl_processor.hpp b/xptifw/basic_test/cl_processor.hpp index b769ac134e354..ecb88500775ae 100644 --- a/xptifw/basic_test/cl_processor.hpp +++ b/xptifw/basic_test/cl_processor.hpp @@ -6,7 +6,8 @@ // // #pragma once -#include "xpti_trace_framework.hpp" + +#include "xpti/xpti_trace_framework.hpp" #include #include diff --git a/xptifw/basic_test/performance_tests.cpp b/xptifw/basic_test/performance_tests.cpp index 0986cdb92d6ed..4ee4ed9b83fdd 100644 --- a/xptifw/basic_test/performance_tests.cpp +++ b/xptifw/basic_test/performance_tests.cpp @@ -17,7 +17,7 @@ #include "tbb/task_group.h" #include "cl_processor.hpp" -#include "xpti_trace_framework.h" +#include "xpti/xpti_trace_framework.h" #include #include diff --git a/xptifw/basic_test/semantic_tests.cpp b/xptifw/basic_test/semantic_tests.cpp index 83dc91afadcaa..96104e0d65acd 100644 --- a/xptifw/basic_test/semantic_tests.cpp +++ b/xptifw/basic_test/semantic_tests.cpp @@ -16,7 +16,7 @@ #include "tbb/task_group.h" #include "cl_processor.hpp" -#include "xpti_trace_framework.h" +#include "xpti/xpti_trace_framework.h" #include #include diff --git a/xptifw/include/xpti_int64_hash_table.hpp b/xptifw/include/xpti_int64_hash_table.hpp index 229111a6d208f..cefc84de33251 100644 --- a/xptifw/include/xpti_int64_hash_table.hpp +++ b/xptifw/include/xpti_int64_hash_table.hpp @@ -4,7 +4,8 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // #pragma once -#include "xpti_data_types.h" + +#include "xpti/xpti_data_types.h" #include #include diff --git a/xptifw/include/xpti_string_table.hpp b/xptifw/include/xpti_string_table.hpp index a366fbd4a3e0b..6df1be3004561 100644 --- a/xptifw/include/xpti_string_table.hpp +++ b/xptifw/include/xpti_string_table.hpp @@ -4,7 +4,8 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // #pragma once -#include "xpti_data_types.h" + +#include "xpti/xpti_data_types.h" #include #include diff --git a/xptifw/samples/basic_collector/CMakeLists.txt b/xptifw/samples/basic_collector/CMakeLists.txt index 118f876e0fd4a..49902b78d943c 100644 --- a/xptifw/samples/basic_collector/CMakeLists.txt +++ b/xptifw/samples/basic_collector/CMakeLists.txt @@ -1,19 +1,17 @@ -file(GLOB SOURCES *.cpp) -include_directories(${XPTIFW_DIR}/include) -include_directories(${XPTI_DIR}/include) -include_directories(${XPTIFW_DIR}/samples/include) - -remove_definitions(-DXPTI_STATIC_LIBRARY) -add_definitions(-DXPTI_API_EXPORTS) -add_library(basic_collector SHARED ${SOURCES}) -add_dependencies(basic_collector xptifw) -target_link_libraries(basic_collector PRIVATE xptifw) -if(UNIX) - target_link_libraries(basic_collector PRIVATE dl) -endif() +add_library(xpti_basic_collector SHARED + basic_collector.cpp + ) +target_link_libraries(xpti_basic_collector PRIVATE + xptifw + ${CMAKE_DL_LIBS} +) +target_include_directories(xpti_basic_collector PRIVATE + ${XPTIFW_DIR}/include + ${XPTI_DIR}/include + ${XPTIFW_DIR}/samples/include +) if (XPTI_ENABLE_TBB) - target_link_libraries(basic_collector PRIVATE tbb) + target_link_libraries(xpti_basic_collector PRIVATE tbb) endif() -# Set the location of the library installation -install(TARGETS basic_collector DESTINATION ${CMAKE_BINARY_DIR}) + diff --git a/xptifw/samples/basic_collector/README.md b/xptifw/samples/basic_collector/README.md index 2040db580b640..92ae146defba1 100644 --- a/xptifw/samples/basic_collector/README.md +++ b/xptifw/samples/basic_collector/README.md @@ -20,7 +20,7 @@ data received from various streams. In order to obtain the data from an applicat 3. Set the environment variable that points to the subscriber, which in this case is `libbasic_collector.[so,dll,dylib]`. - `XPTI_SUBSCRIBERS=/path/to/libbasic_collector.[so,dll,dylib]` + `XPTI_SUBSCRIBERS=/path/to/libxpti_basic_collector.[so,dll,dylib]` For more detail on the framework, the tests that are provided and their usage, please consult the [XPTI Framework library documentation](doc/XPTI_Framework.md). diff --git a/xptifw/samples/syclpi_collector/CMakeLists.txt b/xptifw/samples/syclpi_collector/CMakeLists.txt index acba7cb38231b..8dcac02d79e41 100644 --- a/xptifw/samples/syclpi_collector/CMakeLists.txt +++ b/xptifw/samples/syclpi_collector/CMakeLists.txt @@ -1,19 +1,17 @@ -file(GLOB SOURCES *.cpp) -include_directories(${XPTIFW_DIR}/include) -include_directories(${XPTI_DIR}/include) -include_directories(${XPTIFW_DIR}/samples/include) - -remove_definitions(-DXPTI_STATIC_LIBRARY) -add_definitions(-DXPTI_API_EXPORTS) -add_library(syclpi_collector SHARED ${SOURCES}) -add_dependencies(syclpi_collector xptifw) -target_link_libraries(syclpi_collector PRIVATE xptifw) -if(UNIX) - target_link_libraries(syclpi_collector PRIVATE dl) -endif() +add_library(xpti_syclpi_collector SHARED + syclpi_collector.cpp +) +target_link_libraries(xpti_syclpi_collector PRIVATE + xptifw + ${CMAKE_DL_LIBS} +) +target_include_directories(xpti_basic_collector PRIVATE + ${XPTIFW_DIR}/include + ${XPTI_DIR}/include + ${XPTIFW_DIR}/samples/include +) if (XPTI_ENABLE_TBB) - target_link_libraries(syclpi_collector PRIVATE tbb) + target_link_libraries(xpti_syclpi_collector PRIVATE tbb) endif() -# Set the location of the library installation -install(TARGETS syclpi_collector DESTINATION ${CMAKE_BINARY_DIR}) + diff --git a/xptifw/samples/syclpi_collector/README.md b/xptifw/samples/syclpi_collector/README.md index e0c211df7fc51..7eb077abcb95e 100644 --- a/xptifw/samples/syclpi_collector/README.md +++ b/xptifw/samples/syclpi_collector/README.md @@ -21,7 +21,7 @@ an application instrumented with XPTI, the following steps must be performed. 3. Set the environment variable that points to the subscriber, which in this case is `libsyclpi_collector.[so,dll,dylib]`. - `XPTI_SUBSCRIBERS=/path/to/libsyclpi_collector.[so,dll,dylib]` + `XPTI_SUBSCRIBERS=/path/to/libxpti_syclpi_collector.[so,dll,dylib]` For more detail on the framework, the tests that are provided and their usage, please consult the [XPTI Framework library documentation](doc/XPTI_Framework.md). diff --git a/xptifw/src/CMakeLists.txt b/xptifw/src/CMakeLists.txt index 6bdddc52e353a..1d56f99071718 100644 --- a/xptifw/src/CMakeLists.txt +++ b/xptifw/src/CMakeLists.txt @@ -1,8 +1,8 @@ file(GLOB SOURCES *.cpp) remove_definitions(-DXPTI_STATIC_LIBRARY) -add_definitions(-DXPTI_API_EXPORTS) add_library(xptifw SHARED ${SOURCES}) +target_compile_definitions(xptifw PRIVATE -DXPTI_API_EXPORTS) target_include_directories(xptifw PUBLIC $ @@ -20,5 +20,11 @@ endif() if (SYCL_USE_LIBCXX) target_link_libraries(xptifw PRIVATE "-L${SYCL_LIBCXX_LIBRARY_PATH}" -Wl,-rpath,${SYCL_LIBCXX_LIBRARY_PATH} -nodefaultlibs -lc++ -lc++abi -lm -lc -lgcc_s -lgcc) endif() + # Set the location of the library installation -install(TARGETS xptifw DESTINATION ${CMAKE_BINARY_DIR}) +include(GNUInstallDirs) +install(TARGETS xptifw + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT xptifw + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT xptifw + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT xptifw +) diff --git a/xptifw/src/xpti_trace_framework.cpp b/xptifw/src/xpti_trace_framework.cpp index efa59b28d5cbc..095bc2b09b494 100644 --- a/xptifw/src/xpti_trace_framework.cpp +++ b/xptifw/src/xpti_trace_framework.cpp @@ -3,7 +3,7 @@ // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // -#include "xpti_trace_framework.hpp" +#include "xpti/xpti_trace_framework.hpp" #include "xpti_int64_hash_table.hpp" #include "xpti_string_table.hpp" @@ -727,6 +727,8 @@ class Notifications { #endif } + void clear() { MCallbacksByStream.clear(); } + private: #ifdef XPTI_STATISTICS std::string stringify_trace_type(xpti_trace_point_type_t TraceType) { @@ -807,6 +809,7 @@ class Framework { MUniversalIDs = 1; MTracepoints.clear(); MStringTableRef.clear(); + MNotifier.clear(); } inline void setTraceEnabled(bool yesOrNo = true) { MTraceEnabled = yesOrNo; } diff --git a/xptifw/unit_test/CMakeLists.txt b/xptifw/unit_test/CMakeLists.txt index 7ce07ba4b2662..aafc35974d7a3 100644 --- a/xptifw/unit_test/CMakeLists.txt +++ b/xptifw/unit_test/CMakeLists.txt @@ -38,8 +38,31 @@ if (NOT DEFINED LLVM_EXTERNAL_XPTIFW_SOURCE_DIR) endif() endif() -# Now simply link against gtest or gtest_main as needed. Eg -add_executable(xpti_tests xpti_api_tests.cpp xpti_correctness_tests.cpp) -target_link_libraries(xpti_tests gtest) -target_link_libraries(xpti_tests gtest_main xptifw) -add_test(NAME example_test COMMAND xpti_tests) +add_executable(XPTIFWUnitTests + xpti_api_tests.cpp + xpti_correctness_tests.cpp +) + +# Silence warnings from GTest +target_include_directories(XPTIFWUnitTests SYSTEM PRIVATE + ${gtest_SOURCE_DIR}/include + ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include +) + +if (TARGET Support) + set(SUPPORT_LIB Support) +endif() + +target_link_libraries(XPTIFWUnitTests PRIVATE + gtest + gtest_main + xptifw + ${SUPPORT_LIB} +) + +add_test(NAME XPTIFWTests COMMAND XPTIFWUnitTests) + +add_custom_target(check-xptifw-unittest COMMAND + $/XPTIFWUnitTests) +add_dependencies(check-xptifw-unittest XPTIFWUnitTests) +add_dependencies(check-xptifw check-xptifw-unittest) diff --git a/xptifw/unit_test/xpti_api_tests.cpp b/xptifw/unit_test/xpti_api_tests.cpp index 01041163e578a..b53b97257f9a6 100644 --- a/xptifw/unit_test/xpti_api_tests.cpp +++ b/xptifw/unit_test/xpti_api_tests.cpp @@ -3,7 +3,7 @@ // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // -#include "xpti_trace_framework.hpp" +#include "xpti/xpti_trace_framework.hpp" #include #include @@ -11,13 +11,23 @@ #include static int func_callback_update = 0; +static int TPCB2Called = 0; +class xptiApiTest : public ::testing::Test { +protected: + void SetUp() override { + TPCB2Called = 0; + func_callback_update = 0; + } + + void TearDown() override { xptiReset(); } +}; -TEST(xptiApiTest, xptiInitializeBadInput) { +TEST_F(xptiApiTest, xptiInitializeBadInput) { auto Result = xptiInitialize(nullptr, 0, 0, nullptr); EXPECT_EQ(Result, xpti::result_t::XPTI_RESULT_INVALIDARG); } -TEST(xptiApiTest, xptiRegisterStringBadInput) { +TEST_F(xptiApiTest, xptiRegisterStringBadInput) { char *TStr; auto ID = xptiRegisterString(nullptr, nullptr); @@ -28,7 +38,7 @@ TEST(xptiApiTest, xptiRegisterStringBadInput) { EXPECT_EQ(ID, xpti::invalid_id); } -TEST(xptiApiTest, xptiRegisterStringGoodInput) { +TEST_F(xptiApiTest, xptiRegisterStringGoodInput) { char *TStr = nullptr; auto ID = xptiRegisterString("foo", &TStr); @@ -37,14 +47,14 @@ TEST(xptiApiTest, xptiRegisterStringGoodInput) { EXPECT_STREQ("foo", TStr); } -TEST(xptiApiTest, xptiLookupStringBadInput) { +TEST_F(xptiApiTest, xptiLookupStringBadInput) { const char *TStr; xptiReset(); TStr = xptiLookupString(-1); EXPECT_EQ(TStr, nullptr); } -TEST(xptiApiTest, xptiLookupStringGoodInput) { +TEST_F(xptiApiTest, xptiLookupStringGoodInput) { char *TStr = nullptr; auto ID = xptiRegisterString("foo", &TStr); @@ -58,8 +68,8 @@ TEST(xptiApiTest, xptiLookupStringGoodInput) { EXPECT_STREQ("foo", LookUpString); } -TEST(xptiApiTest, xptiRegisterPayloadGoodInput) { - xpti::payload_t p("foo", "foo.cpp", 10, 0, (void *)0xdeadbeef); +TEST_F(xptiApiTest, xptiRegisterPayloadGoodInput) { + xpti::payload_t p("foo", "foo.cpp", 10, 0, (void *)(0xdeadbeefull)); auto ID = xptiRegisterPayload(&p); EXPECT_NE(ID, xpti::invalid_id); @@ -67,14 +77,14 @@ TEST(xptiApiTest, xptiRegisterPayloadGoodInput) { EXPECT_EQ(p.uid.hash(), ID); } -TEST(xptiApiTest, xptiRegisterPayloadBadInput) { +TEST_F(xptiApiTest, xptiRegisterPayloadBadInput) { xpti::payload_t p; auto ID = xptiRegisterPayload(&p); EXPECT_EQ(ID, xpti::invalid_uid); } -TEST(xptiApiTest, xptiGetUniqueId) { +TEST_F(xptiApiTest, xptiGetUniqueId) { std::set IDs; for (int i = 0; i < 10; ++i) { auto ID = xptiGetUniqueId(); @@ -84,24 +94,24 @@ TEST(xptiApiTest, xptiGetUniqueId) { } } -TEST(xptiApiTest, xptiRegisterStreamBadInput) { +TEST_F(xptiApiTest, xptiRegisterStreamBadInput) { auto ID = xptiRegisterStream(nullptr); EXPECT_EQ(ID, (uint8_t)xpti::invalid_id); } -TEST(xptiApiTest, xptiRegisterStreamGoodInput) { +TEST_F(xptiApiTest, xptiRegisterStreamGoodInput) { auto ID = xptiRegisterStream("foo"); EXPECT_NE(ID, xpti::invalid_id); auto NewID = xptiRegisterStream("foo"); EXPECT_EQ(ID, NewID); } -TEST(xptiApiTest, xptiUnregisterStreamBadInput) { +TEST_F(xptiApiTest, xptiUnregisterStreamBadInput) { auto Result = xptiUnregisterStream(nullptr); EXPECT_EQ(Result, xpti::result_t::XPTI_RESULT_INVALIDARG); } -TEST(xptiApiTest, xptiUnregisterStreamGoodInput) { +TEST_F(xptiApiTest, xptiUnregisterStreamGoodInput) { auto ID = xptiRegisterStream("foo"); EXPECT_NE(ID, xpti::invalid_id); auto Result = xptiUnregisterStream("NoSuchStream"); @@ -111,7 +121,7 @@ TEST(xptiApiTest, xptiUnregisterStreamGoodInput) { EXPECT_EQ(NewResult, xpti::result_t::XPTI_RESULT_NOTFOUND); } -TEST(xptiApiTest, xptiMakeEventBadInput) { +TEST_F(xptiApiTest, xptiMakeEventBadInput) { xpti::payload_t P; auto Result = xptiMakeEvent(nullptr, &P, 0, (xpti::trace_activity_type_t)1, nullptr); @@ -125,7 +135,7 @@ TEST(xptiApiTest, xptiMakeEventBadInput) { EXPECT_EQ(Result, nullptr); } -TEST(xptiApiTest, xptiMakeEventGoodInput) { +TEST_F(xptiApiTest, xptiMakeEventGoodInput) { uint64_t instance; xpti::payload_t Payload("foo", "foo.cpp", 1, 0, (void *)13); auto Result = xptiMakeEvent("foo", &Payload, 0, @@ -139,37 +149,37 @@ TEST(xptiApiTest, xptiMakeEventGoodInput) { EXPECT_EQ(instance, 2); } -TEST(xptiApiTest, xptiFindEventBadInput) { +TEST_F(xptiApiTest, xptiFindEventBadInput) { auto Result = xptiFindEvent(0); EXPECT_EQ(Result, nullptr); Result = xptiFindEvent(1000000); EXPECT_EQ(Result, nullptr); } -TEST(xptiApiTest, xptiFindEventGoodInput) { - uint64_t Instance; +TEST_F(xptiApiTest, xptiFindEventGoodInput) { + uint64_t Instance = 0; xpti::payload_t Payload("foo", "foo.cpp", 1, 0, (void *)13); auto Result = xptiMakeEvent("foo", &Payload, 0, (xpti::trace_activity_type_t)1, &Instance); EXPECT_NE(Result, nullptr); - EXPECT_GT(Instance, 1); + EXPECT_EQ(Instance, 1); auto NewResult = xptiFindEvent(Result->unique_id); EXPECT_EQ(Result, NewResult); } -TEST(xptiApiTest, xptiQueryPayloadBadInput) { +TEST_F(xptiApiTest, xptiQueryPayloadBadInput) { auto Result = xptiQueryPayload(nullptr); EXPECT_EQ(Result, nullptr); } -TEST(xptiApiTest, xptiQueryPayloadGoodInput) { +TEST_F(xptiApiTest, xptiQueryPayloadGoodInput) { uint64_t instance; xpti::payload_t Payload("foo", "foo.cpp", 1, 0, (void *)13); auto Result = xptiMakeEvent("foo", &Payload, 0, (xpti::trace_activity_type_t)1, &instance); EXPECT_NE(Result, nullptr); - EXPECT_GT(instance, 1); + EXPECT_EQ(instance, 1); auto NewResult = xptiQueryPayload(Result); EXPECT_STREQ(Payload.name, NewResult->name); EXPECT_STREQ(Payload.source_file, NewResult->source_file); @@ -179,8 +189,8 @@ TEST(xptiApiTest, xptiQueryPayloadGoodInput) { EXPECT_EQ(Payload.line_no, NewResult->line_no); } -TEST(xptiApiTest, xptiQueryPayloadByUIDGoodInput) { - xpti::payload_t p("foo", "foo.cpp", 10, 0, (void *)0xdeadbeef); +TEST_F(xptiApiTest, xptiQueryPayloadByUIDGoodInput) { + xpti::payload_t p("foo", "foo.cpp", 10, 0, (void *)(0xdeadbeefull)); auto ID = xptiRegisterPayload(&p); EXPECT_NE(ID, xpti::invalid_id); @@ -192,7 +202,7 @@ TEST(xptiApiTest, xptiQueryPayloadByUIDGoodInput) { EXPECT_EQ(p.uid.hash(), pp->uid.hash()); } -TEST(xptiApiTest, xptiTraceEnabled) { +TEST_F(xptiApiTest, xptiTraceEnabled) { // If no env is set, this should be false // The state is determined at app startup // XPTI_TRACE_ENABLE=1 or 0 and XPTI_FRAMEWORK_DISPATCHER= @@ -201,39 +211,31 @@ TEST(xptiApiTest, xptiTraceEnabled) { EXPECT_EQ(Result, false); } -XPTI_CALLBACK_API void trace_point_callback(uint16_t trace_type, - xpti::trace_event_data_t *parent, - xpti::trace_event_data_t *event, - uint64_t instance, - const void *user_data) { - - if (user_data) - (*(int *)user_data) = 1; -} +void trace_point_callback(uint16_t /*trace_type*/, + xpti::trace_event_data_t * /*parent*/, + xpti::trace_event_data_t * /*event*/, + uint64_t /*instance*/, const void * /*user_data*/) {} -XPTI_CALLBACK_API void trace_point_callback2(uint16_t trace_type, - xpti::trace_event_data_t *parent, - xpti::trace_event_data_t *event, - uint64_t instance, - const void *user_data) { - if (user_data) - (*(int *)user_data) = 1; +void trace_point_callback2(uint16_t /*trace_type*/, + xpti::trace_event_data_t * /*parent*/, + xpti::trace_event_data_t * /*event*/, + uint64_t /*instance*/, const void *user_data) { + TPCB2Called = *static_cast(user_data); } -XPTI_CALLBACK_API void fn_callback(uint16_t trace_type, - xpti::trace_event_data_t *parent, - xpti::trace_event_data_t *event, - uint64_t instance, const void *user_data) { +void fn_callback(uint16_t /*trace_type*/, xpti::trace_event_data_t * /*parent*/, + xpti::trace_event_data_t * /*event*/, uint64_t /*instance*/, + const void * /*user_data*/) { func_callback_update++; } -TEST(xptiApiTest, xptiRegisterCallbackBadInput) { +TEST_F(xptiApiTest, xptiRegisterCallbackBadInput) { uint8_t StreamID = xptiRegisterStream("foo"); auto Result = xptiRegisterCallback(StreamID, 1, nullptr); EXPECT_EQ(Result, xpti::result_t::XPTI_RESULT_INVALIDARG); } -TEST(xptiApiTest, xptiRegisterCallbackGoodInput) { +TEST_F(xptiApiTest, xptiRegisterCallbackGoodInput) { uint64_t instance; xpti::payload_t Payload("foo", "foo.cpp", 1, 0, (void *)13); @@ -253,13 +255,13 @@ TEST(xptiApiTest, xptiRegisterCallbackGoodInput) { EXPECT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); } -TEST(xptiApiTest, xptiUnregisterCallbackBadInput) { +TEST_F(xptiApiTest, xptiUnregisterCallbackBadInput) { uint8_t StreamID = xptiRegisterStream("foo"); auto Result = xptiUnregisterCallback(StreamID, 1, nullptr); EXPECT_EQ(Result, xpti::result_t::XPTI_RESULT_INVALIDARG); } -TEST(xptiApiTest, xptiUnregisterCallbackGoodInput) { +TEST_F(xptiApiTest, xptiUnregisterCallbackGoodInput) { uint64_t instance; xpti::payload_t Payload("foo", "foo.cpp", 1, 0, (void *)13); @@ -280,7 +282,7 @@ TEST(xptiApiTest, xptiUnregisterCallbackGoodInput) { EXPECT_EQ(Result, xpti::result_t::XPTI_RESULT_UNDELETE); } -TEST(xptiApiTest, xptiNotifySubscribersBadInput) { +TEST_F(xptiApiTest, xptiNotifySubscribersBadInput) { uint8_t StreamID = xptiRegisterStream("foo"); auto Result = xptiNotifySubscribers(StreamID, 1, nullptr, nullptr, 0, nullptr); @@ -294,7 +296,7 @@ TEST(xptiApiTest, xptiNotifySubscribersBadInput) { EXPECT_EQ(Result, xpti::result_t::XPTI_RESULT_INVALIDARG); } -TEST(xptiApiTest, xptiNotifySubscribersGoodInput) { +TEST_F(xptiApiTest, xptiNotifySubscribersGoodInput) { uint64_t instance; xpti::payload_t Payload("foo", "foo.cpp", 1, 0, (void *)13); @@ -304,13 +306,17 @@ TEST(xptiApiTest, xptiNotifySubscribersGoodInput) { uint8_t StreamID = xptiRegisterStream("foo"); xptiForceSetTraceEnabled(true); - int foo_return = 0; + int FooUserData = 42; auto Result = xptiRegisterCallback(StreamID, 1, trace_point_callback2); - Result = xptiNotifySubscribers(StreamID, 1, nullptr, Event, 0, - (void *)(&foo_return)); EXPECT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); - EXPECT_EQ(foo_return, 1); + Result = xptiNotifySubscribers(StreamID, 1, nullptr, Event, 0, &FooUserData); + EXPECT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); + EXPECT_EQ(TPCB2Called, FooUserData); int tmp = func_callback_update; + Result = xptiRegisterCallback( + StreamID, static_cast(xpti::trace_point_type_t::function_begin), + fn_callback); + EXPECT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); // We allow notification with parent and event being null, only for trace // point type of function_begin/end; This test update checks for that Result = xptiNotifySubscribers( @@ -326,7 +332,7 @@ TEST(xptiApiTest, xptiNotifySubscribersGoodInput) { EXPECT_NE(tmp, func_callback_update); } -TEST(xptiApiTest, xptiAddMetadataBadInput) { +TEST_F(xptiApiTest, xptiAddMetadataBadInput) { uint64_t instance; xpti::payload_t Payload("foo", "foo.cpp", 1, 0, (void *)13); @@ -344,7 +350,7 @@ TEST(xptiApiTest, xptiAddMetadataBadInput) { EXPECT_EQ(Result, xpti::result_t::XPTI_RESULT_INVALIDARG); } -TEST(xptiApiTest, xptiAddMetadataGoodInput) { +TEST_F(xptiApiTest, xptiAddMetadataGoodInput) { uint64_t instance; xpti::payload_t Payload("foo", "foo.cpp", 1, 0, (void *)13); @@ -358,7 +364,7 @@ TEST(xptiApiTest, xptiAddMetadataGoodInput) { EXPECT_EQ(Result, xpti::result_t::XPTI_RESULT_DUPLICATE); } -TEST(xptiApiTest, xptiQueryMetadata) { +TEST_F(xptiApiTest, xptiQueryMetadata) { uint64_t instance; xpti::payload_t Payload("foo", "foo.cpp", 1, 0, (void *)13); @@ -373,7 +379,7 @@ TEST(xptiApiTest, xptiQueryMetadata) { EXPECT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); char *ts; - EXPECT_TRUE(md->size() > 1); + EXPECT_EQ(md->size(), 1); auto ID = (*md)[xptiRegisterString("foo1", &ts)]; auto str = xptiLookupString(ID); EXPECT_STREQ(str, "bar1"); diff --git a/xptifw/unit_test/xpti_correctness_tests.cpp b/xptifw/unit_test/xpti_correctness_tests.cpp index 1d58e65e4c1b2..5759c91d2b7f4 100644 --- a/xptifw/unit_test/xpti_correctness_tests.cpp +++ b/xptifw/unit_test/xpti_correctness_tests.cpp @@ -3,8 +3,8 @@ // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // -#include "xpti_trace_framework.h" -#include "xpti_trace_framework.hpp" +#include "xpti/xpti_trace_framework.h" +#include "xpti/xpti_trace_framework.hpp" #include #include @@ -13,24 +13,32 @@ #include #include -XPTI_CALLBACK_API void tpCallback(uint16_t trace_type, - xpti::trace_event_data_t *parent, - xpti::trace_event_data_t *event, - uint64_t instance, const void *user_data) { +static bool TPCBCalled = false; - if (user_data) - (*(int *)user_data) = trace_type; +class xptiCorrectnessTest : public ::testing::Test { +protected: + void SetUp() override { TPCBCalled = false; } + + void TearDown() override { xptiReset(); } +}; + +void tpCallback(uint16_t trace_type, xpti::trace_event_data_t *parent, + xpti::trace_event_data_t *event, uint64_t instance, + const void *user_data) { + TPCBCalled = true; } -#define NOTIFY(stream, tt, event, retval) \ +#define NOTIFY(stream, tt, event) \ { \ - xpti::result_t Result = xptiNotifySubscribers(stream, tt, nullptr, event, \ - 0, (void *)(&retval)); \ + int data; \ + xpti::result_t Result = \ + xptiNotifySubscribers(stream, tt, nullptr, event, 0, (void *)(&data)); \ EXPECT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); \ - EXPECT_EQ(retval, tt); \ + EXPECT_TRUE(TPCBCalled); \ + TPCBCalled = false; \ } -TEST(xptiCorrectnessTest, xptiMakeEvent) { +TEST_F(xptiCorrectnessTest, xptiMakeEvent) { uint64_t Instance = 0; xpti::payload_t p("foo", "foo.cpp", 1, 0, (void *)13); auto Result = @@ -47,7 +55,7 @@ TEST(xptiCorrectnessTest, xptiMakeEvent) { EXPECT_EQ(Result->reserved.payload->line_no, 1); } -TEST(xptiCorrectnessTest, xptiRegisterString) { +TEST_F(xptiCorrectnessTest, xptiRegisterString) { char *TStr = nullptr; auto ID = xptiRegisterString("foo", &TStr); EXPECT_NE(ID, xpti::invalid_id); @@ -70,11 +78,11 @@ void nestedTest(xpti::payload_t *p, std::vector &uids) { } } -TEST(xptiCorrectnessTest, xptiTracePointTest) { +TEST_F(xptiCorrectnessTest, xptiTracePointTest) { std::vector uids; - xpti::payload_t p("foo", "foo.cpp", 10, 0, (void *)0xdeadbeef); + xpti::payload_t p("foo", "foo.cpp", 10, 0, (void *)(0xdeadbeefull)); - auto ID = xptiRegisterPayload(&p); + (void)xptiRegisterPayload(&p); uint64_t id = xpti::invalid_uid; nestedTest(&p, uids); @@ -87,9 +95,9 @@ TEST(xptiCorrectnessTest, xptiTracePointTest) { } uids.clear(); - xpti::payload_t p1("bar", "foo.cpp", 15, 0, (void *)0xdeaddead); + xpti::payload_t p1("bar", "foo.cpp", 15, 0, (void *)(0xdeaddeadull)); - ID = xptiRegisterPayload(&p1); + (void)xptiRegisterPayload(&p1); id = xpti::invalid_uid; nestedTest(&p1, uids); @@ -102,7 +110,7 @@ TEST(xptiCorrectnessTest, xptiTracePointTest) { } } -TEST(xptiCorrectnessTest, xptiInitializeForDefaultTracePointTypes) { +TEST_F(xptiCorrectnessTest, xptiInitializeForDefaultTracePointTypes) { // We will test functionality of a subscriber // without actually creating a plugin uint8_t StreamID = xptiRegisterStream("test_foo"); @@ -162,7 +170,7 @@ TEST(xptiCorrectnessTest, xptiInitializeForDefaultTracePointTypes) { EXPECT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); } -TEST(xptiCorrectnessTest, xptiNotifySubscribersForDefaultTracePointTypes) { +TEST_F(xptiCorrectnessTest, xptiNotifySubscribersForDefaultTracePointTypes) { uint64_t Instance; xpti::payload_t p("foo", "foo.cpp", 1, 0, (void *)13); xptiForceSetTraceEnabled(true); @@ -170,81 +178,84 @@ TEST(xptiCorrectnessTest, xptiNotifySubscribersForDefaultTracePointTypes) { uint8_t StreamID = xptiRegisterStream("test_foo"); auto Result = xptiRegisterCallback( StreamID, (uint16_t)xpti::trace_point_type_t::graph_create, tpCallback); + ASSERT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); Result = xptiRegisterCallback( StreamID, (uint16_t)xpti::trace_point_type_t::node_create, tpCallback); + ASSERT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); Result = xptiRegisterCallback( StreamID, (uint16_t)xpti::trace_point_type_t::edge_create, tpCallback); + ASSERT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); Result = xptiRegisterCallback( StreamID, (uint16_t)xpti::trace_point_type_t::region_begin, tpCallback); + ASSERT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); Result = xptiRegisterCallback( StreamID, (uint16_t)xpti::trace_point_type_t::region_end, tpCallback); + ASSERT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); Result = xptiRegisterCallback( StreamID, (uint16_t)xpti::trace_point_type_t::task_begin, tpCallback); + ASSERT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); Result = xptiRegisterCallback( StreamID, (uint16_t)xpti::trace_point_type_t::task_end, tpCallback); + ASSERT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); Result = xptiRegisterCallback( StreamID, (uint16_t)xpti::trace_point_type_t::barrier_begin, tpCallback); + ASSERT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); Result = xptiRegisterCallback( StreamID, (uint16_t)xpti::trace_point_type_t::barrier_end, tpCallback); + ASSERT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); Result = xptiRegisterCallback( StreamID, (uint16_t)xpti::trace_point_type_t::lock_begin, tpCallback); + ASSERT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); Result = xptiRegisterCallback( StreamID, (uint16_t)xpti::trace_point_type_t::lock_end, tpCallback); + ASSERT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); Result = xptiRegisterCallback( StreamID, (uint16_t)xpti::trace_point_type_t::transfer_begin, tpCallback); + ASSERT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); Result = xptiRegisterCallback( StreamID, (uint16_t)xpti::trace_point_type_t::transfer_end, tpCallback); + ASSERT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); Result = xptiRegisterCallback( StreamID, (uint16_t)xpti::trace_point_type_t::thread_begin, tpCallback); + ASSERT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); Result = xptiRegisterCallback( StreamID, (uint16_t)xpti::trace_point_type_t::thread_end, tpCallback); + ASSERT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); Result = xptiRegisterCallback( StreamID, (uint16_t)xpti::trace_point_type_t::wait_begin, tpCallback); + ASSERT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); Result = xptiRegisterCallback( StreamID, (uint16_t)xpti::trace_point_type_t::wait_end, tpCallback); + ASSERT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); Result = xptiRegisterCallback( StreamID, (uint16_t)xpti::trace_point_type_t::signal, tpCallback); + ASSERT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); auto GE = xptiMakeEvent("foo", &p, 0, (xpti::trace_activity_type_t)1, &Instance); EXPECT_NE(GE, nullptr); - int FooReturn = 0; - NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::graph_create, GE, - FooReturn); - NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::node_create, GE, - FooReturn); - NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::edge_create, GE, - FooReturn); - NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::region_begin, GE, - FooReturn); - NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::region_end, GE, - FooReturn); - NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::task_begin, GE, - FooReturn); - NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::task_end, GE, FooReturn); - NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::barrier_begin, GE, - FooReturn); - NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::barrier_end, GE, - FooReturn); - NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::lock_begin, GE, - FooReturn); - NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::lock_end, GE, FooReturn); - NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::transfer_begin, GE, - FooReturn); - NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::transfer_end, GE, - FooReturn); - NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::thread_begin, GE, - FooReturn); - NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::thread_end, GE, - FooReturn); - NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::wait_begin, GE, - FooReturn); - NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::wait_end, GE, FooReturn); - NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::signal, GE, FooReturn); + NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::graph_create, GE); + NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::node_create, GE); + NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::edge_create, GE); + NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::region_begin, GE); + NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::region_end, GE); + NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::task_begin, GE); + NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::task_end, GE); + NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::barrier_begin, GE); + NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::barrier_end, GE); + NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::lock_begin, GE); + NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::lock_end, GE); + NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::transfer_begin, GE); + NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::transfer_end, GE); + NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::thread_begin, GE); + NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::thread_end, GE); + NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::wait_begin, GE); + NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::wait_end, GE); + NOTIFY(StreamID, (uint16_t)xpti::trace_point_type_t::signal, GE); } -TEST(xptiCorrectnessTest, xptiInitializeForUserDefinedTracePointTypes) { +TEST_F(xptiCorrectnessTest, xptiInitializeForUserDefinedTracePointTypes) { // We will test functionality of a subscriber // without actually creating a plugin uint8_t StreamID = xptiRegisterStream("test_foo"); @@ -269,7 +280,8 @@ TEST(xptiCorrectnessTest, xptiInitializeForUserDefinedTracePointTypes) { EXPECT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); } -TEST(xptiCorrectnessTest, xptiNotifySubscribersForUserDefinedTracePointTypes) { +TEST_F(xptiCorrectnessTest, + xptiNotifySubscribersForUserDefinedTracePointTypes) { uint64_t Instance; xpti::payload_t p("foo", "foo.cpp", 1, 0, (void *)13); xptiForceSetTraceEnabled(true); @@ -285,27 +297,26 @@ TEST(xptiCorrectnessTest, xptiNotifySubscribersForUserDefinedTracePointTypes) { auto TTType1 = xptiRegisterUserDefinedTracePoint("test_foo_tool", extn1_begin); auto Result = xptiRegisterCallback(StreamID, TTType1, tpCallback); - EXPECT_EQ(Result, xpti::result_t::XPTI_RESULT_DUPLICATE); + EXPECT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); auto TTType2 = xptiRegisterUserDefinedTracePoint("test_foo_tool", extn1_end); Result = xptiRegisterCallback(StreamID, TTType2, tpCallback); - EXPECT_EQ(Result, xpti::result_t::XPTI_RESULT_DUPLICATE); + EXPECT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); auto TTType3 = xptiRegisterUserDefinedTracePoint("test_foo_tool", extn2_begin); Result = xptiRegisterCallback(StreamID, TTType3, tpCallback); - EXPECT_EQ(Result, xpti::result_t::XPTI_RESULT_DUPLICATE); + EXPECT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); auto TTType4 = xptiRegisterUserDefinedTracePoint("test_foo_tool", extn2_end); Result = xptiRegisterCallback(StreamID, TTType4, tpCallback); - EXPECT_EQ(Result, xpti::result_t::XPTI_RESULT_DUPLICATE); + EXPECT_EQ(Result, xpti::result_t::XPTI_RESULT_SUCCESS); auto GE = xptiMakeEvent("foo", &p, 0, (xpti::trace_activity_type_t)1, &Instance); EXPECT_NE(GE, nullptr); - int FooReturn = 0; - NOTIFY(StreamID, TTType1, GE, FooReturn); - NOTIFY(StreamID, TTType2, GE, FooReturn); - NOTIFY(StreamID, TTType3, GE, FooReturn); - NOTIFY(StreamID, TTType4, GE, FooReturn); + NOTIFY(StreamID, TTType1, GE); + NOTIFY(StreamID, TTType2, GE); + NOTIFY(StreamID, TTType3, GE); + NOTIFY(StreamID, TTType4, GE); auto ToolID1 = XPTI_TOOL_ID(TTType1); auto ToolID2 = XPTI_TOOL_ID(TTType2); @@ -326,14 +337,14 @@ TEST(xptiCorrectnessTest, xptiNotifySubscribersForUserDefinedTracePointTypes) { EXPECT_NE(TpID4, TpID1); } -TEST(xptiCorrectnessTest, xptiGetUniqueId) { +TEST_F(xptiCorrectnessTest, xptiGetUniqueId) { auto Result = xptiGetUniqueId(); EXPECT_NE(Result, 0); auto Result1 = xptiGetUniqueId(); EXPECT_NE(Result, Result1); } -TEST(xptiCorrectnessTest, xptiUniversalIDTest) { +TEST_F(xptiCorrectnessTest, xptiUniversalIDTest) { xpti::uid_t Id0, Id1; uint64_t instance; /// Simulates the specialization of a Kernel as used by MKL where @@ -354,7 +365,7 @@ TEST(xptiCorrectnessTest, xptiUniversalIDTest) { EXPECT_NE(Id0.hash(), Id1.hash()); } -TEST(xptiCorrectnessTest, xptiUniversalIDRandomTest) { +TEST_F(xptiCorrectnessTest, xptiUniversalIDRandomTest) { using namespace std; set HashSet; random_device QRd; @@ -390,7 +401,7 @@ TEST(xptiCorrectnessTest, xptiUniversalIDRandomTest) { EXPECT_EQ(id1.hash(), id2.hash()); } -TEST(xptiCorrectnessTest, xptiUniversalIDMapTest) { +TEST_F(xptiCorrectnessTest, xptiUniversalIDMapTest) { using namespace std; map MapTest; random_device QRd; @@ -425,7 +436,7 @@ TEST(xptiCorrectnessTest, xptiUniversalIDMapTest) { } } -TEST(xptiCorrectnessTest, xptiUniversalIDUnorderedMapTest) { +TEST_F(xptiCorrectnessTest, xptiUniversalIDUnorderedMapTest) { using namespace std; unordered_map MapTest; random_device QRd; @@ -454,12 +465,11 @@ TEST(xptiCorrectnessTest, xptiUniversalIDUnorderedMapTest) { } } -TEST(xptiCorrectnessTest, xptiUserDefinedEventTypes) { - uint64_t Instance; +TEST_F(xptiCorrectnessTest, xptiUserDefinedEventTypes) { xpti::payload_t p("foo", "foo.cpp", 1, 0, (void *)13); xptiForceSetTraceEnabled(true); - uint8_t StreamID = xptiRegisterStream("test_foo"); + (void)xptiRegisterStream("test_foo"); typedef enum { extn_ev1 = XPTI_EVENT(0), extn_ev2 = XPTI_EVENT(1),