Repository navigation
Adopt GoogleTest for HostNumerics C++ tests #13562
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
Merged
newling
merged 5 commits into
ROCm:develop
from
newling:users/newling/AIHPBLAS-4195-hostnumerics-gtest
Oct 14, 2026
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
59741f2
test(hostnumerics): adopt GoogleTest for existing C++ tests
newling f70e524
test(hostnumerics): clarify and centralize GoogleTest setup
newling 7a06e97
Improve HostNumerics scalar test failure diagnostics
newling 7973ae5
Validate HostNumerics GoogleTest versions and cover installed packages
newling 3fa28c7
Keep explicit test source roots and reuse CI for installed GoogleTest
newling 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
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
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
32 changes: 32 additions & 0 deletions
32
shared/hostnumerics/cmake/HostNumericsTestDependencies.cmake
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,32 @@ | ||
| # Copyright Advanced Micro Devices, Inc., or its affiliates. | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| option(HOSTNUMERICS_ENABLE_FETCH "Allow test builds to fetch missing dependencies." | ||
| ${PROJECT_IS_TOP_LEVEL}) | ||
|
|
||
| if(TARGET GTest::gtest_main) | ||
| return() | ||
| endif() | ||
|
newling marked this conversation as resolved.
Resolved
|
||
| # Basic assertions work with older installed packages too. | ||
| find_package(GTest 1.12.1 QUIET) | ||
| if(NOT GTest_FOUND) | ||
| if(NOT HOSTNUMERICS_ENABLE_FETCH) | ||
| message(FATAL_ERROR "HostNumerics tests require GTest 1.12.1 or newer.") | ||
| endif() | ||
| include(FetchContent) | ||
| # GoogleTest belongs to the test build, never the installed component. | ||
| set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) | ||
| set(BUILD_GMOCK OFF CACHE BOOL "" FORCE) | ||
| # Match the parent runtime on MSVC, independently of static/shared libraries. | ||
| if(MSVC AND (NOT CMAKE_MSVC_RUNTIME_LIBRARY OR CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DLL")) | ||
| set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) | ||
| endif() | ||
| # Match the pin in cmake/modules/shared_third_party.cmake in the superbuild. | ||
| FetchContent_Declare( | ||
| googletest | ||
| URL https://github.com/google/googletest/archive/refs/tags/v1.17.0.tar.gz | ||
| URL_HASH SHA256=65fab701d9829d38cb77c14acdc431d2108bfdbf8979e40eb8ae567edf10b27c | ||
| SYSTEM | ||
| ) | ||
| FetchContent_MakeAvailable(googletest) | ||
| endif() | ||
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 |
|---|---|---|
| @@ -1,10 +1,12 @@ | ||
| # Copyright Advanced Micro Devices, Inc., or its affiliates. | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| include(HostNumericsTestDependencies) | ||
|
|
||
| add_executable(hostnumerics-version-test version_test.cpp) | ||
| target_link_libraries(hostnumerics-version-test PRIVATE roc::hostnumerics) | ||
| target_link_libraries(hostnumerics-version-test PRIVATE roc::hostnumerics GTest::gtest_main) | ||
| add_test(NAME hostnumerics-version COMMAND hostnumerics-version-test) | ||
|
|
||
| add_executable(hostnumerics-scalar-type-test scalar_type_test.cpp) | ||
| target_link_libraries(hostnumerics-scalar-type-test PRIVATE roc::hostnumerics-core) | ||
| target_link_libraries(hostnumerics-scalar-type-test PRIVATE roc::hostnumerics-core GTest::gtest_main) | ||
| add_test(NAME hostnumerics-scalar-type COMMAND hostnumerics-scalar-type-test) |
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
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 |
|---|---|---|
| @@ -1,10 +1,13 @@ | ||
| // Copyright Advanced Micro Devices, Inc., or its affiliates. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <roc/hostnumerics/scalar_type.hpp> | ||
| #include <roc/hostnumerics/version.hpp> | ||
|
|
||
| int main() { | ||
| TEST(Core, Version) { | ||
| using namespace roc::hostnumerics; | ||
| return version() == "0.1.0" && scalarTypeInfo(ScalarType::Float16).storageBits == 16 ? 0 : 1; | ||
| EXPECT_EQ(version(), "0.1.0"); | ||
| EXPECT_EQ(scalarTypeInfo(ScalarType::Float16).storageBits, 16); | ||
| } |
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.