Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
/home/docs/checkouts/readthedocs.org/user_builds/ska-pss-cheetah/checkouts/st-1252/cheetah/utils/test_utils/AlgorithmTester.h

Macro for defining unit tests that require an accelerated device This provides a device named 'device' to your code

ALGORITHM_TYPED_TEST_P(RfiTester, single_band_interference_spike) { // you have access to the device via

Parameters
devuice// and also TypeParam is available. See Type Param tests in google docs for more info // n.b. the scope is not that of the fixture class Tester and so no access to members // or methods of that class }
/*
* The MIT License (MIT)
*
* Copyright (c) 2016 The SKA organisation
*
* 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.
*/
#ifndef SKA_CHEETAH_TEST_UTILS_ALGORITHMTESTER_H
#define SKA_CHEETAH_TEST_UTILS_ALGORITHMTESTER_H
#include "panda/System.h"
#include "panda/arch/nvidia/Nvidia.h"
#include "panda/test/TestResourcePool.h"
#include <gtest/gtest.h>
#include <functional>
#define ALGORITHM_TYPED_TEST_P(CaseName ,TestName) \
template<typename TestTraits> void _algorithm_test_case_##CaseName##TestName(typename TestTraits::DeviceType&); \
TYPED_TEST_P(CaseName , TestName) \
{ \
ASSERT_NE(0U, this->devices().size()) << "no suitable devices"; \
unsigned count = 0; \
for( auto & device : this->devices()) { \
std::cout << "running on device " << count++ << std::endl; \
device->run([](typename std::decay<decltype(device)>::type::element_type & device) { _algorithm_test_case_##CaseName##TestName<TypeParam>(device); } ); \
} \
} \
template<typename TypeParam> void _algorithm_test_case_##CaseName##TestName(typename TypeParam::DeviceType& device)
#define POOL_ALGORITHM_TYPED_TEST_P(CaseName ,TestName) \
template<typename TestTraits> void _pool_algorithm_test_case_##CaseName##TestName(typename TestTraits::PoolType); \
TYPED_TEST_P(CaseName , TestName) \
{ \
ASSERT_NE(0U, this->devices().size()) << "no suitable devices"; \
unsigned count = 0; \
for( auto & device : this->devices()) { \
typename TypeParam::PoolType pool; \
pool.template add_resource<typename TypeParam::Arch>(device); \
std::cout << "running on pool with device " << count++ << std::endl; \
_pool_algorithm_test_case_##CaseName##TestName<TypeParam>(std::move(pool)); \
} \
} \
template<typename TypeParam> void _pool_algorithm_test_case_##CaseName##TestName(typename TypeParam::PoolType pool)
namespace ska {
namespace cheetah {
namespace utils {
namespace test {
template <typename DeviceType, typename Traits>
struct supports {
static bool compatible(DeviceType const&);
};
template <typename ArchitectureType,
typename CapabilityType,
typename DeviceTypeParam=panda::PoolResource<ArchitectureType>
>
struct AlgorithmTesterTraits {
typedef ArchitectureType Arch;
typedef DeviceTypeParam DeviceType;
typedef CapabilityType Capability;
typedef std::shared_ptr<panda::PoolResource<Arch>> TestParam;
};
template <typename ArchitectureType,
typename CapabilityType=void,
typename DeviceTypeParam=panda::PoolResource<ArchitectureType>,
typename PoolTypeParam=panda::test::TestResourcePool<ArchitectureType>>
struct PoolAlgorithmTesterTraits {
typedef ArchitectureType Arch;
typedef CapabilityType Capability;
typedef DeviceTypeParam DeviceType;
typedef PoolTypeParam PoolType;
typedef PoolType TestParam;
};
template <typename Traits>
class AlgorithmTester : public ::testing::TestWithParam<typename Traits::TestParam>
{
public:
typedef Traits AlgorithmTraits;
typedef std::shared_ptr<panda::PoolResource<typename Traits::Arch>> DeviceType;
public:
AlgorithmTester();
virtual ~AlgorithmTester();
protected:
std::vector<DeviceType>& devices() { return _devices; }
private:
std::vector<DeviceType> _devices;
};
} // namepsace test
} // namespace utils
} // namespace cheetah
} // namespace ska
#include "cheetah/utils/test_utils/detail/AlgorithmTester.cpp"
#endif // SKA_CHEETAH_TEST_UTILS_ALGORITHMTESTER_H