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)
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)
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)
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)
def test_streams(self): """ Test the stream combiner a number of streams. """ width = 32 sendnth = 8 n_streams = 3 buffer_length = 128 max_packet_length = pow(2, config.msg_length_width) defines = config.updated_defines({ 'N_STREAMS': n_streams, 'LOG_N_STREAMS': logceil(n_streams), 'WIDTH': width, 'INPUT_BUFFER_LENGTH': buffer_length, 'LOG_INPUT_BUFFER_LENGTH': logceil(buffer_length), 'MAX_PACKET_LENGTH': max_packet_length, 'LOG_MAX_PACKET_LENGTH': config.msg_length_width, }) top_packet_length = 16 n_packets = 10 data_streams = [] packet_streams = [] data_stream = [] packet_stream = [] max_stream_length = 0 # Prob to start new packet. prob_start = 0.1 for i in range(n_streams): # data and packets have same content but packets is just # broken into the packets data, packets = msg_utils.generate_random_packets( top_packet_length, n_packets, config.msg_length_width, width, prob_start, self.rg) max_stream_length = max(max_stream_length, len(data)) data_streams.append(data) data_stream += data packet_streams.append(packets) packet_stream += packets for ds in data_streams: for i in range(max_stream_length - len(ds)): ds.append(None) expected_packet_dict = msg_utils.make_packet_dict(packet_stream) combined_data = zip(*data_streams) # How many steps are required to simulate the data. steps_rqd = len(combined_data) * sendnth * 2 - 1000 # + 1000 # Create, setup and simulate the test bench. executable = buildutils.generate_icarus_executable( 'message', 'message_stream_combiner', '-streams', defines) tb = TestBenchMessageStreamCombiner(executable, in_raw=combined_data, width=width) tb.run(steps_rqd) # Confirm that our method of converting a stream to packets is correct packets_again = msg_utils.stream_to_packets(data_stream, config.msg_length_width, width, allow_samples=False) packet_dict_again = msg_utils.make_packet_dict(packets_again) self.assertEqual(expected_packet_dict, packet_dict_again) # Now use it on the ouput rather than the input. received_packets = msg_utils.stream_to_packets(tb.out_raw, config.msg_length_width, width, allow_samples=False) received_packet_dict = msg_utils.make_packet_dict(received_packets) self.assertEqual(expected_packet_dict, received_packet_dict)
def test_streams(self): """ Test the stream combiner a number of streams. """ width = 32 sendnth = 8 n_streams = 3 buffer_length = 128 max_packet_length = pow(2, config.msg_length_width) defines = config.updated_defines( {'N_STREAMS': n_streams, 'LOG_N_STREAMS': logceil(n_streams), 'WIDTH': width, 'INPUT_BUFFER_LENGTH': buffer_length, 'LOG_INPUT_BUFFER_LENGTH': logceil(buffer_length), 'MAX_PACKET_LENGTH': max_packet_length, 'LOG_MAX_PACKET_LENGTH': config.msg_length_width, }) top_packet_length = 16 n_packets = 10 data_streams = [] packet_streams = [] data_stream = [] packet_stream = [] max_stream_length = 0 # Prob to start new packet. prob_start = 0.1 for i in range(n_streams): # data and packets have same content but packets is just # broken into the packets data, packets = msg_utils.generate_random_packets( top_packet_length, n_packets, config.msg_length_width, width, prob_start, self.rg) max_stream_length = max(max_stream_length, len(data)) data_streams.append(data) data_stream += data packet_streams.append(packets) packet_stream += packets for ds in data_streams: for i in range(max_stream_length - len(ds)): ds.append(None) expected_packet_dict = msg_utils.make_packet_dict(packet_stream) combined_data = zip(*data_streams) # How many steps are required to simulate the data. steps_rqd = len(combined_data) * sendnth * 2 - 1000 # + 1000 # Create, setup and simulate the test bench. executable = buildutils.generate_icarus_executable( 'message', 'message_stream_combiner', '-streams', defines) tb = TestBenchMessageStreamCombiner( executable, in_raw=combined_data, width=width) tb.run(steps_rqd) # Confirm that our method of converting a stream to packets is correct packets_again = msg_utils.stream_to_packets( data_stream, config.msg_length_width, width, allow_samples=False) packet_dict_again = msg_utils.make_packet_dict(packets_again) self.assertEqual(expected_packet_dict, packet_dict_again) # Now use it on the ouput rather than the input. received_packets = msg_utils.stream_to_packets( tb.out_raw, config.msg_length_width, width, allow_samples=False) received_packet_dict = msg_utils.make_packet_dict(received_packets) self.assertEqual(expected_packet_dict, received_packet_dict)