From 7041b094cfe249fd523ec4dc60a10ba7391854b9 Mon Sep 17 00:00:00 2001 From: Mathias BROUSSET Date: Wed, 29 Apr 2026 09:55:03 +0200 Subject: [PATCH 1/3] Fix stack consumption fixture when test does not interact with device --- CHANGELOG.md | 7 +++++++ src/ragger/conftest/base_conftest.py | 15 +++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0638a70d..ca866d95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.45.1] - 2026-04-27 + +### Fixed + +- `--get-stack-consumption` : fixing case where test does not interact with device + + ## [1.45.1] - 2026-04-27 ### Added diff --git a/src/ragger/conftest/base_conftest.py b/src/ragger/conftest/base_conftest.py index 3f29b788..2ffe14b6 100644 --- a/src/ragger/conftest/base_conftest.py +++ b/src/ragger/conftest/base_conftest.py @@ -130,8 +130,12 @@ def get_stack_consumption(pytestconfig): @pytest.fixture(autouse=True) def stack_consumption_hooks(request, get_stack_consumption: bool): if get_stack_consumption: - backend = request.getfixturevalue("backend") - _backend_name = request.getfixturevalue("backend_name") + try: + backend = request.getfixturevalue("backend") + _backend_name = request.getfixturevalue("backend_name") + except pytest.FixtureLookupError: + yield + return if _backend_name.lower() == "speculos": try: backend.exchange(cla=0xB0, ins=0x57, p1=0x00, p2=0x01, data=b"") @@ -143,8 +147,11 @@ def stack_consumption_hooks(request, get_stack_consumption: bool): pytest.fail(msg) yield if get_stack_consumption: - backend = request.getfixturevalue("backend") - _backend_name = request.getfixturevalue("backend_name") + try: + backend = request.getfixturevalue("backend") + _backend_name = request.getfixturevalue("backend_name") + except pytest.FixtureLookupError: + return if _backend_name.lower() == "speculos": try: rapdu_retrieve: RAPDU = backend.exchange(cla=0xB0, From e185dbb3160bfd6495c135c69bc7020b350af6c5 Mon Sep 17 00:00:00 2001 From: Mathias BROUSSET Date: Wed, 29 Apr 2026 10:28:58 +0200 Subject: [PATCH 2/3] Taking remarks into account + yapf --- .github/workflows/build_and_tests.yml | 2 + CHANGELOG.md | 2 +- src/ragger/conftest/base_conftest.py | 61 ++++++++++++--------------- 3 files changed, 31 insertions(+), 34 deletions(-) diff --git a/.github/workflows/build_and_tests.yml b/.github/workflows/build_and_tests.yml index f9a5141b..12a556f4 100644 --- a/.github/workflows/build_and_tests.yml +++ b/.github/workflows/build_and_tests.yml @@ -27,6 +27,7 @@ jobs: app_repository: LedgerHQ/app-boilerplate app_branch_name: master upload_app_binaries_artifact: boilerplate_binaries + build_comparison: true build_boilerplate_application_nanos: name: Build boilerplate application for Nanos S using the reusable workflow @@ -35,6 +36,7 @@ jobs: app_repository: LedgerHQ/app-boilerplate app_branch_name: nanos_baseline upload_app_binaries_artifact: boilerplate_binaries_nanos + build_comparison: true prepare_matrix: name: Prepare matrix from TOML file diff --git a/CHANGELOG.md b/CHANGELOG.md index ca866d95..c4895d74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [1.45.1] - 2026-04-27 +## [1.45.2] - 2026-04-29 ### Fixed diff --git a/src/ragger/conftest/base_conftest.py b/src/ragger/conftest/base_conftest.py index 2ffe14b6..6fafd667 100644 --- a/src/ragger/conftest/base_conftest.py +++ b/src/ragger/conftest/base_conftest.py @@ -129,41 +129,36 @@ def get_stack_consumption(pytestconfig): @pytest.fixture(autouse=True) def stack_consumption_hooks(request, get_stack_consumption: bool): - if get_stack_consumption: + # This fixture is marked `autouse=True` so that it happens automatically + # on tests that interact with the device. However, it should do nothing if + # running tests that _do not_ interact with the device. + # We detect that by verifying if the `backend` fixture is present. + if not get_stack_consumption: + yield + return + try: + backend = request.getfixturevalue("backend") + _backend_name = request.getfixturevalue("backend_name") + except pytest.FixtureLookupError: + yield + return + if _backend_name.lower() == "speculos": try: - backend = request.getfixturevalue("backend") - _backend_name = request.getfixturevalue("backend_name") - except pytest.FixtureLookupError: + backend.exchange(cla=0xB0, ins=0x57, p1=0x00, p2=0x01, data=b"") + yield - return - if _backend_name.lower() == "speculos": - try: - backend.exchange(cla=0xB0, ins=0x57, p1=0x00, p2=0x01, data=b"") - except ExceptionRAPDU as e: - msg = ( - "Stack consumption not supported: app not built with DEBUG_OS_STACK_CONSUMPTION=1" - if e.status == StatusWords.SWO_INVALID_CLA else - f"Unexpected SW: {e.status:04X}") - pytest.fail(msg) - yield - if get_stack_consumption: - try: - backend = request.getfixturevalue("backend") - _backend_name = request.getfixturevalue("backend_name") - except pytest.FixtureLookupError: - return - if _backend_name.lower() == "speculos": - try: - rapdu_retrieve: RAPDU = backend.exchange(cla=0xB0, - ins=0x57, - p1=0x01, - p2=0x01, - data=b"") - consumption = int.from_bytes(rapdu_retrieve.data, byteorder='big') - print(f"\n[stack consumption] {consumption} bytes.") - _stack_consumption_results[request.node.nodeid] = consumption - except ExceptionRAPDU as e: - pytest.fail(f"Stack consumption retrieve failed with SW: {e.status:04X}") + + rapdu_retrieve: RAPDU = backend.exchange(cla=0xB0, ins=0x57, p1=0x01, p2=0x01, data=b"") + consumption = int.from_bytes(rapdu_retrieve.data, byteorder='big') + print(f"\n[stack consumption] {consumption} bytes.") + _stack_consumption_results[request.node.nodeid] = consumption + except ExceptionRAPDU as e: + msg = ( + "Stack consumption not supported: app not built with DEBUG_OS_STACK_CONSUMPTION=1" + if e.status == StatusWords.SWO_INVALID_CLA else f"Unexpected SW: {e.status:04X}") + pytest.fail(msg) + else: + yield def pytest_terminal_summary(terminalreporter, exitstatus, config): From cd669358861f3e23066c0596d3d4f75f048f3f71 Mon Sep 17 00:00:00 2001 From: Mathias BROUSSET Date: Wed, 29 Apr 2026 11:18:26 +0200 Subject: [PATCH 3/3] disable build comparison --- .github/workflows/build_and_tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_and_tests.yml b/.github/workflows/build_and_tests.yml index 12a556f4..8aa13e02 100644 --- a/.github/workflows/build_and_tests.yml +++ b/.github/workflows/build_and_tests.yml @@ -27,7 +27,7 @@ jobs: app_repository: LedgerHQ/app-boilerplate app_branch_name: master upload_app_binaries_artifact: boilerplate_binaries - build_comparison: true + build_comparison: false build_boilerplate_application_nanos: name: Build boilerplate application for Nanos S using the reusable workflow @@ -36,7 +36,7 @@ jobs: app_repository: LedgerHQ/app-boilerplate app_branch_name: nanos_baseline upload_app_binaries_artifact: boilerplate_binaries_nanos - build_comparison: true + build_comparison: false prepare_matrix: name: Prepare matrix from TOML file