diff options
Diffstat (limited to 'host/tests/device3_test.cpp')
-rw-r--r-- | host/tests/device3_test.cpp | 145 |
1 files changed, 88 insertions, 57 deletions
diff --git a/host/tests/device3_test.cpp b/host/tests/device3_test.cpp index eb29d560f..658855f15 100644 --- a/host/tests/device3_test.cpp +++ b/host/tests/device3_test.cpp @@ -5,71 +5,53 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -#include <uhd/property_tree.hpp> -#include <uhd/types/wb_iface.hpp> + +#include "mock_zero_copy.hpp" +#include "mock_ctrl_iface_impl.hpp" #include <uhd/device3.hpp> +#include <uhd/property_tree.hpp> #include <uhd/rfnoc/block_ctrl.hpp> #include <uhd/rfnoc/graph.hpp> -#include <uhd/rfnoc/constants.hpp> -#include <uhdlib/rfnoc/ctrl_iface.hpp> +#include <uhdlib/rfnoc/graph_impl.hpp> +#include <boost/enable_shared_from_this.hpp> +#include <boost/shared_ptr.hpp> #include <boost/test/unit_test.hpp> #include <exception> #include <iostream> + + using namespace uhd; using namespace uhd::rfnoc; +using namespace uhd::transport::vrt; +using uhd::transport::managed_send_buffer; +using uhd::transport::managed_recv_buffer; -static const uint64_t TEST_NOC_ID = 0xAAAABBBBCCCCDDDD; static const sid_t TEST_SID0 = 0x00000200; // 0.0.2.0 static const sid_t TEST_SID1 = 0x00000210; // 0.0.2.F -// Pseudo-wb-iface -class pseudo_ctrl_iface_impl : public ctrl_iface -{ - public: - pseudo_ctrl_iface_impl() {} - virtual ~pseudo_ctrl_iface_impl() {} - - uint64_t send_cmd_pkt( - const size_t addr, - const size_t data, - const bool readback=false, - const uint64_t timestamp=0 - ) { - if (not readback) { - std::cout << str(boost::format("[PSEUDO] poke to addr: %016X, data == %016X") % addr % data) << std::endl; - } else { - std::cout << str(boost::format("[PSEUDO] peek64 to addr: %016X") % data) << std::endl; - switch (data) { - case SR_READBACK_REG_ID: - return TEST_NOC_ID; - case SR_READBACK_REG_FIFOSIZE: - return 0x000000000000000B; - case SR_READBACK_REG_USER: - return 0x0123456789ABCDEF; - case SR_READBACK_COMPAT: - return uhd::rfnoc::NOC_SHELL_COMPAT_MAJOR << 32 | - uhd::rfnoc::NOC_SHELL_COMPAT_MINOR; - default: - return 0; - } - } - return 0; - } -}; +uhd::both_xports_t make_mock_transport(const uhd::sid_t& tx_sid) { + uhd::both_xports_t xports; + xports.send_sid = tx_sid; + xports.recv_sid = tx_sid.reversed(); + xports.send_buff_size = SEND_BUFF_SIZE; + xports.recv_buff_size = RECV_BUFF_SIZE; + xports.send = boost::make_shared<mock_zero_copy>(); + xports.recv = xports.send; + return xports; +} -// Pseudo-device -class pseudo_device3_impl : public uhd::device3 +// Mock-device +class mock_device3_impl : public uhd::device3, public boost::enable_shared_from_this<mock_device3_impl> { public: - pseudo_device3_impl() + mock_device3_impl() { _tree = uhd::property_tree::make(); - _tree->create<std::string>("/name").set("Test Pseudo-Device3"); - + _tree->create<std::string>("/name").set("Test Mock-Device3"); // We can re-use this: std::map<size_t, ctrl_iface::sptr> ctrl_ifaces{ - {0, ctrl_iface::sptr(new pseudo_ctrl_iface_impl())} + {0, ctrl_iface::sptr(new mock_ctrl_iface_impl())} }; // Add two block controls: @@ -78,10 +60,9 @@ class pseudo_device3_impl : public uhd::device3 make_args.base_address = TEST_SID0.get_dst(); make_args.device_index = 0; make_args.tree = _tree; - std::cout << "[PSEUDO] Generating block controls 1/2:" << std::endl; + std::cout << "[MOCK] Generating block controls 1/2:" << std::endl; _rfnoc_block_ctrl.push_back( block_ctrl_base::make(make_args) ); - - std::cout << "[PSEUDO] Generating block controls 2/2:" << std::endl; + std::cout << "[MOCK] Generating block controls 2/2:" << std::endl; make_args.base_address = TEST_SID1.get_dst(); _rfnoc_block_ctrl.push_back( block_ctrl::make(make_args) ); } @@ -98,20 +79,38 @@ class pseudo_device3_impl : public uhd::device3 throw uhd::not_implemented_error(str(boost::format("%d %f") % async_metadata.channel % timeout)); } - rfnoc::graph::sptr create_graph(const std::string &) { return rfnoc::graph::sptr(); } + rfnoc::graph::sptr create_graph(const std::string &name) + { + sid_t async_sid(0); + async_sid.set_dst_addr(2); + auto async_xports = make_mock_transport(async_sid); + + auto async_msg_handler = uhd::rfnoc::async_msg_handler::make( + async_xports.recv, + async_xports.send, + async_xports.send_sid, + async_xports.endianness + ); + auto graph = boost::make_shared<uhd::rfnoc::graph_impl>( + name, + shared_from_this(), + async_msg_handler + ); + return graph; + } }; -device3::sptr make_pseudo_device() +device3::sptr make_mock_device() { - return device3::sptr(new pseudo_device3_impl()); + return device3::sptr(new mock_device3_impl()); } -class dummy_block_ctrl : public block_ctrl { +class mock_block_ctrl : public block_ctrl { int foo; }; BOOST_AUTO_TEST_CASE(test_device3) { - device3::sptr my_device = make_pseudo_device(); + device3::sptr my_device = make_mock_device(); std::cout << "Checking block 0..." << std::endl; BOOST_REQUIRE(my_device->find_blocks("Block").size()); @@ -130,8 +129,40 @@ BOOST_AUTO_TEST_CASE(test_device3) { BOOST_CHECK_EQUAL(block1->get_block_id(), "0/Block_1"); } + +BOOST_AUTO_TEST_CASE(test_device3_graph) { + auto my_device = make_mock_device(); + std::cout << "Start device3 test graph.." << std::endl; + std::cout << "Checking block 0..." << std::endl; + BOOST_REQUIRE(my_device->find_blocks("Block").size()); + std::cout << "Getting block 0..." << std::endl; + auto block0 = my_device->get_block_ctrl(my_device->find_blocks("Block")[0]); + BOOST_REQUIRE(block0); + BOOST_CHECK_EQUAL(block0->get_block_id(), "0/Block_0"); + + std::cout << "Checking block 1..." << std::endl; + BOOST_REQUIRE(my_device->has_block(block_id_t("0/Block_1"))); + + std::cout << "Getting block 1..." << std::endl; + auto block1 = my_device->get_block_ctrl(block_id_t("0/Block_1")); + BOOST_REQUIRE(block1); + BOOST_CHECK_EQUAL(block1->get_block_id(), "0/Block_1"); + std::cout << "Creating graph..." << std::endl; + auto graph = my_device->create_graph("test_graph"); + BOOST_CHECK(graph); + std::cout << "Connecting block_0 to block_1 ..." << std::endl; + graph->connect(block_id_t("0/Block_0"), 0, block_id_t("0/Block_1"), 0); + + BOOST_CHECK_EQUAL(block0->list_upstream_nodes().size(),0); + BOOST_CHECK_EQUAL(block0->list_downstream_nodes().size(),1); + BOOST_CHECK_EQUAL(block0->list_downstream_nodes()[0].lock()->unique_id(),"0/Block_1"); + BOOST_CHECK_EQUAL(block1->list_upstream_nodes().size(),1); + BOOST_CHECK_EQUAL(block1->list_downstream_nodes().size(),0); + BOOST_CHECK_EQUAL(block1->list_upstream_nodes()[0].lock()->unique_id(),"0/Block_0"); +} + BOOST_AUTO_TEST_CASE(test_device3_cast) { - device3::sptr my_device = make_pseudo_device(); + device3::sptr my_device = make_mock_device(); std::cout << "Getting block 0..." << std::endl; block_ctrl::sptr block0 = my_device->get_block_ctrl<block_ctrl>(block_id_t("0/Block_0")); @@ -144,10 +175,10 @@ BOOST_AUTO_TEST_CASE(test_device3_cast) { } BOOST_AUTO_TEST_CASE(test_device3_fail) { - device3::sptr my_device = make_pseudo_device(); + device3::sptr my_device = make_mock_device(); BOOST_CHECK(not my_device->has_block(block_id_t("0/FooBarBlock_0"))); - BOOST_CHECK(not my_device->has_block<dummy_block_ctrl>(block_id_t("0/Block_1"))); + BOOST_CHECK(not my_device->has_block<mock_block_ctrl>(block_id_t("0/Block_1"))); BOOST_CHECK(my_device->find_blocks("FooBarBlock").size() == 0); BOOST_CHECK(my_device->find_blocks<block_ctrl>("FooBarBlock").size() == 0); @@ -157,7 +188,7 @@ BOOST_AUTO_TEST_CASE(test_device3_fail) { uhd::lookup_error ); BOOST_REQUIRE_THROW( - my_device->get_block_ctrl<dummy_block_ctrl>(block_id_t("0/Block_1")), + my_device->get_block_ctrl<mock_block_ctrl>(block_id_t("0/Block_1")), uhd::lookup_error ); } |