From 0a49a8844a65698b11fe979441a97939dad80044 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Wed, 27 Nov 2019 21:36:46 -0800 Subject: rfnoc: Create mock factory This is an API that allows creating mock block controllers, to write unit tests for block controllers. See rfnoc_blocks_test for an example how to use them. --- host/lib/rfnoc/CMakeLists.txt | 1 + host/lib/rfnoc/mock_block.cpp | 52 +++++++++++++++++++++++++++++++++++++ host/lib/rfnoc/registry_factory.cpp | 8 +++--- 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 host/lib/rfnoc/mock_block.cpp (limited to 'host/lib') diff --git a/host/lib/rfnoc/CMakeLists.txt b/host/lib/rfnoc/CMakeLists.txt index e685cef26..ea774b2c8 100644 --- a/host/lib/rfnoc/CMakeLists.txt +++ b/host/lib/rfnoc/CMakeLists.txt @@ -38,6 +38,7 @@ LIBUHD_APPEND_SOURCES( ${CMAKE_CURRENT_SOURCE_DIR}/rfnoc_rx_streamer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rfnoc_tx_streamer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tx_async_msg_queue.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/mock_block.cpp # Default block control classes: ${CMAKE_CURRENT_SOURCE_DIR}/block_control.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ddc_block_control.cpp diff --git a/host/lib/rfnoc/mock_block.cpp b/host/lib/rfnoc/mock_block.cpp new file mode 100644 index 000000000..867311097 --- /dev/null +++ b/host/lib/rfnoc/mock_block.cpp @@ -0,0 +1,52 @@ +// +// Copyright 2019 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#include +#include +#include +#include +#include +#include + +using namespace uhd::rfnoc; + +uhd::rfnoc::mock_block_container uhd::rfnoc::get_mock_block(const noc_id_t noc_id, + const size_t num_inputs, + const size_t num_outputs, + const device_addr_t& args, + const size_t mtu, + const device_type_t device_id) +{ + block_factory_info_t fac_info = factory::get_block_factory(noc_id, device_id); + + mock_block_container ret_val; + ret_val.factory = fac_info.factory_fn; + ret_val.reg_iface = std::make_shared(); + ret_val.tree = uhd::property_tree::make(); + // Create make args + ret_val.make_args = std::make_unique(); + ret_val.make_args->noc_id = noc_id; + ret_val.make_args->block_id = block_id_t(fac_info.block_name); + ret_val.make_args->num_input_ports = num_inputs; + ret_val.make_args->num_output_ports = num_outputs; + ret_val.make_args->mtu = mtu; + ret_val.make_args->reg_iface = ret_val.reg_iface; + ret_val.make_args->tree = ret_val.tree; + ret_val.make_args->args = args; + ret_val.make_args->tb_clk_iface = + std::make_shared(fac_info.timebase_clk); + ret_val.make_args->ctrlport_clk_iface = + std::make_shared(fac_info.ctrlport_clk); + // TODO Make a mock mb controller too + ret_val.make_args->mb_control = nullptr; + if (fac_info.mb_access) { + UHD_LOG_WARNING("MOCK", "Mock block controllers cannot have mb_controllers."); + } + + // Make block and return + return ret_val; +} + diff --git a/host/lib/rfnoc/registry_factory.cpp b/host/lib/rfnoc/registry_factory.cpp index bf1bc60a5..b251410bf 100644 --- a/host/lib/rfnoc/registry_factory.cpp +++ b/host/lib/rfnoc/registry_factory.cpp @@ -5,13 +5,14 @@ // #include -#include -#include #include +#include +#include +#include #include #include -#include #include +#include #include #include #include @@ -106,3 +107,4 @@ block_factory_info_t factory::get_block_factory(noc_id_t noc_id, device_type_t d } return get_direct_block_registry().at(key); } + -- cgit v1.2.3