summaryrefslogtreecommitdiff
path: root/tests/micropython
AgeCommit message (Collapse)Author
2020-08-02py/persistentcode: Maintain root ptr list of imported native .mpy code.Damien George
On ports where normal heap memory can contain executable code (eg ARM-based ports such as stm32), native code loaded from an .mpy file may be reclaimed by the GC because there's no reference to the very start of the native machine code block that is reachable from root pointers (only pointers to internal parts of the machine code block are reachable, but that doesn't help the GC find the memory). This commit fixes this issue by maintaining an explicit list of root pointers pointing to native code that is loaded from an .mpy file. This is not needed for all ports so is selectable by the new configuration option MICROPY_PERSISTENT_CODE_TRACK_RELOC_CODE. It's enabled by default if a port does not specify any special functions to allocate or commit executable memory. A test is included to test that native code loaded from an .mpy file does not get reclaimed by the GC. Fixes #6045. Signed-off-by: Damien George <damien@micropython.org>
2020-07-26tests/micropython: Improve .mpy import tests to run on more targets.Damien George
All imports are now tested to see if the test should be skipped, UserFile.read is removed, and UserFile.readinto is made more efficient. Signed-off-by: Damien George <damien@micropython.org>
2020-07-26tests: Move .mpy import tests from import/ to micropython/ dir.Damien George
These tests are specific to MicroPython so have a better home in the micropython/ test subdir, and putting them here allows them to be run by all targets, not just those that have access to the local filesystem (eg the unix port). Signed-off-by: Damien George <damien@micropython.org>
2020-06-27py/emitnative: Implement binary operations for viper uint operands.Damien George
uint types in viper mode can now be used for all binary operators except floor-divide and modulo. Fixes issue #1847 and issue #6177. Signed-off-by: Damien George <damien@micropython.org>
2020-05-03py/parse: Support constant folding of power operator for integers.Damien George
Constant expression like "2 ** 3" will now be folded, and the special form "X = const(2 ** 3)" will now compile because the argument to the const is now a constant. Fixes issue #5865.
2020-04-09py/parse: Remove unnecessary check in const folding for ** operator.Damien George
In this part of the code there is no way to get the ** operator, so no need to check for it. This commit also adds tests for this, and other related, invalid const operations.
2020-04-05py/objexcept: Allow compression of exception message text.Jim Mussared
The decompression of error-strings is only done if the string is accessed via printing or via er.args. Tests are added for this feature to ensure the decompression works.
2020-03-30tests: Format all Python code with black, except tests in basics subdir.David Lechner
This adds the Python files in the tests/ directory to be formatted with ./tools/codeformat.py. The basics/ subdirectory is excluded for now so we aren't changing too much at once. In a few places `# fmt: off`/`# fmt: on` was used where the code had special formatting for readability or where the test was actually testing the specific formatting.
2020-03-30tests/micropython/heapalloc_fail_set.py: Remove extra trailing comma.David Lechner
Unlike tuples, sets do not need trailing comma when there is only one item.
2020-03-11py/modmicropython: Add heap_locked function to test state of heap.Andrew Leech
This commit adds micropython.heap_locked() which returns the current lock-depth of the heap, and can be used by Python code to check if the heap is locked or not. This new function is configured via MICROPY_PY_MICROPYTHON_HEAP_LOCKED and is disabled by default. This commit also changes the return value of micropython.heap_unlock() so it returns the current lock-depth as well.
2019-12-27tests/micropython: Add test for yield-from while heap is locked.Damien George
2019-10-22tests: Rename "array" module to "uarray".Damien George
2019-09-26tests/micropython: Add test for native generators.Damien George
2019-08-28tests: Split out test for optimisation level and line-no printing.Damien George
2019-08-06py: Allow to pass in read-only buffers to viper and inline-asm funcs.Damien George
Fixes #4936.
2019-05-03py/native: Improve support for bool type in viper functions.Damien George
Variables with type bool now act more like an int, and there is proper casting to/from Python objects.
2019-04-18tests/micropython: Add some tests for failed heap allocation.Damien George
This adds tests for some locations in the code where a memory allocation should raise an exception.
2018-09-27tests/micropython: Test loading const objs in native and viper funcs.Damien George
2018-09-20py: Shorten error messages by using contractions and some rewording.Damien George
2018-09-15py/emitnative: Make viper funcs run with their correct globals context.Damien George
Viper functions will now capture the globals at the point they were defined and use these globals when executing.
2018-09-15py/emitnative: Support arbitrary number of arguments to viper functions.Damien George
2018-09-15py/compile: Factor code that compiles viper type annotations.Damien George
2018-08-17tests/micropython: Add tests for try and with blocks under native/viper.Damien George
2018-08-04tests/micropython/viper_cond: Add test for large int as bool.Damien George
2018-05-23py/emit: Combine yield value and yield-from emit funcs into one.Damien George
Reduces code size by: bare-arm: -24 minimal x86: -72 unix x64: -200 unix nanbox: -72 stm32: -52 cc3200: -32 esp8266: -84 esp32: -24
2018-04-05tests/micropython/extreme_exc.py: Allow to run without any emg exc buf.Damien George
2018-04-05tests/micropython/extreme_exc.py: Fix test to run on more ports/configs.Damien George
2018-04-05tests/micropython: Add set of tests for extreme cases of raising exc's.Damien George
2018-03-02tests: Move heap-realloc-while-locked test from C to Python.Damien George
This test for calling gc_realloc() while the GC is locked can be done in pure Python, so better to do it that way since it can then be tested on more ports.
2018-02-14tests: Automatically skip tests that require eval, exec or frozenset.Damien George
2017-12-11tests/heapalloc, heapalloc_super: Skip in strict stackless mode.Paul Sokolovsky
These tests involves testing allocation-free function calling, and in strict stackless mode, it's not possible to make a function call with heap locked (because function activation record aka frame is allocated on the heap).
2017-12-11tests/heapalloc_*: Refactor some tests to work in strict stackless mode.Paul Sokolovsky
In strict stackless mode, it's not possible to make a function call with heap locked (because function activation record aka frame is allocated on heap). So, if the only purpose of function is to introduce local variable scope, move heap lock/unlock calls inside the function.
2017-11-24py/runtime: Add MP_BINARY_OP_CONTAINS as reverse of MP_BINARY_OP_IN.Damien George
Before this patch MP_BINARY_OP_IN had two meanings: coming from bytecode it meant that the args needed to be swapped, but coming from within the runtime meant that the args were already in the correct order. This lead to some confusion in the code and comments stating how args were reversed. It also lead to 2 bugs: 1) containment for a subclass of a native type didn't work; 2) the expression "{True} in True" would illegally succeed and return True. In both of these cases it was because the args to MP_BINARY_OP_IN ended up being reversed twice. To fix these things this patch introduces MP_BINARY_OP_CONTAINS which corresponds exactly to the __contains__ special method, and this is the operator that built-in types should implement. MP_BINARY_OP_IN is now only emitted by the compiler and is converted to MP_BINARY_OP_CONTAINS by swapping the arguments.
2017-10-11py/emitnative: Implement floor-division and modulo for viper emitter.Damien George
2017-09-21py/objexcept: Prevent infinite recursion when allocating exceptions.Damien George
The aim of this patch is to rewrite the functions that create exception instances (mp_obj_exception_make_new and mp_obj_new_exception_msg_varg) so that they do not call any functions that may raise an exception. Otherwise it's possible to create infinite recursion with an exception being raised while trying to create an exception object. The two main things that are done to accomplish this are: 1. Change mp_obj_new_exception_msg_varg to just format the string, then call mp_obj_exception_make_new to actually create the exception object. 2. In mp_obj_exception_make_new and mp_obj_new_exception_msg_varg try to allocate all memory first using functions that don't raise exceptions If any of the memory allocations fail (return NULL) then degrade gracefully by trying other options for memory allocation, eg using the emergency exception buffer. 3. Use a custom printer backend to conservatively format strings: if it can't allocate memory then it just truncates the string. As part of this rewrite, raising an exception without a message, like KeyError(123), will now use the emergency buffer to store the arg and traceback data if there is no heap memory available. Memory use with this patch is unchanged. Code size is increased by: bare-arm: +136 minimal x86: +124 unix x64: +72 unix nanbox: +96 stm32: +88 esp8266: +92 cc3200: +80
2017-06-10tests: Convert remaining "sys.exit()" to "raise SystemExit".Paul Sokolovsky
2017-06-09py/objstringio: If created from immutable object, follow copy on write policy.Paul Sokolovsky
Don't create copy of immutable object's contents until .write() is called on BytesIO.
2017-05-06tests/micropython: Add test for int.from_bytes with many zero bytes.Damien George
2017-04-22tests: Add tests for calling super and loading a method directly.Damien George
2017-04-18tests/micropython: Add test for micropython.kbd_intr().Damien George
2017-04-03tests/micropython/heapalloc_iter: Improve skippability.Paul Sokolovsky
2017-03-22tests/heapalloc_str: Test no-replacement case for str.replace().Paul Sokolovsky
2017-03-20tests/micropython: Add tests for micropython.schedule().Damien George
2017-03-14tests/micropython/viper_error: Add more tests to improve coverage.Damien George
2017-03-09tests/micropython/opt_level: Clarify the expected output for opt_level == 3.Paul Sokolovsky
2017-03-09tests/micropython/heapalloc_traceback: Fix backtrace line # after refactor.Paul Sokolovsky
2017-03-09tests/micropython: Make uio-using tests skippable.Paul Sokolovsky
2017-03-07tests/micropython/: Split off intbig tests.Paul Sokolovsky
2017-02-24tests/micropython: Add test for consts that are bignums.Damien George
2017-02-20tests/heapalloc_exc_raise.py: Heap alloc test for raising/catching exc.Paul Sokolovsky