2017-11-30 03:31:52 +08:00
|
|
|
# Keep track if we have all dependencies.
|
|
|
|
set(ENABLE_CHECK_TARGETS TRUE)
|
|
|
|
|
|
|
|
# Function to find required dependencies for testing.
|
|
|
|
function(find_standalone_test_dependencies)
|
|
|
|
include(FindPythonInterp)
|
|
|
|
|
|
|
|
if (NOT PYTHONINTERP_FOUND)
|
|
|
|
message(STATUS "Could not find Python.")
|
|
|
|
message(WARNING "The check targets will not be available!")
|
|
|
|
set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE)
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Find executables.
|
|
|
|
find_program(OPENMP_LLVM_LIT_EXECUTABLE
|
|
|
|
NAMES llvm-lit lit.py lit
|
|
|
|
PATHS ${OPENMP_LLVM_TOOLS_DIR})
|
|
|
|
if (NOT OPENMP_LLVM_LIT_EXECUTABLE)
|
|
|
|
message(STATUS "Cannot find llvm-lit.")
|
|
|
|
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.")
|
|
|
|
message(WARNING "The check targets will not be available!")
|
|
|
|
set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE)
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
find_program(OPENMP_FILECHECK_EXECUTABLE
|
|
|
|
NAMES FileCheck
|
|
|
|
PATHS ${OPENMP_LLVM_TOOLS_DIR})
|
|
|
|
if (NOT OPENMP_FILECHECK_EXECUTABLE)
|
|
|
|
message(STATUS "Cannot find FileCheck.")
|
|
|
|
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.")
|
|
|
|
message(WARNING "The check targets will not be available!")
|
|
|
|
set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE)
|
|
|
|
return()
|
|
|
|
endif()
|
2020-04-22 04:27:32 +08:00
|
|
|
|
|
|
|
find_program(OPENMP_NOT_EXECUTABLE
|
|
|
|
NAMES not
|
|
|
|
PATHS ${OPENMP_LLVM_TOOLS_DIR})
|
|
|
|
if (NOT OPENMP_NOT_EXECUTABLE)
|
|
|
|
message(STATUS "Cannot find 'not'.")
|
|
|
|
message(STATUS "Please put 'not' in your PATH, set OPENMP_NOT_EXECUTABLE to its full path, or point OPENMP_LLVM_TOOLS_DIR to its directory.")
|
|
|
|
message(WARNING "The check targets will not be available!")
|
|
|
|
set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE)
|
|
|
|
return()
|
|
|
|
endif()
|
2017-11-30 03:31:52 +08:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
if (${OPENMP_STANDALONE_BUILD})
|
|
|
|
find_standalone_test_dependencies()
|
|
|
|
|
|
|
|
# Make sure we can use the console pool for recent CMake and Ninja > 1.5.
|
|
|
|
if (CMAKE_VERSION VERSION_LESS 3.1.20141117)
|
|
|
|
set(cmake_3_2_USES_TERMINAL)
|
|
|
|
else()
|
|
|
|
set(cmake_3_2_USES_TERMINAL USES_TERMINAL)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Set lit arguments.
|
|
|
|
set(DEFAULT_LIT_ARGS "-sv --show-unsupported --show-xfail")
|
|
|
|
if (MSVC OR XCODE)
|
|
|
|
set(DEFAULT_LIT_ARGS "${DEFAULT_LIT_ARGS} --no-progress-bar")
|
|
|
|
endif()
|
|
|
|
set(OPENMP_LIT_ARGS "${DEFAULT_LIT_ARGS}" CACHE STRING "Options for lit.")
|
|
|
|
separate_arguments(OPENMP_LIT_ARGS)
|
|
|
|
else()
|
|
|
|
set(OPENMP_FILECHECK_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/FileCheck)
|
2020-04-22 04:27:32 +08:00
|
|
|
set(OPENMP_NOT_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/not)
|
2017-11-30 03:31:52 +08:00
|
|
|
endif()
|
|
|
|
|
2017-12-01 01:08:31 +08:00
|
|
|
# Macro to extract information about compiler from file. (no own scope)
|
|
|
|
macro(extract_test_compiler_information lang file)
|
|
|
|
file(READ ${file} information)
|
|
|
|
list(GET information 0 path)
|
|
|
|
list(GET information 1 id)
|
|
|
|
list(GET information 2 version)
|
|
|
|
list(GET information 3 openmp_flags)
|
2020-01-14 15:44:06 +08:00
|
|
|
list(GET information 4 has_tsan_flags)
|
2017-12-01 01:08:31 +08:00
|
|
|
|
|
|
|
set(OPENMP_TEST_${lang}_COMPILER_PATH ${path})
|
|
|
|
set(OPENMP_TEST_${lang}_COMPILER_ID ${id})
|
|
|
|
set(OPENMP_TEST_${lang}_COMPILER_VERSION ${version})
|
|
|
|
set(OPENMP_TEST_${lang}_COMPILER_OPENMP_FLAGS ${openmp_flags})
|
2020-01-14 15:44:06 +08:00
|
|
|
set(OPENMP_TEST_${lang}_COMPILER_HAS_TSAN_FLAGS ${has_tsan_flags})
|
2017-12-01 01:08:31 +08:00
|
|
|
endmacro()
|
|
|
|
|
|
|
|
# Function to set variables with information about the test compiler.
|
|
|
|
function(set_test_compiler_information dir)
|
|
|
|
extract_test_compiler_information(C ${dir}/CCompilerInformation.txt)
|
|
|
|
extract_test_compiler_information(CXX ${dir}/CXXCompilerInformation.txt)
|
|
|
|
if (NOT("${OPENMP_TEST_C_COMPILER_ID}" STREQUAL "${OPENMP_TEST_CXX_COMPILER_ID}" AND
|
|
|
|
"${OPENMP_TEST_C_COMPILER_VERSION}" STREQUAL "${OPENMP_TEST_CXX_COMPILER_VERSION}"))
|
|
|
|
message(STATUS "Test compilers for C and C++ don't match.")
|
|
|
|
message(WARNING "The check targets will not be available!")
|
|
|
|
set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE)
|
|
|
|
else()
|
|
|
|
set(OPENMP_TEST_COMPILER_ID "${OPENMP_TEST_C_COMPILER_ID}" PARENT_SCOPE)
|
|
|
|
set(OPENMP_TEST_COMPILER_VERSION "${OPENMP_TEST_C_COMPILER_VERSION}" PARENT_SCOPE)
|
|
|
|
set(OPENMP_TEST_COMPILER_OPENMP_FLAGS "${OPENMP_TEST_C_COMPILER_OPENMP_FLAGS}" PARENT_SCOPE)
|
2020-01-14 15:44:06 +08:00
|
|
|
set(OPENMP_TEST_COMPILER_HAS_TSAN_FLAGS "${OPENMP_TEST_C_COMPILER_HAS_TSAN_FLAGS}" PARENT_SCOPE)
|
2017-12-01 01:08:31 +08:00
|
|
|
|
|
|
|
# Determine major version.
|
|
|
|
string(REGEX MATCH "[0-9]+" major "${OPENMP_TEST_C_COMPILER_VERSION}")
|
2018-08-03 03:13:07 +08:00
|
|
|
string(REGEX MATCH "[0-9]+\\.[0-9]+" majorminor "${OPENMP_TEST_C_COMPILER_VERSION}")
|
2017-12-01 01:08:31 +08:00
|
|
|
set(OPENMP_TEST_COMPILER_VERSION_MAJOR "${major}" PARENT_SCOPE)
|
2018-08-03 03:13:07 +08:00
|
|
|
set(OPENMP_TEST_COMPILER_VERSION_MAJOR_MINOR "${majorminor}" PARENT_SCOPE)
|
2017-12-01 01:08:31 +08:00
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
if (${OPENMP_STANDALONE_BUILD})
|
|
|
|
# Detect compiler that should be used for testing.
|
|
|
|
# We cannot use ExternalProject_Add() because its configuration runs when this
|
|
|
|
# project is built which is too late for detecting the compiler...
|
|
|
|
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/DetectTestCompiler)
|
|
|
|
execute_process(
|
2019-01-16 03:08:26 +08:00
|
|
|
COMMAND ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} ${CMAKE_CURRENT_LIST_DIR}/DetectTestCompiler
|
2017-12-01 01:08:31 +08:00
|
|
|
-DCMAKE_C_COMPILER=${OPENMP_TEST_C_COMPILER}
|
|
|
|
-DCMAKE_CXX_COMPILER=${OPENMP_TEST_CXX_COMPILER}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/DetectTestCompiler
|
|
|
|
OUTPUT_VARIABLE DETECT_COMPILER_OUT
|
|
|
|
ERROR_VARIABLE DETECT_COMPILER_ERR
|
|
|
|
RESULT_VARIABLE DETECT_COMPILER_RESULT)
|
|
|
|
if (DETECT_COMPILER_RESULT)
|
|
|
|
message(STATUS "Could not detect test compilers.")
|
|
|
|
message(WARNING "The check targets will not be available!")
|
|
|
|
set(ENABLE_CHECK_TARGETS FALSE)
|
|
|
|
else()
|
|
|
|
set_test_compiler_information(${CMAKE_CURRENT_BINARY_DIR}/DetectTestCompiler)
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
# Set the information that we know.
|
|
|
|
set(OPENMP_TEST_COMPILER_ID "Clang")
|
|
|
|
# Cannot use CLANG_VERSION because we are not guaranteed that this is already set.
|
|
|
|
set(OPENMP_TEST_COMPILER_VERSION "${LLVM_VERSION}")
|
|
|
|
set(OPENMP_TEST_COMPILER_VERSION_MAJOR "${LLVM_MAJOR_VERSION}")
|
2018-08-03 03:13:07 +08:00
|
|
|
set(OPENMP_TEST_COMPILER_VERSION_MAJOR_MINOR "${LLVM_MAJOR_VERSION}.${LLVM_MINOR_VERSION}")
|
Ensure correct pthread flags and libraries are used
On most platforms, certain compiler and linker flags have to be passed
when using pthreads, otherwise linking against libomp.so might fail with
undefined references to several pthread functions.
Use CMake's `find_package(Threads)` to determine these for standalone
builds, or take them (and optionally modify them) from the top-level
LLVM cmake files.
Also, On FreeBSD, ensure that libomp.so is linked against libm.so,
similar to NetBSD.
Adjust test cases with hardcoded `-lpthread` flag to use the common
build flags, which should now have the required pthread flags.
Reviewers: emaste, jlpeyton, krytarowski, mgorny, protze.joachim, Hahnfeld
Reviewed By: Hahnfeld
Subscribers: AndreyChurbanov, tra, EricWF, Hahnfeld, jfb, jdoerfert, openmp-commits
Tags: #openmp
Differential Revision: https://reviews.llvm.org/D59451
llvm-svn: 357618
2019-04-04 02:11:36 +08:00
|
|
|
# Unfortunately the top-level cmake/config-ix.cmake file mangles CMake's
|
|
|
|
# CMAKE_THREAD_LIBS_INIT variable from the FindThreads package, so work
|
|
|
|
# around that, until it is fixed there.
|
2019-04-06 06:19:40 +08:00
|
|
|
if("${CMAKE_THREAD_LIBS_INIT}" STREQUAL "-lpthread")
|
Ensure correct pthread flags and libraries are used
On most platforms, certain compiler and linker flags have to be passed
when using pthreads, otherwise linking against libomp.so might fail with
undefined references to several pthread functions.
Use CMake's `find_package(Threads)` to determine these for standalone
builds, or take them (and optionally modify them) from the top-level
LLVM cmake files.
Also, On FreeBSD, ensure that libomp.so is linked against libm.so,
similar to NetBSD.
Adjust test cases with hardcoded `-lpthread` flag to use the common
build flags, which should now have the required pthread flags.
Reviewers: emaste, jlpeyton, krytarowski, mgorny, protze.joachim, Hahnfeld
Reviewed By: Hahnfeld
Subscribers: AndreyChurbanov, tra, EricWF, Hahnfeld, jfb, jdoerfert, openmp-commits
Tags: #openmp
Differential Revision: https://reviews.llvm.org/D59451
llvm-svn: 357618
2019-04-04 02:11:36 +08:00
|
|
|
set(OPENMP_TEST_COMPILER_THREAD_FLAGS "-pthread")
|
|
|
|
else()
|
|
|
|
set(OPENMP_TEST_COMPILER_THREAD_FLAGS "${CMAKE_THREAD_LIBS_INIT}")
|
|
|
|
endif()
|
2020-01-14 15:44:06 +08:00
|
|
|
if(TARGET tsan)
|
|
|
|
set(OPENMP_TEST_COMPILER_HAS_TSAN_FLAGS 1)
|
|
|
|
else()
|
|
|
|
set(OPENMP_TEST_COMPILER_HAS_TSAN_FLAGS 0)
|
|
|
|
endif()
|
2018-02-15 16:10:22 +08:00
|
|
|
# TODO: Implement blockaddress in GlobalISel and remove this flag!
|
Ensure correct pthread flags and libraries are used
On most platforms, certain compiler and linker flags have to be passed
when using pthreads, otherwise linking against libomp.so might fail with
undefined references to several pthread functions.
Use CMake's `find_package(Threads)` to determine these for standalone
builds, or take them (and optionally modify them) from the top-level
LLVM cmake files.
Also, On FreeBSD, ensure that libomp.so is linked against libm.so,
similar to NetBSD.
Adjust test cases with hardcoded `-lpthread` flag to use the common
build flags, which should now have the required pthread flags.
Reviewers: emaste, jlpeyton, krytarowski, mgorny, protze.joachim, Hahnfeld
Reviewed By: Hahnfeld
Subscribers: AndreyChurbanov, tra, EricWF, Hahnfeld, jfb, jdoerfert, openmp-commits
Tags: #openmp
Differential Revision: https://reviews.llvm.org/D59451
llvm-svn: 357618
2019-04-04 02:11:36 +08:00
|
|
|
set(OPENMP_TEST_COMPILER_OPENMP_FLAGS "-fopenmp ${OPENMP_TEST_COMPILER_THREAD_FLAGS} -fno-experimental-isel")
|
2017-12-01 01:08:31 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Function to set compiler features for use in lit.
|
|
|
|
function(set_test_compiler_features)
|
|
|
|
if ("${OPENMP_TEST_COMPILER_ID}" STREQUAL "GNU")
|
|
|
|
set(comp "gcc")
|
2017-12-21 21:55:16 +08:00
|
|
|
elseif ("${OPENMP_TEST_COMPILER_ID}" STREQUAL "Intel")
|
|
|
|
set(comp "icc")
|
2017-12-01 01:08:31 +08:00
|
|
|
else()
|
|
|
|
# Just use the lowercase of the compiler ID as fallback.
|
|
|
|
string(TOLOWER "${OPENMP_TEST_COMPILER_ID}" comp)
|
|
|
|
endif()
|
2018-08-03 03:13:07 +08:00
|
|
|
set(OPENMP_TEST_COMPILER_FEATURES "['${comp}', '${comp}-${OPENMP_TEST_COMPILER_VERSION_MAJOR}', '${comp}-${OPENMP_TEST_COMPILER_VERSION_MAJOR_MINOR}', '${comp}-${OPENMP_TEST_COMPILER_VERSION}']" PARENT_SCOPE)
|
2017-12-01 01:08:31 +08:00
|
|
|
endfunction()
|
|
|
|
set_test_compiler_features()
|
|
|
|
|
2017-11-30 03:31:52 +08:00
|
|
|
# Function to add a testsuite for an OpenMP runtime library.
|
|
|
|
function(add_openmp_testsuite target comment)
|
|
|
|
if (NOT ENABLE_CHECK_TARGETS)
|
|
|
|
add_custom_target(${target}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo "${target} does nothing, dependencies not found.")
|
|
|
|
message(STATUS "${target} does nothing.")
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
2020-02-07 07:26:10 +08:00
|
|
|
cmake_parse_arguments(ARG "EXCLUDE_FROM_CHECK_ALL" "" "DEPENDS;ARGS" ${ARGN})
|
|
|
|
# EXCLUDE_FROM_CHECK_ALL excludes the test ${target} out of check-openmp.
|
|
|
|
if (NOT ARG_EXCLUDE_FROM_CHECK_ALL)
|
2017-11-30 03:31:52 +08:00
|
|
|
# Register the testsuites and depends for the check-openmp rule.
|
|
|
|
set_property(GLOBAL APPEND PROPERTY OPENMP_LIT_TESTSUITES ${ARG_UNPARSED_ARGUMENTS})
|
|
|
|
set_property(GLOBAL APPEND PROPERTY OPENMP_LIT_DEPENDS ${ARG_DEPENDS})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (${OPENMP_STANDALONE_BUILD})
|
2018-09-28 23:05:43 +08:00
|
|
|
set(LIT_ARGS ${OPENMP_LIT_ARGS} ${ARG_ARGS})
|
2017-11-30 03:31:52 +08:00
|
|
|
add_custom_target(${target}
|
2018-09-28 23:05:43 +08:00
|
|
|
COMMAND ${PYTHON_EXECUTABLE} ${OPENMP_LLVM_LIT_EXECUTABLE} ${LIT_ARGS} ${ARG_UNPARSED_ARGUMENTS}
|
2017-11-30 03:31:52 +08:00
|
|
|
COMMENT ${comment}
|
|
|
|
DEPENDS ${ARG_DEPENDS}
|
|
|
|
${cmake_3_2_USES_TERMINAL}
|
|
|
|
)
|
|
|
|
else()
|
2020-02-14 01:27:52 +08:00
|
|
|
if (ARG_EXCLUDE_FROM_CHECK_ALL)
|
|
|
|
add_lit_testsuite(${target}
|
|
|
|
${comment}
|
|
|
|
${ARG_UNPARSED_ARGUMENTS}
|
|
|
|
EXCLUDE_FROM_CHECK_ALL
|
|
|
|
DEPENDS clang clang-resource-headers FileCheck ${ARG_DEPENDS}
|
|
|
|
ARGS ${ARG_ARGS}
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
add_lit_testsuite(${target}
|
|
|
|
${comment}
|
|
|
|
${ARG_UNPARSED_ARGUMENTS}
|
|
|
|
DEPENDS clang clang-resource-headers FileCheck ${ARG_DEPENDS}
|
|
|
|
ARGS ${ARG_ARGS}
|
|
|
|
)
|
|
|
|
endif()
|
2017-11-30 03:31:52 +08:00
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(construct_check_openmp_target)
|
|
|
|
get_property(OPENMP_LIT_TESTSUITES GLOBAL PROPERTY OPENMP_LIT_TESTSUITES)
|
|
|
|
get_property(OPENMP_LIT_DEPENDS GLOBAL PROPERTY OPENMP_LIT_DEPENDS)
|
|
|
|
|
|
|
|
# We already added the testsuites themselves, no need to do that again.
|
2020-02-07 07:26:10 +08:00
|
|
|
add_openmp_testsuite(check-openmp "Running OpenMP tests" ${OPENMP_LIT_TESTSUITES} EXCLUDE_FROM_CHECK_ALL DEPENDS ${OPENMP_LIT_DEPENDS})
|
2017-11-30 03:31:52 +08:00
|
|
|
endfunction()
|