summaryrefslogtreecommitdiffstats
path: root/host/tests
diff options
context:
space:
mode:
Diffstat (limited to 'host/tests')
-rw-r--r--host/tests/buffer_test.cpp36
-rw-r--r--host/tests/convert_test.cpp46
-rw-r--r--host/tests/time_spec_test.cpp19
3 files changed, 74 insertions, 27 deletions
diff --git a/host/tests/buffer_test.cpp b/host/tests/buffer_test.cpp
index e7bc88699..23b52a9bf 100644
--- a/host/tests/buffer_test.cpp
+++ b/host/tests/buffer_test.cpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010 Ettus Research LLC
+// Copyright 2010-2011 Ettus Research LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -25,40 +25,40 @@ using namespace uhd::transport;
static const double timeout = 0.01/*secs*/;
BOOST_AUTO_TEST_CASE(test_bounded_buffer_with_timed_wait){
- bounded_buffer<int>::sptr bb(bounded_buffer<int>::make(3));
+ bounded_buffer<int> bb(3);
//push elements, check for timeout
- BOOST_CHECK(bb->push_with_timed_wait(0, timeout));
- BOOST_CHECK(bb->push_with_timed_wait(1, timeout));
- BOOST_CHECK(bb->push_with_timed_wait(2, timeout));
- BOOST_CHECK(not bb->push_with_timed_wait(3, timeout));
+ BOOST_CHECK(bb.push_with_timed_wait(0, timeout));
+ BOOST_CHECK(bb.push_with_timed_wait(1, timeout));
+ BOOST_CHECK(bb.push_with_timed_wait(2, timeout));
+ BOOST_CHECK(not bb.push_with_timed_wait(3, timeout));
int val;
//pop elements, check for timeout and check values
- BOOST_CHECK(bb->pop_with_timed_wait(val, timeout));
+ BOOST_CHECK(bb.pop_with_timed_wait(val, timeout));
BOOST_CHECK_EQUAL(val, 0);
- BOOST_CHECK(bb->pop_with_timed_wait(val, timeout));
+ 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(bb.pop_with_timed_wait(val, timeout));
BOOST_CHECK_EQUAL(val, 2);
- BOOST_CHECK(not bb->pop_with_timed_wait(val, timeout));
+ 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(bounded_buffer<int>::make(3));
+ bounded_buffer<int> bb(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));
+ 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(bb.pop_with_timed_wait(val, timeout));
BOOST_CHECK_EQUAL(val, 1);
- BOOST_CHECK(bb->pop_with_timed_wait(val, timeout));
+ 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(bb.pop_with_timed_wait(val, timeout));
BOOST_CHECK_EQUAL(val, 3);
}
diff --git a/host/tests/convert_test.cpp b/host/tests/convert_test.cpp
index 5f2aaf3d1..d3c235e9b 100644
--- a/host/tests/convert_test.cpp
+++ b/host/tests/convert_test.cpp
@@ -29,6 +29,7 @@ using namespace uhd;
//typedefs for complex types
typedef std::complex<boost::int16_t> sc16_t;
typedef std::complex<float> fc32_t;
+typedef std::complex<double> fc64_t;
#define MY_CHECK_CLOSE(a, b, f) if ((std::abs(a) > (f) and std::abs(b) > (f))) \
BOOST_CHECK_CLOSE_FRACTION(a, b, f)
@@ -109,23 +110,26 @@ BOOST_AUTO_TEST_CASE(test_convert_types_le_sc16){
/***********************************************************************
* Test float conversion
**********************************************************************/
-static void test_convert_types_fc32(
+template <typename data_type>
+static void test_convert_types_for_floats(
size_t nsamps,
const io_type_t &io_type,
const otw_type_t &otw_type
){
+ typedef typename data_type::value_type value_type;
+
//fill the input samples
- std::vector<fc32_t> input(nsamps), output(nsamps);
- BOOST_FOREACH(fc32_t &in, input) in = fc32_t(
- (std::rand()/float(RAND_MAX/2)) - 1,
- (std::rand()/float(RAND_MAX/2)) - 1
+ std::vector<data_type> input(nsamps), output(nsamps);
+ BOOST_FOREACH(data_type &in, input) in = data_type(
+ (std::rand()/value_type(RAND_MAX/2)) - 1,
+ (std::rand()/value_type(RAND_MAX/2)) - 1
);
//run the loopback and test
loopback(nsamps, io_type, otw_type, input, output);
for (size_t i = 0; i < nsamps; i++){
- MY_CHECK_CLOSE(input[i].real(), output[i].real(), float(0.01));
- MY_CHECK_CLOSE(input[i].imag(), output[i].imag(), float(0.01));
+ MY_CHECK_CLOSE(input[i].real(), output[i].real(), value_type(0.01));
+ MY_CHECK_CLOSE(input[i].imag(), output[i].imag(), value_type(0.01));
}
}
@@ -137,7 +141,7 @@ BOOST_AUTO_TEST_CASE(test_convert_types_be_fc32){
//try various lengths to test edge cases
for (size_t nsamps = 1; nsamps < 16; nsamps++){
- test_convert_types_fc32(nsamps, io_type, otw_type);
+ test_convert_types_for_floats<fc32_t>(nsamps, io_type, otw_type);
}
}
@@ -149,7 +153,31 @@ BOOST_AUTO_TEST_CASE(test_convert_types_le_fc32){
//try various lengths to test edge cases
for (size_t nsamps = 1; nsamps < 16; nsamps++){
- test_convert_types_fc32(nsamps, io_type, otw_type);
+ test_convert_types_for_floats<fc32_t>(nsamps, io_type, otw_type);
+ }
+}
+
+BOOST_AUTO_TEST_CASE(test_convert_types_be_fc64){
+ io_type_t io_type(io_type_t::COMPLEX_FLOAT64);
+ otw_type_t otw_type;
+ otw_type.byteorder = otw_type_t::BO_BIG_ENDIAN;
+ otw_type.width = 16;
+
+ //try various lengths to test edge cases
+ for (size_t nsamps = 1; nsamps < 16; nsamps++){
+ test_convert_types_for_floats<fc64_t>(nsamps, io_type, otw_type);
+ }
+}
+
+BOOST_AUTO_TEST_CASE(test_convert_types_le_fc64){
+ io_type_t io_type(io_type_t::COMPLEX_FLOAT64);
+ otw_type_t otw_type;
+ otw_type.byteorder = otw_type_t::BO_LITTLE_ENDIAN;
+ otw_type.width = 16;
+
+ //try various lengths to test edge cases
+ for (size_t nsamps = 1; nsamps < 16; nsamps++){
+ test_convert_types_for_floats<fc64_t>(nsamps, io_type, otw_type);
}
}
diff --git a/host/tests/time_spec_test.cpp b/host/tests/time_spec_test.cpp
index 5ad782160..070392f93 100644
--- a/host/tests/time_spec_test.cpp
+++ b/host/tests/time_spec_test.cpp
@@ -18,6 +18,7 @@
#include <boost/test/unit_test.hpp>
#include <uhd/types/time_spec.hpp>
#include <boost/foreach.hpp>
+#include <boost/thread.hpp> //sleep
#include <iostream>
BOOST_AUTO_TEST_CASE(test_time_spec_compare){
@@ -59,3 +60,21 @@ BOOST_AUTO_TEST_CASE(test_time_spec_parts){
BOOST_CHECK_CLOSE(uhd::time_spec_t(-1.1).get_frac_secs(), -0.1, 0.001);
BOOST_CHECK_EQUAL(uhd::time_spec_t(-1.1).get_tick_count(100), -10);
}
+
+BOOST_AUTO_TEST_CASE(test_time_spec_get_system_time){
+ std::cout << "Testing time specification get system time..." << std::endl;
+
+ //Not really checking for high resolution timing here,
+ //just need to check that system time is minimally working.
+
+ uhd::time_spec_t start = uhd::time_spec_t::get_system_time();
+ boost::this_thread::sleep(boost::posix_time::milliseconds(500));
+ uhd::time_spec_t stop = uhd::time_spec_t::get_system_time();
+
+ uhd::time_spec_t diff = stop - start;
+ std::cout << "start: " << start.get_real_secs() << std::endl;
+ std::cout << "stop: " << stop.get_real_secs() << std::endl;
+ std::cout << "diff: " << diff.get_real_secs() << std::endl;
+ BOOST_CHECK(diff.get_real_secs() > 0); //assert positive
+ BOOST_CHECK(diff.get_real_secs() < 1.0); //assert under 1s
+}