aboutsummaryrefslogtreecommitdiffstats
path: root/host/tests/sph_send_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'host/tests/sph_send_test.cpp')
-rw-r--r--host/tests/sph_send_test.cpp93
1 files changed, 25 insertions, 68 deletions
diff --git a/host/tests/sph_send_test.cpp b/host/tests/sph_send_test.cpp
index 99f23a374..2db80c8de 100644
--- a/host/tests/sph_send_test.cpp
+++ b/host/tests/sph_send_test.cpp
@@ -7,71 +7,18 @@
#include <boost/test/unit_test.hpp>
#include "../lib/transport/super_send_packet_handler.hpp"
+#include "../common/mock_zero_copy.hpp"
#include <boost/shared_array.hpp>
#include <boost/bind.hpp>
#include <complex>
#include <vector>
#include <list>
+using namespace uhd::transport;
+
#define BOOST_CHECK_TS_CLOSE(a, b) \
BOOST_CHECK_CLOSE((a).get_real_secs(), (b).get_real_secs(), 0.001)
-/***********************************************************************
- * A dummy managed send buffer for testing
- **********************************************************************/
-class dummy_msb : public uhd::transport::managed_send_buffer{
-public:
- void release(void){
- //NOP
- }
-
- sptr get_new(boost::shared_array<char> mem, size_t *len){
- _mem = mem;
- return make(this, mem.get(), *len);
- }
-
-private:
- boost::shared_array<char> _mem;
-};
-
-/***********************************************************************
- * A dummy transport class to fill with fake data
- **********************************************************************/
-class dummy_send_xport_class{
-public:
- dummy_send_xport_class(const std::string &end){
- _end = end;
- }
-
- void pop_front_packet(
- uhd::transport::vrt::if_packet_info_t &ifpi
- ){
- ifpi.num_packet_words32 = _lens.front()/sizeof(uint32_t);
- if (_end == "big"){
- uhd::transport::vrt::if_hdr_unpack_be(reinterpret_cast<uint32_t *>(_mems.front().get()), ifpi);
- }
- if (_end == "little"){
- uhd::transport::vrt::if_hdr_unpack_le(reinterpret_cast<uint32_t *>(_mems.front().get()), ifpi);
- }
- _mems.pop_front();
- _lens.pop_front();
- }
-
- uhd::transport::managed_send_buffer::sptr get_send_buff(double){
- _msbs.push_back(boost::shared_ptr<dummy_msb>(new dummy_msb()));
- _mems.push_back(boost::shared_array<char>(new char[1000]));
- _lens.push_back(1000);
- uhd::transport::managed_send_buffer::sptr mrb = _msbs.back()->get_new(_mems.back(), &_lens.back());
- return mrb;
- }
-
-private:
- std::list<boost::shared_array<char> > _mems;
- std::list<size_t> _lens;
- std::vector<boost::shared_ptr<dummy_msb> > _msbs;
- std::string _end;
-};
-
////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE(test_sph_send_one_channel_one_packet_mode){
////////////////////////////////////////////////////////////////////////
@@ -81,18 +28,23 @@ BOOST_AUTO_TEST_CASE(test_sph_send_one_channel_one_packet_mode){
id.output_format = "sc16_item32_be";
id.num_outputs = 1;
- dummy_send_xport_class dummy_send_xport("big");
+ mock_zero_copy xport(vrt::if_packet_info_t::LINK_TYPE_VRLP);
static const double TICK_RATE = 100e6;
static const double SAMP_RATE = 10e6;
static const size_t NUM_PKTS_TO_TEST = 30;
//create the super send packet handler
- uhd::transport::sph::send_packet_handler handler(1);
- handler.set_vrt_packer(&uhd::transport::vrt::if_hdr_pack_be);
+ sph::send_packet_handler handler(1);
+ handler.set_vrt_packer(&vrt::if_hdr_pack_be);
handler.set_tick_rate(TICK_RATE);
handler.set_samp_rate(SAMP_RATE);
- handler.set_xport_chan_get_buff(0, boost::bind(&dummy_send_xport_class::get_send_buff, &dummy_send_xport, _1));
+ handler.set_xport_chan_get_buff(
+ 0,
+ [&xport](double timeout) {
+ return xport.get_send_buff(timeout);
+ }
+ );
handler.set_converter(id);
handler.set_max_samples_per_packet(20);
@@ -115,10 +67,10 @@ BOOST_AUTO_TEST_CASE(test_sph_send_one_channel_one_packet_mode){
//check the sent packets
size_t num_accum_samps = 0;
- uhd::transport::vrt::if_packet_info_t ifpi;
+ vrt::if_packet_info_t ifpi;
for (size_t i = 0; i < NUM_PKTS_TO_TEST; i++){
std::cout << "data check " << i << std::endl;
- dummy_send_xport.pop_front_packet(ifpi);
+ xport.pop_send_packet(ifpi);
BOOST_CHECK_EQUAL(ifpi.num_payload_words32, 10+i%10);
BOOST_CHECK(ifpi.has_tsf);
BOOST_CHECK_EQUAL(ifpi.tsf, num_accum_samps*TICK_RATE/SAMP_RATE);
@@ -137,18 +89,23 @@ BOOST_AUTO_TEST_CASE(test_sph_send_one_channel_full_buffer_mode){
id.output_format = "sc16_item32_be";
id.num_outputs = 1;
- dummy_send_xport_class dummy_send_xport("big");
+ mock_zero_copy xport(vrt::if_packet_info_t::LINK_TYPE_VRLP);
static const double TICK_RATE = 100e6;
static const double SAMP_RATE = 10e6;
static const size_t NUM_PKTS_TO_TEST = 30;
//create the super send packet handler
- uhd::transport::sph::send_packet_handler handler(1);
- handler.set_vrt_packer(&uhd::transport::vrt::if_hdr_pack_be);
+ sph::send_packet_handler handler(1);
+ handler.set_vrt_packer(&vrt::if_hdr_pack_be);
handler.set_tick_rate(TICK_RATE);
handler.set_samp_rate(SAMP_RATE);
- handler.set_xport_chan_get_buff(0, boost::bind(&dummy_send_xport_class::get_send_buff, &dummy_send_xport, _1));
+ handler.set_xport_chan_get_buff(
+ 0,
+ [&xport](double timeout) {
+ return xport.get_send_buff(timeout);
+ }
+ );
handler.set_converter(id);
handler.set_max_samples_per_packet(20);
@@ -168,10 +125,10 @@ BOOST_AUTO_TEST_CASE(test_sph_send_one_channel_full_buffer_mode){
//check the sent packets
size_t num_accum_samps = 0;
- uhd::transport::vrt::if_packet_info_t ifpi;
+ vrt::if_packet_info_t ifpi;
for (size_t i = 0; i < NUM_PKTS_TO_TEST; i++){
std::cout << "data check " << i << std::endl;
- dummy_send_xport.pop_front_packet(ifpi);
+ xport.pop_send_packet(ifpi);
BOOST_CHECK_EQUAL(ifpi.num_payload_words32, 20UL);
BOOST_CHECK(ifpi.has_tsf);
BOOST_CHECK_EQUAL(ifpi.tsf, num_accum_samps*TICK_RATE/SAMP_RATE);