aboutsummaryrefslogtreecommitdiffstats
path: root/host/tests/time_spec_test.cpp
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2013-04-11 15:40:25 -0700
committerJosh Blum <josh@joshknows.com>2013-04-12 11:20:10 -0700
commitcb3f554658b6c979bf9649509d8c7a6cd3b8a9a4 (patch)
treef465f37112e7b5ebcb9b47ad01bae75e97726e1c /host/tests/time_spec_test.cpp
parent2b2b9464f64b03c9ae7317555c7db9ec29aa8fcd (diff)
downloaduhd-cb3f554658b6c979bf9649509d8c7a6cd3b8a9a4.tar.gz
uhd-cb3f554658b6c979bf9649509d8c7a6cd3b8a9a4.tar.bz2
uhd-cb3f554658b6c979bf9649509d8c7a6cd3b8a9a4.zip
uhd: fixes for time_spec's to_ticks and from_ticks calls
The fixes address rouding issues when the tick_rate is a non-integer. Conflicts: host/tests/time_spec_test.cpp
Diffstat (limited to 'host/tests/time_spec_test.cpp')
-rw-r--r--host/tests/time_spec_test.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/host/tests/time_spec_test.cpp b/host/tests/time_spec_test.cpp
index 102b7cda3..7dee95c5c 100644
--- a/host/tests/time_spec_test.cpp
+++ b/host/tests/time_spec_test.cpp
@@ -97,3 +97,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));
+}