diff options
author | mattprost <matt.prost@ni.com> | 2020-04-08 17:29:06 -0500 |
---|---|---|
committer | Aaron Rossetto <aaron.rossetto@ni.com> | 2020-04-13 13:44:18 -0500 |
commit | 67918462210cd16c20075c939bdcf06992481a2c (patch) | |
tree | 0814e8191870337cfd916e0c9b49bf7cb2a77978 /host/tests/rfnoc_block_tests/ddc_block_test.cpp | |
parent | a9ce0fdd6a83e2800deaada59985a641fad6e900 (diff) | |
download | uhd-67918462210cd16c20075c939bdcf06992481a2c.tar.gz uhd-67918462210cd16c20075c939bdcf06992481a2c.tar.bz2 uhd-67918462210cd16c20075c939bdcf06992481a2c.zip |
tests: migrated rfnoc block tests to dedicated subdirectory
This separates the rfnoc block tests into files for each specific block.
This was done to improve the readability of these files and declutter
the tests directory.
Signed-off-by: mattprost <matt.prost@ni.com>
Diffstat (limited to 'host/tests/rfnoc_block_tests/ddc_block_test.cpp')
-rw-r--r-- | host/tests/rfnoc_block_tests/ddc_block_test.cpp | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/host/tests/rfnoc_block_tests/ddc_block_test.cpp b/host/tests/rfnoc_block_tests/ddc_block_test.cpp new file mode 100644 index 000000000..d32dd0aec --- /dev/null +++ b/host/tests/rfnoc_block_tests/ddc_block_test.cpp @@ -0,0 +1,131 @@ +// +// Copyright 2020 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#include "../rfnoc_graph_mock_nodes.hpp" +#include <uhd/rfnoc/actions.hpp> +#include <uhd/rfnoc/ddc_block_control.hpp> +#include <uhd/rfnoc/defaults.hpp> +#include <uhd/rfnoc/duc_block_control.hpp> +#include <uhd/rfnoc/mock_block.hpp> +#include <uhd/rfnoc/null_block_control.hpp> +#include <uhdlib/rfnoc/graph.hpp> +#include <uhdlib/rfnoc/node_accessor.hpp> +#include <uhdlib/utils/narrow.hpp> +#include <boost/test/unit_test.hpp> +#include <iostream> + +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_ddc_block) +{ + node_accessor_t node_accessor{}; + constexpr uint32_t num_hb = 2; + constexpr uint32_t max_cic = 128; + constexpr size_t num_chans = 4; + constexpr noc_id_t noc_id = DDC_BLOCK; + constexpr int TEST_DECIM = 20; + + auto block_container = + get_mock_block(noc_id, num_chans, num_chans, uhd::device_addr_t("foo=bar")); + auto& ddc_reg_iface = block_container.reg_iface; + ddc_reg_iface->read_memory[ddc_block_control::RB_COMPAT_NUM] = + (ddc_block_control::MAJOR_COMPAT << 16) | ddc_block_control::MINOR_COMPAT; + ddc_reg_iface->read_memory[ddc_block_control::RB_NUM_HB] = num_hb; + ddc_reg_iface->read_memory[ddc_block_control::RB_CIC_MAX_DECIM] = max_cic; + auto test_ddc = block_container.get_block<ddc_block_control>(); + BOOST_REQUIRE(test_ddc); + BOOST_CHECK_EQUAL(test_ddc->get_block_args().get("foo"), "bar"); + + node_accessor.init_props(test_ddc.get()); + UHD_LOG_DEBUG("TEST", "Init done."); + test_ddc->set_property<int>("decim", TEST_DECIM, 0); + + BOOST_REQUIRE(ddc_reg_iface->write_memory.count(ddc_block_control::SR_DECIM_ADDR)); + BOOST_CHECK_EQUAL( + ddc_reg_iface->write_memory.at(ddc_block_control::SR_DECIM_ADDR), 2 << 8 | 5); + BOOST_CHECK_EQUAL(test_ddc->get_mtu({res_source_info::INPUT_EDGE, 0}), DEFAULT_MTU); + + // 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); + + UHD_LOG_INFO("TEST", "Priming mock source node props"); + mock_source_term.set_edge_property<std::string>( + "type", "sc16", {res_source_info::OUTPUT_EDGE, 0}); + mock_source_term.set_edge_property<double>( + "scaling", 1.0, {res_source_info::OUTPUT_EDGE, 0}); + mock_source_term.set_edge_property<double>( + "samp_rate", 1.0, {res_source_info::OUTPUT_EDGE, 0}); + constexpr size_t NEW_MTU = 4000; + mock_source_term.set_edge_property<size_t>( + "mtu", NEW_MTU, {res_source_info::OUTPUT_EDGE, 0}); + + UHD_LOG_INFO("TEST", "Creating graph..."); + graph.connect(&mock_source_term, test_ddc.get(), edge_info); + graph.connect(test_ddc.get(), &mock_sink_term, edge_info); + UHD_LOG_INFO("TEST", "Committing graph..."); + graph.commit(); + UHD_LOG_INFO("TEST", "Commit complete."); + // We need to set the decimation again, because the rates will screw it + // change it w.r.t. to the previous setting + test_ddc->set_property<int>("decim", TEST_DECIM, 0); + BOOST_CHECK_EQUAL(test_ddc->get_property<int>("decim", 0), TEST_DECIM); + BOOST_CHECK(mock_source_term.get_edge_property<double>( + "samp_rate", {res_source_info::OUTPUT_EDGE, 0}) + == mock_sink_term.get_edge_property<double>( + "samp_rate", {res_source_info::INPUT_EDGE, 0}) + * TEST_DECIM); + BOOST_CHECK(mock_sink_term.get_edge_property<double>( + "scaling", {res_source_info::INPUT_EDGE, 0}) + != 1.0); + + UHD_LOG_INFO("TEST", "Setting freq to 1/8 of input rate"); + constexpr double TEST_FREQ = 1.0 / 8; + test_ddc->set_property<double>("freq", TEST_FREQ, 0); + const uint32_t freq_word_1 = + ddc_reg_iface->write_memory.at(ddc_block_control::SR_FREQ_ADDR); + BOOST_REQUIRE(freq_word_1 != 0); + UHD_LOG_INFO("TEST", "Doubling input rate (to 2.0)"); + // Now this should change the freq word, but not the absolute frequency + mock_source_term.set_edge_property<double>( + "samp_rate", 2.0, {res_source_info::OUTPUT_EDGE, 0}); + const double freq_word_2 = + ddc_reg_iface->write_memory.at(ddc_block_control::SR_FREQ_ADDR); + // The frequency word is the phase increment, which will halve. We skirt + // around fixpoint/floating point accuracy issues by using CLOSE. + BOOST_CHECK_CLOSE(double(freq_word_1) / double(freq_word_2), 2.0, 1e-6); + + UHD_LOG_INFO("TEST", "Testing DDC MTU propagation"); + BOOST_CHECK_EQUAL(test_ddc->get_mtu({res_source_info::INPUT_EDGE, 0}), NEW_MTU); + BOOST_CHECK_EQUAL(test_ddc->get_mtu({res_source_info::OUTPUT_EDGE, 0}), NEW_MTU); + BOOST_CHECK_EQUAL(test_ddc->get_mtu({res_source_info::INPUT_EDGE, 1}), DEFAULT_MTU); + BOOST_CHECK_EQUAL(test_ddc->get_mtu({res_source_info::OUTPUT_EDGE, 1}), DEFAULT_MTU); + mock_source_term.set_edge_property<size_t>( + "mtu", NEW_MTU / 2, {res_source_info::OUTPUT_EDGE, 0}); + BOOST_CHECK_EQUAL(test_ddc->get_mtu({res_source_info::INPUT_EDGE, 0}), NEW_MTU / 2); + BOOST_CHECK_EQUAL(test_ddc->get_mtu({res_source_info::OUTPUT_EDGE, 0}), NEW_MTU / 2); + + // Now reset the props using set_properties + test_ddc->set_properties(uhd::device_addr_t("decim=1,freq=0.0,foo=bar"), 0); + BOOST_CHECK_EQUAL(test_ddc->get_property<int>("decim", 0), 1); + BOOST_CHECK_EQUAL(test_ddc->get_property<double>("freq", 0), 0.0); +} |