diff options
Diffstat (limited to 'host/tests')
-rw-r--r-- | host/tests/CMakeLists.txt | 3 | ||||
-rw-r--r-- | host/tests/addr_test.cpp | 1 | ||||
-rw-r--r-- | host/tests/blockdef_test.cpp | 1 | ||||
-rw-r--r-- | host/tests/cal_container_test.cpp | 200 | ||||
-rw-r--r-- | host/tests/convert_test.cpp | 23 | ||||
-rw-r--r-- | host/tests/device3_test.cpp | 1 | ||||
-rw-r--r-- | host/tests/graph_search_test.cpp | 6 | ||||
-rw-r--r-- | host/tests/log_test.cpp (renamed from host/tests/msg_test.cpp) | 33 | ||||
-rw-r--r-- | host/tests/nocscript_expr_test.cpp | 1 | ||||
-rw-r--r-- | host/tests/nocscript_ftable_test.cpp | 1 | ||||
-rw-r--r-- | host/tests/nocscript_parser_test.cpp | 1 | ||||
-rw-r--r-- | host/tests/ranges_test.cpp | 9 | ||||
-rw-r--r-- | host/tests/sid_t_test.cpp | 3 | ||||
-rw-r--r-- | host/tests/subdev_spec_test.cpp | 9 | ||||
-rw-r--r-- | host/tests/time_spec_test.cpp | 1 |
15 files changed, 256 insertions, 37 deletions
diff --git a/host/tests/CMakeLists.txt b/host/tests/CMakeLists.txt index 8f7fdcd7c..ebda2cf70 100644 --- a/host/tests/CMakeLists.txt +++ b/host/tests/CMakeLists.txt @@ -28,6 +28,7 @@ SET(test_sources buffer_test.cpp byteswap_test.cpp cast_test.cpp + cal_container_test.cpp chdr_test.cpp convert_test.cpp dict_test.cpp @@ -35,8 +36,8 @@ SET(test_sources fp_compare_delta_test.cpp fp_compare_epsilon_test.cpp gain_group_test.cpp + log_test.cpp math_test.cpp - msg_test.cpp property_test.cpp ranges_test.cpp sid_t_test.cpp diff --git a/host/tests/addr_test.cpp b/host/tests/addr_test.cpp index 61bb6d049..92863e44f 100644 --- a/host/tests/addr_test.cpp +++ b/host/tests/addr_test.cpp @@ -20,7 +20,6 @@ #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> diff --git a/host/tests/blockdef_test.cpp b/host/tests/blockdef_test.cpp index 11ddc4b59..5ca8a2472 100644 --- a/host/tests/blockdef_test.cpp +++ b/host/tests/blockdef_test.cpp @@ -21,7 +21,6 @@ #include <boost/assign/list_of.hpp> #include <boost/test/unit_test.hpp> #include <boost/format.hpp> -#include <boost/foreach.hpp> #include <uhd/rfnoc/blockdef.hpp> using namespace uhd::rfnoc; diff --git a/host/tests/cal_container_test.cpp b/host/tests/cal_container_test.cpp new file mode 100644 index 000000000..f45ca429d --- /dev/null +++ b/host/tests/cal_container_test.cpp @@ -0,0 +1,200 @@ +// +// Copyright 2016 Ettus Research +// +// 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/cal/power_container.hpp> +#include <uhd/exception.hpp> +#include <boost/test/unit_test.hpp> +#include <boost/shared_ptr.hpp> +#include <vector> +#include <fstream> + +using namespace uhd; +using namespace uhd::cal; + +static const double eps = 1e-8; + +//////////////////////////////////////////////////////////////////////// +BOOST_AUTO_TEST_CASE(test_power_container_bilinear){ +//////////////////////////////////////////////////////////////////////// + + // Create the data container + power_container::sptr container = power_container::make(); + + // Create some data points to add + std::vector<double> pt0(2, 0.0); + std::vector<double> pt1(2, 0.0); + std::vector<double> pt2(2, 0.0); + std::vector<double> pt3(2, 2.0); + + pt1[0] = 2.0; + pt2[1] = 2.0; + + container->add(1.0, pt0); + container->add(1.0, pt1); + container->add(0.0, pt2); + container->add(0.0, pt3); + + // Add points to interpolate against + std::vector<double> test0(2, 1.0); + std::vector<double> test1(2, 1.5); + std::vector<double> test2(2, 0.0); + test2[1] = 1.0; + + BOOST_CHECK_CLOSE(container->get(test0), 0.50, eps); + BOOST_CHECK_CLOSE(container->get(test1), 0.25, eps); + BOOST_CHECK_CLOSE(container->get(test2), 0.50, eps); +} + + +//////////////////////////////////////////////////////////////////////// +BOOST_AUTO_TEST_CASE(test_power_temp_container){ +//////////////////////////////////////////////////////////////////////// + + // Create the data container + power_container::sptr container = power_container::make(); + + // Create some data points to add + std::vector<double> pt0(3, 1.0); + std::vector<double> pt1(3, 2.0); + std::vector<double> pt2(3, 3.0); + + container->add(1.0, pt0); + container->add(2.0, pt1); + container->add(5.0, pt2); + + // Add points to interpolate against + std::vector<double> test0(3, 1.99); + std::vector<double> test1(3, 1.29); + std::vector<double> test2; + test2.push_back(2.59); + test2.push_back(1.29); + test2.push_back(2.99); + + BOOST_CHECK_CLOSE(container->get(test0), 2.0, eps); + BOOST_CHECK_CLOSE(container->get(test1), 1.0, eps); + BOOST_CHECK_CLOSE(container->get(test2), 5.0, eps); +} + +//////////////////////////////////////////////////////////////////////// +BOOST_AUTO_TEST_CASE(test_power_container_metadata){ +//////////////////////////////////////////////////////////////////////// + + // Create the data container + power_container::sptr container = power_container::make(); + + // Create some metadata to add + base_container::metadata_t data; + + std::string fake_serial = "F2A432"; + data["x300"] = fake_serial; + + // Add some metadata + container->add_metadata(data); + + // Check to see if the metadata matches + power_container::metadata_t recovered_data = container->get_metadata(); + + BOOST_CHECK_EQUAL(recovered_data["x300"], fake_serial); +} + +//////////////////////////////////////////////////////////////////////// +BOOST_AUTO_TEST_CASE(test_power_serialization){ +//////////////////////////////////////////////////////////////////////// + + // Create the data container + power_container::sptr container = power_container::make(); + + // Create some metadata to add + base_container::metadata_t data; + + std::string fake_serial = "F2A432"; + data["x300"] = fake_serial; + + // Add some metadata + container->add_metadata(data); + + // Create some data points to add + std::vector<double> pt0(3, 1.0); + std::vector<double> pt1(3, 2.0); + std::vector<double> pt2(3, 3.0); + + container->add(1.0, pt0); + container->add(2.0, pt1); + container->add(5.0, pt2); + + std::string filename("test_power_serialization"); + + // Create/open a file to store the container + { + std::ofstream ofile(filename.c_str()); + + boost::archive::text_oarchive oarchive(ofile); + oarchive << *container; + } + + // Restore to another data container + power_container::sptr new_container = power_container::make(); + + { + std::ifstream ifile(filename.c_str()); + boost::archive::text_iarchive iarchive(ifile); + + iarchive >> *new_container; + } + + // Add points to interpolate against + std::vector<double> test0(3, 1.99); + std::vector<double> test1(3, 1.29); + std::vector<double> test2; + test2.push_back(2.59); + test2.push_back(1.29); + test2.push_back(2.99); + + power_container::metadata_t recovered_data = new_container->get_metadata(); + + BOOST_CHECK_CLOSE(new_container->get(test0), 2.0, eps); + BOOST_CHECK_CLOSE(new_container->get(test1), 1.0, eps); + BOOST_CHECK_CLOSE(new_container->get(test2), 5.0, eps); + + // Check to see if the metadata matches + BOOST_CHECK_EQUAL(recovered_data["x300"], fake_serial); + + std::remove(filename.c_str()); +} + +//////////////////////////////////////////////////////////////////////// +BOOST_AUTO_TEST_CASE(test_interp_singular){ +//////////////////////////////////////////////////////////////////////// + + // Create the data container + power_container::sptr container = power_container::make(); + + // Create some data points to add + // that result in a singular matrix + std::vector<double> pt0(2, 1.0); + std::vector<double> pt1(2, 2.0); + std::vector<double> pt2(2, 3.0); + std::vector<double> pt3(2, 4.0); + + container->add(1.0, pt0); + container->add(2.0, pt1); + container->add(3.0, pt2); + container->add(4.0, pt3); + + std::vector<double> test(2, 2.5); + BOOST_CHECK_CLOSE(container->get(test), 2.5, eps); +} diff --git a/host/tests/convert_test.cpp b/host/tests/convert_test.cpp index dd04dcafc..b4a616133 100644 --- a/host/tests/convert_test.cpp +++ b/host/tests/convert_test.cpp @@ -17,7 +17,6 @@ #include <uhd/convert.hpp> #include <boost/test/unit_test.hpp> -#include <boost/foreach.hpp> #include <stdint.h> #include <boost/assign/list_of.hpp> #include <complex> @@ -75,7 +74,7 @@ static void test_convert_types_sc16( ){ //fill the input samples std::vector<sc16_t> input(nsamps), output(nsamps); - BOOST_FOREACH(sc16_t &in, input) in = sc16_t( + for(sc16_t &in: input) in = sc16_t( short((float((std::rand())/(double(RAND_MAX)/2)) - 1)*32767/extra_div), short((float((std::rand())/(double(RAND_MAX)/2)) - 1)*32767/extra_div) ); @@ -126,7 +125,7 @@ static void test_convert_types_for_floats( //fill the input samples std::vector<data_type> input(nsamps), output(nsamps); - BOOST_FOREACH(data_type &in, input) in = data_type( + for(data_type &in: input) in = data_type( ((std::rand()/(value_type(RAND_MAX)/2)) - 1)*float(extra_scale), ((std::rand()/(value_type(RAND_MAX)/2)) - 1)*float(extra_scale) ); @@ -145,7 +144,7 @@ static void test_convert_types_for_floats( ; //loopback foreach prio combo (generic vs best) - BOOST_FOREACH(const int_pair_t &prio, prios){ + for(const int_pair_t &prio: prios){ loopback(nsamps, in_id, out_id, input, output, prio.first, prio.second); for (size_t i = 0; i < nsamps; i++){ MY_CHECK_CLOSE(input[i].real(), output[i].real(), value_type(1./(1 << 14))); @@ -284,7 +283,7 @@ BOOST_AUTO_TEST_CASE(test_convert_types_fc32_to_sc16){ const size_t nsamps = 13; std::vector<fc32_t> input(nsamps); - BOOST_FOREACH(fc32_t &in, input) in = fc32_t( + for(fc32_t &in: input) in = fc32_t( (std::rand()/(RAND_MAX/2.0)) - 1, (std::rand()/(RAND_MAX/2.0)) - 1 ); @@ -329,7 +328,7 @@ BOOST_AUTO_TEST_CASE(test_convert_types_sc16_to_fc32){ const size_t nsamps = 13; std::vector<sc16_t> input(nsamps); - BOOST_FOREACH(sc16_t &in, input) in = sc16_t( + for(sc16_t &in: input) in = sc16_t( std::rand()-(RAND_MAX/2), std::rand()-(RAND_MAX/2) ); @@ -424,9 +423,9 @@ static void test_convert_types_u8( ){ //fill the input samples std::vector<uint8_t> input(nsamps), output(nsamps); - BOOST_FOREACH(uint8_t &in, input) in = uint8_t(std::rand() & 0xFF); + for(uint8_t &in: input) in = uint8_t(std::rand() & 0xFF); //uint32_t d = 48; - //BOOST_FOREACH(uint8_t &in, input) in = d++; + //for(uint8_t &in: input) in = d++; //run the loopback and test convert::id_type in_id = id; @@ -464,7 +463,7 @@ static void test_convert_types_s8( ){ //fill the input samples std::vector<int8_t> input(nsamps), output(nsamps); - BOOST_FOREACH(int8_t &in, input) in = int8_t(std::rand() & 0xFF); + for(int8_t &in: input) in = int8_t(std::rand() & 0xFF); //run the loopback and test convert::id_type in_id = id; @@ -502,7 +501,7 @@ static void test_convert_types_s16( ){ //fill the input samples std::vector<int16_t> input(nsamps), output(nsamps); - BOOST_FOREACH(int16_t &in, input) in = int16_t(std::rand() & 0xFFFF); + for(int16_t &in: input) in = int16_t(std::rand() & 0xFFFF); //run the loopback and test convert::id_type in_id = id; @@ -540,7 +539,7 @@ static void test_convert_types_fc32( ){ //fill the input samples std::vector< std::complex<float> > input(nsamps), output(nsamps); - BOOST_FOREACH(fc32_t &in, input) in = fc32_t( + for(fc32_t &in: input) in = fc32_t( (std::rand()/float(RAND_MAX/2)) - 1, (std::rand()/float(RAND_MAX/2)) - 1 ); @@ -581,7 +580,7 @@ static void test_convert_types_f32( ){ //fill the input samples std::vector<float> input(nsamps), output(nsamps); - BOOST_FOREACH(float &in, input) in = float((float(std::rand())/float(RAND_MAX/2)) - 1); + for(float &in: input) in = float((float(std::rand())/float(RAND_MAX/2)) - 1); //run the loopback and test convert::id_type in_id = id; diff --git a/host/tests/device3_test.cpp b/host/tests/device3_test.cpp index 657436717..a81f4ca0a 100644 --- a/host/tests/device3_test.cpp +++ b/host/tests/device3_test.cpp @@ -87,7 +87,6 @@ class pseudo_device3_impl : public uhd::device3 make_args.base_address = TEST_SID0.get_dst(); make_args.device_index = 0; make_args.tree = _tree; - make_args.is_big_endian = false; std::cout << "[PSEUDO] Generating block controls 1/2:" << std::endl; _rfnoc_block_ctrl.push_back( block_ctrl_base::make(make_args) ); diff --git a/host/tests/graph_search_test.cpp b/host/tests/graph_search_test.cpp index 8c96bb954..d39f767e9 100644 --- a/host/tests/graph_search_test.cpp +++ b/host/tests/graph_search_test.cpp @@ -83,7 +83,7 @@ BOOST_AUTO_TEST_CASE(test_linear_downstream_search) std::cout << "size: " << result.size() << std::endl; BOOST_CHECK_EQUAL(result.size(), 1); BOOST_CHECK_EQUAL(result[0]->get_test_id(), "node_B"); - BOOST_FOREACH(const result_node::sptr &node, result) { + for(const result_node::sptr &node: result) { std::cout << node->get_test_id() << std::endl; } } @@ -111,7 +111,7 @@ BOOST_AUTO_TEST_CASE(test_multi_iter_downstream_search) // This time, we search for result_node std::vector< result_node::sptr > result = node_A->find_downstream_node<result_node>(); BOOST_REQUIRE(result.size() == 4); - BOOST_FOREACH(const result_node::sptr &node, result) { + for(const result_node::sptr &node: result) { std::cout << node->get_test_id() << std::endl; } } @@ -140,7 +140,7 @@ BOOST_AUTO_TEST_CASE(test_multi_iter_cycle_downstream_search) // This time, we search for result_node std::vector< result_node::sptr > result = node_A->find_downstream_node<result_node>(); BOOST_REQUIRE(result.size() == 4); - BOOST_FOREACH(const result_node::sptr &node, result) { + for(const result_node::sptr &node: result) { std::cout << node->get_test_id() << std::endl; } } diff --git a/host/tests/msg_test.cpp b/host/tests/log_test.cpp index 94b81268c..b0b17ea84 100644 --- a/host/tests/msg_test.cpp +++ b/host/tests/log_test.cpp @@ -16,25 +16,34 @@ // #include <boost/test/unit_test.hpp> -#include <uhd/utils/msg.hpp> +#include <uhd/utils/log.hpp> +#include <uhd/utils/log_add.hpp> #include <iostream> BOOST_AUTO_TEST_CASE(test_messages){ - std::cerr << "---begin print test ---" << std::endl; - UHD_MSG(status) << - "This is a test print for a status message.\n" - "And this is the second line of the test print.\n" + UHD_LOG_FASTPATH("foo"); + UHD_LOG_FASTPATH("bar"); + uhd::log::set_log_level(uhd::log::debug); + uhd::log::set_console_level(uhd::log::info); + uhd::log::add_logger("test", + [](const uhd::log::logging_info &I){ + std::cout << "<TEST> " << I.message << std::endl; + } + ); + uhd::log::set_logger_level("test", uhd::log::debug); + UHD_LOGGER_DEBUG("logger_test") << + "This is a test print for a debug log." ; - UHD_MSG(warning) << - "This is a test print for a warning message.\n" - "And this is the second line of the test print.\n" + UHD_LOGGER_INFO("logger_test") << + "This is a test print for a info log." ; - UHD_MSG(error) << - "This is a test print for an error message.\n" - "And this is the second line of the test print.\n" + UHD_LOGGER_WARNING("logger_test") << + "This is a test print for a warning log." + ; + UHD_LOGGER_ERROR("logger_test") << + "This is a test print for an error log." ; UHD_HERE(); const int x = 42; UHD_VAR(x); - std::cerr << "---end print test ---" << std::endl; } diff --git a/host/tests/nocscript_expr_test.cpp b/host/tests/nocscript_expr_test.cpp index f82a613a3..31bbc8725 100644 --- a/host/tests/nocscript_expr_test.cpp +++ b/host/tests/nocscript_expr_test.cpp @@ -18,7 +18,6 @@ #include "../lib/rfnoc/nocscript/function_table.hpp" #include <boost/test/unit_test.hpp> #include <boost/test/floating_point_comparison.hpp> -#include <boost/foreach.hpp> #include <boost/bind.hpp> #include <boost/make_shared.hpp> #include <boost/format.hpp> diff --git a/host/tests/nocscript_ftable_test.cpp b/host/tests/nocscript_ftable_test.cpp index 283245132..546da0c2c 100644 --- a/host/tests/nocscript_ftable_test.cpp +++ b/host/tests/nocscript_ftable_test.cpp @@ -19,7 +19,6 @@ #include <boost/test/unit_test.hpp> #include <boost/test/floating_point_comparison.hpp> #include <boost/assign/list_of.hpp> -#include <boost/foreach.hpp> #include <boost/bind.hpp> #include <boost/make_shared.hpp> #include <algorithm> diff --git a/host/tests/nocscript_parser_test.cpp b/host/tests/nocscript_parser_test.cpp index a9c25977e..c21f40ad6 100644 --- a/host/tests/nocscript_parser_test.cpp +++ b/host/tests/nocscript_parser_test.cpp @@ -21,7 +21,6 @@ #include <boost/test/unit_test.hpp> #include <boost/test/floating_point_comparison.hpp> #include <boost/assign/list_of.hpp> -#include <boost/foreach.hpp> #include <boost/bind.hpp> #include <boost/make_shared.hpp> #include <algorithm> diff --git a/host/tests/ranges_test.cpp b/host/tests/ranges_test.cpp index 85bb4c3c4..49607b9a3 100644 --- a/host/tests/ranges_test.cpp +++ b/host/tests/ranges_test.cpp @@ -68,3 +68,12 @@ BOOST_AUTO_TEST_CASE(test_ranges_clip2){ BOOST_CHECK_CLOSE(mr.clip(3.1, true), 3., tolerance); BOOST_CHECK_CLOSE(mr.clip(4., true), 3., tolerance); } + +BOOST_AUTO_TEST_CASE(test_ranges_compare){ + range_t range(1); + range_t n_range(1); + range_t d_range(2); + + BOOST_CHECK(range == n_range); + BOOST_CHECK(range != d_range); +} diff --git a/host/tests/sid_t_test.cpp b/host/tests/sid_t_test.cpp index 2043398a1..e07e1c9bc 100644 --- a/host/tests/sid_t_test.cpp +++ b/host/tests/sid_t_test.cpp @@ -118,8 +118,9 @@ BOOST_AUTO_TEST_CASE(test_sid_t_set) { BOOST_CHECK_EQUAL(sid.get_dst_addr(), (uint32_t)0x0c); BOOST_CHECK_EQUAL(sid.get_dst_endpoint(), (uint32_t)0xbc); - sid_t flipped_sid = sid.reversed(); + const sid_t flipped_sid = sid.reversed(); BOOST_CHECK_EQUAL(flipped_sid.get(), (uint32_t)0x0cbc0a0b); + BOOST_CHECK_EQUAL(flipped_sid.reversed(), sid); // In-place sid.reverse(); diff --git a/host/tests/subdev_spec_test.cpp b/host/tests/subdev_spec_test.cpp index aa0b9a119..81f86380b 100644 --- a/host/tests/subdev_spec_test.cpp +++ b/host/tests/subdev_spec_test.cpp @@ -17,7 +17,6 @@ #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){ @@ -28,6 +27,11 @@ BOOST_AUTO_TEST_CASE(test_subdevice_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")); + //create a subdev_spec with something different + uhd::usrp::subdev_spec_t diff_sd_spec; + diff_sd_spec.push_back(uhd::usrp::subdev_spec_pair_t("B", "BA")); + diff_sd_spec.push_back(uhd::usrp::subdev_spec_pair_t("B", "BA")); + //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(); @@ -41,5 +45,8 @@ BOOST_AUTO_TEST_CASE(test_subdevice_spec){ 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); + + BOOST_CHECK(sd_spec.at(i) == new_sd_spec.at(i)); + BOOST_CHECK(sd_spec.at(i) != diff_sd_spec.at(i)); } } diff --git a/host/tests/time_spec_test.cpp b/host/tests/time_spec_test.cpp index 76dfb1930..9ff89ab0e 100644 --- a/host/tests/time_spec_test.cpp +++ b/host/tests/time_spec_test.cpp @@ -17,7 +17,6 @@ #include <boost/test/unit_test.hpp> #include <uhd/types/time_spec.hpp> -#include <boost/foreach.hpp> #include <boost/thread.hpp> //sleep #include <iostream> #include <iomanip> |