1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-29 09:38:08 +00:00
trezor-firmware/tests/test_trezor.io.py

49 lines
1.2 KiB
Python
Raw Normal View History

2017-06-20 12:13:26 +00:00
from common import *
from trezor import io
2017-12-15 00:00:00 +00:00
2017-06-20 12:13:26 +00:00
class TestIo(unittest.TestCase):
2017-12-15 00:00:00 +00:00
def test_sdcard_start(self):
sd = io.SDCard()
2017-12-16 01:11:26 +00:00
assert sd.present() is True
2017-12-15 00:00:00 +00:00
def test_sdcard_power(self):
sd = io.SDCard()
x = bytearray(8 * 512)
assert sd.capacity() == 0
2017-12-16 01:11:26 +00:00
assert sd.read(0, x) is False
2017-12-15 00:00:00 +00:00
sd.power(True)
assert sd.capacity() > 0
2017-12-16 01:11:26 +00:00
assert sd.read(0, x) is True
2017-12-15 00:00:00 +00:00
sd.power(False)
assert sd.capacity() == 0
2017-12-16 01:11:26 +00:00
assert sd.read(0, x) is False
2017-12-15 00:00:00 +00:00
def test_sdcard_read(self):
sd = io.SDCard()
x = bytearray(8 * 512)
sd.power(True)
2017-12-16 01:11:26 +00:00
assert sd.read(0, x) is True
2017-12-15 00:00:00 +00:00
sd.power(False)
2017-12-16 01:11:26 +00:00
assert sd.read(0, x) is False
2017-12-15 00:00:00 +00:00
def test_sdcard_read_write(self):
2017-06-20 12:13:26 +00:00
sd = io.SDCard()
2017-12-15 00:00:00 +00:00
r = bytearray(8 * 512)
w0 = bytearray(b'0' * (8 * 512))
w1 = bytearray(b'1' * (8 * 512))
sd.power(True)
2017-12-16 01:11:26 +00:00
assert sd.write(0, w0) is True
assert sd.read(0, r) is True
2017-12-15 00:00:00 +00:00
assert r == w0
2017-12-16 01:11:26 +00:00
assert sd.write(0, w1) is True
assert sd.read(0, r) is True
2017-12-15 00:00:00 +00:00
assert r == w1
sd.power(False)
2017-06-20 12:13:26 +00:00
if __name__ == '__main__':
unittest.main()