diff options
Diffstat (limited to 'host/test')
| -rw-r--r-- | host/test/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | host/test/gain_handler_test.cpp | 88 | ||||
| -rw-r--r-- | host/test/vrt_test.cpp | 100 | ||||
| -rw-r--r-- | host/test/wax_test.cpp | 15 | 
4 files changed, 150 insertions, 54 deletions
| diff --git a/host/test/CMakeLists.txt b/host/test/CMakeLists.txt index 234b6f92c..b1d5924c7 100644 --- a/host/test/CMakeLists.txt +++ b/host/test/CMakeLists.txt @@ -20,6 +20,7 @@ ADD_EXECUTABLE(main_test      main_test.cpp      addr_test.cpp      gain_handler_test.cpp +    vrt_test.cpp      wax_test.cpp  ) diff --git a/host/test/gain_handler_test.cpp b/host/test/gain_handler_test.cpp index c81221aac..a4005c0de 100644 --- a/host/test/gain_handler_test.cpp +++ b/host/test/gain_handler_test.cpp @@ -17,33 +17,36 @@  #include <boost/test/unit_test.hpp>  #include <uhd/gain_handler.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 +59,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 +81,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 +103,20 @@ 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_t gain_min, gain_max, gain_step; +    boost::tie(gain_min, gain_max, gain_step) = \ +        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/vrt_test.cpp b/host/test/vrt_test.cpp new file mode 100644 index 000000000..d80908c74 --- /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 +){ +    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..b793b2690 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");          } @@ -81,7 +82,7 @@ BOOST_AUTO_TEST_CASE(test_set_get){                  float val = 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));  } | 
