Skip to content

Commit 18bec60

Browse files
committedNov 29, 2017
[CMake] Refactor testing infrastructure
The code for the two OpenMP runtime libraries was very similar. Move to common CMake file that is included and provides a simple interface for adding testsuites. Also add a common check-openmp target that runs all testsuites that have been registered. Note that this renames all test options to the common OPENMP namespace, for example OPENMP_TEST_C_COMPILER instead of LIBOMP_TEST_COMPILER and so on. Differential Revision: https://reviews.llvm.org/D40082 llvm-svn: 319343
1 parent 5af381a commit 18bec60

11 files changed

+172
-198
lines changed
 

‎openmp/CMakeLists.txt

+24
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,38 @@ if (OPENMP_STANDALONE_BUILD OR "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_S
1919
set(OPENMP_LIBDIR_SUFFIX "" CACHE STRING
2020
"suffix of lib installation directory, e.g. 64 => lib64")
2121

22+
# Group test settings.
23+
set(OPENMP_TEST_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING
24+
"C compiler to use for testing OpenMP runtime libraries.")
25+
set(OPENMP_TEST_CXX_COMPILER ${CMAKE_CXX_COMPILER} CACHE STRING
26+
"C++ compiler to use for testing OpenMP runtime libraries.")
2227
set(OPENMP_LLVM_TOOLS_DIR "" CACHE PATH "Path to LLVM tools for testing.")
2328
else()
2429
set(OPENMP_ENABLE_WERROR ${LLVM_ENABLE_WERROR})
2530
# If building in tree, we honor the same install suffix LLVM uses.
2631
set(OPENMP_LIBDIR_SUFFIX ${LLVM_LIBDIR_SUFFIX})
32+
33+
if (NOT MSVC)
34+
set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
35+
set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++)
36+
else()
37+
set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang.exe)
38+
set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++.exe)
39+
endif()
2740
endif()
2841

2942
# Check and set up common compiler flags.
3043
include(config-ix)
3144
include(HandleOpenMPOptions)
3245

46+
# Set up testing infrastructure.
47+
include(OpenMPTesting)
48+
49+
set(OPENMP_TEST_FLAGS "" CACHE STRING
50+
"Extra compiler flags to send to the test compiler.")
51+
set(OPENMP_TEST_OPENMP_FLAGS "-fopenmp" CACHE STRING
52+
"OpenMP compiler flag to use for testing OpenMP runtime libraries.")
53+
3354

3455
# Build host runtime library.
3556
add_subdirectory(runtime)
@@ -55,3 +76,6 @@ if (OPENMP_ENABLE_LIBOMPTARGET)
5576

5677
add_subdirectory(libomptarget)
5778
endif()
79+
80+
# Now that we have seen all testuites, create the check-openmp target.
81+
construct_check_openmp_target()

‎openmp/cmake/OpenMPTesting.cmake

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Keep track if we have all dependencies.
2+
set(ENABLE_CHECK_TARGETS TRUE)
3+
4+
# Function to find required dependencies for testing.
5+
function(find_standalone_test_dependencies)
6+
include(FindPythonInterp)
7+
8+
if (NOT PYTHONINTERP_FOUND)
9+
message(STATUS "Could not find Python.")
10+
message(WARNING "The check targets will not be available!")
11+
set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE)
12+
return()
13+
endif()
14+
15+
# Find executables.
16+
find_program(OPENMP_LLVM_LIT_EXECUTABLE
17+
NAMES llvm-lit lit.py lit
18+
PATHS ${OPENMP_LLVM_TOOLS_DIR})
19+
if (NOT OPENMP_LLVM_LIT_EXECUTABLE)
20+
message(STATUS "Cannot find llvm-lit.")
21+
message(STATUS "Please put llvm-lit in your PATH, set OPENMP_LLVM_LIT_EXECUTABLE to its full path, or point OPENMP_LLVM_TOOLS_DIR to its directory.")
22+
message(WARNING "The check targets will not be available!")
23+
set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE)
24+
return()
25+
endif()
26+
27+
find_program(OPENMP_FILECHECK_EXECUTABLE
28+
NAMES FileCheck
29+
PATHS ${OPENMP_LLVM_TOOLS_DIR})
30+
if (NOT OPENMP_FILECHECK_EXECUTABLE)
31+
message(STATUS "Cannot find FileCheck.")
32+
message(STATUS "Please put FileCheck in your PATH, set OPENMP_FILECHECK_EXECUTABLE to its full path, or point OPENMP_LLVM_TOOLS_DIR to its directory.")
33+
message(WARNING "The check targets will not be available!")
34+
set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE)
35+
return()
36+
endif()
37+
endfunction()
38+
39+
if (${OPENMP_STANDALONE_BUILD})
40+
find_standalone_test_dependencies()
41+
42+
# Make sure we can use the console pool for recent CMake and Ninja > 1.5.
43+
if (CMAKE_VERSION VERSION_LESS 3.1.20141117)
44+
set(cmake_3_2_USES_TERMINAL)
45+
else()
46+
set(cmake_3_2_USES_TERMINAL USES_TERMINAL)
47+
endif()
48+
49+
# Set lit arguments.
50+
set(DEFAULT_LIT_ARGS "-sv --show-unsupported --show-xfail")
51+
if (MSVC OR XCODE)
52+
set(DEFAULT_LIT_ARGS "${DEFAULT_LIT_ARGS} --no-progress-bar")
53+
endif()
54+
# TODO: Remove once bots are updated to use the new option.
55+
if (DEFINED LIBOMP_LIT_ARGS)
56+
set(DEFAULT_LIT_ARGS ${LIBOMP_LIT_ARGS})
57+
endif()
58+
set(OPENMP_LIT_ARGS "${DEFAULT_LIT_ARGS}" CACHE STRING "Options for lit.")
59+
separate_arguments(OPENMP_LIT_ARGS)
60+
else()
61+
set(OPENMP_FILECHECK_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/FileCheck)
62+
endif()
63+
64+
# Function to add a testsuite for an OpenMP runtime library.
65+
function(add_openmp_testsuite target comment)
66+
if (NOT ENABLE_CHECK_TARGETS)
67+
add_custom_target(${target}
68+
COMMAND ${CMAKE_COMMAND} -E echo "${target} does nothing, dependencies not found.")
69+
message(STATUS "${target} does nothing.")
70+
return()
71+
endif()
72+
73+
cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN})
74+
# EXCLUDE_FROM_ALL excludes the test ${target} out of check-openmp.
75+
if (NOT EXCLUDE_FROM_ALL)
76+
# Register the testsuites and depends for the check-openmp rule.
77+
set_property(GLOBAL APPEND PROPERTY OPENMP_LIT_TESTSUITES ${ARG_UNPARSED_ARGUMENTS})
78+
set_property(GLOBAL APPEND PROPERTY OPENMP_LIT_DEPENDS ${ARG_DEPENDS})
79+
endif()
80+
81+
if (${OPENMP_STANDALONE_BUILD})
82+
add_custom_target(${target}
83+
COMMAND ${PYTHON_EXECUTABLE} ${OPENMP_LLVM_LIT_EXECUTABLE} ${OPENMP_LIT_ARGS} ${ARG_UNPARSED_ARGUMENTS}
84+
COMMENT ${comment}
85+
DEPENDS ${ARG_DEPENDS}
86+
${cmake_3_2_USES_TERMINAL}
87+
)
88+
else()
89+
add_lit_testsuite(${target}
90+
${comment}
91+
${ARG_UNPARSED_ARGUMENTS}
92+
DEPENDS clang clang-headers FileCheck ${ARG_DEPENDS}
93+
)
94+
endif()
95+
endfunction()
96+
97+
function(construct_check_openmp_target)
98+
get_property(OPENMP_LIT_TESTSUITES GLOBAL PROPERTY OPENMP_LIT_TESTSUITES)
99+
get_property(OPENMP_LIT_DEPENDS GLOBAL PROPERTY OPENMP_LIT_DEPENDS)
100+
101+
# We already added the testsuites themselves, no need to do that again.
102+
set(EXCLUDE_FROM_ALL True)
103+
add_openmp_testsuite(check-openmp "Running OpenMP tests" ${OPENMP_LIT_TESTSUITES} DEPENDS ${OPENMP_LIT_DEPENDS})
104+
endfunction()

‎openmp/libomptarget/Build_With_CMake.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ Build type can be Release, Debug, or RelWithDebInfo.
8585
-DOPENMP_ENABLE_WERROR=true|false
8686
Should consider warnings as errors.
8787

88-
-DLIBOMPTARGET_LLVM_LIT_EXECUTABLE=""
88+
-DOPENMP_LLVM_LIT_EXECUTABLE=""
8989
Full path to the llvm-lit tool. Required for testing in out-of-tree builds.
9090

91-
-DLIBOMPTARGET_FILECHECK_EXECUTABLE=""
91+
-DOPENMP_FILECHECK_EXECUTABLE=""
9292
Full path to the FileCheck tool. Required for testing in out-of-tree builds.
9393

9494
-DLIBOMPTARGET_OPENMP_HEADER_FOLDER=""
+7-82
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
# CMakeLists.txt file for unit testing OpenMP Library
2-
include(FindPythonInterp)
3-
include(CheckTypeSize)
4-
if(NOT PYTHONINTERP_FOUND)
5-
libomptarget_warning_say("Could not find Python.")
6-
libomptarget_warning_say("The check-libomptarget target will not be available!")
7-
return()
8-
endif()
9-
10-
set(LIBOMPTARGET_TEST_CFLAGS "" CACHE STRING
11-
"Extra compiler flags to send to the test compiler")
1+
# CMakeLists.txt file for unit testing OpenMP offloading runtime library.
122

133
if(LIBOMPTARGET_CMAKE_BUILD_TYPE MATCHES debug)
144
set(LIBOMPTARGET_DEBUG True)
@@ -17,25 +7,14 @@ else()
177
endif()
188

199
if(${OPENMP_STANDALONE_BUILD})
20-
# Make sure we can use the console pool for recent cmake and ninja > 1.5
21-
if(CMAKE_VERSION VERSION_LESS 3.1.20141117)
22-
set(cmake_3_2_USES_TERMINAL)
23-
else()
24-
set(cmake_3_2_USES_TERMINAL USES_TERMINAL)
25-
endif()
26-
set(LIBOMPTARGET_TEST_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING
27-
"C compiler to use for testing OpenMP offloading library")
28-
set(LIBOMPTARGET_TEST_CXX_COMPILER ${CMAKE_CXX_COMPILER} CACHE STRING
29-
"C++ compiler to use for testing OpenMP offloading library")
30-
31-
if (NOT(${LIBOMPTARGET_TEST_C_COMPILER} MATCHES "clang" AND ${LIBOMPTARGET_TEST_CXX_COMPILER} MATCHES "clang"))
10+
if (NOT(${OPENMP_TEST_C_COMPILER} MATCHES "clang" AND ${OPENMP_TEST_CXX_COMPILER} MATCHES "clang"))
3211
libomptarget_say("Can only test with Clang compiler!")
3312
libomptarget_warning_say("The check-libomptarget target will not be available!")
3413
return()
3514
endif()
3615

3716
execute_process(
38-
COMMAND ${LIBOMPTARGET_TEST_C_COMPILER} --version
17+
COMMAND ${OPENMP_TEST_C_COMPILER} --version
3918
OUTPUT_VARIABLE TEST_COMPILER_VERSION)
4019
string(REGEX MATCH "version ([0-9.]+)" TEST_COMPILER_VERSION ${TEST_COMPILER_VERSION})
4120
if (NOT(TEST_COMPILER_VERSION))
@@ -49,73 +28,19 @@ if(${OPENMP_STANDALONE_BUILD})
4928
libomptarget_warning_say("The check-libomptarget target will not be available!")
5029
return()
5130
endif()
31+
endif()
5232

53-
set(LIBOMPTARGET_TEST_OPENMP_FLAG -fopenmp CACHE STRING
54-
"OpenMP compiler flag to use for testing OpenMP offloading library")
55-
find_program(LIBOMPTARGET_LLVM_LIT_EXECUTABLE
56-
NAMES llvm-lit lit.py lit
57-
PATHS ${OPENMP_LLVM_TOOLS_DIR})
58-
if(NOT LIBOMPTARGET_LLVM_LIT_EXECUTABLE)
59-
libomptarget_say("Cannot find llvm-lit.")
60-
libomptarget_say("Please put llvm-lit in your PATH or set LIBOMPTARGET_LLVM_LIT_EXECUTABLE to its full path or point OPENMP_LLVM_TOOLS_DIR to its directory")
61-
libomptarget_warning_say("The check-libomptarget target will not be available!")
62-
return()
63-
endif()
64-
65-
find_program(LIBOMPTARGET_FILECHECK_EXECUTABLE
66-
NAMES FileCheck
67-
PATHS ${OPENMP_LLVM_TOOLS_DIR})
68-
if(NOT LIBOMPTARGET_FILECHECK_EXECUTABLE)
69-
libomptarget_say("Cannot find FileCheck.")
70-
libomptarget_say("Please put FileCheck in your PATH or set LIBOMPTARGET_FILECHECK_EXECUTABLE to its full path or point OPENMP_LLVM_TOOLS_DIR to its directory")
71-
libomptarget_warning_say("The check-libomptarget target will not be available!")
72-
return()
73-
endif()
74-
75-
# Set lit arguments
76-
# The -j 1 lets the actual tests run with the entire machine.
77-
# We have one test thread that spawns the tests serially. This allows
78-
# Each test to use the entire machine.
79-
set(LIBOMPTARGET_LIT_ARGS_DEFAULT "-sv --show-unsupported --show-xfail -j 1")
80-
if(MSVC OR XCODE)
81-
set(LIBOMPTARGET_LIT_ARGS_DEFAULT "${LIBOMPTARGET_LIT_ARGS_DEFAULT} --no-progress-bar")
82-
endif()
83-
set(LIBOMPTARGET_LIT_ARGS "${LIBOMPTARGET_LIT_ARGS_DEFAULT}" CACHE STRING
84-
"Default options for lit")
85-
separate_arguments(LIBOMPTARGET_LIT_ARGS)
86-
add_custom_target(check-libomptarget
87-
COMMAND ${PYTHON_EXECUTABLE} ${LIBOMPTARGET_LLVM_LIT_EXECUTABLE} ${LIBOMPTARGET_LIT_ARGS} ${CMAKE_CURRENT_BINARY_DIR}
88-
DEPENDS omptarget
89-
COMMENT "Running libomptarget tests"
90-
${cmake_3_2_USES_TERMINAL}
91-
)
92-
33+
add_openmp_testsuite(check-libomptarget "Running libomptarget tests" ${CMAKE_CURRENT_BINARY_DIR} DEPENDS omptarget omp)
34+
35+
if(${OPENMP_STANDALONE_BUILD})
9336
set(LIBOMPTARGET_OPENMP_HEADER_FOLDER "${CMAKE_CURRENT_BINARY_DIR}/../../runtime/src" CACHE STRING
9437
"Path to folder containing omp.h")
9538
set(LIBOMPTARGET_OPENMP_HOST_RTL_FOLDER "${CMAKE_CURRENT_BINARY_DIR}/../../runtime/src" CACHE STRING
9639
"Path to folder containing libomp.so")
9740
else()
98-
# LLVM source tree build, test just-built clang
99-
if(NOT MSVC)
100-
set(LIBOMPTARGET_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
101-
set(LIBOMPTARGET_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++)
102-
set(LIBOMPTARGET_FILECHECK_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/FileCheck)
103-
else()
104-
libomptarget_warning_say("Not prepared to run tests on Windows systems.")
105-
endif()
106-
set(LIBOMPTARGET_TEST_OPENMP_FLAG -fopenmp=libomp)
107-
# Use add_lit_testsuite() from LLVM CMake. This also depends on OpenMP
108-
# implementation because it uses omp.h.
109-
add_lit_testsuite(check-libomptarget
110-
"Running libomptarget tests"
111-
${CMAKE_CURRENT_BINARY_DIR}
112-
DEPENDS omptarget omp
113-
)
114-
11541
set(LIBOMPTARGET_OPENMP_HEADER_FOLDER "${LIBOMPTARGET_BINARY_DIR}/../runtime/src")
11642
endif()
11743

11844
# Configure the lit.site.cfg.in file
11945
set(AUTO_GEN_COMMENT "## Autogenerated by libomptarget configuration.\n# Do not edit!")
12046
configure_file(lit.site.cfg.in lit.site.cfg @ONLY)
121-

‎openmp/libomptarget/test/lit.cfg

+9-10
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,15 @@ config.test_exec_root = config.libomptarget_obj_root
3131
config.test_format = lit.formats.ShTest()
3232

3333
# compiler flags
34-
config.test_cflags = config.test_openmp_flag + \
35-
" -I " + config.test_source_root + \
34+
config.test_flags = " -I " + config.test_source_root + \
3635
" -I " + config.omp_header_directory + \
3736
" -L " + config.library_dir;
3837

3938
if config.omp_host_rtl_directory:
40-
config.test_cflags = config.test_cflags + " -L " + \
39+
config.test_flags = config.test_flags + " -L " + \
4140
config.omp_host_rtl_directory
4241

43-
config.test_cflags = config.test_cflags + " " + config.test_extra_cflags
42+
config.test_flags = config.test_flags + " " + config.test_extra_flags
4443

4544
if config.libomptarget_debug:
4645
config.available_features.add('libomptarget-debug')
@@ -53,8 +52,8 @@ elif config.operating_system == 'Darwin':
5352
append_dynamic_library_path('DYLD_LIBRARY_PATH', config.library_dir, ":")
5453
append_dynamic_library_path('DYLD_LIBRARY_PATH', \
5554
config.omp_host_rtl_directory, ";")
56-
config.test_cflags += " -Wl,-rpath," + config.library_dir
57-
config.test_cflags += " -Wl,-rpath," + config.omp_host_rtl_directory
55+
config.test_flags += " -Wl,-rpath," + config.library_dir
56+
config.test_flags += " -Wl,-rpath," + config.omp_host_rtl_directory
5857
else: # Unices
5958
append_dynamic_library_path('LD_LIBRARY_PATH', config.library_dir, ":")
6059
append_dynamic_library_path('LD_LIBRARY_PATH', \
@@ -98,9 +97,9 @@ for libomptarget_target in config.libomptarget_all_targets:
9897
libomptarget_target, \
9998
"%t-" + libomptarget_target))
10099
config.substitutions.append(("%clangxx-" + libomptarget_target, \
101-
"%clangxx %cflags -fopenmp-targets=" + libomptarget_target))
100+
"%clangxx %openmp_flags %flags -fopenmp-targets=" + libomptarget_target))
102101
config.substitutions.append(("%clang-" + libomptarget_target, \
103-
"%clang %cflags -fopenmp-targets=" + libomptarget_target))
102+
"%clang %openmp_flags %flags -fopenmp-targets=" + libomptarget_target))
104103
config.substitutions.append(("%fcheck-" + libomptarget_target, \
105104
config.libomptarget_filecheck + " %s"))
106105
else:
@@ -134,5 +133,5 @@ for libomptarget_target in config.libomptarget_all_targets:
134133

135134
config.substitutions.append(("%clangxx", config.test_cxx_compiler))
136135
config.substitutions.append(("%clang", config.test_c_compiler))
137-
config.substitutions.append(("%openmp_flag", config.test_openmp_flag))
138-
config.substitutions.append(("%cflags", config.test_cflags))
136+
config.substitutions.append(("%openmp_flags", config.test_openmp_flags))
137+
config.substitutions.append(("%flags", config.test_flags))
+5-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
@AUTO_GEN_COMMENT@
22

3-
config.test_c_compiler = "@LIBOMPTARGET_TEST_C_COMPILER@"
4-
config.test_cxx_compiler = "@LIBOMPTARGET_TEST_CXX_COMPILER@"
5-
config.test_openmp_flag = "@LIBOMPTARGET_TEST_OPENMP_FLAG@"
6-
# For the moment we still need to pass libomptarget explicitly. Once the driver
7-
# patch, lands, this is not required anymore.
8-
config.test_extra_cflags = "-lomptarget @LIBOMPTARGET_TEST_CFLAGS@"
3+
config.test_c_compiler = "@OPENMP_TEST_C_COMPILER@"
4+
config.test_cxx_compiler = "@OPENMP_TEST_CXX_COMPILER@"
5+
config.test_openmp_flags = "@OPENMP_TEST_OPENMP_FLAGS@"
6+
config.test_extra_flags = "@OPENMP_TEST_FLAGS@"
97
config.libomptarget_obj_root = "@CMAKE_CURRENT_BINARY_DIR@"
108
config.library_dir = "@LIBOMPTARGET_LIBRARY_DIR@"
119
config.omp_header_directory = "@LIBOMPTARGET_OPENMP_HEADER_FOLDER@"
1210
config.omp_host_rtl_directory = "@LIBOMPTARGET_OPENMP_HOST_RTL_FOLDER@"
1311
config.operating_system = "@CMAKE_SYSTEM_NAME@"
1412
config.libomptarget_all_targets = "@LIBOMPTARGET_ALL_TARGETS@".split()
1513
config.libomptarget_system_targets = "@LIBOMPTARGET_SYSTEM_TARGETS@".split()
16-
config.libomptarget_filecheck = "@LIBOMPTARGET_FILECHECK_EXECUTABLE@"
14+
config.libomptarget_filecheck = "@OPENMP_FILECHECK_EXECUTABLE@"
1715
config.libomptarget_debug = @LIBOMPTARGET_DEBUG@
1816

1917
# Let the main config do the real work.
2018
lit_config.load_config(config, "@LIBOMPTARGET_BASE_DIR@/test/lit.cfg")
21-

‎openmp/runtime/Build_With_CMake.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ Specifies install location of Hwloc. The configuration system will look for
174174
hwloc.h in ${LIBOMP_HWLOC_INSTALL_DIR}/include and the library in
175175
${LIBOMP_HWLOC_INSTALL_DIR}/lib.
176176

177-
-DLIBOMP_LLVM_LIT_EXECUTABLE=/path/to/llvm-lit
177+
-DOPENMP_LLVM_LIT_EXECUTABLE=/path/to/llvm-lit
178178
Default: search in PATH
179179
Specifiy full path to llvm-lit executable for running tests.
180180

0 commit comments

Comments
 (0)
Please sign in to comment.