Skip to content

Commit f024da4

Browse files
mhalkjplehr
andcommitted
[OpenMP] Add ompTest library to OpenMP
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) ============================== 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); { 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: OFF) `LIBOMPTEST_BUILD_UNITTESTS` (Default: OFF) --------- Co-authored-by: Jan-Patrick Lehr <JanPatrick.Lehr@amd.com>
1 parent 7451e4c commit f024da4

31 files changed

+6665
-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/omptest/CMakeLists.txt

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
##===----------------------------------------------------------------------===##
2+
#
3+
# Build OMPT unit testing library: ompTest
4+
#
5+
##===----------------------------------------------------------------------===##
6+
7+
cmake_minimum_required(VERSION 3.22)
8+
project(omptest LANGUAGES CXX)
9+
10+
option(LIBOMPTEST_BUILD_STANDALONE
11+
"Build ompTest 'standalone', i.e. w/o GoogleTest." OFF)
12+
option(LIBOMPTEST_BUILD_UNITTESTS
13+
"Build ompTest's unit tests , requires GoogleTest." OFF)
14+
15+
# In absence of corresponding OMPT support: exit early
16+
if(NOT ${LIBOMPTARGET_OMPT_SUPPORT})
17+
return()
18+
endif()
19+
20+
set(OMPTEST_HEADERS
21+
./include/AssertMacros.h
22+
./include/InternalEvent.h
23+
./include/InternalEventCommon.h
24+
./include/Logging.h
25+
./include/OmptAliases.h
26+
./include/OmptAsserter.h
27+
./include/OmptAssertEvent.h
28+
./include/OmptCallbackHandler.h
29+
./include/OmptTester.h
30+
./include/OmptTesterGlobals.h
31+
)
32+
33+
add_library(omptest
34+
SHARED
35+
36+
${OMPTEST_HEADERS}
37+
./src/InternalEvent.cpp
38+
./src/InternalEventOperators.cpp
39+
./src/Logging.cpp
40+
./src/OmptAsserter.cpp
41+
./src/OmptAssertEvent.cpp
42+
./src/OmptCallbackHandler.cpp
43+
./src/OmptTester.cpp
44+
)
45+
46+
# Target: ompTest library
47+
# On (implicit) request of GoogleTest, link against the one provided with LLVM.
48+
if ((NOT LIBOMPTEST_BUILD_STANDALONE) OR LIBOMPTEST_BUILD_UNITTESTS)
49+
# Check if standalone build was requested together with unittests
50+
if (LIBOMPTEST_BUILD_STANDALONE)
51+
# Emit warning: this build actually depends on LLVM's GoogleTest
52+
message(WARNING "LIBOMPTEST_BUILD_STANDALONE and LIBOMPTEST_BUILD_UNITTESTS"
53+
" requested simultaneously.\n"
54+
"Linking against LLVM's GoogleTest library archives.\n"
55+
"Disable LIBOMPTEST_BUILD_UNITTESTS to perform an actual"
56+
" standalone build.")
57+
# Explicitly disable LIBOMPTEST_BUILD_STANDALONE
58+
set(LIBOMPTEST_BUILD_STANDALONE OFF)
59+
endif()
60+
61+
# Use LLVM's gtest library archive
62+
set(GTEST_LIB "${LLVM_BINARY_DIR}/lib/libllvm_gtest.a")
63+
# Link gtest as whole-archive to expose required symbols
64+
set(GTEST_LINK_CMD "-Wl,--whole-archive" ${GTEST_LIB}
65+
"-Wl,--no-whole-archive" LLVMSupport)
66+
67+
# Add GoogleTest-based header
68+
target_sources(omptest PRIVATE ./include/OmptTesterGoogleTest.h)
69+
70+
# Add LLVM-provided GoogleTest include directories.
71+
target_include_directories(omptest PRIVATE
72+
${LLVM_THIRD_PARTY_DIR}/unittest/googletest/include)
73+
74+
# TODO: Re-visit ABI breaking checks, disable for now.
75+
target_compile_definitions(omptest PUBLIC
76+
-DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING)
77+
78+
# Link against gtest and gtest_main
79+
target_link_libraries(omptest PRIVATE ${GTEST_LINK_CMD})
80+
else()
81+
# Add 'standalone' compile definitions
82+
target_compile_definitions(omptest PRIVATE
83+
-DOPENMP_LIBOMPTEST_BUILD_STANDALONE)
84+
85+
# Add 'standalone' source files
86+
target_sources(omptest PRIVATE
87+
./include/OmptTesterStandalone.h
88+
./src/OmptTesterStandalone.cpp)
89+
endif()
90+
91+
# Add common include directories.
92+
target_include_directories(omptest PRIVATE
93+
./include
94+
${LIBOMPTARGET_INCLUDE_DIR})
95+
target_compile_features(omptest PRIVATE cxx_std_17)
96+
97+
# Create and install package configuration files.
98+
configure_file(
99+
${omptest_SOURCE_DIR}/cmake/omptest-config.cmake.in
100+
${omptest_BINARY_DIR}/cmake/omptest-config.cmake @ONLY)
101+
102+
install(FILES ${omptest_BINARY_DIR}/cmake/omptest-config.cmake
103+
DESTINATION "${OPENMP_INSTALL_LIBDIR}/cmake/openmp/omptest")
104+
105+
# Install libomptest header files: Copy header-files from include dir
106+
install(DIRECTORY ./include
107+
DESTINATION "${LIBOMP_HEADERS_INSTALL_PATH}/omptest"
108+
FILES_MATCHING PATTERN "*.h")
109+
110+
install(TARGETS omptest LIBRARY COMPONENT omptest
111+
DESTINATION "${OPENMP_INSTALL_LIBDIR}")
112+
113+
# Discover unit tests (added to check-openmp)
114+
if(LIBOMPTEST_BUILD_UNITTESTS)
115+
add_subdirectory(test)
116+
endif()

0 commit comments

Comments
 (0)