diff options
| author | Michael Kruse <llvm-project@meinersbur.de> | 2025-11-12 11:50:33 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-12 11:50:33 +0100 |
| commit | 0957656a4077b6a70f3e3dbb3a011b40d53e1a97 (patch) | |
| tree | 1077c36eb7a5349ae1f17a2e07b042d4f97a2e8f /flang-rt | |
| parent | a276624b2e34bfea36dd472ffc71bb4f78bbd39a (diff) | |
[runtimes][GTest] LLVM-independent unittests (#164794)
The LLVM-customized GTest has a dependency on LLVM to support
`llvm::raw_ostream` and hence has to link to LLVMSupport. The runtimes
use the LLVMSupport from the bootstrapping LLVM build. The problem is
that the boostrapping compiler and the runtimes target can diverge in
their ABI, even in the runtimes default build. For instance, Clang is
built using gcc which uses libstdc++, but the runtimes is built by Clang
which can be configured to use libcxx by default. Altough it does not
use gcc, this issue has caused
[flang-aarch64-libcxx](https://lab.llvm.org/buildbot/#/builders/89)) to
break, and is still (again?) broken.
This patch makes the runtimes' GTest independent from LLVMSupport so we
do not link any runtimes component with LLVM components.
Runtime projects that use GTest unittests:
* flang-rt
* libc
* compiler-rt: Adds `gtest-all.cpp` with
[GTEST_NO_LLVM_SUPPORT=1](https://github.com/llvm/llvm-project/blob/f801b6f67ea896d6e4d2de38bce9a79689ceb254/compiler-rt/CMakeLists.txt#L723)
to each unittest without using `llvm_gtest`. Not touched by this PR.
* openmp: Handled by #159416. Not touched for now by this PR to avoid
conflict.
The current state of this PR tries to reuse
https://github.com/llvm/llvm-project/blob/main/third-party/unittest/CMakeLists.txt
as much as possible, altough personally I would prefer to make it use
"modern CMake" style. third-party/unittest/CMakeLists.txt will detect
whether it is used in runtimes build and adjaust accordingly. It creates
a different target for LLVM (`llvm_gtest`, NFCI) and another one for the
runtimes (`runtimes_gtest`). It is not possible to reuse `llvm_gtest`
for both since `llvm_gtest` is imported using `find_package(LLVM)` if
configured using LLVM_INSTALL_GTEST. An alias `default_gtest` is used to
select between the two. `default_gtest` could also be used for openmp
which also supports standalone and
[LLVM_ENABLE_PROJECTS](https://github.com/llvm/llvm-project/pull/152189)
build mode.
Diffstat (limited to 'flang-rt')
| -rw-r--r-- | flang-rt/unittests/CMakeLists.txt | 8 | ||||
| -rw-r--r-- | flang-rt/unittests/Evaluate/ISO-Fortran-binding.cpp | 21 | ||||
| -rw-r--r-- | flang-rt/unittests/Runtime/AccessTest.cpp | 7 | ||||
| -rw-r--r-- | flang-rt/unittests/Runtime/CrashHandlerFixture.cpp | 11 | ||||
| -rw-r--r-- | flang-rt/unittests/Runtime/Descriptor.cpp | 4 | ||||
| -rw-r--r-- | flang-rt/unittests/Runtime/ExternalIOTest.cpp | 1 |
6 files changed, 13 insertions, 39 deletions
diff --git a/flang-rt/unittests/CMakeLists.txt b/flang-rt/unittests/CMakeLists.txt index 53cd54dfd215..e1ab73d7d930 100644 --- a/flang-rt/unittests/CMakeLists.txt +++ b/flang-rt/unittests/CMakeLists.txt @@ -22,12 +22,8 @@ if (CMAKE_CROSSCOMPILING) return () endif () -if (NOT TARGET llvm_gtest) - message(WARNING "Flang-RT unittests disabled due to GTest being unavailable; " - "Try LLVM_INSTALL_GTEST=ON for the LLVM build") - return () -endif () - +# Make the targets default_gtest and default_gtest_main available. +build_gtest() add_dependencies(flang-rt-test-depends FlangRTUnitTests diff --git a/flang-rt/unittests/Evaluate/ISO-Fortran-binding.cpp b/flang-rt/unittests/Evaluate/ISO-Fortran-binding.cpp index 8c0a6f29b696..1a9817cc665d 100644 --- a/flang-rt/unittests/Evaluate/ISO-Fortran-binding.cpp +++ b/flang-rt/unittests/Evaluate/ISO-Fortran-binding.cpp @@ -9,7 +9,6 @@ #include "flang-rt/runtime/descriptor.h" #include "flang/Common/ISO_Fortran_binding_wrapper.h" #include "flang/Testing/testing.h" -#include "llvm/Support/raw_ostream.h" #include <type_traits> using namespace Fortran::runtime; @@ -73,26 +72,9 @@ static void AddNoiseToCdesc(CFI_cdesc_t *dv, CFI_rank_t rank) { } } -#ifdef VERBOSE -static void DumpTestWorld(const void *bAddr, CFI_attribute_t attr, - CFI_type_t ty, std::size_t eLen, CFI_rank_t rank, - const CFI_index_t *eAddr) { - llvm::outs() << " base_addr: "; - llvm::outs().write_hex(reinterpret_cast<std::intptr_t>(bAddr)) - << " attribute: " << static_cast<int>(attr) - << " type: " << static_cast<int>(ty) << " elem_len: " << eLen - << " rank: " << static_cast<int>(rank) << " extent: "; - llvm::outs().write_hex(reinterpret_cast<std::intptr_t>(eAddr)) << '\n'; - llvm::outs().flush(); -} -#endif - static void check_CFI_establish(CFI_cdesc_t *dv, void *base_addr, CFI_attribute_t attribute, CFI_type_t type, std::size_t elem_len, CFI_rank_t rank, const CFI_index_t extents[]) { -#ifdef VERBOSE - DumpTestWorld(base_addr, attribute, type, elem_len, rank, extent); -#endif // CFI_establish reqs from F2018 section 18.5.5 int retCode{ CFI_establish(dv, base_addr, attribute, type, elem_len, rank, extents)}; @@ -305,9 +287,6 @@ static void check_CFI_allocate(CFI_cdesc_t *dv, const CFI_type_t type{dv->type}; const void *base_addr{dv->base_addr}; const int version{dv->version}; -#ifdef VERBOSE - DumpTestWorld(base_addr, attribute, type, elem_len, rank, nullptr); -#endif int retCode{CFI_allocate(dv, lower_bounds, upper_bounds, elem_len)}; Descriptor *desc = reinterpret_cast<Descriptor *>(dv); if (retCode == CFI_SUCCESS) { diff --git a/flang-rt/unittests/Runtime/AccessTest.cpp b/flang-rt/unittests/Runtime/AccessTest.cpp index d431d0d19bd6..d44f0ec3ced2 100644 --- a/flang-rt/unittests/Runtime/AccessTest.cpp +++ b/flang-rt/unittests/Runtime/AccessTest.cpp @@ -12,8 +12,8 @@ #include "CrashHandlerFixture.h" #include "gtest/gtest.h" #include "flang/Runtime/extensions.h" -#include "llvm/ADT/Twine.h" +#include <cstring> #include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> @@ -82,8 +82,9 @@ static const char *temp_directory_path() { static std::string createTemporaryFile( const char *name, const AccessType &accessType) { - std::string path = - (llvm::Twine{temp_directory_path()} + "/" + addPIDSuffix(name)).str(); + std::ostringstream pathS; + pathS << temp_directory_path() << "/" << addPIDSuffix(name); + std::string path = pathS.str(); // O_CREAT | O_EXCL enforces that this file is newly created by this call. // This feels risky. If we don't have permission to create files in the diff --git a/flang-rt/unittests/Runtime/CrashHandlerFixture.cpp b/flang-rt/unittests/Runtime/CrashHandlerFixture.cpp index 8213edd1f922..34901b5cd213 100644 --- a/flang-rt/unittests/Runtime/CrashHandlerFixture.cpp +++ b/flang-rt/unittests/Runtime/CrashHandlerFixture.cpp @@ -17,12 +17,11 @@ char buffer[1000]; std::vsnprintf(buffer, sizeof buffer, message, ap); va_end(ap); - llvm::errs() - << "Test " - << ::testing::UnitTest::GetInstance()->current_test_info()->name() - << " crashed in file " - << (sourceFile ? sourceFile : "unknown source file") << '(' << sourceLine - << "): " << buffer << '\n'; + std::cerr << "Test " + << ::testing::UnitTest::GetInstance()->current_test_info()->name() + << " crashed in file " + << (sourceFile ? sourceFile : "unknown source file") << '(' + << sourceLine << "): " << buffer << '\n'; std::exit(EXIT_FAILURE); } diff --git a/flang-rt/unittests/Runtime/Descriptor.cpp b/flang-rt/unittests/Runtime/Descriptor.cpp index 3a4a7670fc62..4a7bb43a492a 100644 --- a/flang-rt/unittests/Runtime/Descriptor.cpp +++ b/flang-rt/unittests/Runtime/Descriptor.cpp @@ -32,8 +32,8 @@ TEST(Descriptor, FixedStride) { extent[0] = 8; descriptor.Establish(integer, four, data, 1, extent); ASSERT_EQ(descriptor.rank(), 1); - ASSERT_EQ(descriptor.Elements(), 8); - ASSERT_EQ(descriptor.ElementBytes(), four); + ASSERT_EQ(descriptor.Elements(), 8u); + ASSERT_EQ(descriptor.ElementBytes(), static_cast<unsigned>(four)); ASSERT_EQ(descriptor.GetDimension(0).LowerBound(), 0); ASSERT_EQ(descriptor.GetDimension(0).ByteStride(), four); ASSERT_EQ(descriptor.GetDimension(0).Extent(), 8); diff --git a/flang-rt/unittests/Runtime/ExternalIOTest.cpp b/flang-rt/unittests/Runtime/ExternalIOTest.cpp index 6c148b1de6f8..6421194f4514 100644 --- a/flang-rt/unittests/Runtime/ExternalIOTest.cpp +++ b/flang-rt/unittests/Runtime/ExternalIOTest.cpp @@ -16,7 +16,6 @@ #include "flang/Runtime/io-api.h" #include "flang/Runtime/main.h" #include "flang/Runtime/stop.h" -#include "llvm/Support/raw_ostream.h" #include <cstring> #include <string_view> |
