blob: 76bc5503a11c90c521487913298f3f830485b857 [file] [log] [blame]
Jonathan Peyton2e013352015-07-15 16:05:30 +00001#
2#//===----------------------------------------------------------------------===//
3#//
4#// The LLVM Compiler Infrastructure
5#//
6#// This file is dual licensed under the MIT and the University of Illinois Open
7#// Source Licenses. See LICENSE.txt for details.
8#//
9#//===----------------------------------------------------------------------===//
10#
11
12# The following micro-tests are small tests to perform on the library just created.
13# There are currently five micro-tests:
14# (1) test-touch
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000015# - Compile and run a small program using newly created libomp library
16# - Fails if test-touch.c does not compile or if test-touch.c does not run after compilation
17# - Program dependencies: gcc or g++, grep, bourne shell
18# - Available for all Unix,Mac,Windows builds. Not available on Intel(R) MIC Architecture builds.
Jonathan Peyton2e013352015-07-15 16:05:30 +000019# (2) test-relo
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000020# - Tests dynamic libraries for position-dependent code (can not have any position dependent code)
21# - Fails if TEXTREL is in output of readelf -d libomp.so command
22# - Program dependencies: readelf, grep, bourne shell
23# - Available for Unix, Intel(R) MIC Architecture dynamic library builds. Not available otherwise.
Jonathan Peyton2e013352015-07-15 16:05:30 +000024# (3) test-execstack
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000025# - Tests if stack is executable
26# - Fails if stack is executable. Should only be readable and writable. Not exectuable.
27# - Program dependencies: perl, readelf
28# - Available for Unix dynamic library builds. Not available otherwise.
Jonathan Peyton2e013352015-07-15 16:05:30 +000029# (4) test-instr (Intel(R) MIC Architecutre only)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000030# - Tests Intel(R) MIC Architecture libraries for valid instruction set
31# - Fails if finds invalid instruction for Intel(R) MIC Architecture (wasn't compiled with correct flags)
32# - Program dependencies: perl, objdump
33# - Available for Intel(R) MIC Architecture and i386 builds. Not available otherwise.
Jonathan Peyton2e013352015-07-15 16:05:30 +000034# (5) test-deps
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000035# - Tests newly created libomp for library dependencies
36# - Fails if sees a dependence not listed in td_exp variable below
37# - Program dependencies: perl, (unix)readelf, (mac)otool[64], (windows)link.exe
38# - Available for Unix,Mac,Windows, Intel(R) MIC Architecture dynamic builds and Windows
39# static builds. Not available otherwise.
Jonathan Peyton2e013352015-07-15 16:05:30 +000040
41# get library location
42if(WIN32)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000043 get_target_property(LIBOMP_OUTPUT_DIRECTORY omp RUNTIME_OUTPUT_DIRECTORY)
44 get_target_property(LIBOMPIMP_OUTPUT_DIRECTORY ompimp ARCHIVE_OUTPUT_DIRECTORY)
45 if(NOT LIBOMPIMP_OUTPUT_DIRECTORY)
46 set(LIBOMPIMP_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
47 endif()
Jonathan Peyton2e013352015-07-15 16:05:30 +000048else()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000049 get_target_property(LIBOMP_OUTPUT_DIRECTORY omp LIBRARY_OUTPUT_DIRECTORY)
Jonathan Peyton2e013352015-07-15 16:05:30 +000050endif()
51if(NOT LIBOMP_OUTPUT_DIRECTORY)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000052 set(LIBOMP_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
Jonathan Peyton2e013352015-07-15 16:05:30 +000053endif()
54
55# test-touch
56find_program(LIBOMP_SHELL sh)
57if(WIN32)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000058 if(LIBOMP_SHELL)
59 set(libomp_test_touch_targets test-touch-md/.success test-touch-mt/.success)
60 endif()
61 # pick test-touch compiler
62 set(libomp_test_touch_compiler ${CMAKE_C_COMPILER})
63 # test-touch compilation flags
64 libomp_append(libomp_test_touch_cflags /nologo)
65 libomp_append(libomp_test_touch_libs ${LIBOMPIMP_OUTPUT_DIRECTORY}/${LIBOMP_IMP_LIB_FILE})
66 if(${IA32})
67 libomp_append(libomp_test_touch_ldflags /safeseh)
68 endif()
Jonathan Peyton2e013352015-07-15 16:05:30 +000069else() # (Unix based systems, Intel(R) MIC Architecture, and Mac)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000070 if(LIBOMP_SHELL)
71 set(libomp_test_touch_targets test-touch-rt/.success)
72 endif()
73 # pick test-touch compiler
74 if(${LIBOMP_USE_STDCPPLIB})
75 set(libomp_test_touch_compiler ${CMAKE_CXX_COMPILER})
76 else()
77 set(libomp_test_touch_compiler ${CMAKE_C_COMPILER})
78 endif()
79 # test-touch compilation flags
80 libomp_append(libomp_test_touch_libs "${CMAKE_THREAD_LIBS_INIT}")
81 if(${IA32})
82 libomp_append(libomp_test_touch_cflags -m32 LIBOMP_HAVE_M32_FLAG)
83 endif()
84 libomp_append(libomp_test_touch_libs ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE})
Jonathan Peyton01dcf362015-11-30 20:02:59 +000085 libomp_append(libomp_test_touch_libs "${LIBOMP_HWLOC_LIBRARY}" LIBOMP_USE_HWLOC)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000086 if(APPLE)
87 set(libomp_test_touch_env "DYLD_LIBRARY_PATH=.:${LIBOMP_OUTPUT_DIRECTORY}:$ENV{DYLD_LIBRARY_PATH}")
Jonathan Peyton01dcf362015-11-30 20:02:59 +000088 libomp_append(libomp_test_touch_ldflags "-Wl,-rpath,${LIBOMP_HWLOC_LIBRARY_DIR}" LIBOMP_USE_HWLOC)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000089 else()
90 set(libomp_test_touch_env "LD_LIBRARY_PATH=.:${LIBOMP_OUTPUT_DIRECTORY}:$ENV{LD_LIBRARY_PATH}")
Jonathan Peyton01dcf362015-11-30 20:02:59 +000091 libomp_append(libomp_test_touch_ldflags "-Wl,-rpath=${LIBOMP_HWLOC_LIBRARY_DIR}" LIBOMP_USE_HWLOC)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000092 endif()
Jonathan Peyton2e013352015-07-15 16:05:30 +000093endif()
94macro(libomp_test_touch_recipe test_touch_dir)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000095 set(libomp_test_touch_dependencies ${LIBOMP_SRC_DIR}/test-touch.c omp)
96 set(libomp_test_touch_exe ${test_touch_dir}/test-touch${CMAKE_EXECUTABLE_SUFFIX})
97 set(libomp_test_touch_obj ${test_touch_dir}/test-touch${CMAKE_C_OUTPUT_EXTENSION})
98 if(WIN32)
99 if(${RELEASE_BUILD} OR ${RELWITHDEBINFO_BUILD})
100 if(${test_touch_dir} MATCHES "test-touch-mt")
101 libomp_append(libomp_test_touch_cflags /MT)
102 else()
103 libomp_append(libomp_test_touch_cflags /MD)
104 endif()
Jonathan Peyton2e013352015-07-15 16:05:30 +0000105 else()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000106 if(${test_touch_dir} MATCHES "test-touch-mt")
107 libomp_append(libomp_test_touch_cflags /MTd)
108 else()
109 libomp_append(libomp_test_touch_cflags /MDd)
110 endif()
Jonathan Peyton2e013352015-07-15 16:05:30 +0000111 endif()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000112 set(libomp_test_touch_out_flags -Fe${libomp_test_touch_exe} -Fo${libomp_test_touch_obj})
113 list(APPEND libomp_test_touch_dependencies ompimp)
114 else()
115 set(libomp_test_touch_out_flags -o ${libomp_test_touch_exe})
116 endif()
117 add_custom_command(
118 OUTPUT ${test_touch_dir}/.success ${libomp_test_touch_exe} ${libomp_test_touch_obj}
119 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${test_touch_dir}
120 COMMAND ${CMAKE_COMMAND} -E remove -f ${test_touch_dir}/*
121 COMMAND ${libomp_test_touch_compiler} ${libomp_test_touch_out_flags} ${libomp_test_touch_cflags}
122 ${LIBOMP_SRC_DIR}/test-touch.c ${libomp_test_touch_ldflags} ${libomp_test_touch_libs}
123 COMMAND ${LIBOMP_SHELL} -c \"${libomp_test_touch_env} ${libomp_test_touch_exe}\"
124 COMMAND ${CMAKE_COMMAND} -E touch ${test_touch_dir}/.success
125 DEPENDS ${libomp_test_touch_dependencies}
126 )
Jonathan Peyton2e013352015-07-15 16:05:30 +0000127endmacro()
128libomp_append(libomp_test_touch_env "KMP_VERSION=1")
129add_custom_target(libomp-test-touch DEPENDS ${libomp_test_touch_targets})
130if(WIN32)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000131 libomp_test_touch_recipe(test-touch-mt)
132 libomp_test_touch_recipe(test-touch-md)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000133else()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000134 libomp_test_touch_recipe(test-touch-rt)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000135endif()
136
137# test-relo
138add_custom_target(libomp-test-relo DEPENDS test-relo/.success)
139add_custom_command(
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000140 OUTPUT test-relo/.success test-relo/readelf.log
141 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/test-relo
142 COMMAND readelf -d ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE} > test-relo/readelf.log
Hans Wennborgfd4dfdc2015-07-24 21:24:48 +0000143 COMMAND grep -e TEXTREL test-relo/readelf.log \; test $$? -eq 1
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000144 COMMAND ${CMAKE_COMMAND} -E touch test-relo/.success
145 DEPENDS omp
Jonathan Peyton2e013352015-07-15 16:05:30 +0000146)
147
148# test-execstack
149add_custom_target(libomp-test-execstack DEPENDS test-execstack/.success)
150add_custom_command(
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000151 OUTPUT test-execstack/.success
152 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/test-execstack
Jonathan Peyton4c91ad12016-01-26 19:44:31 +0000153 COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/check-execstack.pl
154 --arch=${LIBOMP_PERL_SCRIPT_ARCH} ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE}
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000155 COMMAND ${CMAKE_COMMAND} -E touch test-execstack/.success
156 DEPENDS omp
Jonathan Peyton2e013352015-07-15 16:05:30 +0000157)
158
159# test-instr
160add_custom_target(libomp-test-instr DEPENDS test-instr/.success)
161add_custom_command(
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000162 OUTPUT test-instr/.success
163 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/test-instr
164 COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/check-instruction-set.pl --os=${LIBOMP_PERL_SCRIPT_OS}
Jonathan Peyton4c91ad12016-01-26 19:44:31 +0000165 --arch=${LIBOMP_PERL_SCRIPT_ARCH} --show --mic-arch=${LIBOMP_MIC_ARCH} ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE}
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000166 COMMAND ${CMAKE_COMMAND} -E touch test-instr/.success
167 DEPENDS omp ${LIBOMP_TOOLS_DIR}/check-instruction-set.pl
Jonathan Peyton2e013352015-07-15 16:05:30 +0000168)
169
170# test-deps
171add_custom_target(libomp-test-deps DEPENDS test-deps/.success)
172set(libomp_expected_library_deps)
173if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000174 set(libomp_expected_library_deps libc.so.7 libthr.so.3)
Jonathan Peyton01dcf362015-11-30 20:02:59 +0000175 libomp_append(libomp_expected_library_deps libhwloc.so.5 LIBOMP_USE_HWLOC)
Joerg Sonnenbergerf16f6492015-09-21 19:40:59 +0000176elseif(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
177 set(libomp_expected_library_deps libc.so.12 libpthread.so.1 libm.so.0)
Jonathan Peyton01dcf362015-11-30 20:02:59 +0000178 libomp_append(libomp_expected_library_deps libhwloc.so.5 LIBOMP_USE_HWLOC)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000179elseif(APPLE)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000180 set(libomp_expected_library_deps /usr/lib/libSystem.B.dylib)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000181elseif(WIN32)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000182 set(libomp_expected_library_deps kernel32.dll)
Jonathan Peyton69e596a2015-10-29 20:56:24 +0000183 libomp_append(libomp_expected_library_deps psapi.dll LIBOMP_OMPT_SUPPORT)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000184else()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000185 if(${MIC})
186 set(libomp_expected_library_deps libc.so.6 libpthread.so.0 libdl.so.2)
187 if("${LIBOMP_MIC_ARCH}" STREQUAL "knf")
188 libomp_append(libomp_expected_library_deps ld-linux-l1om.so.2)
189 libomp_append(libomp_expected_library_deps libgcc_s.so.1)
190 elseif("${LIBOMP_MIC_ARCH}" STREQUAL "knc")
191 libomp_append(libomp_expected_library_deps ld-linux-k1om.so.2)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000192 endif()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000193 else()
194 set(libomp_expected_library_deps libdl.so.2 libgcc_s.so.1)
195 if(${IA32})
196 libomp_append(libomp_expected_library_deps libc.so.6)
197 libomp_append(libomp_expected_library_deps ld-linux.so.2)
198 elseif(${INTEL64})
199 libomp_append(libomp_expected_library_deps libc.so.6)
200 libomp_append(libomp_expected_library_deps ld-linux-x86-64.so.2)
201 elseif(${ARM})
202 libomp_append(libomp_expected_library_deps libc.so.6)
203 libomp_append(libomp_expected_library_deps libffi.so.6)
204 libomp_append(libomp_expected_library_deps libffi.so.5)
205 libomp_append(libomp_expected_library_deps ld-linux-armhf.so.3)
206 elseif(${PPC64})
207 libomp_append(libomp_expected_library_deps libc.so.6)
208 libomp_append(libomp_expected_library_deps ld64.so.1)
209 endif()
210 libomp_append(libomp_expected_library_deps libpthread.so.0 IF_FALSE STUBS_LIBRARY)
Jonathan Peyton01dcf362015-11-30 20:02:59 +0000211 libomp_append(libomp_expected_library_deps libhwloc.so.5 LIBOMP_USE_HWLOC)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000212 endif()
213 libomp_append(libomp_expected_library_deps libstdc++.so.6 LIBOMP_USE_STDCPPLIB)
Jonathan Peyton4b1aad32015-12-17 16:15:39 +0000214 libomp_append(libomp_expected_library_deps libm.so.6 LIBOMP_STATS)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000215endif()
216# Perl script expects comma separated list
217string(REPLACE ";" "," libomp_expected_library_deps "${libomp_expected_library_deps}")
218add_custom_command(
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000219 OUTPUT test-deps/.success
220 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/test-deps
221 COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/check-depends.pl --os=${LIBOMP_PERL_SCRIPT_OS}
Jonathan Peyton4c91ad12016-01-26 19:44:31 +0000222 --arch=${LIBOMP_PERL_SCRIPT_ARCH} --expected="${libomp_expected_library_deps}" ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE}
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000223 COMMAND ${CMAKE_COMMAND} -E touch test-deps/.success
224 DEPENDS omp ${LIBOMP_TOOLS_DIR}/check-depends.pl
Jonathan Peyton2e013352015-07-15 16:05:30 +0000225)