27 unittest for the gstlal GstLALAdder class
29 __author__ =
"Karsten Wiesner <karsten.wiesner@ligo.org>"
30 __copyright__ =
"Copyright 2013, Karsten Wiesner"
37 gobject.threads_init()
42 from gstlal
import simplehandler
43 from gstlal
import pipeparts
53 from pylab
import figure, show
58 def __init__(self, testname,
64 samples_per_buffer= 1000,
68 num_bufs_offset_B= 0 ):
70 super(TestGstLALAdder, self).__init__(testname)
91 numpy_float_width_map= { 32:np.float32 , 64:np.float64 }
98 if(self.
quiet==
False):
103 self.
pipeline = gst.Pipeline(
"test_gstlal_adder")
112 src_a = pipeparts.mkaudiotestsrc(self.
pipeline, wave = 0, freq = 880,
117 capsfilt_a = pipeparts.mkcapsfilter(self.
pipeline, src_a,
120 tee_a = pipeparts.mktee(self.
pipeline, capsfilt_a)
121 if(self.
quiet==
False):
123 tee_a),
"gstlal_adder_unittest_InputA.dump")
126 src_b = pipeparts.mkaudiotestsrc(self.
pipeline, wave = 0, freq = 666,
132 capsfilt_b = pipeparts.mkcapsfilter(self.
pipeline, src_b,
135 tee_b = pipeparts.mktee(self.
pipeline, capsfilt_b)
136 if(self.
quiet==
False):
138 tee_b),
"gstlal_adder_unittest_InputB.dump")
141 adder = gst.element_factory_make(self.
DUT)
142 adder.set_property(
"name",
"DUT")
144 if (self.
DUT ==
"lal_adder"):
146 adder.set_property(
"sync",
True)
148 self.pipeline.add(adder)
149 pipeparts.mkqueue(self.
pipeline, tee_a).link(adder)
150 pipeparts.mkqueue(self.
pipeline, tee_b).link(adder)
153 tee_out = pipeparts.mktee(self.
pipeline, adder)
157 tee_out),
"gstlal_adder_unittest_Output.dump")
158 sink = gst.element_factory_make(
"autoaudiosink")
159 self.pipeline.add(sink)
160 pipeparts.mkqueue(self.
pipeline, tee_out).link(sink)
163 dut_out_appsink = pipeparts.mkappsink(self.
pipeline,
164 pipeparts.mkqueue(self.
pipeline, tee_out))
168 src_a_appsink = pipeparts.mkappsink(self.
pipeline,
169 pipeparts.mkqueue(self.
pipeline, tee_a))
173 src_b_appsink = pipeparts.mkappsink(self.
pipeline,
174 pipeparts.mkqueue(self.
pipeline, tee_b))
180 def on_dut_out_appsink_new_buffer(self, element):
182 buffer = element.emit(
'pull-buffer')
186 if(self.
quiet==
False):
187 print "DUT send buffer no.: {0} of size: {1} bytes ; {2} samples ; accu-samples {3}".format(
189 buffer.data.__sizeof__(),
193 gst_app_buf= np.ndarray( shape= samples,
203 def on_src_a_appsink_new_buffer(self, element):
204 buffer = element.emit(
'pull-buffer')
212 def on_src_b_appsink_new_buffer(self, element):
213 buffer = element.emit(
'pull-buffer')
231 self.pipeline.set_state(gst.STATE_PLAYING)
232 pipeparts.write_dump_dot(self.
pipeline,
"test_1_plot_signals",
241 src_a_plot_l= fig_l.add_subplot(1,1,1)
245 src_a_plot_l.plot(self.
src_a_buf,
'g.', label=
'src a')
247 src_b_plot_l= fig_l.add_subplot(1,1,1)
251 src_b_plot_l.plot(x, self.
src_b_buf,
'b.--', label=
'src b')
253 dut_out_plot_l= fig_l.add_subplot(1,1,1)
256 dut_out_plot_l.plot(self.
dut_out_buf,
'r', label='DUT out')
258 dut_out_plot_l.set_xlabel(
'samples')
259 dut_out_plot_l.set_ylabel(
'volume')
260 dut_out_plot_l.legend(loc=
'upper right')
261 src_b_plot_l.set_title(
'Left side region adding buffer A and B(w/ offset timestamp)')
266 src_a_plot_r= fig_r.add_subplot(1,1,1)
270 src_a_plot_r.plot(self.
src_a_buf,
'g.', label=
'src a')
272 src_b_plot_r= fig_r.add_subplot(1,1,1)
276 src_b_plot_r.plot(x, self.
src_b_buf,
'b.--', label=
'src b')
278 dut_out_plot_r= fig_r.add_subplot(1,1,1)
281 dut_out_plot_r.plot(self.
dut_out_buf,
'r', label='DUT out')
283 dut_out_plot_r.set_xlabel(
'samples')
284 dut_out_plot_r.set_ylabel(
'volume')
285 dut_out_plot_r.legend(loc=
'upper left')
286 src_b_plot_r.set_title(
'Right side region adding buffer A and B(w/ offset timestamp)')
290 dut_out_all=fig_all.add_subplot(1,1,1)
291 dut_out_all.plot(self.
src_a_buf,
'g.', label=
'src a')
293 dut_out_all.plot(x, self.
src_b_buf,
'b.--', label=
'src b')
294 dut_out_all.plot(self.
dut_out_buf,
'r', label='DUT out')
296 dut_out_all.set_xlabel(
'samples')
297 dut_out_all.set_ylabel(
'volume')
298 dut_out_all.legend(loc=
'upper right')
299 dut_out_all.set_title(
'Adding buffer A and B(w/ offset timestamp)')
308 self.pipeline.set_state(gst.STATE_PLAYING)
310 if(self.
quiet==
False):
311 pipeparts.write_dump_dot(self.
pipeline,
"test_2_quiet_at_32bps",
320 absmax= np.amax(np.absolute(np_diff))
322 if(self.
quiet==
False):
324 print "maximum of absolute differences from numpy reference add= {0}".format(absmax)
325 self.failIf(absmax >= 1.8e-8,
"OOOPS!")
337 self.pipeline.set_state(gst.STATE_PLAYING)
339 if(self.
quiet==
False):
340 pipeparts.write_dump_dot(self.
pipeline,
"test_3_quiet_at_64bps",
349 absmax= np.amax(np.absolute(np_diff))
351 if(self.
quiet==
False):
353 print "maximum of absolute differences from numpy reference add= {0}".format(absmax)
354 self.failIf(absmax >= 1.0e-20,
"OOOPS!")
365 suite= unittest.TestSuite()
403 samples_per_buffer= 1000,
405 timestamp_offs_B= 0.2e9,
407 num_bufs_offset_B= -1))
415 samples_per_buffer= 1000,
417 timestamp_offs_B= 0.2e9,
419 num_bufs_offset_B= -1))
425 unittest.TextTestRunner(verbosity=5).run(suite)