From 8a6d92ca50bbc30ee0bdf00e74262116c962a9ad Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Mon, 17 Apr 2023 13:04:14 -0400 Subject: [PATCH 1/3] Allow compilation with any GTest version 1.10+ GTest max support for `Types` was removed in 1.11, so we remove the workarounds in cudf_gtest. Since we need to support our custom `Types` and the GTest 1.11+ version rework the type_list_utilities to be generic and not depend on specific traits. Also corrected the `<<` overloads for GTest printing so that they work with GTest 1.11. --- cpp/include/cudf_test/cudf_gtest.hpp | 9 +++++-- cpp/include/cudf_test/type_list_utilities.hpp | 26 +++++++++++++------ .../optional_iterator_test_numeric.cu | 19 ++++++++------ .../iterator/pair_iterator_test_numeric.cu | 19 ++++++++------ 4 files changed, 47 insertions(+), 26 deletions(-) diff --git a/cpp/include/cudf_test/cudf_gtest.hpp b/cpp/include/cudf_test/cudf_gtest.hpp index ab45d90f2d2..dbe454b84ce 100644 --- a/cpp/include/cudf_test/cudf_gtest.hpp +++ b/cpp/include/cudf_test/cudf_gtest.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2022, NVIDIA CORPORATION. + * Copyright (c) 2019-2023, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ /** * @file cudf_gtest.hpp - * @brief Work around for GTests emulation of variadic templates in + * @brief Work around for GTests( <=v1.10 ) emulation of variadic templates in * @verbatim ::Testing::Types @endverbatim * * @note Instead of including `gtest/gtest.h`, all libcudf test files should @@ -35,6 +35,10 @@ */ // @cond +#if __has_include() +// gtest doesn't provide a version header so we need to +// use a file existence trick. +// gtest-type-util.h.pump only exists in versions < 1.11 #define Types Types_NOT_USED #define Types0 Types0_NOT_USED #define TypeList TypeList_NOT_USED @@ -90,6 +94,7 @@ struct TypeList> { } // namespace internal } // namespace testing +#endif // gtest < 1.11 // @endcond #include diff --git a/cpp/include/cudf_test/type_list_utilities.hpp b/cpp/include/cudf_test/type_list_utilities.hpp index 0cd9f39e29d..67feb87ebc4 100644 --- a/cpp/include/cudf_test/type_list_utilities.hpp +++ b/cpp/include/cudf_test/type_list_utilities.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2022, NVIDIA CORPORATION. + * Copyright (c) 2019-2023, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -79,6 +79,11 @@ namespace test { // Types ----------------------------------------- using ::testing::Types; +template +struct at_type { + using type = T; +}; + // @cond template struct GetTypeImpl { @@ -90,14 +95,19 @@ template struct GetTypeImpl, D> { static_assert(D < sizeof...(T), "Out of bounds"); - using type = typename GetTypeImpl::Tail, D - 1>::type; + using type = decltype(std::get(std::declval>())); }; - -template -struct GetTypeImpl, 0> { - static_assert(sizeof...(ARGS) > 0, "Out of bounds"); - - using type = typename Types::Head; +template +struct GetTypeImpl, 2> { + using type = V; +}; +template +struct GetTypeImpl, 1> { + using type = U; +}; +template +struct GetTypeImpl, 0> { + using type = T; }; // @endcond diff --git a/cpp/tests/iterator/optional_iterator_test_numeric.cu b/cpp/tests/iterator/optional_iterator_test_numeric.cu index 586c9472185..e56c0e3b00e 100644 --- a/cpp/tests/iterator/optional_iterator_test_numeric.cu +++ b/cpp/tests/iterator/optional_iterator_test_numeric.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2022, NVIDIA CORPORATION. + * Copyright (c) 2020-2023, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,16 @@ using TestingTypes = cudf::test::NumericTypes; +namespace cudf { +// To print meanvar for debug. +// Needs to be in the cudf namespace for ADL +template +std::ostream& operator<<(std::ostream& os, cudf::meanvar const& rhs) +{ + return os << "[" << rhs.value << ", " << rhs.value_squared << ", " << rhs.count << "] "; +}; +} // namespace cudf + template struct NumericOptionalIteratorTest : public IteratorTest { }; @@ -35,13 +45,6 @@ TYPED_TEST(NumericOptionalIteratorTest, nonull_optional_iterator) } TYPED_TEST(NumericOptionalIteratorTest, null_optional_iterator) { null_optional_iterator(*this); } -// to print meanvar for debug. -template -std::ostream& operator<<(std::ostream& os, cudf::meanvar const& rhs) -{ - return os << "[" << rhs.value << ", " << rhs.value_squared << ", " << rhs.count << "] "; -}; - // Transformers and Operators for optional_iterator test template struct transformer_optional_meanvar { diff --git a/cpp/tests/iterator/pair_iterator_test_numeric.cu b/cpp/tests/iterator/pair_iterator_test_numeric.cu index 786bd3148f7..2b2d2163ec2 100644 --- a/cpp/tests/iterator/pair_iterator_test_numeric.cu +++ b/cpp/tests/iterator/pair_iterator_test_numeric.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2022, NVIDIA CORPORATION. + * Copyright (c) 2020-2023, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,16 @@ using TestingTypes = cudf::test::NumericTypes; +namespace cudf { +// To print meanvar for debug. +// Needs to be in the cudf namespace for ADL +template +std::ostream& operator<<(std::ostream& os, cudf::meanvar const& rhs) +{ + return os << "[" << rhs.value << ", " << rhs.value_squared << ", " << rhs.count << "] "; +}; +} // namespace cudf + template struct NumericPairIteratorTest : public IteratorTest { }; @@ -30,13 +40,6 @@ TYPED_TEST_SUITE(NumericPairIteratorTest, TestingTypes); TYPED_TEST(NumericPairIteratorTest, nonull_pair_iterator) { nonull_pair_iterator(*this); } TYPED_TEST(NumericPairIteratorTest, null_pair_iterator) { null_pair_iterator(*this); } -// to print meanvar for debug. -template -std::ostream& operator<<(std::ostream& os, cudf::meanvar const& rhs) -{ - return os << "[" << rhs.value << ", " << rhs.value_squared << ", " << rhs.count << "] "; -}; - // Transformers and Operators for pair_iterator test template struct transformer_pair_meanvar { From 313cb7a1340c3336f5d154fcea906e4ee6c1d3ac Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Mon, 17 Apr 2023 14:06:20 -0400 Subject: [PATCH 2/3] Remove unneeded code --- cpp/include/cudf_test/type_list_utilities.hpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/cpp/include/cudf_test/type_list_utilities.hpp b/cpp/include/cudf_test/type_list_utilities.hpp index 67feb87ebc4..e658fc57cee 100644 --- a/cpp/include/cudf_test/type_list_utilities.hpp +++ b/cpp/include/cudf_test/type_list_utilities.hpp @@ -79,11 +79,6 @@ namespace test { // Types ----------------------------------------- using ::testing::Types; -template -struct at_type { - using type = T; -}; - // @cond template struct GetTypeImpl { From ef360aa26045af9c0943be03ec9ce963819fac6c Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Mon, 17 Apr 2023 14:08:13 -0400 Subject: [PATCH 3/3] Corrected a bug that was hidden by specializations --- cpp/include/cudf_test/type_list_utilities.hpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/cpp/include/cudf_test/type_list_utilities.hpp b/cpp/include/cudf_test/type_list_utilities.hpp index e658fc57cee..bbbb8e862be 100644 --- a/cpp/include/cudf_test/type_list_utilities.hpp +++ b/cpp/include/cudf_test/type_list_utilities.hpp @@ -90,15 +90,8 @@ template struct GetTypeImpl, D> { static_assert(D < sizeof...(T), "Out of bounds"); - using type = decltype(std::get(std::declval>())); -}; -template -struct GetTypeImpl, 2> { - using type = V; -}; -template -struct GetTypeImpl, 1> { - using type = U; + using raw_type = decltype(std::get(std::declval>())); + using type = std::decay_t; }; template struct GetTypeImpl, 0> {