summaryrefslogtreecommitdiffstatshomepage
path: root/tests/extmod
Commit message (Collapse)AuthorAge
* tests/extmod: Add platform_basic.py for basic coverage test of platform.Jeff Epler7 days
| | | | Signed-off-by: Jeff Epler <jepler@gmail.com>
* tests/extmod/random_extra_float.py: Skip when funcs not available.Damien George11 days
| | | | | | | | | | | This test was factored out from `random_extra.py` back in commit 6572029dc0665e58c2ea7355c9e541bdf83105a4, and the skip logic copied from that file. But the skip logic needs to test that the `random` and `uniform` functions exist, not `randint`. This commit fixes that skip logic. Signed-off-by: Damien George <damien@micropython.org>
* extmod/modframebuf: Add support for blit'ing read-only data.Damien George2025-06-04
| | | | | | | | | | | | | | | | | | | | | | Currently the `FrameBuffer.blit(buf, x, y)` method requires the `buf` argument to be another `FrameBuffer`, which is quite restrictive because it doesn't allow blit'ing read-only memory/data. This commit extends `blit()` to allow the `buf` argument to be a tuple or list of the form: (buffer, width, height, format[, stride]) where `buffer` can be anything with the buffer protocol and may be read-only, eg `bytes`. Also, the palette argument to `blit()` may be of the same form. The form of this tuple/list was chosen to be the same as the signature of the `FrameBuffer` constructor (that saves quite a bit of code size doing it that way). Signed-off-by: Damien George <damien@micropython.org>
* extmod/modjson: Detect unterminated composite entities.Alessandro Gatti2025-05-19
| | | | | | | | | | | | | | | This commit makes the JSON parser raise an exception when handling objects or arrays whose declaration is incomplete, as in missing the closing marker (brace or bracket) and if the missing marker would have been the last non-whitespace character in the incoming string. Since CPython's JSON parser would raise an exception in such a case, unlike MicroPython's, this commit aligns MicroPython's behaviour with CPython. This commit fixes issue #17141. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* tests/extmod/vfs_lfs_error.py: Test value of all OSError's errno.Damien George2025-05-15
| | | | | | To make sure they have the correct value. Signed-off-by: Damien George <damien@micropython.org>
* tests/extmod/vfs_rom.py: Clear sys.path before running test.Damien George2025-05-12
| | | | | | | 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>
* lib/littlefs: Update LittleFS to v2.10.2.Daniël van de Giessen2025-05-07
| | | | | | | | 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>
* extmod/asyncio: Fix early exit of asyncio scheduler.Yoctopuce dev2025-05-07
| | | | | | | | | | | | | | | | | | | | | 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>
* tests/extmod: Rename ssl tests that only use the tls module.Angus Gratton2025-05-02
| | | | Signed-off-by: Angus Gratton <angus@redyak.com.au>
* py/malloc: Add mutex for tracked allocations.Angus Gratton2025-05-02
| | | | | | | | | | | | | | 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>
* tests/extmod/vfs_posix.py: Fix test on Android.Alessandro Gatti2025-04-24
| | | | | | | | | | | | | | | | | | | | | | 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>
* tests/extmod/vfs_mountinfo.py: Don't import unused errno module.Damien George2025-04-24
| | | | Signed-off-by: Damien George <damien@micropython.org>
* tests/extmod/vfs_lfs_ilistdir_del.py: Skip test if not enough memory.Damien George2025-04-24
| | | | Signed-off-by: Damien George <damien@micropython.org>
* tests/extmod: Skip binascii tests when hexlify/unhexlify don't exist.Damien George2025-04-24
| | | | | | | These functions are only available when `MICROPY_PY_BUILTINS_BYTES_HEX` is enabled. Signed-off-by: Damien George <damien@micropython.org>
* tests: Update UART and SPI tests to work on Alif boards.Damien George2025-04-09
| | | | Signed-off-by: Damien George <damien@micropython.org>
* extmod/vfs_rom: Implement minimal VfsRom.getcwd() method.Damien George2025-03-27
| | | | | | | | | | | 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>
* tests/extmod/vfs_mountinfo.py: Add test for no-args mount output.Anson Mansfield2025-03-27
| | | | Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
* extmod/moddeflate: Keep DeflateIO state consistent on window alloc fail.Damien George2025-03-27
| | | | | | | | | | | 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>
* extmod/vfs_rom: Add bounds checking for all filesystem accesses.Damien George2025-02-26
| | | | | | | | | | | | | | | | | | | 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>
* extmod/modtls_mbedtls: Wire in support for DTLS.Keenan Johnson2025-02-14
| | | | | | | | | | | | | | | | | | | | | | | | | 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>
* extmod/vfs_rom: Remove ability to create VfsRom from an address.Damien George2025-02-11
| | | | | | | | | | 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>
* extmod/modmarshal: Add new marshal module.Damien George2025-02-11
| | | | | | | | | | | | | 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>
* tests: Add a test for SSL socket memory leaks.Angus Gratton2025-02-03
| | | | | | | | | | | | | Test is for an issue reported on the micropython-lib Discord as effecting the rp2 port umqtt.simple interface when reconnecting with TLS, however it's a more generic problem. Currently this test fails on RPI_PICO_W and ESP32_GENERIC_C3 (and no doubt others). Fixes are in the subsequent commits. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* tests/extmod/re_sub.py: Fix test execution on Python 3.13.Alessandro Gatti2025-01-15
| | | | | | | | | | | | | | This commit fixes a test failure for `extmod/re_sub.py` where the code, whilst being correct, would not make the test pass due to a newer Python version than expected. On Python 3.13, running `tests/extmod/re_sub.py` would yield a deprecation warning about `re.sub` not providing the match count as a keyword parameter. This warning would be embedded in the expected test result and thus the test would always fail. Co-authored-by: stijn <stijn@ignitron.net> Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* tests/extmod/vfs_rom.py: Import errno for test.Damien George2025-01-06
| | | | | | | It's needed by the test. This previously passed because the compiler (actually parser) optimises away errno constants. Signed-off-by: Damien George <damien@micropython.org>
* tests/extmod: Add VfsRom test.Damien George2024-12-23
| | | | | | Provides full coverage of the VfsRom driver. Signed-off-by: Damien George <damien@micropython.org>
* tests/extmod: Add test for uctypes.addressof function.Damien George2024-12-18
| | | | Signed-off-by: Damien George <damien@micropython.org>
* tests/extmod: Convert machine1.py test to use unittest.Damien George2024-12-06
| | | | Signed-off-by: Damien George <damien@micropython.org>
* tests/extmod: Workaround CPython warning in asyncio_new_event_loop test.Angus Gratton2024-11-28
| | | | | | | | | | | | | | | | | | | | This started failing in CI on the mingw build, after CPython updated to 3.12.7. The test prints two warnings during interpreter shutdown of "Task was destroyed but it is pending!". This didn't happen on other CPython builds, and I think that's because of finalizer order in CPython interpreter shutdown but not certain (the loop finalizer calls loop.close() if not already closed). Adding explicit calls to loop.close() causes the warning to be printed on every run with CPython 3.12.7 on Linux. Next, added the workaround exception handler to swallow this exception as MicroPython doesn't produce an equivalent. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* extmod/modframebuf: Fix 0 radius bug in FrameBuffer.ellipse.Corran Webster2024-11-28
| | | | | | | | | | | | | | | | | | | | This fixes a bug in FrameBuffer.ellipse where it goes into an infinite loop if both radii are 0. This fixes the bug with a simple pre-check to see if both radii are 0, and in that case sets a single pixel at the center. This is consistent with the behaviour of the method when called with just one of the radii set to 0, where it will draw a horizontal or vertical line of 1 pixel width. The pixel is set with setpixel_checked so it should handle out-of-bounds drawing correctly. This fix also includes three new tests: one for the default behaviour, one for drawing out-of-bounds, and one for when the sector mask is 0. Fixes issue #16053. Signed-off-by: Corran Webster <cwebster@unital.dev>
* tests/extmod: Add test to compare time_ns with time.Damien George2024-10-24
| | | | | | They should be close together. Signed-off-by: Damien George <damien@micropython.org>
* tests/extmod: Use time_ns instead of time in lfs mtime test.Damien George2024-10-24
| | | | | | | Because VfsLfs2 uses time_ns to create timestamps for files, and for the test to give consistent results it also needs to use this same function. Signed-off-by: Damien George <damien@micropython.org>
* tests/extmod: Fix access of RTC class in machine.RTC test.Damien George2024-10-24
| | | | | | | This previously passed on some targets that automatically import the `machine` module in `boot.py`. Signed-off-by: Damien George <damien@micropython.org>
* tests/extmod: Add a simple test for machine.RTC.Damien George2024-10-24
| | | | | | Tests at least that the datetime can be set and get correctly. Signed-off-by: Damien George <damien@micropython.org>
* tests/extmod: Support esp32,mimxrt,stm32,samd ports in UART TX test.Damien George2024-10-22
| | | | | | | | | | | | | Getting this test running on stm32- and mimxrt-based boards requires adding a small delay after constructing the UART so that the initial idle frame has time to be transmitted before the test starts. Also, the timing margin needs to account for an additional 1-bit worth of time on some MCUs. Thanks to @robert-hh for the esp32, mimxrt and samd settings. Signed-off-by: Damien George <damien@micropython.org>
* tests/extmod: Make invalid-blockdev test work consistently on all ports.Damien George2024-10-22
| | | | | | | | | | | Some ports (eg stm32) configure the FAT driver differently (eg with multi-partition support) and that leads to a slightly different sequence of block reads, compared to other configurations (eg rp2). Comment out the printing in `readblocks()` so the tests are deterministic (the printing is still useful for debugging). Signed-off-by: Damien George <damien@micropython.org>
* tests/extmod: Adjust ssl/tls tests to run on targets with axTLS.Damien George2024-10-22
| | | | Signed-off-by: Damien George <damien@micropython.org>
* tests/extmod: Config SPI test for esp8266 and skip SoftTimer test.Damien George2024-10-22
| | | | Signed-off-by: Damien George <damien@micropython.org>
* extmod/modframebuf: Fix FrameBuffer size check for stride corner-cases.Corran Webster2024-10-22
| | | | | | | | | | | | | | | | | | | | | This is a fix for issue #15944, and handles corner cases in the FrameBuffer code when using stride values where the last line's stride may extend past the end of the underlying buffer. This commit includes extra tests for these corner cases. For example a GS8 format FrameBuffer with a width of 8, height of 2 and stride of 10 should be able to fit into a buffer of size 18 (10 bytes for the first horizontal line, and 8 bytes for the second -- the full 10 bytes are not needed). Similarly a 1 by 9 FrameBuffer in MONO_VLSB format with a stride of 10 should be able to fit into a buffer of length 11 (10 bytes for the first 8 lines, and then one byte for the 9th line. Being able to do this is particularly important when cropping the corner of an existing FrameBuffer, either to copy a sprite or to clip drawing. Signed-off-by: Corran Webster <cwebster@unital.dev>
* rp2/machine_uart: Make it so TX is done only when no longer busy.Damien George2024-10-22
| | | | | | | | | | | | | | | | Prior to this commit, when flushing a UART on the rp2 port, it returns just before the last character is sent out the wire. Fix this by waiting until the BUSY flag is cleared. This also fixes the behaviour of `UART.txdone()` to return `True` only when the last byte has gone out. Updated docs and tests to match. The test now checks that UART TX time is very close to the expected time (prior, it was just testing that the TX time was less than the expected time). Signed-off-by: Damien George <damien@micropython.org>
* esp32: Fix hang in taskYIELD() on riscv CPUs when IRQs disabled.Angus Gratton2024-10-10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Regression introduced in 337742f. The hang occurs because the esp32 port was calling "from ISR" port-layer functions to set/clear the interrupt mask. FreeRTOS kernel therefore doesn't know the CPU is in a critical section. In taskYIELD() the riscv port layer blocks after yielding until it knows the yield has happened, and would block indefinitely if IRQs are disabled (until INT WDT triggers). Moving to the "public" portENTER_CRITICAL/portEXIT_CRITICAL API means that FreeRTOS knows we're in a critical section and can react accordingly. Adds a regression test for this case (should be safe to run on all ports). On single core CPUs, this should result in almost exactly the same behaviour apart from fixing this case. On dual core CPUs, we now have cross-CPU mutual exclusion for atomic sections. This also shouldn't change anything, mostly because all the code which enters an atomic section runs on the same CPU. If it does change something, it will be to fix a thread safety bug. There is some risk that this change triggers a FreeRTOS crash where there is a call to a blocking FreeRTOS API with interrupts disabled. Previously this code might have worked, but was probably thread unsafe and would have hung in some circumstances. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* tests: Tweak machine SPI and UART tests to work with esp32c6.Damien George2024-10-09
| | | | Signed-off-by: Damien George <damien@micropython.org>
* extmod/vfs_blockdev: Implement common helper for read and write.Angus Gratton2024-09-26
| | | | | | | | | | | - Code size saving as all of these functions are very similar. - Resolves the "TODO" of the plain read and write functions not propagating errors. An error in the underlying block device now causes VFatFs to return EIO, for example. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* extmod/vfs_blockdev: Check block device function positive results.Angus Gratton2024-09-26
| | | | | | | | | | | | A positive result here can result in eventual memory corruption as littlefs expects the result of a cache read/write function to be 0 or a negative integer for an error. Closes #13046 This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* tests/extmod/machine_uart_irq_txidle.py: Simplify the test script.robert-hh2024-09-06
| | | | | | Now that no minimal delay time is required for SAMD devices. Signed-off-by: robert-hh <robert@hammelrath.com>
* tests/extmod: Add test for machine.UART.IRQ_TXIDLE.Damien George2024-08-29
| | | | | | | | | | | | | | The test checks whether the message created by the IRQ handler appears about at the end of the data sent by UART. Supported MCUs resp. boards: - RP2040 - Teensy 4.x - Adafruit ItsyBitsy M0 - Adafruit ItsyBitsy M4 - NRF52 (Arduino Nano Connect 33 BLE) Signed-off-by: Damien George <damien@micropython.org>
* test/extmod: Fix machine_spi_rate test on ESP32-C3.Angus Gratton2024-08-14
| | | | | | | Update to the test added in 1e98c4cb75bf3015d816455fc46ba28d5bcd9275, changes the SPI pins for ESP32-C3 (IO 18 and 19 are the native USB pins). Signed-off-by: Angus Gratton <angus@redyak.com.au>
* tests/extmod/ssl_keycert.py: Add test for PKCS8 formatted DER key.Peter Züger2024-08-13
| | | | Signed-off-by: Peter Züger <zueger.peter@icloud.com>
* tests/extmod: Add machine_spi_rate test.Angus Gratton2024-08-07
| | | | | | | | | | | Based on machine_i2s_rate, allows testing basic SPI functionality and timings. Implemented and confirmed working for rp2, esp32, and pyboard. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* tests/extmod: Rename machine_timer exp file to machine_soft_timer.Damien George2024-08-07
| | | | | | This was missed in 9ba04cc7563ec934ca14d66aa18ae3563c8d1aea Signed-off-by: Damien George <damien@micropython.org>