diff options
author | Martin Braun <martin.braun@ettus.com> | 2019-06-03 22:33:52 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2019-11-26 11:49:23 -0800 |
commit | debe5189364b0684500b7ce4cd8f45894a3e54e7 (patch) | |
tree | 6a1d3d263e904afbe58d4dad77744ecf26ea37c8 /host/tests | |
parent | 6460e07f91bc468e7c094785093426ee07e26bcb (diff) | |
download | uhd-debe5189364b0684500b7ce4cd8f45894a3e54e7.tar.gz uhd-debe5189364b0684500b7ce4cd8f45894a3e54e7.tar.bz2 uhd-debe5189364b0684500b7ce4cd8f45894a3e54e7.zip |
rfnoc: Add null block controller
Diffstat (limited to 'host/tests')
-rw-r--r-- | host/tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/tests/rfnoc_blocks_test.cpp | 87 |
2 files changed, 88 insertions, 0 deletions
diff --git a/host/tests/CMakeLists.txt b/host/tests/CMakeLists.txt index 484eeb903..df891b7e2 100644 --- a/host/tests/CMakeLists.txt +++ b/host/tests/CMakeLists.txt @@ -250,6 +250,7 @@ UHD_ADD_NONAPI_TEST( ${CMAKE_SOURCE_DIR}/lib/rfnoc/block_id.cpp ${CMAKE_SOURCE_DIR}/lib/utils/compat_check.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/usrp/cores/dsp_core_utils.cpp ) diff --git a/host/tests/rfnoc_blocks_test.cpp b/host/tests/rfnoc_blocks_test.cpp index 4b393eb36..1832fc6ae 100644 --- a/host/tests/rfnoc_blocks_test.cpp +++ b/host/tests/rfnoc_blocks_test.cpp @@ -5,10 +5,13 @@ // #include "rfnoc_mock_reg_iface.hpp" +#include <uhd/rfnoc/null_block_control.hpp> #include <uhd/rfnoc/ddc_block_control.hpp> +#include <uhd/rfnoc/actions.hpp> #include <uhdlib/rfnoc/clock_iface.hpp> #include <uhdlib/rfnoc/node_accessor.hpp> #include <uhdlib/rfnoc/clock_iface.hpp> +#include <uhdlib/utils/narrow.hpp> #include <boost/test/unit_test.hpp> #include <iostream> @@ -38,8 +41,92 @@ noc_block_base::make_args_ptr make_make_args(noc_block_base::noc_id_t noc_id, uhd::rfnoc::noc_block_base::sptr BLOCK_NAME##_make( \ uhd::rfnoc::noc_block_base::make_args_ptr make_args); +MOCK_REGISTER(null_block_control) MOCK_REGISTER(ddc_block_control) +BOOST_AUTO_TEST_CASE(test_null_block) +{ + node_accessor_t node_accessor{}; + constexpr size_t num_chans = 2; + constexpr uint32_t nipc = 2; + constexpr uint32_t item_width = 32; + constexpr noc_block_base::noc_id_t mock_id = 0x7E570000; + + auto make_args = make_make_args(mock_id, "0/NullSrcSink#0", num_chans, num_chans); + auto reg_iface = std::dynamic_pointer_cast<mock_reg_iface_t>(make_args->reg_iface); + auto set_mem = [&](const uint32_t addr, const uint32_t data) { + reg_iface->read_memory[addr] = data; + }; + auto get_mem = [&](const uint32_t addr) { return reg_iface->write_memory[addr]; }; + auto copy_mem = [&](const uint32_t addr) { set_mem(addr, get_mem(addr)); }; + + set_mem(null_block_control::REG_CTRL_STATUS, (nipc << 24) | (item_width << 16)); + auto test_null = std::dynamic_pointer_cast<null_block_control>( + null_block_control_make(std::move(make_args))); + + using uhd::stream_cmd_t; + node_accessor.init_props(test_null.get()); + uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS); + test_null->issue_stream_cmd(stream_cmd); + stream_cmd.stream_mode = stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE; + BOOST_REQUIRE_THROW(test_null->issue_stream_cmd(stream_cmd), uhd::runtime_error); + + constexpr uint64_t snk_count = 1000000000; + constexpr uint64_t snk_count_pkts = 5; + constexpr uint64_t src_count = 2323232323; + constexpr uint64_t loop_count = 4242424242; + set_mem(null_block_control::REG_SNK_LINE_CNT_LO, + uhd::narrow_cast<uint32_t>(snk_count & 0xFFFFFFFF)); + set_mem(null_block_control::REG_SNK_LINE_CNT_HI, + uhd::narrow_cast<uint32_t>((snk_count >> 32) & 0xFFFFFFFF)); + set_mem(null_block_control::REG_SNK_PKT_CNT_LO, + uhd::narrow_cast<uint32_t>(snk_count_pkts & 0xFFFFFFFF)); + set_mem(null_block_control::REG_SNK_PKT_CNT_HI, + uhd::narrow_cast<uint32_t>((snk_count_pkts >> 32) & 0xFFFFFFFF)); + set_mem(null_block_control::REG_SRC_LINE_CNT_LO, + uhd::narrow_cast<uint32_t>(src_count & 0xFFFFFFFF)); + set_mem(null_block_control::REG_SRC_LINE_CNT_HI, + uhd::narrow_cast<uint32_t>((src_count >> 32) & 0xFFFFFFFF)); + set_mem(null_block_control::REG_LOOP_LINE_CNT_LO, + uhd::narrow_cast<uint32_t>(loop_count & 0xFFFFFFFF)); + set_mem(null_block_control::REG_LOOP_LINE_CNT_HI, + uhd::narrow_cast<uint32_t>((loop_count >> 32) & 0xFFFFFFFF)); + BOOST_CHECK_EQUAL( + test_null->get_count(null_block_control::SINK, null_block_control::LINES), + snk_count); + BOOST_CHECK_EQUAL( + test_null->get_count(null_block_control::SINK, null_block_control::PACKETS), + snk_count_pkts); + BOOST_CHECK_EQUAL( + test_null->get_count(null_block_control::SOURCE, null_block_control::LINES), + src_count); + BOOST_CHECK_EQUAL( + test_null->get_count(null_block_control::LOOP, null_block_control::LINES), + loop_count); + + constexpr uint32_t lpp = 3; + constexpr uint32_t bpp = nipc * item_width / 8 * lpp; + test_null->set_bytes_per_packet(bpp); + copy_mem(null_block_control::REG_SRC_LINES_PER_PKT); + copy_mem(null_block_control::REG_SRC_BYTES_PER_PKT); + BOOST_CHECK_EQUAL(test_null->get_lines_per_packet(), lpp); + BOOST_CHECK_EQUAL(test_null->get_bytes_per_packet(), bpp); + + auto sca = stream_cmd_action_info::make(stream_cmd_t::STREAM_MODE_START_CONTINUOUS); + node_accessor.send_action(test_null.get(), {res_source_info::OUTPUT_EDGE, 0}, sca); + BOOST_CHECK_EQUAL(get_mem(null_block_control::REG_CTRL_STATUS) & 0x2, 0x2); + BOOST_REQUIRE_THROW( + node_accessor.send_action(test_null.get(), {res_source_info::OUTPUT_EDGE, 1}, sca), + uhd::runtime_error); + BOOST_REQUIRE_THROW( + node_accessor.send_action(test_null.get(), {res_source_info::INPUT_EDGE, 0}, sca), + uhd::runtime_error); + + stream_cmd.stream_mode = stream_cmd_t::STREAM_MODE_START_CONTINUOUS; + test_null->issue_stream_cmd(stream_cmd); + BOOST_CHECK_EQUAL(get_mem(null_block_control::REG_CTRL_STATUS) & 0x2, 0x2); +} + BOOST_AUTO_TEST_CASE(test_ddc_block) { node_accessor_t node_accessor{}; |