Forum: GNU Radio unittest with USRP not finishing

Posted by maiconkist (Guest)
on 2013-02-06 13:01
(Received via mailing list)
Hello list,

I am trying to write a simple unit test from a flow graph I'm writing. 
The
problem is that the flowgraph dont finish. It hangs in the line
"self.assertNotEqual(out, 0).

The complete code is as follows:

####
from gnuradio import gr_unittest

# Project imports
from usrpDevice import UsrpFlowGraph
from usrpDevice import USRPDevice

from time import sleep


## Test DeviceWrapper methods
#
class qa_device(gr_unittest.TestCase):

  ## Test USRP communication
  def test_001_usrp(self):
    uhd = USRPDevice()
    uhd.start()

    out = uhd.sense()

    self.assertNotEqual(out, 0)


if __name__ == '__main__':
  gr_unittest.main()
####




And the USRPDevice class:

####
class USRPDevice(gr.top_block):

  ## CTOR
  def __init__(self):
                gr.top_block.__init__(self, "Energy Top Block")

    self.mUhd = uhd.usrp_source(device_addr=options.addr,
        stream_args=uhd.stream_args(cpu_format='fc32',
        otw_format='sc16'))

    self.ed = EnergyDetector(options.fft_size)
    self.mavg = gr.moving_average_ff(options.moving_avg_size,
        1.0/options.moving_avg_size
        )
    self.mOut = gr.probe_signal_f()

    self.connect(self.mUhd, self.ed, self.mavg, self.mOut)

  def sense(self):
    return self.mOut.level()

####

I tried changed the code and verified that USRPDevice::sense is 
returning
when its called.
And if I remove the "start()" call in the Unit Test, it works fine.

Any suggestion of whats happening ?



--
View this message in context: 
http://gnuradio.4.n7.nabble.com/unittest-with-USRP...
Sent from the GnuRadio mailing list archive at Nabble.com.
Posted by maiconkist (Guest)
on 2013-02-06 14:38
(Received via mailing list)
Resolved.

Its necessary to call gr.top_block::wait() method before the "stop()".
Anybody know why this is necessary?



--
View this message in context: 
http://gnuradio.4.n7.nabble.com/unittest-with-USRP...
Sent from the GnuRadio mailing list archive at Nabble.com.
Posted by Mike Jameson (Guest)
on 2013-02-06 15:06
(Received via mailing list)
Hi,

You have to call tb.stop() before the tb.wait(), not the other way 
around
like you mentioned:

tb.stop()
tb.wait()

The tb.wait() is to make sure the flowgraph has fully stopped before 
doing
anything else.

Cheers,

Mike

Mike
M0MIK
Posted by Tom Rondeau (Guest)
on 2013-02-06 15:11
(Received via mailing list)
On Wed, Feb 6, 2013 at 8:37 AM, maiconkist <maiconkist@gmail.com> wrote:

> Sent from the GnuRadio mailing list archive at Nabble.com.
>
> _______________________________________________
> Discuss-gnuradio mailing list
> Discuss-gnuradio@gnu.org
> https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
>


In the thread-per-block scheduler:

void
gr_scheduler_tpb::stop()
{
  d_threads.interrupt_all();
}

void
gr_scheduler_tpb::wait()
{
  d_threads.join_all();
}


Tom
Posted by maiconkist (Guest)
on 2013-02-06 15:28
(Received via mailing list)
you're correct. In the code I did in this order.



--
View this message in context: 
http://gnuradio.4.n7.nabble.com/unittest-with-USRP...
Sent from the GnuRadio mailing list archive at Nabble.com.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.