summaryrefslogtreecommitdiff
path: root/tests
AgeCommit message (Collapse)Author
2025-09-26tests/ports/unix: Add coverage test for readinto1 stream method.Damien George
And expand the test for `readinto()` to test the difference between trying to read the requested amount by doing multiple underlying IO calls, and only doing one call. Signed-off-by: Damien George <damien@micropython.org>
2025-09-25tests: Test hardware timers as well as software timers.Chris Webb
On platforms where hardware timers are available, test these in each combination of hard/soft and one-shot/periodic in the same way as for software timers. Where a platform supports both software (id = -1) and hardware (id >= 0) timers, the behaviour of both is now checked. For now, esp8266 is the only platform that supports hardware timers and both hard and soft callbacks. Signed-off-by: Chris Webb <chris@arachsys.com>
2025-09-25tests: Generalise rp2 timer test into a cross-port test.Chris Webb
Now all ports with machine.Timer except nrf support both hard and soft callbacks, generalise tests/ports/rp2_machine_timer.py into tests/extmod/machine_timer.py. There is an existing machine_soft_timer.py which varies period= and covers the nrf port but skips esp32/esp8266 because they don't support software timers. In our new test, we try varying freq= instead of period=, and cover esp32/esp8266 (with a fixed choice of hardware timer) but skip nrf because it doesn't support hard= or freq=. Add a check that the heap is locked (so allocation fails) in hard callbacks and it is unlocked (so allocation succeeds) in soft callbacks, to ensure we're getting the right kind of callback, not falling back to the default. Signed-off-by: Chris Webb <chris@arachsys.com>
2025-09-24tests/README: Update docs for run-perfbench.py now that it uses -t.Damien George
Follow up to dbbc7d96672bb44a04f27fef32231dd7340d7952 Signed-off-by: Damien George <damien@micropython.org>
2025-09-23tests/cmdline: Add tests for using -m combined with sys.atexit.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2025-09-23unix/modsocket: Set file descriptor to -1 on close.Mike Wang
After s.close(), s.fileno() now returns -1, matching CPython behavior. Some code relies on this compatibility, as it allows checking whether a socket is closed by testing its fileno() value. This change ensures better interoperability with existing Python code and libraries. Signed-off-by: Mike Wang <mikewang000000@gmail.com>
2025-09-19py/emitinlinerv32: Add Zba opcodes to the inline assembler.Alessandro Gatti
This commit adds support for Zba opcodes to the RV32 inline assembler. Three new opcodes were added, SH1ADD, SH2ADD, and SH3ADD, which performs a scaled addition (by 1, 2, or 3 bits respectively). At the moment only qemu's VIRT_RV32 and rp2's RPI_PICO2/RPI_PICO2_W ports support these opcodes (the latter only when using the RISCV variant). Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-09-19mpy-cross: Add RISC-V RV64IMC support in MPY files.Alessandro Gatti
MPY files can now hold data to be run on RV64IMC. This can be accomplished by passing the `-march=rv64imc` flag to mpy-cross. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-09-16tests/run-perfbench.py: Fix issues when -s/-m is used with failed tests.Yuuki NAGAO
The option '-s' (--diff-score) or '-m' (--diff-time) fails when the specified result contains tests that was skipped or failed. This patch ignores "skipped: " or "failed: " message. Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2025-09-16unix/modsocket: Use type-checking mp_obj_get_int.Jeff Epler
MP_OBJ_SMALL_INT_VALUE would give erroneous results, such as assertion failures in the coverage build and other oddities like: >>> s = socket.socket() >>> s.recv(3.14) MemoryError: memory allocation failed, allocating 4235896656 bytes Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-09-15tests/internal_bench/var: Benchmark ordered map accesses.Anson Mansfield
This adds an internal_bench benchmark that benchmarks ordered map linear scan cache performance. Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
2025-09-15tests/internal_bench/var: Benchmark checked attribute access.Anson Mansfield
This commit also includes a fix to the `var-6.2-instance-speciallookup.py` test originally added by 82db5c8 / #16806, as the `__getattr__` method actually does not trigger a class's special lookups flag as originally believed. Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
2025-09-15tests/internal_bench/class_instance: Benchmark instantiation.Anson Mansfield
This commit adds tests to benchmark the performance of class instantiation. Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
2025-09-11tests/cpydiff: Test for PEP487 __init_subclass__.Anson Mansfield
This commit documents and verifies the current absence of `__init_subclass__` functionality, in anticipation of a possible future PEP487 'metaclasses lite' patch. The main `core_class_initsubclass.py` test verifies if the method is automatically called, while the other three verify other orthogonal properties it should have: if the method is an implicit classmethod; if MicroPython supplies the base case for the usual recursive function body the PEP encourages; and if kwargs inheritance parameters work correctly. Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
2025-09-11tests/cpydiff: Document ENOTSUP vs EOPNOTSUPP.Anson Mansfield
Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
2025-09-11tests/cpydiff: Document lack of OSError errno subtype mapping.Anson Mansfield
Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
2025-09-10tests: Add a test for invalid syntax in @micropython.asm.Jeff Epler
Signed-off-by: Jeff Epler <jepler@unpythonic.net>
2025-09-08tests/target_wiring/ZEPHYR_NUCLEO_WB55RG.py: Add nucleo_wb55rg.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2025-09-08tests: Convert all machine.UART tests to use target_wiring.Damien George
All the existing `machine.UART` tests in extmod and extmod_hardware are converted to use the new `target_wiring` scheme, which removes a lot of duplicated board-specific settings. All the existing boards that were supported by these UART tests now have their own `target_wiring` file. Some configurations are board specific (eg NUCLEO_WB55) and others are port specific. Signed-off-by: Damien George <damien@micropython.org>
2025-09-08tests/run-tests.py: Add support for board-specific target_wiring config.Damien George
There are currently a few "hardware" tests that need external board connections to be made for them to work, such as bridging a pair of pins. For example, all tests in `tests/extmod_hardware` need some kind of connection. Along with the physical connections -- which are different for each board -- there needs to be corresponding Python settings, eg which UART instance to use and which pins for TX/RX. These settings are currently hard-coded in each test file. That has a few problems: - settings are repeated, eg all the UART tests have pretty much the same settings code duplicated across them - changing the settings means changing many files - adding a new board means adding a lot of code - the tests get bigger and bigger with each new board that they support, meaning they may not fit on targets with a small amount of RAM (that's already the case with `tests/extmod_hardware/machine_pwm.py`) - if you have a custom board you have to manually edit the test to add your own settings This commit aims to solve all the above problems by splitting the board- specific settings out into separate files, one for each board (or port). They are placed in the `tests/target_wiring/` directory. The `run-tests.py` test runner then loads the appropriate configuration for the target that is being tested, sends it to the board so it's available as `import target_wiring` (without needing a filesystem), and then executes the test. Note tht only tests that need `target_wiring` have it loaded. This commit adds support for this `target_wiring` scheme. Signed-off-by: Damien George <damien@micropython.org>
2025-09-08tests/run-tests.py: Detect target sys.implementation._build if possible.Damien George
That's useful to know the exact board that's being tested. Signed-off-by: Damien George <damien@micropython.org>
2025-09-08tests/ports/rp2: Decrease test lower bound for thread lightsleep time.Damien George
This makes the rp2-specific lightsleep test more lenient, so it passes. This test was added in PR #16454 / 69993daa5c2eae6055f0b3b2330e95e78d6e3738 and even back then it did not pass reliably on RP2040. The issue is that threads can race each other to enter lightsleep mode, and when one of them actually stops the CPU clock the other thread is stopped as well. Depending on whether the other thread was just entering or just exiting lightsleep itself, the total duration of all sleeps can vary and can be as small as 2*T. Therefore, adjust the minimum to allow 2*T. `machine.lightsleep()` is anyway 1) specified only to wait at most the given time; and 2) not well specified when multiple threads call it at the same time. So it seems OK to make the test more lenient. Work done in collaboration with @projectgus. Signed-off-by: Damien George <damien@micropython.org>
2025-09-01tests: Add test for heap lock in REPL.Jeff Epler
Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-08-29tests/multi_net: Simplify SKIP when imports don't exist.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2025-08-29tests/multi_net: Require SSL cert file to be available for test to run.Damien George
These were missed in 2bba507148e8a751123257fa2b075c70d67e1160 because they didn't use the `os.stat` pattern. Signed-off-by: Damien George <damien@micropython.org>
2025-08-28tests/net_inet/tls_num_errors.py: Make alloc of emg-exc-buf optional.Damien George
The unix port doesn't have `micropython.alloc_emergency_exception_buf()` but it's still possible to run and pass this test. So make that call optional. Signed-off-by: Damien George <damien@micropython.org>
2025-08-28tests/run-perfbench.py: Change -p/-d arguments to -t.Damien George
And the existing "-t" option is changed to "-m" (shorthand for the "--diff-time" option). Signed-off-by: Damien George <damien@micropython.org>
2025-08-28tests/run-natmodtests.py: Change -p/-d arguments to -t.Damien George
Following the similar change to `run-tests.py` and `run-multitests.py`. What was previously, eg, `-p -d /dev/ttyACM0` is now `-t a0`. Signed-off-by: Damien George <damien@micropython.org>
2025-08-28tests/run-multitests.py: Change -i argument to -t.Damien George
Back in commit 8978102f3595ae321484a6be44c1dcf25c8909a9 (see PR #16111) the `run-tests.py` script was changed to use an improved way of selecting the test instance, eg: $ ./run-tests.py -t a0 that would run on /dev/ttyACM0. This has been a very nice improvement, makes it easier to specify the target. This commit updates `run-multitests.py` to use the same scheme. It previously used `-i` but now that's changed to `-t`. Signed-off-by: Damien George <damien@micropython.org>
2025-08-28tests/run-tests.py: Factor code for device shortcuts to a function.Damien George
So it can be reused by other test runners. Signed-off-by: Damien George <damien@micropython.org>
2025-08-28py/parsenum: Fix parsing LLONG_MIN in longlong configuration.Jeff Epler
Re-organize `mp_parse_num_integer()` (for longlong) slightly so that the most negative 64-bit integer can be parsed. Fixes issue #17932. Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-08-26tests/run-tests.py: Enable Arm inlineasm FPU tests if possible.Alessandro Gatti
This commits lifts the unconditional restriction on inline assembler FPU tests for the Qemu platform, and makes said restriction conditional to the lack of an available floating point unit on the running platform. The Qemu platform supported only emulated machines that could target up to a Cortex-M3, so an ArmV7-M target that had no support for floating point. With the addition of MPS2_AN500 to the list of emulated targets the range was extended to cover up to Cortex-M7, so a floating point unit may possibly be available and thus able to run the FPU inlineasm tests. For that, the test runner was changed to detect the running architecture when checking the target capabilities; if the target reports its MicroPython architecture to be either "armv7emsp" or "armv7emdp" (providing single-precision and double-precision floating point unit support respectively) then the FPU-only inline tests are not put into the blocked tests list. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-08-26tests/micropython: Make tests behave in low memory condition.Alessandro Gatti
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>
2025-08-19py/asmthumb: Fix T3 encoding of conditional branches.Alessandro Gatti
This commit fixes the encoding of conditional branch opcodes emitted for ARMv7-M targets, when the emitter decides to use the T3 encoding for said operation. Fields J1 and J2 are now present in the generated opcode word, along with correcting some minor issues in bitmasks and shifts computation. This fixes #17940. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-08-19tests/stress/recursive_iternext: Rewrite to find its own limit.Angus Gratton
Necessary on the unix port when running with sanitizers, as the newly increased stack size can run all tests at N=5000 without raising RuntimeError, and increasing N to fix this causes issues on other configurations. This way the test progressively builds a deeper data structure until it fails with RuntimeError. This is theoretically slower, but not noticeably so in reality. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-08-15py/objringio: Detect incorrect constructor calls.Jeff Epler
ringbuffer.size must be at least 2, and is a 16-bit quantity. This fixes several cases including the one the fuzzer discovered, which would lead to a fatal signal when accessing the object. Fixes issue #17847. Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-08-15extmod/modframebuf: Fix crash in scroll() for large inputs.Jeff Epler
If mp_int_t is wider than int, then the tests such as `xend < 0` can fail even when the amount of scrolling requested is out of range. This resulted in a segmentation fault when attempting an out-of-bounds access to the framebuffer. Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-08-15tests: Require SSL certificate file to be available for test to run.Damien George
Previously, any test needing an SSL certificate file would automatically skip if the file could not be found. But that makes it too easy to accidentally skip tests. Instead, change it so that the test fails if the certificate file doesn't exist. That matches, for example, the fact that the test fails if networking (LAN, WiFi) is not active. Signed-off-by: Damien George <damien@micropython.org>
2025-08-15tests: Add .native.exp output files for tests that differ with native.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2025-08-15tests/micropython/opt_level_lineno.py: Force test func to use bytecode.Damien George
So that the test can run the same on all targets when used with the native emitter. Signed-off-by: Damien George <damien@micropython.org>
2025-08-15tests/misc/print_exception.py: Use "raise e" instead of no-arg "raise".Damien George
This allows the test to run with the native emitter. The test semantics remain the same. Signed-off-by: Damien George <damien@micropython.org>
2025-08-15tests/run-tests.py: Add support for .native.exp expected output files.Damien George
There are currently a few tests that are excluded when using the native emitter because they test printing of exception tracebacks, which includes line numbers. And the native emitter doesn't store line numbers, so gets these tests wrong. But we'd still like to run these tests using the native emitter, because they test useful things even if the line number info is not in the traceback (eg that threads which crash print out their exception). This commit adds support for native-specific .exp files, which are of the form `<test>.py.native.exp`. If such an .exp file exists then it take precedence over any normal `<test>.py.exp` file. (Actually, the implementation here is general enough that it also supports `<test>.py.bytecode.exp` as well, if bytecode ever needs a specific exp file.) Signed-off-by: Damien George <damien@micropython.org>
2025-08-15tests/misc/rge_sm.py: Remove unused code from the test.Damien George
This cleans up the test to remove all unused code, making it smaller, a bit faster to deploy to a target to run, and also use less RAM on the target (which may help it run on targets that are just slightly out of memory running it). Signed-off-by: Damien George <damien@micropython.org>
2025-08-15tests/basics: Skip tests of io module individually using SKIP.Damien George
Instead of using a feature check. This is more consistent with how other optional modules are skipped. Signed-off-by: Damien George <damien@micropython.org>
2025-08-15tests/run-tests.py: Autodetect if the target has unicode support.Damien George
The unicode tests are now run on all targets that enable unicode. And other unicode tests (namely `extmod/json_loads.py`) are now properly skipped if the target doesn't have unicode support. Signed-off-by: Damien George <damien@micropython.org>
2025-08-15tests/run-tests.py: Generalise addition of port specific test directory.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2025-08-15tests/run-tests.py: Always include stress/ tests directory in tests.Damien George
Ports that now run the stress tests, that didn't prior to this commit are: cc3200, esp8266, minimal, nrf, renesas-ra, samd, qemu, webassembly. Signed-off-by: Damien George <damien@micropython.org>
2025-08-15tests/run-tests.py: Automatically include float tests when possible.Damien George
This simplifies the code by removing the explicit addition of the "float/" test directory for certain targets. It also means the tests won't be added incorrectly, eg on a unix build without float. Signed-off-by: Damien George <damien@micropython.org>
2025-08-11tests/micropython: Remove big ints dependence for viper boundary tests.Alessandro Gatti
This commit provides an implementation for viper boundary tests that can work even without big int support. Since it uses a fixed-size buffer to hold values to work with, this should work on any platform as long as its integers are at least 32 bits wide, regardless its configuration on how big integers can get. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-08-11extmod/modre: Add support for start- and endpos.Jared Hancock
Pattern objects have two additional parameters for the ::search and ::match methods to define the starting and ending position of the subject within the string to be searched. This allows for searching a sub-string without creating a slice. However, one caveat of using the start-pos rather than a slice is that the start anchor (`^`) remains anchored to the beginning of the text. Signed-off-by: Jared Hancock <jared@greezybacon.me>