Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions openmp/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ endif()

add_subdirectory(src)
add_subdirectory(test)
add_subdirectory(unittests)

# make these variables available for tools:
set(LIBOMP_LIBRARY_DIR ${LIBOMP_LIBRARY_DIR} PARENT_SCOPE)
Expand Down
19 changes: 14 additions & 5 deletions openmp/runtime/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,26 @@ if(NOT WIN32)
endif()

# Add the OpenMP library
libomp_get_ldflags(LIBOMP_CONFIGURED_LDFLAGS)

# First, create an OBJECT library with all the runtime sources.
# This allows the unittests later to access internal symbols which don't export
# in libomp.
add_library(obj.omp OBJECT ${LIBOMP_SOURCE_FILES})
set_property(TARGET obj.omp PROPERTY FOLDER "OpenMP/Libraries")
set_property(TARGET obj.omp PROPERTY POSITION_INDEPENDENT_CODE ON)

libomp_get_ldflags(LIBOMP_CONFIGURED_LDFLAGS)
libomp_get_libflags(LIBOMP_CONFIGURED_LIBFLAGS)
# Build libomp library. Add LLVMSupport dependency if building in-tree with libomptarget profiling enabled.

# Build libomp library. Add LLVMSupport dependency if building in-tree with
# libomptarget profiling enabled.
if(OPENMP_STANDALONE_BUILD OR (NOT OPENMP_ENABLE_LIBOMP_PROFILING))
add_library(omp ${LIBOMP_LIBRARY_KIND} ${LIBOMP_SOURCE_FILES})
add_library(omp ${LIBOMP_LIBRARY_KIND} $<TARGET_OBJECTS:obj.omp>)
set_property(TARGET omp PROPERTY FOLDER "OpenMP/Libraries")
# Linking command will include libraries in LIBOMP_CONFIGURED_LIBFLAGS
target_link_libraries(omp ${LIBOMP_CONFIGURED_LIBFLAGS} ${LIBOMP_DL_LIBS})
else()
add_llvm_library(omp ${LIBOMP_LIBRARY_KIND} ${LIBOMP_SOURCE_FILES} PARTIAL_SOURCES_INTENDED
add_llvm_library(omp ${LIBOMP_LIBRARY_KIND} $<TARGET_OBJECTS:obj.omp> PARTIAL_SOURCES_INTENDED
LINK_LIBS ${LIBOMP_CONFIGURED_LIBFLAGS} ${LIBOMP_DL_LIBS}
LINK_COMPONENTS Support
BUILDTREE_ONLY
Expand Down Expand Up @@ -296,7 +305,7 @@ set(LIBOMPTARGET_OPENMP_HOST_RTL_FOLDER "${LIBOMP_LIBRARY_DIR}" CACHE STRING
# objects depend on : .inc files
add_custom_target(libomp-needed-headers DEPENDS kmp_i18n_id.inc kmp_i18n_default.inc)
set_target_properties(libomp-needed-headers PROPERTIES FOLDER "OpenMP/Sourcegenning")
add_dependencies(omp libomp-needed-headers)
add_dependencies(obj.omp libomp-needed-headers)

# Windows specific build rules
if(WIN32)
Expand Down
22 changes: 22 additions & 0 deletions openmp/runtime/test/Unit/lit.cfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- Python -*-

# Configuration file for the 'lit' test runner.

import os
import subprocess

import lit.formats

# name: The name of this test suite.
config.name = "OpenMP-Unit"

# suffixes: A list of file extensions to treat as test files.
config.suffixes = []

# test_source_root: The root path where tests are located.
# test_exec_root: The root path where tests should be run.
config.test_exec_root = config.openmp_unittests_dir
config.test_source_root = config.test_exec_root

# testFormat: The test format to use to interpret tests.
config.test_format = lit.formats.GoogleTest(config.llvm_build_mode, "Tests")
8 changes: 8 additions & 0 deletions openmp/runtime/test/Unit/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@AUTO_GEN_COMMENT@

config.openmp_unittests_dir = "@CMAKE_CURRENT_BINARY_DIR@/../unittests"
config.llvm_build_mode = lit_config.substitute("@LLVM_BUILD_MODE@")

# Let the main config do the real work.
lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/../test/Unit/lit.cfg.py")

76 changes: 76 additions & 0 deletions openmp/runtime/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
add_custom_target(OpenMPUnitTests)
set_target_properties(OpenMPUnitTests PROPERTIES FOLDER "OpenMP/Tests")

if(WIN32 OR STUBS_LIBRARY)
message(WARNING "OpenMP unittests disabled due to stub library or Windows")
return()
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.

libomp_get_ldflags(LIBOMP_TEST_LDFLAGS)
libomp_get_libflags(LIBOMP_TEST_LIBFLAGS)
# 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()
# Duplicate setting of LIBOMP_LINKER_LANGUAGE to match libomp.
if(NOT ${LIBOMP_USE_STDCPPLIB})
set(LIBOMP_LINKER_LANGUAGE C)
set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES)
else()
set(LIBOMP_LINKER_LANGUAGE CXX)
endif()

# Create the testing library from the same objects as libomp.
add_library(omp_testing SHARED $<TARGET_OBJECTS:obj.omp>)
set_property(TARGET omp_testing PROPERTY FOLDER "OpenMP/Libraries")
target_link_libraries(omp_testing PUBLIC default_gtest)
target_link_libraries(omp_testing PUBLIC ${LIBOMP_TEST_LIBFLAGS} ${LIBOMP_DL_LIBS})
set_target_properties(omp_testing PROPERTIES
PREFIX "" SUFFIX "" OUTPUT_NAME "libomp_testing${LIBOMP_LIBRARY_SUFFIX}"
LINK_FLAGS "${LIBOMP_TEST_LDFLAGS}"
LINKER_LANGUAGE ${LIBOMP_LINKER_LANGUAGE}
EXCLUDE_FROM_ALL TRUE # Don't build by default, only when tests need it
)
target_include_directories(omp_testing PUBLIC
${LIBOMP_INCLUDE_DIR}
${LIBOMP_SRC_DIR}
)

# Make the targets default_gtest and default_gtest_main available.
build_gtest()

function(add_openmp_unittest test_name)
add_unittest(OpenMPUnitTests ${test_name} ${ARGN})

# Link against the testing library which exports all symbols.
target_link_libraries(${test_name} PRIVATE omp_testing)

if(TARGET default_gtest)
target_link_libraries(${test_name} PRIVATE default_gtest_main default_gtest)
else ()
target_link_libraries(${test_name} PRIVATE llvm_gtest_main llvm_gtest)
endif ()
endfunction()

configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/../test/Unit/lit.site.cfg.py.in
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
MAIN_CONFIG
${CMAKE_CURRENT_SOURCE_DIR}/../test/Unit/lit.cfg.py
)

add_openmp_testsuite(
check-libomp-unit
"Running libomp unit tests"
${CMAKE_CURRENT_BINARY_DIR}
EXCLUDE_FROM_CHECK_ALL
DEPENDS OpenMPUnitTests
)

add_subdirectory(String)
9 changes: 9 additions & 0 deletions openmp/runtime/unittests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# libomp Unit Tests

Usage:
```
cd <your-llvm-build-directory>/runtimes/runtimes-bins
ninja check-libomp-unit
```

Note: unit tests are currently not supported on Windows
3 changes: 3 additions & 0 deletions openmp/runtime/unittests/String/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_openmp_unittest(StringTests
TestKmpStr.cpp
)
Loading
Loading