diff options
author | Trung Tran <trung.tran@ettus.com> | 2018-10-09 11:22:28 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2018-10-31 12:03:33 -0700 |
commit | 0738580e6ef03f9676632ffc3bc7e8d9fb0bc09f (patch) | |
tree | 2264c2b05f62c3abf75270da5a4765fb3fd161b0 /host/tests/common | |
parent | 77bd36701608551376f33e04ba01d8efa550299c (diff) | |
download | uhd-0738580e6ef03f9676632ffc3bc7e8d9fb0bc09f.tar.gz uhd-0738580e6ef03f9676632ffc3bc7e8d9fb0bc09f.tar.bz2 uhd-0738580e6ef03f9676632ffc3bc7e8d9fb0bc09f.zip |
tests: device3_test: add graph impl test
Diffstat (limited to 'host/tests/common')
-rw-r--r-- | host/tests/common/CMakeLists.txt | 15 | ||||
-rw-r--r-- | host/tests/common/mock_ctrl_iface_impl.cpp | 35 | ||||
-rw-r--r-- | host/tests/common/mock_ctrl_iface_impl.hpp | 30 | ||||
-rw-r--r-- | host/tests/common/mock_zero_copy.cpp | 29 | ||||
-rw-r--r-- | host/tests/common/mock_zero_copy.hpp | 88 |
5 files changed, 197 insertions, 0 deletions
diff --git a/host/tests/common/CMakeLists.txt b/host/tests/common/CMakeLists.txt new file mode 100644 index 000000000..91a70dfae --- /dev/null +++ b/host/tests/common/CMakeLists.txt @@ -0,0 +1,15 @@ +# +# Copyright 2018 Ettus Research, a National Instruments Company +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +######################################################################## +# Build uhd_test static lib +######################################################################## +INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/lib/include") +ADD_LIBRARY(uhd_test ${CMAKE_CURRENT_SOURCE_DIR}/mock_ctrl_iface_impl.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/mock_zero_copy.cpp + ${CMAKE_SOURCE_DIR}/lib/rfnoc/graph_impl.cpp + ${CMAKE_SOURCE_DIR}/lib/rfnoc/async_msg_handler.cpp +)
\ No newline at end of file diff --git a/host/tests/common/mock_ctrl_iface_impl.cpp b/host/tests/common/mock_ctrl_iface_impl.cpp new file mode 100644 index 000000000..24a938e4f --- /dev/null +++ b/host/tests/common/mock_ctrl_iface_impl.cpp @@ -0,0 +1,35 @@ +// +// Copyright 2018 Ettus Research, a National Instruments Company +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#include "mock_ctrl_iface_impl.hpp" +static const uint64_t TEST_NOC_ID = 0xAAAABBBBCCCCDDDD; + +uint64_t mock_ctrl_iface_impl::send_cmd_pkt( + const size_t addr, + const size_t data, + const bool readback, + const uint64_t timestamp +) { + if (not readback) { + std::cout << str(boost::format("[MOCK] poke to addr: %016X, data == %016X") % addr % data) << std::endl; + } else { + std::cout << str(boost::format("[MOCK] peek64 to addr: %016X") % data) << std::endl; + switch (data) { + case uhd::rfnoc::SR_READBACK_REG_ID: + return TEST_NOC_ID; + case uhd::rfnoc::SR_READBACK_REG_FIFOSIZE: + return 0x0000000000010000; + case uhd::rfnoc::SR_READBACK_REG_USER: + return 0x0123456789ABCDEF; + case uhd::rfnoc::SR_READBACK_COMPAT: + return uhd::rfnoc::NOC_SHELL_COMPAT_MAJOR << 32 | + uhd::rfnoc::NOC_SHELL_COMPAT_MINOR; + default: + return 0; + } + } + return 0; +}
\ No newline at end of file diff --git a/host/tests/common/mock_ctrl_iface_impl.hpp b/host/tests/common/mock_ctrl_iface_impl.hpp new file mode 100644 index 000000000..8d2aafed6 --- /dev/null +++ b/host/tests/common/mock_ctrl_iface_impl.hpp @@ -0,0 +1,30 @@ +// +// Copyright 2018 Ettus Research, a National Instruments Company +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + + +#ifndef INCLUDED_MOCK_CTRL_IFACE_IMPL_HPP +#define INCLUDED_MOCK_CTRL_IFACE_IMPL_HPP + +#include <uhd/rfnoc/constants.hpp> +#include <uhdlib/rfnoc/ctrl_iface.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> +#include <boost/format.hpp> +#include <boost/bind.hpp> +#include <boost/make_shared.hpp> +#include <queue> + +class mock_ctrl_iface_impl : public uhd::rfnoc::ctrl_iface +{ + + uint64_t send_cmd_pkt( + const size_t addr, + const size_t data, + const bool readback=false, + const uint64_t timestamp=0 + ); +}; +#endif /* INCLUDED_MOCK_CTRL_IFACE_IMPL_HPP */
\ No newline at end of file diff --git a/host/tests/common/mock_zero_copy.cpp b/host/tests/common/mock_zero_copy.cpp new file mode 100644 index 000000000..b1d384ec7 --- /dev/null +++ b/host/tests/common/mock_zero_copy.cpp @@ -0,0 +1,29 @@ +// +// Copyright 2018 Ettus Research, a National Instruments Company +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + + +#include "mock_zero_copy.hpp" +#include <boost/shared_ptr.hpp> + +uhd::transport::managed_recv_buffer::sptr mock_zero_copy::get_recv_buff(double) { + if (_rx_mems.empty()) { + return uhd::transport::managed_recv_buffer::sptr(); // timeout + } + _mrbs.push_back(boost::make_shared<mock_mrb>()); + uhd::transport::managed_recv_buffer::sptr mrb = + _mrbs.back()->get_new(_rx_mems.front(), _rx_lens.front()); + _rx_mems.pop_front(); + _rx_lens.pop_front(); + return mrb; +} + +uhd::transport::managed_send_buffer::sptr mock_zero_copy::get_send_buff(double) { + _msbs.push_back(boost::make_shared<mock_msb>()); + _tx_mems.push_back( + boost::shared_array<uint8_t>(new uint8_t[SEND_BUFF_SIZE])); + _tx_lens.push_back(SEND_BUFF_SIZE); + return _msbs.back()->get_new(_tx_mems.back(), &_tx_lens.back()); +} diff --git a/host/tests/common/mock_zero_copy.hpp b/host/tests/common/mock_zero_copy.hpp new file mode 100644 index 000000000..838975129 --- /dev/null +++ b/host/tests/common/mock_zero_copy.hpp @@ -0,0 +1,88 @@ +// +// Copyright 2018 Ettus Research, a National Instruments Company +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#ifndef INCLUDED_MOCK_XPORT_HPP +#define INCLUDED_MOCK_XPORT_HPP + +#include <uhdlib/rfnoc/xports.hpp> +#include <uhd/transport/chdr.hpp> +#include <uhd/transport/vrt_if_packet.hpp> +#include <uhd/transport/zero_copy.hpp> +#include <uhd/types/endianness.hpp> +#include <uhd/types/sid.hpp> +#include <uhd/utils/byteswap.hpp> +#include <boost/make_shared.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/shared_array.hpp> +#include <list> +#include <vector> +/*********************************************************************** + * Transport mockups + **********************************************************************/ +/*! A single transport class that implements send() and recv() + * + * Tx and Rx are separate. We can access the other end of the FIFOs from + * this class. + */ +static constexpr size_t SEND_BUFF_SIZE = 1024; +static constexpr size_t RECV_BUFF_SIZE = 1024; + +/*********************************************************************** + * Dummy managed buffers for testing + **********************************************************************/ +class mock_msb : public uhd::transport::managed_send_buffer { + public: + void release(void) { /* nop */ + } + + sptr get_new(boost::shared_array<uint8_t> mem, size_t* len) { + _mem = mem; + return make(this, mem.get(), *len); + } + + private: + boost::shared_array<uint8_t> _mem; +}; + + +class mock_mrb : public uhd::transport::managed_recv_buffer { + public: + void release(void) { /* nop */ + } + + sptr get_new(boost::shared_array<uint8_t> mem, size_t len) { + _mem = mem; + return make(this, _mem.get(), len); + } + + private: + boost::shared_array<uint8_t> _mem; +}; + +class mock_zero_copy : public uhd::transport::zero_copy_if { + public: + typedef boost::shared_ptr<mock_zero_copy> sptr; + uhd::transport::managed_recv_buffer::sptr get_recv_buff(double); + + uhd::transport::managed_send_buffer::sptr get_send_buff(double); + + size_t get_num_recv_frames(void) const { return 1; } + size_t get_num_send_frames(void) const { return 1; } + size_t get_recv_frame_size(void) const { return RECV_BUFF_SIZE; } + size_t get_send_frame_size(void) const { return SEND_BUFF_SIZE; } + + private: + std::list<boost::shared_array<uint8_t>> _tx_mems; + std::list<size_t> _tx_lens; + + std::list<boost::shared_array<uint8_t>> _rx_mems; + std::list<size_t> _rx_lens; + + std::vector<boost::shared_ptr<mock_msb>> _msbs; + std::vector<boost::shared_ptr<mock_mrb>> _mrbs; +}; + +#endif /*INCLUDED_MOCK_XPORT_HPP*/
\ No newline at end of file |