summaryrefslogtreecommitdiff
path: root/tests
AgeCommit message (Collapse)Author
2024-02-20py/objfun: Support __name__ on native functions and generators.Damien George
This is now easy to support, since the first machine-word of a native function tells how to find the prelude, from which the function name can be extracted in the same way as for bytecode. Signed-off-by: Damien George <damien@micropython.org>
2024-02-16tests/ports/unix: Add coverage test for frozen functions and generators.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-02-16tests/multi_bluetooth/ble_irq_calls.py: Enhance test to test recursion.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-02-12extmod/btstack: Reset pending_value_handle before calling read-done cb.Damien George
Similar to the previous commit but for MP_BLUETOOTH_IRQ_GATTC_READ_DONE: the pending_value_handle needs to be reset before calling mp_bluetooth_gattc_on_read_write_status(), which will call the Python IRQ handler, which may in turn call back into BTstack to perform an action like a write. In that case the pending_value_handle will need to be available for the write/read/etc to proceed. Fixes issue #13634. Signed-off-by: Damien George <damien@micropython.org>
2024-02-09extmod/btstack: Reset pending_value_handle before calling write-done cb.Damien George
The pending_value_handle needs to be freed and reset before calling mp_bluetooth_gattc_on_read_write_status(), which will call the Python IRQ handler, which may in turn call back into BTstack to perform an action like a write. In that case the pending_value_handle will need to be available for the write/read/etc to proceed. Fixes issue #13611. Signed-off-by: Damien George <damien@micropython.org>
2024-02-07tests: Use vfs module instead of os.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-02-07extmod/modvfs: Add new "vfs" module with mount/umount and Vfs classes.Damien George
They have been moved from the "os" module. Signed-off-by: Damien George <damien@micropython.org>
2024-02-07extmod/modtls_mbedtls: Implement cert verification callback for mbedtls.Felix Dörre
This is a useful alternative to .getpeercert() when the certificate is not stored to reduce RAM usage. Signed-off-by: Felix Dörre <felix@dogcraft.de>
2024-02-07extmod/modtls: Move the native ssl module to tls.Felix Dörre
The current `ssl` module has quite a few differences to the CPython implementation. This change moves the MicroPython variant to a new `tls` module and provides a wrapper module for `ssl` (in micropython-lib). Users who only rely on implemented comparible behavior can continue to use `ssl`, while users that rely on non-compatible behavior should switch to `tls`. Then we can make the facade in `ssl` more strictly adhere to CPython. Signed-off-by: Felix Dörre <felix@dogcraft.de>
2024-02-06github/workflows: Move Windows CI from AppVeyor to GitHub Actions.David Lechner
By moving to GitHub actions, all MicroPython CI builds are now on GitHub actions. This allows faster parallel builds and saves time by not building when no relevant files changed. This reveals a few failing tests, so those are temporarily disabled until they can be fixed. Signed-off-by: David Lechner <david@pybricks.com> Signed-off-by: Damien George <damien@micropython.org>
2024-01-31py/compile: Fix potential Py-stack overflow in try-finally with return.Damien George
If a return is executed within the try block of a try-finally then the return value is stored on the top of the Python stack during the execution of the finally block. In this case the Python stack is one larger than it normally would be in the finally block. Prior to this commit, the compiler was not taking this case into account and could have a Python stack overflow if the Python stack used by the finally block was more than that used elsewhere in the function. In such a scenario the last argument of the function would be clobbered by the top-most temporary value used in the deepest Python expression/statement. This commit fixes that case by making sure enough Python stack is allocated to the function. Fixes issue #13562. Signed-off-by: Damien George <damien@micropython.org>
2024-01-30tests/ports/rp2/rp2_dma.py: Tweak test to be more reliable.Damien George
The timing of the DMA transfer can vary a bit, so tweak the allowed values. Also test the return value of `rp2.DMA.irq.flags()` to make sure the IRQ is correctly signalled. Signed-off-by: Damien George <damien@micropython.org>
2024-01-30all: Update bindings, ports and tests for mbedtls v3.5.1.Carlosgg
Changes include: - Some mbedtls source files renamed or deprecated. - Our `mbedtls_config.h` files are renamed to `mbedtls_config_port.h`, so they don't clash with mbedtls's new default configuration file named `mbedtls_config.h`. - MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE is deprecated. - MBEDTLS_HAVE_TIME now requires an `mbedtls_ms_time` function to be defined but it's only used for TLSv1.3 (currently not enabled in MicroPython so there is a lazy implementation, i.e. seconds * 1000). - `tests/multi_net/ssl_data.py` is removed (due to deprecation of MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE), there are the existing `ssl_cert_rsa.py` and `sslcontext_server_client.py` tests which do very similar, simple SSL data transfer. - Tests now use an EC key by default (they are smaller and faster), and the RSA key has been regenerated due to the old PKCS encoding used by openssl rsa command, see https://stackoverflow.com/questions/40822328/openssl-rsa-key-pem-and-der-conversion-does-not-match (and `tests/README.md` has been updated accordingly). Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
2024-01-29extmod/modssl_mbedtls: Fix cipher iteration in SSLContext.get_ciphers.Damien George
Prior to this commit it would skip every second cipher returned from mbedtls. The corresponding test is also updated and now passes on esp32, rp2, stm32 and unix. Signed-off-by: Damien George <damien@micropython.org>
2024-01-29tests/extmod/framebuf_polygon.py: Replace sys.stdout.write with print.Damien George
So the test doesn't depend on the `sys` module. Signed-off-by: Damien George <damien@micropython.org>
2024-01-24tests/extmod: Remove asyncio .exp files that match CPython output.Damien George
These were added back in commit c4935f30490d0446e16a51dbf7a6397b771cf804 because the tests required CPython 3.8, which was quite new at the time. But CPython 3.8 was released over 4 years ago (October 2019) and the CI test runners, and developers, have this (or a more recent) CPython version. Removing the .exp files also helps keep MicroPython semantics the same as CPython. The asyncio_fair.py test it adjusted slightly to have more deterministic timing and output. Signed-off-by: Damien George <damien@micropython.org>
2024-01-23tests/extmod/asyncio_wait_task.py: Add test for raise and delayed wait.Damien George
This case was fixed in 2ecbad4e91192c88f831d8690dbad31ddba72135, which stored the exception in the task object. Signed-off-by: Damien George <damien@micropython.org>
2024-01-22extmod/asyncio: Support gather of tasks that finish early.Damien George
Adds support to asyncio.gather() for the case that one or more (or all) sub-tasks finish and/or raise an exception before the gather starts. Signed-off-by: Damien George <damien@micropython.org>
2024-01-22tests/extmod/machine_i2s_rate.py: Test multiple I2S instances.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-01-22tests/ports/rp2: Add rp2-specific tests with a test for rp2.DMA.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-01-22tests: Move port-specific test directories into tests/ports/ directory.Damien George
To keep them all together, mirroring the top-level directory structure. Signed-off-by: Damien George <damien@micropython.org>
2024-01-16tests/extmod/machine_uart_tx.py: Add a test for timing of UART.flush().robert-hh
Currently only runs on rp2 but could be extended to run on other targets. Signed-off-by: robert-hh <robert@hammelrath.com>
2024-01-10tests/run-tests.py: Fix path-based special test detection.stijn
Compare the full absolute path instead of relying on the path form passed by the user. For instance, this will make python3 run-tests.py -d basics python3 run-tests.py -d ./basics python3 run-tests.py -d ../tests/basics python3 run-tests.py -d /full/path/to/basics all behave the same by correctly treating the bytes_compare3 and builtin_help tests as special, whereas previously only the first invocation would do that and hence result in these tests to fail when called with a different path form. Signed-off-by: stijn <stijn@ignitron.net>
2024-01-10tests/run-tests.py: Make repl test detection more correct.stijn
Avoid unrelated tests which happen to have "repl_" anywhere in their path to be treated as repl tests. Signed-off-by: stijn <stijn@ignitron.net>
2024-01-10tests/run-tests.py: Remove unneeded argument from run_feature_check().stijn
In 405893af this was likely left as-is to minimize the diff, but it just complicates things. Signed-off-by: stijn <stijn@ignitron.net>
2024-01-05all: Fix "reuse" and "overridden" spelling mistakes.Damien George
Codespell doesn't pick up "re-used" or "re-uses", and ignores the tests/ directory, so fix these manually. Signed-off-by: Damien George <damien@micropython.org>
2024-01-05tests/run-tests.py: Add an option for running only the failed tests.stijn
Implement the typical 're-run the failed tests' most test runners have, for convenience. Accessible via the new --run-failures argument, and implemented using a json file containing a list of the failed tests. Signed-off-by: stijn <stijn@ignitron.net>
2024-01-05tests/multi_net: Generate smaller certs with 2048-bit RSA.Damien George
Otherwise running the tests can take a long time when the server is a slow target (RP2040 takes 23 seconds for a handshake when using 4096-bit RSA). Also add instructions on how to generate elliptic curve key/certs. Signed-off-by: Damien George <damien@micropython.org>
2024-01-05tests/run-multitests.py: Change to dir of test script when running it.Damien George
This matches the behaviour of run-tests.py, which sets cwd to the directory containing the test script, which helps to isolate the filesystem. It means that the SSL tests no longer need to know the name of their containing directory to find the certificate files, and helps to run these tests on bare-metal. Signed-off-by: Damien George <damien@micropython.org>
2024-01-05tests/thread: Add a test for accuracy of sleep within a thread.Damien George
The existing thread_sleep1.py test only tests execution, not accuracy, of time.sleep. Also the existing test only tests sleep(0) on targets like rp2 that can only create a single thread. The new test in this commit checks for timing accuracy on the main thread and one other thread when they run at the same time. Signed-off-by: Damien George <damien@micropython.org>
2024-01-05tests/thread: Adjust thread tests so most are able to run on rp2 port.Damien George
The aim of this commit is to make it so that the existing thread tests can be used to test the _thread module on the rp2 port. The rp2 port only allows up to one thread to be created at a time, and does not have the GIL enabled. The following changes have been made: - run-tests.py skips mutation tests on rp2, because there's no GIL. - run-tests.py skips other tests on rp2 that require more than one thread. - The tests stop trying to start a new thread after there is an OSError, which indicates that the system cannot create more threads. - Some of these tests also now run the test function on the main thread, not just the spawned threads. - In some tests the output printing is adjusted so it's the same regardless of how many threads were spawned. - Some time.sleep(1) are replaced with time.sleep(0) to make the tests run a little faster (finish sooner when the work is done). For the most part the tests are unchanged for existing platforms like esp32 and unix. Signed-off-by: Damien George <damien@micropython.org>
2024-01-04tests/run-tests.py: Remove machine_mem.py test from skip list.Damien George
This test was removed long ago in eb0e3bab1ed5aa09e491641f427a5d637fe688bd. Signed-off-by: Damien George <damien@micropython.org>
2023-12-21tools/ci.sh: Set `ulimit -n` for unix CI.Jim Mussared
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-12-21extmod/modselect: Handle growing the pollfds allocation correctly.Jim Mussared
The poll_obj_t instances have their pollfd field point into this allocation. So if re-allocating results in a move, we need to update the existing poll_obj_t's. Update the test to cover this case. Fixes issue #12887. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-12-15py/modsys: Implement optional sys.intern.stijn
Signed-off-by: stijn <stijn@ignitron.net>
2023-12-14extmod/asyncio: Add ssl support with SSLContext.Carlosgg
This adds asyncio ssl support with SSLContext and the corresponding tests in `tests/net_inet` and `tests/multi_net`. Note that not doing the handshake on connect will delegate the handshake to the following `mbedtls_ssl_read/write` calls. However if the handshake fails when a client certificate is required and not presented by the peer, it needs to be notified of this handshake error (otherwise it will hang until timeout if any). Finally at MicroPython side raise the proper mbedtls error code and message. Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
2023-12-12tests: Update SSL network tests to use SSLContext, and work on CPython.Damien George
Changes are: - use ssl.SSLContext.wrap_socket instead of ssl.wrap_socket - disable check_hostname and call load_default_certs() where appropriate, to get CPython to run the tests correctly - pass socket.AF_INET to getaddrinfo and socket.socket(), to force IPv4 - change tests to use github.com instead of google.com, because certificate validation was failing with google.com Signed-off-by: Damien George <damien@micropython.org>
2023-12-12extmod/modssl_mbedtls: Make SSLSocket.getpeercert() optional.Damien George
And only enable this method when the relevant feature is available in mbedtls. Otherwise, if mbedtls doesn't support getting the peer certificate, this method always returns None and it's confusing why it does that. It's better to remove the method altogether, so the error trying to use it is more obvious. Signed-off-by: Damien George <damien@micropython.org>
2023-12-12extmod/modssl_mbedtls: Add SSLContext certificate methods.Carlosgg
This commit adds: 1) Methods to SSLContext class that match CPython signature: - `SSLContext.load_cert_chain(certfile, keyfile)` - `SSLContext.load_verify_locations(cafile=, cadata=)` - `SSLContext.get_ciphers()` --> ["CIPHERSUITE"] - `SSLContext.set_ciphers(["CIPHERSUITE"])` 2) `sslsocket.cipher()` to get current ciphersuite and protocol version. 3) `ssl.MBEDTLS_VERSION` string constant. 4) Certificate verification errors info instead of `MBEDTLS_ERR_X509_CERT_VERIFY_FAILED`. 5) Tests in `net_inet` and `multi_net` to test these new methods. `SSLContext.load_cert_chain` method allows loading key and cert from disk passing a filepath in `certfile` or `keyfile` options. `SSLContext.load_verify_locations`'s `cafile` option enables the same functionality for ca files. Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
2023-12-06tests/run-tests.py: Skip Thumb2 tests if target doesn't support them.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2023-12-06tests/float/inf_nan_arith.py: Include -inf in argument combos.Damien George
This adds tests for, eg, -inf + inf which should be nan. Signed-off-by: Damien George <damien@micropython.org>
2023-11-30tests/extmod/deflate_compress.py: Add a test for optimal compression.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2023-11-21py/objslice: Validate that the argument to indices() is an integer.Damien George
Otherwise passing in a non-integer can lead to an invalid memory access. Thanks to Junwha Hong and Wonil Jang @S2Lab, UNIST for finding the issue. Fixes issue #13007. Signed-off-by: Damien George <damien@micropython.org>
2023-11-17tests/net_hosted/asyncio_loopback.py: Add loopback test.Peter Züger
Signed-off-by: Peter Züger <zueger.peter@icloud.com>
2023-11-09extmod/vfs_reader: Add file ioctl to set read buffer size.Andrew Leech
Can be used to speed up importing a file from a vfs based filesystem. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2023-11-03py/lexer: Change token position for new lines.Mathieu Serandour
Set the position of new line tokens as the end of the preceding line instead of the beginning of the next line. This is done by first moving the pointer to the end of the current line to skip any whitespace, record the position for the token, then finaly skip any other line and whitespace. The previous behavior was to skip every new line and whitespace, including the indent of the next line, before recording the token position. (Note that both lex->emit_dent and lex->nested_bracket_level equal 0 if had_physical_newline == true, which allows simplifying the if-logic for MP_TOKEN_NEWLINE.) And update the cmd_parsetree.py test expected output, because the position of the new-line token has changed. Fixes issue #12792. Signed-off-by: Mathieu Serandour <mathieu.serandour@numworks.fr>
2023-11-03all: Update Python formatting to ruff-format.Jim Mussared
This updates a small number of files that change with ruff-format's (vs black's) rules. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
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>