def test_005(self): """test_005: that repeat works (with tagged streams)""" length = 16 src_data = [float(x) for x in range(length)] expected_result = tuple(src_data + src_data) src_tags = tuple([make_tag('key', 'val', 0, 'src')]) expected_tags = tuple([ make_tag('key', 'val', 0, 'src'), make_tag('key', 'val', length, 'src') ]) src = flaress.vector_source_double(src_data, repeat=True, tags=src_tags) head = blocks.head(gr.sizeof_double, 2 * length) dst = flaress.vector_sink_double() self.tb.connect(src, head, dst) self.tb.run() result_data = dst.data() result_tags = dst.tags() self.assertEqual(expected_result, result_data) self.assertEqual(len(result_tags), 2) self.assertTrue(compare_tags(expected_tags[0], result_tags[0])) self.assertTrue(compare_tags(expected_tags[1], result_tags[1]))
def test_003_double_3(self): """test_003_double_3: multiply double version with 3 inputs""" src_data1 = [float(x) for x in range(16)] src_data2 = [float(x) for x in range(16)] src_data3 = [float(x) for x in range(16)] expected_result_temp = [] for i in range(0, len(src_data1)): expected_result_temp.append(src_data1[i] * src_data2[i] * src_data3[i]) expected_result = tuple(expected_result_temp) src1 = flaress.vector_source_double(src_data1) src2 = flaress.vector_source_double(src_data2) src3 = flaress.vector_source_double(src_data3) dst = flaress.vector_sink_double() op = flaress.multiply_double(1) self.tb.connect(src1, (op, 0)) self.tb.connect(src2, (op, 1)) self.tb.connect(src3, (op, 2)) self.tb.connect(op, dst) self.tb.run() result_data = dst.data() self.assertEqual(expected_result, result_data)
def test_002(self): """test_002: vectors (the gnuradio vector I/O type)""" src_data = [float(x) for x in range(16)] expected_result = tuple(src_data) src = flaress.vector_source_double(src_data, False, 2) dst = flaress.vector_sink_double(2) self.tb.connect(src, dst) self.tb.run() result_data = dst.data() self.assertEqual(expected_result, result_data)
def test_001(self): """test_001: that sink has data set in source for the simplest case""" src_data = [float(x) for x in range(16)] expected_result = tuple(src_data) src = flaress.vector_source_double(src_data) dst = flaress.vector_sink_double() self.tb.connect(src, dst) self.tb.run() result_data = dst.data() self.assertEqual(expected_result, result_data)
def test_006(self): """test_006: set_data""" src_data = [float(x) for x in range(16)] expected_result = tuple(src_data) src = flaress.vector_source_double((3,1,4)) dst = flaress.vector_sink_double() src.set_data(src_data) self.tb.connect(src, dst) self.tb.run() result_data = dst.data() self.assertEqual(expected_result, result_data)
def test_007(self): """test_007: set_repeat""" src_data = [float(x) for x in range(16)] expected_result = tuple(src_data) src = flaress.vector_source_double(src_data, True) dst = flaress.vector_sink_double() src.set_repeat(False) self.tb.connect(src, dst) # will timeout if set_repeat does not work self.tb.run() result_data = dst.data() self.assertEqual(expected_result, result_data)
def test_004(self): """test_004: sending and receiving tagged streams""" src_data = [float(x) for x in range(16)] expected_result = tuple(src_data) src_tags = tuple([make_tag('key', 'val', 0, 'src')]) expected_tags = src_tags[:] src = flaress.vector_source_double(src_data, repeat=False, tags=src_tags) dst = flaress.vector_sink_double() self.tb.connect(src, dst) self.tb.run() result_data = dst.data() result_tags = dst.tags() self.assertEqual(expected_result, result_data) self.assertEqual(len(result_tags), 1) self.assertTrue(compare_tags(expected_tags[0], result_tags[0]))
def test_002_double_2 (self): """test_002_double_2: add const double version with 2 inputs""" src_data1 = [float(x) for x in range(16)] expected_result_temp = [] const = 10 for i in range(0, len(src_data1)): expected_result_temp.append(const + src_data1[i]) expected_result = tuple(expected_result_temp) src1 = flaress.vector_source_double(src_data1) dst = flaress.vector_sink_double() op = flaress.add_const_double(const, 1) self.tb.connect(src1, (op, 0)) self.tb.connect(op, dst) self.tb.run() result_data = dst.data() self.assertEqual(expected_result, result_data)
def test_002_double_2(self): """test_002_double_2: divide double version with 2 inputs""" src_data1 = [float(x) for x in range(1, 16)] src_data2 = [float(x) for x in range(1, 16)] expected_result_temp = [] for i in range(0, len(src_data1)): expected_result_temp.append(src_data1[i] / src_data2[i]) expected_result = tuple(expected_result_temp) src1 = flaress.vector_source_double(src_data1) src2 = flaress.vector_source_double(src_data2) dst = flaress.vector_sink_double() op = flaress.divide_double(1) self.tb.connect(src1, (op, 0)) self.tb.connect(src2, (op, 1)) self.tb.connect(op, dst) self.tb.run() result_data = dst.data() self.assertEqual(expected_result, result_data)
def test_002_c(self): """test_002_c: mux version with 3 inputs""" tb = self.tb # Variables samp_rate = 4096 N = samp_rate * 4 # Blocks flaress_selector = flaress.selector(gr.sizeof_gr_complex * 1, 0, 3, 1) debug_switch = flaress.debug_func_probe(gr.sizeof_gr_complex * 1) def _probe_func_probe(): time.sleep(1) try: flaress_selector.set_select(1) debug_switch.debug_nitems() self.debug_select = flaress_selector.get_select() time.sleep(1) except AttributeError: pass try: flaress_selector.set_select(2) debug_switch.debug_nitems() self.debug_select = flaress_selector.get_select() except AttributeError: pass _probe_func_thread = threading.Thread(target=_probe_func_probe) _probe_func_thread.daemon = True throttle0 = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate, True) throttle1 = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate, True) throttle2 = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate, True) dst_in0 = flaress.vector_sink_double() dst_in1 = flaress.vector_sink_double() dst_in2 = flaress.vector_sink_double() dst_out = flaress.vector_sink_double() head = blocks.head(gr.sizeof_gr_complex, N) sig_source0 = analog.sig_source_c(samp_rate, analog.GR_SAW_WAVE, 0.125, 10, 0) sig_source1 = analog.sig_source_c(samp_rate, analog.GR_SAW_WAVE, 0.125, 10, 11) sig_source2 = analog.sig_source_c(samp_rate, analog.GR_SAW_WAVE, 0.125, -10, -1) # Connections tb.connect(sig_source0, throttle0) tb.connect(sig_source1, throttle1) tb.connect(sig_source2, throttle2) tb.connect(throttle0, dst_in0) tb.connect(throttle1, dst_in1) tb.connect(throttle2, dst_in2) tb.connect(throttle0, (flaress_selector, 0)) tb.connect(throttle1, (flaress_selector, 1)) tb.connect(throttle2, (flaress_selector, 2)) tb.connect(flaress_selector, head, dst_out) tb.connect(flaress_selector, debug_switch) _probe_func_thread.start() tb.run() data_in_0 = dst_in0.data() data_in_1 = dst_in1.data() data_in_2 = dst_in2.data() data_out = dst_out.data() switch = debug_switch.data() # Checking lost_items = 0 N_sel0 = 0 N_sel1 = 0 N_sel2 = 0 N_out = len(data_out) for i in range(N): if (data_out[i] == data_in_0[i]): N_sel0 += 1 elif (data_out[i] == data_in_1[(i)]): N_sel1 += 1 elif (data_out[i] == data_in_2[(i)]): N_sel2 += 1 else: lost_items += 1 self.assertGreater(N_sel0, 0) self.assertGreater(N_sel1, 0) self.assertGreater(N_sel2, 0) self.assertEqual(lost_items, 0) self.assertEqual((N_sel0 + N_sel1 + N_sel2), N) print("- Items outputted from in0: ", N_sel0) print("- Items outputted from in1: ", N_sel1) print("- Items outputted from in2: ", N_sel2) print("- Items lost: ", lost_items) #check the switch self.assertEqual(len(switch), 2) self.assertEqual(self.debug_select, 2) print("- Final order of the selector: %d;" % self.debug_select) print( "- First Set function received at the moment (of the simulation): %.2f s;" % (switch[0] * (1.0 / samp_rate))) print( "- Second Set function received at the moment (of the simulation): %.2f s;" % (switch[1] * (1.0 / samp_rate)))
def test_001_d(self): """test_001_d: mux double version with 2 inputs""" tb = self.tb # Variables samp_rate = 4096 N = samp_rate * 3 # Blocks flaress_selector = flaress.selector(gr.sizeof_double * 1, 0, 2, 1) debug_switch = flaress.debug_func_probe(gr.sizeof_double * 1) def _probe_func_probe(): time.sleep(1) try: flaress_selector.set_select(1) debug_switch.debug_nitems() self.debug_select = flaress_selector.get_select() except AttributeError: pass _probe_func_thread = threading.Thread(target=_probe_func_probe) _probe_func_thread.daemon = True throttle0 = blocks.throttle(gr.sizeof_double * 1, samp_rate, True) throttle1 = blocks.throttle(gr.sizeof_double * 1, samp_rate, True) dst_in0 = flaress.vector_sink_double() dst_in1 = flaress.vector_sink_double() dst_out = flaress.vector_sink_double() head0 = blocks.head(gr.sizeof_double, N) head1 = blocks.head(gr.sizeof_double, N) sig_source0 = analog.sig_source_f(samp_rate, analog.GR_SAW_WAVE, 0.125, 10, 0) sig_source1 = analog.sig_source_f(samp_rate, analog.GR_SAW_WAVE, 0.125, -10, -1) conv_in0 = flaress.float_to_double() conv_in1 = flaress.float_to_double() # throttle0.set_max_noutput_items (samp_rate) # throttle1.set_max_noutput_items (samp_rate) # throttle0.set_min_noutput_items (samp_rate) # throttle1.set_min_noutput_items (samp_rate) # Connections tb.connect(sig_source0, conv_in0, throttle0) tb.connect(sig_source1, conv_in1, throttle1) tb.connect(throttle0, head0) tb.connect(throttle1, head1) tb.connect(head0, dst_in0) tb.connect(head1, dst_in1) tb.connect(head0, (flaress_selector, 0)) tb.connect(head1, (flaress_selector, 1)) tb.connect(flaress_selector, dst_out) tb.connect(flaress_selector, debug_switch) _probe_func_thread.start() tb.run() data_in_0 = dst_in0.data() data_in_1 = dst_in1.data() data_out = dst_out.data() switch = debug_switch.data() # Checking lost_items = 0 N_sel0 = 0 N_sel1 = 0 N_out = len(data_out) for i in range(N): if (data_out[i] == data_in_0[i]): N_sel0 += 1 elif (data_out[i] == data_in_1[(i)]): N_sel1 += 1 else: lost_items += 1 self.assertGreater(N_sel0, 0) self.assertGreater(N_sel1, 0) self.assertEqual(lost_items, 0) self.assertEqual((N_sel0 + N_sel1), N) print("- Items outputted from in0: ", N_sel0) print("- Items outputted from in1: ", N_sel1) print("- Items lost: ", lost_items) #check the switch self.assertEqual(len(switch), 1) self.assertEqual(self.debug_select, 1) print("- Final order of the selector: %d;" % self.debug_select) print( "- Set function received at the moment (of the simulation): %.2f s;" % (switch[0] * (1.0 / samp_rate)))