summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Rossetto <aaron.rossetto@ni.com>2021-08-20 14:39:17 -0500
committerAaron Rossetto <aaron.rossetto@ni.com>2021-09-02 16:05:58 -0500
commitec1707de5c75612d3cfb53013bb6ffdff7b180c1 (patch)
tree06a5adec7a42cce92042f7a83f1585e91a9277d7
parentuhd: streamer: Restore original recv(0) semantics (diff)
downloaduhd-ec1707de5c75612d3cfb53013bb6ffdff7b180c1.tar.xz
uhd-ec1707de5c75612d3cfb53013bb6ffdff7b180c1.zip
tests: Add recv(0) case to rx_streamer_test
-rw-r--r--host/tests/rx_streamer_test.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/host/tests/rx_streamer_test.cpp b/host/tests/rx_streamer_test.cpp
index fdc010535..03ab3f456 100644
--- a/host/tests/rx_streamer_test.cpp
+++ b/host/tests/rx_streamer_test.cpp
@@ -53,6 +53,16 @@ public:
const int32_t timeout_ms)
{
frame_buff::uptr buff = _recv_link->get_recv_buff(timeout_ms);
+ if(buff.get() == nullptr) {
+ // No samples available - simulate a timeout for the duration,
+ // then return a nullptr for the buffer. This will ultimately
+ // return an TIMEOUT to the upper-level receive layers.
+ std::this_thread::sleep_for(std::chrono::milliseconds(timeout_ms));
+ return std::make_tuple(
+ nullptr,
+ packet_info_t{},
+ false);
+ }
mock_header_t header = *(reinterpret_cast<mock_header_t*>(buff->data()));
packet_info_t info;
@@ -850,3 +860,32 @@ BOOST_AUTO_TEST_CASE(test_recv_two_channel_aggregate_eov)
BOOST_CHECK_EQUAL(expected_eov_offsets[i], metadata.eov_positions[i]);
}
}
+
+// A call to `recv()` of zero samples should return immediately, regardless of
+// the timeout parameter, and not return a timeout error despite the potential
+// absence of a packet on the wire.
+BOOST_AUTO_TEST_CASE(test_recv_zero_samples)
+{
+ const std::string format("fc64");
+
+ auto recv_links = make_links(1);
+ auto streamer = make_rx_streamer(recv_links, format);
+
+ std::vector<std::complex<double>> buff(1);
+ uhd::rx_metadata_t metadata;
+
+ const auto start_time = std::chrono::steady_clock::now();
+
+ const size_t num_samps_ret =
+ streamer->recv(buff.data(), 0, metadata, 10.0, false);
+
+ const auto end_time = std::chrono::steady_clock::now();
+ const std::chrono::duration<double> elapsed_time(end_time - start_time);
+
+ BOOST_CHECK_EQUAL(num_samps_ret, 0);
+ BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_NONE);
+
+ // Ensure that the `recv()` of zero samples didn't wait the requested
+ // timeout period of 10 seconds.
+ BOOST_CHECK_LE(elapsed_time.count(), 0.5);
+}