From 4c47653b32b419e5a89e3c222f8baa7dbdf6bc05 Mon Sep 17 00:00:00 2001 From: mattprost Date: Fri, 28 Feb 2020 10:55:43 -0600 Subject: tests: Add unit test for Moving Average RFNoC block Signed-off-by: mattprost --- .../moving_average_block_test.cpp | 107 +++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 host/tests/rfnoc_block_tests/moving_average_block_test.cpp (limited to 'host/tests/rfnoc_block_tests') diff --git a/host/tests/rfnoc_block_tests/moving_average_block_test.cpp b/host/tests/rfnoc_block_tests/moving_average_block_test.cpp new file mode 100644 index 000000000..9957dcbc1 --- /dev/null +++ b/host/tests/rfnoc_block_tests/moving_average_block_test.cpp @@ -0,0 +1,107 @@ +// +// Copyright 2020 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#include "../rfnoc_graph_mock_nodes.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace uhd::rfnoc; + +// Redeclare this here, since it's only defined outside of UHD_API +noc_block_base::make_args_t::~make_args_t() = default; + +namespace { + +constexpr size_t DEFAULT_MTU = 8000; + +} // namespace + +BOOST_AUTO_TEST_CASE(test_moving_average_block) +{ + node_accessor_t node_accessor{}; + constexpr size_t num_chans = 1; + constexpr noc_id_t noc_id = MOVING_AVERAGE_BLOCK; + + auto block_container = get_mock_block(noc_id, num_chans, num_chans); + auto& moving_average_reg_iface = block_container.reg_iface; + + auto test_moving_average = block_container.get_block(); + BOOST_REQUIRE(test_moving_average); + + node_accessor.init_props(test_moving_average.get()); + UHD_LOG_DEBUG("TEST", "Init done."); + + // Ensure the hardware was programmed correctly with defaults when the + // block was constructed. + BOOST_CHECK_EQUAL(moving_average_reg_iface->write_memory.at( + moving_average_block_control::REG_SUM_LEN_ADDR), + 10); + BOOST_CHECK_EQUAL(moving_average_reg_iface->write_memory.at( + moving_average_block_control::REG_DIVISOR_ADDR), + 10); + + // Now plop it in a graph + detail::graph_t graph{}; + detail::graph_t::graph_edge_t edge_info; + edge_info.src_port = 0; + edge_info.dst_port = 0; + edge_info.property_propagation_active = true; + edge_info.edge = detail::graph_t::graph_edge_t::DYNAMIC; + + mock_terminator_t mock_source_term(1); + mock_terminator_t mock_sink_term(1); + + // Set up the intial edge properties for the source. + constexpr double sample_rate = 1e6; + constexpr size_t mtu = 4000; + UHD_LOG_INFO("TEST", "Priming mock source node props"); + mock_source_term.set_edge_property( + "type", "sc16", {res_source_info::OUTPUT_EDGE, 0}); + mock_source_term.set_edge_property( + "scaling", 1.0, {res_source_info::OUTPUT_EDGE, 0}); + mock_source_term.set_edge_property( + "samp_rate", sample_rate, {res_source_info::OUTPUT_EDGE, 0}); + mock_source_term.set_edge_property( + "mtu", mtu, {res_source_info::OUTPUT_EDGE, 0}); + + UHD_LOG_INFO("TEST", "Creating graph..."); + graph.connect(&mock_source_term, test_moving_average.get(), edge_info); + graph.connect(test_moving_average.get(), &mock_sink_term, edge_info); + UHD_LOG_INFO("TEST", "Committing graph..."); + graph.commit(); + UHD_LOG_INFO("TEST", "Commit complete."); + + // Change the sum length via the API, and ensure that the hardware is + // programmed arppropriately with the expected value. + UHD_LOG_INFO("TEST", "Testing sum length API..."); + BOOST_REQUIRE_THROW(test_moving_average->set_sum_len(0), uhd::value_error); + constexpr uint8_t new_sum_len = 255; + test_moving_average->set_sum_len(new_sum_len); + BOOST_CHECK_EQUAL(moving_average_reg_iface->write_memory.at( + moving_average_block_control::REG_SUM_LEN_ADDR), + new_sum_len); + BOOST_CHECK_EQUAL(test_moving_average->get_sum_len(), new_sum_len); + + // Change the divisor via the API, and ensure that the hardware is + // programmed arppropriately with the expected value. + UHD_LOG_INFO("TEST", "Testing divisor API..."); + BOOST_REQUIRE_THROW(test_moving_average->set_divisor(0), uhd::value_error); + BOOST_REQUIRE_THROW(test_moving_average->set_divisor(1 << 24), uhd::value_error); + constexpr uint32_t new_divisor = (1 << 24) - 1; + test_moving_average->set_divisor(new_divisor); + BOOST_CHECK_EQUAL(moving_average_reg_iface->write_memory.at( + moving_average_block_control::REG_DIVISOR_ADDR), + new_divisor); + BOOST_CHECK_EQUAL(test_moving_average->get_divisor(), new_divisor); +} -- cgit v1.2.3