3 # Copyright 2004,2005 Free Software Foundation, Inc.
5 # This file is part of GNU Radio
7 # GNU Radio is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3, or (at your option)
12 # GNU Radio is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Radio; see the file COPYING. If not, write to
19 # the Free Software Foundation, Inc., 51 Franklin Street,
20 # Boston, MA 02110-1301, USA.
24 Benchmark the USB/USRP throughput. Finds the maximum full-duplex speed
25 the USRP/USB combination can sustain without errors.
27 This program does not currently give reliable results. Sorry about that...
30 from gnuradio import gr
31 from gnuradio import usrp
32 from gnuradio import eng_notation
36 def run_test (usb_throughput, verbose):
37 # usb_throughput is in bytes/sec.
39 # Returns True or False
42 stream_length = int (usb_throughput/2 * nsec) # length of stream to examine
46 sizeof_sample = 2 * gr.sizeof_short
48 usb_throughput_in_samples = usb_throughput / sizeof_sample
50 # allocate usb throughput 50/50 between Tx and Rx
52 tx_interp = int (dac_freq) / int (usb_throughput_in_samples / 2)
53 rx_decim = int (adc_freq) / int (usb_throughput_in_samples / 2)
55 # print "tx_interp =", tx_interp, "rx_decim =", rx_decim
56 assert (tx_interp == 2 * rx_decim)
60 # Build the Tx pipeline
61 data_src = gr.lfsr_32k_source_s ()
62 src_head = gr.head (gr.sizeof_short, int (stream_length * 2))
63 usrp_tx = usrp.sink_s (0, tx_interp)
64 tb.connect (data_src, src_head, usrp_tx)
67 usrp_rx = usrp.source_s (0, rx_decim, 1, 0x32103210, usrp.FPGA_MODE_LOOPBACK)
68 head = gr.head (gr.sizeof_short, stream_length)
69 check = gr.check_lfsr_32k_s ()
70 tb.connect (usrp_rx, head, check)
74 ntotal = check.ntotal ()
75 nright = check.nright ()
76 runlength = check.runlength ()
79 print "usb_throughput =", eng_notation.num_to_str (usb_throughput)
80 print "ntotal =", ntotal
81 print "nright =", nright
82 print "runlength =", runlength
83 print "delta =", ntotal - runlength
85 return runlength >= stream_length - 80000
90 usb_rate = [ 2e6, 4e6, 8e6, 16e6, 32e6 ]
91 #usb_rate = [ 32e6, 32e6, 32e6, 32e6, 32e6 ]
94 sys.stdout.write ("Testing %sB/sec... " % (eng_notation.num_to_str (rate)))
96 ok = run_test (rate, verbose)
98 best_rate = max (best_rate, rate)
99 sys.stdout.write ("OK\n")
101 sys.stdout.write ("FAILED\n")
103 print "Max USB/USRP throughput = %sB/sec" % (eng_notation.num_to_str (best_rate),)
105 if __name__ == '__main__':