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