blob: bf5afaba7f42706f930cfb2f01ab47db4e16fd43 [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})
85 if(APPLE)
86 set(libomp_test_touch_env "DYLD_LIBRARY_PATH=.:${LIBOMP_OUTPUT_DIRECTORY}:$ENV{DYLD_LIBRARY_PATH}")
87 else()
88 set(libomp_test_touch_env "LD_LIBRARY_PATH=.:${LIBOMP_OUTPUT_DIRECTORY}:$ENV{LD_LIBRARY_PATH}")
89 endif()
Jonathan Peyton2e013352015-07-15 16:05:30 +000090endif()
91macro(libomp_test_touch_recipe test_touch_dir)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000092 set(libomp_test_touch_dependencies ${LIBOMP_SRC_DIR}/test-touch.c omp)
93 set(libomp_test_touch_exe ${test_touch_dir}/test-touch${CMAKE_EXECUTABLE_SUFFIX})
94 set(libomp_test_touch_obj ${test_touch_dir}/test-touch${CMAKE_C_OUTPUT_EXTENSION})
95 if(WIN32)
96 if(${RELEASE_BUILD} OR ${RELWITHDEBINFO_BUILD})
97 if(${test_touch_dir} MATCHES "test-touch-mt")
98 libomp_append(libomp_test_touch_cflags /MT)
99 else()
100 libomp_append(libomp_test_touch_cflags /MD)
101 endif()
Jonathan Peyton2e013352015-07-15 16:05:30 +0000102 else()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000103 if(${test_touch_dir} MATCHES "test-touch-mt")
104 libomp_append(libomp_test_touch_cflags /MTd)
105 else()
106 libomp_append(libomp_test_touch_cflags /MDd)
107 endif()
Jonathan Peyton2e013352015-07-15 16:05:30 +0000108 endif()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000109 set(libomp_test_touch_out_flags -Fe${libomp_test_touch_exe} -Fo${libomp_test_touch_obj})
110 list(APPEND libomp_test_touch_dependencies ompimp)
111 else()
112 set(libomp_test_touch_out_flags -o ${libomp_test_touch_exe})
113 endif()
114 add_custom_command(
115 OUTPUT ${test_touch_dir}/.success ${libomp_test_touch_exe} ${libomp_test_touch_obj}
116 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${test_touch_dir}
117 COMMAND ${CMAKE_COMMAND} -E remove -f ${test_touch_dir}/*
118 COMMAND ${libomp_test_touch_compiler} ${libomp_test_touch_out_flags} ${libomp_test_touch_cflags}
119 ${LIBOMP_SRC_DIR}/test-touch.c ${libomp_test_touch_ldflags} ${libomp_test_touch_libs}
120 COMMAND ${LIBOMP_SHELL} -c \"${libomp_test_touch_env} ${libomp_test_touch_exe}\"
121 COMMAND ${CMAKE_COMMAND} -E touch ${test_touch_dir}/.success
122 DEPENDS ${libomp_test_touch_dependencies}
123 )
Jonathan Peyton2e013352015-07-15 16:05:30 +0000124endmacro()
125libomp_append(libomp_test_touch_env "KMP_VERSION=1")
126add_custom_target(libomp-test-touch DEPENDS ${libomp_test_touch_targets})
127if(WIN32)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000128 libomp_test_touch_recipe(test-touch-mt)
129 libomp_test_touch_recipe(test-touch-md)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000130else()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000131 libomp_test_touch_recipe(test-touch-rt)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000132endif()
133
134# test-relo
135add_custom_target(libomp-test-relo DEPENDS test-relo/.success)
136add_custom_command(
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000137 OUTPUT test-relo/.success test-relo/readelf.log
138 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/test-relo
139 COMMAND readelf -d ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE} > test-relo/readelf.log
Hans Wennborgfd4dfdc2015-07-24 21:24:48 +0000140 COMMAND grep -e TEXTREL test-relo/readelf.log \; test $$? -eq 1
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000141 COMMAND ${CMAKE_COMMAND} -E touch test-relo/.success
142 DEPENDS omp
Jonathan Peyton2e013352015-07-15 16:05:30 +0000143)
144
145# test-execstack
146add_custom_target(libomp-test-execstack DEPENDS test-execstack/.success)
147add_custom_command(
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000148 OUTPUT test-execstack/.success
149 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/test-execstack
150 COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/check-execstack.pl --os=${LIBOMP_PERL_SCRIPT_OS}
151 --arch=${LIBOMP_ARCH} ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE}
152 COMMAND ${CMAKE_COMMAND} -E touch test-execstack/.success
153 DEPENDS omp
Jonathan Peyton2e013352015-07-15 16:05:30 +0000154)
155
156# test-instr
157add_custom_target(libomp-test-instr DEPENDS test-instr/.success)
158add_custom_command(
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000159 OUTPUT test-instr/.success
160 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/test-instr
161 COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/check-instruction-set.pl --os=${LIBOMP_PERL_SCRIPT_OS}
162 --arch=${LIBOMP_ARCH} --show --mic-arch=${LIBOMP_MIC_ARCH} ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE}
163 COMMAND ${CMAKE_COMMAND} -E touch test-instr/.success
164 DEPENDS omp ${LIBOMP_TOOLS_DIR}/check-instruction-set.pl
Jonathan Peyton2e013352015-07-15 16:05:30 +0000165)
166
167# test-deps
168add_custom_target(libomp-test-deps DEPENDS test-deps/.success)
169set(libomp_expected_library_deps)
170if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000171 set(libomp_expected_library_deps libc.so.7 libthr.so.3)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000172elseif(APPLE)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000173 set(libomp_expected_library_deps /usr/lib/libSystem.B.dylib)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000174elseif(WIN32)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000175 set(libomp_expected_library_deps kernel32.dll)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000176else()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000177 if(${MIC})
178 set(libomp_expected_library_deps libc.so.6 libpthread.so.0 libdl.so.2)
179 if("${LIBOMP_MIC_ARCH}" STREQUAL "knf")
180 libomp_append(libomp_expected_library_deps ld-linux-l1om.so.2)
181 libomp_append(libomp_expected_library_deps libgcc_s.so.1)
182 elseif("${LIBOMP_MIC_ARCH}" STREQUAL "knc")
183 libomp_append(libomp_expected_library_deps ld-linux-k1om.so.2)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000184 endif()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000185 else()
186 set(libomp_expected_library_deps libdl.so.2 libgcc_s.so.1)
187 if(${IA32})
188 libomp_append(libomp_expected_library_deps libc.so.6)
189 libomp_append(libomp_expected_library_deps ld-linux.so.2)
190 elseif(${INTEL64})
191 libomp_append(libomp_expected_library_deps libc.so.6)
192 libomp_append(libomp_expected_library_deps ld-linux-x86-64.so.2)
193 elseif(${ARM})
194 libomp_append(libomp_expected_library_deps libc.so.6)
195 libomp_append(libomp_expected_library_deps libffi.so.6)
196 libomp_append(libomp_expected_library_deps libffi.so.5)
197 libomp_append(libomp_expected_library_deps ld-linux-armhf.so.3)
198 elseif(${PPC64})
199 libomp_append(libomp_expected_library_deps libc.so.6)
200 libomp_append(libomp_expected_library_deps ld64.so.1)
201 endif()
202 libomp_append(libomp_expected_library_deps libpthread.so.0 IF_FALSE STUBS_LIBRARY)
203 endif()
204 libomp_append(libomp_expected_library_deps libstdc++.so.6 LIBOMP_USE_STDCPPLIB)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000205endif()
206# Perl script expects comma separated list
207string(REPLACE ";" "," libomp_expected_library_deps "${libomp_expected_library_deps}")
208add_custom_command(
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000209 OUTPUT test-deps/.success
210 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/test-deps
211 COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/check-depends.pl --os=${LIBOMP_PERL_SCRIPT_OS}
212 --arch=${LIBOMP_ARCH} --expected="${libomp_expected_library_deps}" ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE}
213 COMMAND ${CMAKE_COMMAND} -E touch test-deps/.success
214 DEPENDS omp ${LIBOMP_TOOLS_DIR}/check-depends.pl
Jonathan Peyton2e013352015-07-15 16:05:30 +0000215)