1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-16 01:22:02 +00:00

tests: add SD card format feature tests

This commit is contained in:
matejcik 2020-02-17 17:35:46 +01:00
parent ddee77ecb6
commit 5523c7bbef
3 changed files with 55 additions and 4 deletions

View File

@ -160,6 +160,10 @@ class DebugLink:
def flash_erase(self, sector):
self._call(proto.DebugLinkFlashErase(sector=sector), nowait=True)
@expect(proto.Success)
def erase_sd_card(self, format=True):
return self._call(proto.DebugLinkEraseSdCard(format=format))
class NullDebugLink(DebugLink):
def __init__(self):

View File

@ -81,10 +81,8 @@ def client(request):
if request.node.get_closest_marker("skip_t1") and client.features.model == "1":
pytest.skip("Test excluded on Trezor 1")
if (
request.node.get_closest_marker("sd_card")
and not client.features.sd_card_present
):
sd_marker = request.node.get_closest_marker("sd_card")
if sd_marker and not client.features.sd_card_present:
raise RuntimeError(
"This test requires SD card.\n"
"To skip all such tests, run:\n"
@ -101,6 +99,10 @@ def client(request):
# we need to reseed before the wipe
client.debug.reseed(0)
if sd_marker:
should_format = sd_marker.kwargs.get("formatted", True)
client.debug.erase_sd_card(format=should_format)
wipe_device(client)
setup_params = dict(

View File

@ -0,0 +1,45 @@
# This file is part of the Trezor project.
#
# Copyright (C) 2012-2019 SatoshiLabs and contributors
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3
# as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the License along with this library.
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
import pytest
from trezorlib import device, messages
from trezorlib.exceptions import TrezorFailure
from trezorlib.messages import SdProtectOperationType as Op
pytestmark = pytest.mark.skip_t1
@pytest.mark.sd_card(formatted=False)
def test_sd_format(client):
device.sd_protect(client, Op.ENABLE)
assert client.features.sd_protection is True
@pytest.mark.sd_card(formatted=False)
def test_sd_no_format(client):
def input_flow():
yield # enable SD protection?
client.debug.press_yes()
yield # format SD card
client.debug.press_no()
with pytest.raises(TrezorFailure) as e, client:
client.set_input_flow(input_flow)
device.sd_protect(client, Op.ENABLE)
assert e.value.failure.code == messages.FailureType.ProcessError