summaryrefslogtreecommitdiff
path: root/tests
AgeCommit message (Collapse)Author
2025-05-16tests/cpydiff: Add test of underscore-in-literals.Jeff Epler
Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-05-16tests/cpydiff: Document that uPy requires space after number+period.Jeff Epler
Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-05-16tests/cpydiff: Explain the numeric literal parsing difference.Jeff Epler
Fixes issue #17224. Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-05-15tests/extmod/vfs_lfs_error.py: Test value of all OSError's errno.Damien George
To make sure they have the correct value. Signed-off-by: Damien George <damien@micropython.org>
2025-05-13tests/cpydiff: Document format separator difference.Jeff Epler
Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-05-13py/objstr: Add support for the :_b/o/x specifier in str.format.Jeff Epler
This groups non-decimal values by fours, such as bbb_bbbb_bbbb. It also supports `{:_d}` to use underscore for decimal numbers (grouped in threes). Use of incorrect ":,b" is not diagnosed. Thanks to @dpgeorge for the suggestion to reduce code size. Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-05-12rp2/modmachine: Add mutual exclusion for machine.lightsleep().Angus Gratton
There's no specified behaviour for what should happen if both CPUs call `lightsleep()` together, but the latest changes could cause a permanent hang due to a race in the timer cleanup code. Add a flag to prevent hangs if two threads accidentally lightsleep, at least. This allows the new lightsleep test to pass on RPI_PICO and RPI_PICO2, and even have much tighter time deltas. However, the test still fails on wireless boards where the lwIP tick wakes them up too frequently. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-05-12tests/ports/rp2: Add a test case for light sleeping from CPU1.Angus Gratton
Not currently passing. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-05-12tests/ports/rp2: Update machine idle test to revert skip for RP2350.Peter Harper
This reverts commit b42bb911c663dc90575d6a7fe3ea4760b6559372. Signed-off-by: Peter Harper <peter.harper@raspberrypi.com>
2025-05-12tests/multi_net: Add test that requires queuing UDP packets.Damien George
This commit adds a new network multi-test which sends a burst of UDP packets from the client, and the server doesn't recv them until they have all been sent. Signed-off-by: Damien George <damien@micropython.org>
2025-05-12tests/extmod/vfs_rom.py: Clear sys.path before running test.Damien George
Otherwise if the target has certain files/directories (such as "test") in its filesystem then these interfere with the unit tests. Signed-off-by: Damien George <damien@micropython.org>
2025-05-12tests/net_inet: Update micropython.org certificate for SSL tests.Damien George
The Let's Encrypt root certificate has changed so needs updating in these tests. Also use `bytes.fromhex()` instead of `binascii.unhexlify()`, to eliminate the need for the `binascii` module. Both of these features are controlled by `MICROPY_PY_BUILTINS_BYTES_HEX`, so the test will still work on the same targets that it previously did. Signed-off-by: Damien George <damien@micropython.org>
2025-05-07lib/littlefs: Update LittleFS to v2.10.2.Daniël van de Giessen
Going above the root directory (/../foo) now gives an error. This is an intentional change made by LittleFS. It required a update of the testsuite and is a (minor) compatibility break. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2025-05-07extmod/asyncio: Fix early exit of asyncio scheduler.Yoctopuce dev
This commit fixes three open issues related to the asyncio scheduler exiting prematurely when the main task queue is empty, in cases where CPython would not exit (for example, because the main task is not done because it's on a different queue). In the first case, the scheduler exits because running a task via `run_until_complete` did not schedule any dependent tasks. In the other two cases, the scheduler exits because the tasks are queued in an event queue. Tests have been added which reproduce the original issues. These test cases document the unauthorized use of `Event.set()` from a soft IRQ, and are skipped in unsupported environments (webassembly and native emitter). Fixes issues #16759, #16569 and #16318. Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
2025-05-02tests/extmod: Rename ssl tests that only use the tls module.Angus Gratton
Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-05-02py/malloc: Add mutex for tracked allocations.Angus Gratton
Fixes thread safety issue that could cause memory corruption on ports with (MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL) - currently only rp2 and unix have this configuration. Adds unit test for TLS sockets that exercises this code path. I wasn't able to make this fail on rp2, the race condition window is pretty narrow and may not have a direct impact on a quiet system. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-05-01tests/ports/rp2: Tune rp2.DMA test so it runs in all configurations.Damien George
Changes in this commit: - Allow the DMA instance to be any instance, not just DMA(0); eg WLAN may be using DMA(0). - Make the DMA timing test run a little faster by preloading `dma.active`. - Run the DMA timing test 10 times and take the average time taken as the test result, to eliminate any big effects of caching. - Change the expected time to `range(30, 80)` to cover RP2040, RP2350, RISC-V variants, and both bytecode and native emitter. - Add a `sleep_ms(1)` after waiting for the IRQ to fire, so that any scheduled code gets a chance to run when the test is compiled with the native emitter. With these changes this test passes reliably on RPI_PICO, RPI_PICO_W, RPI_PICO2, RPI_PICO2_W, RPI_PICO2-RISCV and RPI_PICO2_W-RISCV, in both bytecode and native emitter mode, with and without WLAN enabled. Signed-off-by: Damien George <damien@micropython.org>
2025-05-01tests/ports/rp2: Convert rp2.DMA test to a unittest.Damien George
This test is rather complicated and benefits from being a unittest. Signed-off-by: Damien George <damien@micropython.org>
2025-05-01tests/net_hosted: Only run network loopback test on supported targets.Damien George
Only a few ports have TCP/IP loopback enabled in their network stack, and this test will only pass on those ports. There's not really any good way to do a feature check for loopback mode without actually running the test and seeing if it passes/fails, so add an explicit check that the test is running on a port known to support loopback. (Enabling loopback on lwIP, eg RPI_PICO_W, costs +568 code and +272 bss and is a rarely used feature, so not worth unconditionally enabling.) Signed-off-by: Damien George <damien@micropython.org>
2025-04-24tests/extmod/vfs_posix.py: Fix test on Android.Alessandro Gatti
This commit makes a slight change to the vfs_posix test suite to let it pass on Android. On Android, non-root processes can perform most filesystem operations only on a restricted set of directories. The vfs_posix test suite attempted to enumerate the filesystem root directory, and said directory happens to be restricted for non-root processes. This would raise an EACCES OSError and terminate the test with a unexpected failure. To fix this, rather than enumerating the filesystem root directory the enumeration target is the internal shared storage area root - which doesn't have enumeration restrictions for non-root processes. The path is hardcoded because it is guaranteed to be there on pretty much any recent-ish device for now (it stayed the same for more than a decade for compatibility reasons). The proper way would be to query the storage subsystem via a JNI round-trip call, but this introduces too much complexity for something that is unlikely to break going forward. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-04-24tests/extmod/vfs_mountinfo.py: Don't import unused errno module.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2025-04-24tests/extmod/vfs_lfs_ilistdir_del.py: Skip test if not enough memory.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2025-04-24tests/extmod: Skip binascii tests when hexlify/unhexlify don't exist.Damien George
These functions are only available when `MICROPY_PY_BUILTINS_BYTES_HEX` is enabled. Signed-off-by: Damien George <damien@micropython.org>
2025-04-21py/objstr: Fix handling of OP_MODULO with namedtuple.Yoctopuce dev
This fix handles attrtuple as well, eg. os.uname(). A test case has been added in basics/attrtuple2.py. Fixes issue #16969. Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
2025-04-21tests/basics/builtin_range.py: Add more tests for range slicing.Jeff Epler
Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-04-09tests: Update UART and SPI tests to work on Alif boards.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2025-04-09tests/ports/alif_hardware: Add flash testing script.Damien George
This test is not intended to be run automatically and does not have a corresponding .exp file. Signed-off-by: Damien George <damien@micropython.org>
2025-04-07tests/cpydiff: Remove types_str_endswith.Angus Gratton
MicroPython support for this behaviour was added in eb45d97898a. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-04-07tests/cpydiff: Update CPy diff for assign expr in nested comprehensions.Angus Gratton
Since 7c1584aef1 MicroPython matches CPython in most cases, aside from nested comprehensions. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-03-27extmod/vfs_rom: Implement minimal VfsRom.getcwd() method.Damien George
This is needed if you chdir to a ROMFS and want to query your current directory. Prior to this change, using `os.getcwd()` when in a ROMFS would raise: AttributeError: 'VfsRom' object has no attribute 'getcwd' Signed-off-by: Damien George <damien@micropython.org>
2025-03-27tests/extmod/vfs_mountinfo.py: Add test for no-args mount output.Anson Mansfield
Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
2025-03-27extmod/moddeflate: Keep DeflateIO state consistent on window alloc fail.Damien George
Allocation of a large compression window may fail, and in that case keep the `DeflateIO` state consistent so its other methods (such as `close()`) still work. Consistency is kept by only updating the `self->write` member if the window allocation succeeds. Thanks to @jimmo for finding the bug. Signed-off-by: Damien George <damien@micropython.org>
2025-03-27tests/cpydiff: Remove builtin_next_arg2.py difference.Damien George
Because 2-arg `next()` is implemented, and now enabled at the basic feature level. Signed-off-by: Damien George <damien@micropython.org>
2025-03-14tests/multi_pyb_can: Add multitests for pyboard CAN controller.Angus Gratton
Currently only classic CAN, but tests run on both the stm32 classic CAN controller and the FD-CAN controller with the same results. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-03-05py/modsys: Add sys.implementation._build entry.Damien George
For a given MicroPython firmware/executable it can be sometimes important to know how it was built, which variant/board configuration it came from. This commit adds a new field `sys.implementation._build` that can help identify the configuration that MicroPython was built with. For now it's either: * <VARIANT> for unix, webassembly and windows ports * <BOARD>-<VARIANT> for microcontroller ports (the variant is optional) In the future additional elements may be added to this string, separated by a hyphen. Resolves issue #16498. Signed-off-by: Damien George <damien@micropython.org>
2025-03-04test/run-tests: Print a note if it looks like unittest.main() missing.Angus Gratton
This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-03-04tests/run-tests: Remove any 'expected' file from a unittest run.Angus Gratton
This won't be generated normally, but a failed run (for example, from a unittest with an error or which doesn't call unittest.main()) will generate one. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-03-02py/objstr: Support tuples and start/end args in startswith and endswith.Glenn Moloney
This change allows tuples to be passed as the prefix/suffix argument to the `str.startswith()` and `str.endswith()` methods. The methods will return `True` if the string starts/ends with any of the prefixes/suffixes in the tuple. Also adds full support for the `start` and `end` arguments to both methods for compatibility with CPython. Tests have been updated for the new behaviour. Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
2025-02-28py/parsenum: Reduce code footprint of mp_parse_num_float.Yoctopuce dev
The mantissa parsing code uses a floating point variable to accumulate digits. Using an `mp_float_uint_t` variable instead and casting to `mp_float_t` at the very end reduces code size. In some cases, it also improves the rounding behaviour as extra digits are taken into account by the int-to-float conversion code. An extra test case handles the special case where mantissa overflow occurs while processing deferred trailing zeros. Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
2025-02-26extmod/vfs_rom: Add bounds checking for all filesystem accesses.Damien George
Testing with ROMFS shows that it is relatively easy to end up with a corrupt filesystem on the device -- eg due to the ROMFS deploy process stopping half way through -- which could lead to hard crashes. Notably, there can be boot loops trying to mount a corrupt filesystem, crashes when importing modules like `os` that first scan the filesystem for `os.py`, and crashing when deploying a new ROMFS in certain cases because the old one is removed while still mounted. The main problem is that `mp_decode_uint()` has an loop that keeps going as long as it reads 0xff byte values, which can happen in the case of erased and unwritten flash. This commit adds full bounds checking in the new `mp_decode_uint_checked()` function, and that makes all ROMFS filesystem accesses robust. Signed-off-by: Damien George <damien@micropython.org>
2025-02-25tests: Four typos in tests directory.Christian Clauss
Found by codespell. Signed-off-by: Christian Clauss <cclauss@me.com>
2025-02-25all: Upgrade to ruff v0.9.6.Christian Clauss
Signed-off-by: Christian Clauss <cclauss@me.com>
2025-02-14tests/multi_net: Add test for DTLS server and client.Damien George
This adds a multi-test for DTLS server and client behaviour. It works on all ports that enable this feature (eg unix, esp32, rp2, stm32), but bare-metal ports that use lwIP are not reliable as the DTLS server because the lwIP bindings only support queuing one UDP packet at a time (that needs to be fixed). Also, to properly implement a DTLS server sockets need to support `socket.recvfrom(n, MSG_PEEK)`. That can be implemented in the future. Signed-off-by: Damien George <damien@micropython.org>
2025-02-14extmod/modtls_mbedtls: Wire in support for DTLS.Keenan Johnson
This commit enables support for DTLS, i.e. TLS over datagram transport protocols like UDP. While support for DTLS is absent in CPython, it is worth supporting it in MicroPython because it is the basis of the ubiquitous CoAP protocol, used in many IoT projects. To select DTLS, a new set of "protocols" are added to SSLContext: - ssl.PROTOCOL_DTLS_CLIENT - ssl.PROTOCOL_DTLS_SERVER If one of these is set, the library assumes that the underlying socket is a datagram-like socket (i.e. UDP or similar). Our own timer callbacks are implemented because the out of the box implementation relies on `gettimeofday()`. This new DTLS feature is enabled on all ports that use mbedTLS. This commit is an update to a previous PR #10062. Addresses issue #5270 which requested DTLS support. Signed-off-by: Keenan Johnson <keenan.johnson@gmail.com>
2025-02-11extmod/vfs_rom: Remove ability to create VfsRom from an address.Damien George
It's not necessary to support this, which allows an arbitrary memory address to be specified and potentially allows invalid memory accesses. Requiring an object with the buffer protocol is safer, and also means that the length of the region is always specified. Signed-off-by: Damien George <damien@micropython.org>
2025-02-11extmod/modmarshal: Add new marshal module.Damien George
This commit implements a small subset of the CPython `marshal` module. It implements `marshal.dumps()` and `marshal.loads()`, but only supports (un)marshalling code objects at this stage. The semantics match CPython, except that the actual marshalled bytes is not compatible with CPython's marshalled bytes. The module is enabled at the everything level (only on the unix coverage build at this stage). Signed-off-by: Damien George <damien@micropython.org>
2025-02-11py/objfun: Implement function.__code__ and function constructor.Damien George
This allows retrieving the code object of a function using `function.__code__`, and then reconstructing a function from a code object using `FunctionType(code_object)`. This feature is controlled by `MICROPY_PY_FUNCTION_ATTRS_CODE` and is enabled at the full-features level. Signed-off-by: Damien George <damien@micropython.org>
2025-02-11tests/run-tests.py: Give more information when CPython crashes.Damien George
To make it easier to diagnose why CPython crashed. Signed-off-by: Damien George <damien@micropython.org>
2025-02-07tests/run-natmodtests.py: Autodetect the test target architecture.Alessandro Gatti
This commit lets the natmod tests runner to automatically detect the architecture of the test target. This allows to avoid to explicitly pass the architecture name to the runner in test scripts. However, the ability to manually specify a target was not removed but it was made optional. This way the user is able to override the architecture name if needed (like if one wants to test an armv6 MPY on an armv7 board). Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-02-07tests/multi_wlan: Remove esp8266 port workaround.Angus Gratton
Not needed due to parent commit. Signed-off-by: Angus Gratton <angus@redyak.com.au>