Skip to content

add option --get-stack-consumption#268

Merged
mbrousset-ledger merged 2 commits intomasterfrom
mbr/stack-fixture
Apr 2, 2026
Merged

add option --get-stack-consumption#268
mbrousset-ledger merged 2 commits intomasterfrom
mbr/stack-fixture

Conversation

@mbrousset-ledger
Copy link
Copy Markdown
Contributor

@mbrousset-ledger mbrousset-ledger commented Mar 19, 2026

Adding a fixture to retrieve peak stack consumption in a test sequence.

⚠️ requires the app to be compiled with the following flags : DEBUG=1 DEBUG_OS_STACK_CONSUMPTION=1

Now test sequences print a stack consumption summary :

...
================================================== stack consumption summary ==================================================
      1185 bytes  test_get_extended_pubkey.py::test_get_extended_pubkey_exception_nodisplay[flex]
      1353 bytes  test_get_extended_pubkey.py::test_get_extended_pubkey_non_standard[flex-flex]
      1497 bytes  test_get_extended_pubkey.py::test_get_extended_pubkey_non_standard_reject[flex-flex]
      1497 bytes  test_get_extended_pubkey.py::test_get_extended_pubkey_non_standard_reject_early[flex-flex]
      1497 bytes  test_get_extended_pubkey.py::test_get_extended_pubkey_nonstandard_display[flex-flex]
       681 bytes  test_get_extended_pubkey.py::test_get_extended_pubkey_nonstandard_nodisplay[flex]
      1497 bytes  test_get_extended_pubkey.py::test_get_extended_pubkey_standard_display[flex-flex]
      1185 bytes  test_get_extended_pubkey.py::test_get_extended_pubkey_standard_nodisplay[flex]
--------- worst case: 1497 bytes  (test_get_extended_pubkey.py::test_get_extended_pubkey_standard_display[flex-flex]) ---------
======================================= 8 passed, 168 deselected, 7 warnings in 28.75s ========================================

The above example is an app-bitcoin-new test run of :

 source /opt/venv/bin/activate && pytest tests -k get_extended_pubkey --device flex --backend speculos --get-stack-consumption

@mbrousset-ledger mbrousset-ledger changed the title add fixture to retrieve stack consumption add option --get-stack-consumption Mar 31, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 31, 2026

Codecov Report

❌ Patch coverage is 34.21053% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.55%. Comparing base (04943af) to head (d4909e6).

Files with missing lines Patch % Lines
src/ragger/conftest/base_conftest.py 34.21% 25 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #268      +/-   ##
==========================================
- Coverage   78.32%   77.55%   -0.77%     
==========================================
  Files          36       36              
  Lines        2191     2228      +37     
==========================================
+ Hits         1716     1728      +12     
- Misses        475      500      +25     
Flag Coverage Δ
apex_p-py3.10 77.46% <34.21%> (-0.77%) ⬇️
apex_p-py3.11 77.46% <34.21%> (-0.77%) ⬇️
apex_p-py3.12 77.46% <34.21%> (-0.77%) ⬇️
apex_p-py3.13 77.46% <34.21%> (-0.77%) ⬇️
apex_p-py3.9 ?
flex-py3.10 77.46% <34.21%> (-0.77%) ⬇️
flex-py3.11 77.46% <34.21%> (-0.77%) ⬇️
flex-py3.12 77.46% <34.21%> (-0.77%) ⬇️
flex-py3.13 77.46% <34.21%> (-0.77%) ⬇️
flex-py3.9 ?
nanos-py3.10 75.85% <34.21%> (-0.74%) ⬇️
nanos-py3.11 75.85% <34.21%> (-0.74%) ⬇️
nanos-py3.12 75.85% <34.21%> (-0.74%) ⬇️
nanos-py3.13 75.85% <34.21%> (-0.74%) ⬇️
nanos-py3.9 ?
nanosp-py3.10 75.89% <34.21%> (-0.74%) ⬇️
nanosp-py3.11 75.89% <34.21%> (-0.74%) ⬇️
nanosp-py3.12 75.89% <34.21%> (-0.74%) ⬇️
nanosp-py3.13 75.89% <34.21%> (-0.74%) ⬇️
nanosp-py3.9 ?
nanox-py3.10 75.85% <34.21%> (-0.74%) ⬇️
nanox-py3.11 75.85% <34.21%> (-0.74%) ⬇️
nanox-py3.12 75.85% <34.21%> (-0.74%) ⬇️
nanox-py3.13 75.85% <34.21%> (-0.74%) ⬇️
nanox-py3.9 ?
stax-py3.10 77.46% <34.21%> (-0.77%) ⬇️
stax-py3.11 77.46% <34.21%> (-0.77%) ⬇️
stax-py3.12 77.46% <34.21%> (-0.77%) ⬇️
stax-py3.13 77.46% <34.21%> (-0.77%) ⬇️
stax-py3.9 ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mbrousset-ledger mbrousset-ledger force-pushed the mbr/stack-fixture branch 2 times, most recently from 55bbd5f to 2f534e8 Compare March 31, 2026 12:55
@mbrousset-ledger mbrousset-ledger marked this pull request as ready for review March 31, 2026 13:12
@iartemov-ledger
Copy link
Copy Markdown
Contributor

⚠️ requires the app to be compiled with the following flags : DEBUG=1 DEBUG_OS_STACK_CONSUMPTION=1

It is not enough to pass the flag as environment variable - it's not handled by the SDK.
To make it work I had to add following line in the Makefile of app-bitcoin-new:

CFLAGS   += -DDEBUG_OS_STACK_CONSUMPTION=1

@mbrousset-ledger
Copy link
Copy Markdown
Contributor Author

⚠️ requires the app to be compiled with the following flags : DEBUG=1 DEBUG_OS_STACK_CONSUMPTION=1

It is not enough to pass the flag as environment variable - it's not handled by the SDK. To make it work I had to add following line in the Makefile of app-bitcoin-new:

CFLAGS   += -DDEBUG_OS_STACK_CONSUMPTION=1

yes, i need to update the SDK

@iartemov-ledger
Copy link
Copy Markdown
Contributor

⚠️ requires the app to be compiled with the following flags : DEBUG=1 DEBUG_OS_STACK_CONSUMPTION=1

It is not enough to pass the flag as environment variable - it's not handled by the SDK. To make it work I had to add following line in the Makefile of app-bitcoin-new:

CFLAGS   += -DDEBUG_OS_STACK_CONSUMPTION=1

yes, i need to update the SDK

LedgerHQ/ledger-secure-sdk#1480.

@mbrousset-ledger mbrousset-ledger force-pushed the mbr/stack-fixture branch 2 times, most recently from a4d6ffc to aa33361 Compare April 1, 2026 11:37
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

@iartemov-ledger iartemov-ledger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The maximum search works:

======================================================================================== stack consumption summary =========================================================================================
      1177 bytes  test_get_extended_pubkey.py::test_get_extended_pubkey_exception_nodisplay[flex]
      1193 bytes  test_get_extended_pubkey.py::test_get_extended_pubkey_non_standard[flex-flex]
      1281 bytes  test_get_extended_pubkey.py::test_get_extended_pubkey_non_standard_reject[flex-flex]
      1281 bytes  test_get_extended_pubkey.py::test_get_extended_pubkey_non_standard_reject_early[flex-flex]
      1281 bytes  test_get_extended_pubkey.py::test_get_extended_pubkey_nonstandard_display[flex-flex]
       673 bytes  test_get_extended_pubkey.py::test_get_extended_pubkey_nonstandard_nodisplay[flex]
      1281 bytes  test_get_extended_pubkey.py::test_get_extended_pubkey_standard_display[flex-flex]
      1177 bytes  test_get_extended_pubkey.py::test_get_extended_pubkey_standard_nodisplay[flex]
----------------------------------------------- worst case: 1281 bytes  (test_get_extended_pubkey.py::test_get_extended_pubkey_standard_display[flex-flex]) ------------------------------------------------

A fix will be done in the SDK to make it work with DEBUG=0.

Maybe to pat attention to the Copilot remark below.

@mbrousset-ledger mbrousset-ledger merged commit 8968d26 into master Apr 2, 2026
53 checks passed
@mbrousset-ledger mbrousset-ledger deleted the mbr/stack-fixture branch April 2, 2026 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants