Unittest with USRP not finishing

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-not-finishing-tp39439.html
Sent from the GnuRadio mailing list archive at Nabble.com.

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-not-finishing-tp39439p39441.html
Sent from the GnuRadio mailing list archive at Nabble.com.

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

On Wed, Feb 6, 2013 at 8:37 AM, maiconkist [email protected] wrote:

Sent from the GnuRadio mailing list archive at Nabble.com.


Discuss-gnuradio mailing list
[email protected]
Discuss-gnuradio Info Page

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

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-not-finishing-tp39439p39445.html
Sent from the GnuRadio mailing list archive at Nabble.com.