diff options
Diffstat (limited to 'host/test')
-rw-r--r-- | host/test/CMakeLists.txt | 12 | ||||
-rw-r--r-- | host/test/gain_handler_test.cpp | 87 | ||||
-rw-r--r-- | host/test/module_test.cpp | 26 | ||||
-rw-r--r-- | host/test/vrt_test.cpp | 100 | ||||
-rw-r--r-- | host/test/wax_test.cpp | 17 |
5 files changed, 184 insertions, 58 deletions
diff --git a/host/test/CMakeLists.txt b/host/test/CMakeLists.txt index 234b6f92c..1791d9082 100644 --- a/host/test/CMakeLists.txt +++ b/host/test/CMakeLists.txt @@ -15,14 +15,20 @@ # 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 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/gain_handler_test.cpp b/host/test/gain_handler_test.cpp index c81221aac..47acb30f0 100644 --- a/host/test/gain_handler_test.cpp +++ b/host/test/gain_handler_test.cpp @@ -17,33 +17,37 @@ #include <boost/test/unit_test.hpp> #include <uhd/gain_handler.hpp> +#include <uhd/types.hpp> +#include <uhd/props.hpp> #include <uhd/dict.hpp> +#include <boost/bind.hpp> #include <iostream> using namespace uhd; enum prop_t{ - PROP_GAIN, - PROP_GAIN_MIN, - PROP_GAIN_MAX, - PROP_GAIN_STEP, + PROP_GAIN_VALUE, + PROP_GAIN_RANGE, PROP_GAIN_NAMES }; class gainful_obj : public wax::obj{ public: gainful_obj(void){ - _gain_handler = gain_handler::sptr(new gain_handler( - this, PROP_GAIN, PROP_GAIN_MIN, PROP_GAIN_MAX, PROP_GAIN_STEP, PROP_GAIN_NAMES - )); - _gains["g0"] = 0; - _gains["g1"] = 0; - _gains_min["g0"] = -10; - _gains_min["g1"] = 0; - _gains_max["g0"] = 0; - _gains_max["g1"] = 100; - _gains_step["g0"] = .1; - _gains_step["g1"] = 1.5; + //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, .1); + _gain_ranges["g1"] = gain_range_t(0, 100, 1.5); } ~gainful_obj(void){} @@ -56,25 +60,17 @@ private: boost::tie(key, name) = extract_named_prop(key_); //handle the get request conditioned on the key - switch(wax::cast<prop_t>(key)){ - case PROP_GAIN: - val = _gains[name]; + switch(key.as<prop_t>()){ + case PROP_GAIN_VALUE: + val = _gain_values[name]; return; - case PROP_GAIN_MIN: - val = _gains_min[name]; - return; - - case PROP_GAIN_MAX: - val = _gains_max[name]; - return; - - case PROP_GAIN_STEP: - val = _gains_step[name]; + case PROP_GAIN_RANGE: + val = _gain_ranges[name]; return; case PROP_GAIN_NAMES: - val = prop_names_t(_gains.get_keys()); + val = _gain_values.get_keys(); return; } } @@ -86,24 +82,20 @@ private: boost::tie(key, name) = extract_named_prop(key_); //handle the get request conditioned on the key - switch(wax::cast<prop_t>(key)){ - case PROP_GAIN: - _gains[name] = wax::cast<gain_t>(val); + switch(key.as<prop_t>()){ + case PROP_GAIN_VALUE: + _gain_values[name] = val.as<gain_t>(); return; - case PROP_GAIN_MIN: - case PROP_GAIN_MAX: - case PROP_GAIN_STEP: + case PROP_GAIN_RANGE: case PROP_GAIN_NAMES: throw std::runtime_error("cannot set this property"); } } gain_handler::sptr _gain_handler; - uhd::dict<std::string, gain_t> _gains; - uhd::dict<std::string, gain_t> _gains_min; - uhd::dict<std::string, gain_t> _gains_max; - uhd::dict<std::string, gain_t> _gains_step; + uhd::dict<std::string, gain_t> _gain_values; + uhd::dict<std::string, gain_range_t> _gain_ranges; }; @@ -112,17 +104,18 @@ BOOST_AUTO_TEST_CASE(test_gain_handler){ gainful_obj go0; BOOST_CHECK_THROW( - wax::cast<gain_t>(go0[named_prop_t(PROP_GAIN, "fail")]), - std::invalid_argument + go0[named_prop_t(PROP_GAIN_VALUE, "fail")].as<gain_t>(), + std::exception ); std::cout << "verifying the overall min, max, step" << std::endl; - BOOST_CHECK_EQUAL(wax::cast<gain_t>(go0[PROP_GAIN_MIN]), gain_t(-10)); - BOOST_CHECK_EQUAL(wax::cast<gain_t>(go0[PROP_GAIN_MAX]), gain_t(100)); - BOOST_CHECK_EQUAL(wax::cast<gain_t>(go0[PROP_GAIN_STEP]), gain_t(1.5)); + gain_range_t gain = go0[PROP_GAIN_RANGE].as<gain_range_t>(); + BOOST_CHECK_EQUAL(gain.min, gain_t(-10)); + BOOST_CHECK_EQUAL(gain.max, gain_t(100)); + BOOST_CHECK_EQUAL(gain.step, gain_t(1.5)); std::cout << "verifying the overall gain" << std::endl; - go0[named_prop_t(PROP_GAIN, "g0")] = gain_t(-5); - go0[named_prop_t(PROP_GAIN, "g1")] = gain_t(30); - BOOST_CHECK_EQUAL(wax::cast<gain_t>(go0[PROP_GAIN]), gain_t(25)); + go0[named_prop_t(PROP_GAIN_VALUE, "g0")] = gain_t(-5); + go0[named_prop_t(PROP_GAIN_VALUE, "g1")] = gain_t(30); + BOOST_CHECK_EQUAL(go0[PROP_GAIN_VALUE].as<gain_t>(), gain_t(25)); } diff --git a/host/test/module_test.cpp b/host/test/module_test.cpp new file mode 100644 index 000000000..71721ef90 --- /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.hpp> +#include <iostream> + +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..40116e110 --- /dev/null +++ b/host/test/vrt_test.cpp @@ -0,0 +1,100 @@ +// +// 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( + metadata, //input + header_buff, //output + num_header_words32, //output + num_payload_words32, //input + num_packet_words32, //output + packet_count //input + ); + + 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( + metadata_out, //output + header_buff, //input + num_header_words32_out, //output + num_payload_words32_out, //output + num_packet_words32, //input + packet_count_out //output + ); + + //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.ticks, metadata_out.time_spec.ticks); + } +} + +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.ticks = 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.ticks = 1000; + pack_and_unpack(metadata, 600, 4); +} diff --git a/host/test/wax_test.cpp b/host/test/wax_test.cpp index e5e1adc25..cb3b12052 100644 --- a/host/test/wax_test.cpp +++ b/host/test/wax_test.cpp @@ -17,14 +17,15 @@ #include <boost/test/unit_test.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(wax::cast<opt_b_t>(opta), wax::bad_cast); - BOOST_CHECK_EQUAL(wax::cast<opt_a_t>(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); } /*********************************************************************** @@ -48,14 +49,14 @@ public: } void get(const wax::obj &key, wax::obj &value){ if (d_subs.size() == 0){ - value = d_nums[wax::cast<size_t>(key)]; + value = d_nums[key.as<size_t>()]; }else{ - value = d_subs[wax::cast<size_t>(key)].get_link(); + 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[wax::cast<size_t>(key)] = wax::cast<float>(value); + d_nums[key.as<size_t>()] = value.as<float>(); }else{ throw std::runtime_error("cant set to a wax demo with sub demos"); } @@ -78,10 +79,10 @@ BOOST_AUTO_TEST_CASE(test_set_get){ 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 = i * j * k + i + j + 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, wax::cast<float>(wd[i][j][k])); + BOOST_CHECK_EQUAL(val, wd[i][j][k].as<float>()); } } } @@ -94,5 +95,5 @@ BOOST_AUTO_TEST_CASE(test_proxy){ std::cout << "assign proxy" << std::endl; wax::obj a = p[size_t(0)]; - BOOST_CHECK_EQUAL(wax::cast<float>(a), float(5)); + BOOST_CHECK_EQUAL(a.as<float>(), float(5)); } |