Skip to content

Commit fa4811e

Browse files
Add workaround for printing 128-bit types in gtest for windows (#708)
* Add workaround for printing 128-bit types in gtest for windows * Update fix * Disable all 128 bit tests * Add workaround to more assert_eq overloads * Fix tabs
1 parent af5def6 commit fa4811e

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

test/rocprim/test_utils_assertions.hpp

+40
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,29 @@ void assert_eq(const std::vector<T>& result,
6868
const size_t max_length = SIZE_MAX)
6969
{
7070
if(max_length == SIZE_MAX || max_length > expected.size())
71+
{
7172
ASSERT_EQ(result.size(), expected.size());
73+
}
7274
for(size_t i = 0; i < std::min(result.size(), max_length); i++)
7375
{
7476
if(bit_equal(result[i], expected[i]))
7577
continue; // Check bitwise equality for +NaN, -NaN, +0.0, -0.0, +inf, -inf.
78+
#if defined(_WIN32)
79+
// GTest's ASSERT_EQ prints the values if the test fails. On Windows, the version of GTest provided by vcpkg doesn't
80+
// provide overloads for printing 128 bit types, resulting in linker errors.
81+
// Check if we're testing with 128 bit types. If so, test using bools so GTest doesn't try to print them on failure.
82+
if (test_utils::is_int128<T>::value || test_utils::is_uint128<T>::value || (typeid(T) == typeid(common::custom_type<double,double,1>)))
83+
{
84+
const bool values_equal = (result[i] == expected[i]);
85+
ASSERT_EQ(values_equal, true) << "where index = " << i;
86+
}
87+
else
88+
{
89+
ASSERT_EQ(result[i], expected[i]) << "where index = " << i;
90+
}
91+
#else
7692
ASSERT_EQ(result[i], expected[i]) << "where index = " << i;
93+
#endif
7794
}
7895
}
7996

@@ -90,7 +107,15 @@ void assert_eq(const std::vector<common::custom_type<T, T, true>>& result,
90107
{
91108
if(bit_equal(result[i].x, expected[i].x) && bit_equal(result[i].y, expected[i].y))
92109
continue; // Check bitwise equality for +NaN, -NaN, +0.0, -0.0, +inf, -inf.
110+
#if defined(_WIN32)
111+
// GTest's ASSERT_EQ prints the values if the test fails. On Windows, the version of GTest provided by vcpkg doesn't
112+
// provide overloads for printing 128 bit types, resulting in linker errors.
113+
// Check if we're testing with 128 bit types. If so, test using bools so GTest doesn't try to print them on failure.
114+
const bool values_equal = (result[i] == expected[i]);
115+
ASSERT_EQ(values_equal, true) << "where index = " << i;
116+
#else
93117
ASSERT_EQ(result[i], expected[i]) << "where index = " << i;
118+
#endif
94119
}
95120
}
96121

@@ -130,7 +155,22 @@ void assert_eq(const T& result, const T& expected)
130155
{
131156
if(bit_equal(result, expected))
132157
return; // Check bitwise equality for +NaN, -NaN, +0.0, -0.0, +inf, -inf.
158+
#if defined(_WIN32)
159+
// GTest's ASSERT_EQ prints the values if the test fails. On Windows, the version of GTest provided by vcpkg doesn't
160+
// provide overloads for printing 128 bit types, resulting in linker errors.
161+
// Check if we're testing with 128 bit types. If so, test using bools so GTest doesn't try to print them on failure.
162+
if (test_utils::is_int128<T>::value || test_utils::is_uint128<T>::value)
163+
{
164+
const bool values_equal = (result == expected);
165+
ASSERT_EQ(values_equal, true);
166+
}
167+
else
168+
{
169+
ASSERT_EQ(result, expected);
170+
}
171+
#else
133172
ASSERT_EQ(result, expected);
173+
#endif
134174
}
135175

136176
template<class T>

test/rocprim/test_utils_data_generation.hpp

+14
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "../../common/utils_custom_type.hpp"
2626
#include "../../common/utils_data_generation.hpp"
2727

28+
#include "../common_test_header.hpp"
29+
2830
#include "test_seed.hpp"
2931
#include "test_utils_custom_float_traits_type.hpp"
3032
#include "test_utils_custom_float_type.hpp"
@@ -580,6 +582,18 @@ std::vector<size_t> get_block_size_multiples(T seed_value, const unsigned int bl
580582
return std::vector<size_t>(unique_sizes.begin(), unique_sizes.end());
581583
}
582584

585+
#if ROCPRIM_HAS_INT128_SUPPORT
586+
template<class T>
587+
using is_int128 = std::is_same<rocprim::int128_t, typename std::remove_cv<T>::type>;
588+
template<class T>
589+
using is_uint128 = std::is_same<rocprim::uint128_t, typename std::remove_cv<T>::type>;
590+
#else
591+
template<class T>
592+
using is_int128 = std::false_type;
593+
template<class T>
594+
using is_uint128 = std::false_type;
595+
#endif // ROCPRIM_HAS_INT128_SUPPORT
596+
583597
} // namespace test_utils
584598

585599
#endif //ROCPRIM_TEST_UTILS_DATA_GENERATION_HPP

0 commit comments

Comments
 (0)