aboutsummaryrefslogtreecommitdiffstats
path: root/host/tests/rfnoc_block_tests/logpwr_block_test.cpp
diff options
context:
space:
mode:
authorAaron Rossetto <aaron.rossetto@ni.com>2020-06-17 12:31:49 -0500
committerAaron Rossetto <aaron.rossetto@ni.com>2020-06-29 14:03:17 -0500
commit6d9b174086ddebf49183eb09b779bd2c2658573a (patch)
treeb274e2cc637b79b2835484bfb646165ad5e9df7b /host/tests/rfnoc_block_tests/logpwr_block_test.cpp
parent1ce6f961a76a455da2284f771a2d0140223a8f48 (diff)
downloaduhd-6d9b174086ddebf49183eb09b779bd2c2658573a.tar.gz
uhd-6d9b174086ddebf49183eb09b779bd2c2658573a.tar.bz2
uhd-6d9b174086ddebf49183eb09b779bd2c2658573a.zip
rfnoc: Add unit test for Log Power RFNoC block
Diffstat (limited to 'host/tests/rfnoc_block_tests/logpwr_block_test.cpp')
-rw-r--r--host/tests/rfnoc_block_tests/logpwr_block_test.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/host/tests/rfnoc_block_tests/logpwr_block_test.cpp b/host/tests/rfnoc_block_tests/logpwr_block_test.cpp
new file mode 100644
index 000000000..28e4d31b3
--- /dev/null
+++ b/host/tests/rfnoc_block_tests/logpwr_block_test.cpp
@@ -0,0 +1,81 @@
+//
+// Copyright 2019 Ettus Research, a National Instruments Brand
+//
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+
+#include "../rfnoc_graph_mock_nodes.hpp"
+#include <uhd/rfnoc/actions.hpp>
+#include <uhd/rfnoc/defaults.hpp>
+#include <uhd/rfnoc/logpwr_block_control.hpp>
+#include <uhd/rfnoc/mock_block.hpp>
+#include <uhd/rfnoc/register_iface_holder.hpp>
+#include <uhdlib/rfnoc/graph.hpp>
+#include <uhdlib/rfnoc/node_accessor.hpp>
+#include <uhdlib/utils/narrow.hpp>
+#include <boost/test/unit_test.hpp>
+#include <iostream>
+
+using namespace uhd::rfnoc;
+
+// Redeclare this here, since it's only defined outside of UHD_API
+noc_block_base::make_args_t::~make_args_t() = default;
+
+constexpr size_t NUM_CHANS = 4;
+
+/*
+ * logpwr_block_fixture is a class which is instantiated before each test
+ * case is run. It sets up the block container, logpwr_blok_control
+ * object and node accessor, all of which are accessible to the test case.
+ * The instance of the object is destroyed at the end of each test case.
+ */
+struct logpwr_block_fixture
+{
+ logpwr_block_fixture()
+ : block_container(
+ get_mock_block(LOGPWR_BLOCK, NUM_CHANS, NUM_CHANS, uhd::device_addr_t()))
+ , test_logpwr(block_container.get_block<logpwr_block_control>())
+ {
+ node_accessor.init_props(test_logpwr.get());
+ }
+
+ mock_block_container block_container;
+ std::shared_ptr<logpwr_block_control> test_logpwr;
+ node_accessor_t node_accessor{};
+};
+
+/*
+ * The block controller doesn't do much but constrain its edge type properties
+ * to what the block expects (sc16 in; s32 out). This test ensures that a
+ * log power block in a graph will propagate its expected types to the
+ * source and sink connected to it.
+ */
+BOOST_FIXTURE_TEST_CASE(logpwr_test_edge_types, logpwr_block_fixture)
+{
+ detail::graph_t graph{};
+
+ mock_terminator_t mock_source_term(NUM_CHANS);
+ mock_terminator_t mock_sink_term(NUM_CHANS);
+
+ UHD_LOG_INFO("TEST", "Creating graph...");
+ for (size_t chan = 0; chan < NUM_CHANS; chan++) {
+ detail::graph_t::graph_edge_t edge_info{
+ chan, chan, detail::graph_t::graph_edge_t::DYNAMIC, true};
+ graph.connect(&mock_source_term, test_logpwr.get(), edge_info);
+ graph.connect(test_logpwr.get(), &mock_sink_term, edge_info);
+ }
+ UHD_LOG_INFO("TEST", "Committing graph...");
+ graph.commit();
+ UHD_LOG_INFO("TEST", "Commit complete.");
+
+ // Now check the type edge properties on the source and sink and ensure
+ // they reflect what the log power block needs
+ for (size_t chan = 0; chan < NUM_CHANS; chan++) {
+ BOOST_CHECK(mock_source_term.get_edge_property<std::string>(
+ "type", {res_source_info::OUTPUT_EDGE, chan})
+ == IO_TYPE_SC16);
+ BOOST_CHECK(mock_sink_term.get_edge_property<std::string>(
+ "type", {res_source_info::INPUT_EDGE, chan})
+ == IO_TYPE_S16);
+ }
+}