summaryrefslogtreecommitdiffstats
path: root/host/test
diff options
context:
space:
mode:
Diffstat (limited to 'host/test')
-rw-r--r--host/test/CMakeLists.txt34
-rw-r--r--host/test/addr_test.cpp67
-rw-r--r--host/test/gain_handler_test.cpp121
-rw-r--r--host/test/main_test.cpp3
-rw-r--r--host/test/module_test.cpp26
-rw-r--r--host/test/vrt_test.cpp102
-rw-r--r--host/test/wax_test.cpp104
7 files changed, 457 insertions, 0 deletions
diff --git a/host/test/CMakeLists.txt b/host/test/CMakeLists.txt
new file mode 100644
index 000000000..1791d9082
--- /dev/null
+++ b/host/test/CMakeLists.txt
@@ -0,0 +1,34 @@
+#
+# 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
+ 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..2ec6de14b
--- /dev/null
+++ b/host/test/addr_test.cpp
@@ -0,0 +1,67 @@
+//
+// 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 <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_string();
+ std::string args_str = dev_addr.to_args_str();
+ std::cout << "Args String: " << args_str << std::endl;
+ uhd::device_addr_t new_dev_addr = uhd::device_addr_t::from_args_str(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()
+ );
+}
diff --git a/host/test/gain_handler_test.cpp b/host/test/gain_handler_test.cpp
new file mode 100644
index 000000000..bf2ec5db7
--- /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;
+ }
+ }
+
+ 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;
+
+ 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, 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..939a61eb4
--- /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(
+ 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(
+ 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));
+}