summaryrefslogtreecommitdiff
path: root/tests/net_hosted
AgeCommit message (Collapse)Author
2025-05-01tests/net_hosted: Only run network loopback test on supported targets.Damien George
Only a few ports have TCP/IP loopback enabled in their network stack, and this test will only pass on those ports. There's not really any good way to do a feature check for loopback mode without actually running the test and seeing if it passes/fails, so add an explicit check that the test is running on a port known to support loopback. (Enabling loopback on lwIP, eg RPI_PICO_W, costs +568 code and +272 bss and is a rarely used feature, so not worth unconditionally enabling.) Signed-off-by: Damien George <damien@micropython.org>
2024-12-06tests/net_hosted: Convert connect-nonblock-xfer test to use unittest.Damien George
This allows it to run parts of the test on esp8266 (or any target using axTLS). Signed-off-by: Damien George <damien@micropython.org>
2024-11-13tests/net_hosted: Improve and simplify non-block-xfer test.Damien George
CPython changed its non-blocking socket behaviour recently and this test would not run under CPython anymore. So the following steps were taken to get the test working again and then simplify it: - Run the test against CPython 3.10.10 and capture the output into the .exp file for the test. - Run this test on unix port of MicroPython and verify that the output matches the CPython 3.10.10 output in the new .exp file (it did). From now on take unix MicroPython as the source of truth for this test when modifying it. - Remove all code that was there for CPython compatibility. - Make it print out more useful information during the test run, including names of the OSError errno values. - Add polling of the socket before the send/write/recv/read to verify that the poll gives the correct result in non-blocking mode. Tested on unix MicroPython, ESP32_GENERIC, PYBD_SF2 and RPI_PICO_W boards. Signed-off-by: Damien George <damien@micropython.org>
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-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-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>
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-11-17tests/net_hosted/asyncio_loopback.py: Add loopback test.Peter Züger
Signed-off-by: Peter Züger <zueger.peter@icloud.com>
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-06-19tests: Rename uasyncio to asyncio.Jim Mussared
This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08tests: Replace umodule with module everywhere.Jim Mussared
This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-04-27all: Fix spelling mistakes based on codespell check.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-06-26extmod/uasyncio: Get addr and bind server socket before creating task.Damien George
Currently when using uasyncio.start_server() the socket configuration is done inside a uasyncio.create_task() background function. If the address and port are already in use however this throws an OSError which cannot be cleanly caught behind the create_task(). This commit moves the getaddrinfo and socket binding to the start_server() function, and only creates the task if that succeeds. This means that any OSError from the initial socket configuration is propagated directly up the call stack, compatible with CPython behaviour. See #7444. Signed-off-by: Damien George <damien@micropython.org>
2021-04-23tests: Use .errno instead of .args[0] for OSError exceptions.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-03-12tests: Rename run-tests to run-tests.py for consistency.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-02-17extmod/modussl: Fix ussl read/recv/send/write errors when non-blocking.Thorsten von Eicken
Also fix related problems with socket on esp32, improve docs for wrap_socket, and add more tests.
2021-02-15esp32: Set MICROPY_USE_INTERNAL_ERRNO=0 to use toolchain's errno.h.Thorsten von Eicken
The underlying OS (the ESP-IDF) uses it's own internal errno codes and so it's simpler and cleaner to use those rather than trying to convert everything to the values defined in py/mperrno.h.
2020-03-30tests: Format all Python code with black, except tests in basics subdir.David Lechner
This adds the Python files in the tests/ directory to be formatted with ./tools/codeformat.py. The basics/ subdirectory is excluded for now so we aren't changing too much at once. In a few places `# fmt: off`/`# fmt: on` was used where the code had special formatting for readability or where the test was actually testing the specific formatting.
2019-10-31extmod/modlwip: Unconditionally return POLLHUP when polling new socket.Damien George
POSIX poll should always return POLLERR and POLLHUP in revents, regardless of whether they were requested in the input events flags. See issues #4290 and #5172.
2017-11-23tests/net_hosted: Add test for socket connect() and poll() behaviour.Damien George
2017-08-16extmod/modussl_mbedtls.c: Add ussl.getpeercert() method.Eric Poulsen
Behaviour is as per CPython but only the binary form is implemented here. A test is included.
2017-06-23tests/connect_nonblock: Refactor towards real net_hosted test.Paul Sokolovsky
In the future, a special runner for such tests will import each test and call test() function with an address of test server to use.
2017-06-23tests/net_inet: Move tests which don't require full Internet to net_hosted.Paul Sokolovsky
The idea is that these tests can be run with just a test server running on a test host, with device under test connecting to it, instead of requiring Internet connection for testing. Such setup is however WIP, and some tests in net_hosted/ are so far written to connect to Internet, as there're not test server written yet. This is expected to evolve over time.