From 52fb587373372e1f6024bd4adb7153c79aca3bde Mon Sep 17 00:00:00 2001 From: Michael West Date: Wed, 29 Apr 2020 03:05:35 -0700 Subject: examples: Update test_messages example The example assumed that there was always at least one TX and on RX channel. Since that is not always true, this change checks for TX and RX channels and only exucutes tests for what exists on the device. Signed-off-by: Michael West --- host/examples/test_messages.cpp | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'host/examples/test_messages.cpp') diff --git a/host/examples/test_messages.cpp b/host/examples/test_messages.cpp index fb930ac7c..512d22d86 100644 --- a/host/examples/test_messages.cpp +++ b/host/examples/test_messages.cpp @@ -316,22 +316,29 @@ int UHD_SAFE_MAIN(int argc, char* argv[]) // create RX and TX streamers uhd::stream_args_t stream_args("fc32"); // complex floats - uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args); - uhd::tx_streamer::sptr tx_stream = usrp->get_tx_stream(stream_args); + uhd::rx_streamer::sptr rx_stream; + uhd::tx_streamer::sptr tx_stream; + if (usrp->get_rx_num_channels()) { + rx_stream = usrp->get_rx_stream(stream_args); + } + if (usrp->get_tx_num_channels()) { + tx_stream = usrp->get_tx_stream(stream_args); + } //------------------------------------------------------------------ // begin messages test //------------------------------------------------------------------ using test_executor_fn = std::function; - // clang-format off - uhd::dict tests = boost::assign::map_list_of - ("Test Burst ACK ", &test_burst_ack_message) - ("Test Underflow ", &test_underflow_message) - ("Test Time Error", &test_time_error_message) - ("Test Late Command", &test_late_command_message) - ; - // clang-format on + uhd::dict tests; + if (tx_stream) { + tests["Test Burst ACK "] = &test_burst_ack_message; + tests["Test Underflow "] = &test_underflow_message; + tests["Test Time Error"] = &test_time_error_message; + } + if (rx_stream) { + tests["Test Late Command"] = &test_late_command_message; + } if (vm.count("test-chain")) { tests["Test Broken Chain"] = &test_broken_chain_message; @@ -350,8 +357,12 @@ int UHD_SAFE_MAIN(int argc, char* argv[]) std::string key = tests.keys()[std::rand() % tests.size()]; bool pass = tests[key](usrp, rx_stream, tx_stream); - flush_recv(rx_stream); - flush_async(tx_stream); + if (rx_stream) { + flush_recv(rx_stream); + } + if (tx_stream) { + flush_async(tx_stream); + } // store result if (pass) -- cgit v1.2.3