| 1 |
add_custom_target(OpenMPUnitTests) |
| 2 |
set_target_properties(OpenMPUnitTests PROPERTIES FOLDER "OpenMP/Tests") |
| 3 |
|
| 4 |
if(WIN32 OR STUBS_LIBRARY) |
| 5 |
message(WARNING "OpenMP unittests disabled due to stub library or Windows") |
| 6 |
return() |
| 7 |
endif() |
| 8 |
|
| 9 |
function(standalone_add_gtest success_var) |
| 10 |
# LLVM_RUNTIMES_BUILD avoids gtest to link to LLVMSupport, which might be |
| 11 |
# incompable with the platform libomp is compiled for. |
| 12 |
set(LLVM_RUNTIMES_BUILD 1) |
| 13 |
if (EXISTS "${LLVM_THIRD_PARTY_DIR}/unittest/googletest/include/gtest/gtest.h") |
| 14 |
set(${success_var} TRUE PARENT_SCOPE) |
| 15 |
add_subdirectory("${LLVM_THIRD_PARTY_DIR}/unittest" "${CMAKE_BINARY_DIR}/third-party/runtimes_gtest") |
| 16 |
else() |
| 17 |
set(${success_var} FALSE PARENT_SCOPE) |
| 18 |
message(WARNING "OpenMP unit tests will be skipped as LLVM third-party unittest directory is not available at: ${LLVM_THIRD_PARTY_DIR}/unittest") |
| 19 |
return() |
| 20 |
endif() |
| 21 |
endfunction() |
| 22 |
|
| 23 |
# Make the targets default_gtest and default_gtest_main available. |
| 24 |
if (OPENMP_STANDALONE_BUILD) |
| 25 |
standalone_add_gtest(STANDALONE_UNIT_TESTS) |
| 26 |
if(NOT STANDALONE_UNIT_TESTS) |
| 27 |
return() |
| 28 |
endif() |
| 29 |
elseif ("openmp" IN_LIST LLVM_ENABLE_PROJECTS) |
| 30 |
# llvm_gtest should already exist |
| 31 |
else () |
| 32 |
# LLVM_ENABLE_RUNTIMES build |
| 33 |
build_gtest() |
| 34 |
endif () |
| 35 |
|
| 36 |
# Build a testing version of libomp that exports all symbols for unit tests. |
| 37 |
# This library uses the same compiled objects as libomp, but with all symbols |
| 38 |
# exported to allow testing internal functions. |
| 39 |
|
| 40 |
libomp_get_ldflags(LIBOMP_TEST_LDFLAGS FOR_UNITTESTS) |
| 41 |
libomp_get_libflags(LIBOMP_TEST_LIBFLAGS) |
| 42 |
|
| 43 |
# Create the testing library from the same objects as libomp. |
| 44 |
add_library(omp_testing SHARED $<TARGET_OBJECTS:obj.omp>) |
| 45 |
set_property(TARGET omp_testing PROPERTY FOLDER "OpenMP/Libraries") |
| 46 |
target_link_libraries(omp_testing PUBLIC default_gtest) |
| 47 |
target_link_libraries(omp_testing PUBLIC ${LIBOMP_TEST_LIBFLAGS} ${LIBOMP_DL_LIBS}) |
| 48 |
set_target_properties(omp_testing PROPERTIES |
| 49 |
PREFIX "" |
| 50 |
SUFFIX "" |
| 51 |
OUTPUT_NAME "libomp_testing${LIBOMP_LIBRARY_SUFFIX}" |
| 52 |
LINK_FLAGS "${LIBOMP_TEST_LDFLAGS}" |
| 53 |
LINKER_LANGUAGE ${LIBOMP_LINKER_LANGUAGE} |
| 54 |
EXCLUDE_FROM_ALL TRUE # Don't build by default, only when tests need it |
| 55 |
) |
| 56 |
target_include_directories(omp_testing PUBLIC |
| 57 |
${LIBOMP_INCLUDE_DIR} |
| 58 |
${LIBOMP_SRC_DIR} |
| 59 |
) |
| 60 |
|
| 61 |
function(add_openmp_unittest test_name) |
| 62 |
add_unittest(OpenMPUnitTests ${test_name} ${ARGN}) |
| 63 |
|
| 64 |
# Link against the testing library which exports all symbols. |
| 65 |
target_link_libraries(${test_name} PRIVATE omp_testing) |
| 66 |
|
| 67 |
if(TARGET default_gtest) |
| 68 |
target_link_libraries(${test_name} PRIVATE default_gtest_main default_gtest) |
| 69 |
else () |
| 70 |
target_link_libraries(${test_name} PRIVATE llvm_gtest_main llvm_gtest) |
| 71 |
endif () |
| 72 |
endfunction() |
| 73 |
|
| 74 |
configure_lit_site_cfg( |
| 75 |
${CMAKE_CURRENT_SOURCE_DIR}/../test/Unit/lit.site.cfg.py.in |
| 76 |
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py |
| 77 |
MAIN_CONFIG |
| 78 |
${CMAKE_CURRENT_SOURCE_DIR}/../test/Unit/lit.cfg.py |
| 79 |
) |
| 80 |
|
| 81 |
add_openmp_testsuite( |
| 82 |
check-libomp-unit |
| 83 |
"Running libomp unit tests" |
| 84 |
${CMAKE_CURRENT_BINARY_DIR} |
| 85 |
EXCLUDE_FROM_CHECK_ALL |
| 86 |
DEPENDS OpenMPUnitTests |
| 87 |
) |
| 88 |
|
| 89 |
add_subdirectory(String) |