• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2#//===----------------------------------------------------------------------===//
3#//
4#// 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
7#//
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
14#  - 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.
18# (2) test-relo
19#  - 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.
23# (3) test-execstack
24#  - Tests if stack is executable
25#  - Fails if stack is executable. Should only be readable and writable. Not executable.
26#  - Program dependencies: perl, readelf
27#  - Available for Unix dynamic library builds. Not available otherwise.
28# (4) test-instr (Intel(R) MIC Architecture only)
29#  - 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.
33# (5) test-deps
34#  - 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.
39
40# get library location
41if(WIN32)
42  get_target_property(LIBOMP_OUTPUT_DIRECTORY omp RUNTIME_OUTPUT_DIRECTORY)
43  get_target_property(LIBOMPIMP_OUTPUT_DIRECTORY ${LIBOMP_IMP_LIB_TARGET} ARCHIVE_OUTPUT_DIRECTORY)
44  if(NOT LIBOMPIMP_OUTPUT_DIRECTORY)
45    set(LIBOMPIMP_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
46  endif()
47else()
48  get_target_property(LIBOMP_OUTPUT_DIRECTORY omp LIBRARY_OUTPUT_DIRECTORY)
49endif()
50if(NOT LIBOMP_OUTPUT_DIRECTORY)
51  set(LIBOMP_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
52endif()
53
54# test-touch
55find_program(LIBOMP_SHELL sh)
56if(WIN32)
57  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()
68else() # (Unix based systems, Intel(R) MIC Architecture, and Mac)
69  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})
84  libomp_append(libomp_test_touch_libs "${LIBOMP_HWLOC_LIBRARY}" LIBOMP_USE_HWLOC)
85  if(APPLE)
86    set(libomp_test_touch_env "DYLD_LIBRARY_PATH=.:${LIBOMP_OUTPUT_DIRECTORY}:$ENV{DYLD_LIBRARY_PATH}")
87    libomp_append(libomp_test_touch_ldflags "-Wl,-rpath,${LIBOMP_HWLOC_LIBRARY_DIR}" LIBOMP_USE_HWLOC)
88  else()
89    set(libomp_test_touch_env "LD_LIBRARY_PATH=.:${LIBOMP_OUTPUT_DIRECTORY}:$ENV{LD_LIBRARY_PATH}")
90    libomp_append(libomp_test_touch_ldflags "-Wl,-rpath=${LIBOMP_HWLOC_LIBRARY_DIR}" LIBOMP_USE_HWLOC)
91  endif()
92endif()
93macro(libomp_test_touch_recipe test_touch_dir)
94  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()
104    else()
105      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()
110    endif()
111    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  )
126endmacro()
127libomp_append(libomp_test_touch_env "KMP_VERSION=1")
128add_custom_target(libomp-test-touch DEPENDS ${libomp_test_touch_targets})
129if(WIN32)
130  libomp_test_touch_recipe(test-touch-mt)
131  libomp_test_touch_recipe(test-touch-md)
132else()
133  libomp_test_touch_recipe(test-touch-rt)
134endif()
135
136# test-relo
137add_custom_target(libomp-test-relo DEPENDS test-relo/.success)
138add_custom_command(
139  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
142  COMMAND grep -e TEXTREL test-relo/readelf.log \; test $$? -eq 1
143  COMMAND ${CMAKE_COMMAND} -E touch test-relo/.success
144  DEPENDS omp
145)
146
147# test-execstack
148add_custom_target(libomp-test-execstack DEPENDS test-execstack/.success)
149add_custom_command(
150  OUTPUT  test-execstack/.success
151  COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/test-execstack
152  COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/check-execstack.pl
153    --arch=${LIBOMP_PERL_SCRIPT_ARCH} ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE}
154  COMMAND ${CMAKE_COMMAND} -E touch test-execstack/.success
155  DEPENDS omp
156)
157
158# test-instr
159add_custom_target(libomp-test-instr DEPENDS test-instr/.success)
160add_custom_command(
161  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}
164    --arch=${LIBOMP_PERL_SCRIPT_ARCH} --show --mic-arch=${LIBOMP_MIC_ARCH} ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE}
165  COMMAND ${CMAKE_COMMAND} -E touch test-instr/.success
166  DEPENDS omp ${LIBOMP_TOOLS_DIR}/check-instruction-set.pl
167)
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")
173  set(libomp_expected_library_deps libc.so.7 libthr.so.3 libm.so.5)
174  libomp_append(libomp_expected_library_deps libhwloc.so.5 LIBOMP_USE_HWLOC)
175elseif(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
176  set(libomp_expected_library_deps libc.so.12 libpthread.so.1 libm.so.0)
177  libomp_append(libomp_expected_library_deps libhwloc.so.5 LIBOMP_USE_HWLOC)
178elseif(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)
181elseif(APPLE)
182  set(libomp_expected_library_deps /usr/lib/libSystem.B.dylib)
183elseif(WIN32)
184  set(libomp_expected_library_deps kernel32.dll)
185  libomp_append(libomp_expected_library_deps psapi.dll LIBOMP_OMPT_SUPPORT)
186else()
187  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)
194    endif()
195  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)
211    elseif(${MIPS} OR ${MIPS64})
212      libomp_append(libomp_expected_library_deps libc.so.6)
213      libomp_append(libomp_expected_library_deps ld.so.1)
214    elseif(${RISCV64})
215      libomp_append(libomp_expected_library_deps libc.so.6)
216      libomp_append(libomp_expected_library_deps ld.so.1)
217    endif()
218    libomp_append(libomp_expected_library_deps libpthread.so.0 IF_FALSE STUBS_LIBRARY)
219    libomp_append(libomp_expected_library_deps libhwloc.so.5 LIBOMP_USE_HWLOC)
220  endif()
221  libomp_append(libomp_expected_library_deps libstdc++.so.6 LIBOMP_USE_STDCPPLIB)
222  libomp_append(libomp_expected_library_deps libm.so.6 LIBOMP_STATS)
223endif()
224# Perl script expects comma separated list
225string(REPLACE ";" "," libomp_expected_library_deps "${libomp_expected_library_deps}")
226add_custom_command(
227  OUTPUT  test-deps/.success
228  COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/test-deps
229  COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/check-depends.pl --os=${LIBOMP_PERL_SCRIPT_OS}
230    --arch=${LIBOMP_PERL_SCRIPT_ARCH} --expected="${libomp_expected_library_deps}" ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE}
231  COMMAND ${CMAKE_COMMAND} -E touch test-deps/.success
232  DEPENDS omp ${LIBOMP_TOOLS_DIR}/check-depends.pl
233)
234