Ejemplo n.º 1
0
 def test_preserve_tag_head_pos(self):
     """ Test the 'preserve head position' function.
     This will add a 'special' tag to item 0 on stream 1.
     It should be on item 0 of the output stream. """
     packet_len_0 = 5
     data0 = range(packet_len_0)
     packet_len_1 = 3
     data1 = range(packet_len_1)
     mux = blocks.tagged_stream_mux(
             gr.sizeof_float,
             self.tsb_key,
             1 # Mark port 1 as carrying special tags on the head position
     )
     sink = blocks.tsb_vector_sink_f(tsb_key=self.tsb_key)
     self.tb.connect(
         blocks.vector_source_f(data0),
         blocks.stream_to_tagged_stream(gr.sizeof_float, 1, packet_len_0, self.tsb_key),
         (mux, 0)
     )
     self.tb.connect(
         blocks.vector_source_f(range(packet_len_1), tags=(make_tag('spam', 'eggs', 0),)),
         blocks.stream_to_tagged_stream(gr.sizeof_float, 1, packet_len_1, self.tsb_key),
         (mux, 1)
     )
     self.tb.connect(mux, sink)
     self.tb.run()
     self.assertEqual(len(sink.data()), 1)
     self.assertEqual(sink.data()[0], tuple(data0 + data1))
     self.assertEqual(len(sink.tags()), 1)
     tag = gr.tag_to_python(sink.tags()[0])
     tag = (tag.offset, tag.key, tag.value)
     tag_expected = (0, 'spam', 'eggs')
     self.assertEqual(tag, tag_expected)
Ejemplo n.º 2
0
 def test_preserve_tag_head_pos(self):
     """ Test the 'preserve head position' function.
     This will add a 'special' tag to item 0 on stream 1.
     It should be on item 0 of the output stream. """
     packet_len_0 = 5
     data0 = list(range(packet_len_0))
     packet_len_1 = 3
     data1 = list(range(packet_len_1))
     mux = blocks.tagged_stream_mux(
         gr.sizeof_float,
         self.tsb_key,
         1  # Mark port 1 as carrying special tags on the head position
     )
     sink = blocks.tsb_vector_sink_f(tsb_key=self.tsb_key)
     self.tb.connect(
         blocks.vector_source_f(data0),
         blocks.stream_to_tagged_stream(gr.sizeof_float, 1, packet_len_0,
                                        self.tsb_key), (mux, 0))
     self.tb.connect(
         blocks.vector_source_f(list(range(packet_len_1)),
                                tags=(make_tag('spam', 'eggs', 0), )),
         blocks.stream_to_tagged_stream(gr.sizeof_float, 1, packet_len_1,
                                        self.tsb_key), (mux, 1))
     self.tb.connect(mux, sink)
     self.tb.run()
     self.assertEqual(len(sink.data()), 1)
     self.assertEqual(sink.data()[0], tuple(data0 + data1))
     self.assertEqual(len(sink.tags()), 1)
     tag = gr.tag_to_python(sink.tags()[0])
     tag = (tag.offset, tag.key, tag.value)
     tag_expected = (0, 'spam', 'eggs')
     self.assertEqual(tag, tag_expected)
Ejemplo n.º 3
0
 def test_001_t(self):
     packet_len = 4
     data = list(range(2 * packet_len))
     tag = gr.tag_t()
     tag.key = pmt.intern("foo")
     tag.offset = 5
     tag.value = pmt.intern("bar")
     src = blocks.vector_source_f(data, tags=(tag, ))
     sink = blocks.tsb_vector_sink_f(tsb_key=self.tsb_key)
     self.tb.connect(
         src,
         blocks.stream_to_tagged_stream(gr.sizeof_float, 1, packet_len,
                                        self.tsb_key), sink)
     self.tb.run()
     self.assertEqual([data[0:packet_len], data[packet_len:]], sink.data())
     self.assertEqual(len(sink.tags()), 1)
     self.assertEqual(sink.tags()[0].offset, tag.offset)
Ejemplo n.º 4
0
 def test_001_t (self):
     packet_len = 4
     data = range(2 * packet_len)
     tag = gr.tag_t()
     tag.key = pmt.intern("foo")
     tag.offset = 5
     tag.value = pmt.intern("bar")
     src = blocks.vector_source_f(data, tags=(tag,))
     sink = blocks.tsb_vector_sink_f(tsb_key=self.tsb_key)
     self.tb.connect(
             src,
             blocks.stream_to_tagged_stream(gr.sizeof_float, 1, packet_len, self.tsb_key),
             sink
     )
     self.tb.run()
     self.assertEqual((tuple(data[0:packet_len]), tuple(data[packet_len:])), sink.data())
     self.assertEqual(len(sink.tags()), 1)
     self.assertEqual(sink.tags()[0].offset, tag.offset)