Add test_header.hpp file
MODIFY
test/test_allocator.cpp
test/test_allocator.cpp
#include <type_traits>
#include <cstdlib>
#include <algorithm>
-
-// Google Test
-#include <gtest/gtest.h>
+#include <memory>
// Thrust
#include <thrust/device_malloc_allocator.h>
#include <thrust/device_vector.h>
#include <thrust/host_vector.h>
#include <thrust/system/cpp/vector.h>
-#include <memory>
-// HIP API
-#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC
-#include <hip/hip_runtime_api.h>
-
-#define HIP_CHECK(condition) ASSERT_EQ(condition, hipSuccess)
-#endif // THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC
+#include "test_header.hpp"
#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC

MODIFY
test/test_binary_search.cpp
test/test_binary_search.cpp
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
-// Google Test
-#include <gtest/gtest.h>
-
// Thrust
#include <thrust/binary_search.h>
#include <thrust/iterator/retag.h>
#include <thrust/sequence.h>
#include <thrust/sort.h>
-// HIP API
-#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC
-#include <hip/hip_runtime_api.h>
-
-#define HIP_CHECK(condition) ASSERT_EQ(condition, hipSuccess)
-#endif // THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC
-
-#include "test_utils.hpp"
+#include "test_header.hpp"
-template<
- class InputType
->
-struct Params
-{
- using input_type = InputType;
-};
+#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC
-template<class Params>
-class BinarySearchTests : public ::testing::Test
-{
-public:
- using input_type = typename Params::input_type;
-};
-
-typedef ::testing::Types<
- Params<thrust::host_vector<short>>,
- Params<thrust::host_vector<int>>,
- Params<thrust::host_vector<long long>>,
- Params<thrust::host_vector<unsigned short>>,
- Params<thrust::host_vector<unsigned int>>,
- Params<thrust::host_vector<unsigned long long>>,
- Params<thrust::host_vector<float>>,
- Params<thrust::host_vector<double>>,
- Params<thrust::device_vector<short>>,
- Params<thrust::device_vector<int>>,
- Params<thrust::device_vector<long long>>,
- Params<thrust::device_vector<unsigned short>>,
- Params<thrust::device_vector<unsigned int>>,
- Params<thrust::device_vector<unsigned long long>>,
- Params<thrust::device_vector<float>>,
- Params<thrust::device_vector<double>>
-> BinarySearchTestsParams;
-
-TYPED_TEST_CASE(BinarySearchTests, BinarySearchTestsParams);
+TESTS_DEFINE(BinarySearchTests, FullTestsParams);
__THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_BEGIN
@@ -332,3 +290,5 @@ TEST(BinarySearchTests, TestScalarEqualRangeDispatchImplicit)
}
__THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_END
+
+#endif // THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC

MODIFY
test/test_binary_search_descending.cpp
test/test_binary_search_descending.cpp
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
-// Google Test
-#include <gtest/gtest.h>
-
// Thrust
#include <thrust/binary_search.h>
#include <thrust/functional.h>
-
#include <thrust/sequence.h>
#include <thrust/sort.h>
-// HIP API
-#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC
-#include <hip/hip_runtime_api.h>
-
-#define HIP_CHECK(condition) ASSERT_EQ(condition, hipSuccess)
-#endif // THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC
-
-#include "test_utils.hpp"
-#include "test_assertions.hpp"
+#include "test_header.hpp"
-template<
- class InputType
->
-struct Params
-{
- using input_type = InputType;
-};
+#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC
-template<class Params>
-class BinarySearchDescendingTests : public ::testing::Test
-{
-public:
- using input_type = typename Params::input_type;
-};
-
-typedef ::testing::Types<
- Params<thrust::host_vector<short>>,
- Params<thrust::host_vector<int>>,
- Params<thrust::host_vector<long long>>,
- Params<thrust::host_vector<unsigned short>>,
- Params<thrust::host_vector<unsigned int>>,
- Params<thrust::host_vector<unsigned long long>>,
- Params<thrust::host_vector<float>>,
- Params<thrust::host_vector<double>>,
- Params<thrust::device_vector<short>>,
- Params<thrust::device_vector<int>>,
- Params<thrust::device_vector<long long>>,
- Params<thrust::device_vector<unsigned short>>,
- Params<thrust::device_vector<unsigned int>>,
- Params<thrust::device_vector<unsigned long long>>,
- Params<thrust::device_vector<float>>,
- Params<thrust::device_vector<double>>
-> BinarySearchDescendingTestsParams;
-
-TYPED_TEST_CASE(BinarySearchDescendingTests, BinarySearchDescendingTestsParams);
+TESTS_DEFINE(BinarySearchDescendingTests, FullTestsParams);
TYPED_TEST(BinarySearchDescendingTests, TestScalarLowerBoundDescendingSimple)
{
@@ -179,3 +135,5 @@ TYPED_TEST(BinarySearchDescendingTests, TestScalarEqualRangeDescendingSimple)
ASSERT_EQ_QUIET(vec.begin() + 1, thrust::equal_range(vec.begin(), vec.end(), 8, thrust::greater<int>()).second);
ASSERT_EQ_QUIET(vec.begin() + 0, thrust::equal_range(vec.begin(), vec.end(), 9, thrust::greater<int>()).second);
}
+
+#endif // THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC

MODIFY
test/test_binary_search_vector.cpp
test/test_binary_search_vector.cpp
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
-// Google Test
-#include <gtest/gtest.h>
-
// Thrust
#include <thrust/binary_search.h>
#include <thrust/sequence.h>
#include <thrust/iterator/discard_iterator.h>
#include <thrust/iterator/retag.h>
-// HIP API
-#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC
-#include <hip/hip_runtime_api.h>
-
-#define HIP_CHECK(condition) ASSERT_EQ(condition, hipSuccess)
-#endif // THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC
-
-#include "test_utils.hpp"
-#include "test_assertions.hpp"
-
-template<
- class InputType
->
-struct Params
-{
- using input_type = InputType;
-};
-
-template<class Params>
-class BinarySearchVectorTests : public ::testing::Test
-{
-public:
- using input_type = typename Params::input_type;
-};
-
-typedef ::testing::Types<
- Params<thrust::host_vector<short>>,
- Params<thrust::host_vector<int>>,
- Params<thrust::host_vector<long long>>,
- Params<thrust::host_vector<unsigned short>>,
- Params<thrust::host_vector<unsigned int>>,
- Params<thrust::host_vector<unsigned long long>>,
- Params<thrust::host_vector<float>>,
- Params<thrust::host_vector<double>>,
- Params<thrust::device_vector<short>>,
- Params<thrust::device_vector<int>>,
- Params<thrust::device_vector<long long>>,
- Params<thrust::device_vector<unsigned short>>,
- Params<thrust::device_vector<unsigned int>>,
- Params<thrust::device_vector<unsigned long long>>,
- Params<thrust::device_vector<float>>,
- Params<thrust::device_vector<double>>
-> BinarySearchVectorTestsParams;
-
-TYPED_TEST_CASE(BinarySearchVectorTests, BinarySearchVectorTestsParams);
-
-template<class Params>
-class BinarySearchVectorIntegerTests : public ::testing::Test
-{
-public:
- using input_type = typename Params::input_type;
-};
+#include "test_header.hpp"
-typedef ::testing::Types<
- Params<short>,
- Params<int>,
- Params<long long>
-> BinarySearchVectorIntegerTestsParams;
+TESTS_DEFINE(BinarySearchVectorTests, FullTestsParams);
-TYPED_TEST_CASE(BinarySearchVectorIntegerTests, BinarySearchVectorIntegerTestsParams);
+TESTS_DEFINE(BinarySearchVectorIntegerTests, SignedIntegerTestsParams);
// convert xxx_vector<T1> to xxx_vector<T2>

MODIFY
test/test_binary_search_vector_descending.cpp
test/test_binary_search_vector_descending.cpp
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
-// Google Test
-#include <gtest/gtest.h>
-
// Thrust
#include <thrust/binary_search.h>
#include <thrust/functional.h>
-
#include <thrust/sequence.h>
#include <thrust/sort.h>
-// HIP API
-#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC
-#include <hip/hip_runtime_api.h>
-
-#define HIP_CHECK(condition) ASSERT_EQ(condition, hipSuccess)
-#endif // THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC
-
-#include "test_utils.hpp"
-#include "test_assertions.hpp"
+#include "test_header.hpp"
-template<
- class InputType
->
-struct Params
-{
- using input_type = InputType;
-};
-
-template<class Params>
-class BinarySearchVectorDescendingTests : public ::testing::Test
-{
-public:
- using input_type = typename Params::input_type;
-};
-
-typedef ::testing::Types<
- Params<thrust::host_vector<short>>,
- Params<thrust::host_vector<int>>,
- Params<thrust::host_vector<long long>>,
- Params<thrust::host_vector<unsigned short>>,
- Params<thrust::host_vector<unsigned int>>,
- Params<thrust::host_vector<unsigned long long>>,
- Params<thrust::host_vector<float>>,
- Params<thrust::host_vector<double>>,
- Params<thrust::device_vector<short>>,
- Params<thrust::device_vector<int>>,
- Params<thrust::device_vector<long long>>,
- Params<thrust::device_vector<unsigned short>>,
- Params<thrust::device_vector<unsigned int>>,
- Params<thrust::device_vector<unsigned long long>>,
- Params<thrust::device_vector<float>>,
- Params<thrust::device_vector<double>>
-> BinarySearchVectorDescendingTestsParams;
-
-TYPED_TEST_CASE(BinarySearchVectorDescendingTests, BinarySearchVectorDescendingTestsParams);
-
-template<class Params>
-class BinarySearchVectorDescendingIntegerTests : public ::testing::Test
-{
-public:
- using input_type = typename Params::input_type;
-};
-
-typedef ::testing::Types<
- Params<short>,
- Params<int>,
- Params<long long>
-> BinarySearchVectorDescendingIntegerTestsParams;
-
-TYPED_TEST_CASE(BinarySearchVectorDescendingIntegerTests, BinarySearchVectorDescendingIntegerTestsParams);
+#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC
+TESTS_DEFINE(BinarySearchVectorDescendingTests, FullTestsParams);
+TESTS_DEFINE(BinarySearchVectorDescendingIntegerTests, SignedIntegerTestsParams);
// convert xxx_vector<T1> to xxx_vector<T2>
template <class ExampleVector, typename NewType>
@@ -305,3 +246,5 @@ TYPED_TEST(BinarySearchVectorDescendingIntegerTests, TestVectorBinarySearchDesce
ASSERT_EQ(h_output, d_output);
}
}
+
+#endif // THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC

ADD
test/test_header.hpp
+// MIT License
+//
+// Copyright (c) 2018 Advanced Micro Devices, Inc. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+
+// Google Test
+#include <gtest/gtest.h>
+
+// HIP API
+#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC
+#include <hip/hip_runtime.h>
+#include <hip/hip_runtime_api.h>
+
+#define HIP_CHECK(condition) ASSERT_EQ(condition, hipSuccess)
+#endif // THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC
+
+#include "test_assertions.hpp"
+#include "test_utils.hpp"
+
+// Input type parameter
+template<class InputType>
+struct Params
+{
+ using input_type = InputType;
+};
+
+// Definition of typed test cases with given parameter type
+#define TESTS_DEFINE(x, y) \
+template<class Params> \
+class x : public ::testing::Test \
+{ \
+public: \
+ using input_type = typename Params::input_type; \
+}; \
+\
+TYPED_TEST_CASE(x, y);
+
+// Set of test parameter types
+
+// Host and device vectors of all type as a test parameter
+typedef ::testing::Types<
+ Params<thrust::host_vector<short>>,
+ Params<thrust::host_vector<int>>,
+ Params<thrust::host_vector<long long>>,
+ Params<thrust::host_vector<unsigned short>>,
+ Params<thrust::host_vector<unsigned int>>,
+ Params<thrust::host_vector<unsigned long long>>,
+ Params<thrust::host_vector<float>>,
+ Params<thrust::host_vector<double>>,
+ Params<thrust::device_vector<short>>,
+ Params<thrust::device_vector<int>>,
+ Params<thrust::device_vector<long long>>,
+ Params<thrust::device_vector<unsigned short>>,
+ Params<thrust::device_vector<unsigned int>>,
+ Params<thrust::device_vector<unsigned long long>>,
+ Params<thrust::device_vector<float>>,
+ Params<thrust::device_vector<double>>
+> FullTestsParams;
+
+
+// Host and device vectors of signed type
+typedef ::testing::Types<
+ Params<thrust::host_vector<short>>,
+ Params<thrust::host_vector<int>>,
+ Params<thrust::host_vector<long long>>,
+ Params<thrust::host_vector<float>>,
+ Params<thrust::host_vector<double>>,
+ Params<thrust::device_vector<short>>,
+ Params<thrust::device_vector<int>>,
+ Params<thrust::device_vector<long long>>,
+ Params<thrust::device_vector<float>>,
+ Params<thrust::device_vector<double>>
+> VectorSignedTestsParams;
+
+
+// Host and device vectors of integer types as a test parameter
+typedef ::testing::Types<
+Params<thrust::host_vector<short>>,
+Params<thrust::host_vector<int>>,
+Params<thrust::host_vector<long long>>,
+Params<thrust::host_vector<unsigned short>>,
+Params<thrust::host_vector<unsigned int>>,
+Params<thrust::host_vector<unsigned long long>>,
+Params<thrust::device_vector<short>>,
+Params<thrust::device_vector<int>>,
+Params<thrust::device_vector<long long>>,
+Params<thrust::device_vector<unsigned short>>,
+Params<thrust::device_vector<unsigned int>>,
+Params<thrust::device_vector<unsigned long long>>
+> VectorIntegerTestsParams;
+
+
+// Host and device vectors of signed integer types as a test parameter
+typedef ::testing::Types<
+Params<thrust::host_vector<short>>,
+Params<thrust::host_vector<int>>,
+Params<thrust::host_vector<long long>>,
+Params<thrust::device_vector<short>>,
+Params<thrust::device_vector<int>>,
+Params<thrust::device_vector<long long>>
+> VectorSignedIntegerTestsParams;
+
+
+// Host vectors of numerical types as a test parameter
+typedef ::testing::Types<
+Params<thrust::host_vector<short>>,
+Params<thrust::host_vector<int>>,
+Params<thrust::host_vector<long long>>,
+Params<thrust::host_vector<unsigned short>>,
+Params<thrust::host_vector<unsigned int>>,
+Params<thrust::host_vector<unsigned long long>>,
+Params<thrust::host_vector<float>>,
+Params<thrust::host_vector<double>>
+> HostVectorTestsParams;
+
+
+// Host vectors of integer types as a test parameter
+typedef ::testing::Types<
+Params<thrust::host_vector<short>>,
+Params<thrust::host_vector<int>>,
+Params<thrust::host_vector<long long>>,
+Params<thrust::host_vector<unsigned short>>,
+Params<thrust::host_vector<unsigned int>>,
+Params<thrust::host_vector<unsigned long long>>
+> HostVectorIntegerTestsParams;
+
+
+// Scalar numerical types
+typedef ::testing::Types<
+ Params<short>,
+ Params<int>,
+ Params<long long>,
+ Params<unsigned short>,
+ Params<unsigned int>,
+ Params<unsigned long long>,
+ Params<float>,
+ Params<double>
+> NumericalTestsParams;
+
+
+// Scalar interger types
+typedef ::testing::Types<
+ Params<short>,
+ Params<int>,
+ Params<long long>,
+ Params<unsigned short>,
+ Params<unsigned int>,
+ Params<unsigned long long>
+> IntegerTestsParams;
+
+
+// Scalar signed interger types
+typedef ::testing::Types<
+ Params<short>,
+ Params<int>,
+ Params<long long>
+> SignedIntegerTestsParams;
+
+
+// Scalar unsigned interger types of all lengths
+typedef ::testing::Types<
+ Params<thrust::detail::uint8_t>,
+ Params<thrust::detail::uint16_t>,
+ Params<thrust::detail::uint32_t>,
+ Params<thrust::detail::uint64_t>
+> UnsignedIntegerTestsParams;
+
+
+// Scalar all interger types
+typedef ::testing::Types<
+ Params<short>,
+ Params<int>,
+ Params<long long>,
+ Params<unsigned short>,
+ Params<unsigned int>,
+ Params<unsigned long long>,
+ Params<thrust::detail::uint8_t>,
+ Params<thrust::detail::uint16_t>,
+ Params<thrust::detail::uint32_t>,
+ Params<thrust::detail::uint64_t>
+> AllIntegerTestsParams;
+
+
+// Scalar float types
+typedef ::testing::Types<
+ Params<float>,
+ Params<double>
+> FloatTestsParams;
+

Add test_header.hpp file