Repository navigation
Run MicroPython's tests in the simulator - #145
Merged
Merged
Conversation
UTF8ToString stops at the first NUL even when given a length, so
print('\x00abc') lost the rest of that write.
Each test from MicroPython's basics, float and unicode directories runs as main.py, and its serial output is compared with the test's .exp file or with CPython's output, as MicroPython's run-tests.py does. This would have caught the miscompiled for loop: 70 of the basics tests crashed on that build. The CPython output is generated by update-expected.py and checked in, so test runs don't depend on the local Python. MicroPython v1.18's CI used Python 3.8, so the script insists on that. A test fails if the checked-in output is for a different MicroPython commit. Tests that don't apply to the port are listed with reasons in skip.ts. The Playwright step's timeout goes up as the run is longer.
|
Preview build will be at |
MicroPython's stack check measured against the 1 MB Emscripten stack in linear memory, but C recursion also uses the browser's own call stack, which ran out first. Recursive generators and printing a container that contains itself ended with "RangeError: Maximum call stack size exceeded" as an internal error. In Chrome that happened with about 128 KB of the linear stack in use on the debug firmware and 260 KB on the release one. Limit the check to 64 KB so these raise RuntimeError, as on the device. Python function recursion is unaffected as the Python stack bounds it first.
A program that finished with the heap locked via micropython.heap_lock() left the REPL unable to allocate, which reached nlr_jump_fail and exit(1). After an uncaught exception it also couldn't build the traceback.
Adds the extmod, import, micropython, misc and stress directories. Most of extmod skips itself as the port lacks those modules, but what runs exercises the simulator's time and random number support. Tests in import need the files alongside them, so those are uploaded too. The skip list moves to JSON so the generator can read it and not write expected output for skipped tests. One of those prints an absolute path.
Loading the simulator took longer than most of these tests. Flashing one that is already loaded roughly halves the run with a single worker. A test that times out or hits a simulator error closes it so the next starts clean.
Each buffer from the sound expression synth is under 12 ms, and the next was only requested when one finished, so playback ran one buffer ahead. Any brief stall on the main thread left a gap of an audio render quantum, heard as a click, usually in the first 50 ms while the program starts. Keep 100 ms scheduled. The synth is pure JavaScript so it can be asked for more straight away. To keep the timing the firmware sees: - an expression counts as active until its scheduled audio has played, not just until the synth has generated it; - stopping an expression, or starting another, silences what is scheduled, as does stopping the board for all buffered audio.
The recorder runs on the main thread, which is busy while the simulator starts. Under load it missed the start of sounds made straight away, so music.pitch occasionally measured short.
The audio tests no longer fail when run alongside others.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Runs MicroPython's own tests in the simulator as a new
micropython-testsPlaywright project. Each test file runs asmain.pyand its serial output must match the test's.expfile or, where it has none, CPython's output, as MicroPython'srun-tests.pydoes.This would have caught the miscompiled
forloop fixed in #144: 70 of thebasicstests crashed on that build. It also found the three bugs fixed here.What runs
The
basics,extmod,float,import,micropython,misc,stressandunicodedirectories: 838 tests, of which 569 pass, 195 skip themselves by printingSKIPfor a missing feature (139 of those inextmod), and 74 are skipped bymicropython-tests/skip.jsonwith reasons. Tests inimporthave the files alongside them uploaded too.The skip list breaks down as:
iomodule (8)help()andmem_info()output (14)machine.mem(1)Expected output
micropython-tests/update-expected.pygenerates the CPython output, which is checked in undermicropython-tests/expected, so test runs don't depend on the local Python.Simulator fixes
print('\x00abc')printed nothing. Found bybasics/string_strip.RangeError: Maximum call stack size exceededas an internal error. Recursive generators and printing a container that contains itself did this. The check now stops at 64 KB of the Emscripten stack so they raiseRuntimeError. That is still far more permissive than the device, which allows 7,680 bytes. The overflow point was measured in Chrome only. Found bystress/recursive_gen.micropython.heap_lock()left the REPL unable to allocate and exited the runtime. Found by two of themicropython/heapalloc_*tests.Audio
SoundEffecttest failing when run in parallel.Other changes