From f9755b0ab33eb20abb5689893061f3b4039505fd Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 12 Oct 2010 10:55:07 -0700 Subject: uhd: test eob ack message, usrp2: remove rx drain on init with the promise of a reset register --- host/examples/test_async_messages.cpp | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'host/examples') diff --git a/host/examples/test_async_messages.cpp b/host/examples/test_async_messages.cpp index e4a996ef5..fa39bcde6 100644 --- a/host/examples/test_async_messages.cpp +++ b/host/examples/test_async_messages.cpp @@ -27,13 +27,13 @@ namespace po = boost::program_options; /*! - * Test that no messages are received: + * Test the eob ack message: * Send a burst of many samples that will fragment internally. - * We expect to not get any async messages. + * We expect to get an eob ack async message. */ -void test_no_async_message(uhd::usrp::single_usrp::sptr sdev){ +void test_ack_async_message(uhd::usrp::single_usrp::sptr sdev){ uhd::device::sptr dev = sdev->get_device(); - std::cout << "Test no async message... " << std::flush; + std::cout << "Test eob ack message... " << std::flush; uhd::tx_metadata_t md; md.start_of_burst = true; @@ -50,19 +50,27 @@ void test_no_async_message(uhd::usrp::single_usrp::sptr sdev){ ); uhd::async_metadata_t async_md; - if (dev->recv_async_msg(async_md)){ + if (not dev->recv_async_msg(async_md)){ std::cout << boost::format( "failed:\n" - " Got unexpected event code 0x%x.\n" - ) % async_md.event_code << std::endl; - //clear the async messages - while (dev->recv_async_msg(async_md, 0)){}; + " Async message recv timed out.\n" + ) << std::endl; + return; } - else{ + + switch(async_md.event_code){ + case uhd::async_metadata_t::EVENT_CODE_EOB_ACK: std::cout << boost::format( "success:\n" - " Did not get an async message.\n" + " Got event code eob ack message.\n" ) << std::endl; + break; + + default: + std::cout << boost::format( + "failed:\n" + " Got unexpected event code 0x%x.\n" + ) % async_md.event_code << std::endl; } } @@ -195,7 +203,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ //------------------------------------------------------------------ // begin asyc messages test //------------------------------------------------------------------ - test_no_async_message(sdev); + test_ack_async_message(sdev); test_underflow_message(sdev); test_time_error_message(sdev); -- cgit v1.2.3 From 4dfb7b8cabef3097f822ac52f346cd6021cb35da Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 13 Oct 2010 11:59:35 -0700 Subject: usrp: test async messages app randomly runs tests --- host/examples/test_async_messages.cpp | 84 ++++++++++++++++++++++++++++------- 1 file changed, 67 insertions(+), 17 deletions(-) (limited to 'host/examples') diff --git a/host/examples/test_async_messages.cpp b/host/examples/test_async_messages.cpp index fa39bcde6..bdee7a504 100644 --- a/host/examples/test_async_messages.cpp +++ b/host/examples/test_async_messages.cpp @@ -19,8 +19,12 @@ #include #include #include +#include #include +#include +#include #include +#include #include #include @@ -31,7 +35,7 @@ namespace po = boost::program_options; * Send a burst of many samples that will fragment internally. * We expect to get an eob ack async message. */ -void test_ack_async_message(uhd::usrp::single_usrp::sptr sdev){ +bool test_eob_ack_message(uhd::usrp::single_usrp::sptr sdev){ uhd::device::sptr dev = sdev->get_device(); std::cout << "Test eob ack message... " << std::flush; @@ -55,7 +59,7 @@ void test_ack_async_message(uhd::usrp::single_usrp::sptr sdev){ "failed:\n" " Async message recv timed out.\n" ) << std::endl; - return; + return false; } switch(async_md.event_code){ @@ -64,13 +68,14 @@ void test_ack_async_message(uhd::usrp::single_usrp::sptr sdev){ "success:\n" " Got event code eob ack message.\n" ) << std::endl; - break; + return true; default: std::cout << boost::format( "failed:\n" " Got unexpected event code 0x%x.\n" ) % async_md.event_code << std::endl; + return false; } } @@ -79,7 +84,7 @@ void test_ack_async_message(uhd::usrp::single_usrp::sptr sdev){ * Send a start of burst packet with no following end of burst. * We expect to get an underflow(within a burst) async message. */ -void test_underflow_message(uhd::usrp::single_usrp::sptr sdev){ +bool test_underflow_message(uhd::usrp::single_usrp::sptr sdev){ uhd::device::sptr dev = sdev->get_device(); std::cout << "Test underflow message... " << std::flush; @@ -88,18 +93,21 @@ void test_underflow_message(uhd::usrp::single_usrp::sptr sdev){ md.end_of_burst = false; md.has_time_spec = false; - dev->send(NULL, 0, md, + std::vector > buff(1); //minimum 1 sample + + dev->send( + &buff.front(), buff.size(), md, uhd::io_type_t::COMPLEX_FLOAT32, uhd::device::SEND_MODE_FULL_BUFF ); uhd::async_metadata_t async_md; - if (not dev->recv_async_msg(async_md)){ + if (not dev->recv_async_msg(async_md, 1)){ std::cout << boost::format( "failed:\n" " Async message recv timed out.\n" ) << std::endl; - return; + return false; } switch(async_md.event_code){ @@ -108,13 +116,14 @@ void test_underflow_message(uhd::usrp::single_usrp::sptr sdev){ "success:\n" " Got event code underflow message.\n" ) << std::endl; - break; + return true; default: std::cout << boost::format( "failed:\n" " Got unexpected event code 0x%x.\n" ) % async_md.event_code << std::endl; + return false; } } @@ -123,7 +132,7 @@ void test_underflow_message(uhd::usrp::single_usrp::sptr sdev){ * Send a burst packet that occurs at a time in the past. * We expect to get a time error async message. */ -void test_time_error_message(uhd::usrp::single_usrp::sptr sdev){ +bool test_time_error_message(uhd::usrp::single_usrp::sptr sdev){ uhd::device::sptr dev = sdev->get_device(); std::cout << "Test time error message... " << std::flush; @@ -135,7 +144,10 @@ void test_time_error_message(uhd::usrp::single_usrp::sptr sdev){ sdev->set_time_now(uhd::time_spec_t(200.0)); //time at 200s - dev->send(NULL, 0, md, + std::vector > buff(1); //minimum 1 sample + + dev->send( + &buff.front(), buff.size(), md, uhd::io_type_t::COMPLEX_FLOAT32, uhd::device::SEND_MODE_FULL_BUFF ); @@ -146,7 +158,7 @@ void test_time_error_message(uhd::usrp::single_usrp::sptr sdev){ "failed:\n" " Async message recv timed out.\n" ) << std::endl; - return; + return false; } switch(async_md.event_code){ @@ -155,29 +167,38 @@ void test_time_error_message(uhd::usrp::single_usrp::sptr sdev){ "success:\n" " Got event code time error message.\n" ) << std::endl; - break; + return true; default: std::cout << boost::format( "failed:\n" " Got unexpected event code 0x%x.\n" ) % async_md.event_code << std::endl; + return false; } } +void flush_async_md(uhd::usrp::single_usrp::sptr sdev){ + uhd::device::sptr dev = sdev->get_device(); + uhd::async_metadata_t async_md; + while (dev->recv_async_msg(async_md, 1.0)){} +} + int UHD_SAFE_MAIN(int argc, char *argv[]){ uhd::set_thread_priority_safe(); //variables to be set by po std::string args; double rate; + size_t ntests; //setup the program options po::options_description desc("Allowed options"); desc.add_options() ("help", "help message") - ("args", po::value(&args)->default_value(""), "single uhd device address args") - ("rate", po::value(&rate)->default_value(1.5e6), "rate of outgoing samples") + ("args", po::value(&args)->default_value(""), "single uhd device address args") + ("rate", po::value(&rate)->default_value(1.5e6), "rate of outgoing samples") + ("ntests", po::value(&ntests)->default_value(10), "number of tests to run") ; po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); @@ -203,9 +224,38 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ //------------------------------------------------------------------ // begin asyc messages test //------------------------------------------------------------------ - test_ack_async_message(sdev); - test_underflow_message(sdev); - test_time_error_message(sdev); + static const uhd::dict > + tests = boost::assign::map_list_of + ("Test EOB ACK ", &test_eob_ack_message) + ("Test Underflow ", &test_underflow_message) + ("Test Time Error", &test_time_error_message) + ; + + //init result counts + uhd::dict failures, successes; + BOOST_FOREACH(const std::string &key, tests.keys()){ + failures[key] = 0; + successes[key] = 0; + } + + //run the tests, pick at random + for (size_t n = 0; n < ntests; n++){ + std::string key = tests.keys()[std::rand() % tests.size()]; + bool pass = tests[key](sdev); + flush_async_md(sdev); + + //store result + if (pass) successes[key]++; + else failures[key]++; + } + + //print the result summary + std::cout << std::endl << "Summary:" << std::endl << std::endl; + BOOST_FOREACH(const std::string &key, tests.keys()){ + std::cout << boost::format( + "%s -> %3d successes, %3d failures" + ) % key % successes[key] % failures[key] << std::endl; + } //finished std::cout << std::endl << "Done!" << std::endl << std::endl; -- cgit v1.2.3 From 71e1763332141603e9edba097fd19b00e9a76ab8 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 14 Oct 2010 16:51:47 -0700 Subject: uhd: removed 1 sample buffers in test async messages made a hack in the vrt handler to bump 0 sample requests up to 1 sample (until the hardware supports it) --- host/examples/test_async_messages.cpp | 8 ++------ host/lib/transport/vrt_packet_handler.hpp | 13 +++++++++++-- 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'host/examples') diff --git a/host/examples/test_async_messages.cpp b/host/examples/test_async_messages.cpp index bdee7a504..61db7ec04 100644 --- a/host/examples/test_async_messages.cpp +++ b/host/examples/test_async_messages.cpp @@ -93,10 +93,8 @@ bool test_underflow_message(uhd::usrp::single_usrp::sptr sdev){ md.end_of_burst = false; md.has_time_spec = false; - std::vector > buff(1); //minimum 1 sample - dev->send( - &buff.front(), buff.size(), md, + NULL, 0, md, uhd::io_type_t::COMPLEX_FLOAT32, uhd::device::SEND_MODE_FULL_BUFF ); @@ -144,10 +142,8 @@ bool test_time_error_message(uhd::usrp::single_usrp::sptr sdev){ sdev->set_time_now(uhd::time_spec_t(200.0)); //time at 200s - std::vector > buff(1); //minimum 1 sample - dev->send( - &buff.front(), buff.size(), md, + NULL, 0, md, uhd::io_type_t::COMPLEX_FLOAT32, uhd::device::SEND_MODE_FULL_BUFF ); diff --git a/host/lib/transport/vrt_packet_handler.hpp b/host/lib/transport/vrt_packet_handler.hpp index d5f03de0e..278bcfeaa 100644 --- a/host/lib/transport/vrt_packet_handler.hpp +++ b/host/lib/transport/vrt_packet_handler.hpp @@ -388,10 +388,19 @@ template UHD_INLINE T get_context_code( if_packet_info.sob = metadata.start_of_burst; if_packet_info.eob = metadata.end_of_burst; + //TODO remove this code when sample counts of zero are supported by hardware + std::vector buffs_(buffs); + size_t total_num_samps_(total_num_samps); + if (total_num_samps == 0){ + static const boost::uint64_t zeros = 0; //max size of a host sample + buffs_ = std::vector(buffs.size(), &zeros); + total_num_samps_ = 1; + } + return _send1( state, - buffs, 0, - std::min(total_num_samps, max_samples_per_packet), + buffs_, 0, + std::min(total_num_samps_, max_samples_per_packet), if_packet_info, io_type, otw_type, vrt_packer, -- cgit v1.2.3