summaryrefslogtreecommitdiff
path: root/tests
AgeCommit message (Collapse)Author
2024-06-20webassembly/asyncio: Schedule run loop when tasks are pushed to queue.Damien George
In the webassembly port there is no asyncio run loop running at the top level. Instead the Python asyncio run loop is scheduled through setTimeout and run by the outer JavaScript event loop. Because tasks can become runable from an external (to Python) event (eg a JavaScript callback), the run loop must be scheduled whenever a task is pushed to the asyncio task queue, otherwise tasks may be waiting forever on the queue. Signed-off-by: Damien George <damien@micropython.org>
2024-06-18webassembly/asyncio: Support top-level await of asyncio Task and Event.Damien George
This change allows doing a top-level await on an asyncio primitive like Task and Event. This feature enables a better interaction and synchronisation between JavaScript and Python, because `api.runPythonAsync` can now be used (called from JavaScript) to await on the completion of asyncio primitives. Signed-off-by: Damien George <damien@micropython.org>
2024-06-18webassembly/objjsproxy: Implement proxying of JS iterable protocol.Damien George
This allows Python to iterate over JavaScript objects that provide Symbol.iterator. Signed-off-by: Damien George <damien@micropython.org>
2024-06-17qemu-riscv: Add new QEMU RV32 port.Alessandro Gatti
This adds a QEMU-based bare metal RISC-V 32 bits port. For the time being only QEMU's "virt" 32 bits board is supported, using the ilp32 ABI and the RV32IMC architecture. The top-level README and the run-tests.py files are updated for this new port. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-06-08extmod/modlwip: Make socket.connect raise ETIMEDOUT on non-zero timeout.Damien George
If the socket timeout is 0 then a failed socket.connect() raises EINPROGRESS (which is what the lwIP bindings already did), but if the socket timeout is non-zero then a failed socket.connect() should raise ETIMEDOUT. The latter is fixed in this commit. A test is added for these timeout cases. Signed-off-by: Damien George <damien@micropython.org>
2024-06-06py/lexer: Support raw f-strings.Damien George
Support for raw str/bytes already exists, and extending that to raw f-strings is easy. It also reduces code size because it eliminates an error message. Signed-off-by: Damien George <damien@micropython.org>
2024-06-06py/lexer: Support concatenation of adjacent f-strings.Damien George
This is quite a simple and small change to support concatenation of adjacent f-strings, and improve compatibility with CPython. Signed-off-by: Damien George <damien@micropython.org>
2024-05-28tests/basics: Move str/bytes tests that give SyntaxWarning to sep file.Damien George
In CPython 3.12 these invalid str/bytes/fstring escapes will issue a SyntaxWarning, and so differ to MicroPython. Signed-off-by: Damien George <damien@micropython.org>
2024-05-28tests/basics: Add .exp file for slice_op test.Damien George
CPython 3.12 implemented hashing for slices, so now differs to MicroPython. Signed-off-by: Damien George <damien@micropython.org>
2024-05-28tests/float: Use "not" instead of ~ to invert bool value.Damien George
Otherwise CPython gives a deprecation warning. This test is not actually testing inversion of bools, rather that bit of the test is used to compute the pass/fail result. Signed-off-by: Damien George <damien@micropython.org>
2024-05-27tests/net_inet/tls_text_errors.py: Tweak test for newer CPython version.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-05-27tests/net_hosted/ssl_verify_callback.py: Make exp match actual output.Damien George
The `cert` argument passed to the verify callback is actually a memoryview. And the `depth` argument seems to start at 1 for the tested URL. Signed-off-by: Damien George <damien@micropython.org>
2024-05-27tests/basics: Split out generator.throw tests that pass multiple args.Damien George
The three-argument form of `.throw()` is deprecated since CPython 3.12. So split out into separate tests (with .exp files) the parts of the generator tests that test more than one argument. Signed-off-by: Damien George <damien@micropython.org>
2024-05-27tests/extmod: Add .exp test files for asyncio.get_event_loop tests.Damien George
And use `asyncio.new_event_loop()` where possible. This change is needed because CPython 3.12 deprecated the `get_event_loop()` function. Signed-off-by: Damien George <damien@micropython.org>
2024-05-27tests/extmod: Fix regex strings to be of r"" type.Damien George
Otherwise escape characters like \s and \W won't work correctly. Signed-off-by: Damien George <damien@micropython.org>
2024-05-27tests/run-natmodtests.py: Fix search for supported native tests.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-05-24py/dynruntime: Export mp_load_method_maybe and mp_arg_parse_all* funcs.Brian Pugh
Also define `mp_type_bytearray`. These all help to write native modules. Signed-off-by: Brian Pugh <bnp117@gmail.com> Signed-off-by: Damien George <damien@micropython.org>
2024-05-16webassembly/proxy_c: Return undefined if dict lookup failed on JS side.Damien George
Instead of raising KeyError. These semantics match JavaScript behaviour and make it much more seamless to pass Python dicts through to JavaScript as though they were JavaScript {} objects. Signed-off-by: Damien George <damien@micropython.org>
2024-05-16webassembly/proxy_js: Create a special "undefined" type for Python.Damien George
This adds a new undefined singleton to Python, that corresponds directly to JavaScript `undefined`. It's accessible via `js.undefined`. Signed-off-by: Damien George <damien@micropython.org>
2024-05-16webassembly/proxy_js: Revert back to converting Py None to JS null.Damien George
This reverts part of commit fa23e4b093f81f03a24187c7ea0c928a9b4a661b, to make it so that Python `None` converts to JavaScript `null` (and JavaScript `null` already converts to Python `None`). That's consistent with how the `json` module converts these values back and forth. Signed-off-by: Damien George <damien@micropython.org>
2024-05-14tests/micropython/import_mpy_invalid.py: Skip if target cant import mpy.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-05-14webassembly/mpconfigport: Enable importing of .mpy files.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-05-13webassembly/proxy_js: Convert JS undefined and JS null to Py None.Damien George
And change Py None conversion so it converts to JS undefined. The semantics for conversion of these objects are then: - Python None -> JavaScript undefined - JavaScript undefined -> Python None - JavaScript null -> Python None This follows Pyodide: https://pyodide.org/en/stable/usage/type-conversions.html Signed-off-by: Damien George <damien@micropython.org>
2024-05-13webassembly/proxy_c: Ensure objs thrown into generators are exceptions.Damien George
This commit defines a new `JsException` exception type which is used on the Python side to wrap JavaScript errors. That's then used when a JavaScript Promise is rejected, and the reason is then converted to a `JsException` for the Python side to handle. This new exception is exposed as `jsffi.JsException`. Signed-off-by: Damien George <damien@micropython.org>
2024-05-13webassembly/asyncio: Fix case where a Promise is resolved with no arg.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-05-07webassembly/api: Resolve thenables returned from runPythonAsync.Damien George
JavaScript semantics are such that the caller of an async function does not need to await that function for it to run to completion. This commit makes that behaviour also apply to top-level async Python code run via `runPythonAsync()`. Signed-off-by: Damien George <damien@micropython.org>
2024-05-07webassembly/objpyproxy: Implement JS iterator protocol for Py iterables.Damien George
This allows using JavaScript for..of on Python iterables. Signed-off-by: Damien George <damien@micropython.org>
2024-05-06webassembly/proxy_c: Reject promises with a PythonError instance.Damien George
The `reason` in a rejected promise should be an instance of `Error`. That leads to better error messages on the JavaScript side. Signed-off-by: Damien George <damien@micropython.org>
2024-04-24webassembly: Add JavaScript-based asyncio support.Damien George
This commit adds a significant portion of the existing MicroPython asyncio module to the webassembly port, using parts of the existing asyncio code and some custom JavaScript parts. The key difference to the standard asyncio is that this version uses the JavaScript runtime to do the actual scheduling and waiting on events, eg Promise fulfillment, timeouts, fetching URLs. This implementation does not include asyncio.run(). Instead one just uses asyncio.create_task(..) to start tasks and then returns to the JavaScript. Then JavaScript will run the tasks. The implementation here tries to reuse as much existing asyncio code as possible, and gets all the semantics correct for things like cancellation and asyncio.wait_for. An alternative approach would reimplement Task, Event, etc using JavaScript Promise's. That approach is very difficult to get right when trying to implement cancellation (because it's not possible to cancel a JavaScript Promise). Signed-off-by: Damien George <damien@micropython.org>
2024-04-22tests/cpydiff: Add a note about risk of resizing memoryview targets.Angus Gratton
This a stop-gap until there is a proper fix for this. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-04-22py/objarray: Fix use-after-free if extending a bytearray from itself.Angus Gratton
Two cases, one assigning to a slice. Closes https://github.com/micropython/micropython/issues/13283 Second is extending a slice from itself, similar logic. In both cases the problem occurs when m_renew causes realloc to move the buffer, leaving a dangling pointer behind. There are more complex and hard to fix cases when either argument is a memoryview into the buffer, currently resizing to a new address breaks memoryviews into that object. Reproducing this bug and confirming the fix was done by running the unix port under valgrind with GC-aware extensions. Note in default configurations with GIL this bug exists but has no impact (the free buffer won't be reused while the function is still executing, and is no longer referenced after it returns). Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-03-30webassembly/proxy_js: Allow a Python proxy of a function to be undone.Damien George
This optimises the case where a Python function is, for example, stored to a JavaScript attribute and then later retrieved from Python. The Python function no longer needs to be a proxy with double proxying needed for the call from Python -> JavaScript -> Python. Signed-off-by: Damien George <damien@micropython.org>
2024-03-30webassembly/proxy_js: Promote Python thenable to a Promise.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-03-30webassembly/proxy_c: Ensure return value of async fun is passed to JS.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-03-29tests/net_inet: Add simpler tls sites test, and skip existing on axtls.Damien George
Ports that use axtls cannot run the `test_tls_sites.py` test because the sites it connects to use advanced ciphers. So skip this test on such ports, and add a new, simpler test that doesn't require certificate verification and works with axtls. Signed-off-by: Damien George <damien@micropython.org>
2024-03-28py/persistentcode: Bump .mpy sub-version to 6.3.Damien George
This is required because the .mpy native ABI was changed by the introduction of `mp_proto_fun_t`, see commits: - 416465d81e911b088836f4e7c37fac2bc0f67917 - 5e3006f1172d0eabbbefeb3268dfb942ec7cf9cd - e2ff00e81113d7a3f32f860652017644b5d68bf1 And three `mp_binary` functions were added to `mp_fun_table` in commit d2276f0d41c2fa66a224725fdb2411846c91cf1a. Signed-off-by: Damien George <damien@micropython.org>
2024-03-22tests/ports/webassembly: Add webassembly JS tests.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-03-22tests/run-tests.py: Support running webassembly tests via node.Damien George
This allows running tests with a .js/.mjs suffix, and also .py tests using node and the webassembly port. Signed-off-by: Damien George <damien@micropython.org>
2024-03-20tests/float/float_struct_e.py: Add specific test for struct 'e' type.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-03-20py/binary: Support half-float 'e' format in struct pack/unpack.Matthias Urlichs
This commit implements the 'e' half-float format: 10-bit mantissa, 5-bit exponent. It uses native _Float16 if supported by the compiler, otherwise uses custom bitshifting encoding/decoding routines. Signed-off-by: Matthias Urlichs <matthias@urlichs.de> Signed-off-by: Damien George <damien@micropython.org>
2024-03-19py/emitnative: Implement viper unary ops positive, negative and invert.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-03-19tests/basics: Split MicroPython-specific deque tests to separate file.Damien George
So that the MicroPython-specific behaviour can be isolated, and the CPython compatible test don't need a .exp file. Signed-off-by: Damien George <damien@micropython.org>
2024-03-18py/objdeque: Expand implementation to be doubly-ended and support iter.Dash Peters
Add `pop()`, `appendleft()`, and `extend()` methods, support iteration and indexing, and initializing from an existing sequence. Iteration and indexing (subscription) have independent configuration flags to enable them. They are enabled by default at the same level that collections.deque is enabled (the extra features level). Also add tests for checking new behavior. Signed-off-by: Damien George <damien@micropython.org>
2024-03-08stm32/dma: Add D-cache protection for DMA RX operations, including SPI.Angus Gratton
This new DMA API corrects possible cache coherency issues on chips with D-Cache, when working with buffers at arbitrary memory locations (i.e. supplied by Python code). The API is used by SPI to fix an issue with corrupt data when reading from SPI using DMA in certain cases. A regression test is included (it depends on external hardware connection). Explanation: 1) It's necessary to invalidate D-Cache after a DMA RX operation completes in case the CPU reads (or speculatively reads) from the DMA RX region during the operation. This seems to have been the root cause of issue #13471 (only when src==dest for this case). 2) More generally, it is also necessary to temporarily mark the first and last cache lines of a DMA RX operation as "uncached", in case the DMA buffer shares this cache line with unrelated data. The CPU could otherwise write the other data at any time during the DMA operation (for example from an interrupt handler), creating a dirty cache line that's inconsistent with the DMA result. Fixes issue #13471. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-03-07all: Prune trailing whitespace.Phil Howard
Prune trailing whitespace across the whole project (almost), done automatically with: grep -IUrl --color "[[:blank:]]$" --exclude-dir=.git --exclude=*.exp |\ xargs sed -i 's/[[:space:]]*$//' Exceptions: - Skip third-party code in lib/ and drivers/cc3100/ - Skip generated code in bluetooth_init_cc2564C_1.5.c - Preserve command output whitespace in docs, eg: docs/esp8266/tutorial/repl.rst Signed-off-by: Phil Howard <phil@gadgetoid.com>
2024-02-29tests/multi_bluetooth: Move ble_deepsleep to stress_deepsleep_reconnect.Damien George
This test cannot run on boards that have a native USB REPL, so rename it to indicate that its "special". This makes it easier to run a subset of tests, for example: ./run-multitests.py multi_bluetooth/ble*.py ./run-multitests.py multi_bluetooth/perf*.py ./run-multitests.py multi_bluetooth/stress*.py Signed-off-by: Damien George <damien@micropython.org>
2024-02-28extmod/asyncio: Make current_task raise exception when there is no task.Damien George
Matches CPython behaviour. Fixes issue #11530. Signed-off-by: Damien George <damien@micropython.org>
2024-02-26extmod/modwebsocket: Fix websocket to send correct close frame.Felix Dörre
When the websocket closes currently, it does not send a proper "close"-frame, but rather encodes the 0x8800-sequence inside a binary packet, which is wrong. The close packet is a different kind of websocket frame, according to https://www.rfc-editor.org/rfc/rfc6455. This change resolves an error in Firefox when the websocket closes. Signed-off-by: Felix Dörre <felix@dogcraft.de>
2024-02-21tests/cpydiff: Add new CPy diff test for class name mangling.Trent Warlaven
Adds new tests/documentation for missing name mangling for private class members. Signed-off-by: Trent Warlaven <trwbox@gmail.com>
2024-02-20py/builtinevex: Fix setting globals for native functions in compile().Damien George
Signed-off-by: Damien George <damien@micropython.org>