Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
SpsTester.h
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 #ifndef SKA_CHEETAH_SPS_TEST_SPSTESTER_H
25 #define SKA_CHEETAH_SPS_TEST_SPSTESTER_H
26 
27 #include "cheetah/sps/Sps.h"
28 #include "cheetah/utils/test_utils/AlgorithmTester.h"
29 #include "panda/ResourcePool.h"
30 #include "panda/test/TestResourcePool.h"
31 #include <gtest/gtest.h>
32 #include <deque>
33 #include <mutex>
34 #include <condition_variable>
35 
36 namespace ska {
37 namespace cheetah {
38 namespace sps {
39 namespace test {
40 
71 template<typename ArchitectureTag, typename ArchitectureCapability>
72 struct SpsTesterTraits : public utils::test::PoolAlgorithmTesterTraits<ArchitectureTag, ArchitectureCapability> {
73  public:
75  typedef ArchitectureTag Arch;
76  typedef typename BaseT::PoolType PoolType;
77 
78  private:
79  struct TestConfig : public sps::Config
80  {
81  typedef typename SpsTesterTraits<ArchitectureTag, ArchitectureCapability>::PoolType PoolType;
82 
83  public:
84  TestConfig() : _pool(nullptr) {}
85  PoolType& pool() const { assert(_pool); return *_pool; }
86  void set_pool(PoolType& pool) { _pool = &pool; }
87 
88  protected:
89  PoolType* _pool;
90  };
91 
92  public:
94  typedef typename Api::DmTrialType DmType;
95  typedef typename Api::SpType SpType;
96 
97  public:
99  Api& api(PoolType& pool);
100  sps::Config& config();
101 
103  bool dm_handler_called() const;
104 
106  bool sp_handler_called() const;
107 
109  // blocks until the sp_handler is called or cancelled
110  // returns true if called, false if cancelled due to time out
111  bool wait_sp_handler_called() const;
112 
114  std::size_t sp_handler_call_count() const;
115 
116  std::shared_ptr<SpType> sp_data() const;
117 
118  protected:
119  virtual void configure(sps::Config& config)
120  {
121  typedef data::DedispersionMeasureType<float> Dm;
122  config.add_dm_range(Dm(0.0 * data::parsec_per_cube_cm)
123  ,Dm(60.0 * data::parsec_per_cube_cm)
124  ,Dm(10.0 * data::parsec_per_cube_cm));
125  }
126 
127  private:
128  bool _dm_called;
129  bool _sp_called;
130 
131  protected:
132  TestConfig _config;
133 
134  std::shared_ptr<DmType> _dm_data;
135  mutable std::deque<std::shared_ptr<SpType>> _sp_data;
136  mutable std::mutex _sp_data_mutex;
137  mutable std::condition_variable _sp_wait;
138  std::size_t _sp_call_count;
139 
140  std::unique_ptr<Api> _api; // must be last member
141 };
142 
143 template <typename TestTraits>
145 {
146  protected:
147  //typename sps::Sps<sps::Config, uint8_t>::BufferFillerType::AggregationBufferType BufferDataType;
149 
150  protected:
151  void SetUp();
152  void TearDown();
153 
154  public:
155  SpsTester();
156  ~SpsTester();
157 };
158 
159 TYPED_TEST_CASE_P(SpsTester);
160 
161 } // namespace test
162 } // namespace sps
163 } // namespace cheetah
164 } // namespace ska
165 #include "cheetah/sps/test_utils/detail/SpsTester.cpp"
166 
167 
168 #endif // SKA_CHEETAH_SPS_TEST_SPSTESTER_H
bool sp_handler_called() const
return true if the sp_handler has been called
Definition: SpsTester.cpp:195
all non-templated options for the sps module
Definition: Config.h:52
bool wait_sp_handler_called() const
return true if the sp_handler has been called
Definition: SpsTester.cpp:201
std::size_t sp_handler_call_count() const
return true if the sp_handler has been called
Definition: SpsTester.cpp:218
Single Pulse Search top level interface.
Definition: Sps.h:61
bool dm_handler_called() const
return true if the dm_handler has been called
Definition: SpsTester.cpp:189
Some limits and constants for FLDO.
Definition: Brdz.h:35
SpCandidate list.
Definition: SpCcl.h:52
Base class for generic algortihm tests that require an accelerator device.
A continuous memory container for dispersion measure trials of varying downsamplings.
Definition: DmTrials.h:62