Commit Graph

1442 Commits

Author SHA1 Message Date
Ayke van Laethem 7642785881 extmod/vfs_fat_file: Implement SEEK_CUR for non-zero offset.
CPython doesn't allow SEEK_CUR with non-zero offset for files in text mode,
and uPy inherited this behaviour for both text and binary files.  It makes
sense to provide full support for SEEK_CUR of binary-mode files in uPy, and
to do this in a minimal way means also allowing to use SEEK_CUR with
non-zero offsets on text-mode files.  That seems to be a fair compromise.
2018-01-31 17:33:07 +11:00
Damien George a1d85d6199 tests/basics/memoryerror: Add test for out-of-memory using realloc. 2017-12-20 16:58:27 +11:00
Damien George d35c6ffc84 tests/extmod: Add some uctypes tests to improve coverage of that module. 2017-12-19 16:48:41 +11:00
Damien George 35a759dc1d tests: Add some more tests to improve coverage of py/parse.c. 2017-12-19 16:13:00 +11:00
Damien George 2bfa531798 tests/basics/builtin_pow3: Add tests for edge cases of pow3. 2017-12-19 15:44:10 +11:00
Damien George 8e6113a188 tests/basics/generator_pend_throw: Add test for just-started generator. 2017-12-19 15:02:34 +11:00
Damien George e800e4463d tests/unix: Add test for printf with %lx format. 2017-12-19 15:01:17 +11:00
Damien George 7cae17fac7 tests/float/builtin_float_hash: Add test to improve objfloat.c coverage. 2017-12-19 14:50:33 +11:00
Damien George 251b00457c tests/extmod/uhashlib_sha256: Add test for hashing 56 bytes of data. 2017-12-19 14:46:31 +11:00
Damien George 7208cad97a tests/basics: Add more set tests to improve coverage of py/objset.c. 2017-12-19 13:59:54 +11:00
Paul Sokolovsky 6364401666 py/objgenerator: Allow to pend an exception for next execution.
This implements .pend_throw(exc) method, which sets up an exception to be
triggered on the next call to generator's .__next__() or .send() method.
This is unlike .throw(), which immediately starts to execute the generator
to process the exception. This effectively adds Future-like capabilities
to generator protocol (exception will be raised in the future).

The need for such a method arised to implement uasyncio wait_for() function
efficiently (its behavior is clearly "Future" like, and normally would
require to introduce an expensive Future wrapper around all native
couroutines, like upstream asyncio does).

py/objgenerator: pend_throw: Return previous pended value.

This effectively allows to store an additional value (not necessary an
exception) in a coroutine while it's not being executed. uasyncio has
exactly this usecase: to mark a coro waiting in I/O queue (and thus
not executed in the normal scheduling queue), for the purpose of
implementing wait_for() function (cancellation of such waiting coro
by a timeout).
2017-12-15 20:20:36 +02:00
Paul Sokolovsky 103eeffcd9 tests/run-tests: Skip running feature checks for --list-tests/--write-exp.
The whole idea of --list-tests is that we prepare a list of tests to run
later, and currently don't have a connection to target board. Similarly
for --write-exp - only "python3" binary would be required for this operation,
not "micropython".
2017-12-15 12:07:09 +02:00
Paul Sokolovsky 3233537a15 tests/run-tests: Don't test for --target=unix with "pyb is None".
If we test for unix target, do that explicitly. pyb var will be None
for commands like --list-tests too.
2017-12-14 13:36:06 +02:00
Paul Sokolovsky 64bb32d87f tests/run-tests: Add composable --include and --exclude options.
The idea that --list-tests would be enough to produce list of tests for
tinytest-codegen didn't work, because normal run-tests processing heavily
relies on dynamic target capabilities discovery, and test filtering happens
as the result of that.

So, approach the issue from different end - allow to specify arbitrary
filtering criteria as run-tests arguments. This way, specific filters
will be still hardcoded, but at least on a particular target's side,
instead of constant patching tinytest-codegen and/or run-tests.
2017-12-14 12:26:10 +02:00
Paul Sokolovsky aaeb70b7b7 tests/run-tests: Fix handling of --list-tests wrt skipped tests.
"skip <test>" message could leak before.
2017-12-14 12:13:36 +02:00
Paul Sokolovsky 8d11fc0bc4 tests/run-tests: minimal: Exclude recently added subclass_native_init.py.
It relies on MICROPY_CPYTHON_COMPAT being defined.
2017-12-14 10:35:05 +02:00
Damien George 46b35356e1 extmod/modframebuf: Add 8-bit greyscale format (GS8). 2017-12-14 17:36:13 +11:00
Petr Viktorin 34247465c3 extmod/modframebuf: Add 2-bit color format (GS2_HMSB).
This format is used in 2-color LED matrices and in e-ink displays like
SSD1606.
2017-12-14 17:13:02 +11:00
Damien George 36f79523ab tests: Add tests to improve coverage of py/objtype.c. 2017-12-14 12:25:30 +11:00
Paul Sokolovsky 334934ee97 tests/run-tests: Add --list-tests switch.
Lists tests to be executed, subject to all other filters requested. This
options would be useful e.g. for scripts like tools/tinytest-codegen.py,
which currently contains hardcoded filters for particular a particular
target and can't work for multiple targets.
2017-12-13 18:35:37 +02:00
Paul Sokolovsky da34b6ef45 tests: Fix few test for proper "skipped" detection with qemu-arm's tinytest.
"Builtin" tinytest-based testsuite as employed by qemu-arm (and now
generalized by me to be reusable for other targets) performs simplified
detection of skipped tests, it treats as such tests which raised SystemExit
(instead of checking got "SKIP" output). Consequently, each "SKIP" must
be accompanied by SystemExit (and conversely, SystemExit should not be
used if test is not skipped, which so far seems to be true).
2017-12-12 23:45:48 +02:00
Damien George e4e3f0d727 tests/cpydiff: Update subclassing Exception case and give work-around. 2017-12-12 17:13:39 +11:00
Damien George 3c28df1658 tests/extmod: Add test which subclasses framebuf.FrameBuffer. 2017-12-12 16:48:09 +11:00
Damien George fd0b0db873 tests/basics: Add test for overriding a native base-class's init method. 2017-12-12 16:47:38 +11:00
Paul Sokolovsky 016f830536 tests/heapalloc, heapalloc_super: Skip in strict stackless mode.
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-11 12:04:59 +02:00
Paul Sokolovsky e02cb9ec31 tests/heapalloc_*: Refactor some tests to work in strict stackless mode.
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-12-11 12:00:41 +02:00
Paul Sokolovsky e104e24e53 tests/run-tests: Wrap long lists to facilitate adding more items. 2017-12-05 01:56:05 +02:00
Paul Sokolovsky 3c483842db tests/cpydiff: Fix markup where "`" (xref) was used instead of "``" (code). 2017-12-03 15:32:09 +02:00
Paul Sokolovsky a289b24e25 tests/run-tests: "minimal": Skip recently added float/float_parse.py.
Fails for Zephyr qemu_x86 with:

-9e-36
+9.000001e-36
2017-11-28 14:11:19 +02:00
Damien George 63f47104fe tests/cpydiff: Add difference-test for second arg of builtin next(). 2017-11-28 10:50:53 +11:00
Damien George c3bc8d7b2b tests/basics/builtin_locals: Add test for using locals() in class body. 2017-11-27 14:14:57 +11:00
Damien George 84895f1a21 py/parsenum: Improve parsing of floating point numbers.
This patch improves parsing of floating point numbers by converting all the
digits (integer and fractional) together into a number 1 or greater, and
then applying the correct power of 10 at the very end.  In particular the
multiple "multiply by 0.1" operations to build a fraction are now combined
together and applied at the same time as the exponent, at the very end.

This helps to retain precision during parsing of floats, and also includes
a check that the number doesn't overflow during the parsing.  One benefit
is that a float will have the same value no matter where the decimal point
is located, eg 1.23 == 123e-2.
2017-11-27 12:51:52 +11:00
Damien George c7a0e1472d tests/basics/builtin_range: Add test for corner case of range slicing. 2017-11-24 15:30:12 +11:00
Damien George 505671b698 tests/basics: Add test for containment of a subclass of a native type. 2017-11-24 14:48:41 +11:00
Damien George 5e34a113ea py/runtime: Add MP_BINARY_OP_CONTAINS as reverse of MP_BINARY_OP_IN.
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-11-24 14:48:23 +11:00
Damien George df078e8213 tests/net_hosted: Add test for socket connect() and poll() behaviour. 2017-11-23 10:45:12 +11:00
Damien George a07fc5b640 py/objfloat: Allow float() to parse anything with the buffer protocol.
This generalises and simplifies the code and follows CPython behaviour.
2017-11-21 15:01:38 +11:00
stijn 79ed58f87b py/objnamedtuple: Add _asdict function if OrderedDict is supported 2017-11-12 14:16:54 +02:00
Paul Sokolovsky 9b9dbc5815 py/objtype: Define all special methods if requested.
If MICROPY_PY_ALL_SPECIAL_METHODS is defined, actually define all special
methods (still subject to gating by e.g. MICROPY_PY_REVERSE_SPECIAL_METHODS).

This adds quite a number of qstr's, so should be used sparingly.
2017-10-27 20:06:35 +03:00
Damien George f36975b679 tests/net_inet: Update tls test to work with CPython and incl new site.
CPython only supports the server_hostname keyword arg via the SSLContext
object, so use that instead of the top-level ssl.wrap_socket.  This allows
the test to run on CPython the same as uPy.

Also add the "Host:" header to correctly make a GET request (for URLs that
are hosted on other servers).  This is not strictly needed to test the SSL
connection but helps to debug things when printing the response.
2017-10-26 12:29:24 +11:00
Damien George a3afa8cfc4 py/emitnative: Implement floor-division and modulo for viper emitter. 2017-10-11 18:54:34 +11:00
Damien George 08a196697c py/formatfloat: Don't print the negative sign of a NaN value.
NaN may have the sign bit set but it has no meaning, so don't print it out.
2017-10-10 16:01:13 +11:00
Damien George 25e140652b py/modmath: Add full checks for math domain errors.
This patch changes how most of the plain math functions are implemented:
there are now two generic math wrapper functions that take a pointer to a
math function (like sin, cos) and perform the necessary conversion to and
from MicroPython types.  This helps to reduce code size.  The generic
functions can also check for math domain errors in a generic way, by
testing if the result is NaN or infinity combined with finite inputs.

The result is that, with this patch, all math functions now have full
domain error checking (even gamma and lgamma) and code size has decreased
for most ports.  Code size changes in bytes for those with the math module
are:

   unix x64:  -432
unix nanbox:  -792
      stm32:   -88
    esp8266:   +12

Tests are also added to check domain errors are handled correctly.
2017-10-10 15:57:45 +11:00
Paul Sokolovsky 71c1a05d88 tests/run-tests: Close device under test using "finally".
We want to close communication object even if there were exceptions
somewhere in the code. This is important for --device exec:/execpty:
which may otherwise leave processing running in the background.
2017-10-07 15:49:58 +03:00
Damien George 98dd126e98 tests/extmod: Add test for '-' in character class in regex. 2017-10-05 11:33:49 +11:00
Damien George 0864a6957f py: Clean up unary and binary enum list to keep groups together.
2 non-bytecode binary ops (NOT_IN and IN_NOT) are moved out of the
bytecode group, so this change will change the bytecode format.
2017-10-05 10:49:44 +11:00
Damien George dfa563c71f py/objstr: Make empty bytes object have a null-terminating byte.
Because a lot of string processing functions assume there is a null
terminating byte, so they can work in an efficient way.

Fixes issue #3334.
2017-10-04 17:59:22 +11:00
Damien George 1394258f37 py/objset: Include the failed key in a KeyError raised from set.remove. 2017-10-03 18:03:06 +11:00
Damien George 2ac1364688 py/objset: Check that RHS of a binary op is a set/frozenset.
CPython docs explicitly state that the RHS of a set/frozenset binary op
must be a set to prevent user errors.  It also preserves commutativity of
the ops, eg: "abc" & set() is a TypeError, and so should be set() & "abc".

This change actually decreases unix (x64) code by 160 bytes; it increases
stm32 by 4 bytes and esp8266 by 28 bytes (but previous patch already
introduced a much large saving).
2017-10-03 17:56:27 +11:00
Paul Sokolovsky 8e0b9f495b tests/extmod: Add test for ure regexes leading to infinite recursion.
These now should be caught properly and lead to RuntimeError instead of
crash.
2017-10-03 00:24:32 +03:00