summaryrefslogtreecommitdiff
path: root/tests
AgeCommit message (Collapse)Author
2023-10-30tests/extmod/asyncio_as_uasyncio.py: Fix qstr order dependency.Jim Mussared
This test depends on the order in which qstrs are stored in ROM, which affects the order in which `dir()` will probe the object to see what it supports. Because of the lazy-loading in asyncio/__init__.py, if it tries to do e.g. `wait_for_ms` before `funcs` then it will import funcs, making `funcs` later succeed. But in the other way around, `funcs` will initially not be found. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-10-27tests/perf_bench: Add string/qstr/map tests.Jim Mussared
These tests are designed to measure changes in performance relating to: - string interning / searching for existing strings - map lookup - string operations - string hashing This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-10-19extmod/vfs_posix: Additional tests for coverage of error cases.Christian Walther
Signed-off-by: Christian Walther <cwalther@gmx.ch>
2023-10-19extmod/vfs_posix: Fix getcwd() on non-root VFS.Christian Walther
The unwritten API contract expected of a VFS.getcwd() by mp_vfs_getcwd() is that its return value should be either "" or "/" when the CWD is at the root of the VFS and otherwise start with a slash and not end with a slash. This was not correctly implemented in VfsPosix for instances with a non-empty root - the required leading slash, if any, was cut off because the root length includes a trailing slash. This would result in missing slashes in the middle of the return value of os.getcwd() or in uninitialized garbage from beyond a string's null terminator when the CWD was at the VFS root. Signed-off-by: Christian Walther <cwalther@gmx.ch>
2023-10-19extmod/vfs_posix: Fix relative paths on non-root VFS.Christian Walther
The unwritten API contract expected of a VFS by mp_vfs_lookup_path() is that paths passed in are relative to the root of the VFS if they start with '/' and relative to the current directory of the VFS otherwise. This was not correctly implemented in VfsPosix for instances with a non-empty root - all paths were interpreted relative to the root. Fix that. Since VfsPosix tracks its CWD using the "external" CWD of the Unix process, the correct handling for relative paths is to pass them through unmodified. Also, when concatenating absolute paths, fix an off-by-one resulting in a harmless double slash (the root path already has a trailing slash). Signed-off-by: Christian Walther <cwalther@gmx.ch>
2023-10-19extmod/vfs_posix: Fix accidentally passing tests.Christian Walther
These tests test an unrealistic situation and only pass by accident due to a bug. The upcoming fix for the bug would make them fail. The unrealistic situation is that VfsPosix methods are called with relative paths while the current working directory is somewhere outside of the root of the VFS. In the intended use of VFS objects via os.mount() (as opposed to calling methods directly as the tests do), this never happens, as mp_vfs_lookup_path() directs incoming calls to the VFS that contains the CWD. Make the testing situation realistic by changing the working directory to the root of the VFS before calling methods on it, as the subsequent relative path accesses expect. Thanks to the preceding commit, the tests still pass, but still for the wrong reason. The following commit "Fix relative paths on non-root VFS" will make them pass for the correct reason. Signed-off-by: Christian Walther <cwalther@gmx.ch>
2023-10-19extmod/vfs_posix: Fix relative root path.Christian Walther
A VfsPosix created with a relative root path would get confused when chdir() was called on it and become unable to properly resolve absolute paths, because changing directories effectively shifted its root. The simplest fix for that would be to say "don't do that", but since the unit tests themselves do it, fix it by making a relative path absolute before storing it. Signed-off-by: Christian Walther <cwalther@gmx.ch>
2023-10-16extmod/modframebuf: Remove FrameBuffer1 from natmod build.Jim Mussared
This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-10-16extmod/modframebuf: Fix FrameBuffer get-buffer implementation.Jim Mussared
This wasn't correctly accounting for the bits-per-pixel and was returning a bufinfo struct with the incorrect length. Instead, just forward directly to the underlying buffer object. Fixes issue #12563. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-10-16extmod/modframebuf: Validate FrameBuffer bounds against input buffer.Jim Mussared
This ensures that the buffer is large enough for the specified width, height, bits-per-pixel, and stride. Also makes the legacy FrameBuffer1 constructor re-use the FrameBuffer make_new to save some code size. Fixes issue #12562. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-10-16py/persistentcode: Bump .mpy sub-version.Damien George
This is required because the previous commit changed the .mpy native ABI. Signed-off-by: Damien George <damien@micropython.org>
2023-10-13py/objboundmeth: Optimise check for types in binary_op.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2023-10-13tests/basics/boundmeth1.py: Add tests for bound method equality/hash.Ned Konz
This commit adds tests for bound method comparison and hashing to support the changes in the previous commit. Signed-off-by: Ned Konz <ned@productcreationstudio.com>
2023-10-12extmod/moductypes: Validate that uctypes.struct addr argument is an int.Damien George
Fixes issue #12660. Signed-off-by: Damien George <damien@micropython.org>
2023-10-12py/builtinevex: Handle invalid filenames for execfile.Jim Mussared
If a non-string buffer was passed to execfile, then it would be passed as a non-null-terminated char* to mp_lexer_new_from_file. This changes mp_lexer_new_from_file to take a qstr instead (as in almost all cases a qstr will be created from this input anyway to set the `__file__` attribute on the module). This now makes execfile require a string (not generic buffer) argument, which is probably a good fix to make anyway. Fixes issue #12522. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-10-09py/vm: Don't emit warning when using "raise ... from None".Matthias Urlichs
"Raise SomeException() from None" is a common Python idiom to suppress chained exceptions and thus shouldn't trigger a warning on a version of Python that doesn't support them in the first place.
2023-10-02extmod/asyncio/stream.py: Fix cancellation handling of start_server.Jim Mussared
The following code: server = await asyncio.start_server(...) async with server: ... code that raises ... would lose the original exception because the server's task would not have had a chance to be scheduled yet, and so awaiting the task in wait_closed would raise the cancellation instead of the original exception. Additionally, ensures that explicitly cancelling the parent task delivers the cancellation correctly (previously was masked by the server loop), now this only happens if the server was closed, not when the task was cancelled. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-09-29tests/extmod/asyncio_threadsafeflag.py: Update for unix select.Jim Mussared
1. Remove the skip for detecting support for polling user-defined objects as this is always possible now on all ports. 2. Don't print when the scheduled task runs as the ordering of this relative to the other prints is dependent on other factors (e.g. if using the native emitter). This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-09-29tests/multi_net/ssl_cert_rsa.py: Update test certificate.Carlosgg
Update expired certificate, increase time validity period to five years and fix command arguments typos in commentaries. Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
2023-09-29tests/run-internalbench.py: Remove old CPython reference.Angus Gratton
At one point it was possible to internal_bench CPython vs MicroPython, but seemingly not any more. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-09-29tests/README: Document ./run-internalbench.py.Angus Gratton
Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-09-29tests/extmod/vfs_fat_finaliser.py: Tweak test so files are collected.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2023-09-29tests/float/math_domain.py: Tweak test to also pass with obj-repr-C.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2023-09-29tests/extmod/ssl_cadata.py: Skip test on axtls.Damien George
The axtls bindings don't support this. Signed-off-by: Damien George <damien@micropython.org>
2023-09-29tests/extmod/deflate_decompress.py: Skip test when not enough memory.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2023-09-29tests/float/float_format_ints.py: Put power-of-10 test in separate file.Damien George
This test doesn't pass on builds with 30-bit floats (object repr C). Signed-off-by: Damien George <damien@micropython.org>
2023-09-29tests/stress/bytecode_limit.py: Reverse order of cases.Jim Mussared
The PYBD_SF2 is right on the limit of being able to run this test and so it succeeds the first two cases and fails the next two with MemoryError. This causes it to SKIP, but that only works if it's the first thing printed. So reverse the order of the tests so it fails on the biggest one first. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-09-14py/persistentcode: Always close reader even if an exception is raised.Damien George
Fixes issue #3874. Signed-off-by: Damien George <damien@micropython.org>
2023-09-14py/parse: Always free lexer even if an exception is raised.Damien George
Fixes issue #3843. Signed-off-by: Damien George <damien@micropython.org>
2023-09-06tests/multi_net: Increase asyncio tests timeouts.iabdalkader
Increase asyncio tests timeouts to account for different WiFi modules and CPU clocks on different boards. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-09-03py/modthread: Return thread id from start_new_thread().David Lechner
In CPython, `_thread.start_new_thread()` returns an ID that is the same ID that is returned by `_thread.get_ident()`. The current MicroPython implementation of `_thread.start_new_thread()` always returns `None`. This modifies the required functions to return a value. The native thread id is returned since this can be used for interop with other functions, for example, `pthread_kill()` on *nix. `_thread.get_ident()` is also modified to return the native thread id so that the values match and avoids the need for a separate `native_id` attribute. Fixes issue #12153. Signed-off-by: David Lechner <david@pybricks.com>
2023-09-01extmod/vfs_posix_file: Implement sys.std*.buffer objects.stephanelsmith
Add the buffer attribute to sys.stdin, sys.stdout and sys.stderr. This provides raw access to underlying stdio streams for the unix port (and others that use VfsPosix). Signed-off-by: stephanelsmith <stephane.smith@titansensor.com>
2023-09-01tests/run-tests.py: Capture output of stderr when running on CPython.stephanelsmith
Signed-off-by: stephanelsmith <stephane.smith@titansensor.com>
2023-09-01py/dynruntime.h: Implement MP_OBJ_NEW_QSTR.Jim Mussared
Because mpy_ld.py doesn't know the target object representation, it emits instances of `MP_OBJ_NEW_QSTR(MP_QSTR_Foo)` as const string objects, rather than qstrs. However this doesn't work for map keys (e.g. for a locals dict) because the map has all_keys_are_qstrs flag is set (and also auto-complete requires the map keys to be qstrs). Instead, emit them as regular qstrs, and make a functioning MP_OBJ_NEW_QSTR function available (via `native_to_obj`, also used for e.g. making integers). Remove the code from mpy_ld.py to emit qstrs as constant strings, but leave behind the scaffold to emit constant objects in case we want to do use this in the future. Strictly this should be a .mpy sub-version bump, even though the function table isn't changing, it does lead to a change in behavior for a new .mpy running against old MicroPython. `mp_native_to_obj` will incorrectly return the qstr value directly as an `mp_obj_t`, leading to unexpected results. But given that it's broken at the moment, it seems unlikely that anyone is relying on this, so it's not work the other downsides of a sub-version bump (i.e. breaking pure-Python modules that use @native). The opposite case of running an old .mpy on new MicroPython is unchanged, and remains broken in exactly the same way. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-09-01py/modstruct: Support pad bytes in struct format.Daniël van de Giessen
This adds support for the x format code in struct.pack and struct.unpack. The primary use case for this is ignoring bytes while unpacking. When interfacing with existing systems, it may often happen that you either have fields in a struct that aren't properly specified or you simply don't care about them. Being able to easily skip them is useful. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2023-09-01py/objstr: Fix `str % {}` edge case.mcskatkat
Eliminate `TypeError` when format string contains no named conversions. This matches CPython behavior. Signed-off-by: mcskatkat <mc_skatkat@hotmail.com>
2023-09-01tests/unix/mod_os: Make os.system() test work on windows.stijn
The "true" command by default is unavailable on windows so use an equivalent which works on both unix and windows. Signed-off-by: stijn <stijn@ignitron.net>
2023-08-30py/profile: Remove the requirement to disable MICROPY_COMP_CONST.Jim Mussared
The only reason that const had to be disabled was to make the test output match CPython when const was involved. Instead, this commit fixes the test to handle the lines where const is used. Also: - remove the special handling for MICROPY_PERSISTENT_CODE_SAVE in unix/mpconfigport.h, and make this automatic. - move the check for MICROPY_PERSISTENT_CODE_SAVE to where it's used (like we do for other similar checks) and add a comment explaining it. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-30tests/misc/sys_settrace_features.py: Fix to run on newer CPython.Jim Mussared
This test was failing on CPython 3.11 as it now emits `0` as the line number for the "call" event corresponding to import, where as in 3.6 it had `1` as the line number. We maintain the old behavior, but in order to make this test pass on both CPython versions, the trace handler now converts the `0` to a `1`. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-15tests/extmod/select_poll_eintr.py: Improve robustness of test.Damien George
Increase allowed range of dt_ms, and print it in case of failure. Signed-off-by: Damien George <damien@micropython.org>
2023-08-14extmod/modselect: Properly track number of poll objects that are fd's.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2023-08-09extmod/modssl_mbedtls: Fix ioctl of a socket in closed/error state.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2023-08-09extmod/modssl_mbedtls: Reject ioctls that are not supported.Damien George
An SSL stream can only handle CLOSE and POLL ioctls. Other ones do not make sense, or at least it doesn't make sense to pass the ioctl request directly down to the underlying stream. In particular MP_STREAM_GET_FILENO should not be passed to the underlying stream because the SSL stream is not directly related to a file descriptor, and the SSL stream must handle the polling itself. Signed-off-by: Damien George <damien@micropython.org>
2023-08-07tests/extmod: Skip select/socket tests if they can't create UDP socket.Damien George
Some targets (eg PYBV10) have the socket module but are unable to create UDP sockets without a registered NIC. So skip UDP tests on these targets. Signed-off-by: Damien George <damien@micropython.org>
2023-08-07tests/extmod: Add coverage tests for select module.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2023-07-24py/mpconfig: Add MICROPY_PY_PLATFORM, enabled at extra features level.Jim Mussared
Previously this was explicitly enabled on esp32/stm32/renesas/mimxrt/samd, but didn't get a default feature level because it wasn't in py/mpconfig.h. With this commit it's now enabled at the "extra features" level, which adds rp2, unix-standard, windows, esp8266, webassembly, and some nrf boards. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21examples/natmod/deflate: Add deflate as a dynamic native module.Jim Mussared
This replaces the previous zlib version. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21tests/extmod: Add deflate.DeflateIO tests.Jim Mussared
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21extmod/moddeflate: Add deflate module providing the DeflateIO class.Jim Mussared
This provides similar functionality to the former zlib.DecompIO and especially CPython's gzip.GzipFile for both compression and decompression. This class can be used directly, and also can be used from Python to implement (via io.BytesIO) zlib.decompress and zlib.compress, as well as gzip.GzipFile. Enable/disable this on all ports/boards that zlib was previously configured for. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21all: Remove the zlib module.Jim Mussared
This will be replaced with a new deflate module providing the same functionality, with an optional frozen Python wrapper providing a replacement zlib module. binascii.crc32 is temporarily disabled. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>