24 #include "cheetah/rcpt/test/UdpStreamTest.h" 25 #include "cheetah/rcpt/UdpStream.h" 26 #include "cheetah/rcpt/Config.h" 27 #include "cheetah/rcpt/PacketGenerator.h" 28 #include "panda/DataManager.h" 29 #include "panda/IpAddress.h" 30 #include "panda/Log.h" 31 #include "panda/Engine.h" 45 UdpStreamTest::UdpStreamTest()
50 UdpStreamTest::~UdpStreamTest()
54 void UdpStreamTest::SetUp()
58 void UdpStreamTest::TearDown()
66 DataType& next(DataType& data) {
68 std::unique_lock<std::mutex> lk(_mutex);
70 std::generate(data.begin(), data.end(), [&]{
return ++val; } );
71 _data.push_back(data);
75 DataType sent_data() {
76 std::lock_guard<std::mutex> lk(_mutex);
77 if(_data.empty())
throw panda::Error(
"no more sent data");
78 DataType d = _data.front();
83 bool has_sent_data()
const {
84 std::lock_guard<std::mutex> lk(_mutex);
85 return !_data.empty();
89 mutable std::mutex _mutex;
90 std::deque<DataType> _data;
99 ss << (unsigned)d <<
",";
105 template<
typename Packet>
106 void test_udp_packets_stream_data_consistency(std::size_t number_of_channels)
108 typedef ska::panda::Connection<ska::panda::ConnectionTraits<ska::panda::Udp>> ConnectionType;
110 panda::IpAddress address(0,
"127.0.0.1");
111 boost::asio::ip::udp::endpoint local_endpoint = address.end_point<boost::asio::ip::udp::endpoint>();
115 ASSERT_EQ(1U, config.samples_per_chunk());
118 SCOPED_TRACE(number_of_channels);
119 SCOPED_TRACE(
"number_of_channels per time sample:");
120 PANDA_LOG_DEBUG <<
"number_of_channles per time sample=" << number_of_channels;
121 config.number_of_channels(number_of_channels);
122 config.remote_end_point(local_endpoint);
123 ASSERT_EQ(number_of_channels, config.number_of_channels());
126 ska::panda::DataManager<UdpStream> dm(stream);
127 auto endpoint = stream.local_end_point();
132 GeneratorType generator(model, data::DimensionSize<data::Frequency>(config.number_of_channels()), data::DimensionSize<data::Time>(config.samples_per_chunk()));
133 panda::Engine& engine = config.engine();
134 ConnectionType connection(engine);
135 connection.set_remote_end_point(endpoint);
139 , data::DimensionSize<data::Frequency>(config.number_of_channels()));
144 unsigned received_count=0U;
148 std::size_t packet_tot = delta;
149 auto chunk_size = traits.
chunk_size(data_ref);
150 unsigned packet_count = 0U;
154 while(packet_tot < 2 * chunk_size )
157 connection.send(generator.next(), [&](ska::panda::Error e){
164 delta = packet_tot - chunk_size;
165 PANDA_LOG <<
"sent " << packet_count <<
" packets";
167 unsigned max_attempts=1000;
168 while(received_count < packet_count) {
170 if(--max_attempts == 0) FAIL() <<
"time out: expected packets not received";
173 auto data_out_ptr = std::get<0>(dm.next());
174 auto const& data_out = *data_out_ptr;
175 ASSERT_NE(
nullptr, &*data_out.begin());
178 auto model_data = model.sent_data();
179 auto sent_it = model_data.cbegin();
180 auto it = data_out.cbegin();
184 unsigned packet_num=0;
186 if(*sent_it != *it) {
189 PANDA_LOG_ERROR <<
"did not match packet " << packet_num <<
"\n" 190 <<
"got " << (int)*it <<
" sent:" << (
int)*sent_it <<
" at position " << count
191 <<
"\n\tpacket samples (" << Packet::number_of_samples() <<
")\n" 192 <<
"\tmodel data size(" << model_data.data_size() <<
")\n" 193 << write_data(model_data) <<
"\n" 194 <<
"\tactual size=" << data_out.data_size()<<
"( " << &data_out <<
")\n" 195 << write_data(data_out);
198 for(
unsigned i=count; i < Packet::number_of_samples(); ++i)
200 if(++sent_it == model_data.end())
202 ASSERT_TRUE(model.has_sent_data()) <<
"unable to match data to any packets sent after checking " << packet_num <<
" packets." <<
" i=" << i;
203 model_data=model.sent_data();
204 sent_it=model_data.cbegin();
208 it = data_out.cbegin();
212 if(++it == data_out.cend())
break;
214 if(++sent_it == model_data.end())
216 ASSERT_TRUE(model.has_sent_data()) <<
"unable to match data to any packets sent after checking " << packet_num <<
" packets.";
217 model_data=model.sent_data();
218 sent_it=model_data.cbegin();
224 TEST_F(
UdpStreamTest, test_udp_packets_stream_data_consistency_channels_size_equal_packet_size)
227 test_udp_packets_stream_data_consistency<Packet>(Packet::number_of_samples());
230 TEST_F(
UdpStreamTest, test_udp_packets_stream_data_consistency_channels_size_greater_packet_size)
233 test_udp_packets_stream_data_consistency<Packet>(Packet::number_of_samples() + 1);
236 TEST_F(
UdpStreamTest, test_udp_packets_stream_data_consistency_channels_size_less_packet_size)
239 test_udp_packets_stream_data_consistency<Packet>(Packet::number_of_samples() - 1);
Packs data into a UDP stream Packet Header format of the BeamFormer.
unsigned samples_per_chunk() const
return the number of time samples in a chunk
Some limits and constants for FLDO.
uint8_t DataType
the underlying data storage type for the amplitude of the signal
configurable parameters for the rcpt