Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
DataExportTest.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/exporters/test/DataExportTest.h"
25 #include "cheetah/exporters/DataExport.h"
26 #include "panda/test/TestChunk.h"
27 #include "panda/test/TestChunkHandler.h"
28 #include "panda/ProcessingEngineConfig.h"
29 #include <iostream>
30 
31 
32 namespace ska {
33 namespace cheetah {
34 namespace exporters {
35 namespace test {
36 
37 
38 DataExportTest::DataExportTest()
39  : ::testing::Test()
40 {
41 }
42 
43 DataExportTest::~DataExportTest()
44 {
45 }
46 
47 void DataExportTest::SetUp()
48 {
49 }
50 
51 void DataExportTest::TearDown()
52 {
53 }
54 
55 /*
56  * a DataExport
57  * that exposes the protected members so we can test easily
58  */
59 template<typename... TestChunks>
60 class TestDataExport : public DataExport<TestChunks...>
61 {
62  typedef DataExport<TestChunks...> BaseT;
63 
64  public:
66  : BaseT(config) {}
67  void init() { BaseT::init(); }
68 
69  template<typename DataType>
70  void set_factory(ExporterType const& type_id, typename ExportInitialiser<BaseT, DataType>::FactoryType const& factory)
71  {
72  BaseT::template set_factory<DataType>(type_id, factory);
73  }
74 };
75 
76 TEST_F(DataExportTest, test_config_not_set)
77 {
78  panda::ChannelId channel_id("channel_1");
79  ExporterType exporter_type("test_exporter");
80 
81  DataExportConfig config;
82  panda::ProcessingEngineConfig engine_config;
83  engine_config.number_of_threads(0);
84  config.set_engine_config(engine_config);
85 
87 
88  bool factory_called = false;
89  panda::test::TestChunkHandler<panda::test::TestChunk_A> handler(false); // this should never be run
90  exporter.set_factory<panda::test::TestChunk_A>(exporter_type, [&handler, &factory_called](exporters::DataExportStreamConfig) { factory_called=true; return handler; } );
91  exporter.init();
92  ASSERT_FALSE(factory_called);
93 
94  // verify available() is returning the correct value
95  std::set<ExporterType> expected_types({exporter_type});
96  ASSERT_EQ(expected_types, exporter.available());
97 
98  // check channel is not calling any handler
99  std::shared_ptr<panda::test::TestChunk_A> chunk = std::make_shared<panda::test::TestChunk_A>("ooo");
100  exporter.send(channel_id, chunk);
101  ASSERT_FALSE(handler.executed());
102 }
103 
105  public:
106  TestExporterConfig() : utils::Config("test") {}
107  void add_options(OptionsDescriptionEasyInit&) {}
108 };
109 
110 TEST_F(DataExportTest, test_config_set_single_thread)
111 {
117  panda::ChannelId channel_id("channel_1");
118  ExporterType exporter_type("test_exporter");
119  TestExporterConfig exporter_config;
120 
121  DataExportConfig config;
122  panda::ProcessingEngineConfig engine_config;
123  engine_config.number_of_threads(0);
124  config.set_engine_config(engine_config);
125  config.activate(channel_id);
126  DataExportStreamConfig export_config(channel_id, config.engine(channel_id), exporter_type, exporter_config);
127  config.add_exporter(export_config);
128 
130 
131  panda::test::TestChunkHandler<panda::test::TestChunk_A> handler(false);
132  bool factory_called = false;
133  exporter.set_factory<panda::test::TestChunk_A>(exporter_type,
134  [&handler, &factory_called](exporters::DataExportStreamConfig)
135  {
136  factory_called=true;
137  return handler;
138  } );
139  exporter.init();
140  ASSERT_TRUE(factory_called);
141 
142  // check channel is calling our handler
143  std::shared_ptr<panda::test::TestChunk_A> chunk = std::make_shared<panda::test::TestChunk_A>("ooo");
144  exporter.send(channel_id, chunk);
145 
146  ASSERT_TRUE(handler.executed());
147  ASSERT_EQ(*chunk, handler.chunk());
148 }
149 
150 TEST_F(DataExportTest, test_config_set_multi_thread)
151 {
157  panda::ChannelId channel_id("channel_1");
158  ExporterType exporter_type("test_exporter");
159  TestExporterConfig exporter_config;
160 
161  DataExportConfig config;
162  config.number_of_threads(1);
163  panda::Engine engine;
164  DataExportStreamConfig export_config(channel_id, engine, exporter_type, exporter_config);
165  config.add_exporter(export_config);
166  config.activate(channel_id);
167 
169 
170  bool factory_called = false;
171  panda::test::TestChunkHandler<panda::test::TestChunk_A> handler(true);
172  exporter.set_factory<panda::test::TestChunk_A>(exporter_type, [&handler, &factory_called](exporters::DataExportStreamConfig) { factory_called=true; return handler; } );
173  exporter.init();
174  ASSERT_TRUE(factory_called);
175 
176  // check channel is calling our handler
177  std::shared_ptr<panda::test::TestChunk_A> chunk = std::make_shared<panda::test::TestChunk_A>("ooo");
178  exporter.send(channel_id, chunk);
179  handler.wait();
180  ASSERT_TRUE(handler.executed());
181  ASSERT_EQ(*chunk, handler.chunk());
182 }
183 
184 TEST_F(DataExportTest, test_activate_test_probe)
185 {
186  panda::ChannelId channel_id("channel_1");
187  DataExportConfig config;
188  config.number_of_threads(0);
190 
191  // activate the probe
192  TestProbe<panda::test::TestChunk_A>& probe = exporter.activate_test_probe<panda::test::TestChunk_A>(channel_id);
193  std::shared_ptr<panda::test::TestChunk_A> chunk = std::make_shared<panda::test::TestChunk_A>("ooo");
194  exporter.send(channel_id, chunk);
195  ASSERT_EQ(&*probe.data(), &*chunk);
196 }
197 
198 } // namespace test
199 } // namespace exporters
200 } // namespace cheetah
201 } // namespace ska
std::shared_ptr< const T > data()
return the data data received
Definition: TestProbe.cpp:54
Configuration Object for DataExport module.
Base class for module configuration.
Definition: Config.h:42
panda::Engine & engine(panda::ChannelId const &)
return the engine allocated to the specified channel
Defines the mapping of a sinks configuration block with the sink type, and the channel to associate i...
void set_engine_config(panda::ChannelId const &channel_id, panda::ProcessingEngineConfig const &config)
set the engine confugration for a specified channel
std::set< ExporterType > const & available() const
return the exporter types available in this class
Definition: DataExport.cpp:127
void add_exporter(DataExportStreamConfig)
set an export streamer configurations
Some limits and constants for FLDO.
Definition: Brdz.h:35
string based tag for refering to the type of Exporter, based on a std::string
Definition: ExporterType.h:36
Attach to a stream to record the data sent.
Definition: TestProbe.h:42
This class initialises a suitable panda::DataSwitch according to the exporters::DataExportConfigurati...
Definition: DataExport.h:55
TestProbe< DataType > & activate_test_probe(panda::ChannelId const &)
activates a TestProbe object for monitoring the streamed data of DataType to a specific ...
Definition: DataExport.cpp:134
void number_of_threads(unsigned const &number_of_threads)
set the number of dedicated threads to service exporters export (default 0)