aboutsummaryrefslogtreecommitdiffstats
path: root/host/tests
diff options
context:
space:
mode:
Diffstat (limited to 'host/tests')
-rw-r--r--host/tests/CMakeLists.txt21
-rw-r--r--host/tests/addr_test.cpp7
-rw-r--r--host/tests/chdr_test.cpp144
-rw-r--r--host/tests/convert_test.cpp40
-rw-r--r--host/tests/dict_test.cpp25
-rw-r--r--host/tests/eeprom_c_test.c157
-rw-r--r--host/tests/error_c_test.cpp144
-rw-r--r--host/tests/fp_compare_delta_test.cpp6
-rw-r--r--host/tests/math_test.cpp29
-rw-r--r--host/tests/ranges_c_test.c236
-rw-r--r--host/tests/sensors_c_test.c411
-rw-r--r--host/tests/sid_t_test.cpp158
-rw-r--r--host/tests/string_vector_c_test.c90
-rw-r--r--host/tests/subdev_spec_c_test.c130
-rw-r--r--host/tests/time_spec_test.cpp4
15 files changed, 1592 insertions, 10 deletions
diff --git a/host/tests/CMakeLists.txt b/host/tests/CMakeLists.txt
index 62544b69b..8b12c961f 100644
--- a/host/tests/CMakeLists.txt
+++ b/host/tests/CMakeLists.txt
@@ -1,5 +1,5 @@
#
-# Copyright 2010-2011 Ettus Research LLC
+# Copyright 2010-2015 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
@@ -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
@@ -47,14 +50,22 @@ 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)
-SET(UHD_TEST_TARGET_DEPS uhd)
-SET(UHD_TEST_LIBRARY_DIRS ${Boost_LIBRARY_DIRS})
+IF(ENABLE_C_API)
+ LIST(APPEND test_sources
+ eeprom_c_test.c
+ error_c_test.cpp
+ ranges_c_test.c
+ sensors_c_test.c
+ string_vector_c_test.c
+ subdev_spec_c_test.c
+ )
+ENDIF(ENABLE_C_API)
#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)
+ 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..f48073a09
--- /dev/null
+++ b/host/tests/chdr_test.cpp
@@ -0,0 +1,144 @@
+//
+// 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") % ((header_bits & 8) > 0)
+ % ((header_bits & 4) > 0)
+ % ((header_bits & 2) > 0)
+ % ((header_bits & 1) > 0) << 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/convert_test.cpp b/host/tests/convert_test.cpp
index 8ef1e74cc..d71d756dd 100644
--- a/host/tests/convert_test.cpp
+++ b/host/tests/convert_test.cpp
@@ -415,3 +415,43 @@ BOOST_AUTO_TEST_CASE(test_convert_types_sc16_and_sc8){
test_convert_types_sc16(nsamps, id, 256);
}
}
+
+/***********************************************************************
+ * Test short conversion
+ **********************************************************************/
+static void test_convert_types_u8(
+ size_t nsamps, convert::id_type &id
+){
+ //fill the input samples
+ std::vector<boost::uint8_t> input(nsamps), output(nsamps);
+ //BOOST_FOREACH(boost::uint8_t &in, input) in = boost::uint8_t(std::rand() & 0xFF);
+ boost::uint32_t d = 48;
+ BOOST_FOREACH(boost::uint8_t &in, input) in = d++;
+
+ //run the loopback and test
+ convert::id_type in_id = id;
+ 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);
+ BOOST_CHECK_EQUAL_COLLECTIONS(input.begin(), input.end(), output.begin(), output.end());
+}
+
+BOOST_AUTO_TEST_CASE(test_convert_types_u8_and_u8){
+ convert::id_type id;
+ id.input_format = "u8";
+ id.num_inputs = 1;
+ id.num_outputs = 1;
+
+ //try various lengths to test edge cases
+ id.output_format = "u8_item32_le";
+ for (size_t nsamps = 1; nsamps < 16; nsamps++){
+ test_convert_types_u8(nsamps, id);
+ }
+
+ //try various lengths to test edge cases
+ id.output_format = "u8_item32_be";
+ for (size_t nsamps = 1; nsamps < 16; nsamps++){
+ test_convert_types_u8(nsamps, id);
+ }
+}
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/eeprom_c_test.c b/host/tests/eeprom_c_test.c
new file mode 100644
index 000000000..1b29dfd44
--- /dev/null
+++ b/host/tests/eeprom_c_test.c
@@ -0,0 +1,157 @@
+//
+// Copyright 2015 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.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define UHD_TEST_EXECUTE_OR_GOTO(label, ...) \
+ if(__VA_ARGS__){ \
+ fprintf(stderr, "Error occurred at %s:%d\n", __FILE__, (__LINE__-1)); \
+ return_code = EXIT_FAILURE; \
+ goto label; \
+ }
+
+#define BUFFER_SIZE 1024
+
+int main(){
+
+ // Variables
+ int return_code;
+ uhd_mboard_eeprom_handle mb_eeprom;
+ uhd_dboard_eeprom_handle db_eeprom;
+ int db_revision;
+ char str_buffer[BUFFER_SIZE];
+
+ return_code = EXIT_SUCCESS;
+
+ /*
+ * Motherboard EEPROM test
+ */
+
+ // Create EEPROM handle
+ UHD_TEST_EXECUTE_OR_GOTO(end_of_test,
+ uhd_mboard_eeprom_make(&mb_eeprom)
+ )
+
+ // Set a value, retrieve it, and make sure it matches
+ UHD_TEST_EXECUTE_OR_GOTO(free_mboard_eeprom,
+ uhd_mboard_eeprom_set_value(
+ mb_eeprom,
+ "serial",
+ "F12345"
+ )
+ )
+ UHD_TEST_EXECUTE_OR_GOTO(free_mboard_eeprom,
+ uhd_mboard_eeprom_get_value(
+ mb_eeprom,
+ "serial",
+ str_buffer,
+ BUFFER_SIZE
+ )
+ )
+ if(strcmp(str_buffer, "F12345")){
+ return_code = EXIT_FAILURE;
+ fprintf(stderr, "%s:%d: Mismatched EEPROM value: \"%s\" vs. \"F12345\"\n",
+ __FILE__, __LINE__,
+ str_buffer);
+ goto free_mboard_eeprom;
+ }
+
+ /*
+ * Daughterboard EEPROM test
+ */
+
+ // Create EEPROM handle
+ UHD_TEST_EXECUTE_OR_GOTO(free_mboard_eeprom,
+ uhd_dboard_eeprom_make(&db_eeprom)
+ )
+
+ // Set the ID, retrieve it, and make sure it matches
+ UHD_TEST_EXECUTE_OR_GOTO(free_dboard_eeprom,
+ uhd_dboard_eeprom_set_id(db_eeprom, "0x0067")
+ )
+ UHD_TEST_EXECUTE_OR_GOTO(free_dboard_eeprom,
+ uhd_dboard_eeprom_get_id(
+ db_eeprom,
+ str_buffer,
+ BUFFER_SIZE
+ )
+ )
+ if(strcmp(str_buffer, "0x0067")){
+ return_code = EXIT_FAILURE;
+ fprintf(stderr, "%s:%d: Mismatched daughterboard ID: \"%s\" vs. \"0x0067\"\n",
+ __FILE__, __LINE__,
+ str_buffer);
+ goto free_dboard_eeprom;
+ }
+
+ // Set the serial, retrieve it, and make sure it matches
+ UHD_TEST_EXECUTE_OR_GOTO(free_dboard_eeprom,
+ uhd_dboard_eeprom_set_serial(db_eeprom, "F12345")
+ )
+ UHD_TEST_EXECUTE_OR_GOTO(free_dboard_eeprom,
+ uhd_dboard_eeprom_get_serial(
+ db_eeprom,
+ str_buffer,
+ BUFFER_SIZE
+ )
+ )
+ if(strcmp(str_buffer, "F12345")){
+ return_code = EXIT_FAILURE;
+ fprintf(stderr, "%s:%d: Mismatched daughterboard serial: \"%s\" vs. \"F12345\"\n",
+ __FILE__, __LINE__,
+ str_buffer);
+ goto free_dboard_eeprom;
+ }
+
+ // Set the revision, retrieve it, and make sure it matches
+ UHD_TEST_EXECUTE_OR_GOTO(free_dboard_eeprom,
+ uhd_dboard_eeprom_set_revision(db_eeprom, 4)
+ )
+ UHD_TEST_EXECUTE_OR_GOTO(free_dboard_eeprom,
+ uhd_dboard_eeprom_get_revision(db_eeprom, &db_revision)
+ )
+ if(db_revision != 4){
+ return_code = EXIT_FAILURE;
+ fprintf(stderr, "%s:%d: Mismatched daughterboard revision: \"%d\" vs. 4\n",
+ __FILE__, __LINE__, db_revision);
+ goto free_dboard_eeprom;
+ }
+
+ free_dboard_eeprom:
+ if(return_code){
+ uhd_dboard_eeprom_last_error(db_eeprom, str_buffer, BUFFER_SIZE);
+ fprintf(stderr, "db_eeprom error: %s\n", str_buffer);
+ }
+ uhd_dboard_eeprom_free(&db_eeprom);
+
+ free_mboard_eeprom:
+ if(return_code){
+ uhd_mboard_eeprom_last_error(mb_eeprom, str_buffer, BUFFER_SIZE);
+ fprintf(stderr, "mb_eeprom error: %s\n", str_buffer);
+ }
+ uhd_mboard_eeprom_free(&mb_eeprom);
+
+ end_of_test:
+ if(!return_code){
+ printf("\nNo errors detected\n");
+ }
+ return return_code;
+}
diff --git a/host/tests/error_c_test.cpp b/host/tests/error_c_test.cpp
new file mode 100644
index 000000000..8eb90f3d4
--- /dev/null
+++ b/host/tests/error_c_test.cpp
@@ -0,0 +1,144 @@
+//
+// Copyright 2015 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/error.h>
+#include <uhd/types/dict.hpp>
+
+#include <boost/test/unit_test.hpp>
+#include <boost/algorithm/string.hpp>
+#include <boost/assign.hpp>
+#include <boost/format.hpp>
+
+/*
+ * Test our conversions from exceptions to C-level UHD error codes.
+ * We use inline functions separate from the Boost test cases themselves
+ * to test our C++ macro, which returns the error code.
+ */
+
+typedef struct {
+ std::string last_error;
+} dummy_handle_t;
+
+template <typename error_type>
+UHD_INLINE uhd_error throw_uhd_exception(dummy_handle_t *handle, const uhd::exception* except){
+ UHD_SAFE_C_SAVE_ERROR(handle,
+ throw *dynamic_cast<const error_type*>(except);
+ )
+}
+
+UHD_INLINE uhd_error throw_boost_exception(dummy_handle_t *handle){
+ UHD_SAFE_C_SAVE_ERROR(handle,
+ std::runtime_error except("This is a std::runtime_error, thrown by Boost.");
+ BOOST_THROW_EXCEPTION(except);
+ )
+}
+
+UHD_INLINE uhd_error throw_std_exception(dummy_handle_t *handle){
+ UHD_SAFE_C_SAVE_ERROR(handle,
+ throw std::runtime_error("This is a std::runtime_error.");
+ )
+}
+
+UHD_INLINE uhd_error throw_unknown_exception(dummy_handle_t *handle){
+ UHD_SAFE_C_SAVE_ERROR(handle,
+ throw 1;
+ )
+}
+
+// There are enough non-standard names that we can't just use a conversion function
+static const uhd::dict<std::string, std::string> pretty_exception_names =
+ boost::assign::map_list_of
+ ("assertion_error", "AssertionError")
+ ("lookup_error", "LookupError")
+ ("index_error", "LookupError: IndexError")
+ ("key_error", "LookupError: KeyError")
+ ("type_error", "TypeError")
+ ("value_error", "ValueError")
+ ("runtime_error", "RuntimeError")
+ ("not_implemented_error", "RuntimeError: NotImplementedError")
+ ("usb_error", "RuntimeError: USBError 1")
+ ("environment_error", "EnvironmentError")
+ ("io_error", "EnvironmentError: IOError")
+ ("os_error", "EnvironmentError: OSError")
+ ("system_error", "SystemError")
+ ;
+
+#define UHD_TEST_CHECK_ERROR_CODE(cpp_exception_type, c_error_code) \
+ expected_msg = str(boost::format("This is a uhd::%s.") % BOOST_STRINGIZE(cpp_exception_type)); \
+ uhd::cpp_exception_type cpp_exception_type ## _foo(expected_msg); \
+ error_code = throw_uhd_exception<uhd::cpp_exception_type>(&handle, &cpp_exception_type ## _foo); \
+ BOOST_CHECK_EQUAL(error_code, c_error_code); \
+ expected_msg = str(boost::format("%s: %s") \
+ % pretty_exception_names.get(BOOST_STRINGIZE(cpp_exception_type)) \
+ % expected_msg); \
+ BOOST_CHECK_EQUAL(handle.last_error, expected_msg); \
+ BOOST_CHECK_EQUAL(get_c_global_error_string(), expected_msg);
+
+// uhd::usb_error has a different constructor
+#define UHD_TEST_CHECK_USB_ERROR_CODE() \
+ expected_msg = "This is a uhd::usb_error."; \
+ uhd::usb_error usb_error_foo(1, expected_msg); \
+ error_code = throw_uhd_exception<uhd::usb_error>(&handle, &usb_error_foo); \
+ BOOST_CHECK_EQUAL(error_code, UHD_ERROR_USB); \
+ expected_msg = str(boost::format("%s: %s") \
+ % pretty_exception_names.get("usb_error") \
+ % expected_msg); \
+ BOOST_CHECK_EQUAL(handle.last_error, expected_msg); \
+ BOOST_CHECK_EQUAL(get_c_global_error_string(), expected_msg);
+
+BOOST_AUTO_TEST_CASE(test_uhd_exception){
+ dummy_handle_t handle;
+ std::string expected_msg;
+ uhd_error error_code;
+
+ UHD_TEST_CHECK_ERROR_CODE(assertion_error, UHD_ERROR_ASSERTION);
+ UHD_TEST_CHECK_ERROR_CODE(lookup_error, UHD_ERROR_LOOKUP);
+ UHD_TEST_CHECK_ERROR_CODE(index_error, UHD_ERROR_INDEX);
+ UHD_TEST_CHECK_ERROR_CODE(key_error, UHD_ERROR_KEY);
+ UHD_TEST_CHECK_ERROR_CODE(type_error, UHD_ERROR_TYPE);
+ UHD_TEST_CHECK_ERROR_CODE(value_error, UHD_ERROR_VALUE);
+ UHD_TEST_CHECK_ERROR_CODE(runtime_error, UHD_ERROR_RUNTIME);
+ UHD_TEST_CHECK_ERROR_CODE(not_implemented_error, UHD_ERROR_NOT_IMPLEMENTED);
+ UHD_TEST_CHECK_ERROR_CODE(io_error, UHD_ERROR_IO);
+ UHD_TEST_CHECK_ERROR_CODE(os_error, UHD_ERROR_OS);
+ UHD_TEST_CHECK_ERROR_CODE(system_error, UHD_ERROR_SYSTEM);
+ UHD_TEST_CHECK_USB_ERROR_CODE();
+}
+
+BOOST_AUTO_TEST_CASE(test_boost_exception){
+ dummy_handle_t handle;
+ uhd_error error_code = throw_boost_exception(&handle);
+
+ // Boost error message cannot be determined here, so just check code
+ BOOST_CHECK_EQUAL(error_code, UHD_ERROR_BOOSTEXCEPT);
+}
+
+BOOST_AUTO_TEST_CASE(test_std_exception){
+ dummy_handle_t handle;
+ uhd_error error_code = throw_std_exception(&handle);
+
+ BOOST_CHECK_EQUAL(error_code, UHD_ERROR_STDEXCEPT);
+ BOOST_CHECK_EQUAL(handle.last_error, "This is a std::runtime_error.");
+}
+
+BOOST_AUTO_TEST_CASE(test_unknown_exception){
+ dummy_handle_t handle;
+ uhd_error error_code = throw_unknown_exception(&handle);
+
+ BOOST_CHECK_EQUAL(error_code, UHD_ERROR_UNKNOWN);
+ BOOST_CHECK_EQUAL(handle.last_error, "Unrecognized exception caught.");
+}
diff --git a/host/tests/fp_compare_delta_test.cpp b/host/tests/fp_compare_delta_test.cpp
index 0ac4e257d..36ff14756 100644
--- a/host/tests/fp_compare_delta_test.cpp
+++ b/host/tests/fp_compare_delta_test.cpp
@@ -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/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/ranges_c_test.c b/host/tests/ranges_c_test.c
new file mode 100644
index 000000000..da9c86a48
--- /dev/null
+++ b/host/tests/ranges_c_test.c
@@ -0,0 +1,236 @@
+//
+// Copyright 2015 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.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+#define UHD_TEST_EXECUTE_OR_GOTO(label, ...) \
+ if(__VA_ARGS__){ \
+ fprintf(stderr, "Error occurred at %s:%d\n", __FILE__, (__LINE__-1)); \
+ return_code = EXIT_FAILURE; \
+ goto label; \
+ }
+
+#define UHD_TEST_CHECK_CLOSE(lhs, rhs) (fabs(lhs-rhs) < 0.001)
+
+#define BUFFER_SIZE 1024
+
+static UHD_INLINE int test_range_values(
+ const uhd_range_t *range,
+ double start_input, double stop_input, double step_input
+){
+ if(!UHD_TEST_CHECK_CLOSE(range->start, start_input)){
+ fprintf(stderr, "%s:%d: Starts did not match: %f vs. %f\n",
+ __FILE__, __LINE__,
+ range->start, start_input);
+ return 1;
+ }
+ if(!UHD_TEST_CHECK_CLOSE(range->stop, stop_input)){
+ fprintf(stderr, "%s:%d: Stops did not match: %f vs. %f\n",
+ __FILE__, __LINE__,
+ range->stop, stop_input);
+ return 1;
+ }
+ if(!UHD_TEST_CHECK_CLOSE(range->step, step_input)){
+ fprintf(stderr, "%s:%d: Steps did not match: %f vs. %f\n",
+ __FILE__, __LINE__,
+ range->step, step_input);
+ return 1;
+ }
+
+ return 0;
+}
+
+static UHD_INLINE int test_meta_range_values(
+ uhd_meta_range_handle meta_range,
+ double start_input, double stop_input, double step_input,
+ double start_test, double stop_test, double step_test
+){
+ // Add range
+ uhd_range_t range;
+ range.start = start_input;
+ range.stop = stop_input;
+ range.step = step_input;
+ if(uhd_meta_range_push_back(meta_range, &range)){
+ fprintf(stderr, "%s:%d: Failed to push back range.\n",
+ __FILE__, __LINE__);
+ return 1;
+ }
+
+ // Test bounds
+ uhd_meta_range_start(meta_range, &range.start);
+ if(!UHD_TEST_CHECK_CLOSE(range.start, start_test)){
+ fprintf(stderr, "%s:%d: Starts did not match: %f vs. %f\n",
+ __FILE__, __LINE__,
+ range.start, start_test);
+ return 1;
+ }
+ uhd_meta_range_stop(meta_range, &range.stop);
+ if(!UHD_TEST_CHECK_CLOSE(range.stop, stop_test)){
+ fprintf(stderr, "%s:%d: Stops did not match: %f vs. %f\n",
+ __FILE__, __LINE__,
+ range.stop, stop_test);
+ return 1;
+ }
+ uhd_meta_range_step(meta_range, &range.step);
+ if(!UHD_TEST_CHECK_CLOSE(range.step, step_test)){
+ fprintf(stderr, "%s:%d: Steps did not match: %f vs. %f\n",
+ __FILE__, __LINE__,
+ range.step, step_test);
+ return 1;
+ }
+
+ return 0;
+}
+
+static UHD_INLINE int test_meta_range_clip(
+ uhd_meta_range_handle meta_range,
+ double clip_value, double test_value,
+ bool clip_step
+){
+ double clip_result;
+
+ uhd_meta_range_clip(meta_range, clip_value, clip_step, &clip_result);
+ if(!UHD_TEST_CHECK_CLOSE(test_value, clip_result)){
+ fprintf(stderr, "%s:%d: Values did not match: %f vs. %f\n",
+ __FILE__, __LINE__,
+ test_value, clip_result);
+ return 1;
+ }
+
+ return 0;
+}
+
+int main(){
+
+ // Variables
+ int return_code;
+ uhd_range_t range;
+ uhd_meta_range_handle meta_range1, meta_range2;
+ char str_buffer[BUFFER_SIZE];
+ size_t size;
+
+ return_code = EXIT_SUCCESS;
+
+ // Create meta range 1
+ UHD_TEST_EXECUTE_OR_GOTO(end_of_test,
+ uhd_meta_range_make(&meta_range1)
+ )
+
+ // Test bounds
+ UHD_TEST_EXECUTE_OR_GOTO(free_meta_range1,
+ test_meta_range_values(meta_range1, -1.0, +1.0, 0.1,
+ -1.0, +1.0, 0.1)
+ )
+ UHD_TEST_EXECUTE_OR_GOTO(free_meta_range1,
+ test_meta_range_values(meta_range1, 40.0, 60.0, 1.0,
+ -1.0, 60.0, 0.1)
+ )
+ uhd_meta_range_at(meta_range1, 0, &range);
+ UHD_TEST_EXECUTE_OR_GOTO(free_meta_range1,
+ test_range_values(&range, -1.0, +1.0, 0.1)
+ )
+
+ // Check meta range size
+ UHD_TEST_EXECUTE_OR_GOTO(free_meta_range1,
+ uhd_meta_range_size(meta_range1, &size)
+ )
+ if(size != 2){
+ fprintf(stderr, "%s:%d: Invalid size: %lu vs. 2",
+ __FILE__, __LINE__,
+ size);
+ goto free_meta_range1;
+ }
+
+ // Test clipping (with steps)
+ UHD_TEST_EXECUTE_OR_GOTO(free_meta_range1,
+ test_meta_range_clip(meta_range1, -30.0, -1.0, false)
+ )
+ UHD_TEST_EXECUTE_OR_GOTO(free_meta_range1,
+ test_meta_range_clip(meta_range1, 70.0, 60.0, false)
+ )
+ UHD_TEST_EXECUTE_OR_GOTO(free_meta_range1,
+ test_meta_range_clip(meta_range1, 20.0, 1.0, false)
+ )
+ UHD_TEST_EXECUTE_OR_GOTO(free_meta_range1,
+ test_meta_range_clip(meta_range1, 50.0, 50.0, false)
+ )
+ UHD_TEST_EXECUTE_OR_GOTO(free_meta_range1,
+ test_meta_range_clip(meta_range1, 50.9, 50.9, false)
+ )
+ UHD_TEST_EXECUTE_OR_GOTO(free_meta_range1,
+ test_meta_range_clip(meta_range1, 50.9, 51.0, true)
+ )
+
+ // Create meta range 2
+ UHD_TEST_EXECUTE_OR_GOTO(free_meta_range1,
+ uhd_meta_range_make(&meta_range2)
+ )
+ range.step = 0.0;
+ range.start = range.stop = 1.;
+ UHD_TEST_EXECUTE_OR_GOTO(free_meta_range2,
+ uhd_meta_range_push_back(meta_range2, &range)
+ )
+ range.start = range.stop = 2.;
+ UHD_TEST_EXECUTE_OR_GOTO(free_meta_range2,
+ uhd_meta_range_push_back(meta_range2, &range)
+ )
+ range.start = range.stop = 3.;
+ UHD_TEST_EXECUTE_OR_GOTO(free_meta_range2,
+ uhd_meta_range_push_back(meta_range2, &range)
+ )
+
+ // Test clipping (without steps)
+ UHD_TEST_EXECUTE_OR_GOTO(free_meta_range2,
+ test_meta_range_clip(meta_range2, 2., 2., true)
+ )
+ UHD_TEST_EXECUTE_OR_GOTO(free_meta_range2,
+ test_meta_range_clip(meta_range2, 0., 1., true)
+ )
+ UHD_TEST_EXECUTE_OR_GOTO(free_meta_range2,
+ test_meta_range_clip(meta_range2, 1.2, 1., true)
+ )
+ UHD_TEST_EXECUTE_OR_GOTO(free_meta_range2,
+ test_meta_range_clip(meta_range2, 3.1, 3., true)
+ )
+ UHD_TEST_EXECUTE_OR_GOTO(free_meta_range2,
+ test_meta_range_clip(meta_range2, 4., 3., true)
+ )
+
+ free_meta_range2:
+ if(return_code){
+ uhd_meta_range_last_error(meta_range2, str_buffer, BUFFER_SIZE);
+ fprintf(stderr, "meta_range2 error: %s\n", str_buffer);
+ }
+ uhd_meta_range_free(&meta_range1);
+
+ free_meta_range1:
+ if(return_code){
+ uhd_meta_range_last_error(meta_range1, str_buffer, BUFFER_SIZE);
+ fprintf(stderr, "meta_range1 error: %s\n", str_buffer);
+ }
+ uhd_meta_range_free(&meta_range1);
+
+ end_of_test:
+ if(!return_code){
+ printf("\nNo errors detected.\n");
+ }
+ return return_code;
+}
diff --git a/host/tests/sensors_c_test.c b/host/tests/sensors_c_test.c
new file mode 100644
index 000000000..8babe905a
--- /dev/null
+++ b/host/tests/sensors_c_test.c
@@ -0,0 +1,411 @@
+//
+// Copyright 2015 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.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+#define UHD_TEST_EXECUTE_OR_GOTO(label, ...) \
+ if(__VA_ARGS__){ \
+ fprintf(stderr, "Error occurred at %s:%d\n", __FILE__, (__LINE__-1)); \
+ return_code = EXIT_FAILURE; \
+ goto label; \
+ }
+
+#define UHD_TEST_CHECK_CLOSE(lhs, rhs) (fabs(lhs-rhs) < 0.001)
+
+#define BUFFER_SIZE 1024
+
+int main(){
+
+ // Variables
+ int return_code;
+ uhd_sensor_value_handle boolean_sensor, integer_sensor, realnum_sensor, string_sensor;
+ uhd_sensor_value_data_type_t sensor_type;
+ bool bool_out;
+ int int_out;
+ double realnum_out;
+ char str_buffer[BUFFER_SIZE];
+
+ return_code = EXIT_SUCCESS;
+
+ /*
+ * Test a sensor made from a boolean
+ */
+
+ // Create the sensor
+ UHD_TEST_EXECUTE_OR_GOTO(end_of_test,
+ uhd_sensor_value_make_from_bool(
+ &boolean_sensor,
+ "Bool sensor", false,
+ "True", "False"
+ )
+ )
+
+ // Check the name
+ UHD_TEST_EXECUTE_OR_GOTO(free_boolean_sensor,
+ uhd_sensor_value_name(
+ boolean_sensor,
+ str_buffer, BUFFER_SIZE
+ )
+ )
+ if(strcmp(str_buffer, "Bool sensor")){
+ fprintf(stderr, "%s:%d: Boolean sensor name invalid: \"%s\" vs. \"false\"\n",
+ __FILE__, __LINE__, str_buffer);
+ return_code = EXIT_FAILURE;
+ goto free_boolean_sensor;
+ }
+
+ // Check the value
+ UHD_TEST_EXECUTE_OR_GOTO(free_boolean_sensor,
+ uhd_sensor_value_value(
+ boolean_sensor,
+ str_buffer, BUFFER_SIZE
+ )
+ )
+ if(strcmp(str_buffer, "false")){
+ fprintf(stderr, "%s:%d: Boolean sensor value invalid: \"%s\" vs. \"false\"\n",
+ __FILE__, __LINE__, str_buffer);
+ return_code = EXIT_FAILURE;
+ goto free_boolean_sensor;
+ }
+
+ // Check the unit
+ UHD_TEST_EXECUTE_OR_GOTO(free_boolean_sensor,
+ uhd_sensor_value_unit(
+ boolean_sensor,
+ str_buffer, BUFFER_SIZE
+ )
+ )
+ if(strcmp(str_buffer, "False")){
+ fprintf(stderr, "%s:%d: Boolean sensor unit invalid: \"%s\" vs. \"False\"\n",
+ __FILE__, __LINE__, str_buffer);
+ return_code = EXIT_FAILURE;
+ goto free_boolean_sensor;
+ }
+
+ // Check the type
+ UHD_TEST_EXECUTE_OR_GOTO(free_boolean_sensor,
+ uhd_sensor_value_data_type(
+ boolean_sensor,
+ &sensor_type
+ )
+ )
+ if(sensor_type != UHD_SENSOR_VALUE_BOOLEAN){
+ fprintf(stderr, "%s:%d: Wrong sensor type detected: %d vs. %d\n",
+ __FILE__, __LINE__,
+ sensor_type, UHD_SENSOR_VALUE_BOOLEAN);
+ return_code = EXIT_FAILURE;
+ goto free_boolean_sensor;
+ }
+
+ // Check the casted value
+ UHD_TEST_EXECUTE_OR_GOTO(free_boolean_sensor,
+ uhd_sensor_value_to_bool(
+ boolean_sensor,
+ &bool_out
+ )
+ )
+ if(bool_out){
+ fprintf(stderr, "%s:%d: Boolean sensor value invalid: true vs. false\n",
+ __FILE__, __LINE__);
+ return_code = EXIT_FAILURE;
+ goto free_boolean_sensor;
+ }
+
+ /*
+ * Test a sensor made from a integer
+ */
+
+ // Create the sensor
+ UHD_TEST_EXECUTE_OR_GOTO(free_boolean_sensor,
+ uhd_sensor_value_make_from_int(
+ &integer_sensor,
+ "Int sensor", 50,
+ "Int type", "%d"
+ )
+ )
+
+ // Check the name
+ UHD_TEST_EXECUTE_OR_GOTO(free_integer_sensor,
+ uhd_sensor_value_name(
+ integer_sensor,
+ str_buffer, BUFFER_SIZE
+ )
+ )
+ if(strcmp(str_buffer, "Int sensor")){
+ fprintf(stderr, "%s:%d: Integer sensor name invalid: \"%s\" vs. \"Int sensor\"\n",
+ __FILE__, __LINE__, str_buffer);
+ return_code = EXIT_FAILURE;
+ goto free_integer_sensor;
+ }
+
+ // Check the value
+ UHD_TEST_EXECUTE_OR_GOTO(free_integer_sensor,
+ uhd_sensor_value_value(
+ integer_sensor,
+ str_buffer, BUFFER_SIZE
+ )
+ )
+ if(strcmp(str_buffer, "50")){
+ fprintf(stderr, "%s:%d: Integer sensor value invalid: \"%s\" vs. \"50\"\n",
+ __FILE__, __LINE__, str_buffer);
+ return_code = EXIT_FAILURE;
+ goto free_integer_sensor;
+ }
+
+ // Check the unit
+ UHD_TEST_EXECUTE_OR_GOTO(free_integer_sensor,
+ uhd_sensor_value_unit(
+ integer_sensor,
+ str_buffer, BUFFER_SIZE
+ )
+ )
+ if(strcmp(str_buffer, "Int type")){
+ fprintf(stderr, "%s:%d: Integer sensor unit invalid: \"%s\" vs. \"Int type\"\n",
+ __FILE__, __LINE__, str_buffer);
+ return_code = EXIT_FAILURE;
+ goto free_integer_sensor;
+ }
+
+ // Check the type
+ UHD_TEST_EXECUTE_OR_GOTO(free_integer_sensor,
+ uhd_sensor_value_data_type(
+ integer_sensor,
+ &sensor_type
+ )
+ )
+ if(sensor_type != UHD_SENSOR_VALUE_INTEGER){
+ fprintf(stderr, "%s:%d: Wrong sensor type detected: %d vs. %d\n",
+ __FILE__, __LINE__,
+ sensor_type, UHD_SENSOR_VALUE_INTEGER);
+ return_code = EXIT_FAILURE;
+ goto free_integer_sensor;
+ }
+
+ // Check the casted value
+ UHD_TEST_EXECUTE_OR_GOTO(free_integer_sensor,
+ uhd_sensor_value_to_int(
+ integer_sensor,
+ &int_out
+ )
+ )
+ if(int_out != 50){
+ fprintf(stderr, "%s:%d: Integer sensor value invalid: %d vs. 50\n",
+ __FILE__, __LINE__,
+ int_out);
+ return_code = EXIT_FAILURE;
+ goto free_integer_sensor;
+ }
+
+ /*
+ * Test a sensor made from a real number
+ */
+
+ // Create the sensor
+ UHD_TEST_EXECUTE_OR_GOTO(free_integer_sensor,
+ uhd_sensor_value_make_from_realnum(
+ &realnum_sensor,
+ "Realnum sensor", 50.0,
+ "Realnum type", "%d"
+ )
+ )
+
+ // Check the name
+ UHD_TEST_EXECUTE_OR_GOTO(free_realnum_sensor,
+ uhd_sensor_value_name(
+ realnum_sensor,
+ str_buffer, BUFFER_SIZE
+ )
+ )
+ if(strcmp(str_buffer, "Realnum sensor")){
+ fprintf(stderr, "%s:%d: Realnum sensor name invalid: \"%s\" vs. \"Realnum sensor\"\n",
+ __FILE__, __LINE__, str_buffer);
+ return_code = EXIT_FAILURE;
+ goto free_realnum_sensor;
+ }
+
+ // Check the value
+ UHD_TEST_EXECUTE_OR_GOTO(free_realnum_sensor,
+ uhd_sensor_value_value(
+ realnum_sensor,
+ str_buffer, BUFFER_SIZE
+ )
+ )
+ if(strcmp(str_buffer, "50")){
+ fprintf(stderr, "%s:%d: Realnum sensor value invalid: \"%s\" vs. \"50\"\n",
+ __FILE__, __LINE__, str_buffer);
+ return_code = EXIT_FAILURE;
+ goto free_realnum_sensor;
+ }
+
+ // Check the unit
+ UHD_TEST_EXECUTE_OR_GOTO(free_realnum_sensor,
+ uhd_sensor_value_unit(
+ realnum_sensor,
+ str_buffer, BUFFER_SIZE
+ )
+ )
+ if(strcmp(str_buffer, "Realnum type")){
+ fprintf(stderr, "%s:%d: Realnum sensor unit invalid: \"%s\" vs. \"Realnum type\"\n",
+ __FILE__, __LINE__, str_buffer);
+ return_code = EXIT_FAILURE;
+ goto free_realnum_sensor;
+ }
+
+ // Check the type
+ UHD_TEST_EXECUTE_OR_GOTO(free_realnum_sensor,
+ uhd_sensor_value_data_type(
+ realnum_sensor,
+ &sensor_type
+ )
+ )
+ if(sensor_type != UHD_SENSOR_VALUE_REALNUM){
+ fprintf(stderr, "%s:%d: Wrong sensor type detected: %d vs. %d\n",
+ __FILE__, __LINE__,
+ sensor_type, UHD_SENSOR_VALUE_REALNUM);
+ return_code = EXIT_FAILURE;
+ goto free_realnum_sensor;
+ }
+
+ // Check the casted value
+ UHD_TEST_EXECUTE_OR_GOTO(free_realnum_sensor,
+ uhd_sensor_value_to_realnum(
+ realnum_sensor,
+ &realnum_out
+ )
+ )
+ if(realnum_out != 50.0){
+ fprintf(stderr, "%s:%d: Realnum sensor value invalid: %2.1f vs. 50.0\n",
+ __FILE__, __LINE__,
+ realnum_out);
+ return_code = EXIT_FAILURE;
+ goto free_realnum_sensor;
+ }
+
+ /*
+ * Test a sensor made from a string
+ */
+
+ // Create the sensor
+ UHD_TEST_EXECUTE_OR_GOTO(free_realnum_sensor,
+ uhd_sensor_value_make_from_string(
+ &string_sensor,
+ "String sensor",
+ "String value",
+ "String unit"
+ )
+ )
+
+ // Check the name
+ UHD_TEST_EXECUTE_OR_GOTO(free_string_sensor,
+ uhd_sensor_value_name(
+ string_sensor,
+ str_buffer, BUFFER_SIZE
+ )
+ )
+ if(strcmp(str_buffer, "String sensor")){
+ fprintf(stderr, "%s:%d: String sensor name invalid: \"%s\" vs. \"String sensor\"\n",
+ __FILE__, __LINE__, str_buffer);
+ return_code = EXIT_FAILURE;
+ goto free_string_sensor;
+ }
+
+ // Check the value
+ UHD_TEST_EXECUTE_OR_GOTO(free_string_sensor,
+ uhd_sensor_value_value(
+ string_sensor,
+ str_buffer, BUFFER_SIZE
+ )
+ )
+ if(strcmp(str_buffer, "String value")){
+ fprintf(stderr, "%s:%d: String sensor value invalid: \"%s\" vs. \"String value\"\n",
+ __FILE__, __LINE__, str_buffer);
+ return_code = EXIT_FAILURE;
+ goto free_string_sensor;
+ }
+
+ // Check the unit
+ UHD_TEST_EXECUTE_OR_GOTO(free_string_sensor,
+ uhd_sensor_value_unit(
+ string_sensor,
+ str_buffer, BUFFER_SIZE
+ )
+ )
+ if(strcmp(str_buffer, "String unit")){
+ fprintf(stderr, "%s:%d: String sensor unit invalid: \"%s\" vs. \"String unit\"\n",
+ __FILE__, __LINE__, str_buffer);
+ return_code = EXIT_FAILURE;
+ goto free_string_sensor;
+ }
+
+ // Check the type
+ UHD_TEST_EXECUTE_OR_GOTO(free_string_sensor,
+ uhd_sensor_value_data_type(
+ string_sensor,
+ &sensor_type
+ )
+ )
+ if(sensor_type != UHD_SENSOR_VALUE_STRING){
+ fprintf(stderr, "%s:%d: Wrong sensor type detected: %d vs. %d\n",
+ __FILE__, __LINE__,
+ sensor_type, UHD_SENSOR_VALUE_STRING);
+ return_code = EXIT_FAILURE;
+ goto free_string_sensor;
+ }
+
+ /*
+ * Cleanup
+ */
+
+ free_string_sensor:
+ if(return_code){
+ uhd_sensor_value_last_error(string_sensor, str_buffer, BUFFER_SIZE);
+ fprintf(stderr, "string_sensor error: %s\n", str_buffer);
+ }
+ uhd_sensor_value_free(&string_sensor);
+
+ free_realnum_sensor:
+ if(return_code){
+ uhd_sensor_value_last_error(realnum_sensor, str_buffer, BUFFER_SIZE);
+ fprintf(stderr, "realnum_sensor error: %s\n", str_buffer);
+ }
+ uhd_sensor_value_free(&realnum_sensor);
+
+ free_integer_sensor:
+ if(return_code){
+ uhd_sensor_value_last_error(integer_sensor, str_buffer, BUFFER_SIZE);
+ fprintf(stderr, "integer_sensor error: %s\n", str_buffer);
+ }
+ uhd_sensor_value_free(&integer_sensor);
+
+ free_boolean_sensor:
+ if(return_code){
+ uhd_sensor_value_last_error(boolean_sensor, str_buffer, BUFFER_SIZE);
+ fprintf(stderr, "boolean_sensor error: %s\n", str_buffer);
+ }
+ uhd_sensor_value_free(&boolean_sensor);
+
+ end_of_test:
+ if(!return_code){
+ printf("\nNo errors detected.\n");
+ }
+ return return_code;
+}
diff --git a/host/tests/sid_t_test.cpp b/host/tests/sid_t_test.cpp
new file mode 100644
index 000000000..31eb4b458
--- /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(), (boost::uint32_t)0x0102);
+ BOOST_CHECK_EQUAL(sid.get_dst(), (boost::uint32_t)0x0310);
+ BOOST_CHECK_EQUAL(sid.get_src_addr(), (boost::uint32_t)0x01);
+ BOOST_CHECK_EQUAL(sid.get_src_endpoint(), (boost::uint32_t)0x02);
+ BOOST_CHECK_EQUAL(sid.get_dst_addr(), (boost::uint32_t)0x03);
+ BOOST_CHECK_EQUAL(sid.get_dst_endpoint(), (boost::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(), (boost::uint32_t)0x01020304);
+ BOOST_CHECK_EQUAL(sid.get_src_addr(),(boost::uint32_t)0x01);
+ BOOST_CHECK_EQUAL(sid.get_src_endpoint(), (boost::uint32_t)0x02);
+ BOOST_CHECK_EQUAL(sid.get_dst_addr(), (boost::uint32_t)0x03);
+ BOOST_CHECK_EQUAL(sid.get_dst_endpoint(), (boost::uint32_t)0x04);
+ BOOST_CHECK_EQUAL(sid.get_dst_xbarport(), (boost::uint32_t)0x0);
+ BOOST_CHECK_EQUAL(sid.get_dst_blockport(), (boost::uint32_t)0x4);
+
+ sid.set_src_addr(0x0a);
+ BOOST_CHECK_EQUAL(sid.get(), (boost::uint32_t)0x0a020304);
+ BOOST_CHECK_EQUAL(sid.get_src_addr(), (boost::uint32_t)0x0a);
+ BOOST_CHECK_EQUAL(sid.get_src_endpoint(), (boost::uint32_t)0x02);
+ BOOST_CHECK_EQUAL(sid.get_dst_addr(), (boost::uint32_t)0x03);
+ BOOST_CHECK_EQUAL(sid.get_dst_endpoint(), (boost::uint32_t)0x04);
+
+ sid.set_src_endpoint(0x0b);
+ BOOST_CHECK_EQUAL(sid.get(), (boost::uint32_t)0x0a0b0304);
+ BOOST_CHECK_EQUAL(sid.get_src_addr(), (boost::uint32_t)0x0a);
+ BOOST_CHECK_EQUAL(sid.get_src_endpoint(), (boost::uint32_t)0x0b);
+ BOOST_CHECK_EQUAL(sid.get_dst_addr(), (boost::uint32_t)0x03);
+ BOOST_CHECK_EQUAL(sid.get_dst_endpoint(), (boost::uint32_t)0x04);
+
+ sid.set_dst_addr(0x0c);
+ BOOST_CHECK_EQUAL(sid.get(), (boost::uint32_t)0x0a0b0c04);
+ BOOST_CHECK_EQUAL(sid.get_src_addr(), (boost::uint32_t)0x0a);
+ BOOST_CHECK_EQUAL(sid.get_src_endpoint(), (boost::uint32_t)0x0b);
+ BOOST_CHECK_EQUAL(sid.get_dst_addr(), (boost::uint32_t)0x0c);
+ BOOST_CHECK_EQUAL(sid.get_dst_endpoint(), (boost::uint32_t)0x04);
+
+ sid.set_dst_endpoint(0x0d);
+ BOOST_CHECK_EQUAL(sid.get(), (boost::uint32_t)0x0a0b0c0d);
+ BOOST_CHECK_EQUAL(sid.get_src_addr(), (boost::uint32_t)0x0a);
+ BOOST_CHECK_EQUAL(sid.get_src_endpoint(), (boost::uint32_t)0x0b);
+ BOOST_CHECK_EQUAL(sid.get_dst_addr(), (boost::uint32_t)0x0c);
+ BOOST_CHECK_EQUAL(sid.get_dst_endpoint(), (boost::uint32_t)0x0d);
+
+ sid.set_dst_xbarport(0xb);
+ BOOST_CHECK_EQUAL(sid.get(), (boost::uint32_t)0x0a0b0cbd);
+ BOOST_CHECK_EQUAL(sid.get_src_addr(), (boost::uint32_t)0x0a);
+ BOOST_CHECK_EQUAL(sid.get_src_endpoint(), (boost::uint32_t)0x0b);
+ BOOST_CHECK_EQUAL(sid.get_dst_addr(), (boost::uint32_t)0x0c);
+ BOOST_CHECK_EQUAL(sid.get_dst_endpoint(), (boost::uint32_t)0xbd);
+
+ sid.set_dst_blockport(0xc);
+ BOOST_CHECK_EQUAL(sid.get(), (boost::uint32_t)0x0a0b0cbc);
+ BOOST_CHECK_EQUAL(sid.get_src_addr(), (boost::uint32_t)0x0a);
+ BOOST_CHECK_EQUAL(sid.get_src_endpoint(), (boost::uint32_t)0x0b);
+ BOOST_CHECK_EQUAL(sid.get_dst_addr(), (boost::uint32_t)0x0c);
+ BOOST_CHECK_EQUAL(sid.get_dst_endpoint(), (boost::uint32_t)0xbc);
+
+ sid_t flipped_sid = sid.reversed();
+ BOOST_CHECK_EQUAL(flipped_sid.get(), (boost::uint32_t)0x0cbc0a0b);
+
+ // In-place
+ sid.reverse();
+ BOOST_CHECK_EQUAL(sid.get(), (boost::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(), (boost::uint32_t)1);
+ BOOST_CHECK_EQUAL(sid.get_src_endpoint(), (boost::uint32_t)2);
+ BOOST_CHECK_EQUAL(sid.get_dst_addr(), (boost::uint32_t)3);
+ BOOST_CHECK_EQUAL(sid.get_dst_endpoint(), (boost::uint32_t)4);
+
+ sid = "01:02>03:10";
+ BOOST_CHECK_EQUAL(sid.get_src_addr(), (boost::uint32_t)1);
+ BOOST_CHECK_EQUAL(sid.get_src_endpoint(), (boost::uint32_t)2);
+ BOOST_CHECK_EQUAL(sid.get_dst_addr(), (boost::uint32_t)3);
+ BOOST_CHECK_EQUAL(sid.get_dst_endpoint(), (boost::uint32_t)16);
+
+ sid = "01:06/03:10";
+ BOOST_CHECK_EQUAL(sid.get_src_addr(), (boost::uint32_t)1);
+ BOOST_CHECK_EQUAL(sid.get_src_endpoint(), (boost::uint32_t)6);
+ BOOST_CHECK_EQUAL(sid.get_dst_addr(), (boost::uint32_t)3);
+ BOOST_CHECK_EQUAL(sid.get_dst_endpoint(), (boost::uint32_t)16);
+
+ sid = "01:02:04:10";
+ BOOST_CHECK_EQUAL(sid.get_src_addr(), (boost::uint32_t)1);
+ BOOST_CHECK_EQUAL(sid.get_src_endpoint(), (boost::uint32_t)2);
+ BOOST_CHECK_EQUAL(sid.get_dst_addr(), (boost::uint32_t)4);
+ BOOST_CHECK_EQUAL(sid.get_dst_endpoint(), (boost::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/string_vector_c_test.c b/host/tests/string_vector_c_test.c
new file mode 100644
index 000000000..fe055fd91
--- /dev/null
+++ b/host/tests/string_vector_c_test.c
@@ -0,0 +1,90 @@
+//
+// Copyright 2015 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.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define UHD_TEST_EXECUTE_OR_GOTO(label, ...) \
+ if(__VA_ARGS__){ \
+ fprintf(stderr, "Error occurred at %s:%d\n", __FILE__, (__LINE__-1)); \
+ return_code = EXIT_FAILURE; \
+ goto label; \
+ }
+
+#define BUFFER_SIZE 1024
+
+int main(){
+
+ // Variables
+ int return_code;
+ uhd_string_vector_handle string_vector;
+ size_t size;
+ char str_buffer[BUFFER_SIZE];
+
+ return_code = EXIT_SUCCESS;
+
+ // Create string_vector
+ UHD_TEST_EXECUTE_OR_GOTO(end_of_test,
+ uhd_string_vector_make(&string_vector)
+ )
+
+ // Add values
+ UHD_TEST_EXECUTE_OR_GOTO(free_string_vector,
+ uhd_string_vector_push_back(&string_vector, "foo")
+ )
+ UHD_TEST_EXECUTE_OR_GOTO(free_string_vector,
+ uhd_string_vector_push_back(&string_vector, "bar")
+ )
+
+ // Check size
+ UHD_TEST_EXECUTE_OR_GOTO(free_string_vector,
+ uhd_string_vector_size(string_vector, &size)
+ )
+ if(size != 2){
+ return_code = EXIT_FAILURE;
+ fprintf(stderr, "%s:%d: Invalid size: %lu vs. 2",
+ __FILE__, __LINE__,size);
+ goto free_string_vector;
+ }
+
+ // Make sure we get right value
+ UHD_TEST_EXECUTE_OR_GOTO(free_string_vector,
+ uhd_string_vector_at(string_vector, 1, str_buffer, BUFFER_SIZE)
+ )
+ if(strcmp(str_buffer, "bar")){
+ return_code = EXIT_FAILURE;
+ fprintf(stderr, "%s:%d: Mismatched daughterboard serial: \"%s\" vs. \"key3=value3,key4=value4\"\n",
+ __FILE__, __LINE__,
+ str_buffer);
+ }
+
+ free_string_vector:
+ if(return_code){
+ uhd_string_vector_last_error(string_vector, str_buffer, BUFFER_SIZE);
+ fprintf(stderr, "string_vector error: %s\n", str_buffer);
+ }
+ uhd_string_vector_free(&string_vector);
+
+ end_of_test:
+ if(!return_code){
+ printf("\nNo errors detected\n");
+ }
+ return return_code;
+}
diff --git a/host/tests/subdev_spec_c_test.c b/host/tests/subdev_spec_c_test.c
new file mode 100644
index 000000000..7663ba357
--- /dev/null
+++ b/host/tests/subdev_spec_c_test.c
@@ -0,0 +1,130 @@
+//
+// Copyright 2015 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.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#define UHD_TEST_EXECUTE_OR_GOTO(label, ...) \
+ if(__VA_ARGS__){ \
+ fprintf(stderr, "Error occurred at %s:%d\n", __FILE__, (__LINE__-1)); \
+ return_code = EXIT_FAILURE; \
+ goto label; \
+ }
+
+#define BUFFER_SIZE 1024
+
+int main(){
+
+ // Variables
+ int return_code;
+ uhd_subdev_spec_pair_t subdev_spec_pair1, subdev_spec_pair2;
+ uhd_subdev_spec_handle subdev_spec1, subdev_spec2;
+ size_t size1, size2, i;
+ bool pairs_equal;
+ char str_buffer[BUFFER_SIZE];
+
+ printf("Testing subdevice specification...\n");
+ return_code = EXIT_SUCCESS;
+
+ // Create subdev spec
+ UHD_TEST_EXECUTE_OR_GOTO(end_of_test,
+ uhd_subdev_spec_make(&subdev_spec1, "A:AB B:AB")
+ )
+
+ // Convert to and from args string
+ UHD_TEST_EXECUTE_OR_GOTO(free_subdev_spec1,
+ uhd_subdev_spec_to_pp_string(subdev_spec1, str_buffer, BUFFER_SIZE)
+ )
+ printf("Pretty Print:\n%s", str_buffer);
+
+ UHD_TEST_EXECUTE_OR_GOTO(free_subdev_spec1,
+ uhd_subdev_spec_to_string(subdev_spec1, str_buffer, BUFFER_SIZE)
+ )
+ printf("Markup String: %s\n", str_buffer);
+
+ // Make a second subdev spec from the first's markup string
+ UHD_TEST_EXECUTE_OR_GOTO(free_subdev_spec2,
+ uhd_subdev_spec_make(&subdev_spec2, str_buffer)
+ )
+
+ // Make sure both subdev specs are equal
+ UHD_TEST_EXECUTE_OR_GOTO(free_subdev_spec2,
+ uhd_subdev_spec_size(subdev_spec1, &size1)
+ )
+ UHD_TEST_EXECUTE_OR_GOTO(free_subdev_spec2,
+ uhd_subdev_spec_size(subdev_spec2, &size2)
+ )
+ if(size1 != size2){
+ printf("%s:%d: Sizes do not match. %lu vs. %lu\n", __FILE__, __LINE__, size1, size2);
+ return_code = EXIT_FAILURE;
+ goto free_subdev_spec2;
+ }
+ for(i = 0; i < size1; i++){
+ UHD_TEST_EXECUTE_OR_GOTO(free_subdev_spec_pair1,
+ uhd_subdev_spec_at(subdev_spec1, i, &subdev_spec_pair1)
+ )
+ UHD_TEST_EXECUTE_OR_GOTO(free_subdev_spec_pair2,
+ uhd_subdev_spec_at(subdev_spec2, i, &subdev_spec_pair2)
+ )
+ UHD_TEST_EXECUTE_OR_GOTO(free_subdev_spec_pair2,
+ uhd_subdev_spec_pairs_equal(&subdev_spec_pair1, &subdev_spec_pair2, &pairs_equal)
+ )
+ if(!pairs_equal){
+ printf("%s:%d: Subdev spec pairs are not equal.\n"
+ " db_name: %s vs. %s\n"
+ " sd_name: %s vs. %s\n",
+ __FILE__, __LINE__,
+ subdev_spec_pair1.db_name, subdev_spec_pair2.db_name,
+ subdev_spec_pair1.sd_name, subdev_spec_pair2.sd_name
+ );
+ return_code = EXIT_FAILURE;
+ goto free_subdev_spec_pair2;
+ }
+ uhd_subdev_spec_pair_free(&subdev_spec_pair1);
+ uhd_subdev_spec_pair_free(&subdev_spec_pair2);
+ }
+
+ // Cleanup (and error report, if needed)
+
+ free_subdev_spec_pair2:
+ uhd_subdev_spec_pair_free(&subdev_spec_pair2);
+
+ free_subdev_spec_pair1:
+ uhd_subdev_spec_pair_free(&subdev_spec_pair1);
+
+ free_subdev_spec2:
+ if(return_code){
+ uhd_subdev_spec_last_error(subdev_spec2, str_buffer, BUFFER_SIZE);
+ fprintf(stderr, "subdev_spec2 error: %s\n", str_buffer);
+ }
+ uhd_subdev_spec_free(&subdev_spec2);
+
+ free_subdev_spec1:
+ if(return_code){
+ uhd_subdev_spec_last_error(subdev_spec1, str_buffer, BUFFER_SIZE);
+ fprintf(stderr, "subdev_spec1 error: %s\n", str_buffer);
+ }
+ uhd_subdev_spec_free(&subdev_spec1);
+
+ end_of_test:
+ if(!return_code){
+ printf("\nNo errors detected.\n");
+ }
+ return return_code;
+}
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;