summaryrefslogtreecommitdiffstats
path: root/host/test
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-08-10 23:29:22 -0700
committerJosh Blum <josh@joshknows.com>2010-08-10 23:29:22 -0700
commit293ccdccd1e111942e9cc48ab87690da5202e406 (patch)
tree4e861ca41fabc1e2664b7d0807242ab9c61544fd /host/test
parent1301d665d621358ec6eccb41a020a4689cb0b566 (diff)
parent9e419c7b7f35062ceb2ed4e508cadb163067593f (diff)
downloaduhd-293ccdccd1e111942e9cc48ab87690da5202e406.tar.gz
uhd-293ccdccd1e111942e9cc48ab87690da5202e406.tar.bz2
uhd-293ccdccd1e111942e9cc48ab87690da5202e406.zip
usrp-e: merged master, does not build
Diffstat (limited to 'host/test')
-rw-r--r--host/test/CMakeLists.txt5
-rw-r--r--host/test/addr_test.cpp2
-rw-r--r--host/test/gain_group_test.cpp122
-rw-r--r--host/test/gain_handler_test.cpp121
-rw-r--r--host/test/subdev_spec_test.cpp45
-rw-r--r--host/test/tune_helper_test.cpp174
-rw-r--r--host/test/warning_test.cpp29
7 files changed, 375 insertions, 123 deletions
diff --git a/host/test/CMakeLists.txt b/host/test/CMakeLists.txt
index 74f3376e6..c620fd641 100644
--- a/host/test/CMakeLists.txt
+++ b/host/test/CMakeLists.txt
@@ -26,8 +26,11 @@ ADD_EXECUTABLE(main_test
convert_types_test.cpp
dict_test.cpp
error_test.cpp
- gain_handler_test.cpp
+ gain_group_test.cpp
+ subdev_spec_test.cpp
+ tune_helper_test.cpp
vrt_test.cpp
+ warning_test.cpp
wax_test.cpp
)
TARGET_LINK_LIBRARIES(main_test uhd)
diff --git a/host/test/addr_test.cpp b/host/test/addr_test.cpp
index 0c50200d6..d4b45aa1a 100644
--- a/host/test/addr_test.cpp
+++ b/host/test/addr_test.cpp
@@ -48,7 +48,7 @@ BOOST_AUTO_TEST_CASE(test_device_addr){
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());
+ BOOST_REQUIRE_EQUAL(dev_addr.size(), new_dev_addr.size());
//the keys should match
std::vector<std::string> old_dev_addr_keys = dev_addr.keys();
diff --git a/host/test/gain_group_test.cpp b/host/test/gain_group_test.cpp
new file mode 100644
index 000000000..6a6af8eb2
--- /dev/null
+++ b/host/test/gain_group_test.cpp
@@ -0,0 +1,122 @@
+//
+// 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_group.hpp>
+#include <boost/bind.hpp>
+#include <boost/math/special_functions/round.hpp>
+#include <iostream>
+
+#define rint(x) boost::math::iround(x)
+
+using namespace uhd;
+
+/***********************************************************************
+ * Define gain element classes with needed functions
+ **********************************************************************/
+class gain_element1{
+public:
+
+ gain_range_t get_range(void){
+ return gain_range_t(0, 90, 1);
+ }
+
+ float get_value(void){
+ return _gain;
+ }
+
+ void set_value(float gain){
+ float step = get_range().step;
+ _gain = step*rint(gain/step);
+ }
+
+private:
+ float _gain;
+};
+
+class gain_element2{
+public:
+
+ gain_range_t get_range(void){
+ return gain_range_t(-20, 10, 0.1);
+ }
+
+ float get_value(void){
+ return _gain;
+ }
+
+ void set_value(float gain){
+ float step = get_range().step;
+ _gain = step*rint(gain/step);
+ }
+
+private:
+ float _gain;
+};
+
+//create static instances of gain elements to be shared by the tests
+static gain_element1 g1;
+static gain_element2 g2;
+
+static gain_group::sptr get_gain_group(size_t pri1 = 0, size_t pri2 = 0){
+ //create instance of gain group
+ gain_fcns_t gain_fcns;
+ gain_group::sptr gg(gain_group::make());
+
+ //load gain group with function sets
+ gain_fcns.get_range = boost::bind(&gain_element1::get_range, &g1);
+ gain_fcns.get_value = boost::bind(&gain_element1::get_value, &g1);
+ gain_fcns.set_value = boost::bind(&gain_element1::set_value, &g1, _1);
+ gg->register_fcns(gain_fcns, pri1);
+
+ gain_fcns.get_range = boost::bind(&gain_element2::get_range, &g2);
+ gain_fcns.get_value = boost::bind(&gain_element2::get_value, &g2);
+ gain_fcns.set_value = boost::bind(&gain_element2::set_value, &g2, _1);
+ gg->register_fcns(gain_fcns, pri2);
+
+ return gg;
+}
+
+/***********************************************************************
+ * Test cases
+ **********************************************************************/
+static const double tolerance = 0.001;
+
+BOOST_AUTO_TEST_CASE(test_gain_group_overall){
+ gain_group::sptr gg = get_gain_group();
+
+ //test the overall stuff
+ gg->set_value(80);
+ BOOST_CHECK_CLOSE(gg->get_value(), float(80), tolerance);
+ BOOST_CHECK_CLOSE(gg->get_range().min, float(-20), tolerance);
+ BOOST_CHECK_CLOSE(gg->get_range().max, float(100), tolerance);
+ BOOST_CHECK_CLOSE(gg->get_range().step, float(0.1), tolerance);
+}
+
+BOOST_AUTO_TEST_CASE(test_gain_group_priority){
+ gain_group::sptr gg = get_gain_group(0, 1);
+
+ //test the overall stuff
+ gg->set_value(80);
+ BOOST_CHECK_CLOSE(gg->get_value(), float(80), tolerance);
+ BOOST_CHECK_CLOSE(gg->get_range().min, float(-20), tolerance);
+ BOOST_CHECK_CLOSE(gg->get_range().max, float(100), tolerance);
+ BOOST_CHECK_CLOSE(gg->get_range().step, float(0.1), tolerance);
+
+ //test the the higher priority gain got filled first (gain 2)
+ BOOST_CHECK_CLOSE(g2.get_value(), g2.get_range().max, tolerance);
+}
diff --git a/host/test/gain_handler_test.cpp b/host/test/gain_handler_test.cpp
deleted file mode 100644
index 5a9f2b714..000000000
--- a/host/test/gain_handler_test.cpp
+++ /dev/null
@@ -1,121 +0,0 @@
-//
-// 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/subdev_spec_test.cpp b/host/test/subdev_spec_test.cpp
new file mode 100644
index 000000000..8817d5eee
--- /dev/null
+++ b/host/test/subdev_spec_test.cpp
@@ -0,0 +1,45 @@
+//
+// 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/usrp/subdev_spec.hpp>
+#include <boost/foreach.hpp>
+#include <iostream>
+
+BOOST_AUTO_TEST_CASE(test_subdevice_spec){
+ std::cout << "Testing subdevice specification..." << std::endl;
+
+ //load the subdev spec with something
+ uhd::usrp::subdev_spec_t sd_spec;
+ sd_spec.push_back(uhd::usrp::subdev_spec_pair_t("A", "AB"));
+ sd_spec.push_back(uhd::usrp::subdev_spec_pair_t("B", "AB"));
+
+ //convert to and from args string
+ std::cout << "Pretty Print: " << std::endl << sd_spec.to_pp_string();
+ std::string markup_str = sd_spec.to_string();
+ std::cout << "Markup String: " << markup_str << std::endl;
+ uhd::usrp::subdev_spec_t new_sd_spec(markup_str);
+
+ //they should be the same size
+ BOOST_REQUIRE_EQUAL(sd_spec.size(), new_sd_spec.size());
+
+ //the contents should match
+ for (size_t i = 0; i < sd_spec.size(); i++){
+ BOOST_CHECK_EQUAL(sd_spec.at(i).db_name, new_sd_spec.at(i).db_name);
+ BOOST_CHECK_EQUAL(sd_spec.at(i).sd_name, new_sd_spec.at(i).sd_name);
+ }
+}
diff --git a/host/test/tune_helper_test.cpp b/host/test/tune_helper_test.cpp
new file mode 100644
index 000000000..570f47293
--- /dev/null
+++ b/host/test/tune_helper_test.cpp
@@ -0,0 +1,174 @@
+//
+// 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/usrp/tune_helper.hpp>
+#include <uhd/usrp/subdev_props.hpp>
+#include <uhd/usrp/dsp_props.hpp>
+#include <iostream>
+
+using namespace uhd;
+using namespace uhd::usrp;
+
+/***********************************************************************
+ * Dummy properties objects
+ **********************************************************************/
+class dummy_subdev : public wax::obj{
+public:
+ dummy_subdev(double resolution):
+ _resolution(resolution)
+ {
+ /* NOP */
+ }
+private:
+ void get(const wax::obj &key, wax::obj &val){
+ switch(key.as<subdev_prop_t>()){
+
+ case SUBDEV_PROP_FREQ:
+ val = _freq;
+ return;
+
+ case SUBDEV_PROP_USE_LO_OFFSET:
+ val = false;
+ return;
+
+ default: UHD_THROW_PROP_GET_ERROR();
+ }
+ }
+
+ void set(const wax::obj &key, const wax::obj &val){
+ switch(key.as<subdev_prop_t>()){
+ case SUBDEV_PROP_FREQ:
+ _freq = _resolution*int(val.as<double>()/_resolution);
+ return;
+
+ default: UHD_THROW_PROP_SET_ERROR();
+ }
+ }
+
+ double _freq, _resolution;
+};
+
+class dummy_subdev_basic : public wax::obj{
+private:
+ void get(const wax::obj &key, wax::obj &val){
+ switch(key.as<subdev_prop_t>()){
+
+ case SUBDEV_PROP_FREQ:
+ val = double(0.0); //always zero
+ return;
+
+ case SUBDEV_PROP_USE_LO_OFFSET:
+ val = false;
+ return;
+
+ default: UHD_THROW_PROP_GET_ERROR();
+ }
+ }
+
+ void set(const wax::obj &key, const wax::obj &){
+ switch(key.as<subdev_prop_t>()){
+ case SUBDEV_PROP_FREQ:
+ // do nothing
+ return;
+
+ default: UHD_THROW_PROP_SET_ERROR();
+ }
+ }
+};
+
+class dummy_dsp : public wax::obj{
+public:
+ dummy_dsp(double codec_rate):
+ _codec_rate(codec_rate)
+ {
+ /* NOP */
+ }
+private:
+ void get(const wax::obj &key, wax::obj &val){
+ switch(key.as<dsp_prop_t>()){
+ case DSP_PROP_CODEC_RATE:
+ val = _codec_rate;
+ return;
+
+ case DSP_PROP_FREQ_SHIFT:
+ val = _freq_shift;
+ return;
+
+ default: UHD_THROW_PROP_GET_ERROR();
+ }
+ }
+
+ void set(const wax::obj &key, const wax::obj &val){
+ switch(key.as<dsp_prop_t>()){
+ case DSP_PROP_FREQ_SHIFT:
+ _freq_shift = val.as<double>();
+ return;
+
+ default: UHD_THROW_PROP_SET_ERROR();
+ }
+ }
+
+ double _codec_rate, _freq_shift;
+};
+
+/***********************************************************************
+ * Test cases
+ **********************************************************************/
+static const double tolerance = 0.001;
+
+BOOST_AUTO_TEST_CASE(test_tune_helper_rx){
+ dummy_subdev subdev(1e6);
+ dummy_dsp dsp(100e6);
+
+ std::cout << "Testing tune helper RX automatic LO offset" << std::endl;
+ tune_result_t tr = tune_rx_subdev_and_dsp(subdev.get_link(), dsp.get_link(), 2.3451e9);
+ std::cout << tr.to_pp_string() << std::endl;
+ BOOST_CHECK_CLOSE(tr.actual_inter_freq, 2.345e9, tolerance);
+ BOOST_CHECK_CLOSE(tr.actual_dsp_freq, -100e3, tolerance);
+
+ double freq_derived = derive_freq_from_rx_subdev_and_dsp(subdev.get_link(), dsp.get_link());
+ BOOST_CHECK_CLOSE(freq_derived, 2.3451e9, tolerance);
+}
+
+BOOST_AUTO_TEST_CASE(test_tune_helper_tx){
+ dummy_subdev subdev(1e6);
+ dummy_dsp dsp(100e6);
+
+ std::cout << "Testing tune helper TX automatic LO offset" << std::endl;
+ tune_result_t tr = tune_tx_subdev_and_dsp(subdev.get_link(), dsp.get_link(), 2.3451e9);
+ std::cout << tr.to_pp_string() << std::endl;
+ BOOST_CHECK_CLOSE(tr.actual_inter_freq, 2.345e9, tolerance);
+ BOOST_CHECK_CLOSE(tr.actual_dsp_freq, 100e3, tolerance);
+
+ double freq_derived = derive_freq_from_tx_subdev_and_dsp(subdev.get_link(), dsp.get_link());
+ BOOST_CHECK_CLOSE(freq_derived, 2.3451e9, tolerance);
+}
+
+BOOST_AUTO_TEST_CASE(test_tune_helper_rx_nyquist){
+ dummy_subdev_basic subdev;
+ dummy_dsp dsp(100e6);
+
+ std::cout << "Testing tune helper RX dummy basic board" << std::endl;
+ tune_result_t tr = tune_rx_subdev_and_dsp(subdev.get_link(), dsp.get_link(), 55e6);
+ std::cout << tr.to_pp_string() << std::endl;
+ BOOST_CHECK_CLOSE(tr.actual_inter_freq, 0.0, tolerance);
+ BOOST_CHECK_CLOSE(tr.actual_dsp_freq, 45e6, tolerance);
+
+ double freq_derived = derive_freq_from_rx_subdev_and_dsp(subdev.get_link(), dsp.get_link());
+ BOOST_CHECK_CLOSE(freq_derived, -45e6, tolerance);
+}
diff --git a/host/test/warning_test.cpp b/host/test/warning_test.cpp
new file mode 100644
index 000000000..6202c4270
--- /dev/null
+++ b/host/test/warning_test.cpp
@@ -0,0 +1,29 @@
+//
+// 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/warning.hpp>
+#include <iostream>
+
+BOOST_AUTO_TEST_CASE(test_print_warning){
+ std::cerr << "---begin print test ---" << std::endl;
+ uhd::print_warning(
+ "This is a test print for a warning message.\n"
+ "And this is the second line of the test print.\n"
+ );
+ std::cerr << "---end print test ---" << std::endl;
+}