From 02fa340711d9b990b50a0daf65eb850404884137 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Thu, 6 Feb 2025 21:45:51 +0100 Subject: [PATCH] [Flang] Promote FortranEvaluateTesting library (#124417) The non-GTest library will be shared by unittests of Flang and Flang-RT. Promote it as a regular library for use by both projects. In the long term, we may want to convert these to regular GTest checks to avoid having multiple testing frameworks. --- .../flang/Testing}/fp-testing.h | 14 ++++++-- .../flang/Testing}/testing.h | 14 ++++++-- flang/lib/CMakeLists.txt | 4 +++ flang/lib/Testing/CMakeLists.txt | 20 +++++++++++ .../Evaluate => lib/Testing}/fp-testing.cpp | 10 +++++- .../Evaluate => lib/Testing}/testing.cpp | 10 +++++- flang/unittests/Evaluate/CMakeLists.txt | 35 ++++++------------- .../Evaluate/ISO-Fortran-binding.cpp | 2 +- .../Evaluate/bit-population-count.cpp | 2 +- flang/unittests/Evaluate/expression.cpp | 2 +- flang/unittests/Evaluate/folding.cpp | 2 +- flang/unittests/Evaluate/integer.cpp | 2 +- flang/unittests/Evaluate/intrinsics.cpp | 2 +- .../Evaluate/leading-zero-bit-count.cpp | 2 +- flang/unittests/Evaluate/logical.cpp | 2 +- flang/unittests/Evaluate/real.cpp | 4 +-- flang/unittests/Evaluate/reshape.cpp | 2 +- flang/unittests/Evaluate/uint128.cpp | 2 +- 18 files changed, 87 insertions(+), 44 deletions(-) rename flang/{unittests/Evaluate => include/flang/Testing}/fp-testing.h (54%) rename flang/{unittests/Evaluate => include/flang/Testing}/testing.h (75%) create mode 100644 flang/lib/Testing/CMakeLists.txt rename flang/{unittests/Evaluate => lib/Testing}/fp-testing.cpp (87%) rename flang/{unittests/Evaluate => lib/Testing}/testing.cpp (88%) diff --git a/flang/unittests/Evaluate/fp-testing.h b/flang/include/flang/Testing/fp-testing.h similarity index 54% rename from flang/unittests/Evaluate/fp-testing.h rename to flang/include/flang/Testing/fp-testing.h index 9091963a99b3..c65766b8b47e 100644 --- a/flang/unittests/Evaluate/fp-testing.h +++ b/flang/include/flang/Testing/fp-testing.h @@ -1,5 +1,13 @@ -#ifndef FORTRAN_TEST_EVALUATE_FP_TESTING_H_ -#define FORTRAN_TEST_EVALUATE_FP_TESTING_H_ +//===-- include/flang/Testing/fp-testing.h ----------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef FORTRAN_TESTING_FP_TESTING_H_ +#define FORTRAN_TESTING_FP_TESTING_H_ #include "flang/Common/target-rounding.h" #include @@ -24,4 +32,4 @@ private: #endif }; -#endif // FORTRAN_TEST_EVALUATE_FP_TESTING_H_ +#endif // FORTRAN_TESTING_FP_TESTING_H_ diff --git a/flang/unittests/Evaluate/testing.h b/flang/include/flang/Testing/testing.h similarity index 75% rename from flang/unittests/Evaluate/testing.h rename to flang/include/flang/Testing/testing.h index 422e2853c05b..03b589924518 100644 --- a/flang/unittests/Evaluate/testing.h +++ b/flang/include/flang/Testing/testing.h @@ -1,5 +1,13 @@ -#ifndef FORTRAN_EVALUATE_TESTING_H_ -#define FORTRAN_EVALUATE_TESTING_H_ +//===-- include/flang/Testing/testing.h -------------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef FORTRAN_TESTING_TESTING_H_ +#define FORTRAN_TESTING_TESTING_H_ #include #include @@ -33,4 +41,4 @@ FailureDetailPrinter Match(const char *file, int line, const std::string &want, FailureDetailPrinter Compare(const char *file, int line, const char *xs, const char *rel, const char *ys, std::uint64_t x, std::uint64_t y); } // namespace testing -#endif // FORTRAN_EVALUATE_TESTING_H_ +#endif // FORTRAN_TESTING_TESTING_H_ diff --git a/flang/lib/CMakeLists.txt b/flang/lib/CMakeLists.txt index 05c3535b09b3..8b201d9a758a 100644 --- a/flang/lib/CMakeLists.txt +++ b/flang/lib/CMakeLists.txt @@ -8,3 +8,7 @@ add_subdirectory(Frontend) add_subdirectory(FrontendTool) add_subdirectory(Optimizer) + +if (FLANG_INCLUDE_TESTS) + add_subdirectory(Testing) +endif () diff --git a/flang/lib/Testing/CMakeLists.txt b/flang/lib/Testing/CMakeLists.txt new file mode 100644 index 000000000000..8051bc09736d --- /dev/null +++ b/flang/lib/Testing/CMakeLists.txt @@ -0,0 +1,20 @@ +#===-- lib/Testing/CMakeLists.txt ------------------------------------------===# +# +# 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 +# +#===------------------------------------------------------------------------===# + +add_library(NonGTestTesting EXCLUDE_FROM_ALL + testing.cpp + fp-testing.cpp +) +set_target_properties(NonGTestTesting PROPERTIES FOLDER "Flang/Tests") + +if (LLVM_LINK_LLVM_DYLIB) + set(llvm_libs LLVM) +else() + llvm_map_components_to_libnames(llvm_libs Support) +endif() +target_link_libraries(NonGTestTesting ${llvm_libs}) diff --git a/flang/unittests/Evaluate/fp-testing.cpp b/flang/lib/Testing/fp-testing.cpp similarity index 87% rename from flang/unittests/Evaluate/fp-testing.cpp rename to flang/lib/Testing/fp-testing.cpp index 1a1d7425d582..5e1728e8df5e 100644 --- a/flang/unittests/Evaluate/fp-testing.cpp +++ b/flang/lib/Testing/fp-testing.cpp @@ -1,4 +1,12 @@ -#include "fp-testing.h" +//===-- lib/Testing/fp-testing.cpp ------------------------------*- C++ -*-===// +// +// 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 "flang/Testing/fp-testing.h" #include "llvm/Support/Errno.h" #include #include diff --git a/flang/unittests/Evaluate/testing.cpp b/flang/lib/Testing/testing.cpp similarity index 88% rename from flang/unittests/Evaluate/testing.cpp rename to flang/lib/Testing/testing.cpp index b2f73bf1b265..37f9d88f4886 100644 --- a/flang/unittests/Evaluate/testing.cpp +++ b/flang/lib/Testing/testing.cpp @@ -1,4 +1,12 @@ -#include "testing.h" +//===-- lib/Testing/testing.cpp ---------------------------------*- C++ -*-===// +// +// 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 "flang/Testing/testing.h" #include "llvm/Support/raw_ostream.h" #include #include diff --git a/flang/unittests/Evaluate/CMakeLists.txt b/flang/unittests/Evaluate/CMakeLists.txt index 0ea02ad7f711..8111ecd72cfc 100644 --- a/flang/unittests/Evaluate/CMakeLists.txt +++ b/flang/unittests/Evaluate/CMakeLists.txt @@ -1,47 +1,34 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) -add_library(FortranEvaluateTesting - testing.cpp - fp-testing.cpp -) -set_target_properties(FortranEvaluateTesting PROPERTIES FOLDER "Flang/Tests") -if (LLVM_LINK_LLVM_DYLIB) - set(llvm_libs LLVM) -else() - llvm_map_components_to_libnames(llvm_libs Support) -endif() - -target_link_libraries(FortranEvaluateTesting - ${llvm_libs}) add_flang_nongtest_unittest(leading-zero-bit-count - FortranEvaluateTesting + NonGTestTesting ) add_flang_nongtest_unittest(bit-population-count - FortranEvaluateTesting + NonGTestTesting ) add_flang_nongtest_unittest(uint128 - FortranEvaluateTesting + NonGTestTesting ) add_flang_nongtest_unittest(expression FortranSupport - FortranEvaluateTesting + NonGTestTesting FortranEvaluate FortranSemantics FortranParser ) add_flang_nongtest_unittest(integer - FortranEvaluateTesting + NonGTestTesting FortranEvaluate FortranSemantics ) add_flang_nongtest_unittest(intrinsics FortranSupport - FortranEvaluateTesting + NonGTestTesting FortranEvaluate FortranDecimal FortranSemantics @@ -50,7 +37,7 @@ add_flang_nongtest_unittest(intrinsics ) add_flang_nongtest_unittest(logical - FortranEvaluateTesting + NonGTestTesting FortranEvaluate FortranSemantics ) @@ -62,7 +49,7 @@ add_flang_nongtest_unittest(logical set(LLVM_REQUIRES_EH ON) set(LLVM_REQUIRES_RTTI ON) add_flang_nongtest_unittest(real - FortranEvaluateTesting + NonGTestTesting FortranEvaluate FortranDecimal FortranSemantics @@ -70,14 +57,14 @@ add_flang_nongtest_unittest(real llvm_update_compile_flags(real.test) add_flang_nongtest_unittest(reshape - FortranEvaluateTesting + NonGTestTesting FortranSemantics FortranEvaluate FortranRuntime ) add_flang_nongtest_unittest(ISO-Fortran-binding - FortranEvaluateTesting + NonGTestTesting FortranEvaluate FortranSemantics FortranRuntime @@ -85,7 +72,7 @@ add_flang_nongtest_unittest(ISO-Fortran-binding add_flang_nongtest_unittest(folding FortranSupport - FortranEvaluateTesting + NonGTestTesting FortranEvaluate FortranSemantics ) diff --git a/flang/unittests/Evaluate/ISO-Fortran-binding.cpp b/flang/unittests/Evaluate/ISO-Fortran-binding.cpp index 38688b404876..2884686b3f26 100644 --- a/flang/unittests/Evaluate/ISO-Fortran-binding.cpp +++ b/flang/unittests/Evaluate/ISO-Fortran-binding.cpp @@ -1,6 +1,6 @@ -#include "testing.h" #include "flang/Common/ISO_Fortran_binding_wrapper.h" #include "flang/Runtime/descriptor.h" +#include "flang/Testing/testing.h" #include "llvm/Support/raw_ostream.h" #include diff --git a/flang/unittests/Evaluate/bit-population-count.cpp b/flang/unittests/Evaluate/bit-population-count.cpp index 24e721c14f94..0c9529a92e57 100644 --- a/flang/unittests/Evaluate/bit-population-count.cpp +++ b/flang/unittests/Evaluate/bit-population-count.cpp @@ -1,5 +1,5 @@ #include "flang/Common/bit-population-count.h" -#include "testing.h" +#include "flang/Testing/testing.h" using Fortran::common::BitPopulationCount; using Fortran::common::Parity; diff --git a/flang/unittests/Evaluate/expression.cpp b/flang/unittests/Evaluate/expression.cpp index f03a6bc2a4e2..d575f36def28 100644 --- a/flang/unittests/Evaluate/expression.cpp +++ b/flang/unittests/Evaluate/expression.cpp @@ -1,10 +1,10 @@ #include "flang/Evaluate/expression.h" -#include "testing.h" #include "flang/Evaluate/fold.h" #include "flang/Evaluate/intrinsics.h" #include "flang/Evaluate/target.h" #include "flang/Evaluate/tools.h" #include "flang/Parser/message.h" +#include "flang/Testing/testing.h" #include #include #include diff --git a/flang/unittests/Evaluate/folding.cpp b/flang/unittests/Evaluate/folding.cpp index 4e8ff9754e4c..832e55d44316 100644 --- a/flang/unittests/Evaluate/folding.cpp +++ b/flang/unittests/Evaluate/folding.cpp @@ -1,4 +1,3 @@ -#include "testing.h" #include "../../lib/Evaluate/host.h" #include "flang/Evaluate/call.h" #include "flang/Evaluate/expression.h" @@ -7,6 +6,7 @@ #include "flang/Evaluate/intrinsics.h" #include "flang/Evaluate/target.h" #include "flang/Evaluate/tools.h" +#include "flang/Testing/testing.h" #include using namespace Fortran::evaluate; diff --git a/flang/unittests/Evaluate/integer.cpp b/flang/unittests/Evaluate/integer.cpp index 3eabb2434cce..5ab22cc6443a 100644 --- a/flang/unittests/Evaluate/integer.cpp +++ b/flang/unittests/Evaluate/integer.cpp @@ -1,5 +1,5 @@ #include "flang/Evaluate/integer.h" -#include "testing.h" +#include "flang/Testing/testing.h" #include #include diff --git a/flang/unittests/Evaluate/intrinsics.cpp b/flang/unittests/Evaluate/intrinsics.cpp index 86c471d2c629..cca2f8c30247 100644 --- a/flang/unittests/Evaluate/intrinsics.cpp +++ b/flang/unittests/Evaluate/intrinsics.cpp @@ -1,10 +1,10 @@ #include "flang/Evaluate/intrinsics.h" -#include "testing.h" #include "flang/Evaluate/common.h" #include "flang/Evaluate/expression.h" #include "flang/Evaluate/target.h" #include "flang/Evaluate/tools.h" #include "flang/Parser/provenance.h" +#include "flang/Testing/testing.h" #include "llvm/Support/raw_ostream.h" #include #include diff --git a/flang/unittests/Evaluate/leading-zero-bit-count.cpp b/flang/unittests/Evaluate/leading-zero-bit-count.cpp index 968946b69f27..25e2664e76df 100644 --- a/flang/unittests/Evaluate/leading-zero-bit-count.cpp +++ b/flang/unittests/Evaluate/leading-zero-bit-count.cpp @@ -1,5 +1,5 @@ #include "flang/Common/leading-zero-bit-count.h" -#include "testing.h" +#include "flang/Testing/testing.h" using Fortran::common::LeadingZeroBitCount; diff --git a/flang/unittests/Evaluate/logical.cpp b/flang/unittests/Evaluate/logical.cpp index d79aff844871..ba7d0d8d0c0e 100644 --- a/flang/unittests/Evaluate/logical.cpp +++ b/flang/unittests/Evaluate/logical.cpp @@ -1,5 +1,5 @@ -#include "testing.h" #include "flang/Evaluate/type.h" +#include "flang/Testing/testing.h" #include template void testKind() { diff --git a/flang/unittests/Evaluate/real.cpp b/flang/unittests/Evaluate/real.cpp index 1bf7fa1016a9..a28da5c3273c 100644 --- a/flang/unittests/Evaluate/real.cpp +++ b/flang/unittests/Evaluate/real.cpp @@ -1,6 +1,6 @@ -#include "fp-testing.h" -#include "testing.h" #include "flang/Evaluate/type.h" +#include "flang/Testing/fp-testing.h" +#include "flang/Testing/testing.h" #include "llvm/Support/raw_ostream.h" #include #include diff --git a/flang/unittests/Evaluate/reshape.cpp b/flang/unittests/Evaluate/reshape.cpp index 5d138cd3d88d..16cba15dcef6 100644 --- a/flang/unittests/Evaluate/reshape.cpp +++ b/flang/unittests/Evaluate/reshape.cpp @@ -1,6 +1,6 @@ -#include "testing.h" #include "flang/Runtime/descriptor.h" #include "flang/Runtime/transformational.h" +#include "flang/Testing/testing.h" #include using namespace Fortran::common; diff --git a/flang/unittests/Evaluate/uint128.cpp b/flang/unittests/Evaluate/uint128.cpp index f05c1c96a7e8..0b749abe1c08 100644 --- a/flang/unittests/Evaluate/uint128.cpp +++ b/flang/unittests/Evaluate/uint128.cpp @@ -1,6 +1,6 @@ #define AVOID_NATIVE_UINT128_T 1 #include "flang/Common/uint128.h" -#include "testing.h" +#include "flang/Testing/testing.h" #include "llvm/Support/raw_ostream.h" #include