root / host / tests / vrt_test.cpp @ 95b966a5
History | View | Annotate | Download (5.21 KB)
| 1 |
//
|
|---|---|
| 2 |
// Copyright 2010-2011 Ettus Research LLC
|
| 3 |
//
|
| 4 |
// This program is free software: you can redistribute it and/or modify
|
| 5 |
// it under the terms of the GNU General Public License as published by
|
| 6 |
// the Free Software Foundation, either version 3 of the License, or
|
| 7 |
// (at your option) any later version.
|
| 8 |
//
|
| 9 |
// This program is distributed in the hope that it will be useful,
|
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
// GNU General Public License for more details.
|
| 13 |
//
|
| 14 |
// You should have received a copy of the GNU General Public License
|
| 15 |
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 16 |
//
|
| 17 |
|
| 18 |
#include <boost/test/unit_test.hpp> |
| 19 |
#include <uhd/transport/vrt_if_packet.hpp> |
| 20 |
#include <cstdlib> |
| 21 |
|
| 22 |
using namespace uhd::transport; |
| 23 |
|
| 24 |
static void pack_and_unpack( |
| 25 |
vrt::if_packet_info_t &if_packet_info_in |
| 26 |
){
|
| 27 |
boost::uint32_t header_buff[vrt::max_if_hdr_words32]; |
| 28 |
|
| 29 |
//pack metadata into a vrt header
|
| 30 |
vrt::if_hdr_pack_be( |
| 31 |
header_buff, if_packet_info_in |
| 32 |
); |
| 33 |
|
| 34 |
vrt::if_packet_info_t if_packet_info_out; |
| 35 |
if_packet_info_out.num_packet_words32 = if_packet_info_in.num_packet_words32; |
| 36 |
|
| 37 |
//unpack the vrt header back into metadata
|
| 38 |
vrt::if_hdr_unpack_be( |
| 39 |
header_buff, if_packet_info_out |
| 40 |
); |
| 41 |
|
| 42 |
//check the the unpacked metadata is the same
|
| 43 |
BOOST_CHECK_EQUAL(if_packet_info_in.packet_count, if_packet_info_out.packet_count); |
| 44 |
BOOST_CHECK_EQUAL(if_packet_info_in.num_header_words32, if_packet_info_out.num_header_words32); |
| 45 |
BOOST_CHECK_EQUAL(if_packet_info_in.num_payload_words32, if_packet_info_out.num_payload_words32); |
| 46 |
BOOST_CHECK_EQUAL(if_packet_info_in.has_sid, if_packet_info_out.has_sid); |
| 47 |
if (if_packet_info_in.has_sid and if_packet_info_out.has_sid){ |
| 48 |
BOOST_CHECK_EQUAL(if_packet_info_in.sid, if_packet_info_out.sid); |
| 49 |
} |
| 50 |
BOOST_CHECK_EQUAL(if_packet_info_in.has_cid, if_packet_info_out.has_cid); |
| 51 |
if (if_packet_info_in.has_cid and if_packet_info_out.has_cid){ |
| 52 |
BOOST_CHECK_EQUAL(if_packet_info_in.cid, if_packet_info_out.cid); |
| 53 |
} |
| 54 |
BOOST_CHECK_EQUAL(if_packet_info_in.has_tsi, if_packet_info_out.has_tsi); |
| 55 |
if (if_packet_info_in.has_tsi and if_packet_info_out.has_tsi){ |
| 56 |
BOOST_CHECK_EQUAL(if_packet_info_in.tsi, if_packet_info_out.tsi); |
| 57 |
} |
| 58 |
BOOST_CHECK_EQUAL(if_packet_info_in.has_tsf, if_packet_info_out.has_tsf); |
| 59 |
if (if_packet_info_in.has_tsf and if_packet_info_out.has_tsf){ |
| 60 |
BOOST_CHECK_EQUAL(if_packet_info_in.tsf, if_packet_info_out.tsf); |
| 61 |
} |
| 62 |
BOOST_CHECK_EQUAL(if_packet_info_in.has_tlr, if_packet_info_out.has_tlr); |
| 63 |
if (if_packet_info_in.has_tlr and if_packet_info_out.has_tlr){ |
| 64 |
BOOST_CHECK_EQUAL(if_packet_info_in.tlr, if_packet_info_out.tlr); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
/***********************************************************************
|
| 69 |
* Loopback test the vrt packer/unpacker with various packet info combos
|
| 70 |
* The trailer is not tested as it is not convenient to do so.
|
| 71 |
**********************************************************************/
|
| 72 |
|
| 73 |
BOOST_AUTO_TEST_CASE(test_with_none){
|
| 74 |
vrt::if_packet_info_t if_packet_info; |
| 75 |
if_packet_info.packet_count = 0;
|
| 76 |
if_packet_info.has_sid = false;
|
| 77 |
if_packet_info.has_cid = false;
|
| 78 |
if_packet_info.has_tsi = false;
|
| 79 |
if_packet_info.has_tsf = false;
|
| 80 |
if_packet_info.has_tlr = false;
|
| 81 |
if_packet_info.num_payload_words32 = 0;
|
| 82 |
pack_and_unpack(if_packet_info); |
| 83 |
} |
| 84 |
|
| 85 |
BOOST_AUTO_TEST_CASE(test_with_sid){
|
| 86 |
vrt::if_packet_info_t if_packet_info; |
| 87 |
if_packet_info.packet_count = 1;
|
| 88 |
if_packet_info.has_sid = true;
|
| 89 |
if_packet_info.has_cid = false;
|
| 90 |
if_packet_info.has_tsi = false;
|
| 91 |
if_packet_info.has_tsf = false;
|
| 92 |
if_packet_info.has_tlr = false;
|
| 93 |
if_packet_info.sid = std::rand(); |
| 94 |
if_packet_info.num_payload_words32 = 1111;
|
| 95 |
pack_and_unpack(if_packet_info); |
| 96 |
} |
| 97 |
|
| 98 |
static const bool cid_enb = false; |
| 99 |
|
| 100 |
BOOST_AUTO_TEST_CASE(test_with_cid){
|
| 101 |
vrt::if_packet_info_t if_packet_info; |
| 102 |
if_packet_info.packet_count = 2;
|
| 103 |
if_packet_info.has_sid = false;
|
| 104 |
if_packet_info.has_cid = cid_enb; |
| 105 |
if_packet_info.has_tsi = false;
|
| 106 |
if_packet_info.has_tsf = false;
|
| 107 |
if_packet_info.has_tlr = false;
|
| 108 |
if_packet_info.cid = std::rand(); |
| 109 |
if_packet_info.num_payload_words32 = 2222;
|
| 110 |
pack_and_unpack(if_packet_info); |
| 111 |
} |
| 112 |
|
| 113 |
BOOST_AUTO_TEST_CASE(test_with_time){
|
| 114 |
vrt::if_packet_info_t if_packet_info; |
| 115 |
if_packet_info.packet_count = 3;
|
| 116 |
if_packet_info.has_sid = false;
|
| 117 |
if_packet_info.has_cid = false;
|
| 118 |
if_packet_info.has_tsi = true;
|
| 119 |
if_packet_info.has_tsf = true;
|
| 120 |
if_packet_info.has_tlr = false;
|
| 121 |
if_packet_info.tsi = std::rand(); |
| 122 |
if_packet_info.tsf = std::rand(); |
| 123 |
if_packet_info.num_payload_words32 = 33333;
|
| 124 |
pack_and_unpack(if_packet_info); |
| 125 |
} |
| 126 |
|
| 127 |
BOOST_AUTO_TEST_CASE(test_with_all){
|
| 128 |
vrt::if_packet_info_t if_packet_info; |
| 129 |
if_packet_info.packet_count = 4;
|
| 130 |
if_packet_info.has_sid = true;
|
| 131 |
if_packet_info.has_cid = cid_enb; |
| 132 |
if_packet_info.has_tsi = true;
|
| 133 |
if_packet_info.has_tsf = true;
|
| 134 |
if_packet_info.has_tlr = false;
|
| 135 |
if_packet_info.sid = std::rand(); |
| 136 |
if_packet_info.cid = std::rand(); |
| 137 |
if_packet_info.tsi = std::rand(); |
| 138 |
if_packet_info.tsf = std::rand(); |
| 139 |
if_packet_info.num_payload_words32 = 44444;
|
| 140 |
pack_and_unpack(if_packet_info); |
| 141 |
} |