-
Notifications
You must be signed in to change notification settings - Fork 15.6k
[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 all commits
a30a642
4d12f24
c63c254
4cd6cbe
16ad02e
b12ff59
197b195
5eb66f4
03ddc0c
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 |
|---|---|---|
| @@ -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, "Tests") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| @AUTO_GEN_COMMENT@ | ||
|
|
||
| config.openmp_unittests_dir = "@CMAKE_CURRENT_BINARY_DIR@/../unittests" | ||
| config.llvm_build_mode = lit_config.substitute("@LLVM_BUILD_MODE@") | ||
|
|
||
| # Let the main config do the real work. | ||
| lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/../test/Unit/lit.cfg.py") | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| add_custom_target(OpenMPUnitTests) | ||
| set_target_properties(OpenMPUnitTests PROPERTIES FOLDER "OpenMP/Tests") | ||
|
|
||
| if(WIN32 OR STUBS_LIBRARY) | ||
| message(WARNING "OpenMP unittests disabled due to stub library or Windows") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason this doesn't work on Windows?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. But since the CMake changes are already complicated enough to review and test as they are, I thought it might be best to get things working first and then add something like the Windows support in a follow-up |
||
| return() | ||
| 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. | ||
|
|
||
| libomp_get_ldflags(LIBOMP_TEST_LDFLAGS FOR_UNITTESTS) | ||
| libomp_get_libflags(LIBOMP_TEST_LIBFLAGS) | ||
|
|
||
| # Create the testing library from the same objects as libomp. | ||
| add_library(omp_testing SHARED $<TARGET_OBJECTS:obj.omp>) | ||
| set_property(TARGET omp_testing PROPERTY FOLDER "OpenMP/Libraries") | ||
| target_link_libraries(omp_testing PUBLIC default_gtest) | ||
| target_link_libraries(omp_testing PUBLIC ${LIBOMP_TEST_LIBFLAGS} ${LIBOMP_DL_LIBS}) | ||
| 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 | ||
Meinersbur marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
| target_include_directories(omp_testing PUBLIC | ||
| ${LIBOMP_INCLUDE_DIR} | ||
| ${LIBOMP_SRC_DIR} | ||
| ) | ||
|
|
||
| # Make the targets default_gtest and default_gtest_main available. | ||
| build_gtest() | ||
|
|
||
| function(add_openmp_unittest test_name) | ||
| add_unittest(OpenMPUnitTests ${test_name} ${ARGN}) | ||
|
|
||
| # Link against the testing library which exports all symbols. | ||
| target_link_libraries(${test_name} PRIVATE omp_testing) | ||
|
|
||
| if(TARGET default_gtest) | ||
| target_link_libraries(${test_name} PRIVATE default_gtest_main default_gtest) | ||
| else () | ||
| target_link_libraries(${test_name} PRIVATE llvm_gtest_main llvm_gtest) | ||
| endif () | ||
Meinersbur marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| endfunction() | ||
|
|
||
| configure_lit_site_cfg( | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/../test/Unit/lit.site.cfg.py.in | ||
| ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py | ||
| MAIN_CONFIG | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/../test/Unit/lit.cfg.py | ||
| ) | ||
|
|
||
| add_openmp_testsuite( | ||
| check-libomp-unit | ||
| "Running libomp unit tests" | ||
| ${CMAKE_CURRENT_BINARY_DIR} | ||
| EXCLUDE_FROM_CHECK_ALL | ||
| DEPENDS OpenMPUnitTests | ||
| ) | ||
|
|
||
| add_subdirectory(String) | ||
| 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,3 @@ | ||
| add_openmp_unittest(StringTests | ||
| TestKmpStr.cpp | ||
| ) |
Uh oh!
There was an error while loading. Please reload this page.