From 44f9bca2c5b561fa3f5f08d0d616c91d2142cbf9 Mon Sep 17 00:00:00 2001 From: Trung Tran Date: Mon, 18 Feb 2019 17:00:07 -0800 Subject: rfnoc: add new data_chdr packetization. --- host/tests/CMakeLists.txt | 1 + host/tests/rfnoc_chdr_test.cpp | 95 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 host/tests/rfnoc_chdr_test.cpp (limited to 'host/tests') diff --git a/host/tests/CMakeLists.txt b/host/tests/CMakeLists.txt index e476eb61b..e4255196b 100644 --- a/host/tests/CMakeLists.txt +++ b/host/tests/CMakeLists.txt @@ -52,6 +52,7 @@ set(test_sources vrt_test.cpp expert_test.cpp fe_conn_test.cpp + rfnoc_chdr_test.cpp ) set(benchmark_sources diff --git a/host/tests/rfnoc_chdr_test.cpp b/host/tests/rfnoc_chdr_test.cpp new file mode 100644 index 000000000..1fb2df8cf --- /dev/null +++ b/host/tests/rfnoc_chdr_test.cpp @@ -0,0 +1,95 @@ +// +// Copyright 2019 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#include +#include +#include +#include +#include +#include +#include + +using namespace uhd::rfnoc::chdr; + +namespace { + constexpr size_t MAX_BUF_SIZE = 8192; + + // Poorman's send + void send(const void* from, void* to, size_t len) + { + std::memcpy(to, from, len); + } +} + +uint8_t send_packet_buff[MAX_BUF_SIZE]; +uint8_t recv_packet_buff[MAX_BUF_SIZE]; + + +template +void test_loopback(packet_type_t pkt_type, + uint16_t dst_epid, + uint8_t flags, + uint16_t num_md, + size_t num_payload) +{ + // Clear buffers + std::memset(send_packet_buff, 0, MAX_BUF_SIZE); + std::memset(recv_packet_buff, 0, MAX_BUF_SIZE); + + auto send_header = chdr_header(pkt_type); + send_header.set_dst_epid(dst_epid); + send_header.set_flags(flags); + send_header.set_packet_size(num_payload, num_md); + chdr_packet send_chdr_packet(send_header, send_packet_buff); + //chdr_packet<64, uhd::endianness_t::ENDIANNESS_LITTLE> send_chdr_packet(send_header, send_packet_buff); + uint8_t* md_buff = send_chdr_packet.template metadata_ptr_of_type(); + //* start filling in the meta data + for (size_t i = 0; i < send_chdr_packet.get_header().get_num_bytes_metadata(); i++) { + md_buff[i] = i + 1; + } + auto* pay_load = send_chdr_packet.template payload_ptr_of_type(); + //* start filling in the pay load + for (size_t i = 0; i < send_chdr_packet.get_header().get_num_bytes_payload(); i++) { + pay_load[i] = 2 * (i + 1); + } + send(send_packet_buff, recv_packet_buff, MAX_BUF_SIZE); + + const chdr_packet recv_chdr_packet(recv_packet_buff); + BOOST_CHECK_EQUAL((num_md + num_payload + 1 + + (pkt_type == packet_type_t::PACKET_TYPE_DATA_WITH_TS ? 1 : 0)) + * (chdr_w / 8), + recv_chdr_packet.get_header().get_length()); + BOOST_CHECK_EQUAL(flags, recv_chdr_packet.get_header().get_flags()); + BOOST_CHECK_EQUAL(dst_epid, recv_chdr_packet.get_header().get_dst_epid()); + BOOST_CHECK_EQUAL(num_md, recv_chdr_packet.get_header().get_num_metadata()); + BOOST_CHECK_EQUAL(num_payload, recv_chdr_packet.get_header().get_num_words_payload()); + BOOST_CHECK(pkt_type == recv_chdr_packet.get_header().get_pkt_type()); + const auto* out_md_buff = recv_chdr_packet.template metadata_ptr_of_type(); + for (size_t i = 0; i < recv_chdr_packet.get_header().get_num_bytes_metadata(); i++) { + BOOST_CHECK_EQUAL(md_buff[i], out_md_buff[i]); + } + const auto* out_payload = recv_chdr_packet.template payload_ptr_of_type(); + for (size_t i = 0; i < recv_chdr_packet.get_header().get_num_bytes_payload(); i++) { + BOOST_CHECK_EQUAL(pay_load[i], out_payload[i]); + } +} + +BOOST_AUTO_TEST_CASE(simple_read_if_chdr_pkt) +{ + constexpr size_t num_payload = 5; // in words + constexpr packet_type_t pkt_type = packet_type_t::PACKET_TYPE_DATA_NO_TS; + constexpr uint16_t num_md = 0x5A; // 90 + constexpr uint16_t dst_epid = 0xCAFE; + constexpr uint8_t flags = 0x3A; + + test_loopback<64, uhd::endianness_t::ENDIANNESS_LITTLE>(pkt_type, dst_epid, flags, num_md, num_payload); + test_loopback<128, uhd::endianness_t::ENDIANNESS_LITTLE>(pkt_type, dst_epid, flags, num_md, num_payload); + test_loopback<256, uhd::endianness_t::ENDIANNESS_LITTLE>(pkt_type, dst_epid, flags, num_md, num_payload); + + test_loopback<64, uhd::endianness_t::ENDIANNESS_BIG>(pkt_type, dst_epid, flags, num_md, num_payload); + test_loopback<128, uhd::endianness_t::ENDIANNESS_BIG>(pkt_type, dst_epid, flags, num_md, num_payload); + test_loopback<256, uhd::endianness_t::ENDIANNESS_BIG>(pkt_type, dst_epid, flags, num_md, num_payload); +} -- cgit v1.2.3