-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[OpenMP] Add libomp unit test infrastructure #168063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ro-i
wants to merge
5
commits into
main
Choose a base branch
from
users/ro-i/check-libomp-unit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -174,17 +174,26 @@ if(NOT WIN32) | |
| endif() | ||
|
|
||
| # Add the OpenMP library | ||
|
|
||
| # First, create an OBJECT library with all the runtime sources. | ||
| # This allows both the main library and unit tests to link against the same compiled objects. | ||
| add_library(omp_objects OBJECT ${LIBOMP_SOURCE_FILES}) | ||
ro-i marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| set_property(TARGET omp_objects PROPERTY FOLDER "OpenMP/Libraries") | ||
| set_property(TARGET omp_objects PROPERTY POSITION_INDEPENDENT_CODE ON) | ||
| # Export the omp_objects target so unittests can use it | ||
| set(LIBOMP_OBJECTS_TARGET omp_objects PARENT_SCOPE) | ||
ro-i marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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. | ||
| 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:omp_objects>) | ||
|
||
| 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:omp_objects> PARTIAL_SOURCES_INTENDED | ||
| LINK_LIBS ${LIBOMP_CONFIGURED_LIBFLAGS} ${LIBOMP_DL_LIBS} | ||
| LINK_COMPONENTS Support | ||
| BUILDTREE_ONLY | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| add_custom_target(OpenMPUnitTests) | ||
| set_target_properties(OpenMPUnitTests PROPERTIES FOLDER "OpenMP/Tests") | ||
|
|
||
| if (NOT TARGET llvm_gtest) | ||
| message(WARNING "OpenMP unittests disabled due to GTest being unavailable; " | ||
| "Try LLVM_INSTALL_GTEST=ON for the LLVM build") | ||
| return () | ||
| endif () | ||
|
|
||
| function(add_openmp_unittest test_dirname) | ||
ro-i marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| add_unittest(OpenMPUnitTests ${test_dirname} ${ARGN}) | ||
|
|
||
| # Link against the object library created in runtime/src | ||
| target_link_libraries(${test_dirname} PRIVATE | ||
| $<TARGET_OBJECTS:omp_objects> | ||
| ) | ||
|
|
||
| target_include_directories(${test_dirname} PRIVATE | ||
| ${LIBOMP_INCLUDE_DIR} | ||
| ${LIBOMP_SRC_DIR} | ||
| ) | ||
| endfunction() | ||
|
|
||
| configure_lit_site_cfg( | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in | ||
| ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py | ||
| MAIN_CONFIG | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py | ||
| ) | ||
|
|
||
| add_openmp_testsuite( | ||
| check-libomp-unit | ||
| "Running libomp unit tests" | ||
| ${CMAKE_CURRENT_BINARY_DIR} | ||
| EXCLUDE_FROM_CHECK_ALL | ||
| DEPENDS OpenMPUnitTests omp | ||
ro-i marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| add_subdirectory(src) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # libomp Unit Tests | ||
|
|
||
| Usage: | ||
| ``` | ||
| cd <your-llvm-build-directory>/runtimes/runtimes-bins | ||
| ninja check-libomp-unit | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, ".unittests") | ||
ro-i marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| @AUTO_GEN_COMMENT@ | ||
|
|
||
| config.library_dir = "@LIBOMP_LIBRARY_DIR@" | ||
ro-i marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| config.openmp_unittests_dir = "@CMAKE_CURRENT_BINARY_DIR@" | ||
| config.llvm_build_mode = lit_config.substitute("@LLVM_BUILD_MODE@") | ||
Meinersbur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Let the main config do the real work. | ||
| lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg.py") | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| add_openmp_unittest(libomp.unittests | ||
| TestKmpStr.cpp | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,239 @@ | ||
| //===- TestKmpStr.cpp - Tests for kmp_str utilities ----------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "kmp_str.h" | ||
| #include "gtest/gtest.h" | ||
| #include <cstring> | ||
|
|
||
| namespace { | ||
|
|
||
| // Test basic string buffer initialization | ||
| TEST(KmpStrTest, BufferInit) { | ||
| kmp_str_buf_t buffer; | ||
| __kmp_str_buf_init(&buffer); | ||
|
|
||
| EXPECT_NE(buffer.str, nullptr); | ||
| EXPECT_GT(buffer.size, 0u); | ||
| EXPECT_EQ(buffer.used, 0); | ||
| EXPECT_EQ(buffer.str[0], '\0'); | ||
| } | ||
|
|
||
| // Test string buffer clear | ||
| TEST(KmpStrTest, BufferClear) { | ||
| kmp_str_buf_t buffer; | ||
| __kmp_str_buf_init(&buffer); | ||
| __kmp_str_buf_print(&buffer, "test string"); | ||
|
|
||
| EXPECT_GT(buffer.used, 0); | ||
|
|
||
| __kmp_str_buf_clear(&buffer); | ||
| EXPECT_EQ(buffer.used, 0); | ||
| EXPECT_EQ(buffer.str[0], '\0'); | ||
|
|
||
| __kmp_str_buf_free(&buffer); | ||
| } | ||
|
|
||
| // Test string buffer print | ||
| TEST(KmpStrTest, BufferPrint) { | ||
| kmp_str_buf_t buffer; | ||
| __kmp_str_buf_init(&buffer); | ||
|
|
||
| __kmp_str_buf_print(&buffer, "Hello, %s!", "World"); | ||
|
|
||
| EXPECT_STREQ(buffer.str, "Hello, World!"); | ||
| EXPECT_EQ(buffer.used, 13); | ||
|
|
||
| __kmp_str_buf_free(&buffer); | ||
| } | ||
|
|
||
| // Test string buffer concatenation | ||
| TEST(KmpStrTest, BufferCat) { | ||
| kmp_str_buf_t buffer; | ||
| __kmp_str_buf_init(&buffer); | ||
|
|
||
| __kmp_str_buf_cat(&buffer, "Hello", 5); | ||
| __kmp_str_buf_cat(&buffer, " ", 1); | ||
| __kmp_str_buf_cat(&buffer, "World", 5); | ||
|
|
||
| EXPECT_STREQ(buffer.str, "Hello World"); | ||
|
|
||
| __kmp_str_buf_free(&buffer); | ||
| } | ||
|
|
||
| // Test string buffer reservation | ||
| TEST(KmpStrTest, BufferReserve) { | ||
| kmp_str_buf_t buffer; | ||
| __kmp_str_buf_init(&buffer); | ||
|
|
||
| size_t large_size = 2048; | ||
| __kmp_str_buf_reserve(&buffer, large_size); | ||
|
|
||
| EXPECT_GE(buffer.size, large_size); | ||
|
|
||
| __kmp_str_buf_free(&buffer); | ||
| } | ||
|
|
||
| // Test basic string to int conversion | ||
| TEST(KmpStrTest, BasicStrToInt) { | ||
| EXPECT_EQ(__kmp_basic_str_to_int("0"), 0); | ||
| EXPECT_EQ(__kmp_basic_str_to_int("1"), 1); | ||
| EXPECT_EQ(__kmp_basic_str_to_int("42"), 42); | ||
| EXPECT_EQ(__kmp_basic_str_to_int("123"), 123); | ||
| } | ||
|
|
||
| // Test string match | ||
| TEST(KmpStrTest, StrMatch) { | ||
| const char *data = "Hello World"; | ||
|
|
||
| // Test exact match (len == 0) | ||
| EXPECT_TRUE(__kmp_str_match("Hello World", 0, data)); | ||
| EXPECT_FALSE(__kmp_str_match("Hello", 0, data)); // Not exact (data is longer) | ||
|
|
||
| // Test prefix match (len < 0) | ||
| EXPECT_TRUE( | ||
| __kmp_str_match("Hello", -1, data)); // "Hello" is prefix of "Hello World" | ||
| EXPECT_FALSE(__kmp_str_match("World", -1, data)); // "World" is not a prefix | ||
|
|
||
| // Test minimum length match (len > 0) | ||
| EXPECT_TRUE(__kmp_str_match("Hello", 5, data)); // At least 5 chars match | ||
| EXPECT_TRUE(__kmp_str_match("Hello", 3, data)); // At least 3 chars match | ||
| EXPECT_FALSE(__kmp_str_match("World", 5, data)); // First chars don't match | ||
| } | ||
|
|
||
| // Test string contains | ||
| TEST(KmpStrTest, StrContains) { | ||
| const char *data = "Hello World"; | ||
|
|
||
| EXPECT_TRUE(__kmp_str_contains("Hello", 5, data)); | ||
| EXPECT_TRUE(__kmp_str_contains("World", 5, data)); | ||
| EXPECT_TRUE(__kmp_str_contains("lo Wo", 5, data)); | ||
| EXPECT_FALSE(__kmp_str_contains("Goodbye", 7, data)); | ||
| } | ||
|
|
||
| // Test string match for true/false values | ||
| TEST(KmpStrTest, MatchBool) { | ||
| // Test true values | ||
| EXPECT_TRUE(__kmp_str_match_true("true")); | ||
| EXPECT_TRUE(__kmp_str_match_true("TRUE")); | ||
| EXPECT_TRUE(__kmp_str_match_true("on")); | ||
| EXPECT_TRUE(__kmp_str_match_true("ON")); | ||
| EXPECT_TRUE(__kmp_str_match_true("1")); | ||
| EXPECT_TRUE(__kmp_str_match_true("yes")); | ||
| EXPECT_TRUE(__kmp_str_match_true("YES")); | ||
|
|
||
| // Test false values | ||
| EXPECT_TRUE(__kmp_str_match_false("false")); | ||
| EXPECT_TRUE(__kmp_str_match_false("FALSE")); | ||
| EXPECT_TRUE(__kmp_str_match_false("off")); | ||
| EXPECT_TRUE(__kmp_str_match_false("OFF")); | ||
| EXPECT_TRUE(__kmp_str_match_false("0")); | ||
| EXPECT_TRUE(__kmp_str_match_false("no")); | ||
| EXPECT_TRUE(__kmp_str_match_false("NO")); | ||
| } | ||
|
|
||
| // Test string replace | ||
| TEST(KmpStrTest, StrReplace) { | ||
| char str[] = "Hello World"; | ||
| __kmp_str_replace(str, ' ', '_'); | ||
| EXPECT_STREQ(str, "Hello_World"); | ||
|
|
||
| __kmp_str_replace(str, 'o', '0'); | ||
| EXPECT_STREQ(str, "Hell0_W0rld"); | ||
| } | ||
|
|
||
| // Test string split | ||
| TEST(KmpStrTest, StrSplit) { | ||
| char str[] = "key=value"; | ||
| char *head = nullptr; | ||
| char *tail = nullptr; | ||
|
|
||
| __kmp_str_split(str, '=', &head, &tail); | ||
|
|
||
| EXPECT_STREQ(head, "key"); | ||
| EXPECT_STREQ(tail, "value"); | ||
| } | ||
|
|
||
| // Test file name parsing | ||
| TEST(KmpStrTest, FileNameInit) { | ||
| const char *path = "/path/to/file.txt"; | ||
| kmp_str_fname_t fname; | ||
| __kmp_str_fname_init(&fname, path); | ||
|
|
||
| EXPECT_NE(fname.path, nullptr); | ||
| EXPECT_STREQ(fname.path, path); | ||
| EXPECT_NE(fname.base, nullptr); | ||
| EXPECT_STREQ(fname.base, "file.txt"); | ||
|
|
||
| __kmp_str_fname_free(&fname); | ||
| } | ||
|
|
||
| // Test string format | ||
| TEST(KmpStrTest, StrFormat) { | ||
| char *result = __kmp_str_format("Number: %d, String: %s", 42, "test"); | ||
|
|
||
| EXPECT_NE(result, nullptr); | ||
| EXPECT_STREQ(result, "Number: 42, String: test"); | ||
|
|
||
| __kmp_str_free(&result); | ||
| EXPECT_EQ(result, nullptr); | ||
| } | ||
|
|
||
| // Test string buffer concatenate buffers | ||
| TEST(KmpStrTest, BufferCatBuf) { | ||
| kmp_str_buf_t buf1, buf2; | ||
| __kmp_str_buf_init(&buf1); | ||
| __kmp_str_buf_init(&buf2); | ||
|
|
||
| __kmp_str_buf_print(&buf1, "Hello"); | ||
| __kmp_str_buf_print(&buf2, " World"); | ||
|
|
||
| __kmp_str_buf_catbuf(&buf1, &buf2); | ||
|
|
||
| EXPECT_STREQ(buf1.str, "Hello World"); | ||
|
|
||
| __kmp_str_buf_free(&buf1); | ||
| __kmp_str_buf_free(&buf2); | ||
| } | ||
|
|
||
| // Test size string parsing | ||
| TEST(KmpStrTest, StrToSize) { | ||
| size_t result; | ||
| const char *error = nullptr; | ||
|
|
||
| __kmp_str_to_size("100", &result, 1, &error); | ||
| EXPECT_EQ(error, nullptr); | ||
| EXPECT_EQ(result, 100u); | ||
|
|
||
| __kmp_str_to_size("1K", &result, 1024, &error); | ||
| EXPECT_EQ(error, nullptr); | ||
| EXPECT_EQ(result, 1024u); | ||
|
|
||
| __kmp_str_to_size("2M", &result, 1024, &error); | ||
| EXPECT_EQ(error, nullptr); | ||
| EXPECT_EQ(result, 2u * 1024u * 1024u); | ||
| } | ||
|
|
||
| // Test uint string parsing | ||
| TEST(KmpStrTest, StrToUint) { | ||
| kmp_uint64 result; | ||
| const char *error = nullptr; | ||
|
|
||
| __kmp_str_to_uint("0", &result, &error); | ||
| EXPECT_EQ(error, nullptr); | ||
| EXPECT_EQ(result, 0u); | ||
|
|
||
| __kmp_str_to_uint("42", &result, &error); | ||
| EXPECT_EQ(error, nullptr); | ||
| EXPECT_EQ(result, 42u); | ||
|
|
||
| __kmp_str_to_uint("1234567890", &result, &error); | ||
| EXPECT_EQ(error, nullptr); | ||
| EXPECT_EQ(result, 1234567890u); | ||
| } | ||
|
|
||
| } // namespace |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.