blob: 38f4486b30dcedba37a6e6559cebedde836352df [file] [log] [blame]
Jonathan Peyton2e013352015-07-15 16:05:30 +00001#
2#//===----------------------------------------------------------------------===//
3#//
Chandler Carruth57b08b02019-01-19 10:56:40 +00004#// 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
Jonathan Peyton2e013352015-07-15 16:05:30 +00007#//
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
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000014# - 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.
Jonathan Peyton2e013352015-07-15 16:05:30 +000018# (2) test-relo
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000019# - 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.
Jonathan Peyton2e013352015-07-15 16:05:30 +000023# (3) test-execstack
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000024# - Tests if stack is executable
25# - Fails if stack is executable. Should only be readable and writable. Not exectuable.
26# - Program dependencies: perl, readelf
27# - Available for Unix dynamic library builds. Not available otherwise.
Jonathan Peyton2e013352015-07-15 16:05:30 +000028# (4) test-instr (Intel(R) MIC Architecutre only)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000029# - 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.
Jonathan Peyton2e013352015-07-15 16:05:30 +000033# (5) test-deps
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000034# - 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.
Jonathan Peyton2e013352015-07-15 16:05:30 +000039
40# get library location
41if(WIN32)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000042 get_target_property(LIBOMP_OUTPUT_DIRECTORY omp RUNTIME_OUTPUT_DIRECTORY)
43 get_target_property(LIBOMPIMP_OUTPUT_DIRECTORY ompimp ARCHIVE_OUTPUT_DIRECTORY)
44 if(NOT LIBOMPIMP_OUTPUT_DIRECTORY)
45 set(LIBOMPIMP_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
46 endif()
Jonathan Peyton2e013352015-07-15 16:05:30 +000047else()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000048 get_target_property(LIBOMP_OUTPUT_DIRECTORY omp LIBRARY_OUTPUT_DIRECTORY)
Jonathan Peyton2e013352015-07-15 16:05:30 +000049endif()
50if(NOT LIBOMP_OUTPUT_DIRECTORY)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000051 set(LIBOMP_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
Jonathan Peyton2e013352015-07-15 16:05:30 +000052endif()
53
54# test-touch
55find_program(LIBOMP_SHELL sh)
56if(WIN32)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000057 if(LIBOMP_SHELL)
58 set(libomp_test_touch_targets test-touch-md/.success test-touch-mt/.success)
59 endif()
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})
65 if(${IA32})
66 libomp_append(libomp_test_touch_ldflags /safeseh)
67 endif()
Jonathan Peyton2e013352015-07-15 16:05:30 +000068else() # (Unix based systems, Intel(R) MIC Architecture, and Mac)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000069 if(LIBOMP_SHELL)
70 set(libomp_test_touch_targets test-touch-rt/.success)
71 endif()
72 # pick test-touch compiler
73 if(${LIBOMP_USE_STDCPPLIB})
74 set(libomp_test_touch_compiler ${CMAKE_CXX_COMPILER})
75 else()
76 set(libomp_test_touch_compiler ${CMAKE_C_COMPILER})
77 endif()
78 # test-touch compilation flags
79 libomp_append(libomp_test_touch_libs "${CMAKE_THREAD_LIBS_INIT}")
80 if(${IA32})
81 libomp_append(libomp_test_touch_cflags -m32 LIBOMP_HAVE_M32_FLAG)
82 endif()
83 libomp_append(libomp_test_touch_libs ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE})
Jonathan Peyton01dcf362015-11-30 20:02:59 +000084 libomp_append(libomp_test_touch_libs "${LIBOMP_HWLOC_LIBRARY}" LIBOMP_USE_HWLOC)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000085 if(APPLE)
86 set(libomp_test_touch_env "DYLD_LIBRARY_PATH=.:${LIBOMP_OUTPUT_DIRECTORY}:$ENV{DYLD_LIBRARY_PATH}")
Jonathan Peyton01dcf362015-11-30 20:02:59 +000087 libomp_append(libomp_test_touch_ldflags "-Wl,-rpath,${LIBOMP_HWLOC_LIBRARY_DIR}" LIBOMP_USE_HWLOC)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000088 else()
89 set(libomp_test_touch_env "LD_LIBRARY_PATH=.:${LIBOMP_OUTPUT_DIRECTORY}:$ENV{LD_LIBRARY_PATH}")
Jonathan Peyton01dcf362015-11-30 20:02:59 +000090 libomp_append(libomp_test_touch_ldflags "-Wl,-rpath=${LIBOMP_HWLOC_LIBRARY_DIR}" LIBOMP_USE_HWLOC)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000091 endif()
Jonathan Peyton2e013352015-07-15 16:05:30 +000092endif()
93macro(libomp_test_touch_recipe test_touch_dir)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000094 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})
97 if(WIN32)
98 if(${RELEASE_BUILD} OR ${RELWITHDEBINFO_BUILD})
99 if(${test_touch_dir} MATCHES "test-touch-mt")
100 libomp_append(libomp_test_touch_cflags /MT)
101 else()
102 libomp_append(libomp_test_touch_cflags /MD)
103 endif()
Jonathan Peyton2e013352015-07-15 16:05:30 +0000104 else()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000105 if(${test_touch_dir} MATCHES "test-touch-mt")
106 libomp_append(libomp_test_touch_cflags /MTd)
107 else()
108 libomp_append(libomp_test_touch_cflags /MDd)
109 endif()
Jonathan Peyton2e013352015-07-15 16:05:30 +0000110 endif()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000111 set(libomp_test_touch_out_flags -Fe${libomp_test_touch_exe} -Fo${libomp_test_touch_obj})
112 list(APPEND libomp_test_touch_dependencies ompimp)
113 else()
114 set(libomp_test_touch_out_flags -o ${libomp_test_touch_exe})
115 endif()
116 add_custom_command(
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}
125 )
Jonathan Peyton2e013352015-07-15 16:05:30 +0000126endmacro()
127libomp_append(libomp_test_touch_env "KMP_VERSION=1")
128add_custom_target(libomp-test-touch DEPENDS ${libomp_test_touch_targets})
129if(WIN32)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000130 libomp_test_touch_recipe(test-touch-mt)
131 libomp_test_touch_recipe(test-touch-md)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000132else()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000133 libomp_test_touch_recipe(test-touch-rt)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000134endif()
135
136# test-relo
137add_custom_target(libomp-test-relo DEPENDS test-relo/.success)
138add_custom_command(
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000139 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
Hans Wennborgfd4dfdc2015-07-24 21:24:48 +0000142 COMMAND grep -e TEXTREL test-relo/readelf.log \; test $$? -eq 1
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000143 COMMAND ${CMAKE_COMMAND} -E touch test-relo/.success
144 DEPENDS omp
Jonathan Peyton2e013352015-07-15 16:05:30 +0000145)
146
147# test-execstack
148add_custom_target(libomp-test-execstack DEPENDS test-execstack/.success)
149add_custom_command(
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000150 OUTPUT test-execstack/.success
151 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/test-execstack
Jonathan Peyton4c91ad12016-01-26 19:44:31 +0000152 COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/check-execstack.pl
153 --arch=${LIBOMP_PERL_SCRIPT_ARCH} ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE}
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000154 COMMAND ${CMAKE_COMMAND} -E touch test-execstack/.success
155 DEPENDS omp
Jonathan Peyton2e013352015-07-15 16:05:30 +0000156)
157
158# test-instr
159add_custom_target(libomp-test-instr DEPENDS test-instr/.success)
160add_custom_command(
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000161 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}
Jonathan Peyton4c91ad12016-01-26 19:44:31 +0000164 --arch=${LIBOMP_PERL_SCRIPT_ARCH} --show --mic-arch=${LIBOMP_MIC_ARCH} ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE}
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000165 COMMAND ${CMAKE_COMMAND} -E touch test-instr/.success
166 DEPENDS omp ${LIBOMP_TOOLS_DIR}/check-instruction-set.pl
Jonathan Peyton2e013352015-07-15 16:05:30 +0000167)
168
169# test-deps
170add_custom_target(libomp-test-deps DEPENDS test-deps/.success)
171set(libomp_expected_library_deps)
172if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000173 set(libomp_expected_library_deps libc.so.7 libthr.so.3)
Jonathan Peyton01dcf362015-11-30 20:02:59 +0000174 libomp_append(libomp_expected_library_deps libhwloc.so.5 LIBOMP_USE_HWLOC)
Joerg Sonnenbergerf16f6492015-09-21 19:40:59 +0000175elseif(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
176 set(libomp_expected_library_deps libc.so.12 libpthread.so.1 libm.so.0)
Jonathan Peyton01dcf362015-11-30 20:02:59 +0000177 libomp_append(libomp_expected_library_deps libhwloc.so.5 LIBOMP_USE_HWLOC)
Kamil Rytarowskia56ac942018-12-09 16:40:33 +0000178elseif(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)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000181elseif(APPLE)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000182 set(libomp_expected_library_deps /usr/lib/libSystem.B.dylib)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000183elseif(WIN32)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000184 set(libomp_expected_library_deps kernel32.dll)
Jonathan Peyton69e596a2015-10-29 20:56:24 +0000185 libomp_append(libomp_expected_library_deps psapi.dll LIBOMP_OMPT_SUPPORT)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000186else()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000187 if(${MIC})
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)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000194 endif()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000195 else()
196 set(libomp_expected_library_deps libdl.so.2 libgcc_s.so.1)
197 if(${IA32})
198 libomp_append(libomp_expected_library_deps libc.so.6)
199 libomp_append(libomp_expected_library_deps ld-linux.so.2)
200 elseif(${INTEL64})
201 libomp_append(libomp_expected_library_deps libc.so.6)
202 libomp_append(libomp_expected_library_deps ld-linux-x86-64.so.2)
203 elseif(${ARM})
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)
208 elseif(${PPC64})
209 libomp_append(libomp_expected_library_deps libc.so.6)
210 libomp_append(libomp_expected_library_deps ld64.so.1)
Sylvestre Ledrucd9d3742016-12-08 09:22:24 +0000211 elseif(${MIPS} OR ${MIPS64})
212 libomp_append(libomp_expected_library_deps libc.so.6)
213 libomp_append(libomp_expected_library_deps ld.so.1)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000214 endif()
215 libomp_append(libomp_expected_library_deps libpthread.so.0 IF_FALSE STUBS_LIBRARY)
Jonathan Peyton01dcf362015-11-30 20:02:59 +0000216 libomp_append(libomp_expected_library_deps libhwloc.so.5 LIBOMP_USE_HWLOC)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000217 endif()
218 libomp_append(libomp_expected_library_deps libstdc++.so.6 LIBOMP_USE_STDCPPLIB)
Jonathan Peyton4b1aad32015-12-17 16:15:39 +0000219 libomp_append(libomp_expected_library_deps libm.so.6 LIBOMP_STATS)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000220endif()
221# Perl script expects comma separated list
222string(REPLACE ";" "," libomp_expected_library_deps "${libomp_expected_library_deps}")
223add_custom_command(
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000224 OUTPUT test-deps/.success
225 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/test-deps
226 COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/check-depends.pl --os=${LIBOMP_PERL_SCRIPT_OS}
Jonathan Peyton4c91ad12016-01-26 19:44:31 +0000227 --arch=${LIBOMP_PERL_SCRIPT_ARCH} --expected="${libomp_expected_library_deps}" ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE}
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000228 COMMAND ${CMAKE_COMMAND} -E touch test-deps/.success
229 DEPENDS omp ${LIBOMP_TOOLS_DIR}/check-depends.pl
Jonathan Peyton2e013352015-07-15 16:05:30 +0000230)