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.
28 # (4) test-instr (Intel(R) MIC Architecture only)
29 # - Tests Intel(R) MIC Architecture libraries for valid instruction set
30 # - Fails if finds invalid instruction for Intel(R) MIC Architecture (wasn't compiled with correct flags)
31 # - Program dependencies: perl, objdump
32 # - Available for Intel(R) MIC Architecture and i386 builds. Not available otherwise.
34 # - Tests newly created libomp for library dependencies
35 # - Fails if sees a dependence not listed in td_exp variable below
36 # - Program dependencies: perl, (unix)readelf, (mac)otool[64], (windows)link.exe
37 # - Available for Unix,Mac,Windows, Intel(R) MIC Architecture dynamic builds and Windows
38 # static builds. Not available otherwise.
40 # get library location
42 get_target_property(LIBOMP_OUTPUT_DIRECTORY omp RUNTIME_OUTPUT_DIRECTORY)
43 get_target_property(LIBOMPIMP_OUTPUT_DIRECTORY ${LIBOMP_IMP_LIB_TARGET} ARCHIVE_OUTPUT_DIRECTORY)
44 if(NOT LIBOMPIMP_OUTPUT_DIRECTORY)
45 set(LIBOMPIMP_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
48 get_target_property(LIBOMP_OUTPUT_DIRECTORY omp LIBRARY_OUTPUT_DIRECTORY)
50 if(NOT LIBOMP_OUTPUT_DIRECTORY)
51 set(LIBOMP_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
55 find_program(LIBOMP_SHELL sh)
58 set(libomp_test_touch_targets test-touch-md/.success test-touch-mt/.success)
60 # pick test-touch compiler
61 set(libomp_test_touch_compiler ${CMAKE_C_COMPILER})
62 # test-touch compilation flags
63 libomp_append(libomp_test_touch_cflags /nologo)
64 libomp_append(libomp_test_touch_libs ${LIBOMPIMP_OUTPUT_DIRECTORY}/${LIBOMP_IMP_LIB_FILE})
66 libomp_append(libomp_test_touch_ldflags /safeseh)
68 else() # (Unix based systems, Intel(R) MIC Architecture, and Mac)
70 set(libomp_test_touch_targets test-touch-rt/.success)
72 # pick test-touch compiler
73 if(${LIBOMP_USE_STDCPPLIB})
74 set(libomp_test_touch_compiler ${CMAKE_CXX_COMPILER})
76 set(libomp_test_touch_compiler ${CMAKE_C_COMPILER})
78 # test-touch compilation flags
79 libomp_append(libomp_test_touch_libs "${CMAKE_THREAD_LIBS_INIT}")
81 libomp_append(libomp_test_touch_cflags -m32 LIBOMP_HAVE_M32_FLAG)
83 libomp_append(libomp_test_touch_libs ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE})
84 libomp_append(libomp_test_touch_libs "${LIBOMP_HWLOC_LIBRARY}" LIBOMP_USE_HWLOC)
86 set(libomp_test_touch_env "DYLD_LIBRARY_PATH=.:${LIBOMP_OUTPUT_DIRECTORY}:$ENV{DYLD_LIBRARY_PATH}")
87 libomp_append(libomp_test_touch_ldflags "-Wl,-rpath,${LIBOMP_HWLOC_LIBRARY_DIR}" LIBOMP_USE_HWLOC)
89 set(libomp_test_touch_env "LD_LIBRARY_PATH=.:${LIBOMP_OUTPUT_DIRECTORY}:$ENV{LD_LIBRARY_PATH}")
90 libomp_append(libomp_test_touch_ldflags "-Wl,-rpath=${LIBOMP_HWLOC_LIBRARY_DIR}" LIBOMP_USE_HWLOC)
93 macro(libomp_test_touch_recipe test_touch_dir)
94 set(libomp_test_touch_dependencies ${LIBOMP_SRC_DIR}/test-touch.c omp)
95 set(libomp_test_touch_exe ${test_touch_dir}/test-touch${CMAKE_EXECUTABLE_SUFFIX})
96 set(libomp_test_touch_obj ${test_touch_dir}/test-touch${CMAKE_C_OUTPUT_EXTENSION})
98 if(${RELEASE_BUILD} OR ${RELWITHDEBINFO_BUILD})
99 if(${test_touch_dir} MATCHES "test-touch-mt")
100 libomp_append(libomp_test_touch_cflags /MT)
102 libomp_append(libomp_test_touch_cflags /MD)
105 if(${test_touch_dir} MATCHES "test-touch-mt")
106 libomp_append(libomp_test_touch_cflags /MTd)
108 libomp_append(libomp_test_touch_cflags /MDd)
111 set(libomp_test_touch_out_flags -Fe${libomp_test_touch_exe} -Fo${libomp_test_touch_obj})
112 list(APPEND libomp_test_touch_dependencies ompimp)
114 set(libomp_test_touch_out_flags -o ${libomp_test_touch_exe})
117 OUTPUT ${test_touch_dir}/.success ${libomp_test_touch_exe} ${libomp_test_touch_obj}
118 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${test_touch_dir}
119 COMMAND ${CMAKE_COMMAND} -E remove -f ${test_touch_dir}/*
120 COMMAND ${libomp_test_touch_compiler} ${libomp_test_touch_out_flags} ${libomp_test_touch_cflags}
121 ${LIBOMP_SRC_DIR}/test-touch.c ${libomp_test_touch_ldflags} ${libomp_test_touch_libs}
122 COMMAND ${LIBOMP_SHELL} -c \"${libomp_test_touch_env} ${libomp_test_touch_exe}\"
123 COMMAND ${CMAKE_COMMAND} -E touch ${test_touch_dir}/.success
124 DEPENDS ${libomp_test_touch_dependencies}
127 libomp_append(libomp_test_touch_env "KMP_VERSION=1")
128 add_custom_target(libomp-test-touch DEPENDS ${libomp_test_touch_targets})
130 libomp_test_touch_recipe(test-touch-mt)
131 libomp_test_touch_recipe(test-touch-md)
133 libomp_test_touch_recipe(test-touch-rt)
137 add_custom_target(libomp-test-relo DEPENDS test-relo/.success)
139 OUTPUT test-relo/.success test-relo/readelf.log
140 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/test-relo
141 COMMAND readelf -d ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE} > test-relo/readelf.log
142 COMMAND grep -e TEXTREL test-relo/readelf.log \; test $$? -eq 1
143 COMMAND ${CMAKE_COMMAND} -E touch test-relo/.success
148 add_custom_target(libomp-test-execstack DEPENDS test-execstack/.success)
150 OUTPUT test-execstack/.success
151 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/test-execstack
152 COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/check-execstack.pl
153 --arch=${LIBOMP_PERL_SCRIPT_ARCH} ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE}
154 COMMAND ${CMAKE_COMMAND} -E touch test-execstack/.success
159 add_custom_target(libomp-test-instr DEPENDS test-instr/.success)
161 OUTPUT test-instr/.success
162 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/test-instr
163 COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/check-instruction-set.pl --os=${LIBOMP_PERL_SCRIPT_OS}
164 --arch=${LIBOMP_PERL_SCRIPT_ARCH} --show --mic-arch=${LIBOMP_MIC_ARCH} ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE}
165 COMMAND ${CMAKE_COMMAND} -E touch test-instr/.success
166 DEPENDS omp ${LIBOMP_TOOLS_DIR}/check-instruction-set.pl
170 add_custom_target(libomp-test-deps DEPENDS test-deps/.success)
171 set(libomp_expected_library_deps)
172 if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
173 set(libomp_expected_library_deps libc.so.7 libthr.so.3 libm.so.5)
174 libomp_append(libomp_expected_library_deps libhwloc.so.5 LIBOMP_USE_HWLOC)
175 elseif(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
176 set(libomp_expected_library_deps libc.so.12 libpthread.so.1 libm.so.0)
177 libomp_append(libomp_expected_library_deps libhwloc.so.5 LIBOMP_USE_HWLOC)
178 elseif(CMAKE_SYSTEM_NAME MATCHES "DragonFly")
179 set(libomp_expected_library_deps libc.so.8 libpthread.so.0 libm.so.4)
180 libomp_append(libomp_expected_library_deps libhwloc.so.5 LIBOMP_USE_HWLOC)
182 set(libomp_expected_library_deps /usr/lib/libSystem.B.dylib)
184 set(libomp_expected_library_deps kernel32.dll)
185 libomp_append(libomp_expected_library_deps psapi.dll LIBOMP_OMPT_SUPPORT)
188 set(libomp_expected_library_deps libc.so.6 libpthread.so.0 libdl.so.2)
189 if("${LIBOMP_MIC_ARCH}" STREQUAL "knf")
190 libomp_append(libomp_expected_library_deps ld-linux-l1om.so.2)
191 libomp_append(libomp_expected_library_deps libgcc_s.so.1)
192 elseif("${LIBOMP_MIC_ARCH}" STREQUAL "knc")
193 libomp_append(libomp_expected_library_deps ld-linux-k1om.so.2)
196 set(libomp_expected_library_deps libdl.so.2 libgcc_s.so.1)
198 libomp_append(libomp_expected_library_deps libc.so.6)
199 libomp_append(libomp_expected_library_deps ld-linux.so.2)
201 libomp_append(libomp_expected_library_deps libc.so.6)
202 libomp_append(libomp_expected_library_deps ld-linux-x86-64.so.2)
204 libomp_append(libomp_expected_library_deps libc.so.6)
205 libomp_append(libomp_expected_library_deps libffi.so.6)
206 libomp_append(libomp_expected_library_deps libffi.so.5)
207 libomp_append(libomp_expected_library_deps ld-linux-armhf.so.3)
209 libomp_append(libomp_expected_library_deps libc.so.6)
210 libomp_append(libomp_expected_library_deps ld64.so.1)
211 elseif(${MIPS} OR ${MIPS64})
212 libomp_append(libomp_expected_library_deps libc.so.6)
213 libomp_append(libomp_expected_library_deps ld.so.1)
215 libomp_append(libomp_expected_library_deps libc.so.6)
216 libomp_append(libomp_expected_library_deps ld.so.1)
217 elseif(${LOONGARCH64})
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 # Perl 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 ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/check-depends.pl --os=${LIBOMP_PERL_SCRIPT_OS}
233 --arch=${LIBOMP_PERL_SCRIPT_ARCH} --expected="${libomp_expected_library_deps}" ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE}
234 COMMAND ${CMAKE_COMMAND} -E touch test-deps/.success
235 DEPENDS omp ${LIBOMP_TOOLS_DIR}/check-depends.pl