blob: 50beb594db80a7c811c7429601fe4cc53d402a93 [file] [log] [blame]
Jim Cownie3b81ce62014-08-05 09:32:28 +00001######################################################
2# MICRO TESTS
3# The following micro-tests are small tests to perform on
4# the library just created in ${build_dir}/, there are currently
5# five micro-tests:
6# (1) test-touch
7# - Compile and run a small program using newly created libiomp5 library
8# - Fails if test-touch.c does not compile or if test-touch.c does not run after compilation
9# - Program dependencies: gcc or g++, grep, bourne shell
10# - Available for all Linux,Mac,Windows builds. Not availble on Intel(R) MIC Architecture builds.
11# (2) test-relo
12# - Tests dynamic libraries for position-dependent code (can not have any position dependent code)
13# - Fails if TEXTREL is in output of readelf -d libiomp5.so command
14# - Program dependencies: readelf, grep, bourne shell
15# - Available for Linux, Intel(R) MIC Architecture dynamic library builds. Not available otherwise.
16# (3) test-execstack
17# - Tests if stack is executable
18# - Fails if stack is executable. Should only be readable and writable. Not exectuable.
19# - Program dependencies: perl, readelf
20# - Available for Linux dynamic library builds. Not available otherwise.
21# (4) test-instr (Intel(R) MIC Architecutre only)
22# - Tests Intel(R) MIC Architecture libraries for valid instruction set
23# - Fails if finds invalid instruction for Intel(R) MIC Architecture (wasn't compiled with correct flags)
24# - Program dependencies: perl, objdump
25# - Available for Intel(R) MIC Architecture builds. Not available otherwise.
26# (5) test-deps
27# - Tests newly created libiomp5 for library dependencies
28# - Fails if sees a dependence not listed in td_exp variable below
29# - Program dependencies: perl, (linux)readelf, (mac)otool[64], (windows)link.exe
30# - Available for Linux,Mac,Windows, Intel(R) MIC Architecture dynamic builds and Windows static builds. Not available otherwise.
31#
32# All tests can be turned off by including -Dtests=off when calling cmake
33# An individual test can be turned off by issuing something like -Dtest_touch=off when calling cmake
34
35# test-touch
36if(NOT ${MIC} AND ${test_touch} AND ${tests})
37 if(${WINDOWS})
38 set(do_test_touch_mt TRUE)
39 if(${do_test_touch_mt})
40 set(test_touch_items ${test_touch_items} test-touch-md test-touch-mt)
41 else()
42 set(test_touch_items ${test_touch_items} test-touch-md)
43 endif()
44 else()
45 set(test_touch_items ${test_touch_items} test-touch-rt)
46 endif()
47 set(regular_test_touch_items "${test_touch_items}")
48 add_suffix("/.success" regular_test_touch_items)
49 # test-touch : ${test_touch_items}/.success
50 set(ldeps "${regular_test_touch_items}")
51 add_custom_target( test-touch DEPENDS ${ldeps})
52
53 if(${WINDOWS})
54 # pick test-touch compiler
55 set(tt-c cl)
56 # test-touch compilation flags
57 list(APPEND tt-c-flags -nologo)
58 if(${RELEASE_BUILD} OR ${RELWITHDEBINFO_BUILD})
59 list(APPEND tt-c-flags-mt -MT)
60 list(APPEND tt-c-flags-md -MD)
61 else()
62 list(APPEND tt-c-flags-mt -MTd)
63 list(APPEND tt-c-flags-md -MDd)
64 endif()
65 list(APPEND tt-libs ${build_dir}/${imp_file})
66 list(APPEND tt-ld-flags -link -nodefaultlib:oldnames)
67 if(${IA32})
68 list(APPEND tt-ld-flags -safeseh)
69 endif()
70 list(APPEND tt-ld-flags-v -verbose)
71 else() # (Unix based systems, Intel(R) MIC Architecture, and Mac)
72 # pick test-touch compiler
73 if(${STD_CPP_LIB})
74 set(tt-c ${CMAKE_CXX_COMPILER})
75 else()
76 set(tt-c ${CMAKE_C_COMPILER})
77 endif()
78 # test-touch compilation flags
79 if(${LINUX})
80 list(APPEND tt-c-flags -pthread)
81 endif()
82 if(${IA32})
83 list(APPEND tt-c-flags -m32)
84 elseif(${INTEL64})
85 list(APPEND tt-c-flags -m64)
86 endif()
87 list(APPEND tt-libs ${build_dir}/${lib_file})
88 if(${MAC})
89 list(APPEND tt-ld-flags-v -Wl,-t)
90 set(tt-env "DYLD_LIBRARY_PATH=.:$ENV{DYLD_LIBRARY_PATH}")
91 else()
92 list(APPEND tt-ld-flags-v -Wl,--verbose)
93 set(tt-env LD_LIBRARY_PATH=".:${build_dir}:$ENV{LD_LIBRARY_PATH}")
94 endif()
95 endif()
96 list(APPEND tt-c-flags "${tt-c-flags-rt}")
97 list(APPEND tt-env "KMP_VERSION=1")
98
99 macro(test_touch_recipe test_touch_dir)
100 file(MAKE_DIRECTORY ${build_dir}/${test_touch_dir})
101 set(ldeps ${src_dir}/test-touch.c ${build_dir}/${lib_file})
102 set(tt-exe-file ${test_touch_dir}/test-touch${exe})
103 if(${WINDOWS})
104 # ****** list(APPEND tt-c-flags -Fo$(dir $@)test-touch${obj} -Fe$(dir $@)test-touch${exe}) *******
105 set(tt-c-flags-out -Fo${test_touch_dir}/test-touch${obj} -Fe${test_touch_dir}/test-touch${exe})
106 list(APPEND ldeps ${build_dir}/${imp_file})
107 else()
108 # ****** list(APPEND tt-c-flags -o $(dir $@)test-touch${exe}) ********
109 set(tt-c-flags-out -o ${test_touch_dir}/test-touch${exe})
110 endif()
111 add_custom_command(
112 OUTPUT ${test_touch_dir}/.success
113 COMMAND ${CMAKE_COMMAND} -E remove -f ${test_touch_dir}/*
114 COMMAND ${tt-c} ${tt-c-flags-out} ${tt-c-flags} ${src_dir}/test-touch.c ${tt-libs} ${tt-ld-flags}
115 COMMAND ${CMAKE_COMMAND} -E remove -f ${tt-exe-file}
116 COMMAND ${tt-c} ${tt-c-flags-out} ${tt-c-flags} ${src_dir}/test-touch.c ${tt-libs} ${tt-ld-flags} ${tt-ld-flags-v} > ${test_touch_dir}/build.log 2>&1
117 COMMAND ${tt-env} ${tt-exe-file}
118 #COMMAND grep -i -e \"[^_]libirc\" ${test_touch_dir}/build.log > ${test_touch_dir}/libirc.log \; [ $$? -eq 1 ]
119 COMMAND ${CMAKE_COMMAND} -E touch ${test_touch_dir}/.success
120 DEPENDS ${ldeps}
121 )
122 endmacro()
123 if(${WINDOWS})
124 test_touch_recipe(test-touch-mt)
125 test_touch_recipe(test-touch-md)
126 else()
127 test_touch_recipe(test-touch-rt)
128 endif()
129else()
130 add_custom_target(test-touch DEPENDS test-touch/.success)
131 macro(test_touch_recipe_skip test_touch_dir)
132 if(${tests} AND ${test_touch})
133 set(test_touch_message 'test-touch is not available for the Intel(R) MIC Architecture. Will not perform it.')
134 else()
135 set(test_touch_message "test-touch is turned off. Will not perform it.")
136 endif()
137 add_custom_command(
138 OUTPUT ${test_touch_dir}/.success
139 COMMAND ${CMAKE_COMMAND} -E echo ${test_touch_message}
140 )
141 endmacro()
142 test_touch_recipe_skip(test-touch-rt)
143 test_touch_recipe_skip(test-touch-mt)
144 test_touch_recipe_skip(test-touch-md)
145endif()
146
147# test-relo
148add_custom_target(test-relo DEPENDS test-relo/.success)
149if((${LINUX} OR ${MIC}) AND ${test_relo} AND ${tests})
150 file(MAKE_DIRECTORY ${build_dir}/test-relo)
151 add_custom_command(
152 OUTPUT test-relo/.success
153 COMMAND readelf -d ${build_dir}/${lib_file} > test-relo/readelf.log
154 COMMAND grep -e TEXTREL test-relo/readelf.log \; [ $$? -eq 1 ]
155 COMMAND ${CMAKE_COMMAND} -E touch test-relo/.success
156 DEPENDS ${build_dir}/${lib_file}
157 )
158else()
159 if(${tests} AND ${test_relo})
160 set(test_relo_message 'test-relo is only available for dynamic library on Linux or Intel(R) MIC Architecture. Will not perform it.')
161 else()
162 set(test_relo_message "test-relo is turned off. Will not perform it.")
163 endif()
164 add_custom_command(
165 OUTPUT test-relo/.success
166 COMMAND ${CMAKE_COMMAND} -E echo ${test_relo_message}
167 )
168endif()
169
170# test-execstack
171add_custom_target(test-execstack DEPENDS test-execstack/.success)
172if(${LINUX} AND ${test_execstack} AND ${tests})
173 file(MAKE_DIRECTORY ${build_dir}/test-execstack)
174 add_custom_command(
175 OUTPUT test-execstack/.success
176 COMMAND ${PERL_EXECUTABLE} ${tools_dir}/check-execstack.pl ${build_dir}/${lib_file}
177 COMMAND ${CMAKE_COMMAND} -E touch test-execstack/.success
178 DEPENDS ${build_dir}/${lib_file}
179 )
180else()
181 if(${tests} AND ${test_execstack})
182 set(test_execstack_message "test-execstack is only available for dynamic library on Linux. Will not perform it.")
183 else()
184 set(test_execstack_message "test-execstack is turned off. Will not perform it.")
185 endif()
186 add_custom_command(
187 OUTPUT test-execstack/.success
188 COMMAND ${CMAKE_COMMAND} -E echo ${test_execstack_message}
189 )
190endif()
191
192# test-instr
193add_custom_target(test-instr DEPENDS test-instr/.success)
194if(${MIC} AND ${test_instr} AND ${tests})
195 file(MAKE_DIRECTORY ${build_dir}/test-instr)
196 add_custom_command(
197 OUTPUT test-instr/.success
198 COMMAND ${PERL_EXECUTABLE} ${tools_dir}/check-instruction-set.pl ${oa_opts} --show --mic-arch=${mic_arch} --mic-os=${mic_os} ${build_dir}/${lib_file}
199 COMMAND ${CMAKE_COMMAND} -E touch test-instr/.success
200 DEPENDS ${build_dir}/${lib_file} ${tools_dir}/check-instruction-set.pl
201 )
202else()
203 if(${tests} AND ${test_instr})
204 set(test_instr_message 'test-instr is only available for Intel(R) MIC Architecture libraries. Will not perform it.')
205 else()
206 set(test_instr_message "test-instr is turned off. Will not perform it.")
207 endif()
208 add_custom_command(
209 OUTPUT test-instr/.success
210 COMMAND ${CMAKE_COMMAND} -E echo ${test_instr_message}
211 )
212endif()
213
214# test-deps
215add_custom_target(test-deps DEPENDS test-deps/.success)
216if(${test_deps} AND ${tests})
217 set(td_exp)
218 if(${FREEBSD})
219 set(td_exp libc.so.7 libthr.so.3 libunwind.so.5)
220 elseif(${LINUX})
221 set(td_exp libdl.so.2,libgcc_s.so.1)
222 if(NOT ${IA32} AND NOT ${INTEL64})
223 set(td_exp ${td_exp},libffi.so.6,libffi.so.5)
224 endif()
225 if(${IA32})
226 set(td_exp ${td_exp},libc.so.6,ld-linux.so.2)
227 elseif(${INTEL64})
228 set(td_exp ${td_exp},libc.so.6,ld-linux-x86-64.so.2)
229 elseif(${ARM})
230 set(td_exp ${td_exp},libc.so.6,ld-linux-armhf.so.3)
231 endif()
232 if(${STD_CPP_LIB})
233 set(td_exp ${td_exp},libstdc++.so.6)
234 endif()
235 if(NOT ${STUBS_LIBRARY})
236 set(td_exp ${td_exp},libpthread.so.0)
237 endif()
238 elseif(${MIC})
239 if("${mic_os}" STREQUAL "lin")
240 set(td_exp libc.so.6,libpthread.so.0,libdl.so.2)
241 if(${STD_CPP_LIB})
242 set(td_exp ${td_exp},libstdc++.so.6)
243 endif()
244 if("${mic_arch}" STREQUAL "knf")
245 set(td_exp ${td_exp},ld-linux-l1om.so.2,libgcc_s.so.1)
246 elseif("${mic_arch}" STREQUAL "knc")
247 set(td_exp ${td_exp},ld-linux-k1om.so.2)
248 endif()
249 elseif("${mic_os}" STREQUAL "bsd")
250 set(td_exp libc.so.7,libthr.so.3,libunwind.so.5)
251 endif()
252 elseif(${MAC})
253 set(td_exp /usr/lib/libSystem.B.dylib)
254 elseif(${WINDOWS})
255 set(td_exp kernel32.dll)
256 endif()
257
258 file(MAKE_DIRECTORY ${build_dir}/test-deps)
259 add_custom_command(
260 OUTPUT test-deps/.success
261 COMMAND ${PERL_EXECUTABLE} ${tools_dir}/check-depends.pl ${oa_opts} --expected="${td_exp}" ${build_dir}/${lib_file}
262 COMMAND ${CMAKE_COMMAND} -E touch test-deps/.success
263 DEPENDS ${build_dir}/${lib_file} ${tools_dir}/check-depends.pl
264 )
265else()
266 if(${tests} AND ${test_deps})
267 set(test_deps_message 'test-deps is available for dynamic libraries on Linux, Mac, Intel(R) MIC Architecture, Windows and static libraries on Windows. Will not perform it.')
268 else()
269 set(test_deps_message "test-deps is turned off. Will not perform it.")
270 endif()
271 add_custom_command(
272 OUTPUT test-deps/.success
273 COMMAND ${CMAKE_COMMAND} -E echo ${test_deps_message}
274 )
275endif()
276# END OF TESTS
277######################################################