.. from non UTF-8 inputs. In this case, MicroPython raises
UnicodeError while CPython uses SyntaxError. By catching either
exception, the test does not require an .exp file.
Signed-off-by: Jeff Epler <jepler@gmail.com>
ringbuffer.size must be at least 2, and is a 16-bit quantity.
This fixes several cases including the one the fuzzer discovered, which
would lead to a fatal signal when accessing the object.
Fixes issue #17847.
Signed-off-by: Jeff Epler <jepler@gmail.com>
If mp_int_t is wider than int, then the tests such as `xend < 0` can fail
even when the amount of scrolling requested is out of range. This resulted
in a segmentation fault when attempting an out-of-bounds access to the
framebuffer.
Signed-off-by: Jeff Epler <jepler@gmail.com>
Previously, any test needing an SSL certificate file would automatically
skip if the file could not be found. But that makes it too easy to
accidentally skip tests.
Instead, change it so that the test fails if the certificate file doesn't
exist. That matches, for example, the fact that the test fails if
networking (LAN, WiFi) is not active.
Signed-off-by: Damien George <damien@micropython.org>
There are currently a few tests that are excluded when using the native
emitter because they test printing of exception tracebacks, which includes
line numbers. And the native emitter doesn't store line numbers, so gets
these tests wrong.
But we'd still like to run these tests using the native emitter, because
they test useful things even if the line number info is not in the
traceback (eg that threads which crash print out their exception).
This commit adds support for native-specific .exp files, which are of the
form `<test>.py.native.exp`. If such an .exp file exists then it take
precedence over any normal `<test>.py.exp` file.
(Actually, the implementation here is general enough that it also supports
`<test>.py.bytecode.exp` as well, if bytecode ever needs a specific exp
file.)
Signed-off-by: Damien George <damien@micropython.org>
This cleans up the test to remove all unused code, making it smaller,
a bit faster to deploy to a target to run, and also use less RAM on the
target (which may help it run on targets that are just slightly out of
memory running it).
Signed-off-by: Damien George <damien@micropython.org>
Instead of using a feature check. This is more consistent with how other
optional modules are skipped.
Signed-off-by: Damien George <damien@micropython.org>
The unicode tests are now run on all targets that enable unicode. And
other unicode tests (namely `extmod/json_loads.py`) are now properly
skipped if the target doesn't have unicode support.
Signed-off-by: Damien George <damien@micropython.org>
Ports that now run the stress tests, that didn't prior to this commit are:
cc3200, esp8266, minimal, nrf, renesas-ra, samd, qemu, webassembly.
Signed-off-by: Damien George <damien@micropython.org>
This simplifies the code by removing the explicit addition of the "float/"
test directory for certain targets. It also means the tests won't be added
incorrectly, eg on a unix build without float.
Signed-off-by: Damien George <damien@micropython.org>
This commit provides an implementation for viper boundary tests that can
work even without big int support.
Since it uses a fixed-size buffer to hold values to work with, this
should work on any platform as long as its integers are at least 32 bits
wide, regardless its configuration on how big integers can get.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Pattern objects have two additional parameters for the ::search and ::match
methods to define the starting and ending position of the subject within
the string to be searched.
This allows for searching a sub-string without creating a slice. However,
one caveat of using the start-pos rather than a slice is that the start
anchor (`^`) remains anchored to the beginning of the text.
Signed-off-by: Jared Hancock <jared@greezybacon.me>
Some tests (currently given by the `special_tests` list) have output which
must be mached via a regex, because it can change from run to run (eg the
address of an object is printed). These tests are currently classified as
`is_special` in the test runner, which means they get special treatment.
In particular they don't set the emitter as specified by `args.emit`. That
means these tests do not run via .mpy or using the native emitter, even if
those options are given on the command line.
This commit fixes that by considering `is_special` as different to
`tests_with_regex_output`. The former is used for things like target
feature detection (which are not really tests) and when extra command line
options need to be passed to the unix micropython executable. The latter
(now called `tests_with_regex_output`) are specifically for tests that have
output to be matched via regex.
The `thread_exc2.py` test now needs to be excluded when running using the
native emitter, because the native emitter doesn't print traceback info.
And the `sys_settrace_cov.py` test needs to be excluded because set-trace
output is different with the native emitter.
Signed-off-by: Damien George <damien@micropython.org>
This makes `run-tests.py` a little more organised, by putting all the
tests-to-skip-when-using-the-native-emitter in a dedicated list.
This should make it easier to maintain the list, and understand why a test
is there.
Signed-off-by: Damien George <damien@micropython.org>
These don't test any advanced features, just the basics.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This test uses a SoftI2C controller wired to an I2CTarget on the one board,
and tests all functionality of the I2CTarget class.
Signed-off-by: Damien George <damien@micropython.org>
When running the viper boundary tests, assert that the offset stores don't
clobber the base register, which is saved and temporarily modified on some
architectures.
Signed-off-by: Chris Webb <chris@arachsys.com>
Add a new MICROPY_COMP_CONST_FLOAT feature, enabled by in mpy-cross and
when compiling with MICROPY_CONFIG_ROM_LEVEL_CORE_FEATURES. The new
feature leverages the code of MICROPY_COMP_CONST_FOLDING to support folding
of floating point constants.
If MICROPY_COMP_MODULE_CONST is defined as well, math module constants are
made available at compile time. For example:
_DEG_TO_GRADIANT = const(math.pi / 180)
_INVALID_VALUE = const(math.nan)
A few corner cases had to be handled:
- The float const folding code should not fold expressions resulting into
complex results, as the mpy parser for complex immediates has
limitations.
- The constant generation code must distinguish between -0.0 and 0.0, which
are different even if C consider them as ==.
This change removes previous limitations on the use of `const()`
expressions that would result in floating point number, so the test cases
of micropython/const_error have to be updated.
Additional test cases have been added to cover the new repr() code (from a
previous commit). A few other simple test cases have been added to handle
the use of floats in `const()` expressions, but the float folding code
itself is also tested when running general float test cases, as float
expressions often get resolved at compile-time (with this change).
Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
Since commit dbbaa959c8, this test now
produces the same output on MicroPython as CPython does, namely -1e+01.
Signed-off-by: Damien George <damien@micropython.org>
Following discussions in PR #16666, this commit updates the float
formatting code to improve the `repr` reversibility, i.e. the percentage of
valid floating point numbers that do parse back to the same number when
formatted by `repr` (in CPython it's 100%).
This new code offers a choice of 3 float conversion methods, depending on
the desired tradeoff between code size and conversion precision:
- BASIC method is the smallest code footprint
- APPROX method uses an iterative method to approximate the exact
representation, which is a bit slower but but does not have a big impact
on code size. It provides `repr` reversibility on >99.8% of the cases in
double precision, and on >98.5% in single precision (except with REPR_C,
where reversibility is 100% as the last two bits are not taken into
account).
- EXACT method uses higher-precision floats during conversion, which
provides perfect results but has a higher impact on code size. It is
faster than APPROX method, and faster than the CPython equivalent
implementation. It is however not available on all compilers when using
FLOAT_IMPL_DOUBLE.
Here is the table comparing the impact of the three conversion methods on
code footprint on PYBV10 (using single-precision floats) and reversibility
rate for both single-precision and double-precision floats. The table
includes current situation as a baseline for the comparison:
PYBV10 REPR_C FLOAT DOUBLE
current = 364688 12.9% 27.6% 37.9%
basic = 364812 85.6% 60.5% 85.7%
approx = 365080 100.0% 98.5% 99.8%
exact = 366408 100.0% 100.0% 100.0%
Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
This reduces memory use by reusing objects, and improves identity/equality
relationships of JavaScript objects on the Python side.
In 77bd8fe5b8 PyProxy's were reused when the
same Python object was proxied across to JavaScript. This commit does the
same thing but for JsProxy's going from JS to Python. If an existing
JsProxy reference exists for the JS object about to be proxied across, then
it's reused.
This helps reduce the number of alive objects (memory use), and, more
importantly, improves equality relationships of JavaScript objects on the
Python side. Eg we now get, on the Python side:
import js
print(js.Object == js.Object)
that prints True. Previously it was False.
Note that this change does not make identity work with `is`, for example
`js.Object is js.Object` is actually False. With more work that could be
made True but for now we leave that as-is.
The behaviour with this commit matches Pyodide semantics.
Signed-off-by: Damien George <damien@micropython.org>
It's possible for a test to output non-ASCII characters (for example, due
to a hard fault or serial noise or memory corruption). Rather than crashing
the test runner, backslash escape those characters and treat them as
program output.
Refactors the string encoding step to a single helper to avoid copy-paste.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
As per comment, if a boot.py is present that connects to Wi-Fi then waking
can take a little longer.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This follows a similar change made for `run-tests.py` in commit
229104558f. The change here uses the same
logic to detect if a natmod test is too big for the target (eg overflows
(I)RAM loading the native .mpy), by printing "START TEST" at the start of
the test.
Typical output is now something like this:
...
pass extmod/random_basic.py
pass extmod/random_extra_float.py
pass extmod/random_extra.py
SKIP extmod/random_seed_default.py
LRGE extmod/re1.py
SKIP extmod/re_debug.py
pass extmod/re_error.py
pass extmod/re_group.py
pass extmod/re_groups.py
...
and the tests that are too large are reported at the end, and written to
the `_result.json` file.
Signed-off-by: Damien George <damien@micropython.org>
Includes:
esp32/esp32c2: Adapt to target chip ESP32C2.
esp32/esp32c2: Fix heap size is too small to enable Bluetooth.
Signed-off-by: TianShuangKe <qinyun575@gmail.com>
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Including the stochastic tests needed to guarantee sensitivity to the
potential iterate-while-modifying hazard a naive implementation might have.
Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
Current longlong implementation does not allow a float as RHS of mathematic
operators, as it lacks the delegation code present in mpz.
Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
This is to fix an outstanding TODO. The test cases is using a range as
this will exist in all builds, but `mp_obj_get_int` is used in many
different parts of code where an overflow is more likely to occur.
Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
These tests all depend on generating arbitrarily long (>64-bit) integers.
It would be possible to have these tests work in this case I think, as the
results are always masked to shorter values. But quite fiddly. So just
rename them so they are automatically skipped if the target doesn't have
big int support.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
The recently merged 5e9189d6d1 now allows
temporary slices to be allocated on the C stack, which is much better than
allocating them on the GC heap.
Unfortunately there are cases where the C-allocated slice can escape and be
retained as an object, which leads to crashes (because that object points
to the C stack which now has other values on it).
The fix here is to add a new `MP_TYPE_FLAG_SUBSCR_ALLOWS_STACK_SLICE`.
Native types should set this flag if their subscr method is guaranteed not
to hold on to a reference of the slice object.
Fixes issue #17733 (see also #17723).
Signed-off-by: Damien George <damien@micropython.org>
Fixes a bug in the binding of self/this to JavaScript methods.
The new semantics match Pyodide's behaviour, at least for the included
tests.
Signed-off-by: Damien George <damien@micropython.org>
Commit dc2fcfcc55 seems to have accidentally
changed the ruff quote style to "preserve", instead of keeping it at the
default which is "double".
Put it back to the default and update relevant .py files with this rule.
Signed-off-by: Damien George <damien@micropython.org>
Current implementation of REPR_C works by clearing the two lower bits of
the mantissa to zero. As this happens after each floating point operation,
this tends to bias floating point numbers towards zero, causing decimals
like .9997 instead of rounded numbers. This is visible in test cases
involving repeated computations, such as `tests/misc/rge_sm.py` for
instance.
The suggested fix fills in the missing bits by copying the previous two
bits. Although this cannot recreate missing information, it fixes the bias
by inserting plausible values for the lost bits, at a relatively low cost.
Some float tests involving irrational numbers have to be softened in case
of REPR_C, as the 30 bits are not always enough to fulfill the expectations
of the original test, and the change may randomly affect the last digits.
Such cases have been made explicit by testing for REPR_C or by adding a
clear comment.
The perf_test fft code was also missing a call to round() before casting a
log_2 operation to int, which was causing a failure due to a last-decimal
change.
Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
The original version of this test had to exchange a 1 byte UDP packet
before the DTLS handshake. This is no longer needed due to MSG_PEEK
support.
The test also doesn't work with HelloVerify enabled, as the first
connection attempt always fails with an
MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED result. Anticipate this by listening
for the client twice on the server side.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
- DTLS spec recommends HelloVerify and Anti Replay protection be enabled,
and these are enabled in the default mbedTLS config. Implement them here.
- To help compensate for the possible increase in code size, add a
MICROPY_PY_SSL_DTLS build config macro that's enabled for EXTRA and
above by default.
This allows bare metal mbedTLS ports to use DTLS with HelloVerify support.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
With the recent update to ESP-IDF 5.4.2, there is a change in BLE event
behaviour which makes `tests/multi_bluetooth/ble_mtu.py` and
`tests/multi_bluetooth/ble_mtu_peripheral.py` now fail on ESP32 with IDF
5.4.2.
The change in behaviour is that MTU_EXCHANGE events can now occur before
CENTRAL_CONNECT/PERIPHERAL_CONNECT events. That seems a bit strange,
because the MTU exchange occurs after the connection. And looking at the
timing of the events there is exactly 100ms between them, ie MTU_EXCHANGE
fires and then exactly 100ms later CENTRAL_CONNECT/PERIPHERAL_CONNECT
fires.
It's unknown if this is a bug in (Espressif's) NimBLE, a subtle change in
scheduling with still valid behaviour, an intended change, a change allowed
under the BLE spec, or something else.
But in order to move forward with updating to IDF 5.4.2, the relevant tests
have been adjusted so they can pass. The test just needs to wait a bit
between doing the connect and doing the MTU exchange, so the other side
sees the original/correct ordering of events. This wait is done using the
multitest synchronisation primitives (broadcast and wait).
Signed-off-by: Damien George <damien@micropython.org>
This parameter is already used for PC-based tests (eg unix and webassembly
ports), and it makes sense for it to be used for bare-metal ports as well.
That way the timeout is configurable for all targets.
Because this increases the default timeout from 10s to 30s, this fixes some
long-running tests that would previously fail due to a timeout such as
`thread/stress_aes.py` on ESP32.
Signed-off-by: Damien George <damien@micropython.org>
The native emitter will not release/bounce the GIL when running code, so
if it runs tight loops then no other threads get a chance to run (if the
GIL is enabled). So for the thread tests, explicitly include a call to
`time.sleep(0)` (or equivalent) to bounce the GIL and give other threads a
chance to run.
For some tests (eg `thread_coop.py`) the whole point of the test is to test
that the GIL is correctly bounced. So for those cases force the use of the
bytecode emitter for the busy functions.
Signed-off-by: Damien George <damien@micropython.org>