2 #//===----------------------------------------------------------------------===//
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
8 #//===----------------------------------------------------------------------===//
11 # The following micro-tests are small tests to perform on the library just created.
12 # There are currently five micro-tests:
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.
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.
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.
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.
35 # get library location
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})
43 get_target_property(LIBOMP_OUTPUT_DIRECTORY omp LIBRARY_OUTPUT_DIRECTORY)
45 if(NOT LIBOMP_OUTPUT_DIRECTORY)
46 set(LIBOMP_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
50 find_program(LIBOMP_SHELL sh)
53 set(libomp_test_touch_targets test-touch-md/.success test-touch-mt/.success)
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})
61 libomp_append(libomp_test_touch_ldflags /safeseh)
63 else() # (Unix based systems, Intel(R) MIC Architecture, and Mac)
65 set(libomp_test_touch_targets test-touch-rt/.success)
67 # pick test-touch compiler
68 if(${LIBOMP_USE_STDCPPLIB})
69 set(libomp_test_touch_compiler ${CMAKE_CXX_COMPILER})
71 set(libomp_test_touch_compiler ${CMAKE_C_COMPILER})
73 # test-touch compilation flags
74 libomp_append(libomp_test_touch_libs "${CMAKE_THREAD_LIBS_INIT}")
76 libomp_append(libomp_test_touch_cflags -m32 LIBOMP_HAVE_M32_FLAG)
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)
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)
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)
88 macro(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})
92 if(${RELEASE_BUILD} OR ${RELWITHDEBINFO_BUILD})
93 if(${test_touch_dir} MATCHES "test-touch-mt")
94 libomp_append(libomp_test_touch_cflags /MT)
96 libomp_append(libomp_test_touch_cflags /MD)
99 if(${test_touch_dir} MATCHES "test-touch-mt")
100 libomp_append(libomp_test_touch_cflags /MTd)
102 libomp_append(libomp_test_touch_cflags /MDd)
105 set(libomp_test_touch_out_flags -Fe${libomp_test_touch_exe})
106 list(APPEND libomp_test_touch_dependencies ompimp)
108 set(libomp_test_touch_out_flags -o ${libomp_test_touch_exe})
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}
121 libomp_append(libomp_test_touch_env "KMP_VERSION=1")
122 add_custom_target(libomp-test-touch DEPENDS ${libomp_test_touch_targets})
123 set_target_properties(libomp-test-touch PROPERTIES FOLDER "OpenMP/Tests")
125 libomp_test_touch_recipe(test-touch-mt)
126 libomp_test_touch_recipe(test-touch-md)
128 libomp_test_touch_recipe(test-touch-rt)
132 add_custom_target(libomp-test-relo DEPENDS test-relo/.success)
133 set_target_properties(libomp-test-relo PROPERTIES FOLDER "OpenMP/Tests")
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
144 add_custom_target(libomp-test-execstack DEPENDS test-execstack/.success)
145 set_target_properties(libomp-test-execstack PROPERTIES FOLDER "OpenMP/Tests")
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
156 add_custom_target(libomp-test-deps DEPENDS test-deps/.success)
157 set_target_properties(libomp-test-deps PROPERTIES FOLDER "OpenMP/Tests")
158 set(libomp_expected_library_deps)
159 if(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)
162 elseif(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)
165 elseif(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)
169 set(libomp_expected_library_deps /usr/lib/libSystem.B.dylib)
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)
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)
191 set(libomp_expected_library_deps libdl.so.2 libgcc_s.so.1)
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)
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)
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)
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)
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)
218 libomp_append(libomp_expected_library_deps libc.so.6)
219 libomp_append(libomp_expected_library_deps ld.so.1)
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)
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)
227 # Check depends script expects comma separated list
228 string(REPLACE ";" "," libomp_expected_library_deps "${libomp_expected_library_deps}")
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