Ragger tests can now run with a display; disabled by default

This commit is contained in:
Alexandre Paillier
2023-02-27 10:54:35 +01:00
parent 7aaae18980
commit f33aad45fe
2 changed files with 20 additions and 10 deletions
+19 -9
View File
@@ -14,6 +14,7 @@ def pytest_addoption(parser):
parser.addoption("--backend", action="store", default="speculos")
parser.addoption("--path", action="store", default="./elfs")
parser.addoption("--model", action="store", required=True)
parser.addoption("--display", action="store_true", default=False)
# accessing the value of the "--backend" option as a fixture
@pytest.fixture
@@ -28,6 +29,10 @@ def arg_path(pytestconfig) -> str:
def arg_model(pytestconfig) -> str:
return pytestconfig.getoption("model")
@pytest.fixture
def arg_display(pytestconfig) -> bool:
return pytestconfig.getoption("display")
# Providing the firmware as a fixture
@pytest.fixture
def firmware(arg_model: str) -> Firmware:
@@ -36,30 +41,35 @@ def firmware(arg_model: str) -> Firmware:
return fw
raise ValueError("Unknown device model \"%s\"" % (arg_model))
def get_elf_path(arg_path: str, firmware: Firmware) -> Path:
def get_speculos_args(arg_path: str, display: bool, fw: Firmware):
extra_args = list()
if display:
extra_args += ["--display", "qt"]
elf_dir = Path(arg_path).resolve()
assert elf_dir.is_dir(), ("%s is not a directory" % (arg_path))
app = elf_dir / ("app-%s.elf" % firmware.device)
app = elf_dir / ("app-%s.elf" % (fw.device))
assert app.is_file(), ("Firmware %s does not exist !" % (app))
return app
return (app, {"args": extra_args})
# Depending on the "--backend" option value, a different backend is
# instantiated, and the tests will either run on Speculos or on a physical
# device depending on the backend
def create_backend(backend: str, arg_path: str, firmware: Firmware) -> BackendInterface:
def create_backend(backend: str, arg_path: str, display: bool, fw: Firmware) -> BackendInterface:
if backend.lower() == "ledgercomm":
return LedgerCommBackend(firmware, interface="hid")
return LedgerCommBackend(fw, interface="hid")
elif backend.lower() == "ledgerwallet":
return LedgerWalletBackend(firmware)
return LedgerWalletBackend(fw)
elif backend.lower() == "speculos":
return SpeculosBackend(get_elf_path(arg_path, firmware), firmware)
app, args = get_speculos_args(arg_path, display, fw)
return SpeculosBackend(app, fw, **args)
else:
raise ValueError(f"Backend '{backend}' is unknown. Valid backends are: {BACKENDS}")
# This fixture will create and return the backend client
@pytest.fixture
def backend_client(arg_backend: str, arg_path: str, firmware: Firmware) -> BackendInterface:
with create_backend(arg_backend, arg_path, firmware) as b:
def backend_client(arg_backend: str, arg_path: str, arg_display: bool, firmware: Firmware) -> BackendInterface:
with create_backend(arg_backend, arg_path, arg_display, firmware) as b:
yield b
# This final fixture will return the properly configured app client, to be used in tests
+1 -1
View File
@@ -1,6 +1,6 @@
requests>=2.28,<3.0
click>=8.0,<9.0 # needed by the CI as it installs an older version and breaks dependencies
protobuf==3.20.1 # To fix the protobuf dependency bug
ragger[speculos]
ragger[speculos]==0.8.1
pytest
ecdsa