Skip to content

tests/micropython: Make tests behave in low memory condition. #17955

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

agatti
Copy link
Contributor

@agatti agatti commented Aug 19, 2025

Summary

This PR changes the "viper_ptr*_store_boundary" tests to make them fail more gracefully in low memory conditions.

The original version of the tests compiled viper code blocks on the fly when it needed them, making them fail at runtime on some boards that do not come with enough memory for this test. This clashes with "run-tests.py"'s ability to look for a particular signature to mark tests as skipped due to not enough memory.

Now compiled code blocks are generated at the beginning of the test inside an appropriate exception handler. In case of a memory error when pre-compiling a code block, the running test exits reporting a low memory condition to the test runner. This allows to have clean test runs on all platforms when it comes to viper pointer tests.

Testing

Modified tests were run on an ESP8266 without any parameters to make sure they were reported as too large, and then with an appropriate prologue file to make sure the output is correct. The same tests were also executed on the Unix port on x64, just to be sure.

Trade-offs and Alternatives

I've tried to simplify certain parts of the test to counter the added complexity of generating blocks upfront, although it came with a test output data rearrangement to make it work. On the other hand, now those tests share most of their code except for the typed getters and setters.

This commit changes the "viper_ptr*_store_boundary" tests to make them
fail more gracefully in low memory conditions.

The original version of the tests compiled viper code blocks on the fly
when it needed them, making them fail at runtime on some boards that do
not come with enough memory for this test.  This clashes with
"run-tests.py"'s ability to look for a particular signature to mark
tests as skipped due to not enough memory.

Now compiled code blocks are generated at the beginning of the test
inside an appropriate exception handler.  In case of a memory error when
pre-compiling a code block, the running test exits reporting a low
memory condition to the test runner.  This allows to have clean test
runs on all platforms when it comes to viper pointer tests.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Copy link

codecov bot commented Aug 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.38%. Comparing base (989abae) to head (4510716).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #17955   +/-   ##
=======================================
  Coverage   98.38%   98.38%           
=======================================
  Files         171      171           
  Lines       22296    22296           
=======================================
  Hits        21937    21937           
  Misses        359      359           

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dpgeorge dpgeorge added the tests Relates to tests/ directory in source label Aug 19, 2025
@agatti
Copy link
Contributor Author

agatti commented Aug 19, 2025

This is odd. The error reported by Octoprobe is for an empty line in the source file, but that's right above a @micropython.viper decorator so I assume that's what it really wanted to mark.

That said, I thought compile-time memory errors were caught by the test runner, but no worries. I can move the declaration for set_index in an exec block and move the definition for buffer in the same try..catch block as the runtime compiled functions.

And if the remaining exec calls still make it fail, heh, I'll just wrap the whole lot in an exception handler and call it a day :) I'll fix this right away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Relates to tests/ directory in source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants