コード例 #1
0
ファイル: qa_message.py プロジェクト: benreynwar/fpga-sdrlib
 def test_one(self):
     """
     Tests split module and message stream combiner together.
     """
     width = 32
     sendnth = 2
     max_packet_length = 10
     n_packets = 20
     data1 = []
     for i in range(n_packets):
         length = random.randint(0, max_packet_length)
         packet = msg_utils.generate_random_packet(length, config.msg_length_width,
                                         width)
         data1.extend(packet)
     max_val = pow(2, width-1)-1
     data2 = [random.randint(1, max_val) for i in range(len(data1))]
     i_data = []
     for d1, d2 in zip(data1, data2):
         i_data.append(d1)
         i_data.append(d2)
     a_data = data1 + data2
     padded_data = i_data + [0]*1000
     buffer_length = 128
     defines = config.updated_defines(
         {'COMBINER_BUFFER_LENGTH': buffer_length,
          'LOG_COMBINER_BUFFER_LENGTH': logceil(buffer_length),
          'MAX_PACKET_LENGTH': pow(2, config.msg_length_width),
          'ERRORCODE': 666,
          'WIDTH': width,
          })
     executable = buildutils.generate_icarus_executable(
         'message', 'splitcombiner', '-test', defines=defines)
     fpgaimage = buildutils.generate_B100_image(
         'message', 'splitcombiner', '-test', defines=defines)
     tb_icarus = TestBenchIcarusOuter(executable, in_raw=i_data,
                                      sendnth=sendnth)
     tb_b100 = TestBenchB100(fpgaimage, in_raw=padded_data)
     for tb, steps in (
             (tb_icarus, len(i_data)*sendnth*2+1000),
             (tb_b100, 100000), 
             ):
         tb.run(steps)
         e_samples, e_packets = msg_utils.stream_to_samples_and_packets(
             a_data, config.msg_length_width, width)
         r_samples, r_packets = msg_utils.stream_to_samples_and_packets(
             tb.out_raw, config.msg_length_width, width)
         # Remove 0's from samples.
         # The splitter can introduce 0's at beginning and end.
         r_samples = [r for r in r_samples if r != 0]
         self.assertEqual(len(e_samples), len(r_samples))
         for e, r in zip(e_samples, r_samples):
             self.assertEqual(e, r)
         # Confirm all the packets are equal.
         self.assertEqual(len(e_packets), len(r_packets))
         for ep, rp in zip(e_packets, r_packets):
             self.assertEqual(len(ep), len(rp))
             for e, r in zip(ep, rp):
                 self.assertEqual(e, r)
コード例 #2
0
 def test_combo(self):
     """
     Tests sample msg splitter and message stream combiner together.
     """
     top_packet_length = 64
     n_packets = 20
     width = 32
     prob_start = 0.1
     data, packets = msg_utils.generate_random_packets(
         top_packet_length,
         n_packets,
         config.msg_length_width,
         width,
         prob_start,
         self.rg,
         none_sample=False)
     padded_data = data
     buffer_length = 128
     defines = config.updated_defines({
         'COMBINER_BUFFER_LENGTH':
         buffer_length,
         'LOG_COMBINER_BUFFER_LENGTH':
         logceil(buffer_length),
         'MAX_PACKET_LENGTH':
         pow(2, config.msg_length_width),
     })
     executable = buildutils.generate_icarus_executable('message',
                                                        'combo',
                                                        '-test',
                                                        defines=defines)
     fpgaimage = buildutils.generate_B100_image('message',
                                                'combo',
                                                '-test',
                                                defines=defines)
     tb_icarus = TestBenchIcarusOuter(executable, in_raw=data)
     tb_b100 = TestBenchB100(fpgaimage, in_raw=padded_data)
     for tb, steps in (
         (tb_icarus, 10000),
         (tb_b100, 100000),
     ):
         tb.run(steps)
         e_samples, e_packets = msg_utils.stream_to_samples_and_packets(
             data, config.msg_length_width, width)
         r_samples, r_packets = msg_utils.stream_to_samples_and_packets(
             tb.out_raw, config.msg_length_width, width)
         # Confirm all the samples are equal.
         self.assertEqual(len(e_samples), len(r_samples))
         for e, r in zip(e_samples, r_samples):
             self.assertEqual(e, r)
         # Confirm all the packets are equal.
         self.assertEqual(len(e_packets), len(r_packets))
         for ep, rp in zip(e_packets, r_packets):
             self.assertEqual(len(ep), len(rp))
             for e, r in zip(ep, rp):
                 self.assertEqual(e, r)
コード例 #3
0
ファイル: qa_message.py プロジェクト: benreynwar/fpga-sdrlib
 def test_one(self):
     """
     Tests passing debug messages back.
     """
     width = 32
     sendnth = 2
     max_val = pow(2, width-2)-1
     n_data = 10
     in_data = [random.randint(1, max_val) for i in range(n_data)]
     defines = config.updated_defines({})
     executable = buildutils.generate_icarus_executable(
         'message', 'debug', '-test', defines=defines)
     fpgaimage = buildutils.generate_B100_image(
         'message', 'debug', '-test', defines=defines)
     tb_icarus = TestBenchIcarusOuter(executable, in_raw=in_data,
                                      sendnth=sendnth)
     tb_b100 = TestBenchB100(fpgaimage, in_raw=in_data)
     for tb, steps in (
         #(tb_icarus, len(in_data)*sendnth*2+1000),
         (tb_b100, 100000), 
         ):
         tb.run(steps)
         r_samples, r_packets = msg_utils.stream_to_samples_and_packets(
             tb.out_raw, config.msg_length_width, width)
         print(in_data)
         print(r_samples)
         print(r_packets)
         self.assertEqual(len(in_data), len(r_samples))
         for e, r in zip(in_data, r_samples):
             self.assertEqual(e, r)
         e_even = [s for s in in_data if s%2==0]
         r_even = [p[1] for p in r_packets]
         self.assertEqual(len(e_even), len(r_even))
         for e, r in zip(e_even, r_even):
             self.assertEqual(e, r)
コード例 #4
0
 def run(self, n_receive=None):
     """
     Run the simulation.
     
     Args:
         n_receive: Stop after receiving this many samples.
     """
     b100.set_image(self.fpgaimage)
     # steps_rqd only in for compatibility
     from gnuradio import gr, uhd
     if n_receive is None:
         n_receive = 10000
     # Flip high and low bits of in_raw
     flipped_raw = flip_bits(self.in_raw, self.width)
     flipped_raw = unsigned_to_signed(flipped_raw, self.width)
     stream_args = uhd.stream_args(cpu_format='sc16', channels=range(1))
     from_usrp = uhd.usrp_source(device_addr='', stream_args=stream_args)
     head = gr.head(4, n_receive)
     snk = gr.vector_sink_i()
     to_usrp = uhd.usrp_sink(device_addr='', stream_args=stream_args)
     src = gr.vector_source_i(flipped_raw)
     tb = gr.top_block()
     tb.connect(from_usrp, head, snk)
     tb.connect(src, to_usrp)
     tb.run()
     self.out_raw = snk.data()
     # Remove 0's
     start_offset = None
     stop_offset = None
     enumerated_raw = list(enumerate(self.out_raw))
     for i, r in enumerated_raw:
         if r != 0:
             start_offset = i
             break
     for i, r in reversed(enumerated_raw):
         if r != 0:
             stop_offset = i
             break
     if start_offset is None or stop_offset is None:
         raise StandardError("Could not find any non-zero returned data.")
     self.out_raw = self.out_raw[start_offset:stop_offset + 1]
     # Shift to positive integers
     positive = []
     for r in self.out_raw:
         if r < 0:
             r += pow(2, self.width)
         positive.append(r)
     self.out_raw = positive
     # Flip bits in out_raw
     self.out_raw = flip_bits(self.out_raw, self.width)
     if self.output_msgs:
         header_shift = pow(2, self.width - 1)
         samples, packets = stream_to_samples_and_packets(self.out_raw)
         self.out_samples = [
             int_to_c(s, self.width / 2 - 1) for s in samples
         ]
         self.out_messages = packets
コード例 #5
0
 def run(self, clks):
     """
     Run a test bench simulation.
     """
     TestBenchIcarusBase.run(self, clks)
     self.out_samples = [int_to_c(r, self.width / 2) for r in self.out_raw]
     samples, packets = stream_to_samples_and_packets(self.out_msgs)
     if samples:
         raise StandardError("Found samples is message stream.")
     self.out_messages = packets
コード例 #6
0
ファイル: qa_message.py プロジェクト: benreynwar/fpga-sdrlib
 def test_combo(self):
     """
     Tests sample msg splitter and message stream combiner together.
     """
     top_packet_length = 64
     n_packets = 20
     width = 32
     prob_start = 0.1
     data, packets = msg_utils.generate_random_packets(
         top_packet_length, n_packets, config.msg_length_width,
         width, prob_start, self.rg, none_sample=False)
     padded_data = data
     buffer_length = 128
     defines = config.updated_defines(
         {'COMBINER_BUFFER_LENGTH': buffer_length,
          'LOG_COMBINER_BUFFER_LENGTH': logceil(buffer_length),
          'MAX_PACKET_LENGTH': pow(2, config.msg_length_width),
          })
     executable = buildutils.generate_icarus_executable(
         'message', 'combo', '-test', defines=defines)
     fpgaimage = buildutils.generate_B100_image(
         'message', 'combo', '-test', defines=defines)
     tb_icarus = TestBenchIcarusOuter(executable, in_raw=data)
     tb_b100 = TestBenchB100(fpgaimage, in_raw=padded_data)
     for tb, steps in (
             (tb_icarus, 10000),
             (tb_b100, 100000), 
             ):
         tb.run(steps)
         e_samples, e_packets = msg_utils.stream_to_samples_and_packets(
             data, config.msg_length_width, width)
         r_samples, r_packets = msg_utils.stream_to_samples_and_packets(
             tb.out_raw, config.msg_length_width, width)
         # Confirm all the samples are equal.
         self.assertEqual(len(e_samples), len(r_samples))
         for e, r in zip(e_samples, r_samples):
             self.assertEqual(e, r)
         # Confirm all the packets are equal.
         self.assertEqual(len(e_packets), len(r_packets))
         for ep, rp in zip(e_packets, r_packets):
             self.assertEqual(len(ep), len(rp))
             for e, r in zip(ep, rp):
                 self.assertEqual(e, r)
コード例 #7
0
ファイル: testbench.py プロジェクト: benreynwar/fpga-sdrlib
 def run(self, clks):
     """
     Run a test bench simulation.
     """
     TestBenchIcarusBase.run(self, clks)
     self.out_samples = [int_to_c(r, self.width/2) for r in self.out_raw]
     samples, packets = stream_to_samples_and_packets(self.out_msgs) 
     if samples:
         raise StandardError("Found samples is message stream.")
     self.out_messages = packets
コード例 #8
0
ファイル: testbench.py プロジェクト: benreynwar/fpga-sdrlib
 def run(self, steps_rqd):
     super(TestBenchIcarusOuter, self).run(steps_rqd)
     header_shift = pow(2, self.width-1)
     if self.output_msgs:
         samples, packets = stream_to_samples_and_packets(self.out_raw)
         for s in samples:
             if s == config.errorcode:
                 raise ValueError("Errorcode detected.")
         self.out_samples = [int_to_c(s, self.width/2-1) for s in samples]
         self.out_messages = packets
コード例 #9
0
ファイル: testbench.py プロジェクト: benreynwar/fpga-sdrlib
 def run(self, n_receive=None):
     """
     Run the simulation.
     
     Args:
         n_receive: Stop after receiving this many samples.
     """
     b100.set_image(self.fpgaimage)
     # steps_rqd only in for compatibility
     from gnuradio import gr, uhd
     if n_receive is None:
         n_receive = 10000
     # Flip high and low bits of in_raw
     flipped_raw = flip_bits(self.in_raw, self.width)
     flipped_raw = unsigned_to_signed(flipped_raw, self.width)
     stream_args = uhd.stream_args(cpu_format='sc16', channels=range(1))
     from_usrp = uhd.usrp_source(device_addr='', stream_args=stream_args)
     head = gr.head(4, n_receive)
     snk = gr.vector_sink_i()
     to_usrp = uhd.usrp_sink(device_addr='', stream_args=stream_args)
     src = gr.vector_source_i(flipped_raw)
     tb = gr.top_block()
     tb.connect(from_usrp, head, snk)
     tb.connect(src, to_usrp)
     tb.run()
     self.out_raw = snk.data()
     # Remove 0's
     start_offset = None
     stop_offset = None
     enumerated_raw = list(enumerate(self.out_raw))
     for i, r in enumerated_raw:
         if r != 0:
             start_offset = i
             break
     for i, r in reversed(enumerated_raw):
         if r != 0:
             stop_offset = i
             break
     if start_offset is None or stop_offset is None:
         raise StandardError("Could not find any non-zero returned data.")
     self.out_raw = self.out_raw[start_offset: stop_offset+1]
     # Shift to positive integers
     positive = []
     for r in self.out_raw:
         if r < 0:
             r += pow(2, self.width)
         positive.append(r)
     self.out_raw = positive
     # Flip bits in out_raw
     self.out_raw = flip_bits(self.out_raw, self.width)
     if self.output_msgs:
         header_shift = pow(2, self.width-1)
         samples, packets = stream_to_samples_and_packets(self.out_raw)
         self.out_samples = [int_to_c(s, self.width/2-1) for s in samples]
         self.out_messages = packets
コード例 #10
0
 def run(self, steps_rqd):
     super(TestBenchIcarusOuter, self).run(steps_rqd)
     header_shift = pow(2, self.width - 1)
     if self.output_msgs:
         samples, packets = stream_to_samples_and_packets(self.out_raw)
         for s in samples:
             if s == config.errorcode:
                 raise ValueError("Errorcode detected.")
         self.out_samples = [
             int_to_c(s, self.width / 2 - 1) for s in samples
         ]
         self.out_messages = packets
コード例 #11
0
ファイル: qa_message.py プロジェクト: benreynwar/fpga-sdrlib
 def setUp(self):
     self.rg = random.Random(0)
     top_packet_length = 64
     n_packets = 10
     self.width = 32
     prob_start = 0.1
     data, packets = msg_utils.generate_random_packets(
         top_packet_length, n_packets, config.msg_length_width,
         self.width, prob_start, self.rg, none_sample=False)
     self.dummypacket = msg_utils.generate_random_packet(0, config.msg_length_width, self.width)
     self.original_data = data
     self.data = data + self.dummypacket * 100000
     self.samples, self.packets = msg_utils.stream_to_samples_and_packets(
         data, config.msg_length_width, self.width)
コード例 #12
0
 def setUp(self):
     self.rg = random.Random(0)
     top_packet_length = 64
     n_packets = 10
     self.width = 32
     prob_start = 0.1
     data, packets = msg_utils.generate_random_packets(
         top_packet_length,
         n_packets,
         config.msg_length_width,
         self.width,
         prob_start,
         self.rg,
         none_sample=False)
     self.dummypacket = msg_utils.generate_random_packet(
         0, config.msg_length_width, self.width)
     self.original_data = data
     self.data = data + self.dummypacket * 100000
     self.samples, self.packets = msg_utils.stream_to_samples_and_packets(
         data, config.msg_length_width, self.width)
コード例 #13
0
 def test_one(self):
     """
     Tests passing debug messages back.
     """
     width = 32
     sendnth = 2
     max_val = pow(2, width - 2) - 1
     n_data = 10
     in_data = [random.randint(1, max_val) for i in range(n_data)]
     defines = config.updated_defines({})
     executable = buildutils.generate_icarus_executable('message',
                                                        'debug',
                                                        '-test',
                                                        defines=defines)
     fpgaimage = buildutils.generate_B100_image('message',
                                                'debug',
                                                '-test',
                                                defines=defines)
     tb_icarus = TestBenchIcarusOuter(executable,
                                      in_raw=in_data,
                                      sendnth=sendnth)
     tb_b100 = TestBenchB100(fpgaimage, in_raw=in_data)
     for tb, steps in (
             #(tb_icarus, len(in_data)*sendnth*2+1000),
         (tb_b100, 100000), ):
         tb.run(steps)
         r_samples, r_packets = msg_utils.stream_to_samples_and_packets(
             tb.out_raw, config.msg_length_width, width)
         print(in_data)
         print(r_samples)
         print(r_packets)
         self.assertEqual(len(in_data), len(r_samples))
         for e, r in zip(in_data, r_samples):
             self.assertEqual(e, r)
         e_even = [s for s in in_data if s % 2 == 0]
         r_even = [p[1] for p in r_packets]
         self.assertEqual(len(e_even), len(r_even))
         for e, r in zip(e_even, r_even):
             self.assertEqual(e, r)
コード例 #14
0
    def test_sample_msg_splitter_returns_msgs(self):
        """
        Tests the sample msg splitter.

        Just checks that the messages are correct.
        """
        # Then test qa_wrapper modules returning the messages.
        executable = buildutils.generate_icarus_executable(
            'message', 'sample_msg_splitter_returns_msgs', '-test')
        fpgaimage = buildutils.generate_B100_image(
            'message', 'sample_msg_splitter_returns_msgs', '-test')
        tb_icarus = TestBenchIcarusOuter(executable, in_raw=self.data)
        tb_b100 = TestBenchB100(fpgaimage, in_raw=self.data)
        for tb, steps in (
            (tb_icarus, 10000),
            (tb_b100, 1000),
        ):
            tb.run(steps)
            samples, packets = msg_utils.stream_to_samples_and_packets(
                tb.out_raw, config.msg_length_width, self.width)
            self.assertEqual(len(samples), 0)
            first_index = None
            for i, p in enumerate(packets):
                if p != self.dummypacket:
                    first_index = i
                    break
            last_index = None
            for i, p in reversed(list(enumerate(packets))):
                if p != self.dummypacket:
                    last_index = i + 1
                    break
            if first_index is None:
                raise StandardError("No packets found")
            packets = packets[first_index:last_index]
            self.assertEqual(len(packets), len(self.packets))
            for e, r in zip(packets, self.packets):
                self.assertEqual(len(e), len(r))
                for ee, rr in zip(e, r):
                    self.assertEqual(ee, rr)
コード例 #15
0
ファイル: qa_message.py プロジェクト: benreynwar/fpga-sdrlib
    def test_sample_msg_splitter_returns_msgs(self):
        """
        Tests the sample msg splitter.

        Just checks that the messages are correct.
        """
        # Then test qa_wrapper modules returning the messages.
        executable = buildutils.generate_icarus_executable(
            'message', 'sample_msg_splitter_returns_msgs', '-test')
        fpgaimage = buildutils.generate_B100_image(
            'message', 'sample_msg_splitter_returns_msgs', '-test')
        tb_icarus = TestBenchIcarusOuter(executable, in_raw=self.data)
        tb_b100 = TestBenchB100(fpgaimage, in_raw=self.data)
        for tb, steps in (
            (tb_icarus, 10000),
            (tb_b100, 1000), 
            ):
            tb.run(steps)
            samples, packets = msg_utils.stream_to_samples_and_packets(
                tb.out_raw, config.msg_length_width, self.width)
            self.assertEqual(len(samples), 0)
            first_index = None
            for i, p in enumerate(packets):
                if p != self.dummypacket:
                    first_index = i
                    break
            last_index = None
            for i, p in reversed(list(enumerate(packets))):
                if p != self.dummypacket:
                    last_index = i+1
                    break
            if first_index is None:
                raise StandardError("No packets found")
            packets = packets[first_index: last_index]
            self.assertEqual(len(packets), len(self.packets))
            for e, r in zip(packets, self.packets):
                self.assertEqual(len(e), len(r))
                for ee, rr in zip(e, r):
                    self.assertEqual(ee, rr)
コード例 #16
0
ファイル: qa_message.py プロジェクト: benreynwar/fpga-sdrlib
    def test_sample_msg_splitter(self):
        """
        Tests the sample msg splitter.

        Just checks that the samples are correct.
        """
        # First test qa_wrapper modules that return the samples
        executable = buildutils.generate_icarus_executable(
            'message', 'sample_msg_splitter', '-test')
        fpgaimage = buildutils.generate_B100_image(
            'message', 'sample_msg_splitter', '-test')
        tb_icarus = TestBenchIcarusOuter(executable, in_raw=self.data)
        tb_b100 = TestBenchB100(fpgaimage, in_raw=self.data)
        for tb, steps in (
            (tb_icarus, 10000),
            (tb_b100, 10000),
            ):
            tb.run(steps)
            samples, packets = msg_utils.stream_to_samples_and_packets(
                self.original_data, config.msg_length_width, self.width)
            self.assertEqual(len(samples), len(tb.out_raw))
            for e, r in zip(samples, tb.out_raw):
                self.assertEqual(e, r)
コード例 #17
0
    def test_sample_msg_splitter(self):
        """
        Tests the sample msg splitter.

        Just checks that the samples are correct.
        """
        # First test qa_wrapper modules that return the samples
        executable = buildutils.generate_icarus_executable(
            'message', 'sample_msg_splitter', '-test')
        fpgaimage = buildutils.generate_B100_image('message',
                                                   'sample_msg_splitter',
                                                   '-test')
        tb_icarus = TestBenchIcarusOuter(executable, in_raw=self.data)
        tb_b100 = TestBenchB100(fpgaimage, in_raw=self.data)
        for tb, steps in (
            (tb_icarus, 10000),
            (tb_b100, 10000),
        ):
            tb.run(steps)
            samples, packets = msg_utils.stream_to_samples_and_packets(
                self.original_data, config.msg_length_width, self.width)
            self.assertEqual(len(samples), len(tb.out_raw))
            for e, r in zip(samples, tb.out_raw):
                self.assertEqual(e, r)
コード例 #18
0
 def test_one(self):
     """
     Tests split module and message stream combiner together.
     """
     width = 32
     sendnth = 2
     max_packet_length = 10
     n_packets = 20
     data1 = []
     for i in range(n_packets):
         length = random.randint(0, max_packet_length)
         packet = msg_utils.generate_random_packet(length,
                                                   config.msg_length_width,
                                                   width)
         data1.extend(packet)
     max_val = pow(2, width - 1) - 1
     data2 = [random.randint(1, max_val) for i in range(len(data1))]
     i_data = []
     for d1, d2 in zip(data1, data2):
         i_data.append(d1)
         i_data.append(d2)
     a_data = data1 + data2
     padded_data = i_data + [0] * 1000
     buffer_length = 128
     defines = config.updated_defines({
         'COMBINER_BUFFER_LENGTH':
         buffer_length,
         'LOG_COMBINER_BUFFER_LENGTH':
         logceil(buffer_length),
         'MAX_PACKET_LENGTH':
         pow(2, config.msg_length_width),
         'ERRORCODE':
         666,
         'WIDTH':
         width,
     })
     executable = buildutils.generate_icarus_executable('message',
                                                        'splitcombiner',
                                                        '-test',
                                                        defines=defines)
     fpgaimage = buildutils.generate_B100_image('message',
                                                'splitcombiner',
                                                '-test',
                                                defines=defines)
     tb_icarus = TestBenchIcarusOuter(executable,
                                      in_raw=i_data,
                                      sendnth=sendnth)
     tb_b100 = TestBenchB100(fpgaimage, in_raw=padded_data)
     for tb, steps in (
         (tb_icarus, len(i_data) * sendnth * 2 + 1000),
         (tb_b100, 100000),
     ):
         tb.run(steps)
         e_samples, e_packets = msg_utils.stream_to_samples_and_packets(
             a_data, config.msg_length_width, width)
         r_samples, r_packets = msg_utils.stream_to_samples_and_packets(
             tb.out_raw, config.msg_length_width, width)
         # Remove 0's from samples.
         # The splitter can introduce 0's at beginning and end.
         r_samples = [r for r in r_samples if r != 0]
         self.assertEqual(len(e_samples), len(r_samples))
         for e, r in zip(e_samples, r_samples):
             self.assertEqual(e, r)
         # Confirm all the packets are equal.
         self.assertEqual(len(e_packets), len(r_packets))
         for ep, rp in zip(e_packets, r_packets):
             self.assertEqual(len(ep), len(rp))
             for e, r in zip(ep, rp):
                 self.assertEqual(e, r)