2024-11-15 12:55:14 +00:00
|
|
|
# flake8: noqa: F403,F405
|
2024-01-26 11:16:55 +00:00
|
|
|
from common import * # isort:skip
|
2019-06-20 15:22:00 +00:00
|
|
|
|
2023-06-28 11:09:03 +00:00
|
|
|
from trezor import io, utils
|
2019-06-20 15:22:00 +00:00
|
|
|
|
2023-06-28 10:58:54 +00:00
|
|
|
|
2019-06-20 15:22:00 +00:00
|
|
|
class TestTrezorIoSdcard(unittest.TestCase):
|
|
|
|
def test_start(self):
|
2020-02-18 13:30:46 +00:00
|
|
|
self.assertTrue(io.sdcard.is_present())
|
2019-06-20 15:22:00 +00:00
|
|
|
|
|
|
|
def test_power(self):
|
|
|
|
x = bytearray(8 * 512)
|
2020-02-18 13:30:46 +00:00
|
|
|
self.assertEqual(io.sdcard.capacity(), 0)
|
2019-06-21 20:51:21 +00:00
|
|
|
with self.assertRaises(OSError):
|
2020-02-18 13:30:46 +00:00
|
|
|
io.sdcard.read(0, x)
|
|
|
|
io.sdcard.power_on()
|
|
|
|
self.assertTrue(io.sdcard.capacity() > 0)
|
|
|
|
io.sdcard.read(0, x)
|
|
|
|
io.sdcard.power_off()
|
|
|
|
self.assertEqual(io.sdcard.capacity(), 0)
|
2019-06-21 20:51:21 +00:00
|
|
|
with self.assertRaises(OSError):
|
2020-02-18 13:30:46 +00:00
|
|
|
io.sdcard.read(0, x)
|
2019-06-20 15:22:00 +00:00
|
|
|
|
|
|
|
def test_read(self):
|
|
|
|
x = bytearray(8 * 512)
|
2020-02-18 13:30:46 +00:00
|
|
|
io.sdcard.power_on()
|
|
|
|
io.sdcard.read(0, x)
|
|
|
|
io.sdcard.power_off()
|
2019-06-21 20:51:21 +00:00
|
|
|
with self.assertRaises(OSError):
|
2020-02-18 13:30:46 +00:00
|
|
|
io.sdcard.read(0, x)
|
2019-06-20 15:22:00 +00:00
|
|
|
|
|
|
|
def test_read_write(self):
|
|
|
|
r = bytearray(8 * 512)
|
2023-06-28 10:46:29 +00:00
|
|
|
w0 = bytearray(b"0" * (8 * 512))
|
|
|
|
w1 = bytearray(b"1" * (8 * 512))
|
2020-02-18 13:30:46 +00:00
|
|
|
io.sdcard.power_on()
|
|
|
|
io.sdcard.write(0, w0)
|
|
|
|
io.sdcard.read(0, r)
|
2019-06-20 15:22:00 +00:00
|
|
|
self.assertEqual(r, w0)
|
2020-02-18 13:30:46 +00:00
|
|
|
io.sdcard.write(0, w1)
|
|
|
|
io.sdcard.read(0, r)
|
2019-06-20 15:22:00 +00:00
|
|
|
self.assertEqual(r, w1)
|
2020-02-18 13:30:46 +00:00
|
|
|
io.sdcard.power_off()
|
2019-06-20 15:22:00 +00:00
|
|
|
|
|
|
|
|
2023-06-28 10:46:29 +00:00
|
|
|
if __name__ == "__main__":
|
2023-06-28 11:09:03 +00:00
|
|
|
if utils.USE_SD_CARD:
|
|
|
|
unittest.main()
|