summaryrefslogtreecommitdiffstatshomepage
path: root/tests
Commit message (Collapse)AuthorAge
* tests/extmod/vfs_posix.py: Fix test on Android.Alessandro Gatti8 days
| | | | | | | | | | | | | | | | | | | | | | 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 George8 days
| | | | Signed-off-by: Damien George <damien@micropython.org>
* tests/extmod/vfs_lfs_ilistdir_del.py: Skip test if not enough memory.Damien George8 days
| | | | Signed-off-by: Damien George <damien@micropython.org>
* tests/extmod: Skip binascii tests when hexlify/unhexlify don't exist.Damien George8 days
| | | | | | | These functions are only available when `MICROPY_PY_BUILTINS_BYTES_HEX` is enabled. Signed-off-by: Damien George <damien@micropython.org>
* py/objstr: Fix handling of OP_MODULO with namedtuple.Yoctopuce dev11 days
| | | | | | | | | 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>
* tests/basics/builtin_range.py: Add more tests for range slicing.Jeff Epler11 days
| | | | Signed-off-by: Jeff Epler <jepler@gmail.com>
* tests: Update UART and SPI tests to work on Alif boards.Damien George2025-04-09
| | | | Signed-off-by: Damien George <damien@micropython.org>
* tests/ports/alif_hardware: Add flash testing script.Damien George2025-04-09
| | | | | | | 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>
* tests/cpydiff: Remove types_str_endswith.Angus Gratton2025-04-07
| | | | | | | | 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>
* tests/cpydiff: Update CPy diff for assign expr in nested comprehensions.Angus Gratton2025-04-07
| | | | | | | | | 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>
* 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>
* tests/cpydiff: Remove builtin_next_arg2.py difference.Damien George2025-03-27
| | | | | | | Because 2-arg `next()` is implemented, and now enabled at the basic feature level. Signed-off-by: Damien George <damien@micropython.org>
* tests/multi_pyb_can: Add multitests for pyboard CAN controller.Angus Gratton2025-03-14
| | | | | | | 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>
* py/modsys: Add sys.implementation._build entry.Damien George2025-03-05
| | | | | | | | | | | | | | | | | | | 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>
* test/run-tests: Print a note if it looks like unittest.main() missing.Angus Gratton2025-03-04
| | | | | | This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* tests/run-tests: Remove any 'expected' file from a unittest run.Angus Gratton2025-03-04
| | | | | | | | | | 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>
* py/objstr: Support tuples and start/end args in startswith and endswith.Glenn Moloney2025-03-02
| | | | | | | | | | | | | | 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>
* py/parsenum: Reduce code footprint of mp_parse_num_float.Yoctopuce dev2025-02-28
| | | | | | | | | | | | | 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>
* 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>
* tests: Four typos in tests directory.Christian Clauss2025-02-25
| | | | | | Found by codespell. Signed-off-by: Christian Clauss <cclauss@me.com>
* all: Upgrade to ruff v0.9.6.Christian Clauss2025-02-25
| | | | Signed-off-by: Christian Clauss <cclauss@me.com>
* tests/multi_net: Add test for DTLS server and client.Damien George2025-02-14
| | | | | | | | | | | | | 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>
* 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>
* py/objfun: Implement function.__code__ and function constructor.Damien George2025-02-11
| | | | | | | | | | | 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>
* tests/run-tests.py: Give more information when CPython crashes.Damien George2025-02-11
| | | | | | To make it easier to diagnose why CPython crashed. Signed-off-by: Damien George <damien@micropython.org>
* tests/run-natmodtests.py: Autodetect the test target architecture.Alessandro Gatti2025-02-07
| | | | | | | | | | | | | 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>
* tests/multi_wlan: Remove esp8266 port workaround.Angus Gratton2025-02-07
| | | | | | Not needed due to parent commit. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* rp2/rp2_flash: Workaround multicore lockout not being reset.Mike Bell2025-02-07
| | | | | | | | | With regression test. See upstream bug https://github.com/raspberrypi/pico-sdk/issues/2201 Tested-by: Angus Gratton <angus@redyak.com.au> Signed-off-by: Mike Bell <mdb036@gmail.com>
* tests/ports/rp2: Add test for SLEEP_ENx registers over lightsleep.Damien George2025-02-07
| | | | 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>
* py/parsenum: Throw an exception for invalid int literals like "01".Jeff Epler2025-01-26
| | | | | | | | | | | | | | | This includes making int("01") parse in base 10 like standard Python. When a base of 0 is specified it means auto-detect based on the prefix, and literals begining with 0 (except when the literal is all 0's) like "01" are then invalid and now throw an exception. The new error message is different from CPython. It says e.g., `SyntaxError: invalid syntax for integer with base 0: '09'` Additional test cases were added to cover the changed & added code. Co-authored-by: Damien George <damien@micropython.org> Signed-off-by: Jeff Epler <jepler@gmail.com>
* tests/basics/nanbox_smallint.py: Fix incorrect use of int() in test.Jeff Epler2025-01-26
| | | | | | | The literal is in base 16 but int()'s default radix in CPython is 10, not 0. Signed-off-by: Jeff Epler <jepler@gmail.com>
* 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/multi_net: Update TLS test certificates and keys.Damien George2025-01-14
| | | | | | They expired in early January 2025. Signed-off-by: Damien George <damien@micropython.org>
* tests/README: Update TLS certificate generation instructions.Damien George2025-01-14
| | | | | | | Fix the command that converts `ec_key.pem` to `ec_key.der`, and increase the certificate validity to 10 years. Signed-off-by: Damien George <damien@micropython.org>
* 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/run-tests.py: Implement getcwd on __FS hook filesystem.Damien George2025-01-06
| | | | | | This method is needed by tests like `extmod/vfs_rom.py`. Signed-off-by: Damien George <damien@micropython.org>
* tests/run-tests.py: Set __main__ module to __injected_test.Damien George2025-01-06
| | | | | | | | | When using unittest (for example) with injected mpy files, not only does the name of the main test module need to be `__main__`, but also the `__main__` module should correspond to this injected module. Otherwise the unittest test won't be detected. Signed-off-by: Damien George <damien@micropython.org>
* tests/run-tests.py: Detect inlineasm support and add tests if needed.Alessandro Gatti2025-01-02
| | | | | | | | | | | | | This commit implements a method to detect at runtime if inline assembler support is enabled, and if so which platform it targets. This allows clean test runs even on modified version of ARM-based ports where inline assembler support is disabled, running inline assembler tests on ports that have such feature not enabled by default and manually enabled, and allows to always run the correct inlineasm tests for ports that support more than one architecture (esp32, qemu, rp2). Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* py/emitinlinerv32: Add inline assembler support for RV32.Alessandro Gatti2025-01-02
| | | | | | | | | | | | This commit adds support for writing inline assembler functions when targeting a RV32IMC processor. Given that this takes up a bit of rodata space due to its large instruction decoding table and its extensive error messages, it is enabled by default only on offline targets such as mpy-cross and the qemu port. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* tests/inlineasm: Make room for RV32IMC inline asm tests.Alessandro Gatti2025-01-01
| | | | | | | | Thumb/Thumb2 tests are now into their own subdirectory, as RV32IMC-specific tests will be added as part of the RV32 inline assembler support. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* 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: Fix all file ioctl's to support only MP_STREAM_CLOSE.Damien George2024-12-20
| | | | | | | | | | | | | | A return value of 0 from Python-level `ioctl()` means success, but if that's returned unconditionally it means that the method supports all ioctl calls, which is not true. Returning 0 without doing anything can potentially lead to a crash, eg for MP_STREAM_SEEK which requires returning a value in the passed-in struct pointer. This commit makes it so that all `ioctl()` methods respond only to MP_STREAM_CLOSE, ie they return -1 (indicating error) for all other ioctl calls. Signed-off-by: Damien George <damien@micropython.org>
* rp2/modmachine: Fix USB sleep on RP2350 MCUs.Peter Harper2024-12-19
| | | | Signed-off-by: Peter Harper <peter.harper@raspberrypi.com>
* tests/run-tests.py: Set name of injected test module to '__main__'.Damien George2024-12-19
| | | | | | | | | | Running unittest-based tests with --via-mpy is currently broken, because the unittest test needs the module to be named `__main__`, whereas it's actually called `__injected_test`. Fix this by changing the name when the file is opened. 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>