1# 2#//===----------------------------------------------------------------------===// 3#// 4#// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5#// See https://llvm.org/LICENSE.txt for license information. 6#// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7#// 8#//===----------------------------------------------------------------------===// 9# 10 11# The following micro-tests are small tests to perform on the library just created. 12# There are currently five micro-tests: 13# (1) test-touch 14# - Compile and run a small program using newly created libomp library 15# - Fails if test-touch.c does not compile or if test-touch.c does not run after compilation 16# - Program dependencies: gcc or g++, grep, bourne shell 17# - Available for all Unix,Mac,Windows builds. Not available on Intel(R) MIC Architecture builds. 18# (2) test-relo 19# - Tests dynamic libraries for position-dependent code (can not have any position dependent code) 20# - Fails if TEXTREL is in output of readelf -d libomp.so command 21# - Program dependencies: readelf, grep, bourne shell 22# - Available for Unix, Intel(R) MIC Architecture dynamic library builds. Not available otherwise. 23# (3) test-execstack 24# - Tests if stack is executable 25# - Fails if stack is executable. Should only be readable and writable. Not executable. 26# - Program dependencies: perl, readelf 27# - Available for Unix dynamic library builds. Not available otherwise. 28# (4) test-deps 29# - Tests newly created libomp for library dependencies 30# - Fails if sees a dependence not listed in td_exp variable below 31# - Program dependencies: perl, (unix)readelf, (mac)otool[64], (windows)link.exe 32# - Available for Unix,Mac,Windows, Intel(R) MIC Architecture dynamic builds and Windows 33# static builds. Not available otherwise. 34 35# get library location 36if(WIN32) 37 get_target_property(LIBOMP_OUTPUT_DIRECTORY omp RUNTIME_OUTPUT_DIRECTORY) 38 get_target_property(LIBOMPIMP_OUTPUT_DIRECTORY ${LIBOMP_IMP_LIB_TARGET} ARCHIVE_OUTPUT_DIRECTORY) 39 if(NOT LIBOMPIMP_OUTPUT_DIRECTORY) 40 set(LIBOMPIMP_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) 41 endif() 42else() 43 get_target_property(LIBOMP_OUTPUT_DIRECTORY omp LIBRARY_OUTPUT_DIRECTORY) 44endif() 45if(NOT LIBOMP_OUTPUT_DIRECTORY) 46 set(LIBOMP_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) 47endif() 48 49# test-touch 50find_program(LIBOMP_SHELL sh) 51if(WIN32) 52 if(LIBOMP_SHELL) 53 set(libomp_test_touch_targets test-touch-md/.success test-touch-mt/.success) 54 endif() 55 # pick test-touch compiler 56 set(libomp_test_touch_compiler ${CMAKE_C_COMPILER}) 57 # test-touch compilation flags 58 libomp_append(libomp_test_touch_cflags /nologo) 59 libomp_append(libomp_test_touch_libs ${LIBOMPIMP_OUTPUT_DIRECTORY}/${LIBOMP_IMP_LIB_FILE}) 60 if(${IA32}) 61 libomp_append(libomp_test_touch_ldflags /safeseh) 62 endif() 63else() # (Unix based systems, Intel(R) MIC Architecture, and Mac) 64 if(LIBOMP_SHELL) 65 set(libomp_test_touch_targets test-touch-rt/.success) 66 endif() 67 # pick test-touch compiler 68 if(${LIBOMP_USE_STDCPPLIB}) 69 set(libomp_test_touch_compiler ${CMAKE_CXX_COMPILER}) 70 else() 71 set(libomp_test_touch_compiler ${CMAKE_C_COMPILER}) 72 endif() 73 # test-touch compilation flags 74 libomp_append(libomp_test_touch_libs "${CMAKE_THREAD_LIBS_INIT}") 75 if(${IA32}) 76 libomp_append(libomp_test_touch_cflags -m32 LIBOMP_HAVE_M32_FLAG) 77 endif() 78 libomp_append(libomp_test_touch_libs ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE}) 79 libomp_append(libomp_test_touch_libs "${LIBOMP_HWLOC_LIBRARY}" LIBOMP_USE_HWLOC) 80 if(APPLE) 81 set(libomp_test_touch_env "DYLD_LIBRARY_PATH=.:${LIBOMP_OUTPUT_DIRECTORY}:$ENV{DYLD_LIBRARY_PATH}") 82 libomp_append(libomp_test_touch_ldflags "-Wl,-rpath,${LIBOMP_HWLOC_LIBRARY_DIR}" LIBOMP_USE_HWLOC) 83 else() 84 set(libomp_test_touch_env "LD_LIBRARY_PATH=.:${LIBOMP_OUTPUT_DIRECTORY}:$ENV{LD_LIBRARY_PATH}") 85 libomp_append(libomp_test_touch_ldflags "-Wl,-rpath=${LIBOMP_HWLOC_LIBRARY_DIR}" LIBOMP_USE_HWLOC) 86 endif() 87endif() 88macro(libomp_test_touch_recipe test_touch_dir) 89 set(libomp_test_touch_dependencies ${LIBOMP_SRC_DIR}/test-touch.c omp) 90 set(libomp_test_touch_exe ${test_touch_dir}/test-touch${CMAKE_EXECUTABLE_SUFFIX}) 91 if(WIN32) 92 if(${RELEASE_BUILD} OR ${RELWITHDEBINFO_BUILD}) 93 if(${test_touch_dir} MATCHES "test-touch-mt") 94 libomp_append(libomp_test_touch_cflags /MT) 95 else() 96 libomp_append(libomp_test_touch_cflags /MD) 97 endif() 98 else() 99 if(${test_touch_dir} MATCHES "test-touch-mt") 100 libomp_append(libomp_test_touch_cflags /MTd) 101 else() 102 libomp_append(libomp_test_touch_cflags /MDd) 103 endif() 104 endif() 105 set(libomp_test_touch_out_flags -Fe${libomp_test_touch_exe}) 106 list(APPEND libomp_test_touch_dependencies ompimp) 107 else() 108 set(libomp_test_touch_out_flags -o ${libomp_test_touch_exe}) 109 endif() 110 add_custom_command( 111 OUTPUT ${test_touch_dir}/.success ${libomp_test_touch_exe} 112 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${test_touch_dir} 113 COMMAND ${CMAKE_COMMAND} -E remove -f ${test_touch_dir}/* 114 COMMAND ${libomp_test_touch_compiler} ${libomp_test_touch_out_flags} ${libomp_test_touch_cflags} 115 ${LIBOMP_SRC_DIR}/test-touch.c ${libomp_test_touch_ldflags} ${libomp_test_touch_libs} 116 COMMAND ${LIBOMP_SHELL} -c \"${libomp_test_touch_env} ${libomp_test_touch_exe}\" 117 COMMAND ${CMAKE_COMMAND} -E touch ${test_touch_dir}/.success 118 DEPENDS ${libomp_test_touch_dependencies} 119 ) 120endmacro() 121libomp_append(libomp_test_touch_env "KMP_VERSION=1") 122add_custom_target(libomp-test-touch DEPENDS ${libomp_test_touch_targets}) 123set_target_properties(libomp-test-touch PROPERTIES FOLDER "OpenMP/Tests") 124if(WIN32) 125 libomp_test_touch_recipe(test-touch-mt) 126 libomp_test_touch_recipe(test-touch-md) 127else() 128 libomp_test_touch_recipe(test-touch-rt) 129endif() 130 131# test-relo 132add_custom_target(libomp-test-relo DEPENDS test-relo/.success) 133set_target_properties(libomp-test-relo PROPERTIES FOLDER "OpenMP/Tests") 134add_custom_command( 135 OUTPUT test-relo/.success test-relo/readelf.log 136 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/test-relo 137 COMMAND readelf -d ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE} > test-relo/readelf.log 138 COMMAND grep -e TEXTREL test-relo/readelf.log \; test $$? -eq 1 139 COMMAND ${CMAKE_COMMAND} -E touch test-relo/.success 140 DEPENDS omp 141) 142 143# test-execstack 144add_custom_target(libomp-test-execstack DEPENDS test-execstack/.success) 145set_target_properties(libomp-test-execstack PROPERTIES FOLDER "OpenMP/Tests") 146add_custom_command( 147 OUTPUT test-execstack/.success 148 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/test-execstack 149 COMMAND ${Python3_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/check-execstack.py 150 ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE} 151 COMMAND ${CMAKE_COMMAND} -E touch test-execstack/.success 152 DEPENDS omp ${LIBOMP_TOOLS_DIR}/check-execstack.py 153) 154 155# test-deps 156add_custom_target(libomp-test-deps DEPENDS test-deps/.success) 157set_target_properties(libomp-test-deps PROPERTIES FOLDER "OpenMP/Tests") 158set(libomp_expected_library_deps) 159if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") 160 set(libomp_expected_library_deps libc.so.7 libthr.so.3 libm.so.5) 161 libomp_append(libomp_expected_library_deps libhwloc.so.5 LIBOMP_USE_HWLOC) 162elseif(CMAKE_SYSTEM_NAME MATCHES "NetBSD") 163 set(libomp_expected_library_deps libc.so.12 libpthread.so.1 libm.so.0) 164 libomp_append(libomp_expected_library_deps libhwloc.so.5 LIBOMP_USE_HWLOC) 165elseif(CMAKE_SYSTEM_NAME MATCHES "DragonFly") 166 set(libomp_expected_library_deps libc.so.8 libpthread.so.0 libm.so.4) 167 libomp_append(libomp_expected_library_deps libhwloc.so.5 LIBOMP_USE_HWLOC) 168elseif(APPLE) 169 set(libomp_expected_library_deps /usr/lib/libSystem.B.dylib) 170elseif(WIN32) 171 set(libomp_expected_library_deps kernel32.dll) 172 libomp_append(libomp_expected_library_deps api-ms-win-crt-convert-l1-1-0.dll) 173 libomp_append(libomp_expected_library_deps api-ms-win-crt-environment-l1-1-0.dll) 174 libomp_append(libomp_expected_library_deps api-ms-win-crt-heap-l1-1-0.dll) 175 libomp_append(libomp_expected_library_deps api-ms-win-crt-runtime-l1-1-0.dll) 176 libomp_append(libomp_expected_library_deps api-ms-win-crt-stdio-l1-1-0.dll) 177 libomp_append(libomp_expected_library_deps api-ms-win-crt-string-l1-1-0.dll) 178 libomp_append(libomp_expected_library_deps api-ms-win-crt-utility-l1-1-0.dll) 179 libomp_append(libomp_expected_library_deps vcruntime140.dll) 180 libomp_append(libomp_expected_library_deps psapi.dll) 181else() 182 if(${MIC}) 183 set(libomp_expected_library_deps libc.so.6 libpthread.so.0 libdl.so.2) 184 if("${LIBOMP_MIC_ARCH}" STREQUAL "knf") 185 libomp_append(libomp_expected_library_deps ld-linux-l1om.so.2) 186 libomp_append(libomp_expected_library_deps libgcc_s.so.1) 187 elseif("${LIBOMP_MIC_ARCH}" STREQUAL "knc") 188 libomp_append(libomp_expected_library_deps ld-linux-k1om.so.2) 189 endif() 190 else() 191 set(libomp_expected_library_deps libdl.so.2 libgcc_s.so.1) 192 if(${IA32}) 193 libomp_append(libomp_expected_library_deps libc.so.6) 194 libomp_append(libomp_expected_library_deps ld-linux.so.2) 195 libomp_append(libomp_expected_library_deps librt.so.1) 196 elseif(${INTEL64}) 197 libomp_append(libomp_expected_library_deps libc.so.6) 198 libomp_append(libomp_expected_library_deps ld-linux-x86-64.so.2) 199 libomp_append(libomp_expected_library_deps librt.so.1) 200 elseif(${ARM}) 201 libomp_append(libomp_expected_library_deps libc.so.6) 202 libomp_append(libomp_expected_library_deps libffi.so.6) 203 libomp_append(libomp_expected_library_deps libffi.so.5) 204 libomp_append(libomp_expected_library_deps ld-linux-armhf.so.3) 205 elseif(${PPC64}) 206 libomp_append(libomp_expected_library_deps libc.so.6) 207 libomp_append(libomp_expected_library_deps ld64.so.1) 208 elseif(${MIPS} OR ${MIPS64}) 209 libomp_append(libomp_expected_library_deps libc.so.6) 210 libomp_append(libomp_expected_library_deps ld.so.1) 211 elseif(${RISCV64}) 212 libomp_append(libomp_expected_library_deps libc.so.6) 213 libomp_append(libomp_expected_library_deps ld.so.1) 214 elseif(${LOONGARCH64}) 215 libomp_append(libomp_expected_library_deps libc.so.6) 216 libomp_append(libomp_expected_library_deps ld.so.1) 217 elseif(${S390X}) 218 libomp_append(libomp_expected_library_deps libc.so.6) 219 libomp_append(libomp_expected_library_deps ld.so.1) 220 endif() 221 libomp_append(libomp_expected_library_deps libpthread.so.0 IF_FALSE STUBS_LIBRARY) 222 libomp_append(libomp_expected_library_deps libhwloc.so.5 LIBOMP_USE_HWLOC) 223 endif() 224 libomp_append(libomp_expected_library_deps libstdc++.so.6 LIBOMP_USE_STDCPPLIB) 225 libomp_append(libomp_expected_library_deps libm.so.6 LIBOMP_STATS) 226endif() 227# Check depends script expects comma separated list 228string(REPLACE ";" "," libomp_expected_library_deps "${libomp_expected_library_deps}") 229add_custom_command( 230 OUTPUT test-deps/.success 231 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/test-deps 232 COMMAND ${Python3_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/check-depends.py 233 --expected="${libomp_expected_library_deps}" 234 ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE} 235 COMMAND ${CMAKE_COMMAND} -E touch test-deps/.success 236 DEPENDS omp ${LIBOMP_TOOLS_DIR}/check-depends.py 237) 238