def test_one_stream(self): """ Test the stream combiner with a single stream of data. """ width = 32 sendnth = 4 input_buffer_length = 64 max_packet_length = 1024 # First bit is 0 so data is from 0 to pow(2, 31)-1 maxint = pow(2, width - 1) - 1 n_data = 10 data = [self.rg.randint(0, maxint) for d in range(n_data)] # How many steps are required to simulate the data. steps_rqd = n_data * sendnth * 2 + 1000 # Create, setup and simulate the test bench. defines = config.updated_defines({ 'N_STREAMS': 1, 'LOG_N_STREAMS': 1, 'WIDTH': width, 'INPUT_BUFFER_LENGTH': 16, 'LOG_INPUT_BUFFER_LENGTH': 4, 'MAX_PACKET_LENGTH': 16, 'LOG_MAX_PACKET_LENGTH': 4, }) executable = buildutils.generate_icarus_executable( 'message', 'message_stream_combiner', '-one_stream', defines) tb = TestBenchIcarusOuter(executable, in_raw=data, width=width, output_msgs=False) tb.run(steps_rqd) # Confirm that our data is correct. self.assertEqual(len(tb.out_raw), len(data)) for r, e in zip(tb.out_raw, data): self.assertEqual(e, r)
def test_one_stream(self): """ Test the stream combiner with a single stream of data. """ width = 32 sendnth = 4 input_buffer_length = 64 max_packet_length = 1024 # First bit is 0 so data is from 0 to pow(2, 31)-1 maxint = pow(2, width-1)-1 n_data = 10 data = [self.rg.randint(0, maxint) for d in range(n_data)] # How many steps are required to simulate the data. steps_rqd = n_data * sendnth * 2 + 1000 # Create, setup and simulate the test bench. defines = config.updated_defines( {'N_STREAMS': 1, 'LOG_N_STREAMS': 1, 'WIDTH': width, 'INPUT_BUFFER_LENGTH': 16, 'LOG_INPUT_BUFFER_LENGTH': 4, 'MAX_PACKET_LENGTH': 16, 'LOG_MAX_PACKET_LENGTH': 4, }) executable = buildutils.generate_icarus_executable( 'message', 'message_stream_combiner', '-one_stream', defines) tb = TestBenchIcarusOuter(executable, in_raw=data, width=width, output_msgs=False) tb.run(steps_rqd) # Confirm that our data is correct. self.assertEqual(len(tb.out_raw), len(data)) for r, e in zip(tb.out_raw, data): self.assertEqual(e, r)
def test_slicer(self): """ Test the stream slicer. """ width = 32 n_slices = 3 sendnth = 4 buffer_length = 16 n_data = 10 data = [] expected_data = [] mfactor = pow(2, width) for i in range(n_data): m = pow(mfactor, n_slices - 1) t = 0 for s in range(n_slices): d = self.rg.randint(0, mfactor - 1) t += d * m m = m / mfactor expected_data.append(d) data.append(t) # How many steps are required to simulate the data. steps_rqd = len(data) * sendnth * 2 #+ 1000 # Create, setup and simulate the test bench. defines = config.updated_defines({ 'N_SLICES': 3, 'LOG_N_SLICES': logceil(n_slices), 'WIDTH': width, 'BUFFER_LENGTH': buffer_length, 'LOG_BUFFER_LENGTH': logceil(buffer_length), }) executable = buildutils.generate_icarus_executable( 'message', 'message_slicer', '-test', defines) tb = TestBenchIcarusOuter(executable, in_raw=data, width=width, output_msgs=False) tb.run(steps_rqd) # Now check output self.assertEqual(len(expected_data), len(tb.out_raw)) for e, r in zip(expected_data, tb.out_raw): self.assertAlmostEqual(e, r, 3)
def test_slicer(self): """ Test the stream slicer. """ width = 32 n_slices = 3 sendnth = 4 buffer_length = 16 n_data = 10 data = [] expected_data = [] mfactor = pow(2, width) for i in range(n_data): m = pow(mfactor, n_slices-1) t = 0 for s in range(n_slices): d = self.rg.randint(0, mfactor-1) t += d * m m = m / mfactor expected_data.append(d) data.append(t) # How many steps are required to simulate the data. steps_rqd = len(data) * sendnth * 2 #+ 1000 # Create, setup and simulate the test bench. defines = config.updated_defines( {'N_SLICES': 3, 'LOG_N_SLICES': logceil(n_slices), 'WIDTH': width, 'BUFFER_LENGTH': buffer_length, 'LOG_BUFFER_LENGTH': logceil(buffer_length), }) executable = buildutils.generate_icarus_executable( 'message', 'message_slicer', '-test', defines) tb = TestBenchIcarusOuter(executable, in_raw=data, width=width, output_msgs=False) tb.run(steps_rqd) # Now check output self.assertEqual(len(expected_data), len(tb.out_raw)) for e,r in zip(expected_data, tb.out_raw): self.assertAlmostEqual(e, r, 3)
def test_one(self): """ Test the split module. """ width = 32 sendnth = 4 maxint = pow(2, width)-1 n_data = 100 n_streams = 3 data = [random.randint(0, maxint) for d in range(n_data)] # Work out what the expected result is. expected_data = [] for ds in [data[n_streams*i:n_streams*(i+1)] for i in range(n_data/n_streams)]: e_d = 0 f = 1 for d in ds: e_d += d*f f *= pow(2, width) expected_data.append(e_d) # How many steps are required to simulate the data. steps_rqd = n_data * sendnth * 2 + 1000 # Create, setup and simulate the test bench. defines = config.updated_defines( {'N_OUT_STREAMS': n_streams, 'LOG_N_OUT_STREAMS': logceil(n_streams), 'WIDTH': width, }) executable = buildutils.generate_icarus_executable( 'flow', 'split', '-test', defines) tb = TestBenchIcarusOuter(executable, in_raw=data, width=width, output_msgs=False) tb.run(steps_rqd) # Confirm that our data is correct. self.assertEqual(len(tb.out_raw), len(expected_data)) for r, e in zip(tb.out_raw, expected_data): self.assertEqual(e, r)