3 # Copyright 2006 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.
23 from gnuradio import gr, gru
24 from gnuradio import audio
25 from gnuradio.eng_option import eng_option
26 from optparse import OptionParser
31 # Test script to test setting up the buffers using gr_test
32 # For very large buffers it will fail when you hit the circbuf memory limit.
33 # On linux this limit is shmmax, it will fail when it tries to create a buffer > shmmax.
34 # With a 2.6 or later kernel you can set the shmmax limit manually in a root console
35 #show current shmmax limit
36 #$ cat /proc/sys/kernel/shmmax
39 #set shmmax limit manually to 300MB
40 #echo 300000000 >/proc/sys/kernel/shmmax
42 #show new shmmax limit
43 #$ cat /proc/sys/kernel/shmmax
46 class my_graph(gr.top_block):
48 def __init__(self, seconds,history,output_multiple):
49 gr.top_block.__init__(self)
51 parser = OptionParser(option_class=eng_option)
52 parser.add_option("-O", "--audio-output", type="string", default="",
53 help="pcm output device name. E.g., hw:0,0 or /dev/dsp")
54 parser.add_option("-r", "--sample-rate", type="eng_float", default=48000,
55 help="set sample rate to RATE (48000)")
56 (options, args) = parser.parse_args ()
61 sample_rate = int(options.sample_rate)
64 src0 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 350, ampl)
66 nsamples=int(sample_rate * seconds) #1 seconds
67 # gr.test (const std::string &name=std::string("gr_test"),
68 # int min_inputs=1, int max_inputs=1, unsigned int sizeof_input_item=1,
69 # int min_outputs=1, int max_outputs=1, unsigned int sizeof_output_item=1,
70 # unsigned int history=1,unsigned int output_multiple=1,double relative_rate=1.0,
71 # bool fixed_rate=true,gr_consume_type_t cons_type=CONSUME_NOUTPUT_ITEMS, gr_produce_type_t prod_type=PRODUCE_NOUTPUT_ITEMS);
75 sizeof_input_item=gr.sizeof_float
78 sizeof_output_item=gr.sizeof_float
79 #history=1 # problems start at 8150
80 #output_multiple=1 #problems start at 8000 in combination with large history
83 consume_type=gr.CONSUME_NOUTPUT_ITEMS
84 produce_type=gr.PRODUCE_NOUTPUT_ITEMS
85 test = gr.test(name, min_inputs,max_inputs,sizeof_input_item,
86 min_outputs,max_outputs,sizeof_output_item,
87 history,output_multiple,relative_rate,
88 fixed_rate, consume_type,produce_type)
89 #test = gr.test("gr_test",1,1,gr.sizeof_float,
90 # 1,1,gr.sizeof_float,
92 # True, gr.CONSUME_NOUTPUT_ITEMS,gr.PRODUCE_NOUTPUT_ITEMS)
93 #unsigned int history=1,unsigned int output_multiple=1,double relative_rate=1.0,
94 #bool fixed_rate=false
95 dst = audio.sink (sample_rate, options.audio_output)
96 head= gr.head(gr.sizeof_float, nsamples)
98 self.connect (src0,test,head,(dst, 0))
101 if __name__ == '__main__':
105 for history in (1,1000,8000,8100,8150,8175,8190,8191,8192,8193,8194,8195,9000,10000,100000,1000000,10000000): #,100000000):
108 print 'Test with history=', history, 'output_multiple=',output_multiple
112 starttime=time.time()
114 my_graph(seconds,history,output_multiple).run()
115 except KeyboardInterrupt:
118 print "\nAn exception has terminated the graph."
126 duration=endtime - starttime
127 if (duration < 0.5*seconds) and (succeed):
128 print "A problem has terminated the graph."
130 if (duration > 1.5*seconds) and (succeed):
131 print "Something slowed the graph down considerably."
134 print 'The test result was:' , succeed
135 print 'Test duration' , duration