[Openmp-commits] [openmp] [OpenMP] Add libomp unit test infrastructure (PR #168063)

Michael Kruse via Openmp-commits openmp-commits at lists.llvm.org
Wed Dec 3 14:58:50 PST 2025


================
@@ -200,6 +211,31 @@ if(${LIBOMP_USE_HWLOC})
   )
 endif()
 
+# Build a testing version of libomp that exports all symbols for unit tests.
+# This library uses the same compiled objects as libomp, but with all symbols
+# exported to allow testing internal functions.
+if(NOT WIN32 AND NOT STUBS_LIBRARY)
+  set(LIBOMP_TEST_LDFLAGS ${LIBOMP_CONFIGURED_LDFLAGS})
+  # Replace the libomp exports with the test exports exporting all symbols.
+  if(LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
+    string(REPLACE "${LIBOMP_SRC_DIR}/exports_so.txt"
+                   "${LIBOMP_SRC_DIR}/exports_test_so.txt"
+                   LIBOMP_TEST_LDFLAGS "${LIBOMP_TEST_LDFLAGS}")
+  endif()
+
+  # Create the testing library from the same objects as libomp.
+  add_library(omp_testing SHARED $<TARGET_OBJECTS:omp_objects>)
----------------
Meinersbur wrote:

You can hoist the definition of `LIBOMP_LINKER_LANGUAGE` one level up, i.e. https://github.com/llvm/llvm-project/blob/main/openmp/runtime/CMakeLists.txt, so it is available in both, src/ and unittests/.

I usually add such things to the top-level CMakeLists.txt in the first place. I don't see why definitions such as [`LIBOMP_VERSION_MAJOR`](https://github.com/llvm/llvm-project/pull/169909/files) should not be available in the entire project.

https://github.com/llvm/llvm-project/pull/168063


More information about the Openmp-commits mailing list