diff options
author | Ashish Chaudhari <ashish@ettus.com> | 2015-03-17 13:52:29 -0700 |
---|---|---|
committer | Ashish Chaudhari <ashish@ettus.com> | 2015-03-17 13:52:29 -0700 |
commit | 6a34824ad10eaa2d2b642b959f278f6c4e326d6d (patch) | |
tree | 1aa582ee8e5cef716b59ec4deb3a8e5f4f532929 /host/tests | |
parent | 5682321efa26bb97f5d0c37d8e9921fc11a9b923 (diff) | |
parent | 306b5243e12af0db493856ad8397abac9835db0c (diff) | |
download | uhd-6a34824ad10eaa2d2b642b959f278f6c4e326d6d.tar.gz uhd-6a34824ad10eaa2d2b642b959f278f6c4e326d6d.tar.bz2 uhd-6a34824ad10eaa2d2b642b959f278f6c4e326d6d.zip |
Merge branch 'master' into ashish/vivado
Diffstat (limited to 'host/tests')
-rw-r--r-- | host/tests/CMakeLists.txt | 13 | ||||
-rw-r--r-- | host/tests/addr_test.cpp | 7 | ||||
-rw-r--r-- | host/tests/chdr_test.cpp | 141 | ||||
-rw-r--r-- | host/tests/dict_test.cpp | 25 | ||||
-rw-r--r-- | host/tests/fp_compare_delta_test.cpp | 32 | ||||
-rw-r--r-- | host/tests/fp_compare_epsilon_test.cpp | 32 | ||||
-rw-r--r-- | host/tests/math_test.cpp | 29 | ||||
-rw-r--r-- | host/tests/sid_t_test.cpp | 158 | ||||
-rw-r--r-- | host/tests/sph_recv_test.cpp | 4 | ||||
-rw-r--r-- | host/tests/sph_send_test.cpp | 2 | ||||
-rw-r--r-- | host/tests/time_spec_test.cpp | 4 |
11 files changed, 407 insertions, 40 deletions
diff --git a/host/tests/CMakeLists.txt b/host/tests/CMakeLists.txt index 62544b69b..596ab1017 100644 --- a/host/tests/CMakeLists.txt +++ b/host/tests/CMakeLists.txt @@ -27,16 +27,19 @@ SET(test_sources addr_test.cpp buffer_test.cpp byteswap_test.cpp - convert_test.cpp cast_test.cpp + chdr_test.cpp + convert_test.cpp dict_test.cpp error_test.cpp fp_compare_delta_test.cpp fp_compare_epsilon_test.cpp gain_group_test.cpp + math_test.cpp msg_test.cpp property_test.cpp ranges_test.cpp + sid_t_test.cpp sph_recv_test.cpp sph_send_test.cpp subdev_spec_test.cpp @@ -45,7 +48,11 @@ 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) +IF(MINGW) + ADD_DEFINITIONS(-DBOOST_TEST_MAIN) +ELSE() + ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN) +ENDIF() SET(UHD_TEST_TARGET_DEPS uhd) SET(UHD_TEST_LIBRARY_DIRS ${Boost_LIBRARY_DIRS}) @@ -54,7 +61,7 @@ SET(UHD_TEST_LIBRARY_DIRS ${Boost_LIBRARY_DIRS}) 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) + TARGET_LINK_LIBRARIES(${test_name} uhd ${Boost_LIBRARIES}) 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/addr_test.cpp b/host/tests/addr_test.cpp index cea2f224c..61bb6d049 100644 --- a/host/tests/addr_test.cpp +++ b/host/tests/addr_test.cpp @@ -66,6 +66,13 @@ BOOST_AUTO_TEST_CASE(test_device_addr){ old_dev_addr_vals.begin(), old_dev_addr_vals.end(), new_dev_addr_vals.begin(), new_dev_addr_vals.end() ); + + uhd::device_addr_t dev_addr_lhs1("key1=val1,key2=val2"); + dev_addr_lhs1.update(uhd::device_addr_t("key2=val2x,key3=val3"), false); + BOOST_CHECK_EQUAL(dev_addr_lhs1["key1"], "val1"); + BOOST_CHECK_EQUAL(dev_addr_lhs1["key2"], "val2x"); + BOOST_CHECK_EQUAL(dev_addr_lhs1["key3"], "val3"); + std::cout << "Merged: " << dev_addr_lhs1.to_string() << std::endl; } BOOST_AUTO_TEST_CASE(test_dboard_id){ diff --git a/host/tests/chdr_test.cpp b/host/tests/chdr_test.cpp new file mode 100644 index 000000000..ed6c690f9 --- /dev/null +++ b/host/tests/chdr_test.cpp @@ -0,0 +1,141 @@ +// +// Copyright 2014 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 +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + +#include <uhd/transport/chdr.hpp> +#include <uhd/utils/byteswap.hpp> +#include <boost/test/unit_test.hpp> +#include <boost/format.hpp> +#include <cstdlib> +#include <iostream> + +using namespace uhd::transport::vrt; + +static void pack_and_unpack( + if_packet_info_t &if_packet_info_in +){ + // Temp buffer for packed packet + boost::uint32_t packet_buff[2048] = {0}; + + // Check input (must not be lazy) + BOOST_REQUIRE( + (if_packet_info_in.num_payload_words32 == 0 and if_packet_info_in.num_payload_bytes == 0) + or + (if_packet_info_in.num_payload_words32 != 0 and if_packet_info_in.num_payload_bytes != 0) + ); + if (if_packet_info_in.num_payload_words32) { + BOOST_REQUIRE(if_packet_info_in.num_payload_bytes <= 4 * if_packet_info_in.num_payload_words32); + BOOST_REQUIRE(if_packet_info_in.num_payload_bytes > 4*(if_packet_info_in.num_payload_words32-1)); + } + + //pack metadata into a vrt header + chdr::if_hdr_pack_be( + packet_buff, if_packet_info_in + ); + std::cout << std::endl; + boost::uint32_t header_bits = (uhd::ntohx(packet_buff[0]) >> 28); + std::cout << boost::format("header bits = 0b%d%d%d%d") % bool(header_bits & 8) % bool(header_bits & 4) % bool(header_bits & 2) % bool(header_bits & 1) << std::endl; + for (size_t i = 0; i < 5; i++) + { + std::cout << boost::format("packet_buff[%u] = 0x%08x") % i % uhd::ntohx(packet_buff[i]) << std::endl; + } + + if_packet_info_t if_packet_info_out; + // Must be set a-priori as per contract + if_packet_info_out.num_packet_words32 = if_packet_info_in.num_packet_words32; + + //unpack the vrt header back into metadata + chdr::if_hdr_unpack_be( + packet_buff, if_packet_info_out + ); + + //check the the unpacked metadata is the same + BOOST_CHECK_EQUAL(if_packet_info_in.packet_count, if_packet_info_out.packet_count); + BOOST_CHECK_EQUAL(if_packet_info_in.num_header_words32, if_packet_info_out.num_header_words32); + BOOST_CHECK_EQUAL(if_packet_info_in.num_payload_words32, if_packet_info_out.num_payload_words32); + BOOST_CHECK(if_packet_info_out.has_sid); + BOOST_CHECK_EQUAL(if_packet_info_in.sid, if_packet_info_out.sid); + BOOST_CHECK(if_packet_info_out.has_sid); + BOOST_CHECK_EQUAL(if_packet_info_in.has_tsf, if_packet_info_out.has_tsf); + if (if_packet_info_in.has_tsf and if_packet_info_out.has_tsf){ + BOOST_CHECK_EQUAL(if_packet_info_in.tsf, if_packet_info_out.tsf); + } +} + +BOOST_AUTO_TEST_CASE(test_with_chdr){ + if_packet_info_t if_packet_info; + if_packet_info.packet_type = if_packet_info_t::PACKET_TYPE_DATA; + if_packet_info.eob = false; + if_packet_info.packet_count = 7; + if_packet_info.has_tsf = true; + if_packet_info.tsf = 0x1234567890ABCDEFull; + if_packet_info.sid = 0xAABBCCDD; + if_packet_info.num_payload_words32 = 24; + if_packet_info.num_payload_bytes = 95; + pack_and_unpack(if_packet_info); +} + +BOOST_AUTO_TEST_CASE(test_with_chdr_fc){ + if_packet_info_t if_packet_info; + if_packet_info.packet_type = if_packet_info_t::PACKET_TYPE_FC; + if_packet_info.eob = false; + if_packet_info.packet_count = 19; + if_packet_info.has_tsf = false; + if_packet_info.tsf = 0x1234567890ABCDEFull; + if_packet_info.sid = 0xAABBCCDD; + if_packet_info.num_payload_words32 = 4; + if_packet_info.num_payload_bytes = 16; + pack_and_unpack(if_packet_info); +} + +BOOST_AUTO_TEST_CASE(test_with_chdr_cmd){ + if_packet_info_t if_packet_info; + if_packet_info.packet_type = if_packet_info_t::PACKET_TYPE_CMD; + if_packet_info.packet_count = 19; + if_packet_info.has_tsf = true; + if_packet_info.tsf = 0x1234567890ABCDEFull; + if_packet_info.sid = 0xAABBCCDD; + if_packet_info.num_payload_words32 = 4; + if_packet_info.num_payload_bytes = 16; + pack_and_unpack(if_packet_info); +} + +BOOST_AUTO_TEST_CASE(test_with_chdr_resp){ + if_packet_info_t if_packet_info; + if_packet_info.packet_type = if_packet_info_t::PACKET_TYPE_RESP; + if_packet_info.packet_count = 123; + if_packet_info.has_tsf = false; + if_packet_info.tsf = 0x1234567890ABCDEFull; + if_packet_info.sid = 0xAABBCCDD; + if_packet_info.num_payload_words32 = 4; + if_packet_info.num_payload_bytes = 16; + pack_and_unpack(if_packet_info); +} + +BOOST_AUTO_TEST_CASE(test_with_chdr_err){ + if_packet_info_t if_packet_info; + if_packet_info.packet_type = if_packet_info_t::PACKET_TYPE_ERROR; + if_packet_info.packet_count = 1928; + if_packet_info.eob = false; + if_packet_info.error = false; // Needs to be set explicitly + if_packet_info.has_tsf = false; + if_packet_info.tsf = 0x1234567890ABCDEFull; + if_packet_info.sid = 0xAABBCCDD; + if_packet_info.num_payload_words32 = 4; + if_packet_info.num_payload_bytes = 16; + pack_and_unpack(if_packet_info); +} + diff --git a/host/tests/dict_test.cpp b/host/tests/dict_test.cpp index 7b388d090..333aadbba 100644 --- a/host/tests/dict_test.cpp +++ b/host/tests/dict_test.cpp @@ -70,3 +70,28 @@ BOOST_AUTO_TEST_CASE(test_dict_pop){ BOOST_CHECK(d.keys()[0] == -1); BOOST_CHECK(d.keys()[1] == 1); } + +BOOST_AUTO_TEST_CASE(test_dict_update) +{ + uhd::dict<std::string, std::string> d1 = boost::assign::map_list_of + ("key1", "val1") + ("key2", "val2") + ; + uhd::dict<std::string, std::string> d2 = boost::assign::map_list_of + ("key2", "val2x") + ("key3", "val3") + ; + + d1.update(d2, false /* don't throw cause of conflict */); + BOOST_CHECK_EQUAL(d1["key1"], "val1"); + BOOST_CHECK_EQUAL(d1["key2"], "val2x"); + BOOST_CHECK_EQUAL(d1["key3"], "val3"); + + uhd::dict<std::string, std::string> d3 = boost::assign::map_list_of + ("key1", "val1") + ("key2", "val2") + ; + BOOST_CHECK_THROW(d3.update(d2), uhd::value_error); +} + + diff --git a/host/tests/fp_compare_delta_test.cpp b/host/tests/fp_compare_delta_test.cpp index 9b009a79d..36ff14756 100644 --- a/host/tests/fp_compare_delta_test.cpp +++ b/host/tests/fp_compare_delta_test.cpp @@ -101,8 +101,8 @@ BOOST_AUTO_TEST_CASE(double_equality_operators) { BOOST_AUTO_TEST_CASE(float_inequality_operators) { // Test inequality operator, which is based on equality operator - fp_compare_delta<float> alpha = fp_compare_delta<float>(127.0); - fp_compare_delta<float> beta = fp_compare_delta<float>(alpha._value + 1.19e-3); + fp_compare_delta<float> alpha = fp_compare_delta<float>(127.0f); + fp_compare_delta<float> beta = fp_compare_delta<float>(alpha._value + 1.19e-3f); BOOST_CHECK(alpha != beta); BOOST_CHECK(alpha != float(alpha._value + 1.19e-3)); @@ -119,17 +119,17 @@ BOOST_AUTO_TEST_CASE(double_inequality_operators) { BOOST_AUTO_TEST_CASE(float_lessthan_operators) { // Test less-than operator - fp_compare_delta<float> alpha = fp_compare_delta<float>(274192.7); - fp_compare_delta<float> beta = fp_compare_delta<float>(alpha._value - 0.2); + fp_compare_delta<float> alpha = fp_compare_delta<float>(274192.7f); + fp_compare_delta<float> beta = fp_compare_delta<float>(alpha._value - 0.2f); BOOST_CHECK(beta < alpha); BOOST_CHECK(float(alpha._value - 0.2) < alpha); // Confirm false less-than case - fp_compare_delta<float> charlie = fp_compare_delta<float>(alpha._value - 1.2); + fp_compare_delta<float> charlie = fp_compare_delta<float>(alpha._value - 1.2f); BOOST_CHECK(not (alpha < charlie)); - BOOST_CHECK(not (alpha < float(alpha._value - 1.2))); + BOOST_CHECK(not (alpha < float(alpha._value - 1.2f))); } BOOST_AUTO_TEST_CASE(double_lessthan_operators) { @@ -149,14 +149,14 @@ BOOST_AUTO_TEST_CASE(double_lessthan_operators) { BOOST_AUTO_TEST_CASE(float_lessthanequals_operators) { // Test that <= correctly reports for equal values - fp_compare_delta<float> alpha = fp_compare_delta<float>(827.3); + fp_compare_delta<float> alpha = fp_compare_delta<float>(827.3f); fp_compare_delta<float> beta = fp_compare_delta<float>(alpha._value); BOOST_CHECK(alpha <= beta); BOOST_CHECK(alpha <= float(alpha._value)); // Test that <= correctly reports for less-than values - fp_compare_delta<float> charlie = fp_compare_delta<float>(alpha._value - 1.2); + fp_compare_delta<float> charlie = fp_compare_delta<float>(alpha._value - 1.2f); BOOST_CHECK(charlie <= alpha); BOOST_CHECK(float(alpha._value - 1.2) <= alpha); @@ -179,14 +179,14 @@ BOOST_AUTO_TEST_CASE(double_lessthanequals_operators) { BOOST_AUTO_TEST_CASE(float_greaterthan_operators) { // Test basic greater-than functionality - fp_compare_delta<float> alpha = fp_compare_delta<float>(98325.4); - fp_compare_delta<float> beta = fp_compare_delta<float>(alpha._value + 0.15); + fp_compare_delta<float> alpha = fp_compare_delta<float>(98325.4f); + fp_compare_delta<float> beta = fp_compare_delta<float>(alpha._value + 0.15f); BOOST_CHECK(beta > alpha); BOOST_CHECK(float(alpha._value + 0.15) > alpha); // Test false greater-than case - fp_compare_delta<float> charlie = fp_compare_delta<float>(alpha._value + 1.2); + fp_compare_delta<float> charlie = fp_compare_delta<float>(alpha._value + 1.2f); BOOST_CHECK(not (alpha > charlie)); BOOST_CHECK(not (alpha > float(alpha._value + 1.2))); @@ -209,14 +209,14 @@ BOOST_AUTO_TEST_CASE(double_greaterthan_operators) { BOOST_AUTO_TEST_CASE(float_greaterthanequals_operators) { // Test that >= correctly reports for equal values - fp_compare_delta<float> alpha = fp_compare_delta<float>(7834.89); + fp_compare_delta<float> alpha = fp_compare_delta<float>(7834.89f); fp_compare_delta<float> beta = fp_compare_delta<float>(alpha._value); BOOST_CHECK(alpha >= beta); BOOST_CHECK(alpha >= float(alpha._value)); // Test that >= correctly reports for greater-than values - fp_compare_delta<float> charlie = fp_compare_delta<float>(alpha._value + 4.8); + fp_compare_delta<float> charlie = fp_compare_delta<float>(alpha._value + 4.8f); BOOST_CHECK(charlie >= alpha); BOOST_CHECK(float(alpha._value + 4.8) >= alpha); @@ -239,12 +239,12 @@ BOOST_AUTO_TEST_CASE(double_greaterthanequals_operators) { BOOST_AUTO_TEST_CASE(frequency_compare_function) { - BOOST_CHECK(uhd::math::frequencies_are_equal(6817333232, 6817333232)); - BOOST_CHECK(!uhd::math::frequencies_are_equal(6817333233, 6817333232)); + BOOST_CHECK(uhd::math::frequencies_are_equal(6817333232.0, 6817333232.0)); + BOOST_CHECK(!uhd::math::frequencies_are_equal(6817333233.0, 6817333232.0)); BOOST_CHECK(uhd::math::frequencies_are_equal(6817333232.1, 6817333232.1)); BOOST_CHECK(!uhd::math::frequencies_are_equal(6817333232.5, 6817333232.6)); BOOST_CHECK(uhd::math::frequencies_are_equal(16.8173332321e9, 16.8173332321e9)); BOOST_CHECK(!uhd::math::frequencies_are_equal(16.8173332322e9, 16.8173332321e9)); BOOST_CHECK(!uhd::math::frequencies_are_equal(5.0, 4.0)); - BOOST_CHECK(uhd::math::frequencies_are_equal(48750000, 48749999.9946)); + BOOST_CHECK(uhd::math::frequencies_are_equal(48750000.0, 48749999.9946)); } diff --git a/host/tests/fp_compare_epsilon_test.cpp b/host/tests/fp_compare_epsilon_test.cpp index 5790318c2..45687ad26 100644 --- a/host/tests/fp_compare_epsilon_test.cpp +++ b/host/tests/fp_compare_epsilon_test.cpp @@ -30,7 +30,7 @@ BOOST_AUTO_TEST_CASE(fp_compare_epsilon_constructors) { // Test constructor with specified epsilon fp_compare_epsilon<float> foxtrot = fp_compare_epsilon<float>(alpha._value, uhd::math::SINGLE_PRECISION_EPSILON); - fp_compare_epsilon<float> gamma = fp_compare_epsilon<float>(alpha._value, 2.0e-1); + fp_compare_epsilon<float> gamma = fp_compare_epsilon<float>(alpha._value, 2.0e-1f); BOOST_CHECK_EQUAL(alpha._epsilon, foxtrot._epsilon); BOOST_CHECK(not (alpha._epsilon == gamma._epsilon)); @@ -102,10 +102,10 @@ BOOST_AUTO_TEST_CASE(double_equality_operators) { BOOST_AUTO_TEST_CASE(float_inequality_operators) { // Test inequality operator, which is based on equality operator fp_compare_epsilon<float> alpha = fp_compare_epsilon<float>(127.0); - fp_compare_epsilon<float> beta = fp_compare_epsilon<float>(alpha._value + 1.19e-5); + fp_compare_epsilon<float> beta = fp_compare_epsilon<float>(alpha._value + 1.19e-5f); BOOST_CHECK(alpha != beta); - BOOST_CHECK(alpha != float(alpha._value + 1.19e-5)); + BOOST_CHECK(alpha != float(alpha._value + 1.19e-5f)); } BOOST_AUTO_TEST_CASE(double_inequality_operators) { @@ -119,17 +119,17 @@ BOOST_AUTO_TEST_CASE(double_inequality_operators) { BOOST_AUTO_TEST_CASE(float_lessthan_operators) { // Test less-than operator - fp_compare_epsilon<float> alpha = fp_compare_epsilon<float>(274192.7); - fp_compare_epsilon<float> beta = fp_compare_epsilon<float>(alpha._value - 0.15); + fp_compare_epsilon<float> alpha = fp_compare_epsilon<float>(274192.7f); + fp_compare_epsilon<float> beta = fp_compare_epsilon<float>(alpha._value - 0.15f); BOOST_CHECK(beta < alpha); BOOST_CHECK(float(alpha._value - 0.15) < alpha); // Confirm false less-than case - fp_compare_epsilon<float> charlie = fp_compare_epsilon<float>(alpha._value - 1.2); + fp_compare_epsilon<float> charlie = fp_compare_epsilon<float>(alpha._value - 1.2f); BOOST_CHECK(not (alpha < charlie)); - BOOST_CHECK(not (alpha < float(alpha._value - 1.2))); + BOOST_CHECK(not (alpha < float(alpha._value - 1.2f))); } BOOST_AUTO_TEST_CASE(double_lessthan_operators) { @@ -149,14 +149,14 @@ BOOST_AUTO_TEST_CASE(double_lessthan_operators) { BOOST_AUTO_TEST_CASE(float_lessthanequals_operators) { // Test that <= correctly reports for equal values - fp_compare_epsilon<float> alpha = fp_compare_epsilon<float>(827.3); + fp_compare_epsilon<float> alpha = fp_compare_epsilon<float>(827.3f); fp_compare_epsilon<float> beta = fp_compare_epsilon<float>(alpha._value); BOOST_CHECK(alpha <= beta); BOOST_CHECK(alpha <= float(alpha._value)); // Test that <= correctly reports for less-than values - fp_compare_epsilon<float> charlie = fp_compare_epsilon<float>(alpha._value - 1.2); + fp_compare_epsilon<float> charlie = fp_compare_epsilon<float>(alpha._value - 1.2f); BOOST_CHECK(charlie <= alpha); BOOST_CHECK(float(alpha._value - 1.2) <= alpha); @@ -179,17 +179,17 @@ BOOST_AUTO_TEST_CASE(double_lessthanequals_operators) { BOOST_AUTO_TEST_CASE(float_greaterthan_operators) { // Test basic greater-than functionality - fp_compare_epsilon<float> alpha = fp_compare_epsilon<float>(98325.4); - fp_compare_epsilon<float> beta = fp_compare_epsilon<float>(alpha._value + 0.15); + fp_compare_epsilon<float> alpha = fp_compare_epsilon<float>(98325.4f); + fp_compare_epsilon<float> beta = fp_compare_epsilon<float>(alpha._value + 0.15f); BOOST_CHECK(beta > alpha); BOOST_CHECK(float(alpha._value + 0.15) > alpha); // Test false greater-than case - fp_compare_epsilon<float> charlie = fp_compare_epsilon<float>(alpha._value + 1.2); + fp_compare_epsilon<float> charlie = fp_compare_epsilon<float>(alpha._value + 1.2f); BOOST_CHECK(not (alpha > charlie)); - BOOST_CHECK(not (alpha > float(alpha._value + 1.2))); + BOOST_CHECK(not (alpha > float(alpha._value + 1.2f))); } BOOST_AUTO_TEST_CASE(double_greaterthan_operators) { @@ -209,17 +209,17 @@ BOOST_AUTO_TEST_CASE(double_greaterthan_operators) { BOOST_AUTO_TEST_CASE(float_greaterthanequals_operators) { // Test that >= correctly reports for equal values - fp_compare_epsilon<float> alpha = fp_compare_epsilon<float>(7834.89); + fp_compare_epsilon<float> alpha = fp_compare_epsilon<float>(7834.89f); fp_compare_epsilon<float> beta = fp_compare_epsilon<float>(alpha._value); BOOST_CHECK(alpha >= beta); BOOST_CHECK(alpha >= float(alpha._value)); // Test that >= correctly reports for greater-than values - fp_compare_epsilon<float> charlie = fp_compare_epsilon<float>(alpha._value + 4.8); + fp_compare_epsilon<float> charlie = fp_compare_epsilon<float>(alpha._value + 4.8f); BOOST_CHECK(charlie >= alpha); - BOOST_CHECK(float(alpha._value + 4.8) >= alpha); + BOOST_CHECK(float(alpha._value + 4.8f) >= alpha); } BOOST_AUTO_TEST_CASE(double_greaterthanequals_operators) { diff --git a/host/tests/math_test.cpp b/host/tests/math_test.cpp new file mode 100644 index 000000000..6c890c484 --- /dev/null +++ b/host/tests/math_test.cpp @@ -0,0 +1,29 @@ +// +// Copyright 2014 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 +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + +#include <boost/test/unit_test.hpp> +#include <boost/cstdint.hpp> +#include <uhd/utils/math.hpp> + +// NOTE: This is not the only math test case, see e.g. special tests +// for fp comparison. + +BOOST_AUTO_TEST_CASE(test_log2){ + double y = uhd::math::log2(16.0); + BOOST_CHECK_EQUAL(y, 4.0); +} + diff --git a/host/tests/sid_t_test.cpp b/host/tests/sid_t_test.cpp new file mode 100644 index 000000000..b5cdeb3d8 --- /dev/null +++ b/host/tests/sid_t_test.cpp @@ -0,0 +1,158 @@ +// +// Copyright 2014 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 +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + +#include <iostream> +#include <sstream> +#include <boost/test/unit_test.hpp> +#include <uhd/types/sid.hpp> +#include <uhd/exception.hpp> + +using uhd::sid_t; + +BOOST_AUTO_TEST_CASE(test_sid_t) { + boost::uint32_t sid_value = 0x01020310; + sid_t sid(sid_value); + + BOOST_CHECK_EQUAL(sid.is_set(), true); + BOOST_CHECK_EQUAL(sid.to_pp_string(), "1.2>3.16"); + BOOST_CHECK_EQUAL(sid.to_pp_string_hex(), "01:02>03:10"); + BOOST_CHECK_EQUAL(sid.get_src(), (uint32_t)0x0102); + BOOST_CHECK_EQUAL(sid.get_dst(), (uint32_t)0x0310); + BOOST_CHECK_EQUAL(sid.get_src_addr(), (uint32_t)0x01); + BOOST_CHECK_EQUAL(sid.get_src_endpoint(), (uint32_t)0x02); + BOOST_CHECK_EQUAL(sid.get_dst_addr(), (uint32_t)0x03); + BOOST_CHECK_EQUAL(sid.get_dst_endpoint(), (uint32_t)0x10); + BOOST_CHECK_EQUAL(sid == sid, true); + BOOST_CHECK_EQUAL(sid == sid_value, true); + + boost::uint32_t check_sid_val = (boost::uint32_t) sid; + BOOST_CHECK_EQUAL(check_sid_val, sid_value); + + std::stringstream ss_dec; + ss_dec << sid; + BOOST_CHECK_EQUAL(ss_dec.str(), "1.2>3.16"); + + std::stringstream ss_hex; + ss_hex << std::hex << sid; + BOOST_CHECK_EQUAL(ss_hex.str(), "01:02>03:10"); + + sid_t empty_sid; + BOOST_CHECK_EQUAL(empty_sid.is_set(), false); + BOOST_CHECK_EQUAL(empty_sid.to_pp_string(), "x.x>x.x"); + BOOST_CHECK_EQUAL(empty_sid.to_pp_string_hex(), "xx:xx>xx:xx"); + BOOST_CHECK_EQUAL(empty_sid == sid, false); + BOOST_CHECK_EQUAL(empty_sid == sid_value, false); + BOOST_CHECK_EQUAL((bool) empty_sid, false); + + empty_sid = sid_value; // No longer empty + BOOST_CHECK_EQUAL(empty_sid.is_set(), true); + BOOST_CHECK_EQUAL(empty_sid == sid, true); +} + +BOOST_AUTO_TEST_CASE(test_sid_t_set) { + boost::uint32_t sid_value = 0x0; + sid_t sid(sid_value); + + sid.set(0x01020304); + BOOST_CHECK_EQUAL(sid.get(), (uint32_t)0x01020304); + BOOST_CHECK_EQUAL(sid.get_src_addr(),(uint32_t)0x01); + BOOST_CHECK_EQUAL(sid.get_src_endpoint(), (uint32_t)0x02); + BOOST_CHECK_EQUAL(sid.get_dst_addr(), (uint32_t)0x03); + BOOST_CHECK_EQUAL(sid.get_dst_endpoint(), (uint32_t)0x04); + BOOST_CHECK_EQUAL(sid.get_dst_xbarport(), (uint32_t)0x0); + BOOST_CHECK_EQUAL(sid.get_dst_blockport(), (uint32_t)0x4); + + sid.set_src_addr(0x0a); + BOOST_CHECK_EQUAL(sid.get(), (uint32_t)0x0a020304); + BOOST_CHECK_EQUAL(sid.get_src_addr(), (uint32_t)0x0a); + BOOST_CHECK_EQUAL(sid.get_src_endpoint(), (uint32_t)0x02); + BOOST_CHECK_EQUAL(sid.get_dst_addr(), (uint32_t)0x03); + BOOST_CHECK_EQUAL(sid.get_dst_endpoint(), (uint32_t)0x04); + + sid.set_src_endpoint(0x0b); + BOOST_CHECK_EQUAL(sid.get(), (uint32_t)0x0a0b0304); + BOOST_CHECK_EQUAL(sid.get_src_addr(), (uint32_t)0x0a); + BOOST_CHECK_EQUAL(sid.get_src_endpoint(), (uint32_t)0x0b); + BOOST_CHECK_EQUAL(sid.get_dst_addr(), (uint32_t)0x03); + BOOST_CHECK_EQUAL(sid.get_dst_endpoint(), (uint32_t)0x04); + + sid.set_dst_addr(0x0c); + BOOST_CHECK_EQUAL(sid.get(), (uint32_t)0x0a0b0c04); + BOOST_CHECK_EQUAL(sid.get_src_addr(), (uint32_t)0x0a); + BOOST_CHECK_EQUAL(sid.get_src_endpoint(), (uint32_t)0x0b); + BOOST_CHECK_EQUAL(sid.get_dst_addr(), (uint32_t)0x0c); + BOOST_CHECK_EQUAL(sid.get_dst_endpoint(), (uint32_t)0x04); + + sid.set_dst_endpoint(0x0d); + BOOST_CHECK_EQUAL(sid.get(), (uint32_t)0x0a0b0c0d); + BOOST_CHECK_EQUAL(sid.get_src_addr(), (uint32_t)0x0a); + BOOST_CHECK_EQUAL(sid.get_src_endpoint(), (uint32_t)0x0b); + BOOST_CHECK_EQUAL(sid.get_dst_addr(), (uint32_t)0x0c); + BOOST_CHECK_EQUAL(sid.get_dst_endpoint(), (uint32_t)0x0d); + + sid.set_dst_xbarport(0xb); + BOOST_CHECK_EQUAL(sid.get(), (uint32_t)0x0a0b0cbd); + BOOST_CHECK_EQUAL(sid.get_src_addr(), (uint32_t)0x0a); + BOOST_CHECK_EQUAL(sid.get_src_endpoint(), (uint32_t)0x0b); + BOOST_CHECK_EQUAL(sid.get_dst_addr(), (uint32_t)0x0c); + BOOST_CHECK_EQUAL(sid.get_dst_endpoint(), (uint32_t)0xbd); + + sid.set_dst_blockport(0xc); + BOOST_CHECK_EQUAL(sid.get(), (uint32_t)0x0a0b0cbc); + BOOST_CHECK_EQUAL(sid.get_src_addr(), (uint32_t)0x0a); + BOOST_CHECK_EQUAL(sid.get_src_endpoint(), (uint32_t)0x0b); + BOOST_CHECK_EQUAL(sid.get_dst_addr(), (uint32_t)0x0c); + BOOST_CHECK_EQUAL(sid.get_dst_endpoint(), (uint32_t)0xbc); + + sid_t flipped_sid = sid.reversed(); + BOOST_CHECK_EQUAL(flipped_sid.get(), (uint32_t)0x0cbc0a0b); + + // In-place + sid.reverse(); + BOOST_CHECK_EQUAL(sid.get(), (uint32_t)0x0cbc0a0b); +} + +BOOST_AUTO_TEST_CASE(test_sid_t_from_str) { + sid_t sid("1.2>3.4"); + BOOST_CHECK_EQUAL(sid.get_src_addr(), (uint32_t)1); + BOOST_CHECK_EQUAL(sid.get_src_endpoint(), (uint32_t)2); + BOOST_CHECK_EQUAL(sid.get_dst_addr(), (uint32_t)3); + BOOST_CHECK_EQUAL(sid.get_dst_endpoint(), (uint32_t)4); + + sid = "01:02>03:10"; + BOOST_CHECK_EQUAL(sid.get_src_addr(), (uint32_t)1); + BOOST_CHECK_EQUAL(sid.get_src_endpoint(), (uint32_t)2); + BOOST_CHECK_EQUAL(sid.get_dst_addr(), (uint32_t)3); + BOOST_CHECK_EQUAL(sid.get_dst_endpoint(), (uint32_t)16); + + sid = "01:06/03:10"; + BOOST_CHECK_EQUAL(sid.get_src_addr(), (uint32_t)1); + BOOST_CHECK_EQUAL(sid.get_src_endpoint(), (uint32_t)6); + BOOST_CHECK_EQUAL(sid.get_dst_addr(), (uint32_t)3); + BOOST_CHECK_EQUAL(sid.get_dst_endpoint(), (uint32_t)16); + + sid = "01:02:04:10"; + BOOST_CHECK_EQUAL(sid.get_src_addr(), (uint32_t)1); + BOOST_CHECK_EQUAL(sid.get_src_endpoint(), (uint32_t)2); + BOOST_CHECK_EQUAL(sid.get_dst_addr(), (uint32_t)4); + BOOST_CHECK_EQUAL(sid.get_dst_endpoint(), (uint32_t)16); + + BOOST_REQUIRE_THROW(sid_t fail_sid("foobar"), uhd::value_error); + BOOST_REQUIRE_THROW(sid_t fail_sid("01:02:03:4"), uhd::value_error); + BOOST_REQUIRE_THROW(sid_t fail_sid("01:02:03:004"), uhd::value_error); + BOOST_REQUIRE_THROW(sid_t fail_sid("1.2.3.0004"), uhd::value_error); +} diff --git a/host/tests/sph_recv_test.cpp b/host/tests/sph_recv_test.cpp index 5dd0761db..e8c51b847 100644 --- a/host/tests/sph_recv_test.cpp +++ b/host/tests/sph_recv_test.cpp @@ -675,7 +675,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_fragment){ BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_NONE); BOOST_CHECK(metadata.has_time_spec); BOOST_CHECK_TS_CLOSE(metadata.time_spec, uhd::time_spec_t::from_ticks(num_accum_samps, SAMP_RATE)); - BOOST_CHECK_EQUAL(num_samps_ret, 10); + BOOST_CHECK_EQUAL(num_samps_ret, (size_t)10); num_accum_samps += num_samps_ret; if (not metadata.more_fragments) continue; @@ -685,7 +685,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_fragment){ ); BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_NONE); BOOST_CHECK(not metadata.more_fragments); - BOOST_CHECK_EQUAL(metadata.fragment_offset, 10); + BOOST_CHECK_EQUAL(metadata.fragment_offset, (size_t)10); BOOST_CHECK(metadata.has_time_spec); BOOST_CHECK_TS_CLOSE(metadata.time_spec, uhd::time_spec_t::from_ticks(num_accum_samps, SAMP_RATE)); BOOST_CHECK_EQUAL(num_samps_ret, i%10); diff --git a/host/tests/sph_send_test.cpp b/host/tests/sph_send_test.cpp index 603b36c85..58d47c76d 100644 --- a/host/tests/sph_send_test.cpp +++ b/host/tests/sph_send_test.cpp @@ -182,7 +182,7 @@ BOOST_AUTO_TEST_CASE(test_sph_send_one_channel_full_buffer_mode){ for (size_t i = 0; i < NUM_PKTS_TO_TEST; i++){ std::cout << "data check " << i << std::endl; dummy_send_xport.pop_front_packet(ifpi); - BOOST_CHECK_EQUAL(ifpi.num_payload_words32, 20); + BOOST_CHECK_EQUAL(ifpi.num_payload_words32, (size_t)20); BOOST_CHECK(ifpi.has_tsf); BOOST_CHECK_EQUAL(ifpi.tsf, num_accum_samps*TICK_RATE/SAMP_RATE); BOOST_CHECK_EQUAL(ifpi.sob, i == 0); diff --git a/host/tests/time_spec_test.cpp b/host/tests/time_spec_test.cpp index c9b9652f9..b98bea7d9 100644 --- a/host/tests/time_spec_test.cpp +++ b/host/tests/time_spec_test.cpp @@ -112,8 +112,8 @@ BOOST_AUTO_TEST_CASE(test_time_large_ticks_to_time_spec) BOOST_AUTO_TEST_CASE(test_time_error_irrational_rate) { - static const double rate = 1625e3/6; - const long long tick_in = 23423436291667; + static const double rate = 1625e3/6.0; + const long long tick_in = 23423436291667ll; 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; |