diff options
Diffstat (limited to 'host/tests')
-rw-r--r-- | host/tests/CMakeLists.txt | 10 | ||||
-rw-r--r-- | host/tests/rfnoc_blocks_test.cpp | 73 | ||||
-rw-r--r-- | host/tests/rfnoc_graph_mock_nodes.hpp | 61 |
3 files changed, 135 insertions, 9 deletions
diff --git a/host/tests/CMakeLists.txt b/host/tests/CMakeLists.txt index 1cdb42b96..0df2d810c 100644 --- a/host/tests/CMakeLists.txt +++ b/host/tests/CMakeLists.txt @@ -245,17 +245,25 @@ UHD_ADD_NONAPI_TEST( ${CMAKE_SOURCE_DIR}/lib/rfnoc/client_zero.cpp ) +set_source_files_properties( + ${CMAKE_SOURCE_DIR}/lib/utils/system_time.cpp + PROPERTIES COMPILE_DEFINITIONS + "HAVE_MICROSEC_CLOCK" +) UHD_ADD_NONAPI_TEST( TARGET rfnoc_blocks_test.cpp EXTRA_SOURCES ${CMAKE_SOURCE_DIR}/lib/rfnoc/noc_block_base.cpp ${CMAKE_SOURCE_DIR}/lib/rfnoc/block_id.cpp ${CMAKE_SOURCE_DIR}/lib/utils/compat_check.cpp + ${CMAKE_SOURCE_DIR}/lib/utils/system_time.cpp ${CMAKE_SOURCE_DIR}/lib/rfnoc/ddc_block_control.cpp ${CMAKE_SOURCE_DIR}/lib/rfnoc/null_block_control.cpp - ${CMAKE_SOURCE_DIR}/lib/rfnoc/radio_control_impl.cpp ${CMAKE_SOURCE_DIR}/lib/rfnoc/register_iface_holder.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/cores/dsp_core_utils.cpp + ${CMAKE_SOURCE_DIR}/lib/rfnoc/graph.cpp + INCLUDE_DIRS + ${CMAKE_BINARY_DIR}/lib/ic_reg_maps/ ) UHD_ADD_NONAPI_TEST( diff --git a/host/tests/rfnoc_blocks_test.cpp b/host/tests/rfnoc_blocks_test.cpp index 13fc15848..ca82ee305 100644 --- a/host/tests/rfnoc_blocks_test.cpp +++ b/host/tests/rfnoc_blocks_test.cpp @@ -5,12 +5,14 @@ // #include "rfnoc_mock_reg_iface.hpp" -#include <uhd/rfnoc/null_block_control.hpp> -#include <uhd/rfnoc/ddc_block_control.hpp> +#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/null_block_control.hpp> #include <uhdlib/rfnoc/clock_iface.hpp> #include <uhdlib/rfnoc/node_accessor.hpp> -#include <uhdlib/rfnoc/clock_iface.hpp> +#include <uhdlib/rfnoc/graph.hpp> #include <uhdlib/utils/narrow.hpp> #include <boost/test/unit_test.hpp> #include <iostream> @@ -22,7 +24,9 @@ namespace { noc_block_base::make_args_ptr make_make_args(noc_block_base::noc_id_t noc_id, const std::string& block_id, const size_t n_inputs, - const size_t n_outputs) + const size_t n_outputs, + const std::string& tb_clock_name = CLOCK_KEY_GRAPH, + const std::string& cp_clock_name = "MOCK_CLOCK") { auto make_args = std::make_unique<noc_block_base::make_args_t>(); make_args->noc_id = noc_id; @@ -30,8 +34,8 @@ noc_block_base::make_args_ptr make_make_args(noc_block_base::noc_id_t noc_id, make_args->num_output_ports = n_outputs; make_args->reg_iface = std::make_shared<mock_reg_iface_t>(); make_args->block_id = block_id; - make_args->ctrlport_clk_iface = std::make_shared<clock_iface>("MOCK_CLOCK"); - make_args->tb_clk_iface = std::make_shared<clock_iface>("MOCK_CLOCK"); + make_args->ctrlport_clk_iface = std::make_shared<clock_iface>(cp_clock_name); + make_args->tb_clk_iface = std::make_shared<clock_iface>(tb_clock_name); make_args->tree = uhd::property_tree::make(); return make_args; } @@ -141,6 +145,7 @@ BOOST_AUTO_TEST_CASE(test_ddc_block) constexpr uint32_t max_cic = 128; constexpr size_t num_chans = 4; constexpr noc_block_base::noc_id_t mock_noc_id = 0x7E57DDC0; + constexpr int TEST_DECIM = 20; auto ddc_make_args = make_make_args(mock_noc_id, "0/DDC#0", num_chans, num_chans); ddc_make_args->args = uhd::device_addr_t("foo=bar"); @@ -154,10 +159,62 @@ BOOST_AUTO_TEST_CASE(test_ddc_block) node_accessor.init_props(test_ddc.get()); UHD_LOG_DEBUG("TEST", "Init done."); - test_ddc->set_property<int>("decim", 4, 0); + 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 | 1); + ddc_reg_iface->write_memory.at(ddc_block_control::SR_DECIM_ADDR), 2 << 8 | 5); + + // 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}); + + 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); + graph.commit(); + // 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); } diff --git a/host/tests/rfnoc_graph_mock_nodes.hpp b/host/tests/rfnoc_graph_mock_nodes.hpp index 2137e3336..63e8bc534 100644 --- a/host/tests/rfnoc_graph_mock_nodes.hpp +++ b/host/tests/rfnoc_graph_mock_nodes.hpp @@ -10,6 +10,7 @@ #include <uhd/rfnoc/defaults.hpp> #include <uhd/rfnoc/node.hpp> #include <uhd/types/stream_cmd.hpp> +#include <uhdlib/rfnoc/node_accessor.hpp> using namespace uhd::rfnoc; @@ -350,4 +351,64 @@ private: const size_t _num_ports; }; +/*! Terminator: Probe edge properties + */ +class mock_terminator_t : public node_t +{ +public: + static size_t counter; + + mock_terminator_t(const size_t num_ports) + : _num_ports(num_ports), _term_count(counter++) + { + set_prop_forwarding_policy(forwarding_policy_t::DROP); + set_action_forwarding_policy(forwarding_policy_t::DROP); + } + + std::string get_unique_id() const + { + return "MOCK_TERMINATOR" + std::to_string(_term_count); + } + + size_t get_num_input_ports() const + { + return _num_ports; + } + + size_t get_num_output_ports() const + { + return _num_ports; + } + + template <typename data_t> + void set_edge_property(const std::string& id, data_t val, res_source_info edge_info) + { + UHD_ASSERT_THROW(edge_info.type == res_source_info::INPUT_EDGE + || edge_info.type == res_source_info::OUTPUT_EDGE); + try { + set_property<data_t>(id, val, edge_info); + } catch (const uhd::lookup_error&) { + node_accessor_t node_accessor{}; + auto edge_info_inverted = edge_info; + edge_info_inverted.type = res_source_info::invert_edge(edge_info.type); + property_t<data_t> new_prop(id, val, edge_info_inverted); + node_accessor.forward_edge_property(this, edge_info.instance, &new_prop); + set_property<data_t>(id, val, edge_info); + } + } + + template <typename data_t> + data_t get_edge_property(const std::string& id, res_source_info edge_info) + { + UHD_ASSERT_THROW(edge_info.type == res_source_info::INPUT_EDGE + || edge_info.type == res_source_info::OUTPUT_EDGE); + return get_property<data_t>(id, edge_info); + } + +private: + const size_t _num_ports; + const size_t _term_count; +}; +size_t mock_terminator_t::counter = 0; + #endif /* INCLUDED_LIBUHD_TESTS_MOCK_NODES_HPP */ |