aboutsummaryrefslogtreecommitdiffstats
path: root/host/tests
diff options
context:
space:
mode:
Diffstat (limited to 'host/tests')
-rw-r--r--host/tests/CMakeLists.txt14
-rw-r--r--host/tests/convert_test.cpp28
-rw-r--r--host/tests/sph_recv_test.cpp13
-rw-r--r--host/tests/sph_send_test.cpp18
-rw-r--r--host/tests/time_spec_test.cpp30
5 files changed, 72 insertions, 31 deletions
diff --git a/host/tests/CMakeLists.txt b/host/tests/CMakeLists.txt
index 67e99941b..2a40d0050 100644
--- a/host/tests/CMakeLists.txt
+++ b/host/tests/CMakeLists.txt
@@ -16,6 +16,11 @@
#
########################################################################
+# unit test support
+########################################################################
+include(UHDUnitTest)
+
+########################################################################
# unit test suite
########################################################################
SET(test_sources
@@ -39,13 +44,16 @@ SET(test_sources
#turn each test cpp file into an executable with an int main() function
ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN)
-#for each source: build an executable, register it as a test, and install
+SET(UHD_TEST_TARGET_DEPS uhd)
+SET(UHD_TEST_LIBRARY_DIRS ${Boost_LIBRARY_DIRS})
+
+#for each source: build an executable, register it as a test
FOREACH(test_source ${test_sources})
GET_FILENAME_COMPONENT(test_name ${test_source} NAME_WE)
ADD_EXECUTABLE(${test_name} ${test_source})
TARGET_LINK_LIBRARIES(${test_name} uhd)
- ADD_TEST(${test_name} ${test_name})
- INSTALL(TARGETS ${test_name} RUNTIME DESTINATION ${PKG_LIB_DIR}/tests COMPONENT tests)
+ UHD_ADD_TEST(${test_name} ${test_name})
+ UHD_INSTALL(TARGETS ${test_name} RUNTIME DESTINATION ${PKG_LIB_DIR}/tests COMPONENT tests)
ENDFOREACH(test_source)
########################################################################
diff --git a/host/tests/convert_test.cpp b/host/tests/convert_test.cpp
index 6b0ae53a9..4b0226e3d 100644
--- a/host/tests/convert_test.cpp
+++ b/host/tests/convert_test.cpp
@@ -19,6 +19,7 @@
#include <boost/test/unit_test.hpp>
#include <boost/foreach.hpp>
#include <boost/cstdint.hpp>
+#include <boost/assign/list_of.hpp>
#include <complex>
#include <vector>
#include <cstdlib>
@@ -45,7 +46,9 @@ template <typename Range> static void loopback(
convert::id_type &in_id,
convert::id_type &out_id,
const Range &input,
- Range &output
+ Range &output,
+ const int prio_in = -1,
+ const int prio_out = -1
){
//item32 is largest device type
std::vector<boost::uint32_t> interm(nsamps);
@@ -54,12 +57,12 @@ template <typename Range> static void loopback(
std::vector<void *> output0(1, &interm[0]), output1(1, &output[0]);
//convert to intermediate type
- convert::converter::sptr c0 = convert::get_converter(in_id)();
+ convert::converter::sptr c0 = convert::get_converter(in_id, prio_in)();
c0->set_scalar(32767.);
c0->conv(input0, output0, nsamps);
//convert back to host type
- convert::converter::sptr c1 = convert::get_converter(out_id)();
+ convert::converter::sptr c1 = convert::get_converter(out_id, prio_out)();
c1->set_scalar(1/32767.);
c1->conv(input1, output1, nsamps);
}
@@ -133,10 +136,21 @@ static void test_convert_types_for_floats(
convert::id_type out_id = id;
std::swap(out_id.input_format, out_id.output_format);
std::swap(out_id.num_inputs, out_id.num_outputs);
- loopback(nsamps, in_id, out_id, input, output);
- for (size_t i = 0; i < nsamps; i++){
- MY_CHECK_CLOSE(input[i].real(), output[i].real(), value_type(1./32767));
- MY_CHECK_CLOSE(input[i].imag(), output[i].imag(), value_type(1./32767));
+
+ //make a list of all prio: best/generic combos
+ typedef std::pair<int, int> int_pair_t;
+ std::vector<int_pair_t> prios = boost::assign::list_of
+ (int_pair_t(0, 0)) (int_pair_t(-1, 0))
+ (int_pair_t(0, -1)) (int_pair_t(-1, -1))
+ ;
+
+ //loopback foreach prio combo (generic vs best)
+ BOOST_FOREACH(const int_pair_t &prio, prios){
+ loopback(nsamps, in_id, out_id, input, output, prio.first, prio.second);
+ for (size_t i = 0; i < nsamps; i++){
+ MY_CHECK_CLOSE(input[i].real(), output[i].real(), value_type(1./32767));
+ MY_CHECK_CLOSE(input[i].imag(), output[i].imag(), value_type(1./32767));
+ }
}
}
diff --git a/host/tests/sph_recv_test.cpp b/host/tests/sph_recv_test.cpp
index 9b45d7016..5a40029dc 100644
--- a/host/tests/sph_recv_test.cpp
+++ b/host/tests/sph_recv_test.cpp
@@ -50,16 +50,11 @@ public:
sptr get_new(boost::shared_array<char> mem, size_t len){
_mem = mem;
- _len = len;
- return make_managed_buffer(this);
+ return make(this, _mem.get(), len);
}
private:
- const void *get_buff(void) const{return _mem.get();}
- size_t get_size(void) const{return _len;}
-
boost::shared_array<char> _mem;
- size_t _len;
};
/***********************************************************************
@@ -89,8 +84,8 @@ public:
uhd::transport::managed_recv_buffer::sptr get_recv_buff(double){
if (_mems.empty()) return uhd::transport::managed_recv_buffer::sptr(); //timeout
- _mrbs.push_back(dummy_mrb());
- uhd::transport::managed_recv_buffer::sptr mrb = _mrbs.back().get_new(_mems.front(), _lens.front());
+ _mrbs.push_back(boost::shared_ptr<dummy_mrb>(new dummy_mrb()));
+ uhd::transport::managed_recv_buffer::sptr mrb = _mrbs.back()->get_new(_mems.front(), _lens.front());
_mems.pop_front();
_lens.pop_front();
return mrb;
@@ -99,7 +94,7 @@ public:
private:
std::list<boost::shared_array<char> > _mems;
std::list<size_t> _lens;
- std::list<dummy_mrb> _mrbs; //list means no-realloc
+ std::vector<boost::shared_ptr<dummy_mrb> > _mrbs;
std::string _end;
};
diff --git a/host/tests/sph_send_test.cpp b/host/tests/sph_send_test.cpp
index c31399d12..603b36c85 100644
--- a/host/tests/sph_send_test.cpp
+++ b/host/tests/sph_send_test.cpp
@@ -31,23 +31,17 @@
**********************************************************************/
class dummy_msb : public uhd::transport::managed_send_buffer{
public:
- void commit(size_t len){
- if (len == 0) return;
- *_len = len;
+ void release(void){
+ //NOP
}
sptr get_new(boost::shared_array<char> mem, size_t *len){
_mem = mem;
- _len = len;
- return make_managed_buffer(this);
+ return make(this, mem.get(), *len);
}
private:
- void *get_buff(void) const{return _mem.get();}
- size_t get_size(void) const{return *_len;}
-
boost::shared_array<char> _mem;
- size_t *_len;
};
/***********************************************************************
@@ -74,17 +68,17 @@ public:
}
uhd::transport::managed_send_buffer::sptr get_send_buff(double){
- _msbs.push_back(dummy_msb());
+ _msbs.push_back(boost::shared_ptr<dummy_msb>(new dummy_msb()));
_mems.push_back(boost::shared_array<char>(new char[1000]));
_lens.push_back(1000);
- uhd::transport::managed_send_buffer::sptr mrb = _msbs.back().get_new(_mems.back(), &_lens.back());
+ uhd::transport::managed_send_buffer::sptr mrb = _msbs.back()->get_new(_mems.back(), &_lens.back());
return mrb;
}
private:
std::list<boost::shared_array<char> > _mems;
std::list<size_t> _lens;
- std::list<dummy_msb> _msbs; //list means no-realloc
+ std::vector<boost::shared_ptr<dummy_msb> > _msbs;
std::string _end;
};
diff --git a/host/tests/time_spec_test.cpp b/host/tests/time_spec_test.cpp
index 102b7cda3..37a039cc5 100644
--- a/host/tests/time_spec_test.cpp
+++ b/host/tests/time_spec_test.cpp
@@ -20,6 +20,7 @@
#include <boost/foreach.hpp>
#include <boost/thread.hpp> //sleep
#include <iostream>
+#include <iomanip>
BOOST_AUTO_TEST_CASE(test_time_spec_compare){
std::cout << "Testing time specification compare..." << std::endl;
@@ -97,3 +98,32 @@ BOOST_AUTO_TEST_CASE(test_time_spec_neg_values){
BOOST_CHECK(tsa > tsb);
BOOST_CHECK(tsc > tsd);
}
+
+BOOST_AUTO_TEST_CASE(test_time_large_ticks_to_time_spec)
+{
+ std::cout << "sizeof(time_t) " << sizeof(time_t) << std::endl;
+ const boost::uint64_t ticks0 = boost::uint64_t(100e6*1360217663.739296);
+ const uhd::time_spec_t t0 = uhd::time_spec_t::from_ticks(ticks0, 100e6);
+ std::cout << "t0.get_real_secs() " << t0.get_real_secs() << std::endl;
+ std::cout << "t0.get_full_secs() " << t0.get_full_secs() << std::endl;
+ std::cout << "t0.get_frac_secs() " << t0.get_frac_secs() << std::endl;
+ BOOST_CHECK_EQUAL(t0.get_full_secs(), time_t(1360217663));
+}
+
+BOOST_AUTO_TEST_CASE(test_time_error_irrational_rate)
+{
+ static const double rate = 1625e3/6;
+ const long long tick_in = 23423436291667;
+ const uhd::time_spec_t ts = uhd::time_spec_t::from_ticks(tick_in, rate);
+ const long long tick_out = ts.to_ticks(rate);
+ const long long err = tick_in - tick_out;
+
+ std::cout << std::setprecision(18);
+ std::cout << "time ............ " << ts.get_real_secs() << std::endl;
+ std::cout << "tick in ......... " << tick_in << std::endl;
+ std::cout << "tick out ........ " << tick_out << std::endl;
+ std::cout << "tick error ...... " << err << std::endl;
+ std::cout << std::endl;
+
+ BOOST_CHECK_EQUAL(err, (long long)(0));
+}