1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-13 00:40:58 +00:00

core: fix unit tests

This commit is contained in:
matejcik 2020-02-18 14:30:46 +01:00
parent d88540f2e0
commit 7983fd34d6
2 changed files with 21 additions and 26 deletions

View File

@ -6,15 +6,14 @@ from trezor import io
class TestTrezorIoFatfs(unittest.TestCase): class TestTrezorIoFatfs(unittest.TestCase):
def setUp(self): def setUp(self):
self.sd = io.SDCard() io.sdcard.power_on()
self.sd.power(True)
self.fs = io.FatFS() self.fs = io.FatFS()
self.fs.mkfs() self.fs.mkfs()
self.fs.mount() self.fs.mount()
def tearDown(self): def tearDown(self):
self.fs.unmount() self.fs.unmount()
self.sd.power(False) io.sdcard.power_off()
def _filename(self, suffix=""): def _filename(self, suffix=""):
return "FILE%s.TXT" % suffix return "FILE%s.TXT" % suffix

View File

@ -6,45 +6,41 @@ from trezor import io
class TestTrezorIoSdcard(unittest.TestCase): class TestTrezorIoSdcard(unittest.TestCase):
def test_start(self): def test_start(self):
sd = io.SDCard() self.assertTrue(io.sdcard.is_present())
self.assertTrue(sd.present())
def test_power(self): def test_power(self):
sd = io.SDCard()
x = bytearray(8 * 512) x = bytearray(8 * 512)
self.assertEqual(sd.capacity(), 0) self.assertEqual(io.sdcard.capacity(), 0)
with self.assertRaises(OSError): with self.assertRaises(OSError):
sd.read(0, x) io.sdcard.read(0, x)
sd.power(True) io.sdcard.power_on()
self.assertTrue(sd.capacity() > 0) self.assertTrue(io.sdcard.capacity() > 0)
sd.read(0, x) io.sdcard.read(0, x)
sd.power(False) io.sdcard.power_off()
self.assertEqual(sd.capacity(), 0) self.assertEqual(io.sdcard.capacity(), 0)
with self.assertRaises(OSError): with self.assertRaises(OSError):
sd.read(0, x) io.sdcard.read(0, x)
def test_read(self): def test_read(self):
sd = io.SDCard()
x = bytearray(8 * 512) x = bytearray(8 * 512)
sd.power(True) io.sdcard.power_on()
sd.read(0, x) io.sdcard.read(0, x)
sd.power(False) io.sdcard.power_off()
with self.assertRaises(OSError): with self.assertRaises(OSError):
sd.read(0, x) io.sdcard.read(0, x)
def test_read_write(self): def test_read_write(self):
sd = io.SDCard()
r = bytearray(8 * 512) r = bytearray(8 * 512)
w0 = bytearray(b'0' * (8 * 512)) w0 = bytearray(b'0' * (8 * 512))
w1 = bytearray(b'1' * (8 * 512)) w1 = bytearray(b'1' * (8 * 512))
sd.power(True) io.sdcard.power_on()
sd.write(0, w0) io.sdcard.write(0, w0)
sd.read(0, r) io.sdcard.read(0, r)
self.assertEqual(r, w0) self.assertEqual(r, w0)
sd.write(0, w1) io.sdcard.write(0, w1)
sd.read(0, r) io.sdcard.read(0, r)
self.assertEqual(r, w1) self.assertEqual(r, w1)
sd.power(False) io.sdcard.power_off()
if __name__ == '__main__': if __name__ == '__main__':