diff options
Diffstat (limited to 'host/test')
-rw-r--r-- | host/test/CMakeLists.txt | 39 | ||||
-rw-r--r-- | host/test/addr_test.cpp | 80 | ||||
-rw-r--r-- | host/test/buffer_test.cpp | 115 | ||||
-rw-r--r-- | host/test/byteswap_test.cpp | 39 | ||||
-rw-r--r-- | host/test/convert_types_test.cpp | 125 | ||||
-rw-r--r-- | host/test/dict_test.cpp | 72 | ||||
-rw-r--r-- | host/test/error_test.cpp | 48 | ||||
-rw-r--r-- | host/test/gain_handler_test.cpp | 121 | ||||
-rw-r--r-- | host/test/main_test.cpp | 3 | ||||
-rw-r--r-- | host/test/module_test.cpp | 26 | ||||
-rw-r--r-- | host/test/vrt_test.cpp | 102 | ||||
-rw-r--r-- | host/test/wax_test.cpp | 104 |
12 files changed, 874 insertions, 0 deletions
diff --git a/host/test/CMakeLists.txt b/host/test/CMakeLists.txt new file mode 100644 index 000000000..74f3376e6 --- /dev/null +++ b/host/test/CMakeLists.txt @@ -0,0 +1,39 @@ +# +# Copyright 2010 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/>. +# + +######################################################################## +# unit test suite +######################################################################## +ADD_EXECUTABLE(main_test + main_test.cpp + addr_test.cpp + buffer_test.cpp + byteswap_test.cpp + convert_types_test.cpp + dict_test.cpp + error_test.cpp + gain_handler_test.cpp + vrt_test.cpp + wax_test.cpp +) +TARGET_LINK_LIBRARIES(main_test uhd) +ADD_TEST(test main_test) + +######################################################################## +# demo of a loadable module +######################################################################## +ADD_LIBRARY(module_test MODULE module_test.cpp) diff --git a/host/test/addr_test.cpp b/host/test/addr_test.cpp new file mode 100644 index 000000000..0c50200d6 --- /dev/null +++ b/host/test/addr_test.cpp @@ -0,0 +1,80 @@ +// +// Copyright 2010 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 <uhd/types/mac_addr.hpp> +#include <uhd/types/device_addr.hpp> +#include <uhd/usrp/dboard_id.hpp> +#include <boost/assign/list_of.hpp> +#include <boost/foreach.hpp> +#include <algorithm> +#include <iostream> + +BOOST_AUTO_TEST_CASE(test_mac_addr){ + std::cout << "Testing mac addr..." << std::endl; + const std::string mac_addr_str("00:01:23:45:67:89"); + uhd::mac_addr_t mac_addr = uhd::mac_addr_t::from_string(mac_addr_str); + std::cout << "Input: " << mac_addr_str << std::endl; + std::cout << "Output: " << mac_addr.to_string() << std::endl; + BOOST_CHECK_EQUAL(mac_addr_str, mac_addr.to_string()); +} + +BOOST_AUTO_TEST_CASE(test_device_addr){ + std::cout << "Testing device addr..." << std::endl; + + //load the device address with something + uhd::device_addr_t dev_addr; + dev_addr["key1"] = "val1"; + dev_addr["key2"] = "val2"; + + //convert to and from args string + std::cout << "Pretty Print: " << std::endl << dev_addr.to_pp_string(); + std::string args_str = dev_addr.to_string(); + std::cout << "Args String: " << args_str << std::endl; + uhd::device_addr_t new_dev_addr(args_str); + + //they should be the same size + BOOST_CHECK_EQUAL(dev_addr.size(), new_dev_addr.size()); + + //the keys should match + std::vector<std::string> old_dev_addr_keys = dev_addr.keys(); + std::vector<std::string> new_dev_addr_keys = new_dev_addr.keys(); + BOOST_CHECK_EQUAL_COLLECTIONS( + old_dev_addr_keys.begin(), old_dev_addr_keys.end(), + new_dev_addr_keys.begin(), new_dev_addr_keys.end() + ); + + //the vals should match + std::vector<std::string> old_dev_addr_vals = dev_addr.vals(); + std::vector<std::string> new_dev_addr_vals = new_dev_addr.vals(); + BOOST_CHECK_EQUAL_COLLECTIONS( + old_dev_addr_vals.begin(), old_dev_addr_vals.end(), + new_dev_addr_vals.begin(), new_dev_addr_vals.end() + ); +} + +BOOST_AUTO_TEST_CASE(test_dboard_id){ + std::cout << "Testing dboard id..." << std::endl; + + using namespace uhd::usrp; + + BOOST_CHECK(dboard_id_t() == dboard_id_t::none()); + BOOST_CHECK_EQUAL(dboard_id_t().to_uint16(), dboard_id_t::none().to_uint16()); + BOOST_CHECK_EQUAL(dboard_id_t::from_string("0x1234").to_uint16(), 0x1234); + BOOST_CHECK_EQUAL(dboard_id_t::from_string("1234").to_uint16(), 1234); + std::cout << "Pretty Print: " << std::endl << dboard_id_t::none().to_pp_string(); +} diff --git a/host/test/buffer_test.cpp b/host/test/buffer_test.cpp new file mode 100644 index 000000000..aadb3f951 --- /dev/null +++ b/host/test/buffer_test.cpp @@ -0,0 +1,115 @@ +// +// Copyright 2010 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 <uhd/transport/bounded_buffer.hpp> +#include <uhd/transport/alignment_buffer.hpp> +#include <boost/assign/list_of.hpp> + +using namespace boost::assign; +using namespace uhd::transport; + +static const boost::posix_time::milliseconds timeout(10); + +BOOST_AUTO_TEST_CASE(test_bounded_buffer_with_timed_wait){ + bounded_buffer<int>::sptr bb(bounded_buffer<int>::make(3)); + + //push elements, check for timeout + BOOST_CHECK(bb->push_with_timed_wait(0, timeout)); + BOOST_CHECK(bb->push_with_timed_wait(1, timeout)); + BOOST_CHECK(bb->push_with_timed_wait(2, timeout)); + BOOST_CHECK(not bb->push_with_timed_wait(3, timeout)); + + int val; + //pop elements, check for timeout and check values + BOOST_CHECK(bb->pop_with_timed_wait(val, timeout)); + BOOST_CHECK_EQUAL(val, 0); + BOOST_CHECK(bb->pop_with_timed_wait(val, timeout)); + BOOST_CHECK_EQUAL(val, 1); + BOOST_CHECK(bb->pop_with_timed_wait(val, timeout)); + BOOST_CHECK_EQUAL(val, 2); + BOOST_CHECK(not bb->pop_with_timed_wait(val, timeout)); +} + +BOOST_AUTO_TEST_CASE(test_bounded_buffer_with_pop_on_full){ + bounded_buffer<int>::sptr bb(bounded_buffer<int>::make(3)); + + //push elements, check for timeout + BOOST_CHECK(bb->push_with_pop_on_full(0)); + BOOST_CHECK(bb->push_with_pop_on_full(1)); + BOOST_CHECK(bb->push_with_pop_on_full(2)); + BOOST_CHECK(not bb->push_with_pop_on_full(3)); + + int val; + //pop elements, check for timeout and check values + BOOST_CHECK(bb->pop_with_timed_wait(val, timeout)); + BOOST_CHECK_EQUAL(val, 1); + BOOST_CHECK(bb->pop_with_timed_wait(val, timeout)); + BOOST_CHECK_EQUAL(val, 2); + BOOST_CHECK(bb->pop_with_timed_wait(val, timeout)); + BOOST_CHECK_EQUAL(val, 3); +} + +BOOST_AUTO_TEST_CASE(test_alignment_buffer){ + alignment_buffer<int, size_t>::sptr ab(alignment_buffer<int, size_t>::make(7, 3)); + //load index 0 with all good seq numbers + BOOST_CHECK(ab->push_with_pop_on_full(0, 0, 0)); + BOOST_CHECK(ab->push_with_pop_on_full(1, 1, 0)); + BOOST_CHECK(ab->push_with_pop_on_full(2, 2, 0)); + BOOST_CHECK(ab->push_with_pop_on_full(3, 3, 0)); + BOOST_CHECK(ab->push_with_pop_on_full(4, 4, 0)); + + //load index 1 with some skipped seq numbers + BOOST_CHECK(ab->push_with_pop_on_full(10, 0, 1)); + BOOST_CHECK(ab->push_with_pop_on_full(11, 1, 1)); + BOOST_CHECK(ab->push_with_pop_on_full(14, 4, 1)); + BOOST_CHECK(ab->push_with_pop_on_full(15, 5, 1)); + BOOST_CHECK(ab->push_with_pop_on_full(16, 6, 1)); + + //load index 2 with all good seq numbers + BOOST_CHECK(ab->push_with_pop_on_full(20, 0, 2)); + BOOST_CHECK(ab->push_with_pop_on_full(21, 1, 2)); + BOOST_CHECK(ab->push_with_pop_on_full(22, 2, 2)); + BOOST_CHECK(ab->push_with_pop_on_full(23, 3, 2)); + BOOST_CHECK(ab->push_with_pop_on_full(24, 4, 2)); + + //readback aligned values + std::vector<int> aligned_elems(3); + + static const std::vector<int> expected_elems0 = list_of(0)(10)(20); + BOOST_CHECK(ab->pop_elems_with_timed_wait(aligned_elems, timeout)); + BOOST_CHECK_EQUAL_COLLECTIONS( + aligned_elems.begin(), aligned_elems.end(), + expected_elems0.begin(), expected_elems0.end() + ); + + static const std::vector<int> expected_elems1 = list_of(1)(11)(21); + BOOST_CHECK(ab->pop_elems_with_timed_wait(aligned_elems, timeout)); + BOOST_CHECK_EQUAL_COLLECTIONS( + aligned_elems.begin(), aligned_elems.end(), + expected_elems1.begin(), expected_elems1.end() + ); + + //there was a skip now find 4 + + static const std::vector<int> expected_elems4 = list_of(4)(14)(24); + BOOST_CHECK(ab->pop_elems_with_timed_wait(aligned_elems, timeout)); + BOOST_CHECK_EQUAL_COLLECTIONS( + aligned_elems.begin(), aligned_elems.end(), + expected_elems4.begin(), expected_elems4.end() + ); +} diff --git a/host/test/byteswap_test.cpp b/host/test/byteswap_test.cpp new file mode 100644 index 000000000..3d50c9bfa --- /dev/null +++ b/host/test/byteswap_test.cpp @@ -0,0 +1,39 @@ +// +// Copyright 2010 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 <uhd/utils/byteswap.hpp> + +BOOST_AUTO_TEST_CASE(test_byteswap16){ + boost::uint16_t x = 0x0123; + boost::uint16_t y = 0x2301; + BOOST_CHECK_EQUAL(uhd::byteswap(x), y); +} + +BOOST_AUTO_TEST_CASE(test_byteswap32){ + boost::uint32_t x = 0x01234567; + boost::uint32_t y = 0x67452301; + BOOST_CHECK_EQUAL(uhd::byteswap(x), y); +} + +BOOST_AUTO_TEST_CASE(test_byteswap64){ + //split up 64 bit constants to avoid long-long compiler warnings + boost::uint64_t x = 0x01234567 | (boost::uint64_t(0x89abcdef) << 32); + boost::uint64_t y = 0xefcdab89 | (boost::uint64_t(0x67452301) << 32); + BOOST_CHECK_EQUAL(uhd::byteswap(x), y); +} + diff --git a/host/test/convert_types_test.cpp b/host/test/convert_types_test.cpp new file mode 100644 index 000000000..1587be57f --- /dev/null +++ b/host/test/convert_types_test.cpp @@ -0,0 +1,125 @@ +// +// Copyright 2010 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/convert_types.hpp> +#include <boost/test/unit_test.hpp> +#include <boost/cstdint.hpp> +#include <complex> + +using namespace uhd; + +template <typename host_type, typename dev_type, size_t nsamps> +void loopback( + const io_type_t &io_type, + const otw_type_t &otw_type, + const host_type *input, + host_type *output +){ + dev_type dev[nsamps]; + + //convert to dev type + transport::convert_io_type_to_otw_type( + input, io_type, + dev, otw_type, + nsamps + ); + + //convert back to host type + transport::convert_otw_type_to_io_type( + dev, otw_type, + output, io_type, + nsamps + ); +} + +typedef std::complex<boost::uint16_t> sc16_t; + +BOOST_AUTO_TEST_CASE(test_convert_types_be_sc16){ + sc16_t in_sc16[] = { + sc16_t(0, -1234), sc16_t(4321, 1234), + sc16_t(9876, -4567), sc16_t(8912, 0) + }, out_sc16[4]; + + io_type_t io_type(io_type_t::COMPLEX_INT16); + otw_type_t otw_type; + otw_type.byteorder = otw_type_t::BO_BIG_ENDIAN; + otw_type.width = 16; + + loopback<sc16_t, boost::uint32_t, 4>(io_type, otw_type, in_sc16, out_sc16); + BOOST_CHECK_EQUAL_COLLECTIONS(in_sc16, in_sc16+4, out_sc16, out_sc16+4); +} + +BOOST_AUTO_TEST_CASE(test_convert_types_le_sc16){ + sc16_t in_sc16[] = { + sc16_t(0, -1234), sc16_t(4321, 1234), + sc16_t(9876, -4567), sc16_t(8912, 0) + }, out_sc16[4]; + + io_type_t io_type(io_type_t::COMPLEX_INT16); + otw_type_t otw_type; + otw_type.byteorder = otw_type_t::BO_LITTLE_ENDIAN; + otw_type.width = 16; + + loopback<sc16_t, boost::uint32_t, 4>(io_type, otw_type, in_sc16, out_sc16); + BOOST_CHECK_EQUAL_COLLECTIONS(in_sc16, in_sc16+4, out_sc16, out_sc16+4); +} + +typedef std::complex<float> fc32_t; + +#define BOOST_CHECK_CLOSE_COMPLEX(a1, a2, p) \ + BOOST_CHECK_CLOSE(a1.real(), a2.real(), p); \ + BOOST_CHECK_CLOSE(a1.imag(), a2.imag(), p); + +static const float tolerance = float(0.1); + +BOOST_AUTO_TEST_CASE(test_convert_types_be_fc32){ + fc32_t in_fc32[] = { + fc32_t(float(0), float(-0.2)), fc32_t(float(0.03), float(-0.16)), + fc32_t(float(1.0), float(.45)), fc32_t(float(0.09), float(0)) + }, out_fc32[4]; + + io_type_t io_type(io_type_t::COMPLEX_FLOAT32); + otw_type_t otw_type; + otw_type.byteorder = otw_type_t::BO_BIG_ENDIAN; + otw_type.width = 16; + + loopback<fc32_t, boost::uint32_t, 4>(io_type, otw_type, in_fc32, out_fc32); + + BOOST_CHECK_CLOSE_COMPLEX(in_fc32[0], out_fc32[0], tolerance); + BOOST_CHECK_CLOSE_COMPLEX(in_fc32[1], out_fc32[1], tolerance); + BOOST_CHECK_CLOSE_COMPLEX(in_fc32[2], out_fc32[2], tolerance); + BOOST_CHECK_CLOSE_COMPLEX(in_fc32[3], out_fc32[3], tolerance); +} + +BOOST_AUTO_TEST_CASE(test_convert_types_le_fc32){ + fc32_t in_fc32[] = { + fc32_t(float(0), float(-0.2)), fc32_t(float(0.03), float(-0.16)), + fc32_t(float(1.0), float(.45)), fc32_t(float(0.09), float(0)) + }, out_fc32[4]; + + io_type_t io_type(io_type_t::COMPLEX_FLOAT32); + otw_type_t otw_type; + otw_type.byteorder = otw_type_t::BO_LITTLE_ENDIAN; + otw_type.width = 16; + + loopback<fc32_t, boost::uint32_t, 4>(io_type, otw_type, in_fc32, out_fc32); + + BOOST_CHECK_CLOSE_COMPLEX(in_fc32[0], out_fc32[0], tolerance); + BOOST_CHECK_CLOSE_COMPLEX(in_fc32[1], out_fc32[1], tolerance); + BOOST_CHECK_CLOSE_COMPLEX(in_fc32[2], out_fc32[2], tolerance); + BOOST_CHECK_CLOSE_COMPLEX(in_fc32[3], out_fc32[3], tolerance); +} diff --git a/host/test/dict_test.cpp b/host/test/dict_test.cpp new file mode 100644 index 000000000..0501a7878 --- /dev/null +++ b/host/test/dict_test.cpp @@ -0,0 +1,72 @@ +// +// Copyright 2010 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 <uhd/types/dict.hpp> +#include <boost/assign/list_of.hpp> + +BOOST_AUTO_TEST_CASE(test_dict_init){ + uhd::dict<int, int> d; + d[-1] = 3; + d[0] = 4; + d[1] = 5; + BOOST_CHECK(d.has_key(0)); + BOOST_CHECK(not d.has_key(2)); + BOOST_CHECK(d.keys()[1] == 0); + BOOST_CHECK(d.vals()[1] == 4); + BOOST_CHECK_EQUAL(d[-1], 3); +} + +BOOST_AUTO_TEST_CASE(test_dict_assign){ + uhd::dict<int, int> d = boost::assign::map_list_of + (-1, 3) + (0, 4) + (1, 5) + ; + BOOST_CHECK(d.has_key(0)); + BOOST_CHECK(not d.has_key(2)); + BOOST_CHECK(d.keys()[1] == 0); + BOOST_CHECK(d.vals()[1] == 4); + BOOST_CHECK_EQUAL(d[-1], 3); +} + +BOOST_AUTO_TEST_CASE(test_const_dict){ + const uhd::dict<int, int> d = boost::assign::map_list_of + (-1, 3) + (0, 4) + (1, 5) + ; + BOOST_CHECK(d.has_key(0)); + BOOST_CHECK(not d.has_key(2)); + BOOST_CHECK(d.keys()[1] == 0); + BOOST_CHECK(d.vals()[1] == 4); + BOOST_CHECK_EQUAL(d[-1], 3); + BOOST_CHECK_THROW(d[2], std::exception); +} + +BOOST_AUTO_TEST_CASE(test_dict_pop){ + uhd::dict<int, int> d = boost::assign::map_list_of + (-1, 3) + (0, 4) + (1, 5) + ; + BOOST_CHECK(d.has_key(0)); + BOOST_CHECK_EQUAL(d.pop(0), 4); + BOOST_CHECK(not d.has_key(0)); + BOOST_CHECK(d.keys()[0] == -1); + BOOST_CHECK(d.keys()[1] == 1); +} diff --git a/host/test/error_test.cpp b/host/test/error_test.cpp new file mode 100644 index 000000000..c76a15ab7 --- /dev/null +++ b/host/test/error_test.cpp @@ -0,0 +1,48 @@ +// +// Copyright 2010 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 <uhd/utils/assert.hpp> +#include <vector> +#include <iostream> + +BOOST_AUTO_TEST_CASE(test_assert_has){ + std::vector<int> vec; + vec.push_back(2); + vec.push_back(3); + vec.push_back(5); + + //verify the std::has utility + BOOST_CHECK(std::has(vec, 2)); + BOOST_CHECK(not std::has(vec, 1)); + + std::cout << "The output of the assert_has error:" << std::endl; + try{ + uhd::assert_has(vec, 1, "prime"); + }catch(const std::exception &e){ + std::cout << e.what() << std::endl; + } +} + +BOOST_AUTO_TEST_CASE(test_assert_throw){ + std::cout << "The output of the assert throw error:" << std::endl; + try{ + UHD_ASSERT_THROW(2 + 2 == 5); + }catch(const std::exception &e){ + std::cout << e.what() << std::endl; + } +} diff --git a/host/test/gain_handler_test.cpp b/host/test/gain_handler_test.cpp new file mode 100644 index 000000000..5a9f2b714 --- /dev/null +++ b/host/test/gain_handler_test.cpp @@ -0,0 +1,121 @@ +// +// Copyright 2010 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 <uhd/utils/gain_handler.hpp> +#include <uhd/types/ranges.hpp> +#include <uhd/types/dict.hpp> +#include <uhd/utils/props.hpp> +#include <boost/bind.hpp> +#include <iostream> + +using namespace uhd; + +enum prop_t{ + PROP_GAIN_VALUE, + PROP_GAIN_RANGE, + PROP_GAIN_NAMES +}; + +class gainful_obj : public wax::obj{ +public: + gainful_obj(void){ + //initialize gain props struct + gain_handler::props_t gain_props; + gain_props.value = PROP_GAIN_VALUE; + gain_props.range = PROP_GAIN_RANGE; + gain_props.names = PROP_GAIN_NAMES; + //make a new gain handler + _gain_handler = gain_handler::make( + this->get_link(), gain_props, + boost::bind(&gain_handler::is_equal<prop_t>, _1, _2) + ); + _gain_values["g0"] = 0; + _gain_values["g1"] = 0; + _gain_ranges["g0"] = gain_range_t(-10, 0, float(.1)); + _gain_ranges["g1"] = gain_range_t(0, 100, float(1.5)); + } + + ~gainful_obj(void){} + +private: + void get(const wax::obj &key_, wax::obj &val){ + if (_gain_handler->intercept_get(key_, val)) return; + + wax::obj key; std::string name; + boost::tie(key, name) = extract_named_prop(key_); + + //handle the get request conditioned on the key + switch(key.as<prop_t>()){ + case PROP_GAIN_VALUE: + val = _gain_values[name]; + return; + + case PROP_GAIN_RANGE: + val = _gain_ranges[name]; + return; + + case PROP_GAIN_NAMES: + val = _gain_values.keys(); + return; + + default: UHD_THROW_PROP_GET_ERROR(); + } + } + + void set(const wax::obj &key_, const wax::obj &val){ + if (_gain_handler->intercept_set(key_, val)) return; + + wax::obj key; std::string name; + boost::tie(key, name) = extract_named_prop(key_); + + //handle the get request conditioned on the key + switch(key.as<prop_t>()){ + case PROP_GAIN_VALUE: + _gain_values[name] = val.as<float>(); + return; + + default: UHD_THROW_PROP_SET_ERROR(); + } + } + + gain_handler::sptr _gain_handler; + uhd::dict<std::string, float> _gain_values; + uhd::dict<std::string, gain_range_t> _gain_ranges; + +}; + +BOOST_AUTO_TEST_CASE(test_gain_handler){ + std::cout << "Testing the gain handler..." << std::endl; + gainful_obj go0; + + BOOST_CHECK_THROW( + go0[named_prop_t(PROP_GAIN_VALUE, "fail")].as<float>(), + std::exception + ); + + std::cout << "verifying the overall min, max, step" << std::endl; + gain_range_t gain = go0[PROP_GAIN_RANGE].as<gain_range_t>(); + BOOST_CHECK_EQUAL(gain.min, float(-10)); + BOOST_CHECK_EQUAL(gain.max, float(100)); + BOOST_CHECK_EQUAL(gain.step, float(1.5)); + + std::cout << "verifying the overall gain" << std::endl; + go0[named_prop_t(PROP_GAIN_VALUE, "g0")] = float(-5); + go0[named_prop_t(PROP_GAIN_VALUE, "g1")] = float(30); + BOOST_CHECK_EQUAL(go0[PROP_GAIN_VALUE].as<float>(), float(25)); +} diff --git a/host/test/main_test.cpp b/host/test/main_test.cpp new file mode 100644 index 000000000..0b47303b7 --- /dev/null +++ b/host/test/main_test.cpp @@ -0,0 +1,3 @@ +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MAIN +#include <boost/test/unit_test.hpp> diff --git a/host/test/module_test.cpp b/host/test/module_test.cpp new file mode 100644 index 000000000..47a0e1af9 --- /dev/null +++ b/host/test/module_test.cpp @@ -0,0 +1,26 @@ +// +// Copyright 2010 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/utils/static.hpp> +#include <iostream> + +UHD_STATIC_BLOCK(module_test){ + std::cout << "---------------------------------------" << std::endl; + std::cout << "-- Good news, everyone!" << std::endl; + std::cout << "-- The test module has been loaded." << std::endl; + std::cout << "---------------------------------------" << std::endl; +} diff --git a/host/test/vrt_test.cpp b/host/test/vrt_test.cpp new file mode 100644 index 000000000..3e596164c --- /dev/null +++ b/host/test/vrt_test.cpp @@ -0,0 +1,102 @@ +// +// Copyright 2010 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 <uhd/transport/vrt.hpp> + +using namespace uhd::transport; + +static void pack_and_unpack( + const uhd::tx_metadata_t &metadata, + size_t num_payload_words32, + size_t packet_count +){ + boost::uint32_t header_buff[vrt::max_header_words32]; + size_t num_header_words32; + size_t num_packet_words32; + + //pack metadata into a vrt header + vrt::pack_be( + metadata, //input + header_buff, //output + num_header_words32, //output + num_payload_words32, //input + num_packet_words32, //output + packet_count, //input + 100e6 + ); + + uhd::rx_metadata_t metadata_out; + size_t num_header_words32_out; + size_t num_payload_words32_out; + size_t packet_count_out; + + //unpack the vrt header back into metadata + vrt::unpack_be( + metadata_out, //output + header_buff, //input + num_header_words32_out, //output + num_payload_words32_out, //output + num_packet_words32, //input + packet_count_out, //output + 100e6 + ); + + //check the the unpacked metadata is the same + BOOST_CHECK_EQUAL(packet_count, packet_count_out); + BOOST_CHECK_EQUAL(num_header_words32, num_header_words32_out); + BOOST_CHECK_EQUAL(num_payload_words32, num_payload_words32_out); + BOOST_CHECK_EQUAL(metadata.has_stream_id, metadata_out.has_stream_id); + if (metadata.has_stream_id and metadata_out.has_stream_id){ + BOOST_CHECK_EQUAL(metadata.stream_id, metadata_out.stream_id); + } + BOOST_CHECK_EQUAL(metadata.has_time_spec, metadata_out.has_time_spec); + if (metadata.has_time_spec and metadata_out.has_time_spec){ + BOOST_CHECK_EQUAL(metadata.time_spec.secs, metadata_out.time_spec.secs); + BOOST_CHECK_EQUAL(metadata.time_spec.nsecs, metadata_out.time_spec.nsecs); + } +} + +BOOST_AUTO_TEST_CASE(test_with_none){ + uhd::tx_metadata_t metadata; + pack_and_unpack(metadata, 300, 1); +} + +BOOST_AUTO_TEST_CASE(test_with_sid){ + uhd::tx_metadata_t metadata; + metadata.has_stream_id = true; + metadata.stream_id = 6; + pack_and_unpack(metadata, 400, 2); +} + +BOOST_AUTO_TEST_CASE(test_with_time_spec){ + uhd::tx_metadata_t metadata; + metadata.has_time_spec = true; + metadata.time_spec.secs = 7; + metadata.time_spec.nsecs = 2000; + pack_and_unpack(metadata, 500, 3); +} + +BOOST_AUTO_TEST_CASE(test_with_sid_and_time_spec){ + uhd::tx_metadata_t metadata; + metadata.has_stream_id = true; + metadata.stream_id = 2; + metadata.has_time_spec = true; + metadata.time_spec.secs = 5; + metadata.time_spec.nsecs = 1000; + pack_and_unpack(metadata, 600, 4); +} diff --git a/host/test/wax_test.cpp b/host/test/wax_test.cpp new file mode 100644 index 000000000..731f470ed --- /dev/null +++ b/host/test/wax_test.cpp @@ -0,0 +1,104 @@ +// +// Copyright 2010 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/shared_ptr.hpp> +#include <uhd/wax.hpp> +#include <iostream> + +enum opt_a_t{OPTION_A_0, OPTION_A_1}; +enum opt_b_t{OPTION_B_0, OPTION_B_1}; + +BOOST_AUTO_TEST_CASE(test_enums){ + wax::obj opta = OPTION_A_0; + BOOST_CHECK_THROW(opta.as<opt_b_t>(), wax::bad_cast); + BOOST_CHECK_EQUAL(opta.as<opt_a_t>(), OPTION_A_0); +} + +/*********************************************************************** + * demo class for wax framework + **********************************************************************/ +class wax_demo : public wax::obj{ +public: + typedef boost::shared_ptr<wax_demo> sptr; + + wax_demo(size_t sub_demos, size_t len){ + d_nums = std::vector<float>(len); + if (sub_demos != 0){ + for (size_t i = 0; i < len; i++){ + d_subs.push_back(sptr(new wax_demo(sub_demos-1, len))); + } + } + } + ~wax_demo(void){ + /* NOP */ + } +private: + std::vector<float> d_nums; + std::vector<sptr> d_subs; + + void get(const wax::obj &key, wax::obj &value){ + if (d_subs.size() == 0){ + value = d_nums[key.as<size_t>()]; + }else{ + value = d_subs[key.as<size_t>()]->get_link(); + } + } + void set(const wax::obj &key, const wax::obj &value){ + if (d_subs.size() == 0){ + d_nums[key.as<size_t>()] = value.as<float>(); + }else{ + throw std::runtime_error("cant set to a wax demo with sub demos"); + } + } +}; + +BOOST_AUTO_TEST_CASE(test_chaining){ + wax_demo wd(2, 1); + std::cout << "chain 1" << std::endl; + wd[size_t(0)]; + std::cout << "chain 2" << std::endl; + wd[size_t(0)][size_t(0)]; + std::cout << "chain 3" << std::endl; + wd[size_t(0)][size_t(0)][size_t(0)]; +} + +BOOST_AUTO_TEST_CASE(test_set_get){ + wax_demo wd(2, 10); + std::cout << "set and get all" << std::endl; + for (size_t i = 0; i < 10; i++){ + for (size_t j = 0; j < 10; j++){ + for (size_t k = 0; k < 10; k++){ + float val = float(i * j * k + i + j + k); + //std::cout << i << " " << j << " " << k << std::endl; + wd[i][j][k] = val; + BOOST_CHECK_EQUAL(val, wd[i][j][k].as<float>()); + } + } + } +} + +BOOST_AUTO_TEST_CASE(test_proxy){ + wax_demo wd(2, 1); + std::cout << "store proxy" << std::endl; + wax::obj p = wd[size_t(0)][size_t(0)]; + p[size_t(0)] = float(5); + + std::cout << "assign proxy" << std::endl; + wax::obj a = p[size_t(0)]; + BOOST_CHECK_EQUAL(a.as<float>(), float(5)); +} |