Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
BeamFormerDataTraitsTest.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/rcpt/test/BeamFormerDataTraitsTest.h"
25 #include "cheetah/rcpt/BeamFormerPacket.h"
26 #include "cheetah/rcpt/BeamFormerDataTraits.h"
27 #include "panda/concepts/ChunkerContextDataTraitsConcept.h"
28 #include <vector>
29 
30 
31 namespace ska {
32 namespace cheetah {
33 namespace rcpt {
34 namespace test {
35 
36 
37 BeamFormerDataTraitsTest::BeamFormerDataTraitsTest()
38  : ::testing::Test()
39 {
40 }
41 
42 BeamFormerDataTraitsTest::~BeamFormerDataTraitsTest()
43 {
44 }
45 
46 void BeamFormerDataTraitsTest::SetUp()
47 {
48 }
49 
50 void BeamFormerDataTraitsTest::TearDown()
51 {
52 }
53 
54 TEST_F(BeamFormerDataTraitsTest, test_packets_per_chunk)
55 {
56  BOOST_CONCEPT_ASSERT((panda::ChunkerContextDataTraitsConcept<BeamFormerDataTraits>));
57 
58  typedef BeamFormerDataTraits::DataType DataType;
60  BeamFormerDataTraits traits;
61  {
62  // number_of_channels == payload size
63  data::DimensionSize<data::Frequency> number_of_channels(samples_per_packet);
64  data::DimensionSize<data::Time> number_of_time_samples(10);
65 
66  DataType data(number_of_time_samples, number_of_channels);
67  unsigned packets_per_chunk = traits.chunk_size(data)/traits.packet_size();
68  ASSERT_EQ((std::size_t)number_of_time_samples, packets_per_chunk);
69  }
70  {
71  // number_of_channels int multiple of payload size
72  data::DimensionSize<data::Frequency> number_of_channels( 2 * samples_per_packet );
73  data::DimensionSize<data::Time> number_of_time_samples(2);
74 
75  DataType data(number_of_time_samples, number_of_channels);
76  unsigned packets_per_chunk = traits.chunk_size(data)/traits.packet_size();
77  ASSERT_EQ(number_of_time_samples * 2, packets_per_chunk);
78  }
79  {
80  // number_of_channels < packet payload
81  data::DimensionSize<data::Frequency> number_of_channels( samples_per_packet - 1 );
82  data::DimensionSize<data::Time> number_of_time_samples(2);
83 
84  DataType data(number_of_time_samples, number_of_channels);
85  ASSERT_EQ(number_of_time_samples * number_of_channels, traits.chunk_size(data));
86  ASSERT_EQ(samples_per_packet, traits.packet_size());
87 
88  // verify realign chunk with packet boundary.
89  number_of_time_samples = data::DimensionSize<data::Time>(samples_per_packet);
90  DataType data2(number_of_time_samples, number_of_channels);
91  unsigned packets_per_chunk = traits.chunk_size(data2)/traits.packet_size();
92  ASSERT_EQ(number_of_time_samples - 1, packets_per_chunk);
93  }
94 }
95 
96 struct TestContext {
97  public:
98  TestContext()
99  : _data(new data::TimeFrequency<Cpu, uint8_t>(data::DimensionSize<data::Time>(100), data::DimensionSize<data::Frequency>(100)))
100  {}
101 
102  std::size_t offset() const { return 0; }
103  std::size_t packet_offset() const { return 0; }
104  data::TimeFrequency<Cpu, uint8_t>& chunk() { return *_data; }
105  //TestContext& next() { _next.reset(new TestContext()); return *_next; }
106  std::size_t size() const { return 2; }
107 
108  uint64_t sequence_number(BeamFormerDataTraits::PacketInspector const& packet) const { return packet.sequence_number(); }
109 
110  private:
111  std::shared_ptr<data::TimeFrequency<Cpu, uint8_t>> _data;
112  std::shared_ptr<TestContext> _next;
113 };
114 
115 std::ostream& operator<<(std::ostream& os, TestContext const&) { return os;}
116 
117 TEST_F(BeamFormerDataTraitsTest, test_deserialise)
118 {
119  // basic compile test
121  packet.packet_type(PacketType::StokesI);
123  TestContext context;
124  dt.deserialise_packet(context, packet);
125 }
126 
127 
128 } // namespace test
129 } // namespace rcpt
130 } // namespace cheetah
131 } // namespace ska
uint64_t sequence_number() const
return the sequence number embedded in the packet
static void deserialise_packet(ContextType &context, PacketInspector const &)
function responsible for transfering data from the packet in to the data structure ...
Traits describing the BeamFormer Data Stream to the panda::PacketSream system.
BeamFormerPacket inspection and data extraction.
Some limits and constants for FLDO.
Definition: Brdz.h:35
static constexpr std::size_t number_of_samples()
the total number of samples in the rcpt payload
void packet_type(PacketType const)
set the type of packet