From 6a77d4a2c48250e3d6ac325630c8b9cb3ec3cbc4 Mon Sep 17 00:00:00 2001 From: Jesus Checa Hidalgo Date: Tue, 5 Mar 2024 14:07:37 +0100 Subject: [PATCH] Detect if libomp is supported in the environment From LLVM 18, libomp is supported in s390x. Previously all the libomp related tests were marked as XFAIL for s390x, which is no longer valid and marks passing tests as failures. With the libomp detection and a new REQUIRE rule for them the XFAIL is no longer needed. --- CMakeLists.txt | 19 +++++++++++++++++++ tests/basic_openmp.c | 3 +-- tests/lit.site.cfg.in | 1 + tests/openmp_headers.c | 3 +-- tests/openmp_tools.c | 3 +-- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d5def3a..982f28b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,6 +63,25 @@ option(ENABLE_HWASAN ${SUPPORT_HWASAN} ) +# Detect if libomp is supported in the current host. Setting it manually in all +# the environments can be tricky as s390x supports it only in llvm < 18 +# This can still be explicitly enforced via -DENABLE_LIBOMP=ON|OFF +file(WRITE ${CMAKE_BINARY_DIR}/test.c "int main(){return 0;}") +message(STATUS "Checking libomp support") +execute_process(COMMAND + ${CLANG_BINARY} -x c -fopenmp ${CMAKE_BINARY_DIR}/test.c + RESULT_VARIABLE PROC_RETURN + ) +if (PROC_RETURN EQUAL 0) + set(SUPPORT_LIBOMP ON) +else() + message(STATUS "libomp not supported, related tests will be disabled") + set(SUPPORT_LIBOMP OFF) +endif() +OPTION(ENABLE_LIBOMP + "Enable tests that require libomp" + ${SUPPORT_LIBOMP}) + configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/tests/lit.site.cfg.in ${CMAKE_BINARY_DIR}/tests/lit.site.cfg diff --git a/tests/basic_openmp.c b/tests/basic_openmp.c index c389e41..4073c2e 100644 --- a/tests/basic_openmp.c +++ b/tests/basic_openmp.c @@ -2,8 +2,7 @@ // // RUN: %clang -fopenmp %s -o %t // RUN: %t | grep "Num Threads: 1" -// REQUIRES: clang -// XFAIL: s390x +// REQUIRES: clang, libomp #include #include diff --git a/tests/lit.site.cfg.in b/tests/lit.site.cfg.in index a40946f..0608006 100644 --- a/tests/lit.site.cfg.in +++ b/tests/lit.site.cfg.in @@ -52,3 +52,4 @@ enable_feature("libc++", "@ENABLE_LIBCXX@") enable_feature("static-libc++", "@ENABLE_STATIC_LIBCXX@") enable_feature("libunwind", "@ENABLE_LIBUNWIND@") enable_feature("support_hwasan", "@ENABLE_HWASAN@") +enable_feature("libomp", "@ENABLE_LIBOMP@") diff --git a/tests/openmp_headers.c b/tests/openmp_headers.c index 40db640..d428b8c 100644 --- a/tests/openmp_headers.c +++ b/tests/openmp_headers.c @@ -1,8 +1,7 @@ // Test OpenMP headers install // // RUN: %clang -fopenmp -E %s -o %t -// REQUIRES: clang -// XFAIL: s390x +// REQUIRES: clang, libomp #include #if _OPENMP >= 201811 diff --git a/tests/openmp_tools.c b/tests/openmp_tools.c index ea5893d..6154e56 100644 --- a/tests/openmp_tools.c +++ b/tests/openmp_tools.c @@ -2,8 +2,7 @@ // RUN: %clang -fopenmp -DTOOLS %s -shared -o %t_Tools.so // RUN: %clang -fopenmp -UTOOLS %s -o %t // RUN: OMP_TOOL_LIBRARIES=%t_Tools.so %t | grep "INIT" -// REQUIRES: clang -// XFAIL: s390x +// REQUIRES: clang, libomp #ifdef TOOLS // OpenMP Tools are only supported starting OpenMP 5