diff options
author | Josh Blum <josh@joshknows.com> | 2010-05-27 18:47:27 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-05-28 18:44:50 -0700 |
commit | 6665d7eb90264f12abdce86302fffe968879d94d (patch) | |
tree | 4bb9f2beabe7eba291952f0844b3b83668a024ce /host/test | |
parent | 4c133daee30e04d7740ca02a307f8e956de6dec6 (diff) | |
download | uhd-6665d7eb90264f12abdce86302fffe968879d94d.tar.gz uhd-6665d7eb90264f12abdce86302fffe968879d94d.tar.bz2 uhd-6665d7eb90264f12abdce86302fffe968879d94d.zip |
work on bounded and alignment buffer with unit testing
Diffstat (limited to 'host/test')
-rw-r--r-- | host/test/bounded_buffer_test.cpp | 79 |
1 files changed, 75 insertions, 4 deletions
diff --git a/host/test/bounded_buffer_test.cpp b/host/test/bounded_buffer_test.cpp index 5d6b6faec..dba1a4258 100644 --- a/host/test/bounded_buffer_test.cpp +++ b/host/test/bounded_buffer_test.cpp @@ -18,14 +18,11 @@ #include <boost/test/unit_test.hpp> #include <uhd/transport/bounded_buffer.hpp> -//test #Include -#include <uhd/transport/alignment_buffer.hpp> - using namespace uhd::transport; static const boost::posix_time::milliseconds timeout(10); -BOOST_AUTO_TEST_CASE(test_bounded_buffer){ +BOOST_AUTO_TEST_CASE(test_bounded_buffer_with_timed_wait){ bounded_buffer<int>::sptr bb(new bounded_buffer<int>(3)); //push elements, check for timeout @@ -44,3 +41,77 @@ BOOST_AUTO_TEST_CASE(test_bounded_buffer){ BOOST_CHECK_EQUAL(val, 2); BOOST_CHECK(not bb->pop_with_timed_wait(val, timeout)); } + +BOOST_AUTO_TEST_CASE(test_bounded_buffer_with_pop_on_full){ + bounded_buffer<int>::sptr bb(new bounded_buffer<int>(3)); + + //push elements, check for timeout + BOOST_CHECK(bb->push_with_pop_on_full(0)); + BOOST_CHECK(bb->push_with_pop_on_full(1)); + BOOST_CHECK(bb->push_with_pop_on_full(2)); + BOOST_CHECK(not bb->push_with_pop_on_full(3)); + + int val; + //pop elements, check for timeout and check values + BOOST_CHECK(bb->pop_with_timed_wait(val, timeout)); + BOOST_CHECK_EQUAL(val, 1); + BOOST_CHECK(bb->pop_with_timed_wait(val, timeout)); + BOOST_CHECK_EQUAL(val, 2); + BOOST_CHECK(bb->pop_with_timed_wait(val, timeout)); + BOOST_CHECK_EQUAL(val, 3); +} + +#include <uhd/transport/alignment_buffer.hpp> +#include <boost/assign/list_of.hpp> + +using namespace boost::assign; + +BOOST_AUTO_TEST_CASE(test_alignment_buffer_tmp){ + alignment_buffer<int, size_t>::sptr ab(new alignment_buffer<int, size_t>(5, 3)); + //load index 0 with all good seq numbers + BOOST_CHECK(ab->push_with_pop_on_full(0, 0, 0)); + BOOST_CHECK(ab->push_with_pop_on_full(1, 1, 0)); + BOOST_CHECK(ab->push_with_pop_on_full(2, 2, 0)); + BOOST_CHECK(ab->push_with_pop_on_full(3, 3, 0)); + BOOST_CHECK(ab->push_with_pop_on_full(4, 4, 0)); + + //load index 1 with some skipped seq numbers + BOOST_CHECK(ab->push_with_pop_on_full(10, 0, 1)); + BOOST_CHECK(ab->push_with_pop_on_full(11, 1, 1)); + BOOST_CHECK(ab->push_with_pop_on_full(14, 4, 1)); + BOOST_CHECK(ab->push_with_pop_on_full(15, 5, 1)); + BOOST_CHECK(ab->push_with_pop_on_full(16, 6, 1)); + + //load index 2 with all good seq numbers + BOOST_CHECK(ab->push_with_pop_on_full(20, 0, 2)); + BOOST_CHECK(ab->push_with_pop_on_full(21, 1, 2)); + BOOST_CHECK(ab->push_with_pop_on_full(22, 2, 2)); + BOOST_CHECK(ab->push_with_pop_on_full(23, 3, 2)); + BOOST_CHECK(ab->push_with_pop_on_full(24, 4, 2)); + + //readback aligned values + std::vector<int> aligned_elems(3); + + std::vector<int> expected_elems0 = list_of(0)(10)(20); + BOOST_CHECK(ab->pop_elems_with_timed_wait(aligned_elems, timeout)); + BOOST_CHECK_EQUAL_COLLECTIONS( + aligned_elems.begin(), aligned_elems.end(), + expected_elems0.begin(), expected_elems0.end() + ); + + std::vector<int> expected_elems1 = list_of(1)(11)(21); + BOOST_CHECK(ab->pop_elems_with_timed_wait(aligned_elems, timeout)); + BOOST_CHECK_EQUAL_COLLECTIONS( + aligned_elems.begin(), aligned_elems.end(), + expected_elems1.begin(), expected_elems1.end() + ); + + //there was a skip now find 4 + + std::vector<int> expected_elems4 = list_of(4)(14)(24); + BOOST_CHECK(ab->pop_elems_with_timed_wait(aligned_elems, timeout)); + BOOST_CHECK_EQUAL_COLLECTIONS( + aligned_elems.begin(), aligned_elems.end(), + expected_elems4.begin(), expected_elems4.end() + ); +} |