summaryrefslogtreecommitdiffstatshomepage
path: root/tests
Commit message (Collapse)AuthorAge
* tests/run-natmodtests.py: Consider a test skipped if mpy doesn't exist.Damien George4 days
| | | | | | | This is different to a test not being run because there is no corresponding natmod at all. Signed-off-by: Damien George <damien@micropython.org>
* tests/run-perfbench.py: Create a _result.json at end of run.Damien George4 days
| | | | | | | Reuse the `create_test_report()` function from `run-tests.py` to generate a `_result.json` file summarising the test run. Signed-off-by: Damien George <damien@micropython.org>
* tests/run-natmodtests.py: Create a _result.json at end of run.Damien George4 days
| | | | | | | Reuse the `create_test_report()` function from `run-tests.py` to generate a `_result.json` file summarising the test run. Signed-off-by: Damien George <damien@micropython.org>
* tests/run-multitests.py: Create a _result.json at end of run.Damien George4 days
| | | | | | | | Reuse the `create_test_report()` function from `run-tests.py` to generate a `_result.json` file summarising the test run. If there's more than one permutation of the test run, only the last result is saved. Signed-off-by: Damien George <damien@micropython.org>
* tests/run-tests.py: Factor out helper function to create test report.Damien George4 days
| | | | | | | | | | | | | | | | | | | | | | This commit factors existing code in `run-tests.py` into a new helper function `create_test_report()`. That function prints out a summary of the test run (eg number of tests passed, number failed, number skipped) and creates the corresponding `_results.json` file. This is done so `create_test_report()` can be reused by the other test runners. The `test_count` counter is now gone, and instead the number of passed plus number of failed tests is used as an equivalent count. For consistency this commit makes a minor change to the printed output of `run-tests.py`: instead of printing a shorthand name for tests that failed or skipped, it now prints the full name. Eg what was previously printed as `attrtuple2` is now printed as `basics/attrtuple2.py`. This makes the output a little longer (when there are failed/skipped tests) but helps to disambiguate the test name, eg which directory it's in. Signed-off-by: Damien George <damien@micropython.org>
* tests/extmod/random_extra_float.py: Skip when funcs not available.Damien George4 days
| | | | | | | | | | | This test was factored out from `random_extra.py` back in commit 6572029dc0665e58c2ea7355c9e541bdf83105a4, and the skip logic copied from that file. But the skip logic needs to test that the `random` and `uniform` functions exist, not `randint`. This commit fixes that skip logic. Signed-off-by: Damien George <damien@micropython.org>
* py/parsenum: Fix parsing complex literals with negative real part.Jeff Epler6 days
| | | | | | | | | | | If a complex literal had a negative real part and a positive imaginary part, it was not parsed properly because the imaginary part also came out negative. Includes a test of complex parsing, which fails without this fix. Co-authored-by: ComplexSymbol <141301057+ComplexSymbol@users.noreply.github.com> Signed-off-by: Jeff Epler <jepler@gmail.com>
* py/objarray: Allow extending array with any iterable.Jeff Epler6 days
| | | | | | | | | | | | As suggested by @dpgeorge, factor out part of array_construct to allow it to be used for construction & extension. Note that extending with a known-length list (or tuple) goes through the slow path of calling array_extend once per element. Fixes issue #7408. Signed-off-by: Jeff Epler <jepler@gmail.com>
* tests/run-tests.py: Unconditionally enable native tests if asked.Alessandro Gatti6 days
| | | | | | | | | | | | | | | | | | This commit lets the test runner enumerate and run native tests if the feature check fails but native tests were explicitly requested from the command line. The old behaviour would disable native tests anyway if the feature check failed, however this hid a bug in the x86 native emitter that would be triggered even during the feature check. That meant the test suite would pass on x86 even with a broken emitter, as those tests would have been skipped anyway. Now, if the user asks for native code it will get native code out of the runner no matter what. Co-authored-by: Damien George <damien@micropython.org> Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* tests/run-tests.py: Remove filename arg from prepare_script_for_target.Damien George11 days
| | | | | | It's no longer used. Signed-off-by: Damien George <damien@micropython.org>
* tests/run-tests.py: Automatically skip tests that are too large.Damien George11 days
| | | | | | | | | | | | | | | | | | | | | | | | | Some tests are just too big for targets that don't have much heap memory, eg `tests/extmod/vfs_rom.py`. Other tests are too large because the target doesn't have enough IRAM for native code, eg esp8266 running `tests/micropython/viper_args.py`. Previously, such tests were explicitly skipped on targets known to have little memory, eg esp8266. But this doesn't scale to multiple targets, nor to more and more tests which are too large. This commit addresses that by adding logic to the test runner so it can automatically skip tests when they don't fit in the target's memory. It does this by prepending a `print('START TEST')` to every test, and if a `MemoryError` occurs before that line is printed then the test was too big. This works for standard tests, tests that go via .mpy files, and tests that run in native emitter mode via .mpy files. For tests that are too big, it prints `lrge <test name>` on the output, and at the end prints them on a separate line of skipped tests so they can be distinguished. They are also distinguished in the `_result.json` file as a skipped test with reason "too large". Signed-off-by: Damien George <damien@micropython.org>
* tests/run-natmodtests.py: Allow injected code customisation.Alessandro Gatti12 days
| | | | | | | | | | | | | This commit introduces a mechanism to customise the code that is injected to the board when performing a native module import. A new argument, "-b"/"--begin", is added so regular Python code can be inserted in the injected fragment between the module file creation and the effective module import. This is needed for running natmod tests on ESP8266 as that board does not have enough memory to fit certain modules unless additional configuration is performed. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* unix/coverage: Add coverage test for mp_sched_schedule_node.Andrew Leech12 days
| | | | | | | | | | Test modified to reschedule itself based on a flag setting. Without the change in the parent commit, this test executes the callback indefinitely and hangs but with the change it runs only once each time mp_handle_pending() is called. Modified-by: Angus Gratton <angus@redyak.com.au> Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
* extmod/modframebuf: Add support for blit'ing read-only data.Damien George13 days
| | | | | | | | | | | | | | | | | | | | | | Currently the `FrameBuffer.blit(buf, x, y)` method requires the `buf` argument to be another `FrameBuffer`, which is quite restrictive because it doesn't allow blit'ing read-only memory/data. This commit extends `blit()` to allow the `buf` argument to be a tuple or list of the form: (buffer, width, height, format[, stride]) where `buffer` can be anything with the buffer protocol and may be read-only, eg `bytes`. Also, the palette argument to `blit()` may be of the same form. The form of this tuple/list was chosen to be the same as the signature of the `FrameBuffer` constructor (that saves quite a bit of code size doing it that way). Signed-off-by: Damien George <damien@micropython.org>
* tests/multi_net: Add test coverage for socket recv flag MSG_DONTWAIT.Angus Gratton13 days
| | | | | | Adding multi_net case for UDP only, as TCP timing is hard to test reliably. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* tests/multi_net: Add test coverage for socket recv flag MSG_PEEK.Angus Gratton13 days
| | | | | | | | Adds TCP and UDP multi_net test cases. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* tests/run-tests.py: Change _results.json to have a combined result list.Damien George13 days
| | | | | | | | | | | | | | | | | | | | | | | The `_results.json` output of `run-tests.py` was recently changed in 7a55cb6b364fdbc2f3291456643bd640ba566ec9 to add a list of passed and skipped tests. The way this was done turned out to be not general enough, because we want to add another type of result, namely tests that are skipped because they are too large. Instead of having separate lists in `_results.json` for each kind of result (pass, fail, skip, skip too large, etc), this commit changes the output form of `_results.json` so that it stores a single list of 3-tuples of all tests that were run: [(test_name, result, reason), ...] That's more general and allows adding a reason for skipped and failed tests. At the moment this reason is just an empty string, but can be improved in the future. Signed-off-by: Damien George <damien@micropython.org>
* py/emitinlinextensa: Add the rest of LX3 opcodes to the assembler.Alessandro Gatti2025-05-29
| | | | | | | | | | | | | | | | | | This commit expands the Xtensa inline assembler to support most if not all opcodes available on the ESP8266 and LX3 Xtensa cores. This is meant as a stepping stone to add inline assembler support for the ESP32 and its LX6 core, along to windowed-specific opcodes and additional opcodes that are present only on the LX7 core (ESP32-S3 and later). New opcodes being added are covered by tests, and the provided tests were expanded to also include opcodes available in the existing implementation. Given that the ESP8266 space requirements are tighter than ESP32's, certain opcodes that won't be commonly used have been put behind a define to save some space in the general use case. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* tests/float/math_constants.py: Test actual e and pi constant values.Damien George2025-05-22
| | | | | | | | | | | | | The existing test for `math.e` and `math.pi` constants can fail on certain targets if the functions `math.exp()` and/or `math.cos()` are not accurate enough (eg out by an LSB of float precision). For example this test currently fails on PYBD_SF6 which uses double precision floats (and that's due to the `lib/libm_dbl/exp.c` implementation not being exact). This commit changes this constant test so that it tests the actual constant value, not the evaluation of `exp()` and `cos()` functions. Signed-off-by: Damien George <damien@micropython.org>
* tests/micropython/viper_ptr: Add tests for arch edge cases.Alessandro Gatti2025-05-21
| | | | | | | | | | | | | | | This commit adds a series of test cases to exercise the Viper code generator load/store emitting capabilities on certain boundary conditions. The new test cases check whether the emitted load/store code performs correctly when dealing with specific memory offsets, which trigger specific code generation sequences on different architectures. Right now the cases are for unsigned offsets whose bitmasks span up to 5, 8, and 12 bits (respectively Arm/Thumb, Xtensa, RV32). Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* extmod/modjson: Detect unterminated composite entities.Alessandro Gatti2025-05-19
| | | | | | | | | | | | | | | This commit makes the JSON parser raise an exception when handling objects or arrays whose declaration is incomplete, as in missing the closing marker (brace or bracket) and if the missing marker would have been the last non-whitespace character in the incoming string. Since CPython's JSON parser would raise an exception in such a case, unlike MicroPython's, this commit aligns MicroPython's behaviour with CPython. This commit fixes issue #17141. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* tests/run-tests.py: Add list of passed/skipped tests to _result.json.Damien George2025-05-18
| | | | | | | | | The output `_result.json` file generated by `run-tests.py` currently contains a list of failed tests. This commit adds to the output a list of passed and skipped tests, and so now provides full information about which tests were run and what their results were. Signed-off-by: Damien George <damien@micropython.org>
* tests/cpydiff: Ensure all have two levels of category.Jeff Epler2025-05-16
| | | | | | This improves the TOC display of the generated differences section. Signed-off-by: Jeff Epler <jepler@gmail.com>
* tests/cpydiff: Add test of underscore-in-literals.Jeff Epler2025-05-16
| | | | Signed-off-by: Jeff Epler <jepler@gmail.com>
* tests/cpydiff: Document that uPy requires space after number+period.Jeff Epler2025-05-16
| | | | Signed-off-by: Jeff Epler <jepler@gmail.com>
* tests/cpydiff: Explain the numeric literal parsing difference.Jeff Epler2025-05-16
| | | | | | Fixes issue #17224. Signed-off-by: Jeff Epler <jepler@gmail.com>
* tests/extmod/vfs_lfs_error.py: Test value of all OSError's errno.Damien George2025-05-15
| | | | | | To make sure they have the correct value. Signed-off-by: Damien George <damien@micropython.org>
* tests/cpydiff: Document format separator difference.Jeff Epler2025-05-13
| | | | Signed-off-by: Jeff Epler <jepler@gmail.com>
* py/objstr: Add support for the :_b/o/x specifier in str.format.Jeff Epler2025-05-13
| | | | | | | | | | | This groups non-decimal values by fours, such as bbb_bbbb_bbbb. It also supports `{:_d}` to use underscore for decimal numbers (grouped in threes). Use of incorrect ":,b" is not diagnosed. Thanks to @dpgeorge for the suggestion to reduce code size. Signed-off-by: Jeff Epler <jepler@gmail.com>
* rp2/modmachine: Add mutual exclusion for machine.lightsleep().Angus Gratton2025-05-12
| | | | | | | | | | | | | | | There's no specified behaviour for what should happen if both CPUs call `lightsleep()` together, but the latest changes could cause a permanent hang due to a race in the timer cleanup code. Add a flag to prevent hangs if two threads accidentally lightsleep, at least. This allows the new lightsleep test to pass on RPI_PICO and RPI_PICO2, and even have much tighter time deltas. However, the test still fails on wireless boards where the lwIP tick wakes them up too frequently. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* tests/ports/rp2: Add a test case for light sleeping from CPU1.Angus Gratton2025-05-12
| | | | | | | | Not currently passing. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* tests/ports/rp2: Update machine idle test to revert skip for RP2350.Peter Harper2025-05-12
| | | | | | This reverts commit b42bb911c663dc90575d6a7fe3ea4760b6559372. Signed-off-by: Peter Harper <peter.harper@raspberrypi.com>
* tests/multi_net: Add test that requires queuing UDP packets.Damien George2025-05-12
| | | | | | | | This commit adds a new network multi-test which sends a burst of UDP packets from the client, and the server doesn't recv them until they have all been sent. Signed-off-by: Damien George <damien@micropython.org>
* tests/extmod/vfs_rom.py: Clear sys.path before running test.Damien George2025-05-12
| | | | | | | Otherwise if the target has certain files/directories (such as "test") in its filesystem then these interfere with the unit tests. Signed-off-by: Damien George <damien@micropython.org>
* tests/net_inet: Update micropython.org certificate for SSL tests.Damien George2025-05-12
| | | | | | | | | | | | The Let's Encrypt root certificate has changed so needs updating in these tests. Also use `bytes.fromhex()` instead of `binascii.unhexlify()`, to eliminate the need for the `binascii` module. Both of these features are controlled by `MICROPY_PY_BUILTINS_BYTES_HEX`, so the test will still work on the same targets that it previously did. Signed-off-by: Damien George <damien@micropython.org>
* lib/littlefs: Update LittleFS to v2.10.2.Daniël van de Giessen2025-05-07
| | | | | | | | Going above the root directory (/../foo) now gives an error. This is an intentional change made by LittleFS. It required a update of the testsuite and is a (minor) compatibility break. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
* extmod/asyncio: Fix early exit of asyncio scheduler.Yoctopuce dev2025-05-07
| | | | | | | | | | | | | | | | | | | | | This commit fixes three open issues related to the asyncio scheduler exiting prematurely when the main task queue is empty, in cases where CPython would not exit (for example, because the main task is not done because it's on a different queue). In the first case, the scheduler exits because running a task via `run_until_complete` did not schedule any dependent tasks. In the other two cases, the scheduler exits because the tasks are queued in an event queue. Tests have been added which reproduce the original issues. These test cases document the unauthorized use of `Event.set()` from a soft IRQ, and are skipped in unsupported environments (webassembly and native emitter). Fixes issues #16759, #16569 and #16318. Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
* tests/extmod: Rename ssl tests that only use the tls module.Angus Gratton2025-05-02
| | | | Signed-off-by: Angus Gratton <angus@redyak.com.au>
* py/malloc: Add mutex for tracked allocations.Angus Gratton2025-05-02
| | | | | | | | | | | | | | Fixes thread safety issue that could cause memory corruption on ports with (MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL) - currently only rp2 and unix have this configuration. Adds unit test for TLS sockets that exercises this code path. I wasn't able to make this fail on rp2, the race condition window is pretty narrow and may not have a direct impact on a quiet system. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* tests/ports/rp2: Tune rp2.DMA test so it runs in all configurations.Damien George2025-05-01
| | | | | | | | | | | | | | | | | | | | Changes in this commit: - Allow the DMA instance to be any instance, not just DMA(0); eg WLAN may be using DMA(0). - Make the DMA timing test run a little faster by preloading `dma.active`. - Run the DMA timing test 10 times and take the average time taken as the test result, to eliminate any big effects of caching. - Change the expected time to `range(30, 80)` to cover RP2040, RP2350, RISC-V variants, and both bytecode and native emitter. - Add a `sleep_ms(1)` after waiting for the IRQ to fire, so that any scheduled code gets a chance to run when the test is compiled with the native emitter. With these changes this test passes reliably on RPI_PICO, RPI_PICO_W, RPI_PICO2, RPI_PICO2_W, RPI_PICO2-RISCV and RPI_PICO2_W-RISCV, in both bytecode and native emitter mode, with and without WLAN enabled. Signed-off-by: Damien George <damien@micropython.org>
* tests/ports/rp2: Convert rp2.DMA test to a unittest.Damien George2025-05-01
| | | | | | This test is rather complicated and benefits from being a unittest. Signed-off-by: Damien George <damien@micropython.org>
* tests/net_hosted: Only run network loopback test on supported targets.Damien George2025-05-01
| | | | | | | | | | | | | 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>
* tests/extmod/vfs_posix.py: Fix test on Android.Alessandro Gatti2025-04-24
| | | | | | | | | | | | | | | | | | | | | | 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 George2025-04-24
| | | | Signed-off-by: Damien George <damien@micropython.org>
* tests/extmod/vfs_lfs_ilistdir_del.py: Skip test if not enough memory.Damien George2025-04-24
| | | | Signed-off-by: Damien George <damien@micropython.org>
* tests/extmod: Skip binascii tests when hexlify/unhexlify don't exist.Damien George2025-04-24
| | | | | | | 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 dev2025-04-21
| | | | | | | | | 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 Epler2025-04-21
| | | | 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>