Now uses the reusable conftest from Ragger
This commit is contained in:
31
.github/workflows/ci-workflow.yml
vendored
31
.github/workflows/ci-workflow.yml
vendored
@@ -167,6 +167,16 @@ jobs:
|
||||
|
||||
build_ragger_elfs:
|
||||
name: Building binaries for Ragger tests
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- sdk: "$NANOS_SDK"
|
||||
name: "nanos"
|
||||
- sdk: "$NANOX_SDK"
|
||||
name: "nanox"
|
||||
- sdk: "$NANOSP_SDK"
|
||||
name: "nanosp"
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder-lite:latest
|
||||
@@ -177,20 +187,14 @@ jobs:
|
||||
|
||||
- name: Build test binaries
|
||||
run: |
|
||||
make -j BOLOS_SDK=$NANOS_SDK CAL_CI_KEY=1 DOMAIN_NAME_TEST_KEY=1
|
||||
mv bin/app.elf app-nanos.elf
|
||||
make clean
|
||||
make -j BOLOS_SDK=$NANOX_SDK CAL_CI_KEY=1 DOMAIN_NAME_TEST_KEY=1
|
||||
mv bin/app.elf app-nanox.elf
|
||||
make clean
|
||||
make -j BOLOS_SDK=$NANOSP_SDK CAL_CI_KEY=1 DOMAIN_NAME_TEST_KEY=1
|
||||
mv bin/app.elf app-nanosp.elf
|
||||
make -j BOLOS_SDK=${{ matrix.sdk }} CAL_CI_KEY=1 DOMAIN_NAME_TEST_KEY=1
|
||||
mv bin/app.elf app-${{ matrix.name }}.elf
|
||||
|
||||
- name: Upload app binaries
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: ragger_elfs
|
||||
path: ./app-*.elf
|
||||
path: app-${{ matrix.name }}.elf
|
||||
|
||||
create_ragger_env:
|
||||
name: Cache Ragger environment
|
||||
@@ -249,12 +253,7 @@ jobs:
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: ragger_elfs
|
||||
path: tmp/
|
||||
|
||||
- name: Put them where they belong
|
||||
run: |
|
||||
mkdir -p tests/ragger/elfs
|
||||
find tmp/ -type f -name '*.elf' -exec cp {} tests/ragger/elfs/ \;
|
||||
path: tests/ragger/elfs/
|
||||
|
||||
- name: Get cached environment
|
||||
uses: actions/cache@v3
|
||||
@@ -273,4 +272,4 @@ jobs:
|
||||
run: |
|
||||
cd tests/ragger
|
||||
. ./venv/bin/activate
|
||||
pytest --path ./elfs --model ${{ matrix.model }} -s -v --tb=short
|
||||
pytest --device ${{ matrix.model }} -s -v --tb=short
|
||||
|
||||
@@ -1,68 +1,12 @@
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
from ragger.firmware import Firmware
|
||||
from ragger.backend import SpeculosBackend, LedgerCommBackend, LedgerWalletBackend, BackendInterface
|
||||
from ragger.conftest import configuration
|
||||
from ragger.backend import BackendInterface
|
||||
from ethereum_client.client import EthereumClient
|
||||
|
||||
FWS = [
|
||||
Firmware("nanos", "2.1"),
|
||||
Firmware("nanox", "2.0.2"),
|
||||
Firmware("nanosp", "1.0.3")
|
||||
]
|
||||
|
||||
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)
|
||||
|
||||
# accessing the value of the "--backend" option as a fixture
|
||||
@pytest.fixture
|
||||
def arg_backend(pytestconfig) -> str:
|
||||
return pytestconfig.getoption("backend")
|
||||
|
||||
@pytest.fixture
|
||||
def arg_path(pytestconfig) -> str:
|
||||
return pytestconfig.getoption("path")
|
||||
|
||||
@pytest.fixture
|
||||
def arg_model(pytestconfig) -> str:
|
||||
return pytestconfig.getoption("model")
|
||||
|
||||
# Providing the firmware as a fixture
|
||||
@pytest.fixture
|
||||
def firmware(arg_model: str) -> Firmware:
|
||||
for fw in FWS:
|
||||
if fw.device == arg_model:
|
||||
return fw
|
||||
raise ValueError("Unknown device model \"%s\"" % (arg_model))
|
||||
|
||||
def get_elf_path(arg_path: str, firmware: Firmware) -> Path:
|
||||
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)
|
||||
assert app.is_file(), ("Firmware %s does not exist !" % (app))
|
||||
return app
|
||||
|
||||
# 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:
|
||||
if backend.lower() == "ledgercomm":
|
||||
return LedgerCommBackend(firmware, interface="hid")
|
||||
elif backend.lower() == "ledgerwallet":
|
||||
return LedgerWalletBackend(firmware)
|
||||
elif backend.lower() == "speculos":
|
||||
return SpeculosBackend(get_elf_path(arg_path, firmware), firmware)
|
||||
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:
|
||||
yield b
|
||||
|
||||
# This final fixture will return the properly configured app client, to be used in tests
|
||||
@pytest.fixture
|
||||
def app_client(backend_client: BackendInterface) -> EthereumClient:
|
||||
return EthereumClient(backend_client)
|
||||
def app_client(backend: BackendInterface) -> EthereumClient:
|
||||
return EthereumClient(backend)
|
||||
|
||||
# Pull all features from the base ragger conftest using the overridden configuration
|
||||
pytest_plugins = ("ragger.conftest.base_conftest", )
|
||||
|
||||
Reference in New Issue
Block a user