def test_program_bitstream(success): # prepare calls = [] fpga = TinyFPGAB(None, lambda *a: calls.append(('progress', a))) # patching methods fpga.wake = lambda *a: calls.append(('wake', a)) fpga.read_sts = lambda *a: calls.append(('read_sts', a)) fpga.read = lambda *a: calls.append(('read', a)) if success: fpga.program = lambda *a: calls.append(('program', a)) or True else: fpga.program = lambda *a: calls.append(('program', a)) or False fpga.boot = lambda *a: calls.append(('boot', a)) # run output = fpga.program_bitstream(0x123456, DATA) # check assert output == success expected_calls = [ ('progress', ('Waking up SPI flash', )), ('progress', ('35 bytes to program', )), ('program', (0x123456, DATA)), ] if success: expected_calls.append(('boot', ())) assert calls == expected_calls
def test_program(success): # prepare calls = [] fpga = TinyFPGAB(None, lambda *a: calls.append(('progress', a))) # patching methods fpga.erase = lambda *a: calls.append(('erase', a)) fpga.write = lambda *a: calls.append(('write', a)) if success: fpga.read = lambda *a: calls.append(('read', a)) or DATA else: fpga.read = lambda *a: calls.append(('read', a)) or 'This is a fail' # run output = fpga.program(0x123456, DATA) # check assert output == success expected_calls = [ ('progress', ('Erasing designated flash pages', )), ('erase', (0x123456, 35)), ('progress', ('Writing bitstream', )), ('write', (0x123456, DATA)), ('progress', ('Verifying bitstream', )), ('read', (0x123456, 35)), ] if success: expected_calls.extend([ ('progress', ('Success!', )), ]) else: expected_calls.extend([ ('progress', ('Need to rewrite some pages...', )), ('progress', ('len: 000023 00000e', )), ('progress', ('rewriting page 123456', )), ('erase', (1193046, 35)), ('write', (1193046, 'Thequickbrownfoxjumpsoverthelazydog')), ('read', (1193046, 35)), ('erase', (1193046, 35)), ('write', (1193046, 'Thequickbrownfoxjumpsoverthelazydog')), ('read', (1193046, 35)), ('erase', (1193046, 35)), ('write', (1193046, 'Thequickbrownfoxjumpsoverthelazydog')), ('read', (1193046, 35)), ('erase', (1193046, 35)), ('write', (1193046, 'Thequickbrownfoxjumpsoverthelazydog')), ('read', (1193046, 35)), ('erase', (1193046, 35)), ('write', (1193046, 'Thequickbrownfoxjumpsoverthelazydog')), ('read', (1193046, 35)), ('erase', (1193046, 35)), ('write', (1193046, 'Thequickbrownfoxjumpsoverthelazydog')), ('read', (1193046, 35)), ('progress', ('Verification Failed!', )), ]) assert calls == expected_calls
def test_program(success): # prepare calls = [] fpga = TinyFPGAB(None, lambda *a: calls.append(('progress', a))) # patching methods fpga.erase = lambda *a: calls.append(('erase', a)) fpga.write = lambda *a: calls.append(('write', a)) if success: fpga.read = lambda *a: calls.append(('read', a)) or DATA else: fpga.read = lambda *a: calls.append(('read', a)) or 'This is a fail' # run output = fpga.program(0x123456, DATA) # check assert output == success expected_calls = [ ('progress', ('Erasing designated flash pages', )), ('erase', (0x123456, 35)), ('progress', ('Writing bitstream', )), ('write', (0x123456, DATA)), ('progress', ('Verifying bitstream', )), ('read', (0x123456, 35)), ] if success: expected_calls.extend([ ('progress', ('Success!',)), ]) else: expected_calls.extend([ ('progress', ('Need to rewrite some pages...',)), ('progress', ('len: 000023 00000e',)), ('progress', ('rewriting page 123456',)), ('erase', (1193046, 35)), ('write', (1193046, b'Thequickbrownfoxjumpsoverthelazydog')), ('read', (1193046, 35)), ('erase', (1193046, 35)), ('write', (1193046, b'Thequickbrownfoxjumpsoverthelazydog')), ('read', (1193046, 35)), ('erase', (1193046, 35)), ('write', (1193046, b'Thequickbrownfoxjumpsoverthelazydog')), ('read', (1193046, 35)), ('erase', (1193046, 35)), ('write', (1193046, b'Thequickbrownfoxjumpsoverthelazydog')), ('read', (1193046, 35)), ('erase', (1193046, 35)), ('write', (1193046, b'Thequickbrownfoxjumpsoverthelazydog')), ('read', (1193046, 35)), ('erase', (1193046, 35)), ('write', (1193046, b'Thequickbrownfoxjumpsoverthelazydog')), ('read', (1193046, 35)), ('progress', ('Verification Failed!',)), ]) assert calls == expected_calls
def test_program(success): # prepare calls = [] fpga = TinyFPGAB(None, lambda *a: calls.append(('progress', a))) # patching methods fpga.erase = lambda *a: calls.append(('erase', a)) fpga.write = lambda *a: calls.append(('write', a)) if success: fpga.read = lambda *a: calls.append(('read', a)) or DATA else: fpga.read = lambda *a: calls.append(('read', a)) or 'This is a fail' # run output = fpga.program(0x123456, DATA) # check assert output == success assert calls == [ ('progress', ('Erasing designated flash pages', )), ('erase', (0x123456, 35)), ('progress', ('Writing bitstream', )), ('write', (0x123456, DATA)), ('progress', ('Verifying bitstream', )), ('read', (0x123456, 35)), ('progress', ('Success!' if success else 'Verification Failed!', )), ]