Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
SigProcFileStreamTest.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/sigproc/test/SigProcFileStreamTest.h"
25 #include "cheetah/sigproc/SigProcFileStream.h"
26 #include "pss/astrotypes/sigproc/FileReader.h"
27 
28 #include "panda/DataManager.h"
29 #include "panda/test/gtest.h"
30 
31 namespace ska {
32 namespace cheetah {
33 namespace sigproc {
34 namespace test {
35 
36 
37 SigProcFileStreamTest::SigProcFileStreamTest()
38  : ::testing::Test()
39 {
40 }
41 
42 SigProcFileStreamTest::~SigProcFileStreamTest()
43 {
44 }
45 
46 void SigProcFileStreamTest::SetUp()
47 {
48 }
49 
50 void SigProcFileStreamTest::TearDown()
51 {
52 }
53 
54 TEST_F(SigProcFileStreamTest, test_empty_file_name)
55 {
56  Config config;
57  SigProcFileStream stream(config);
58  panda::DataManager<SigProcFileStream> chunk_manager(stream);
59  ASSERT_TRUE(stream.process()); // end of stream
60 }
61 
62 TEST_F(SigProcFileStreamTest, test_single_valid_file_defined)
63 {
64  Config config;
65  config.set_sigproc_files(panda::test::test_file("valid_sigproc.sigproc"));
66  SigProcFileStream stream(config);
67  panda::DataManager<SigProcFileStream> chunk_manager(stream);
68  ASSERT_FALSE(stream.process());
69 
70  std::tuple<std::shared_ptr<data::TimeFrequency<Cpu, uint8_t>>> data_tuple=chunk_manager.next();
71  data::TimeFrequency<Cpu, uint8_t>& data = *(std::get<0>(data_tuple));
72  ASSERT_EQ(250368U, data.number_of_spectra());
73  ASSERT_EQ(std::size_t(2), data.number_of_channels());
74 }
75 
76 TEST_F(SigProcFileStreamTest, test_single_invalid_file_defined)
77 {
78  Config config;
79  config.set_sigproc_files(panda::test::test_file("invalid_sigproc.sigproc"));
80  SigProcFileStream stream(config);
81  panda::DataManager<SigProcFileStream> chunk_manager(stream);
82  ASSERT_THROW(stream.process(), panda::Error);
83  ASSERT_TRUE(stream.process()); // end of stream
84 }
85 
86 TEST_F(SigProcFileStreamTest, test_invalid_file_followed_by_valid_file)
87 {
88  Config config;
89  config.set_sigproc_files(std::vector<std::string>({panda::test::test_file("invalid_sigproc.sigproc"), panda::test::test_file("valid_sigproc.sigproc") }));
90  SigProcFileStream stream(config);
91  panda::DataManager<SigProcFileStream> chunk_manager(stream);
92  ASSERT_THROW(stream.process(), panda::Error);
93  ASSERT_FALSE(stream.process()); // valid data
94 }
95 
96 TEST_F(SigProcFileStreamTest, test_chunk_samples_from_config_preset)
97 {
98  // prep test files
99  std::string sigproc_file { panda::test::test_file("valid_sigproc.sigproc") };
100  pss::astrotypes::sigproc::FileReader<> sfr(sigproc_file);
101  std::size_t number_of_spectra=sfr.number_of_data_points()/sfr.header().number_of_channels();
102 
103  for(unsigned i=1; i<7; ++i) {
104  SCOPED_TRACE(i);
105  Config config;
106  config.set_sigproc_files(sigproc_file);
107  config.set_chunk_samples(i);
108 
109  SigProcFileStream stream(config);
110  panda::DataManager<SigProcFileStream> chunk_manager(stream);
111  ASSERT_FALSE(stream.process()) << i;
112  std::size_t number_of_chunks = number_of_spectra/i;
113  for(unsigned chunk=0; chunk<number_of_chunks; ++chunk) {
114  std::tuple<std::shared_ptr<data::TimeFrequency<Cpu, uint8_t>>> data = chunk_manager.next();
115  ASSERT_EQ(i, std::get<0>(data)->number_of_spectra());
116  ASSERT_EQ(std::size_t(2), std::get<0>(data)->number_of_channels());
117  ASSERT_EQ( std::get<0>(data)->end() - std::get<0>(data)->begin(), i * std::get<0>(data)->number_of_channels());
118  }
119  // check chunks that do not match the exact length of the file (should be resized to fit)
120  std::size_t remainder = number_of_spectra - number_of_chunks * i;
121  if(remainder > 0) {
122  std::tuple<std::shared_ptr<data::TimeFrequency<Cpu, uint8_t>>> data = chunk_manager.next();
123  ASSERT_EQ(remainder, (std::size_t)std::get<0>(data)->number_of_spectra());
124  ASSERT_EQ(std::size_t(2), std::get<0>(data)->number_of_channels());
125  ASSERT_NE(0.0, *std::get<0>(data)->begin()); // check we get some data
126  }
127  }
128 }
129 
130 } // namespace test
131 } // namespace sigproc
132 } // namespace cheetah
133 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35