Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions openmp/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ There are following check-* make targets for tests.

- ``check-ompt`` (ompt tests under runtime/test/ompt)
- ``check-ompt-multiplex`` (ompt multiplex tests under tools/multiplex/tests)
- ``check-ompt-omptest`` (ompt omptest tests under tools/omptest/tests)
- ``check-libarcher`` (libarcher tests under tools/archer/tests)
- ``check-libomp`` (libomp tests under runtime/test. This includes check-ompt tests too)
- ``check-libomptarget-*`` (libomptarget tests for specific target under libomptarget/test)
Expand Down
15 changes: 15 additions & 0 deletions openmp/tools/archer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ if(LIBOMP_OMPT_SUPPORT AND LIBOMP_ARCHER_SUPPORT)
target_link_libraries(archer ${CMAKE_DL_LIBS})
add_library(archer_static STATIC ompt-tsan.cpp)

if(TARGET cxx-headers)
add_dependencies(archer cxx-headers)
add_dependencies(archer_static cxx-headers)
endif()

if(TARGET cxx_shared)
add_dependencies(archer cxx_shared)
add_dependencies(archer_static cxx_shared)
endif()

if(TARGET cxxabi_shared)
add_dependencies(archer cxxabi_shared)
add_dependencies(archer_static cxxabi_shared)
endif()

install(TARGETS archer archer_static
LIBRARY DESTINATION ${OPENMP_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${OPENMP_INSTALL_LIBDIR})
Expand Down
154 changes: 154 additions & 0 deletions openmp/tools/omptest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
##===----------------------------------------------------------------------===##
#
# Build OMPT unit testing library: ompTest
#
##===----------------------------------------------------------------------===##

cmake_minimum_required(VERSION 3.20)
project(omptest LANGUAGES CXX)

option(LIBOMPTEST_BUILD_STANDALONE
"Build ompTest 'standalone', i.e. w/o GoogleTest."
${OPENMP_STANDALONE_BUILD})
option(LIBOMPTEST_BUILD_UNITTESTS
"Build ompTest's unit tests, requires GoogleTest." OFF)

# In absence of corresponding OMPT support: exit early
if(NOT ${LIBOMP_OMPT_SUPPORT})
return()
endif()

include(CMakePackageConfigHelpers)

set(OMPTEST_HEADERS
./include/AssertMacros.h
./include/InternalEvent.h
./include/InternalEventCommon.h
./include/Logging.h
./include/OmptAliases.h
./include/OmptAsserter.h
./include/OmptAssertEvent.h
./include/OmptCallbackHandler.h
./include/OmptTester.h
./include/OmptTesterGlobals.h
)

add_library(omptest
SHARED

${OMPTEST_HEADERS}
./src/InternalEvent.cpp
./src/InternalEventOperators.cpp
./src/Logging.cpp
./src/OmptAsserter.cpp
./src/OmptAssertEvent.cpp
./src/OmptCallbackHandler.cpp
./src/OmptTester.cpp
)

# Target: ompTest library
# On (implicit) request of GoogleTest, link against the one provided with LLVM.
if ((NOT LIBOMPTEST_BUILD_STANDALONE) OR LIBOMPTEST_BUILD_UNITTESTS)
# Check if standalone build was requested together with unittests
if (LIBOMPTEST_BUILD_STANDALONE)
# Emit warning: this build actually depends on LLVM's GoogleTest
message(WARNING "LIBOMPTEST_BUILD_STANDALONE and LIBOMPTEST_BUILD_UNITTESTS"
" requested simultaneously.\n"
"Linking against LLVM's GoogleTest library archives.\n"
"Disable LIBOMPTEST_BUILD_UNITTESTS to perform an actual"
" standalone build.")
# Explicitly disable LIBOMPTEST_BUILD_STANDALONE
set(LIBOMPTEST_BUILD_STANDALONE OFF)
endif()

# Make sure target llvm_gtest is available
if (NOT TARGET llvm_gtest)
message(FATAL_ERROR "Required target not found: llvm_gtest")
endif()

# Add llvm_gtest as dependency
add_dependencies(omptest llvm_gtest)

# Link llvm_gtest as whole-archive to expose required symbols
set(GTEST_LINK_CMD "-Wl,--whole-archive" llvm_gtest
"-Wl,--no-whole-archive" LLVMSupport)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really need this now that you're using the llvm_gtest target? None of the other places that use llvm_gtest require this. Why does this one?

Copy link
Contributor Author

@mhalk mhalk Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually "yes", ompTest should be usable like an OMPT-extended version of GoogleTest.
Thus, my goal is pulling in all symbols, but I'm by no means an expert on this matter.

The issue is that without it, there are linker errors when a user-test links against libomptest.so.
That's because of missing symbols, like e.g. testing::Test::Test() or testing::internal::GTestLog::~GTestLog().
Advice on how to improve this part would be greatly appreciated.

One possibility I saw was to use an intermediate build file, similar to this:

  [...]

  set(GTEST_OBJECT "build/third-party/unittest/CMakeFiles/llvm_gtest.dir/googletest/src/gtest-all.cc.o")

  # Add GoogleTest-based header and merge pre-built object
  target_sources(omptest PRIVATE
    ./include/OmptTesterGoogleTest.h
    "${GTEST_OBJECT}")

  [...]

Apart from locating that file properly, I'm not sure which other dependencies this approach would imply (maybe compiler-rt?).


# Add GoogleTest-based header
target_sources(omptest PRIVATE ./include/OmptTesterGoogleTest.h)

# Add LLVM-provided GoogleTest include directories.
target_include_directories(omptest PRIVATE
${LLVM_THIRD_PARTY_DIR}/unittest/googletest/include)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? Shouldn't this be covered on the PUBLIC target_include_directories on llvm_gtest?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think you're right. AFAICT this can be removed.


# TODO: Re-visit ABI breaking checks, disable for now.
target_compile_definitions(omptest PUBLIC
-DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? This looks very fishy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I had build failures without it, but this seems to depend on how you link LLVMSupport.
It seems to be implicitly linked as PRIVATE but needs PUBLIC from what I found out during tests.


# Link against gtest and gtest_main
target_link_libraries(omptest PRIVATE ${GTEST_LINK_CMD})
else()
# Add 'standalone' compile definitions
target_compile_definitions(omptest PRIVATE
-DOPENMP_LIBOMPTEST_BUILD_STANDALONE)

# Add 'standalone' source files
target_sources(omptest PRIVATE
./include/OmptTesterStandalone.h
./src/OmptTesterStandalone.cpp)
endif()

if(TARGET cxx-headers)
add_dependencies(omptest cxx-headers)
endif()

if(TARGET cxx_shared)
add_dependencies(omptest cxx_shared)
endif()

if(TARGET cxxabi_shared)
add_dependencies(omptest cxxabi_shared)
endif()

# Add common include directories.
target_include_directories(omptest PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${LIBOMP_HEADERS_INSTALL_PATH}/omptest>
)

target_compile_features(omptest PRIVATE cxx_std_17)

# Create and install package configuration files.
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/omptest-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake/omptest-config.cmake
INSTALL_DESTINATION "${OPENMP_INSTALL_LIBDIR}/cmake/openmp/omptest"
)

install(FILES ${omptest_BINARY_DIR}/cmake/omptest-config.cmake
DESTINATION "${OPENMP_INSTALL_LIBDIR}/cmake/openmp/omptest")

# Install libomptest header files: Copy header-files from include dir
install(DIRECTORY ./include/
DESTINATION "${LIBOMP_HEADERS_INSTALL_PATH}/omptest"
FILES_MATCHING PATTERN "*.h")

# Install library and export targets.
# Note: find_package(omptest) may require setting of PATH_SUFFIXES
# Example: "lib/cmake/openmp/omptest", this is due to the install location
install(TARGETS omptest
EXPORT OPENMPomptest
LIBRARY COMPONENT omptest
DESTINATION "${OPENMP_INSTALL_LIBDIR}"
INCLUDES DESTINATION "${LIBOMP_HEADERS_INSTALL_PATH}/omptest")

# Allow to link omptest by using: target_link_libraries( ... omptest::omptest)
# Additionally, it automatically propagates the include directory.
install(EXPORT OPENMPomptest
DESTINATION "${OPENMP_INSTALL_LIBDIR}/cmake/openmp/omptest"
NAMESPACE omptest::
FILE omptest-targets.cmake)

# Discover unit tests (added to check-openmp)
if(LIBOMPTEST_BUILD_UNITTESTS)
add_subdirectory(test)
endif()
Loading
Loading