Wykres commitów

2320 Commity (master)

Autor SHA1 Wiadomość Data
Glenn Moloney 7fa322afb8 esp32,esp8266: Add support for the Espressif ESP-NOW protocol.
ESP-NOW is a proprietary wireless communication protocol which supports
connectionless communication between ESP32 and ESP8266 devices, using
vendor specific WiFi frames.  This commit adds support for this protocol
through a new `espnow` module.

This commit builds on original work done by @nickzoic, @shawwwn and with
contributions from @zoland.  Features include:
- Use of (extended) ring buffers in py/ringbuf.[ch] for robust IO.
- Signal strength (RSSI) monitoring.
- Core support in `_espnow` C module, extended by `espnow.py` module.
- Asyncio support via `aioespnow.py` module (separate to this commit).
- Docs provided at `docs/library/espnow.rst`.

Methods available in espnow.ESPNow class are:
- active(True/False)
- config(): set rx buffer size, read timeout and tx rate
- recv()/irecv()/recvinto() to read incoming messages from peers
- send() to send messages to peer devices
- any() to test if a message is ready to read
- irq() to set callback for received messages
- stats() returns transfer stats:
    (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts)
- add_peer(mac, ...) registers a peer before sending messages
- get_peer(mac) returns peer info: (mac, lmk, channel, ifidx, encrypt)
- mod_peer(mac, ...) changes peer info parameters
- get_peers() returns all peer info tuples
- peers_table supports RSSI signal monitoring for received messages:
    {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...}

ESP8266 is a pared down version of the ESP32 ESPNow support due to code
size restrictions and differences in the low-level API.  See docs for
details.

Also included is a test suite in tests/multi_espnow.  This tests basic
espnow data transfer, multiple transfers, various message sizes, encrypted
messages (pmk and lmk), and asyncio support.

Initial work is from https://github.com/micropython/micropython/pull/4115.
Initial import of code is from:
https://github.com/nickzoic/micropython/tree/espnow-4115.
2023-05-01 16:47:21 +10:00
Damien George b1229efbd1 all: Fix spelling mistakes based on codespell check.
Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 18:03:06 +10:00
Takeo Takahashi dc7de6ed83 renesas-ra: Change MICROPY_HW_BOARD_NAME definition to product name.
Changes in this commit:
- Change MICROPY_HW_BOARD_NAME definition to match the product name.
- Rename board folder's name to match the product name style.
- Change related files like Makefile, document descriptions, test cases, CI
  and tools.

Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
2023-04-27 14:12:53 +10:00
Jim Mussared ab31e23f7a tests/multi_bluetooth: Use multitest.broadcast instead of sleep.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-04-26 11:37:20 +10:00
Jim Mussared 419017e1e4 tests/multi_bluetooth/ble_characteristic.py: Add write-no-response.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-04-26 11:37:20 +10:00
Jim Mussared 80fc1c8fbf tests/multi_bluetooth: Add test for descriptors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-04-26 11:37:20 +10:00
Jim Mussared f9b60a240a tests/multi_bluetooth/ble_subscribe: Use end_handle in desc discovery.
Obtaining the end_handle was added in cacc96d9.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-04-26 11:37:20 +10:00
Jim Mussared a652695153 tests/multi_bluetooth/ble_mtu: Split peripheral/central-initiated.
btstack only supports central-initiated, so this allows us to have a test
that works on both (ble_mtu.py), and then another one for just the NimBLE
supported behavior (ble_mtu_peripheral.py).

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-04-26 11:37:20 +10:00
Jim Mussared dcb863ebfb tests/multi_bluetooth: Use time.sleep_ms instead of time.sleep.
On unix, time.sleep is implemented as select(timeout=<time>) which means
that it does not run the poll hook during sleeping.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-04-26 11:37:20 +10:00
Damien George a4672149b6 tests/extmod/vfs_fat_ilistdir_del.py: Use 512-byte erase block size.
Following other vfs_fat tests, so the test works on ports like stm32 that
only support 512-byte block size.

Signed-off-by: Damien George <damien@micropython.org>
2023-03-29 23:15:16 +11:00
Damien George 6c76248960 tests/multi_bluetooth: Use multitest.output_metric in BLE perf tests.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-23 13:18:52 +11:00
Damien George af42634866 tests/run-multitests.py: Support outputting test metrics.
If a multitest calls `multitest.output_metric(...)` then that output will
be collected separately, not considered as part of the test verification
output, and instead be printed at the end.  This is useful for tests that
want to output performance/timing metrics that may change from one run to
the next.

Signed-off-by: Damien George <damien@micropython.org>
2023-03-23 13:18:52 +11:00
Jeremy Rand d677023b3d extmod/vfs_posix: Do not filter '..*' in ilistdir when filtering '..'.
When iterating over os.ilistdir(), the special directories '.' and '..'
are filtered from the results.  But the code inadvertently also filtered
any file/directory which happened to match '..*'.  This change fixes the
filter.

Fixes issue #11032.

Signed-off-by: Jeremy Rand <jeremy@rand-family.com>
2023-03-21 16:13:10 +11:00
Damien George 7c1584aef1 py/compile: Fix scope of assignment expression target in comprehensions.
When := is used in a comprehension the target variable is bound to the
parent scope, so it's either a global or a nonlocal.  Prior to this commit
that was handled by simply using the parent scope's id_info for the
target variable.  That's completely wrong because it uses the slot number
for the parent's Python stack to store the variable, rather than the slot
number for the comprehension.  This will in most cases lead to incorrect
behaviour or memory faults.

This commit fixes the scoping of the target variable by explicitly
declaring it a global or nonlocal, depending on whether the parent is the
global scope or not.  Then the id_info of the comprehension can be used to
access the target variable.  This fixes a lot of cases of using := in a
comprehension.

Code size change for this commit:

       bare-arm:    +0 +0.000%
    minimal x86:    +0 +0.000%
       unix x64:  +152 +0.019% standard
          stm32:   +96 +0.024% PYBV10
         cc3200:   +96 +0.052%
        esp8266:  +196 +0.028% GENERIC
          esp32:  +156 +0.010% GENERIC[incl +8(data)]
         mimxrt:   +96 +0.027% TEENSY40
     renesas-ra:   +88 +0.014% RA6M2_EK
            nrf:   +88 +0.048% pca10040
            rp2:  +104 +0.020% PICO
           samd:   +88 +0.033% ADAFRUIT_ITSYBITSY_M4_EXPRESS

Fixes issue #10895.

Signed-off-by: Damien George <damien@micropython.org>
2023-03-09 12:13:12 +11:00
Andrew Leech 0359aac10a tests/multi_bluetooth: Add bluetooth multi-test for deepsleep.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2023-03-08 14:04:14 +11:00
Andrew Leech 211859b11f tests/run-multitests.py: Add ability to test instance over reboot.
The device-under-test should use `multitest.expect_reboot()` to indicate
that it will reboot.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2023-03-08 14:04:14 +11:00
Damien George 2e4dda3c20 py/modmath: Fix two-argument math function domain check.
Prior to this fix, pow(1.5, inf) and pow(0.5, -inf) (among other things)
would incorrectly raise a ValueError, because the result is inf with the
first argument being finite.  This commit fixes this by allowing the result
to be infinite if the first or second (or both) argument is infinite.

This fix doesn't affect the other three math functions that have two
arguments:
- atan2 never returns inf, so always fails isinf(ans)
- copysign returns inf only if the first argument x is inf, so will never
  reach the isinf(y) check
- fmod never returns inf, so always fails isinf(ans)

Signed-off-by: Damien George <damien@micropython.org>
2023-02-24 15:55:12 +11:00
Damien George 177ae2f346 tests/float: Make output of math function tests more readable.
By explicitly naming the function, its arguments, and result.

Signed-off-by: Damien George <damien@micropython.org>
2023-02-16 10:38:38 +11:00
Damien George 799d888182 tests/float: Add domain checks for log and also -inf.
Signed-off-by: Damien George <damien@micropython.org>
2023-02-16 10:26:33 +11:00
Damien George 41ed01f139 tests/micropython: Split viper_misc test into two files.
So it can run on targets with low memory, eg esp8266.

Also enable the viper_4args() sub-test, which is now supported.

Signed-off-by: Damien George <damien@micropython.org>
2023-02-09 16:12:25 +11:00
Damien George d99ebb310c tests/extmod: Skip vfs tests if target doesn't have enough memory.
Signed-off-by: Damien George <damien@micropython.org>
2023-02-09 15:32:06 +11:00
Damien George b1123a54c1 tests/extmod: Get DecompIO test running on low-memory targets.
By changing the zlib header so that it uses a small (256 byte) window.

Signed-off-by: Damien George <damien@micropython.org>
2023-02-09 15:20:25 +11:00
Damien George 5c3c1c737e tests/float: Skip new complex tests if complex unavailable.
These complex tests were recently added.

Signed-off-by: Damien George <damien@micropython.org>
2023-02-09 15:20:00 +11:00
Jim Mussared 8b27482692 top: Update Python formatting to black "2023 stable style".
See https://black.readthedocs.io/en/stable/the_black_code_style/index.html

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-02-02 12:51:03 +11:00
Damien George d387ae3444 py/objint_mpz: Catch and reject @ and @= operating on big integers.
This will also catch / and /= when float support is disabled.

Fixes issue #10544.

Signed-off-by: Damien George <damien@micropython.org>
2023-01-23 13:03:51 +11:00
Jim Mussared fb8792c095 py/lexer: Wrap in parenthesis all f-string arguments passed to format.
This is important for literal tuples, e.g.

    f"{a,b,}, {c}" --> "{}".format((a,b), (c),)

which would otherwise result in either a syntax error or the wrong result.

Fixes issue #9635.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-01-20 17:54:32 +11:00
Andrew Leech 5c4153ea37 py/objarray: Raise error on out-of-bound memoryview slice start.
32-bit platforms only support a slice offset start of 24 bit max due to the
limited size of the mp_obj_array_t.free member.  Similarly on 64-bit
platforms the limit is 56 bits.

This commit adds an OverflowError if the user attempts to slice a
memoryview beyond this limit.

Signed-off-by: Damien George <damien@micropython.org>
2023-01-20 16:31:37 +11:00
Damien George fc745d85fe tests/extmod/ure_namedclass: Add tests for named classes in class sets.
Signed-off-by: Damien George <damien@micropython.org>
2023-01-18 09:15:32 +11:00
Damien George 910f579403 py/emitnative: Initialise locals as Python object type for native code.
In @micropython.native code the types of variables and expressions are
always Python objects, so they can be initialised as such.  This prevents
problems with compiling optimised code like while-loops where a local may
be referenced before it is assigned to.

Signed-off-by: Damien George <damien@micropython.org>
2022-12-16 11:44:10 +11:00
Damien Tournoud ed58d6e4ce extmod/modussl_mbedtls: Fix support for ioctl(MP_STREAM_POLL).
During the initial handshake or subsequent renegotiation, the protocol
might need to read in order to write (or conversely to write in order
to read). It might be blocked from doing so by the state of the
underlying socket (i.e. there is no data to read, or there is no space
to write).

The library indicates this condition by returning one of the errors
`MBEDTLS_ERR_SSL_WANT_READ` or `MBEDTLS_ERR_SSL_WANT_WRITE`. When that
happens, we need to enforce that the next poll operation only considers
the direction that the library indicated.

In addition, mbedtls does its own read buffering that we need to take
into account while polling, and we need to save the last error between
read()/write() and ioctl().
2022-12-15 12:06:22 -08:00
David Lechner 3c2d7563d2 tests/unix/mod_os: Add test for os module.
This adds a test to get coverage of the unix port-specific implementation
of the `os` module.

Signed-off-by: David Lechner <david@pybricks.com>
2022-12-14 13:38:51 +11:00
David Lechner 958f748e53 unix/moduos: Implement 2-arg version of os.getenv().
This adds the `default` argument of `os.getenv(key, default=None)`.

Signed-off-by: David Lechner <david@pybricks.com>
2022-12-14 13:38:39 +11:00
stijn 9c7ff87643 all: Keep msvc build output in build/ directories.
This follow the change made for Makefile-based projects in b2e82402.
2022-12-13 17:18:53 +11:00
TPReal 002f54ab4e tests/extmod/framebuf_scroll: Add tests for FrameBuffer scrolling.
Includes a currently-failing test of scrolling by at least the size of the
buffer.
2022-12-09 16:47:08 +11:00
Jeff Epler d75ff42297 unix/coverage: Add extra GC coverage test for ATB gap byte.
The assertion that is added here (to gc.c) fails when running this new test
if ALLOC_TABLE_GAP_BYTE is set to 0.

Signed-off-by: Jeff Epler <jepler@gmail.com>
Signed-off-by: Damien George <damien@micropython.org>
2022-12-08 14:35:08 +11:00
Laurens Valk 632d43ed44 py/mpconfig: Include micropython module in core features.
This excludes it from the minimal builds.

Signed-off-by: Laurens Valk <laurens@pybricks.com>
2022-12-06 13:34:17 +11:00
David Lechner d5181034f2 py/bc: Fix checking for duplicate **kwargs.
The code was already checking for duplicate kwargs for named parameters but
if `**kwargs` was given as a parameter, it did not check for multiples of
the same argument name.

This fixes the issue by adding an addition test to catch duplicates and
adds a test to exercise the code.

Fixes issue #10083.

Signed-off-by: David Lechner <david@pybricks.com>
2022-11-28 11:23:22 +11:00
Laurens Valk 3c1a2a942a tests/misc/cexample_class: Fix timing sensitivity.
This test could occasionally fail because some operations take longer
than expected. This relaxes the timing constraints and defers printing
until the very end.

Signed-off-by: Laurens Valk <laurens@pybricks.com>
2022-11-25 08:14:54 +01:00
Laurens Valk 5588647ad2 tests/misc/cexample_module: Test class presence.
Now that the Timer class has been merged in a separate pull request,
this can be added to the module test too.

Signed-off-by: Laurens Valk <laurens@pybricks.com>
2022-11-25 08:13:15 +01:00
Rayane Chatrieux f3e4c505d1 py/objdict: Implement dictionary union (PEP 584).
Implements dictionary union according to PEP 584's specifications, minus
the fact that dictionary entries are not guaranteed to be in insertion
order.  This feature is enabled with MICROPY_CPYTHON_COMPAT.

Includes a new test.

With the assistance of Fangrui Qin <qinf@purdue.edu>

Signed-off-by: Rayane Chatrieux <rayane.chatrieux@gmail.com>
Signed-off-by: Damien George <damien@micropython.org>
2022-11-25 12:46:14 +11:00
Laurens Valk a67989aa20 examples/usercmodule: Add example of a native C class.
This shows how ports can add their own custom types/classes.

It is part of the unix coverage build, so we can use it for tests too.

Signed-off-by: Laurens Valk <laurens@pybricks.com>
2022-11-23 11:46:17 +11:00
Laurens Valk 1d27c7d423 tests/misc: Add test for cexample module.
This also moves the existing test for cexample.add_ints
originally done in extra_coverage.

Signed-off-by: Laurens Valk <laurens@pybricks.com>
2022-11-23 11:44:13 +11:00
Jim Mussared 4ff10b5976 tests/run-tests.py: Use host arch for mpy-cross for target=unix.
This will make mpy-cross auto-detect. Allow overriding for non-default
configurations (e.g. using 32-bit build of the unix port).

Also use armv7m by default for qemu-arm (the default qemu target is
Cortex-M3).

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-11-17 23:03:02 +11:00
Damien George 0698dd72ea py/emitnative: Ensure load_subscr does not clobber existing REG_ARG_2.
Follow up from a similar fix in 426785a19e

Fixes issue #6314.

Signed-off-by: Damien George <damien@micropython.org>
2022-11-11 12:25:32 +11:00
Damien George 451ded8d7b tests/basics: Add exp file for builtin_str_hex test.
Because bytes.hex() only supports the sep argument since Python 3.8.

Signed-off-by: Damien George <damien@micropython.org>
2022-11-10 11:44:49 +11:00
Jim Mussared 2c8dab7ab4 py/objarray: Detect bytearray(str) without an encoding.
This prevents a very subtle bug caused by writing e.g. `bytearray('\xfd')`
which gives you `(0xc3, 0xbd)`.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-11-08 23:09:22 +11:00
Damien George 329f8252b9 tests/run-perfbench: Support --heapsize argument and pass to executable.
Signed-off-by: Damien George <damien@micropython.org>
2022-11-03 17:33:25 +11:00
Damien George 965a87b53c tests/extmod: Add test for sleep_ms value that overflows ticks.
Addresses #9516.

Signed-off-by: Damien George <damien@micropython.org>
2022-10-14 16:10:38 +11:00
Damien George 815920c87f extmod/utime_mphal: Make ticks_add check for overflow of delta.
Work done in collaboration with @jimmo.

Signed-off-by: Damien George <damien@micropython.org>
2022-10-14 15:54:53 +11:00
Jim Mussared 8e912a501a unix: Enable sys.executable.
Gives the absolute path to the unix micropython binary.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Damien George <damien@micropython.org>
2022-10-11 18:10:30 +11:00
Jim Mussared 9d6f474ea4 py/objstr: Don't treat bytes as unicode in str.count.
`b'\xaa \xaa'.count(b'\xaa')` now (correctly) returns 2 instead of 1.

Fixes issue #9404.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-26 00:54:18 +10:00
Angus Gratton 25ff5b52d9 py/parse: Allow const types other than int to optimise as true/false.
Allows optimisation of cases like:

    import micropython
    _DEBUG = micropython.const(False)
    if _DEBUG:
        print('Debugging info')

Previously the 'if' statement was only optimised out if the type of the
const() argument was integer.

The change is implemented in a way that makes the compiler slightly smaller
(-16 bytes on PYBV11) but compilation will also be very slightly slower.

As a bonus, if const support is enabled then the compiler can now optimise
const truthy/falsey expressions of other types, like:

    while "something":
        pass

... unclear if that is useful, but perhaps it could be.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2022-09-23 16:04:13 +10:00
Angus Gratton f91ebf6fa9 tests: Allow 'special' tests to output "SKIP" on a single line. 2022-09-23 16:02:59 +10:00
Andrew Leech 13c4470fd0 tests/run-multitests: Make paths more deterministic.
Allows running from a different directory, etc.

This work was funded by Planet Innovation.
2022-09-20 09:07:18 +10:00
Andrew Leech 7589d86b6b tests/run-multitests: Extend usage information. 2022-09-20 09:07:02 +10:00
Jim Mussared 920da9c5e3 unix/variants/coverage: Add test for manifest freeze_mpy().
This uses the frozentest.mpy that is also used by ports/minimal.

Also fixes two bugs that these new tests picked up:
 - File extension matching in manifestfile.py.
 - Handling of freeze_mpy results in makemanifest.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 23:51:10 +10:00
Jim Mussared 6ecdf1a240 tests/frozen: Move frozentest.mpy from ports/ to tests/.
frozentest.mpy was previously duplicated in ports/minimal and
ports/powerpc.

This needs to be re-generated on every .mpy version increase, so might as
well just have a single copy of it.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 23:51:10 +10:00
stijn 9ae8d38204 extmod/vfs_posix_file: Implement finaliser for files.
Prevent handle leaks when file objects aren't closed explicitly and
fix some MICROPY_CPYTHON_COMPAT issues: this wasn't properly adhered
to because #ifdef was used so it was always on, and closing files
multiple times should be avoided unconditionally.
2022-09-19 23:44:50 +10:00
Jim Mussared 15d0615d5c py/objmodule: Add support for __dict__.
This matches class `__dict__`, and is similarly gated on
MICROPY_CPYTHON_COMPAT. Unlike class though, because modules's globals are
actually dict instances, the result is a mutable dictionary.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 23:22:46 +10:00
Jim Mussared d94141e147 py/persistentcode: Introduce .mpy sub-version.
The intent is to allow us to make breaking changes to the native ABI (e.g.
changes to dynruntime.h) without needing the bytecode version to increment.

With this commit the two bits previously used for the feature flags (but
now unused as of .mpy version 6) encode a sub-version.  A bytecode-only
.mpy file can be loaded as long as MPY_VERSION matches, but a native .mpy
(i.e. one with an arch set) must also match MPY_SUB_VERSION.  This allows 3
additional updates to the native ABI per bytecode revision.

The sub-version is set to 1 because the previous commits that changed the
layout of mp_obj_type_t have changed the native ABI.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Damien George <damien@micropython.org>
2022-09-19 23:19:55 +10:00
Jim Mussared 6da41b5900 py/obj: Merge getiter and iternext mp_obj_type_t slots.
The goal here is to remove a slot (making way to turn make_new into a slot)
as well as reduce code size by the ~40 references to mp_identity_getiter
and mp_stream_unbuffered_iter.

This introduces two new type flags:
- MP_TYPE_FLAG_ITER_IS_ITERNEXT: This means that the "iter" slot in the
  type is "iternext", and should use the identity getiter.
- MP_TYPE_FLAG_ITER_IS_CUSTOM: This means that the "iter" slot is a pointer
  to a mp_getiter_iternext_custom_t instance, which then defines both
  getiter and iternext.

And a third flag that is the OR of both, MP_TYPE_FLAG_ITER_IS_STREAM: This
means that the type should use the identity getiter, and
mp_stream_unbuffered_iter as iternext.

Finally, MP_TYPE_FLAG_ITER_IS_GETITER is defined as a no-op flag to give
the default case where "iter" is "getiter".

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:13 +10:00
Jim Mussared 6c376a9306 tests/extmod/uasyncio_heaplock.py: Force SKIP on stackless.
This is a latent issue that wasn't caught by CI because there was no
configuration that had both stackless+uasyncio.

The previous check to skip with stackless builds only worked when the
bytecode emitter was used by default.  Force the check to use the bytecode
emitter.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-13 17:41:02 +10:00
Andrew Leech 4e0964b59f extmod/vfs: Add finaliser to ilistdir to close directory handle.
When iterating over filesystem/folders with os.iterdir(), an open file
(directory) handle is used internally.  Currently this file handle is only
closed once the iterator is completely drained, eg. once all entries have
been looped over / converted into list etc.

If a program opens an iterdir but does not loop over it, or starts to loop
over the iterator but breaks out of the loop, then the handle never gets
closed.  In this state, when the iter object is cleaned up by the garbage
collector this open handle can cause corruption of the filesystem.

Fixes issues #6568 and #8506.
2022-09-13 13:00:42 +10:00
Jeff Epler e90b85cc98 extmod/modure: Convert byte offsets to unicode indices when necessary.
And add a test.

Fixes issue #9202.

Signed-off-by: Jeff Epler <jepler@gmail.com>
2022-09-06 17:08:18 +10:00
Takeo Takahashi 2f2fd36713 tests/renesas-ra: Update pin test to support all boards.
Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
2022-08-31 12:00:41 +10:00
Jim Mussared bd4e45fd68 tests/unicode: Add test for invalid utf-8 file contents.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-08-26 16:47:27 +10:00
Jim Mussared c616721b1a extmod/modframebuf: Improve poly-fill boundary pixels.
Rather than drawing the entire boundary to catch missing pixels, just
detect the cases where boundary pixels are skipped during node calculation
and pre-emptively draw them then.

This adds 72 bytes on PYBV11, but makes filled poly() 20% faster.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-08-19 23:31:28 +10:00
Mat Booth 04a655c744 extmod/modframebuf: Add polygon drawing methods.
Add method for drawing polygons.

For non-filled polygons, uses the existing line-drawing code to render
arbitrary polygons using the given coords list, at the given x,y position,
in the given colour.

For filled polygons, arbitrary closed polygons are rendered using a fast
point-in-polygon algorithm to determine where the edges of the polygon lie
on each pixel row.

Tests and documentation updates are also included.

Signed-off-by: Mat Booth <mat.booth@gmail.com>
2022-08-19 23:31:28 +10:00
Peter Hinch 42ec9703a0 extmod/modframebuf: Add ellipse drawing method. 2022-08-19 23:31:28 +10:00
Damien George cbc9f944c4 tests,tools: Update path to unix micropython executable.
These were missed by 47c84286e8

Signed-off-by: Damien George <damien@micropython.org>
2022-08-18 11:47:58 +10:00
Dan Ellis 6f4d424f46 py/formatfloat: Use pow(10, e) instead of pos/neg_pow lookup tables.
Rework the conversion of floats to decimal strings so it aligns precisely
with the conversion of strings to floats in parsenum.c.  This is to avoid
rendering 1eX as 9.99999eX-1 etc.  This is achieved by removing the power-
of-10 tables and using pow() to compute the exponent directly, and that's
done efficiently by first estimating the power-of-10 exponent from the
power-of-2 exponent in the floating-point representation.

Code size is reduced by roughly 100 to 200 bytes by this commit.

Signed-off-by: Dan Ellis <dan.ellis@gmail.com>
2022-08-12 23:53:34 +10:00
Ned Konz 5543b2a9cc extmod/uasyncio: Add clear method to ThreadSafeFlag.
This is useful in situations where the ThreadSafeFlag is reused and needs
to be cleared of any previous, unwanted event.

For example, clear the flag at the start of an operation, trigger the
operation (eg an I2C write), then (a)wait for an external event to set the
flag (eg a pin IRQ).  Further events may trigger the flag again but these
are unwanted and should be cleared before the next cycle starts.
2022-08-12 17:06:28 +10:00
Jim Mussared f694058f2b tests/extmod/ubinascii: Add tests for bytes.hex etc.
Also make the sep test not micropython-specific.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-08-12 12:44:30 +10:00
Andrew Leech f7f56d4285 py/objstr: Consolidate methods for str/bytes/bytearray/array.
This commit adds the bytes methods to bytearray, matching CPython.  The
existing implementations of these methods for str/bytes are reused for
bytearray with minor updates to match CPython return types.

For details on the CPython behaviour see
https://docs.python.org/3/library/stdtypes.html#bytes-and-bytearray-operations

The work to merge locals tables for str/bytes/bytearray/array was done by
@jimmo.  Because of this merging of locals the change in code size for this
commit is mostly negative:

       bare-arm:    +0 +0.000%
    minimal x86:   +29 +0.018%
       unix x64:  -792 -0.128% standard[incl -448(data)]
    unix nanbox:  -436 -0.078% nanbox[incl -448(data)]
          stm32:   -40 -0.010% PYBV10
         cc3200:   -32 -0.017%
        esp8266:   -28 -0.004% GENERIC
          esp32:   -72 -0.005% GENERIC[incl -200(data)]
         mimxrt:   -40 -0.011% TEENSY40
     renesas-ra:   -40 -0.006% RA6M2_EK
            nrf:   -16 -0.009% pca10040
            rp2:   -64 -0.013% PICO
           samd:  +148 +0.105% ADAFRUIT_ITSYBITSY_M4_EXPRESS
2022-08-11 23:18:02 +10:00
Damien George d53c3b6ade unix/variants: Remove variant suffix from executable filename.
The executable now lives in the build directory, and since the build
directory already contains the variant name there is no need to also add
it to the executable.

Signed-off-by: Damien George <damien@micropython.org>
2022-08-11 13:34:34 +10:00
Daniel Jour c7aa6a2c73 tests/run-tests.py: Provide better default MPYCROSS value for Windows. 2022-08-11 13:34:04 +10:00
Daniel Jour 47c84286e8 all: Fix paths to mpy-cross and micropython binaries.
Binaries built using the Make build system now no longer appear in the
working directory of the build, but rather in the build directory.  Thus
some paths had to be adjusted.
2022-08-11 13:31:13 +10:00
David Lechner 6baeded322 py/runtime: Fix crash in star arg unpacking.
The reallocation trigger for unpacking star args with unknown length
did not take into account the number of fixed args remaining. So it was
possible that the unpacked iterators could take up exactly the memory
allocated then nothing would be left for fixed args after the star args.
This causes a segfault crash.

This is fixed by taking into account the remaining number of fixed args
in the check to decide whether to realloc yet or not.

Signed-off-by: David Lechner <david@pybricks.com>
2022-08-06 11:32:58 -05:00
Damien George 963e599ec0 tests/cpydiff: Fix formatting of code snippet to use double quotes.
Signed-off-by: Damien George <damien@micropython.org>
2022-07-29 12:23:05 +10:00
Dan Ellis f9cbe6bc47 py/formatfloat: Format all whole-number floats exactly.
Formerly, py/formatfloat would print whole numbers inaccurately with
nonzero digits beyond the decimal place.  This resulted from its strategy
of successive scaling of the argument by 0.1 which cannot be exactly
represented in floating point.  The change in this commit avoids scaling
until the value is smaller than 1, so all whole numbers print with zero
fractional part.

Fixes issue #4212.

Signed-off-by: Dan Ellis dan.ellis@gmail.com
2022-07-26 22:23:47 +10:00
Jim Mussared b22abcdbbe extmod/uasyncio: Handle gather with no awaitables.
This previously resulted in gather() yielding but with no way to be
resumed.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-07-26 18:16:19 +10:00
Jim Mussared e65d1e69e8 py/modio: Remove FileIO and TextIOWrapper from io module.
On ports with more than one filesystem, the type will be wrong, for example
if using LFS but FAT enabled, then the type will be FAT.  So it's not
possible to use these classes to identify a file object type.

Furthermore, constructing an io.FileIO currently crashes on FAT, and
make_new isn't supported on LFS.

And the io.TextIOWrapper class does not match CPython at all.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-07-26 17:58:01 +10:00
Damien George c0fa903d6b py/compile: Support large integers in inline-asm data directive.
Fixes issue #8956.

Signed-off-by: Damien George <damien@micropython.org>
2022-07-26 12:24:50 +10:00
Damien George 4fe3e493b1 py/obj: Make mp_obj_get_complex_maybe call mp_obj_get_float_maybe first.
This commit simplifies mp_obj_get_complex_maybe() by first calling
mp_obj_get_float_maybe() to handle the cases corresponding to floats.
Only if that fails does it attempt to extra a full complex number.

This reduces code size and also means that mp_obj_get_complex_maybe() now
supports user-defined classes defining __float__; in particular this allows
user-defined classes to be used as arguments to cmath-module function.

Furthermore, complex_make_new() can now be simplified to directly call
mp_obj_get_complex(), instead of mp_obj_get_complex_maybe() followed by
mp_obj_get_float().  This also improves error messages from complex with
an invalid argument, it now raises "can't convert <type> to complex" rather
than "can't convert <type> to float".

Signed-off-by: Damien George <damien@micropython.org>
2022-07-25 16:11:26 +10:00
Andrew Leech 1e87b56219 py/obj: Add support for __float__ and __complex__ functions. 2022-07-25 14:23:34 +10:00
Carlosgg b41cfea02a extmod/modussl_mbedtls: Implement cert_reqs and cadata arguments.
Add cert_reqs and cadata keyword-args to ssl.wrap_socket() and
ssl.CERT_NONE, ssl.CERT_OPTIONAL, ssl.CERT_REQUIRED constants to allow
certificate validation.

CPython doesn't accept cadata in ssl.wrap_socket(), but it does in
SSLContext.load_verify_locations(), so we use this name to at least match
the same name in load_verify_locations().

Add docs for these new arguments, as well as docs for the existing
server_hostname argument which is important for certificate validation.

Tests are added as well.

Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
2022-07-20 16:46:04 +10:00
Damien George 18ecc29bb8 tests/extmod/ussl_basic: Make test run on axtls and mbedtls.
Fixes issue #4364.

Signed-off-by: Damien George <damien@micropython.org>
2022-07-18 18:12:39 +10:00
Lars Haulin 5bf3765631 py/objnamedtuple: Fix segfault with empty namedtuple.
The empty tuple is usually a constant object, but named tuples must be
allocated to allow modification.  Added explicit allocation to fix this.

Also added a regression test to verify creating an empty named tuple works.

Fixes issue #7870.

Signed-off-by: Lars Haulin <lars.haulin@gmail.com>
2022-07-13 16:25:35 +10:00
Jim Mussared 9714a0ead5 py/emitnative: Fix STORE_ATTR viper code-gen when value is not a pyobj.
There was a missing call to MP_F_CONVERT_NATIVE_TO_OBJ.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-07-12 17:18:27 +10:00
Damien George 932556d5fc tests/micropython: Add test for builtin execfile() function.
Signed-off-by: Damien George <damien@micropython.org>
2022-06-29 12:48:42 +10:00
Angus Gratton e024a4c59c tests: Fix run-perfbench parsing "no matching params" case.
Signed-off-by: Angus Gratton <gus@projectgus.com>
2022-06-28 14:22:06 +10:00
Angus Gratton ad308bc322 tests: Add an explanation of run-perfbench.py.
Also changes this file to a Markdown file.

Signed-off-by: Angus Gratton <gus@projectgus.com>
2022-06-28 14:21:41 +10:00
Angus Gratton 5568c324ba tests/perf_bench: Add some configurations for N=32, M=10.
For STM32L072 and similar, very low end targets.

The other perf_bench tests run out of memory, crash, or fail on
prerequisite features.

Signed-off-by: Angus Gratton <gus@projectgus.com>
2022-06-28 10:32:18 +10:00
Damien George e22b7fb4af py/objfun: Support function attributes on native functions.
Native functions can just reuse the bytecode function attribute code.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-25 00:22:15 +10:00
Damien George 268ec1e3eb tests/basics: Add tests for __name__ and __globals__ attrs on closures.
Signed-off-by: Damien George <damien@micropython.org>
2022-06-24 23:55:13 +10:00
Damien George db7682e02d extmod/uasyncio: Implement stream read(-1) to read all data up to EOF.
Fixes issue #6355.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-24 17:04:57 +10:00
Damien George 2a2589738c tests/extmod: Add heap-lock test for stream writing.
Signed-off-by: Damien George <damien@micropython.org>
2022-06-24 17:00:24 +10:00
Damien George 61ce260ff7 py/parsenum: Fix parsing of complex "j" and also "nanj", "infj".
Prior to this commit, complex("j") would return 0j, and complex("nanj")
would return nan+0j.  This commit makes sure "j" is tested for after
parsing the number (nan, inf or a decimal), and also supports the case of
"j" on its own.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-23 11:46:47 +10:00
Jim Mussared 0172292762 py/parsenum: Support parsing complex numbers of the form "a+bj".
To conform with CPython.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-06-23 11:46:47 +10:00
David Lechner a565811f23 extmod/modbtree: Use buffer protocol for keys/values.
This changes the btree implementation to use the buffer protocol for
reading key/values in all methods.  `str` and `bytes` objects are not the
only bytes-like objects that could be used.

Documentation and tests are also updated.

Addresses issue #8748.

Signed-off-by: David Lechner <david@pybricks.com>
2022-06-21 00:44:49 +10:00
Damien George a506335524 py/emit: Suppress unreachable bytecode/native code that follows jump.
This new logic tracks when an unconditional jump/raise occurs in the
emitted code stream (bytecode or native machine code) and suppresses all
subsequent code, until a label is assigned.  This eliminates a lot of
cases of dead code, with relatively simple logic.

This commit combined with the previous one (that removed the existing
dead-code finding logic) has the following code size change:

       bare-arm:   -16 -0.028%
    minimal x86:   -60 -0.036%
       unix x64:  -368 -0.070%
    unix nanbox:   -80 -0.017%
          stm32:  -204 -0.052% PYBV10
         cc3200:    +0 +0.000%
        esp8266:  -232 -0.033% GENERIC
          esp32:  -224 -0.015% GENERIC[incl -40(data)]
         mimxrt:  -192 -0.054% TEENSY40
     renesas-ra:  -200 -0.032% RA6M2_EK
            nrf:   +28 +0.015% pca10040
            rp2:  -256 -0.050% PICO
           samd:   -12 -0.009% ADAFRUIT_ITSYBITSY_M4_EXPRESS

Signed-off-by: Damien George <damien@micropython.org>
2022-06-20 22:28:18 +10:00
Damien George e85a096302 py/emit: Remove logic to detect last-emit-was-return-value.
This optimisation to remove dead code is not as good as it could be.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-20 22:28:18 +10:00
Damien George 182256dc13 tests/stress: Adjust bytecode_limit test so it can SKIP if no memory.
Signed-off-by: Damien George <damien@micropython.org>
2022-06-08 15:00:59 +10:00
Damien George 1d143cec63 tests/basics: Add .exp file for sys.tracebacklimit test.
The sys.tracebacklimit feature has changed semantics a bit from CPython 3.7
(in the way it modifies the output), so provide a .exp file for the test so
it doesn't rely on CPython.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-07 16:55:18 +10:00
Damien George b37b578214 py/persistentcode: Remove remaining native qstr linking support.
Support for architecture-specific qstr linking was removed in
d4d53e9e11, where native code was changed to
access qstr values via qstr_table.  The only remaining use for the special
qstr link table in persistentcode.c is to support native module written in
C, linked via mpy_ld.py.  But native modules can also use the standard
module-level qstr_table (and obj_table) which was introduced in the .mpy
file reworking in f2040bfc7e.

This commit removes the remaining native qstr liking support in
persistentcode.c's load_raw_code function, and adds two new relocation
options for constants.qstr_table and constants.obj_table.  mpy_ld.py is
updated to use these relocations options instead of the native qstr link
table.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-07 13:19:55 +10:00
Andrew Leech b7a39ad2d1 tests/run-multitests.py: Read IP address from boot nic if available.
This works if your network is pre-configured in boot.py as an object called
"nic".  Without this, multitests expects to access the WLAN/LAN class which
isn't always correct.

Signed-off-by: Andrew Leech <andrew@alelec.net>
2022-06-03 14:35:37 +10:00
Andrew Leech 73a1ea8812 tests/net_inet: Remove broken api.telegram.org from tests.
Signed-off-by: Andrew Leech <andrew@alelec.net>
2022-06-03 14:34:29 +10:00
Takeo Takahashi 19c680ff57 test/renesas-ra: Remove unsupported feature test of Pin.
Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
2022-06-03 10:58:16 +10:00
Damien George a1afb337d2 extmod/uasyncio: Fix edge case for cancellation of wait_for.
This fixes the cases where the task being waited on finishes just before or
just after the wait_for itself is cancelled.

Fixes issue #8717.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-02 17:14:20 +10:00
Damien George 065df5568c tests: Move native while test from pybnative to micropython.
And make it so this test can run on any target.

LED and time testing has been removed from this test, that can now be
tested using: ./run-tests.py --via-mpy --emit native.

Signed-off-by: Damien George <damien@micropython.org>
2022-05-26 12:54:43 +10:00
Damien George 20d9f3409a tests/run-tests.py: Add rp2 test target.
Signed-off-by: Damien George <damien@micropython.org>
2022-05-26 12:54:43 +10:00
Damien George 80a86c48e3 tests/micropython: Make import_mpy_native test run on all architectures.
Signed-off-by: Damien George <damien@micropython.org>
2022-05-26 12:54:43 +10:00
Damien George 3180113aef tests/micropython: Make import_mpy_native_gc run on ARMv6-M and above.
Signed-off-by: Damien George <damien@micropython.org>
2022-05-26 12:23:49 +10:00
robert-hh dd35f76db3 tests/run-multitests.py: Use LAN for IP address if WLAN doesn't exist.
This allows running the test on boards with just a LAN interface.

Fixes issue #8681.
2022-05-24 13:21:05 +10:00
iabdalkader beeb250d58 tests/multi_net: Fix TCP accept test when using system error numbers.
If a port is not using internal error numbers, which match both lwIP and
Linux error numbers, ENTOCONN from standard libraries errno.h equals 128,
not 107.
2022-05-24 13:15:22 +10:00
Damien George 5fa8ea1b8b tests/extmod: Change expected errno code from 36 to 30 in VfsLfs2 test.
Errno 30 is EROFS, which is now the correct value reported by littlefs 2.

Signed-off-by: Damien George <damien@micropython.org>
2022-05-24 12:52:00 +10:00
David Lechner d42d35f56d tests/run-tests.py: Enable `-X realtime` option for macOS tests.
This enables the new `-X realtime` runtime option when running tests on
macOS.  This causes MicroPython to configure all threads to be high
priority so that they are allowed to use high precision timers.  This
makes tests that depend on the passage of time more likely to succeed.

CI tests that were disabled because of this are now enabled again.

Signed-off-by: David Lechner <david@pybricks.com>
2022-05-24 00:52:44 +10:00
Damien George 7d3204783a tests/run-tests.py: Handle case where mpy-cross fails to compile script.
Signed-off-by: Damien George <damien@micropython.org>
2022-05-23 15:45:21 +10:00
Damien George a8492253c1 tests/basics: Unlock heap if skipping nanbox small-int test.
Signed-off-by: Damien George <damien@micropython.org>
2022-05-23 15:45:16 +10:00
Damien George 54ab9d23e9 tests/run-perfbench.py: Allow running tests via mpy and native emitter.
The performance benchmark tests now support `--via-mpy` and `--emit native`
on remote targets.  For example:

    $ ./run-perfbench.py -p --via-mpy --emit native 100 100

Signed-off-by: Damien George <damien@micropython.org>
2022-05-19 17:31:56 +10:00
Damien George 1786dacc83 tests/run-tests.py: Allow running tests via mpy-cross on remote targets.
This adds support for the `--via-mpy` and `--emit native` options when
running tests on remote targets (via pyboard.py).  It's now possible to do:

    $ ./run-tests.py --target pyboard --via-mpy
    $ ./run-tests.py --target pyboard --via-mpy --emit native

Signed-off-by: Damien George <damien@micropython.org>
2022-05-19 17:31:56 +10:00
Damien George 079f3e5e5b py/parse: Allow all constant objects to be used in "X = const(o)".
Now that constant tuples are supported in the parser, eg (1, True, "str"),
it's a small step to allow anything that is a constant to be used with the
pattern:

    from micropython import const

    X = const(obj)

This commit makes the required changes to allow the following types of
constants:

    from micropython import const

    _INT = const(123)
    _FLOAT = const(1.2)
    _COMPLEX = const(3.4j)
    _STR = const("str")
    _BYTES = const(b"bytes")
    _TUPLE = const((_INT, _STR, _BYTES))
    _TUPLE2 = const((None, False, True, ..., (), _TUPLE))

Prior to this, only integers could be used in const(...).

Signed-off-by: Damien George <damien@micropython.org>
2022-05-18 16:18:35 +10:00
Damien George 761d2f6741 tests/micropython: Add more test cases for native generators.
Signed-off-by: Damien George <damien@micropython.org>
2022-05-18 15:23:11 +10:00
Damien George 80938839c1 tests/extmod: Use bytearray instead of bytes for uctypes test.
Because the test modifies the (now) bytearray object, and if it's a bytes
object it's not guaranteed that it can be modified, or that this constant
object isn't used elsewhere.

Signed-off-by: Damien George <damien@micropython.org>
2022-05-18 15:23:11 +10:00
Damien George b3d0f5f67c tests/micropython: Fully unlink nested list in extreme exc test.
To make sure there are no dangling references to the lists, and the GC can
reclaim heap memory.

Signed-off-by: Damien George <damien@micropython.org>
2022-05-18 09:16:33 +10:00
Damien George 90682f43af py/compile: Allow new qstrs to be allocated at all compiler passes.
Prior to this commit, all qstrs were required to be allocated (by calling
mp_emit_common_use_qstr) in the MP_PASS_SCOPE pass (the first one).  But
this is an unnecessary restriction, which is lifted by this commit.
Lifting the restriction simplifies the compiler because it can allocate
qstrs in later passes.

This also generates better code, because in some cases (eg when a variable
is closed over) the scope of an identifier is not known until a bit later
and then the identifier no longer needs its qstr allocated in the global
table.

Code size is reduced for all ports with this commit.

Signed-off-by: Damien George <damien@micropython.org>
2022-05-17 23:39:22 +10:00
Damien George acfc3bbdf8 tests/multi_net: Skip SSL test if relevant modules aren't available.
Signed-off-by: Damien George <damien@micropython.org>
2022-05-17 14:25:51 +10:00
Damien George ab0a8f3086 tests/run-tests.py: Exclude settrace tests when using native emitter.
Signed-off-by: Damien George <damien@micropython.org>
2022-05-17 14:25:51 +10:00
Damien George 5f650b7b7a tests/thread: Use less resources for stress_aes if settrace enabled.
Signed-off-by: Damien George <damien@micropython.org>
2022-05-17 14:25:51 +10:00
Damien George 6f68a8c240 tests/run-perfbench.py: Return error code if any test fails on target.
Signed-off-by: Damien George <damien@micropython.org>
2022-05-17 14:06:41 +10:00
Damien George d7cf8a3b9d tests/perf_bench: Update .mpy file header to remove old unicode flag.
Signed-off-by: Damien George <damien@micropython.org>
2022-05-17 14:06:41 +10:00
Damien George c49d5207e9 py/persistentcode: Remove unicode feature flag from .mpy file.
Prior to this commit, even with unicode disabled .py and .mpy files could
contain unicode characters, eg by entering them directly in a string as
utf-8 encoded.

The only thing the compiler disallowed (with unicode disabled) was using
\uxxxx and \Uxxxxxxxx notation to specify a character within a string with
value >= 0x100; that would give a SyntaxError.

With this change mpy-cross will now accept \u and \U notation to insert a
character with value >= 0x100 into a string (because the -mno-unicode
option is now gone, there's no way to forbid this).  The runtime will
happily work with strings with such characters, just like it already works
with strings with characters that were utf-8 encoded directly.

This change simplifies things because there are no longer any feature
flags in .mpy files, and any bytecode .mpy will now run on any target.

Signed-off-by: Damien George <damien@micropython.org>
2022-05-17 12:51:54 +10:00
Damien George 8aa254c369 tests: Fix tests to use sys.implementation._mpy.
The field was renamed to _mpy in 59c5d41611

Signed-off-by: Damien George <damien@micropython.org>
2022-05-17 09:46:40 +10:00
Damien George fca5701f74 py/malloc: Introduce m_tracked_calloc, m_tracked_free functions.
Enabled by MICROPY_TRACKED_ALLOC.

Signed-off-by: Damien George <damien@micropython.org>
2022-05-05 10:31:50 +10:00
Damien George c90f097519 tests/extmod: Increase timing on uasyncio tests to make more reliable.
Non-real-time systems like Windows, Linux and macOS do not have reliable
timing, so increase the sleep intervals to make these tests more likely to
pass.

Signed-off-by: Damien George <damien@micropython.org>
2022-05-03 22:53:12 +10:00
Damien George 590de399f0 py/emitcommon: Don't implicitly close class vars that are assigned to.
When in a class body or at the module level don't implicitly close over
variables that have been assigned to.

Fixes issue #8603.

Signed-off-by: Damien George <damien@micropython.org>
2022-05-03 16:38:43 +10:00
Takeo Takahashi 3717d599e2 tests/run-tests.py: Update for renesas-ra port.
Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
2022-04-29 12:29:08 +09:00
Takeo Takahashi 4753913253 tests/renesas-ra: Add tests for renesas-ra port.
Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
2022-04-29 12:29:07 +09:00
Damien George 6bec5c4da5 tests/cmdline: Add test for REPL auto-indent.
Signed-off-by: Damien George <damien@micropython.org>
2022-04-22 17:00:16 +10:00
Damien George 28e7e15c0a extmod/uasyncio: Fix bug with task ending just after gather is cancel'd.
This fixes a bug where the gather is cancelled externally and then one of
its sub-tasks (that the gather was waiting on) finishes right between the
cancellation being queued and being executed.

Signed-off-by: Damien George <damien@micropython.org>
2022-04-21 14:25:17 +10:00
Damien George 8631753ff4 tests/run-tests.py: Add timeout for running PC-based MicroPython test.
So the test suite runs to completion, even if the interpreter locks up.

Signed-off-by: Damien George <damien@micropython.org>
2022-04-21 14:25:17 +10:00
Damien George ef1c2cdab0 tests/extmod/uasyncio_gather: Make double-raise gather test reliable.
This double-raise test could fail when task[0] raises and stops the gather
before task[1] raises, then task[1] is left to raise later on and spoil the
test.

Signed-off-by: Damien George <damien@micropython.org>
2022-04-20 19:32:49 +10:00
Jon Bjarni Bjarnason 1ded8a2977 py/objtype: Convert result of user __contains__ method to bool.
Per https://docs.python.org/3/reference/expressions.html#membership-test-operations

    For user-defined classes which define the contains() method, x in y
    returns True if y.contains(x) returns a true value, and False
    otherwise.

Fixes issue #7884.
2022-04-20 15:44:46 +10:00
Damien George 865b61dac2 tests/micropython: Add tests that const tuples don't use the heap.
Signed-off-by: Damien George <damien@micropython.org>
2022-04-15 00:17:02 +10:00
Damien George 999abbb8b5 tests/perf_bench: Update import tests for changes to .mpy consts.
Signed-off-by: Damien George <damien@micropython.org>
2022-04-14 23:52:14 +10:00
Damien George 35c0cff92b py/parse: Add MICROPY_COMP_CONST_TUPLE option to build const tuples.
This commit adds support to the parser so that tuples which contain only
constant elements (bool, int, str, bytes, etc) are immediately converted to
a tuple object.  This makes it more efficient to use tuples containing
constant data because they no longer need to be created at runtime by the
bytecode (or native code).

Furthermore, with this improvement constant tuples that are part of frozen
code are now able to be stored fully in ROM (this will be implemented in
later commits).

Code size is increased by about 400 bytes on Cortex-M4 platforms.

See related issue #722.

Signed-off-by: Damien George <damien@micropython.org>
2022-04-14 23:52:12 +10:00
Damien George 24bc1f61f9 py/parse: Print const object value in mp_parse_node_print.
To give more information when printing the parse tree.

Signed-off-by: Damien George <damien@micropython.org>
2022-04-14 22:45:42 +10:00
Christian Zietz d6c59c9d72 tests/inlineasm: Add test for PUSH LR and POP PC. 2022-04-11 15:35:42 +10:00
Jon Bjarni Bjarnason 919f696ad2 extmod/modusocket: Implement optional socket.listen backlog argument.
This follows the CPython change: https://bugs.python.org/issue21455

Socket listen backlog defaults to 2 if not given, based on most bare metal
targets not having many resources for a large backlog.  On UNIX it defaults
to SOMAXCONN or 128, whichever is less.
2022-04-11 15:26:47 +10:00
Damien George 71344c15f4 tests/pyb: Update CAN tests to match revised CAN API.
Signed-off-by: Damien George <damien@micropython.org>
2022-04-02 22:46:31 +11:00
Damien George 1dbf393962 tests/basics/fun_callstardblstar: Add test for large arg allocation.
Signed-off-by: Damien George <damien@micropython.org>
2022-04-01 09:20:42 +11:00
Damien George bd556b6996 py: Fix compiling and decoding of *args at large arg positions.
There were two issues with the existing code:

1. "1 << i" is computed as a 32-bit number so would overflow when
   executed on 64-bit machines (when mp_uint_t is 64-bit).  This meant that
   *args beyond 32 positions would not be handled correctly.

2. star_args must fit as a positive small int so that it is encoded
   correctly in the emitted code.  MP_SMALL_INT_BITS is too big because it
   overflows a small int by 1 bit.  MP_SMALL_INT_BITS - 1 does not work
   because it produces a signed small int which is then sign extended when
   extracted (even by mp_obj_get_int_truncated), and this sign extension
   means that any position arg after *args is also treated as a star-arg.
   So the maximum bit position is MP_SMALL_INT_BITS - 2.  This means that
   MP_OBJ_SMALL_INT_VALUE() can be used instead of
   mp_obj_get_int_truncated() to get the value of star_args.

These issues are fixed by this commit, and a test added.

Signed-off-by: Damien George <damien@micropython.org>
2022-04-01 09:20:42 +11:00
David Lechner 47685180f0 tests/basics/fun_callstardblstar: Add coverage test.
This fixes code coverage for the case where a *arg without __len__ is
unpacked and uses exactly the amount of memory that was allocated for
kw args. This triggers the code branch where the memory for the kw args
gets reallocated since it was used already by the *arg unpacking.

Signed-off-by: David Lechner <david@pybricks.com>
2022-03-31 17:01:15 +11:00
David Lechner 783b1a868f py/runtime: Allow multiple *args in a function call.
This is a partial implementation of PEP 448 to allow unpacking multiple
star args in a function or method call.

This is implemented by changing the emitted bytecodes so that both
positional args and star args are stored as positional args.  A bitmap is
added to indicate if an argument at a given position is a positional
argument or a star arg.

In the generated code, this new bitmap takes the place of the old star arg.
It is stored as a small int, so this means only the first N arguments can
be star args where N is the number of bits in a small int.

The runtime is modified to interpret this new bytecode format while still
trying to perform as few memory reallocations as possible.

Signed-off-by: David Lechner <david@pybricks.com>
2022-03-31 16:59:30 +11:00
David Lechner 1e99d29f36 py/runtime: Allow multiple **args in a function call.
This is a partial implementation of PEP 448 to allow multiple ** unpackings
when calling a function or method.

The compiler is modified to encode the argument as a None: obj key-value
pair (similar to how regular keyword arguments are encoded as str: obj
pairs).  The extra object that was pushed on the stack to hold a single **
unpacking object is no longer used and is removed.

The runtime is modified to decode this new format.

Signed-off-by: David Lechner <david@pybricks.com>
2022-03-31 16:54:00 +11:00
Damien George 90aaf2dbef extmod/uasyncio: Fix gather cancelling and handling of exceptions.
The following fixes are made:
- cancelling a gather now cancels all sub-tasks of the gather (previously
  it would only cancel the first)
- if any sub-task of a gather raises an exception then the gather finishes
  (previously it would only finish if the first sub-task raised)

Fixes issues #5798, #7807, #7901.

Signed-off-by: Damien George <damien@micropython.org>
2022-03-30 16:07:44 +11:00
Damien George 3e70be8ee9 tests/extmod: Update I2S rate test to work on mimxrt.
Tested on Teensy 4.0.

Signed-off-by: Damien George <damien@micropython.org>
2022-03-30 14:14:57 +11:00
Damien George 7266285845 tests/extmod: Add test for machine.I2S data rate.
Signed-off-by: Damien George <damien@micropython.org>
2022-03-29 11:44:08 +11:00
Damien George acd2c5c834 py/emitbc: Add check for bytecode jump offset overflow.
Signed-off-by: Damien George <damien@micropython.org>
2022-03-28 15:41:51 +11:00
Damien George 538c3c0a55 py: Change jump opcodes to emit 1-byte jump offset when possible.
This commit introduces changes:

- All jump opcodes are changed to have variable length arguments, of either
  1 or 2 bytes (previously they were fixed at 2 bytes).  In most cases only
  1 byte is needed to encode the short jump offset, saving bytecode size.

- The bytecode emitter now selects 1 byte jump arguments when the jump
  offset is guaranteed to fit in 1 byte.  This is achieved by checking if
  the code size changed during the last pass and, if it did (if it shrank),
  then requesting that the compiler make another pass to get the correct
  offsets of the now-smaller code.  This can continue multiple times until
  the code stabilises.  The code can only ever shrink so this iteration is
  guaranteed to complete.  In most cases no extra passes are needed, the
  original 4 passes are enough to get it right by the 4th pass (because the
  2nd pass computes roughly the correct labels and the 3rd pass computes
  the correct size for the jump argument).

This change to the jump opcode encoding reduces .mpy files and RAM usage
(when bytecode is in RAM) by about 2% on average.

The performance of the VM is not impacted, at least within measurment of
the performance benchmark suite.

Code size is reduced for builds that include a decent amount of frozen
bytecode.  ARM Cortex-M builds without any frozen code increase by about
350 bytes.

Signed-off-by: Damien George <damien@micropython.org>
2022-03-28 15:41:38 +11:00
David Lechner e7a92c0e69 tests/cmdline/cmd_showbc: Fix spelling of sequence. 2022-03-25 12:11:17 +11:00
Damien George 63f0e700f4 extmod/modure: Set subject begin_line so ^ doesn't match interior.
Fixes issue #8402.

Signed-off-by: Damien George <damien@micropython.org>
2022-03-16 12:21:00 +11:00
Damien George 3c7cab4e98 py/parse: Put const bytes objects in parse tree as const object.
Instead of as an intermediate qstr, which may unnecessarily intern the data
of the bytes object.

Signed-off-by: Damien George <damien@micropython.org>
2022-03-16 00:41:10 +11:00
Damien George ac2293161e py/modsys: Add optional mutable attributes sys.ps1/ps2 and use them.
This allows customising the REPL prompt strings.

Signed-off-by: Damien George <damien@micropython.org>
2022-03-10 10:58:33 +11:00
Damien George cac939ddc3 py/modsys: Add optional sys.tracebacklimit attribute.
With behaviour as per CPython.

Signed-off-by: Damien George <damien@micropython.org>
2022-03-10 10:43:21 +11:00
Damien George d470c5a5ba tests/extmod/vfs_posix.py: Only test statvfs if it exists.
Signed-off-by: Damien George <damien@micropython.org>
2022-03-10 00:41:03 +11:00
Damien George 3440201e2e tests/micropython: Switch from set.pop to raise-0 to test exc strings.
To not rely on sets, which are an optional feature.

Signed-off-by: Damien George <damien@micropython.org>
2022-03-07 16:48:35 +11:00
Damien George 9a8ee6a5df tests/run-tests.py: Include test files ending in _set as set tests.
Signed-off-by: Damien George <damien@micropython.org>
2022-03-07 16:48:35 +11:00
Damien George 7cd166ff92 tests/basics: Add test for creating small-ints in nan-box builds.
Signed-off-by: Damien George <damien@micropython.org>
2022-03-07 15:25:11 +11:00
Damien George c4b8dae438 tests/unix: Add coverage test for freezing various objects.
Signed-off-by: Damien George <damien@micropython.org>
2022-02-28 19:02:58 +11:00
Damien George 414b59d39c qemu-arm: Add tests for freezing viper and asm_thumb code.
Signed-off-by: Damien George <damien@micropython.org>
2022-02-24 18:29:02 +11:00
Damien George 0a2895b099 tests/perf_bench: Skip bm_chaos test if random.randrange is unavailable.
Signed-off-by: Damien George <damien@micropython.org>
2022-02-24 18:29:02 +11:00
Damien George f2040bfc7e py: Rework bytecode and .mpy file format to be mostly static data.
Background: .mpy files are precompiled .py files, built using mpy-cross,
that contain compiled bytecode functions (and can also contain machine
code). The benefit of using an .mpy file over a .py file is that they are
faster to import and take less memory when importing.  They are also
smaller on disk.

But the real benefit of .mpy files comes when they are frozen into the
firmware.  This is done by loading the .mpy file during compilation of the
firmware and turning it into a set of big C data structures (the job of
mpy-tool.py), which are then compiled and downloaded into the ROM of a
device.  These C data structures can be executed in-place, ie directly from
ROM.  This makes importing even faster because there is very little to do,
and also means such frozen modules take up much less RAM (because their
bytecode stays in ROM).

The downside of frozen code is that it requires recompiling and reflashing
the entire firmware.  This can be a big barrier to entry, slows down
development time, and makes it harder to do OTA updates of frozen code
(because the whole firmware must be updated).

This commit attempts to solve this problem by providing a solution that
sits between loading .mpy files into RAM and freezing them into the
firmware.  The .mpy file format has been reworked so that it consists of
data and bytecode which is mostly static and ready to run in-place.  If
these new .mpy files are located in flash/ROM which is memory addressable,
the .mpy file can be executed (mostly) in-place.

With this approach there is still a small amount of unpacking and linking
of the .mpy file that needs to be done when it's imported, but it's still
much better than loading an .mpy from disk into RAM (although not as good
as freezing .mpy files into the firmware).

The main trick to make static .mpy files is to adjust the bytecode so any
qstrs that it references now go through a lookup table to convert from
local qstr number in the module to global qstr number in the firmware.
That means the bytecode does not need linking/rewriting of qstrs when it's
loaded.  Instead only a small qstr table needs to be built (and put in RAM)
at import time.  This means the bytecode itself is static/constant and can
be used directly if it's in addressable memory.  Also the qstr string data
in the .mpy file, and some constant object data, can be used directly.
Note that the qstr table is global to the module (ie not per function).

In more detail, in the VM what used to be (schematically):

    qst = DECODE_QSTR_VALUE;

is now (schematically):

    idx = DECODE_QSTR_INDEX;
    qst = qstr_table[idx];

That allows the bytecode to be fixed at compile time and not need
relinking/rewriting of the qstr values.  Only qstr_table needs to be linked
when the .mpy is loaded.

Incidentally, this helps to reduce the size of bytecode because what used
to be 2-byte qstr values in the bytecode are now (mostly) 1-byte indices.
If the module uses the same qstr more than two times then the bytecode is
smaller than before.

The following changes are measured for this commit compared to the
previous (the baseline):
- average 7%-9% reduction in size of .mpy files
- frozen code size is reduced by about 5%-7%
- importing .py files uses about 5% less RAM in total
- importing .mpy files uses about 4% less RAM in total
- importing .py and .mpy files takes about the same time as before

The qstr indirection in the bytecode has only a small impact on VM
performance.  For stm32 on PYBv1.0 the performance change of this commit
is:

diff of scores (higher is better)
N=100 M=100             baseline -> this-commit  diff      diff% (error%)
bm_chaos.py               371.07 ->  357.39 :  -13.68 =  -3.687% (+/-0.02%)
bm_fannkuch.py             78.72 ->   77.49 :   -1.23 =  -1.563% (+/-0.01%)
bm_fft.py                2591.73 -> 2539.28 :  -52.45 =  -2.024% (+/-0.00%)
bm_float.py              6034.93 -> 5908.30 : -126.63 =  -2.098% (+/-0.01%)
bm_hexiom.py               48.96 ->   47.93 :   -1.03 =  -2.104% (+/-0.00%)
bm_nqueens.py            4510.63 -> 4459.94 :  -50.69 =  -1.124% (+/-0.00%)
bm_pidigits.py            650.28 ->  644.96 :   -5.32 =  -0.818% (+/-0.23%)
core_import_mpy_multi.py  564.77 ->  581.49 :  +16.72 =  +2.960% (+/-0.01%)
core_import_mpy_single.py  68.67 ->   67.16 :   -1.51 =  -2.199% (+/-0.01%)
core_qstr.py               64.16 ->   64.12 :   -0.04 =  -0.062% (+/-0.00%)
core_yield_from.py        362.58 ->  354.50 :   -8.08 =  -2.228% (+/-0.00%)
misc_aes.py               429.69 ->  405.59 :  -24.10 =  -5.609% (+/-0.01%)
misc_mandel.py           3485.13 -> 3416.51 :  -68.62 =  -1.969% (+/-0.00%)
misc_pystone.py          2496.53 -> 2405.56 :  -90.97 =  -3.644% (+/-0.01%)
misc_raytrace.py          381.47 ->  374.01 :   -7.46 =  -1.956% (+/-0.01%)
viper_call0.py            576.73 ->  572.49 :   -4.24 =  -0.735% (+/-0.04%)
viper_call1a.py           550.37 ->  546.21 :   -4.16 =  -0.756% (+/-0.09%)
viper_call1b.py           438.23 ->  435.68 :   -2.55 =  -0.582% (+/-0.06%)
viper_call1c.py           442.84 ->  440.04 :   -2.80 =  -0.632% (+/-0.08%)
viper_call2a.py           536.31 ->  532.35 :   -3.96 =  -0.738% (+/-0.06%)
viper_call2b.py           382.34 ->  377.07 :   -5.27 =  -1.378% (+/-0.03%)

And for unix on x64:

diff of scores (higher is better)
N=2000 M=2000        baseline -> this-commit     diff      diff% (error%)
bm_chaos.py          13594.20 ->  13073.84 :  -520.36 =  -3.828% (+/-5.44%)
bm_fannkuch.py          60.63 ->     59.58 :    -1.05 =  -1.732% (+/-3.01%)
bm_fft.py           112009.15 -> 111603.32 :  -405.83 =  -0.362% (+/-4.03%)
bm_float.py         246202.55 -> 247923.81 : +1721.26 =  +0.699% (+/-2.79%)
bm_hexiom.py           615.65 ->    617.21 :    +1.56 =  +0.253% (+/-1.64%)
bm_nqueens.py       215807.95 -> 215600.96 :  -206.99 =  -0.096% (+/-3.52%)
bm_pidigits.py        8246.74 ->   8422.82 :  +176.08 =  +2.135% (+/-3.64%)
misc_aes.py          16133.00 ->  16452.74 :  +319.74 =  +1.982% (+/-1.50%)
misc_mandel.py      128146.69 -> 130796.43 : +2649.74 =  +2.068% (+/-3.18%)
misc_pystone.py      83811.49 ->  83124.85 :  -686.64 =  -0.819% (+/-1.03%)
misc_raytrace.py     21688.02 ->  21385.10 :  -302.92 =  -1.397% (+/-3.20%)

The code size change is (firmware with a lot of frozen code benefits the
most):

       bare-arm:  +396 +0.697%
    minimal x86: +1595 +0.979% [incl +32(data)]
       unix x64: +2408 +0.470% [incl +800(data)]
    unix nanbox: +1396 +0.309% [incl -96(data)]
          stm32: -1256 -0.318% PYBV10
         cc3200:  +288 +0.157%
        esp8266:  -260 -0.037% GENERIC
          esp32:  -216 -0.014% GENERIC[incl -1072(data)]
            nrf:  +116 +0.067% pca10040
            rp2:  -664 -0.135% PICO
           samd:  +844 +0.607% ADAFRUIT_ITSYBITSY_M4_EXPRESS

As part of this change the .mpy file format version is bumped to version 6.
And mpy-tool.py has been improved to provide a good visualisation of the
contents of .mpy files.

In summary: this commit changes the bytecode to use qstr indirection, and
reworks the .mpy file format to be simpler and allow .mpy files to be
executed in-place.  Performance is not impacted too much.  Eventually it
will be possible to store such .mpy files in a linear, read-only, memory-
mappable filesystem so they can be executed from flash/ROM.  This will
essentially be able to replace frozen code for most applications.

Signed-off-by: Damien George <damien@micropython.org>
2022-02-24 18:08:43 +11:00
stijn ff9c708507 tests/run-tests.py: Skip repl tests when running windows underneath.
Some versions of Python (for instance: the mingw-w64 version which can be
installed on MSYS2) do include a pty module and claim to be posix-like
(os.name == 'posix'), yet the select.select call used in run-tests.py hangs
forever.  To be on the safe side just exclude anything which might be
running on windows.
2022-02-18 15:14:47 +11:00
Damien George 2ea21abae0 tests/extmod/vfs_fat_finaliser.py: Make finalisation more robust.
Signed-off-by: Damien George <damien@micropython.org>
2022-02-12 09:45:32 +11:00
Damien George e8bc4a3a5b tests/run-perfbench.py: Use SKIP consistently, and increase print width.
A script will print "SKIP" if it wants to be skipped, so the test runner
must also use uppercase SKIP.

Signed-off-by: Damien George <damien@micropython.org>
2022-02-11 22:19:38 +11:00
Damien George a434705700 tests/perf_bench: Add perf test for yield-from execution.
Signed-off-by: Damien George <damien@micropython.org>
2022-02-11 13:42:00 +11:00
Damien George 75da124cf8 tests/perf_bench: Add perf tests for qstr interning and importing .mpy.
Signed-off-by: Damien George <damien@micropython.org>
2022-02-10 15:25:33 +11:00
Damien George b33fdbe535 tests/run-perfbench.py: Allow a test to SKIP, and to have a .exp file.
Signed-off-by: Damien George <damien@micropython.org>
2022-02-10 15:25:33 +11:00
iabdalkader 30a022548f tests/multi_net/udp_data.py: Make UDP test more reliable.
The current test depends on a specific number and order of packets to pass,
which can't be reproduced every run due to the unreliable UDP protocol.
This patch adds simple packets sequencing, retransmits with timeouts, and a
packet loss threshold, to make the test more tolerant to UDP protocol
packet drops and reordering.
2022-02-09 14:05:01 +11:00
Damien George ab2923dfa1 all: Update Python formatting to latest Black version 22.1.0.
Signed-off-by: Damien George <damien@micropython.org>
2022-02-02 16:49:55 +11:00
Christian Decker 2e3a2785cd extmod/modubinascii: Add newline keyword to b2a_base64 function.
This allows encoding things (eg a Basic-Auth header for a request) without
slicing the \n from the string, which allocates additional memory.

Co-authored-by: David Lechner <david@lechnology.com>
2022-01-23 10:18:01 +11:00
stijn dd6967202a py/modmath: Add math.tau, math.nan and math.inf constants.
Configurable by the new MICROPY_PY_MATH_CONSTANTS option.
2022-01-23 09:28:33 +11:00
iabdalkader 6e8f4eaa52 tests/multi_net/udp_data.py: Allow reusing port before bind. 2022-01-21 13:34:33 +11:00
iabdalkader e6ddda29ca tests/multi_net: Close accepted sockets when tests are done.
gc_sweep_all() cleans up sockets via the finaliser, but tests should
cleanly free resources they use.
2022-01-21 13:34:20 +11:00
Jeff Epler 037b2c72a1 py/objstr: Support '{:08}'.format("Jan") like Python 3.10.
The new test has an .exp file, because it is not compatible with Python 3.9
and lower.

See CPython version of the issue at https://bugs.python.org/issue27772

Signed-off-by: Jeff Epler <jepler@gmail.com>
2022-01-19 15:34:32 +11:00
Damien George 2c9dc5742a tests/multi_net: Add testing key/cert to SSL server/client test.
So that this tests works with mbedtls.

Signed-off-by: Damien George <damien@micropython.org>
2022-01-17 17:35:04 +11:00
Damien George c54717a78f tests/run-multitests.py: Set HOST_IP so tests work between PC and board.
Signed-off-by: Damien George <damien@micropython.org>
2022-01-17 17:35:04 +11:00
Damien George 5df1d8be6c tests/run-multitests.py: Ignore lld_pdu_get_tx_flush_nb msgs from IDF.
BLE still functions correctly even though these messages are sometimes
printed by the IDF.  Ignoring them allows the multi_bluetooth tests to pass
on an esp32 board.

Signed-off-by: Damien George <damien@micropython.org>
2022-01-17 14:23:24 +11:00
stijn 19d949a866 tests/extmod: Skip uselect_poll_udp when poll() is not available.
This is the same fix as applied in uselect_poll_basic.py.
2022-01-04 15:07:45 +11:00
Damien George aac5a97d08 ports: Move '.frozen' to second entry in sys.path.
In commit 86ce442607 the '.frozen' entry was
added at the start of sys.path, to allow control over when frozen modules
are searched during import, and retain existing behaviour whereby frozen
was searched before the filesystem.

But Python semantics of sys.path require sys.path[0] to be the directory of
the currently executing script, or ''.

This commit moves the '.frozen' entry to second place in sys.path, so
sys.path[0] retains its correct value (described above).

Signed-off-by: Damien George <damien@micropython.org>
2021-12-29 23:55:36 +11:00
Damien George c768704cfd tests/basics/int_big_cmp.py: Add more tests for big-int comparison.
To improve coverage of mpz_cmp and mpn_cmp.

Signed-off-by: Damien George <damien@micropython.org>
2021-12-21 18:00:11 +11:00
Damien George 2c139bbf4e py/mpz: Fix bugs with bitwise of -0 by ensuring all 0's are positive.
This commit makes sure that the value zero is always encoded in an mpz_t as
neg=0 and len=0 (previously it was just len=0).

This invariant is needed for some of the bitwise operations that operate on
negative numbers, because they cannot handle -0.  For example
(-((1<<100)-(1<<100)))|1 was being computed as -65535, instead of 1.

Fixes issue #8042.

Signed-off-by: Damien George <damien@micropython.org>
2021-12-21 18:00:05 +11:00
Jim Mussared cc23e99f32 py/modio: Remove io.resource_stream function.
This feature is not enabled on any port, it's not in CPython's io module,
and functionality is better suited to the micropython-lib implementation of
pkg_resources.
2021-12-17 23:53:44 +11:00
Jim Mussared 3770fab334 all: Update Python formatting to latest Black version 21.12b0.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-12-09 12:09:40 +11:00
Jim Mussared e99f7b6d25 tests/cpydiff: Clarify f-string diffs regarding concatenation.
Concatenation of any literals (including f-strings) should be avoided.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-11-25 22:09:59 +11:00
Damien George 11ed94797d py/lexer: Support nested [] and {} characters within f-string params.
Signed-off-by: Damien George <damien@micropython.org>
2021-11-25 21:50:58 +11:00
Damien George 78ab2eeda3 py/showbc: Print unary-op string when dumping bytecode.
Signed-off-by: Damien George <damien@micropython.org>
2021-11-19 17:05:40 +11:00
jc_.kim 19f09414a6 tests/micropython/const.py: Add comment about required config for test.
Expected result of const.py will be matched only when MICROPY_COMP_CONST is
enabled.  For easy understanding, added description at the first of the
test code.
2021-11-17 14:28:20 +11:00
Damien George 43d08688c3 extmod/uasyncio: Fix gather returning exceptions from a cancelled task.
Fixes issue #5882.
2021-11-17 14:11:31 +11:00