summaryrefslogtreecommitdiffstatshomepage
path: root/tests
Commit message (Collapse)AuthorAge
* tests: Use .errno instead of .args[0] for OSError exceptions.Damien George2021-04-23
| | | | Signed-off-by: Damien George <damien@micropython.org>
* py/objexcept: Support errno attribute on OSError exceptions.Damien George2021-04-23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit adds the errno attribute to exceptions, so code can retrieve errno codes from an OSError using exc.errno. The implementation here simply lets `errno` (and the existing `value`) attributes work on any exception instance (they both alias args[0]). This is for efficiency and to keep code size down. The pros and cons of this are: Pros: - more compatible with CPython, less difference to document and learn - OSError().errno will correctly return None, whereas the current way of doing it via OSError().args[0] will raise an IndexError - it reduces code size on most bare-metal ports (because they already have the errno qstr) - for Python code that uses exc.errno the generated bytecode is 2 bytes smaller and more efficient to execute (compared with exc.args[0]); so bytecode loaded to RAM saves 2 bytes RAM for each use of this attribute, and bytecode that is frozen saves 2 bytes flash/ROM for each use - it's easier/shorter to type, and saves 2 bytes of space in .py files that use it (for each use) Cons: - increases code size by 4-8 bytes on minimal ports that don't already have the `errno` qstr - all exceptions now have .errno and .value attributes (a cpydiff test is added to address this) See also #2407. Signed-off-by: Damien George <damien@micropython.org>
* tests/net_inet: Add 'Strict-Transport-Security' to exp file.Damien George2021-04-18
| | | | | | Because micropython.org now adds this to the headers. Signed-off-by: Damien George <damien@micropython.org>
* tests/feature_check: Check for lack of pass result rather than failure.Damien George2021-04-15
| | | | | | | | | | | Commit cb68a5741aba5d4935428674234a9d643f97405f broke automatic Python feature detection when running tests, because some detection relied on a crash of a feature script returning exactly b"CRASH". This commit fixes this and improves the situation by testing for the lack of a known pass result, rather than an exact failure result. Signed-off-by: Damien George <damien@micropython.org>
* unix: Improve command line argument processing.stijn2021-04-07
| | | | | | | | | | | | | Per CPython everything which comes after the command, module or file argument is not an option for the interpreter itself. Hence the processing of options should stop when encountering those, and the remainder be passed as sys.argv. Note the latter was already the case for a module or file but not for a command. This fixes issues like 'micropython myfile.py -h' showing the help and exiting instead of passing '-h' as sys.argv[1], likewise for '-X <something>' being treated as a special option no matter where it occurs on the command line.
* extmod/re1.5: Check and report byte overflow errors in _compilecode.Jeff Epler2021-04-06
| | | | | | | | | | | | | The generated regex code is limited in the range of jumps and counts, and this commit checks all cases which can overflow given the right kind of input regex, and returns an error in such a case. This change assumes that the results that overflow an int8_t do not overflow a platform int. Closes: #7078 Signed-off-by: Jeff Epler <jepler@gmail.com>
* tests/run-tests.py: Provide more info if script run via pyboard crashes.Damien George2021-03-16
| | | | Signed-off-by: Damien George <damien@micropython.org>
* tests/extmod/vfs_fat_fileio2.py: Close test file at end of test.Damien George2021-03-16
| | | | | | Otherwise it can lead to inconsistent results running subsequent tests. Signed-off-by: Damien George <damien@micropython.org>
* tests/multi_bluetooth: Skip tests when BLE features are unsupported.Damien George2021-03-12
| | | | Signed-off-by: Damien George <damien@micropython.org>
* tests/run-tests.py: Reformat with Black.Damien George2021-03-12
| | | | Signed-off-by: Damien George <damien@micropython.org>
* tests: Rename run-tests to run-tests.py for consistency.Damien George2021-03-12
| | | | Signed-off-by: Damien George <damien@micropython.org>
* tests/multi_bluetooth: Add basic performance tests.Jim Mussared2021-02-19
| | | | | | | 1. Exchange GATT notifications. 2. Transmit a stream of data over L2CAP. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* esp32: Add basic support for Non-Volatile-Storage in esp32 module.Thorsten von Eicken2021-02-19
| | | | | | | | | | This commit implements basic NVS support for the esp32. It follows the pattern of the esp32.Partition class and exposes an NVS object per NVS namespace. The initial support provided is only for signed 32-bit integers and binary blobs. It's easy (albeit a bit tedious) to add support for more types. See discussions in: #4436, #4707, #6780
* extmod/modussl: Fix ussl read/recv/send/write errors when non-blocking.Thorsten von Eicken2021-02-17
| | | | | Also fix related problems with socket on esp32, improve docs for wrap_socket, and add more tests.
* tests/extmod: Add test for ThreadSafeFlag.Jim Mussared2021-02-16
| | | | Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* esp32: Set MICROPY_USE_INTERNAL_ERRNO=0 to use toolchain's errno.h.Thorsten von Eicken2021-02-15
| | | | | | The underlying OS (the ESP-IDF) uses it's own internal errno codes and so it's simpler and cleaner to use those rather than trying to convert everything to the values defined in py/mperrno.h.
* extmod/uasyncio: Add asyncio.current_task().Jim Mussared2021-02-13
| | | | | | Matches CPython behavior. Fixes #6686
* tests/extmod/vfs_posix.py: Add more tests for VfsPosix class.Damien George2021-02-11
| | | | Signed-off-by: Damien George <damien@micropython.org>
* extmod/vfs_posix_file: Allow closing an already closed file.Damien George2021-02-11
| | | | Signed-off-by: Damien George <damien@micropython.org>
* py/mpz: Fix overflow of borrow in mpn_div.Damien George2021-02-08
| | | | | | | | | | | | | | | | | | | | | | | | For certain operands to mpn_div, the existing code path for `DIG_SIZE == MPZ_DBL_DIG_SIZE / 2` had a bug in it where borrow could still overflow in the `(x >= *n || *n - x <= borrow)` branch, ie `borrow + x - (mpz_dbl_dig_t)*n` overflows the borrow variable. In such cases the subsequent right-shift of borrow would not bring in the overflow bit, leading to an error in the result. An example division that had overflow when MPZ_DIG_SIZE = 16 is `(2 ** 48 - 1) ** 2 // (2 ** 48 - 1)`. This is fixed in this commit by simplifying the code and handling the low digits of borrow first, and then the upper bits (to shift down) separately. There is no longer a distinction between `DIG_SIZE < MPZ_DBL_DIG_SIZE / 2` and `DIG_SIZE == MPZ_DBL_DIG_SIZE / 2`. This commit also simplifies the second part of the calculation so that borrow does not need to be negated (instead the code just works knowing that borrow is negative and using + instead of - in calculations involving borrow). Fixes #6777. Signed-off-by: Damien George <damien@micropython.org>
* tests/run-tests: Change default Python command used on Windows.stijn2021-02-02
| | | | | | | | | | | Default to just calling python since that is most commonly available: the official installer or zipfiles from python.org, anaconda, nupkg all result in python being available but not python3. In other words: the default used so far is wrong. Note that os.name is 'posix' when running the python version which comes with Cygwin or MSys2 so they are not affected by this. However of all possible ways to get Python on Windows, only Cygwin provides no python command so update the default way for running tests in the README.
* tests/extmod/utime_time_ns.py: Relax bounds on time_ns measurement.Damien George2021-02-01
| | | | | | | Some devices have lower precision than 1ms for time_ns() (eg PYBv1.x has 3.9ms resolution of the RTC) so make the test more lenient for them. Signed-off-by: Damien George <damien@micropython.org>
* tests: Move native for test from pybnative to micropython.Damien George2021-01-29
| | | | | | And make it generic so it can be run on any target. Signed-off-by: Damien George <damien@micropython.org>
* py/objfun: Support fun.__globals__ attribute.Damien George2021-01-29
| | | | | | | | This returns a reference to the globals dict associated with the function, ie the global scope that the function was defined in. This attribute is read-only but the dict itself is modifiable, per CPython behaviour. Signed-off-by: Damien George <damien@micropython.org>
* extmod/vfs: Check block 0 and 1 when auto-detecting littlefs.Damien George2021-01-29
| | | | | | | | | | | | The superblock for littlefs is in block 0 and 1, but block 0 may be erased or partially written, so block 1 must be checked if block 0 does not have a valid littlefs superblock in it. Prior to this commit, the mount of a block device which auto-detected the filysystem type would fail for littlefs if block 0 did not contain a valid superblock. That is now fixed. Signed-off-by: Damien George <damien@micropython.org>
* tests/extmod: Add test for the precision of utime functions.Oliver Joos2021-01-23
| | | | | | | | According to documentation time() has a precision of at least 1 second. This test runs for 2.5 seconds and calls all utime functions every 100ms. Then it checks if they returned enough different results. All functions with sub-second precision will return ~25 results. This test passes with 15 results or more. Functions that do not exist are skipped silently.
* tests/misc/sys_settrace_features.py: Fix running with non-dflt encoding.stijn2020-12-18
| | | | | Notably git-cmd which comes with git installations on Windows alters the encoding resulting in CPython tracing encodings/cp1252.py calls.
* tests/misc/sys_settrace: Make test output independent of invoked path.stijn2020-12-18
| | | | | | | | | | | | The original logic of reducing a full path to a relative one assumes "tests/misc" is in the filename which is limited in usage: it never works for CPython on Windows since that will use a backslash as path separator, and also won't work when the filename is a path not relative to the tests directory which happens for example in the common case of running "./run-tests -d misc". Fix all cases by printing only the bare filename, which requires them all to start with sys_settrace_ hence the renaming.
* tests/extmod: Add test to try and mount a block device directly.Oliver Joos2020-12-17
| | | | | | | | | Mounting a bdev directly tries to auto-detect the filesystem and if none is found an OSError(19,) should be raised. The fourth parameter of readblocks() and writeblocks() must be optional to support ports with MICROPY_VFS_FAT=1. Otherwise mounting a bdev may fail because looking for a FATFS will call readblocks() with only 3 parameters.
* tests/misc/sys_settrace_features.py: Ignore CPython zipimport traces.Damien George2020-12-14
| | | | Signed-off-by: Damien George <damien@micropython.org>
* py/mpprint: Fix length calculation for strings with precision-modifier.Joris Peeraer2020-12-07
| | | | | | | | | | | | | | | | | | | Two issues are tackled: 1. The calculation of the correct length to print is fixed to treat the precision as a maximum length instead as the exact length. This is done for both qstr (%q) and for regular str (%s). 2. Fix the incorrect use of mp_printf("%.*s") to mp_print_strn(). Because of the fix of above issue, some testcases that would print an embedded null-byte (^@ in test-output) would now fail. The bug here is that "%s" was used to print null-bytes. Instead, mp_print_strn is used to make sure all bytes are outputted and the exact length is respected. Test-cases are added for both %s and %q with a combination of precision and padding specifiers.
* tests/multi_bluetooth: Add multitests for BLE pairing and bonding.Damien George2020-12-02
| | | | Signed-off-by: Damien George <damien@micropython.org>
* extmod/uasyncio: Fix cancellation handling of wait_for.Damien George2020-12-02
| | | | | | | | | | | | | This commit switches the roles of the helper task from a cancellation task to a runner task, to get the correct semantics for cancellation of wait_for. Some uasyncio tests are now disabled for the native emitter due to issues with native code generation of generators and yield-from. Fixes #5797. Signed-off-by: Damien George <damien@micropython.org>
* extmod/uasyncio: Add Task.done() method.Damien George2020-12-02
| | | | | | | | This is added because task.coro==None is no longer the way to detect if a task is finished. Providing a (CPython compatible) function for this allows the implementation to be abstracted away. Signed-off-by: Damien George <damien@micropython.org>
* extmod/uasyncio: Delay calling Loop.call_exception_handler by 1 loop.Damien George2020-12-02
| | | | | | | | | | | | | | | | | | | | | | | When a tasks raises an exception which is uncaught, and no other task await's on that task, then an error message is printed (or a user function called) via a call to Loop.call_exception_handler. In CPython this call is made when the Task object is freed (eg via reference counting) because it's at that point that it is known that the exception that was raised will never be handled. MicroPython does not have reference counting and the current behaviour is to deal with uncaught exceptions as early as possible, ie as soon as they terminate the task. But this can be undesirable because in certain cases a task can start and raise an exception immediately (before any await is executed in that task's coro) and before any other task gets a chance to await on it to catch the exception. This commit changes the behaviour so that tasks which end due to an uncaught exception are scheduled one more time for execution, and if they are not await'ed on by the next scheduling loop, then the exception handler is called (eg the exception is printed out). Signed-off-by: Damien George <damien@micropython.org>
* tests/run-tests: Update skipped tests on CI for GitHub Actions.Damien George2020-11-30
| | | | Signed-off-by: Damien George <damien@micropython.org>
* tests/extmod: Add vfs_posix.py test for uos.VfsPosix class.Damien George2020-11-29
| | | | Signed-off-by: Damien George <damien@micropython.org>
* tests/multi_bluetooth: Add L2CAP channels multi-test.Jim Mussared2020-11-24
| | | | Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* tests/multi_bluetooth: Add a test for WB55 concurrent flash access.Jim Mussared2020-11-16
| | | | | | | This test currently passes on Unix/PYBD, but fails on WB55 because it lacks synchronisation of the internal flash. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* tests/multi_bluetooth: Change dict index-and-del to pop, to clear event.Jim Mussared2020-11-16
| | | | Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* tests/run-multitests.py: Add a -p flag to run permutations of instances.Jim Mussared2020-11-13
| | | | Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* tests/multi_bluetooth: Improve reliability of event waiting.Jim Mussared2020-11-13
| | | | | | | | | Use the same `wait_for_event` in all tests that doesn't hold a reference to the event data tuple and handles repeat events. Also fix a few misc reliability issues around timeouts and sequencing. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* tests/run-multitests.py: Fix diff order, show changes relative to truth.Jim Mussared2020-11-13
| | | | Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* extmod/machine_mem: Only allow integers in machine.memX subscript.Arrowana2020-11-13
| | | | | | | | | | | | | | | | Prior to this change machine.mem32['foo'] (or using any other non-integer subscript) could result in a fault due to 'foo' being interpreted as an integer. And when writing code it's hard to tell if the fault is due to a bad subscript type, or an integer subscript that specifies an invalid memory address. The type of the object used in the subscript is now tested to be an integer by using mp_obj_get_int_truncated instead of mp_obj_int_get_truncated. The performance hit of this change is minimal, and machine.memX objects are more for convenience than performance (there are many other ways to read/write memory in a faster way), Fixes issue #6588.
* py/binary: Fix sign extension setting wide integer on 32-bit archs.Damien George2020-11-11
| | | | Signed-off-by: Damien George <damien@micropython.org>
* extmod/moductypes: Fix storing to (U)INT64 arrays on 32-bit archs.Damien George2020-11-11
| | | | | | Fixes issue #6583. Signed-off-by: Damien George <damien@micropython.org>
* py/mpz: Do sign extension in mpz_as_bytes for negative values.Damien George2020-11-11
| | | | Signed-off-by: Damien George <damien@micropython.org>
* tests/micropython/extreme_exc.py: Unlink alloc'd lists earlier in chain.Damien George2020-10-29
| | | | | | To help the GC collect this memory that's no longer needed after the test. Signed-off-by: Damien George <damien@micropython.org>
* examples: Add example code for user C modules, both C and C++.stijn2020-10-29
| | | | | | | | Add working example code to provide a starting point for users with files that they can just copy, and include the modules in the coverage test to verify the complete user C module build functionality. The cexample module uses the code originally found in cmodules.rst, which has been updated to reflect this and partially rewritten with more complete information.
* esp32,unix: Support building C++ code.stijn2020-10-29
| | | | | | | | | | | | Support building .cpp files and linking them into the micropython executable in a way similar to how it is done for .c files. The main incentive here is to enable user C modules to use C++ files (which are put in SRC_MOD_CXX by py.mk) since the core itself does not utilize C++. However, to verify build functionality a unix overage test is added. The esp32 port already has CXXFLAGS so just add the user modules' flags to it. For the unix port use a copy of the CFLAGS but strip the ones which are not usable for C++.