aboutsummaryrefslogtreecommitdiffstats
path: root/host/tests/actions_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'host/tests/actions_test.cpp')
-rw-r--r--host/tests/actions_test.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/host/tests/actions_test.cpp b/host/tests/actions_test.cpp
new file mode 100644
index 000000000..c0344eacf
--- /dev/null
+++ b/host/tests/actions_test.cpp
@@ -0,0 +1,81 @@
+//
+// Copyright 2019 Ettus Research, a National Instruments Brand
+//
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+
+#include <uhd/rfnoc/node.hpp>
+#include <uhd/rfnoc/actions.hpp>
+#include <uhd/utils/log.hpp>
+#include <uhdlib/rfnoc/node_accessor.hpp>
+#include <uhdlib/rfnoc/prop_accessor.hpp>
+#include <uhdlib/rfnoc/graph.hpp>
+#include <boost/test/unit_test.hpp>
+#include <iostream>
+
+#include "rfnoc_graph_mock_nodes.hpp"
+
+
+const std::string STREAM_CMD_KEY = "stream_cmd";
+
+BOOST_AUTO_TEST_CASE(test_actions_single_node)
+{
+ node_accessor_t node_accessor{};
+
+ // Define some mock nodes:
+ mock_radio_node_t mock_radio(0);
+
+ auto stream_cmd = action_info::make(STREAM_CMD_KEY);
+ std::string cmd_payload = "START";
+ stream_cmd->payload = std::vector<uint8_t>(cmd_payload.begin(), cmd_payload.end());
+
+ auto other_cmd = action_info::make("FOO");
+
+ node_accessor.send_action(&mock_radio, {res_source_info::INPUT_EDGE, 0}, stream_cmd);
+ node_accessor.send_action(&mock_radio, {res_source_info::INPUT_EDGE, 0}, other_cmd);
+
+ mock_radio.update_fwd_policy(node_t::forwarding_policy_t::ONE_TO_ONE);
+ node_accessor.send_action(&mock_radio, {res_source_info::INPUT_EDGE, 0}, other_cmd);
+ mock_radio.update_fwd_policy(node_t::forwarding_policy_t::ONE_TO_FAN);
+ node_accessor.send_action(&mock_radio, {res_source_info::INPUT_EDGE, 0}, other_cmd);
+ mock_radio.update_fwd_policy(node_t::forwarding_policy_t::ONE_TO_ALL);
+ node_accessor.send_action(&mock_radio, {res_source_info::INPUT_EDGE, 0}, other_cmd);
+ mock_radio.update_fwd_policy(node_t::forwarding_policy_t::ONE_TO_ALL_IN);
+ node_accessor.send_action(&mock_radio, {res_source_info::INPUT_EDGE, 0}, other_cmd);
+ mock_radio.update_fwd_policy(node_t::forwarding_policy_t::ONE_TO_ALL_OUT);
+ node_accessor.send_action(&mock_radio, {res_source_info::INPUT_EDGE, 0}, other_cmd);
+}
+
+BOOST_AUTO_TEST_CASE(test_actions_simple_graph)
+{
+ node_accessor_t node_accessor{};
+ uhd::rfnoc::detail::graph_t graph{};
+
+ // Define some mock nodes:
+ mock_radio_node_t mock_rx_radio{0};
+ mock_ddc_node_t mock_ddc{};
+ mock_fifo_t mock_fifo{1};
+ mock_streamer_t mock_streamer{1};
+
+ // These init calls would normally be done by the framework
+ node_accessor.init_props(&mock_rx_radio);
+ node_accessor.init_props(&mock_ddc);
+ node_accessor.init_props(&mock_fifo);
+ node_accessor.init_props(&mock_streamer);
+
+ graph.connect(&mock_rx_radio, &mock_ddc, {0, 0, graph_edge_t::DYNAMIC, true});
+ graph.connect(&mock_ddc, &mock_fifo, {0, 0, graph_edge_t::DYNAMIC, true});
+ graph.connect(&mock_fifo, &mock_streamer, {0, 0, graph_edge_t::DYNAMIC, true});
+ graph.initialize();
+
+ // Force the DDC to actually set a decimation rate != 1
+ mock_streamer.set_property<double>("samp_rate", 10e6, 0);
+
+ uhd::stream_cmd_t num_samps_cmd(uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE);
+ constexpr size_t NUM_SAMPS = 100;
+ num_samps_cmd.num_samps = NUM_SAMPS;
+
+ mock_streamer.issue_stream_cmd(num_samps_cmd, 0);
+ BOOST_CHECK_EQUAL(NUM_SAMPS * mock_ddc.get_property<int>("decim", 0),
+ mock_rx_radio.last_num_samps);
+}