def test_wait_while_busy(): # prepare serial = FakeSerial('0101010100'.decode('hex')) fpga = TinyFPGAB(serial) # run assert fpga.wait_while_busy() is None # check assert not serial.read_data serial.assert_written(['010100020005'.decode('hex')] * 5)
def test_wait_while_busy(): # prepare serial = FakeSerial(bytearray.fromhex('0101010100')) fpga = TinyFPGAB(serial) # run assert fpga.wait_while_busy() is None # check assert not serial.read_data serial.assert_written([bytearray.fromhex('010100020005')] * 5)
def test_wait_while_busy(): # prepare serial = FakeSerial(bytearray.fromhex('0101010100')) fpga = TinyFPGAB(serial) # run assert fpga.wait_while_busy() is None # check assert not serial.read_data serial.assert_written([bytearray.fromhex('010100020005')] * 5)
def test_write(offset, length, serial_outs): # prepare serial = FakeSerial() fpga = TinyFPGAB(serial) fpga.write_enable = lambda: None # patch write_enable fpga.wait_while_busy = lambda: None # patch wait_while_busy data = DATA[:length] # run assert fpga.write(offset, data) is None # check assert not serial.read_data serial.assert_written([d.decode('hex') for d in serial_outs])
def test_write(offset, length, serial_outs): # prepare serial = FakeSerial() fpga = TinyFPGAB(serial) fpga.write_enable = lambda: None # patch write_enable fpga.wait_while_busy = lambda: None # patch wait_while_busy data = DATA[:length] # run assert fpga.write(offset, data) is None # check assert not serial.read_data serial.assert_written([bytearray.fromhex(d) for d in serial_outs])
def test_write(offset, length, serial_outs): # prepare serial = FakeSerial() fpga = TinyFPGAB(serial) fpga.write_enable = lambda: None # patch write_enable fpga.wait_while_busy = lambda: None # patch wait_while_busy data = DATA[:length] # run assert fpga.write(offset, data) is None # check assert not serial.read_data prueba = [bytes.fromhex(d) for d in serial_outs] print("Creado: {}".format(prueba)) serial.assert_written(prueba)
def test_erase(offset, length, block_len, serial_outs): # prepare calls = [] serial = FakeSerial() fpga = TinyFPGAB(serial) fpga.write_enable = lambda: None # patch write_enable fpga.wait_while_busy = lambda: None # patch wait_while_busy fpga.read = lambda *a: calls.append(('read', a)) \ or DATA_4096[a[0] % 4096:][:a[1]] fpga.write = lambda *a: calls.append(('write', a)) # run assert fpga.erase(offset, length) is None # check assert not serial.read_data serial.assert_written([d.decode('hex') for d in serial_outs]) expected_calls = [] restore_first_block = None if offset % block_len > 0: # restore start of first block restore_offset = offset & ~(block_len - 1) restore_len = offset % block_len expected_calls.append(('read', (restore_offset, restore_len))) expected_calls.append( ('write', (restore_offset, DATA_4096[:restore_len]))) restore_first_block = restore_offset if (offset + length) % block_len > 0: # restore end of last block restore_offset = offset + length restore_len = block_len - (restore_offset % block_len) read_call = ('read', (restore_offset, restore_len)) if restore_first_block == ((offset + length) & ~(block_len - 1)): # restore before and after erase in same block expected_calls.insert(1, read_call) # 2nd read before 1st write else: expected_calls.append(read_call) # 2nd read after 1st write expected_calls.append( ('write', (restore_offset, DATA_4096[restore_offset % block_len:]))) assert calls == expected_calls
def test_erase(offset, length, block_len, serial_outs): # prepare calls = [] serial = FakeSerial() fpga = TinyFPGAB(serial) fpga.write_enable = lambda: None # patch write_enable fpga.wait_while_busy = lambda: None # patch wait_while_busy fpga.read = lambda *a: calls.append(('read', a)) \ or DATA_4096[a[0] % 4096:][:a[1]] fpga.write = lambda *a: calls.append(('write', a)) # run assert fpga.erase(offset, length) is None # check assert not serial.read_data serial.assert_written([bytearray.fromhex(d) for d in serial_outs]) expected_calls = [] restore_first_block = None if offset % block_len > 0: # restore start of first block restore_offset = offset & ~(block_len - 1) restore_len = offset % block_len expected_calls.append(( 'read', (restore_offset, restore_len))) expected_calls.append(( 'write', (restore_offset, DATA_4096[:restore_len]))) restore_first_block = restore_offset if (offset + length) % block_len > 0: # restore end of last block restore_offset = offset + length restore_len = block_len - (restore_offset % block_len) read_call = ('read', (restore_offset, restore_len)) if restore_first_block == ((offset + length) & ~(block_len - 1)): # restore before and after erase in same block expected_calls.insert(1, read_call) # 2nd read before 1st write else: expected_calls.append(read_call) # 2nd read after 1st write expected_calls.append(( 'write', (restore_offset, DATA_4096[restore_offset % block_len:]))) assert calls == expected_calls