-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[OpenMP] Add libomp unit test infrastructure #168063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -174,17 +174,28 @@ if(NOT WIN32) | |
| endif() | ||
|
|
||
| # Add the OpenMP library | ||
| libomp_get_ldflags(LIBOMP_CONFIGURED_LDFLAGS) | ||
|
|
||
| # First, create an OBJECT library with all the runtime sources. | ||
| # This allows both the main library and unit tests to link against the same | ||
| # compiled objects. | ||
| add_library(omp_objects OBJECT ${LIBOMP_SOURCE_FILES}) | ||
ro-i marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| set_property(TARGET omp_objects PROPERTY FOLDER "OpenMP/Libraries") | ||
| set_property(TARGET omp_objects PROPERTY POSITION_INDEPENDENT_CODE ON) | ||
| # Export the omp_objects target so unit tests can use it | ||
| set(LIBOMP_OBJECTS_TARGET omp_objects PARENT_SCOPE) | ||
ro-i marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| libomp_get_ldflags(LIBOMP_CONFIGURED_LDFLAGS) | ||
| libomp_get_libflags(LIBOMP_CONFIGURED_LIBFLAGS) | ||
| # Build libomp library. Add LLVMSupport dependency if building in-tree with libomptarget profiling enabled. | ||
|
|
||
| # Build libomp library. Add LLVMSupport dependency if building in-tree with | ||
| # libomptarget profiling enabled. | ||
| if(OPENMP_STANDALONE_BUILD OR (NOT OPENMP_ENABLE_LIBOMP_PROFILING)) | ||
| add_library(omp ${LIBOMP_LIBRARY_KIND} ${LIBOMP_SOURCE_FILES}) | ||
| add_library(omp ${LIBOMP_LIBRARY_KIND} $<TARGET_OBJECTS:omp_objects>) | ||
|
||
| set_property(TARGET omp PROPERTY FOLDER "OpenMP/Libraries") | ||
| # Linking command will include libraries in LIBOMP_CONFIGURED_LIBFLAGS | ||
| target_link_libraries(omp ${LIBOMP_CONFIGURED_LIBFLAGS} ${LIBOMP_DL_LIBS}) | ||
| else() | ||
| add_llvm_library(omp ${LIBOMP_LIBRARY_KIND} ${LIBOMP_SOURCE_FILES} PARTIAL_SOURCES_INTENDED | ||
| add_llvm_library(omp ${LIBOMP_LIBRARY_KIND} $<TARGET_OBJECTS:omp_objects> PARTIAL_SOURCES_INTENDED | ||
| LINK_LIBS ${LIBOMP_CONFIGURED_LIBFLAGS} ${LIBOMP_DL_LIBS} | ||
| LINK_COMPONENTS Support | ||
| BUILDTREE_ONLY | ||
|
|
@@ -200,6 +211,31 @@ if(${LIBOMP_USE_HWLOC}) | |
| ) | ||
| endif() | ||
|
|
||
| # Build a testing version of libomp that exports all symbols for unit tests. | ||
| # This library uses the same compiled objects as libomp, but with all symbols | ||
| # exported to allow testing internal functions. | ||
| if(NOT WIN32 AND NOT STUBS_LIBRARY) | ||
| set(LIBOMP_TEST_LDFLAGS ${LIBOMP_CONFIGURED_LDFLAGS}) | ||
| # Replace the libomp exports with the test exports exporting all symbols. | ||
| if(LIBOMP_HAVE_VERSION_SCRIPT_FLAG) | ||
| string(REPLACE "${LIBOMP_SRC_DIR}/exports_so.txt" | ||
| "${LIBOMP_SRC_DIR}/exports_test_so.txt" | ||
| LIBOMP_TEST_LDFLAGS "${LIBOMP_TEST_LDFLAGS}") | ||
|
||
| endif() | ||
|
|
||
| # Create the testing library from the same objects as libomp. | ||
| add_library(omp_testing SHARED $<TARGET_OBJECTS:omp_objects>) | ||
|
||
| set_property(TARGET omp_testing PROPERTY FOLDER "OpenMP/Libraries") | ||
| target_link_libraries(omp_testing ${LIBOMP_CONFIGURED_LIBFLAGS} ${LIBOMP_DL_LIBS}) | ||
ro-i marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| set_target_properties(omp_testing PROPERTIES | ||
| PREFIX "" SUFFIX "" OUTPUT_NAME "libomp_testing${LIBOMP_LIBRARY_SUFFIX}" | ||
| LINK_FLAGS "${LIBOMP_TEST_LDFLAGS}" | ||
| LINKER_LANGUAGE ${LIBOMP_LINKER_LANGUAGE} | ||
| EXCLUDE_FROM_ALL TRUE # Don't build by default, only when tests need it | ||
| ) | ||
| add_dependencies(omp_testing libomp-needed-headers) | ||
ro-i marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| endif() | ||
|
|
||
| if(OPENMP_MSVC_NAME_SCHEME) | ||
| if(uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") | ||
| set(LIBOMP_PDB_NAME ${LIBOMP_DEFAULT_LIB_NAME}${MSVC_TOOLS_VERSION}d.${LIBOMP_ARCH}) | ||
|
|
@@ -296,6 +332,7 @@ set(LIBOMPTARGET_OPENMP_HOST_RTL_FOLDER "${LIBOMP_LIBRARY_DIR}" CACHE STRING | |
| # objects depend on : .inc files | ||
| add_custom_target(libomp-needed-headers DEPENDS kmp_i18n_id.inc kmp_i18n_default.inc) | ||
| set_target_properties(libomp-needed-headers PROPERTIES FOLDER "OpenMP/Sourcegenning") | ||
| add_dependencies(omp_objects libomp-needed-headers) | ||
| add_dependencies(omp libomp-needed-headers) | ||
ro-i marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Windows specific build rules | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| add_custom_target(OpenMPUnitTests) | ||
| set_target_properties(OpenMPUnitTests PROPERTIES FOLDER "OpenMP/Tests") | ||
|
|
||
| if(NOT TARGET llvm_gtest) | ||
ro-i marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| message(WARNING "OpenMP unittests disabled due to GTest being unavailable; " | ||
| "Try LLVM_INSTALL_GTEST=ON for the LLVM build") | ||
| return() | ||
| endif() | ||
| if(NOT TARGET omp_testing) | ||
| message(WARNING "OpenMP unittests disabled due to omp_testing library being unavailable") | ||
| return() | ||
| endif() | ||
|
|
||
| function(add_openmp_unittest test_dirname) | ||
ro-i marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| add_unittest(OpenMPUnitTests ${test_dirname} ${ARGN}) | ||
|
|
||
| # Link against the testing library which exports all symbols. | ||
| target_link_libraries(${test_dirname} PRIVATE omp_testing) | ||
| add_dependencies(${test_dirname} omp_testing) | ||
|
|
||
| target_include_directories(${test_dirname} PRIVATE | ||
| ${LIBOMP_INCLUDE_DIR} | ||
| ${LIBOMP_SRC_DIR} | ||
| ) | ||
| endfunction() | ||
|
|
||
| configure_lit_site_cfg( | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in | ||
| ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py | ||
| MAIN_CONFIG | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py | ||
| ) | ||
|
|
||
| add_openmp_testsuite( | ||
| check-libomp-unit | ||
| "Running libomp unit tests" | ||
| ${CMAKE_CURRENT_BINARY_DIR} | ||
| EXCLUDE_FROM_CHECK_ALL | ||
| DEPENDS OpenMPUnitTests omp | ||
ro-i marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| add_subdirectory(src) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # libomp Unit Tests | ||
|
|
||
| Usage: | ||
| ``` | ||
| cd <your-llvm-build-directory>/runtimes/runtimes-bins | ||
| ninja check-libomp-unit | ||
| ``` | ||
|
|
||
| Note: unit tests are currently not supported on Windows |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # -*- Python -*- | ||
|
|
||
| # Configuration file for the 'lit' test runner. | ||
|
|
||
| import os | ||
| import subprocess | ||
|
|
||
| import lit.formats | ||
|
|
||
| # name: The name of this test suite. | ||
| config.name = "OpenMP-Unit" | ||
|
|
||
| # suffixes: A list of file extensions to treat as test files. | ||
| config.suffixes = [] | ||
|
|
||
| # test_source_root: The root path where tests are located. | ||
| # test_exec_root: The root path where tests should be run. | ||
| config.test_exec_root = config.openmp_unittests_dir | ||
| config.test_source_root = config.test_exec_root | ||
|
|
||
| # testFormat: The test format to use to interpret tests. | ||
| config.test_format = lit.formats.GoogleTest(config.llvm_build_mode, ".unittests") | ||
ro-i marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| @AUTO_GEN_COMMENT@ | ||
|
|
||
| config.library_dir = "@LIBOMP_LIBRARY_DIR@" | ||
ro-i marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| config.openmp_unittests_dir = "@CMAKE_CURRENT_BINARY_DIR@" | ||
| config.llvm_build_mode = lit_config.substitute("@LLVM_BUILD_MODE@") | ||
Meinersbur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Let the main config do the real work. | ||
| lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg.py") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| add_openmp_unittest(libomp.unittests | ||
| TestKmpStr.cpp | ||
| ) |
Uh oh!
There was an error while loading. Please reload this page.