Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
AlgoModuleTest.cpp
1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright (c) 2016 The SKA organisation
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #include "cheetah/utils/test/AlgoModuleTest.h"
25 #include "cheetah/utils/AlgoModule.h"
26 #include "panda/test/TestHandler.h"
27 #include "panda/test/TestPoolManager.h"
28 #include "panda/test/TestArch.h"
29 #include <typeinfo>
30 #include <typeindex>
31 
32 
33 namespace ska {
34 namespace cheetah {
35 namespace utils {
36 namespace test {
37 
38 
39 AlgoModuleTest::AlgoModuleTest()
40  : ::testing::Test()
41 {
42 }
43 
44 void AlgoModuleTest::SetUp()
45 {
46 }
47 
48 void AlgoModuleTest::TearDown()
49 {
50 }
51 
53 {
54  template<typename Algo>
55  Algo create() const
56  {
57  _called[std::type_index(typeid(Algo))] = true;
58  return Algo();
59  }
60 
61  template<class Algo>
62  bool active() const { return true; }
63 
64  template<class Algo>
65  bool called() const { return _called.find(std::type_index(typeid(Algo))) != _called.end(); }
66 
67  private:
68  mutable std::map<std::type_index, bool> _called;
69 };
70 
71 template<typename Arch>
72 class TestAlgo : public panda::test::TestHandler
73 {
74  typedef panda::test::TestHandler BaseT;
75 
76  public:
77  TestAlgo()
78  : BaseT(false)
79  {
80  }
81 
82  typedef Arch Architecture;
83  template<typename...Ts>
84  void operator()(Ts&&...) {
85  this->BaseT::operator()();
86  }
87 };
88 
89 class TestHandler : public panda::test::TestHandler
90 {
91  typedef panda::test::TestHandler BaseT;
92 
93  public:
94  TestHandler() : BaseT(false)
95  {}
96 };
97 
98 struct ArchA {};
99 struct ArchB {};
100 
101 template<typename... Archs>
103 {
105  typedef panda::test::TestPoolManager<Archs...> PoolType;
106  typedef std::tuple<TestAlgo<Archs>...> Algos;
107  typedef TestHandler Handler;
108 };
109 
110 template<typename... Archs>
112 {
113  typedef std::tuple<int> Signatures;
114 };
115 
116 struct TestA {};
117 
118 template<typename... Archs>
120 {
121  typedef std::tuple<panda::SubmitMethod<TestA>, int> Signatures;
122 };
123 
124 
125 TEST_F(AlgoModuleTest, test_basic_operation_single_algo)
126 {
127  TestHandler handler;
128  panda::test::TestPoolManager<ArchA> pool;
129  AlgoModuleTestFactory factory;
130  pool.add_resource<ArchA>();
131 
132  AlgoModule<TestAlgoModuleTraits<ArchA>> mod(pool, factory, handler);
133  int data =100;
134  auto job = mod(data);
135 
136  handler.wait(std::chrono::seconds(5));
137  job->wait();
138 }
139 
140 TEST_F(AlgoModuleTest, test_basic_operation_single_algo_multiple_signatures)
141 {
142  TestHandler handler;
143  panda::test::TestPoolManager<ArchA> pool;
144  AlgoModuleTestFactory factory;
145  pool.add_resource<ArchA>();
146 
147  AlgoModule<TestAlgoModuleTraitsMultiSig<ArchA>> mod(pool, factory, handler);
148  int data =100;
149  auto job = mod(data);
150 
151  handler.wait(std::chrono::seconds(5));
152  handler.reset();
153 
154  TestA data_2;
155  mod(data_2);
156  handler.wait(std::chrono::seconds(5));
157 }
158 
159 TEST_F(AlgoModuleTest, test_basic_operation_multi_algo)
160 {
161  TestHandler handler;
162  panda::test::TestPoolManager<ArchA, ArchB> pool;
163  AlgoModuleTestFactory factory;
164  pool.add_resource<ArchA>();
165  pool.add_resource<ArchB>();
166 
167  AlgoModule<TestAlgoModuleTraits<ArchA, ArchB>> mod(pool, factory, handler);
168  int data =100;
169  auto job = mod(data);
170 
171  handler.wait(std::chrono::seconds(5));
172  job->wait();
173 
174  ASSERT_TRUE(factory.called<TestAlgo<ArchA>>());
175  ASSERT_TRUE(factory.called<TestAlgo<ArchB>>());
176 }
177 
178 } // namespace test
179 } // namespace utils
180 } // namespace cheetah
181 } // namespace ska
Provides a module of multiple algorimic implementations to perform a specific task.
Definition: AlgoModule.h:53
Some limits and constants for FLDO.
Definition: Brdz.h:35