Skip to content

Commit 7c1d246

Browse files
mhalkjplehrjprotze
authored
Reland: [OpenMP] Add ompTest library to OpenMP (#154786)
Reland of #147381 Added changes to fix observed BuildBot failures: * CMake version (reduced minimum to `3.20`, was: `3.22`) * GoogleTest linking (missing `./build/lib/libllvm_gtest.a`) * Related header issue (missing `#include "llvm/Support/raw_os_ostream.h"`) Original message Description =========== OpenMP Tooling Interface Testing Library (ompTest) ompTest is a unit testing framework for testing OpenMP implementations. It offers a simple-to-use framework that allows a tester to check for OMPT events in addition to regular unit testing code, supported by linking against GoogleTest by default. It also facilitates writing concise tests while bridging the semantic gap between the unit under test and the OMPT-event testing. Background ========== This library has been developed to provide the means of testing OMPT implementations with reasonable effort. Especially, asynchronous or unordered events are supported and can be verified with ease, which may prove to be challenging with LIT-based tests. Additionally, since the assertions are part of the code being tested, ompTest can reference all corresponding variables during assertion. Basic Usage =========== OMPT event assertions are placed before the code, which shall be tested. These assertion can either be provided as one block or interleaved with the test code. There are two types of asserters: (1) sequenced "order-sensitive" and (2) set "unordered" assserters. Once the test is being run, the corresponding events are triggered by the OpenMP runtime and can be observed. Each of these observed events notifies asserters, which then determine if the test should pass or fail. Example (partial, interleaved) ============================== ```c++ int N = 100000; int a[N]; int b[N]; OMPT_ASSERT_SEQUENCE(Target, TARGET, BEGIN, 0); OMPT_ASSERT_SEQUENCE(TargetDataOp, ALLOC, N * sizeof(int)); // a ? OMPT_ASSERT_SEQUENCE(TargetDataOp, H2D, N * sizeof(int), &a); OMPT_ASSERT_SEQUENCE(TargetDataOp, ALLOC, N * sizeof(int)); // b ? OMPT_ASSERT_SEQUENCE(TargetDataOp, H2D, N * sizeof(int), &b); OMPT_ASSERT_SEQUENCE(TargetSubmit, 1); OMPT_ASSERT_SEQUENCE(TargetDataOp, D2H, N * sizeof(int), nullptr, &b); OMPT_ASSERT_SEQUENCE(TargetDataOp, D2H, N * sizeof(int), nullptr, &a); OMPT_ASSERT_SEQUENCE(TargetDataOp, DELETE); OMPT_ASSERT_SEQUENCE(TargetDataOp, DELETE); OMPT_ASSERT_SEQUENCE(Target, TARGET, END, 0); #pragma omp target parallel for { for (int j = 0; j < N; j++) a[j] = b[j]; } ``` References ========== This work has been presented at SC'24 workshops, see: https://ieeexplore.ieee.org/document/10820689 Current State and Future Work ============================= ompTest's development was mostly device-centric and aimed at OMPT device callbacks and device-side tracing. Consequentially, a substantial part of host-related events or features may not be supported in its current state. However, we are confident that the related functionality can be added and ompTest provides a general foundation for future OpenMP and especially OMPT testing. This PR will allow us to upstream the corresponding features, like OMPT device-side tracing in the future with significantly reduced risk of introducing regressions in the process. Build ===== ompTest is linked against LLVM's GoogleTest by default, but can also be built 'standalone'. Additionally, it comes with a set of unit tests, which in turn require GoogleTest (overriding a standalone build). The unit tests are added to the `check-openmp` target. Use the following parameters to perform the corresponding build: `LIBOMPTEST_BUILD_STANDALONE` (Default: ${OPENMP_STANDALONE_BUILD}) `LIBOMPTEST_BUILD_UNITTESTS` (Default: OFF) --------- Co-authored-by: Jan-Patrick Lehr <[email protected]> Co-authored-by: Joachim <[email protected]> Co-authored-by: Joachim Jenke <[email protected]>
1 parent 15a192c commit 7c1d246

32 files changed

+6741
-0
lines changed

openmp/README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ There are following check-* make targets for tests.
369369

370370
- ``check-ompt`` (ompt tests under runtime/test/ompt)
371371
- ``check-ompt-multiplex`` (ompt multiplex tests under tools/multiplex/tests)
372+
- ``check-ompt-omptest`` (ompt omptest tests under tools/omptest/tests)
372373
- ``check-libarcher`` (libarcher tests under tools/archer/tests)
373374
- ``check-libomp`` (libomp tests under runtime/test. This includes check-ompt tests too)
374375
- ``check-libomptarget-*`` (libomptarget tests for specific target under libomptarget/test)

openmp/tools/archer/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ if(LIBOMP_OMPT_SUPPORT AND LIBOMP_ARCHER_SUPPORT)
1515
target_link_libraries(archer ${CMAKE_DL_LIBS})
1616
add_library(archer_static STATIC ompt-tsan.cpp)
1717

18+
if(TARGET cxx-headers)
19+
add_dependencies(archer cxx-headers)
20+
add_dependencies(archer_static cxx-headers)
21+
endif()
22+
23+
if(TARGET cxx_shared)
24+
add_dependencies(archer cxx_shared)
25+
add_dependencies(archer_static cxx_shared)
26+
endif()
27+
28+
if(TARGET cxxabi_shared)
29+
add_dependencies(archer cxxabi_shared)
30+
add_dependencies(archer_static cxxabi_shared)
31+
endif()
32+
1833
install(TARGETS archer archer_static
1934
LIBRARY DESTINATION ${OPENMP_INSTALL_LIBDIR}
2035
ARCHIVE DESTINATION ${OPENMP_INSTALL_LIBDIR})

openmp/tools/omptest/CMakeLists.txt

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
##===----------------------------------------------------------------------===##
2+
#
3+
# Build OMPT unit testing library: ompTest
4+
#
5+
##===----------------------------------------------------------------------===##
6+
7+
cmake_minimum_required(VERSION 3.20)
8+
project(omptest LANGUAGES CXX)
9+
10+
option(LIBOMPTEST_BUILD_STANDALONE
11+
"Build ompTest 'standalone', i.e. w/o GoogleTest."
12+
${OPENMP_STANDALONE_BUILD})
13+
option(LIBOMPTEST_BUILD_UNITTESTS
14+
"Build ompTest's unit tests, requires GoogleTest." OFF)
15+
16+
# In absence of corresponding OMPT support: exit early
17+
if(NOT ${LIBOMP_OMPT_SUPPORT})
18+
return()
19+
endif()
20+
21+
include(CMakePackageConfigHelpers)
22+
23+
set(OMPTEST_HEADERS
24+
./include/AssertMacros.h
25+
./include/InternalEvent.h
26+
./include/InternalEventCommon.h
27+
./include/Logging.h
28+
./include/OmptAliases.h
29+
./include/OmptAsserter.h
30+
./include/OmptAssertEvent.h
31+
./include/OmptCallbackHandler.h
32+
./include/OmptTester.h
33+
./include/OmptTesterGlobals.h
34+
)
35+
36+
add_library(omptest
37+
SHARED
38+
39+
${OMPTEST_HEADERS}
40+
./src/InternalEvent.cpp
41+
./src/InternalEventOperators.cpp
42+
./src/Logging.cpp
43+
./src/OmptAsserter.cpp
44+
./src/OmptAssertEvent.cpp
45+
./src/OmptCallbackHandler.cpp
46+
./src/OmptTester.cpp
47+
)
48+
49+
# Target: ompTest library
50+
# On (implicit) request of GoogleTest, link against the one provided with LLVM.
51+
if ((NOT LIBOMPTEST_BUILD_STANDALONE) OR LIBOMPTEST_BUILD_UNITTESTS)
52+
# Check if standalone build was requested together with unittests
53+
if (LIBOMPTEST_BUILD_STANDALONE)
54+
# Emit warning: this build actually depends on LLVM's GoogleTest
55+
message(WARNING "LIBOMPTEST_BUILD_STANDALONE and LIBOMPTEST_BUILD_UNITTESTS"
56+
" requested simultaneously.\n"
57+
"Linking against LLVM's GoogleTest library archives.\n"
58+
"Disable LIBOMPTEST_BUILD_UNITTESTS to perform an actual"
59+
" standalone build.")
60+
# Explicitly disable LIBOMPTEST_BUILD_STANDALONE
61+
set(LIBOMPTEST_BUILD_STANDALONE OFF)
62+
endif()
63+
64+
# Make sure target llvm_gtest is available
65+
if (NOT TARGET llvm_gtest)
66+
message(FATAL_ERROR "Required target not found: llvm_gtest")
67+
endif()
68+
69+
# Add llvm_gtest as dependency
70+
add_dependencies(omptest llvm_gtest)
71+
72+
# Link llvm_gtest as whole-archive to expose required symbols
73+
set(GTEST_LINK_CMD "-Wl,--whole-archive" llvm_gtest
74+
"-Wl,--no-whole-archive" LLVMSupport)
75+
76+
# Add GoogleTest-based header
77+
target_sources(omptest PRIVATE ./include/OmptTesterGoogleTest.h)
78+
79+
# Add LLVM-provided GoogleTest include directories.
80+
target_include_directories(omptest PRIVATE
81+
${LLVM_THIRD_PARTY_DIR}/unittest/googletest/include)
82+
83+
# TODO: Re-visit ABI breaking checks, disable for now.
84+
target_compile_definitions(omptest PUBLIC
85+
-DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING)
86+
87+
# Link against gtest and gtest_main
88+
target_link_libraries(omptest PRIVATE ${GTEST_LINK_CMD})
89+
else()
90+
# Add 'standalone' compile definitions
91+
target_compile_definitions(omptest PRIVATE
92+
-DOPENMP_LIBOMPTEST_BUILD_STANDALONE)
93+
94+
# Add 'standalone' source files
95+
target_sources(omptest PRIVATE
96+
./include/OmptTesterStandalone.h
97+
./src/OmptTesterStandalone.cpp)
98+
endif()
99+
100+
if(TARGET cxx-headers)
101+
add_dependencies(omptest cxx-headers)
102+
endif()
103+
104+
if(TARGET cxx_shared)
105+
add_dependencies(omptest cxx_shared)
106+
endif()
107+
108+
if(TARGET cxxabi_shared)
109+
add_dependencies(omptest cxxabi_shared)
110+
endif()
111+
112+
# Add common include directories.
113+
target_include_directories(omptest PUBLIC
114+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
115+
$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${LIBOMP_HEADERS_INSTALL_PATH}/omptest>
116+
)
117+
118+
target_compile_features(omptest PRIVATE cxx_std_17)
119+
120+
# Create and install package configuration files.
121+
configure_package_config_file(
122+
${CMAKE_CURRENT_SOURCE_DIR}/cmake/omptest-config.cmake.in
123+
${CMAKE_CURRENT_BINARY_DIR}/cmake/omptest-config.cmake
124+
INSTALL_DESTINATION "${OPENMP_INSTALL_LIBDIR}/cmake/openmp/omptest"
125+
)
126+
127+
install(FILES ${omptest_BINARY_DIR}/cmake/omptest-config.cmake
128+
DESTINATION "${OPENMP_INSTALL_LIBDIR}/cmake/openmp/omptest")
129+
130+
# Install libomptest header files: Copy header-files from include dir
131+
install(DIRECTORY ./include/
132+
DESTINATION "${LIBOMP_HEADERS_INSTALL_PATH}/omptest"
133+
FILES_MATCHING PATTERN "*.h")
134+
135+
# Install library and export targets.
136+
# Note: find_package(omptest) may require setting of PATH_SUFFIXES
137+
# Example: "lib/cmake/openmp/omptest", this is due to the install location
138+
install(TARGETS omptest
139+
EXPORT OPENMPomptest
140+
LIBRARY COMPONENT omptest
141+
DESTINATION "${OPENMP_INSTALL_LIBDIR}"
142+
INCLUDES DESTINATION "${LIBOMP_HEADERS_INSTALL_PATH}/omptest")
143+
144+
# Allow to link omptest by using: target_link_libraries( ... omptest::omptest)
145+
# Additionally, it automatically propagates the include directory.
146+
install(EXPORT OPENMPomptest
147+
DESTINATION "${OPENMP_INSTALL_LIBDIR}/cmake/openmp/omptest"
148+
NAMESPACE omptest::
149+
FILE omptest-targets.cmake)
150+
151+
# Discover unit tests (added to check-openmp)
152+
if(LIBOMPTEST_BUILD_UNITTESTS)
153+
add_subdirectory(test)
154+
endif()

0 commit comments

Comments
 (0)