def test_pattern_num_samples(): """Test for the PatternGenerator class. This test will examine 0 sample and more than the maximum number of samples. In these cases, exception should be raised. Here the `MAX_NUM_PATTERN_SAMPLE` is used for display purpose. The maximum number of samples that can be captured by the trace analyzer is defined as `MAX_NUM_TRACE_SAMPLES`. """ ol.download() for num_samples in [0, MAX_NUM_PATTERN_SAMPLES + 1]: loopback_sent = build_loopback_pattern(num_samples) pattern_generator = PatternGenerator(mb_info) exception_raised = False try: pattern_generator.trace(use_analyzer=True, num_analyzer_samples=num_samples) pattern_generator.setup(loopback_sent, stimulus_group_name='stimulus', analysis_group_name='analysis') except ValueError: exception_raised = True assert exception_raised, 'Should raise exception if number of ' \ 'samples is out of range.' pattern_generator.reset() del pattern_generator
def test_all_generators_step(): """Test all the generator classes implemented in this overlay. In this test, the boolean generators, pattern generators, and FSM generators are tested together by calling the `step()` method. By stepping for enough number of samples, the waveform should look identical to the results received by calling `run()` directly. """ ol.download() logictools_controller = LogicToolsController( mb_info, 'PYNQZ1_LOGICTOOLS_SPECIFICATION') for generator_name in logictools_controller.status: assert logictools_controller.status[generator_name] == 'RESET' print("\nConnect {} to GND, and {} to VCC.".format(rst, direction)) input("Hit enter after done ...") print('Connect randomly {} to VCC or GND.'.format(in_pins)) input("Hit enter after done ...") num_samples = 64 fsm_generator = FSMGenerator(mb_info) fsm_generator.trace(num_analyzer_samples=num_samples) fsm_generator.setup(fsm_spec, frequency_mhz=10) pattern_generator = PatternGenerator(mb_info) pattern_generator.trace(num_analyzer_samples=num_samples) pattern_generator.setup(loopback_64_samples, stimulus_group_name='stimulus', analysis_group_name='analysis', frequency_mhz=10) boolean_generator = BooleanGenerator(mb_info) boolean_generator.trace(num_analyzer_samples=num_samples) boolean_generator.setup(expressions=test_expressions, frequency_mhz=10) for _ in range(num_samples): logictools_controller.step( [fsm_generator, pattern_generator, boolean_generator]) for generator_name in logictools_controller.status: if generator_name != 'TraceAnalyzer': assert logictools_controller.status[generator_name] == 'RUNNING' check_boolean_data(boolean_generator) check_pattern_data(pattern_generator, num_samples) check_fsm_data(fsm_generator, num_samples) logictools_controller.stop( [fsm_generator, pattern_generator, boolean_generator]) for generator_name in logictools_controller.status: assert logictools_controller.status[generator_name] == 'READY' logictools_controller.reset( [fsm_generator, pattern_generator, boolean_generator]) for generator_name in logictools_controller.status: assert logictools_controller.status[generator_name] == 'RESET' del fsm_generator, pattern_generator, boolean_generator
def test_all_generators_state(): """Test all the generator classes implemented in this overlay. In this test, the boolean generators, pattern generators, and FSM generators are all instantiated. Their states are checked during the test. A maximum number of pattern samples are tested. """ ol.download() print("\nConnect {} to GND, and {} to VCC.".format(rst, direction)) input("Hit enter after done ...") print('Connect randomly {} to VCC or GND.'.format(in_pins)) input('Hit enter after done ...') fsm_generator = FSMGenerator(mb_info) assert fsm_generator.status == 'RESET' fsm_generator.trace(use_analyzer=False) fsm_generator.setup(fsm_spec, frequency_mhz=10) assert fsm_generator.status == 'READY' pattern_generator = PatternGenerator(mb_info) assert pattern_generator.status == 'RESET' pattern_generator.trace(use_analyzer=False) pattern_generator.setup(loopback_max_samples, stimulus_group_name='stimulus', analysis_group_name='analysis', frequency_mhz=10) assert pattern_generator.status == 'READY' boolean_generator = BooleanGenerator(mb_info) assert boolean_generator.status == 'RESET' boolean_generator.trace(use_analyzer=False) boolean_generator.setup(expressions=test_expressions, frequency_mhz=10) assert boolean_generator.status == 'READY' for generator in [fsm_generator, pattern_generator, boolean_generator]: generator.step() assert generator.status == 'RUNNING' generator.stop() assert fsm_generator.status == 'READY' assert pattern_generator.status == 'READY' assert boolean_generator.status == 'READY' generator.run() assert generator.status == 'RUNNING' generator.stop() assert fsm_generator.status == 'READY' assert pattern_generator.status == 'READY' assert boolean_generator.status == 'READY' for generator in [fsm_generator, pattern_generator, boolean_generator]: generator.reset() assert generator.status == 'RESET' del fsm_generator, pattern_generator, boolean_generator
def test_all_generators_data(): """Test all the generator classes implemented in this overlay. In this test, the boolean generators, pattern generators, and FSM generators are tested together by a single call to the controller. The input and output patterns are checked during the test. """ ol.download() logictools_controller = LogicToolsController( mb_info, 'PYNQZ1_LOGICTOOLS_SPECIFICATION') for generator_name in logictools_controller.status: assert logictools_controller.status[generator_name] == 'RESET' print("\nConnect {} to GND, and {} to VCC.".format(rst, direction)) input("Hit enter after done ...") print('Connect randomly {} to VCC or GND.'.format(in_pins)) input("Hit enter after done ...") num_samples = MAX_NUM_PATTERN_SAMPLES fsm_generator = FSMGenerator(mb_info) fsm_generator.trace(num_analyzer_samples=num_samples) fsm_generator.setup(fsm_spec, frequency_mhz=100) pattern_generator = PatternGenerator(mb_info) pattern_generator.trace(num_analyzer_samples=num_samples) pattern_generator.setup(loopback_max_samples, stimulus_group_name='stimulus', analysis_group_name='analysis', frequency_mhz=100) boolean_generator = BooleanGenerator(mb_info) boolean_generator.trace(num_analyzer_samples=num_samples) boolean_generator.setup(expressions=test_expressions, frequency_mhz=100) logictools_controller.run( [fsm_generator, pattern_generator, boolean_generator]) for generator_name in logictools_controller.status: if generator_name != 'TraceAnalyzer': assert logictools_controller.status[generator_name] == 'RUNNING' check_boolean_data(boolean_generator) check_pattern_data(pattern_generator, num_samples) check_fsm_data(fsm_generator, num_samples) logictools_controller.stop( [fsm_generator, pattern_generator, boolean_generator]) for generator_name in logictools_controller.status: assert logictools_controller.status[generator_name] == 'READY' logictools_controller.reset( [fsm_generator, pattern_generator, boolean_generator]) for generator_name in logictools_controller.status: assert logictools_controller.status[generator_name] == 'RESET' del fsm_generator, pattern_generator, boolean_generator
def test_pattern_step(): """Test for the PatternGenerator class. This test will examine a moderate number of 128 samples (in order to shorten testing time). For theses cases, random signals will be used, and all the pins will be used to build the pattern. Each sample is captured after advancing the `step()`. """ ol.download() num_samples = 128 loopback_sent = build_random_pattern(num_samples) pattern_generator = PatternGenerator(mb_info) pattern_generator.trace(use_analyzer=True, num_analyzer_samples=num_samples) pattern_generator.setup(loopback_sent, stimulus_group_name='stimulus', analysis_group_name='analysis', frequency_mhz=100) for _ in range(num_samples): pattern_generator.step() loopback_recv = pattern_generator.waveform.waveform_dict list1 = list2 = list3 = list() for wavelane_group in loopback_sent['signal']: if wavelane_group and wavelane_group[0] == 'stimulus': for i in wavelane_group[1:]: temp = deepcopy(i) temp['wave'] = wave_to_bitstring(i['wave']) list1.append(temp) for wavelane_group in loopback_recv['signal']: if wavelane_group and wavelane_group[0] == 'stimulus': for i in wavelane_group[1:]: temp = deepcopy(i) temp['wave'] = wave_to_bitstring(i['wave']) list2.append(temp) elif wavelane_group and wavelane_group[0] == 'analysis': for i in wavelane_group[1:]: temp = deepcopy(i) temp['wave'] = wave_to_bitstring(i['wave']) list3.append(temp) assert list1 == list2, \ 'Stimulus not equal in generated and captured patterns.' assert list2 == list3, \ 'Stimulus not equal to analysis in captured patterns.' pattern_generator.stop() pattern_generator.reset() del pattern_generator
def test_pattern_random(): """Test for the PatternGenerator class. This test will examine 1 sample, and a maximum number of samples. For theses cases, random signals will be used, and all the pins will be used to build the pattern. """ ol.download() for num_samples in [1, MAX_NUM_PATTERN_SAMPLES]: loopback_sent = build_random_pattern(num_samples) pattern_generator = PatternGenerator(mb_info) pattern_generator.trace(use_analyzer=True, num_analyzer_samples=num_samples) pattern_generator.setup(loopback_sent, stimulus_group_name='stimulus', analysis_group_name='analysis', frequency_mhz=100) pattern_generator.run() loopback_recv = pattern_generator.waveform.waveform_dict list1 = list2 = list3 = list() for wavelane_group in loopback_sent['signal']: if wavelane_group and wavelane_group[0] == 'stimulus': for i in wavelane_group[1:]: temp = deepcopy(i) temp['wave'] = wave_to_bitstring(i['wave']) list1.append(temp) for wavelane_group in loopback_recv['signal']: if wavelane_group and wavelane_group[0] == 'stimulus': for i in wavelane_group[1:]: temp = deepcopy(i) temp['wave'] = wave_to_bitstring(i['wave']) list2.append(temp) elif wavelane_group and wavelane_group[0] == 'analysis': for i in wavelane_group[1:]: temp = deepcopy(i) temp['wave'] = wave_to_bitstring(i['wave']) list3.append(temp) assert list1 == list2, \ 'Stimulus not equal in generated and captured patterns.' assert list2 == list3, \ 'Stimulus not equal to analysis in captured patterns.' pattern_generator.stop() pattern_generator.reset() del pattern_generator
def test_pattern_no_trace(): """Test for the PatternGenerator class. This test will test the case when no analyzer is used. Exception should be raised when users want to show the waveform. """ ol.download() num_samples = 128 loopback_sent = build_loopback_pattern(num_samples) pattern_generator = PatternGenerator(mb_info) pattern_generator.trace(use_analyzer=False, num_analyzer_samples=num_samples) exception_raised = False try: pattern_generator.setup(loopback_sent, stimulus_group_name='stimulus', analysis_group_name='analysis') pattern_generator.run() pattern_generator.show_waveform() except ValueError: exception_raised = True assert exception_raised, 'Should raise exception for show_waveform().' pattern_generator.reset() del pattern_generator
def test_pattern_state(): """Test for the PatternGenerator class. This test will test a set of loopback signals. Each lane is simulating a clock of a specific frequency. """ ol.download() print("\nDisconnect all the pins.") input("Hit enter after done ...") num_samples = 128 loopback_sent = build_loopback_pattern(num_samples) pattern_generator = PatternGenerator(mb_info) assert pattern_generator.status == 'RESET' pattern_generator.trace(use_analyzer=True, num_analyzer_samples=num_samples) pattern_generator.setup(loopback_sent, stimulus_group_name='stimulus', analysis_group_name='analysis') assert pattern_generator.status == 'READY' pattern_generator.run() assert pattern_generator.status == 'RUNNING' loopback_recv = pattern_generator.waveform.waveform_dict list1 = list2 = list3 = list() for wavelane_group in loopback_sent['signal']: if wavelane_group and wavelane_group[0] == 'stimulus': list1 = wavelane_group[1:] for wavelane_group in loopback_recv['signal']: if wavelane_group and wavelane_group[0] == 'stimulus': list2 = wavelane_group[1:] elif wavelane_group and wavelane_group[0] == 'analysis': list3 = wavelane_group[1:] assert list1 == list2, \ 'Stimulus not equal in generated and captured patterns.' assert list2 == list3, \ 'Stimulus not equal to analysis in captured patterns.' pattern_generator.stop() assert pattern_generator.status == 'READY' pattern_generator.reset() assert pattern_generator.status == 'RESET' del pattern_generator