From 6a6e998ea5bcfcc5ca4ca8a689720acc365b6927 Mon Sep 17 00:00:00 2001 From: sabas1080 Date: Sat, 7 Nov 2020 19:21:36 -0600 Subject: [PATCH 01/70] Added BastBLE --- ports/nrf/boards/bastble/README.md | 8 ++++ ports/nrf/boards/bastble/board.c | 41 +++++++++++++++++++ ports/nrf/boards/bastble/mpconfigboard.h | 16 ++++++++ ports/nrf/boards/bastble/mpconfigboard.mk | 12 ++++++ ports/nrf/boards/bastble/pins.c | 48 +++++++++++++++++++++++ 5 files changed, 125 insertions(+) create mode 100644 ports/nrf/boards/bastble/README.md create mode 100644 ports/nrf/boards/bastble/board.c create mode 100644 ports/nrf/boards/bastble/mpconfigboard.h create mode 100644 ports/nrf/boards/bastble/mpconfigboard.mk create mode 100644 ports/nrf/boards/bastble/pins.c diff --git a/ports/nrf/boards/bastble/README.md b/ports/nrf/boards/bastble/README.md new file mode 100644 index 0000000000..c684641062 --- /dev/null +++ b/ports/nrf/boards/bastble/README.md @@ -0,0 +1,8 @@ +# Electronic Cats BastBLE + +The [BastBLE](https://electroniccats.com/store/bast-ble/) based on Nordic nRF 52840 and containing +a powerful Cortex M4F. This board include a external memory QSPI flash. + + +I2C pins `board.SCL1` and `board.SDA1` are not exposed and are used for onboard peripherals. + diff --git a/ports/nrf/boards/bastble/board.c b/ports/nrf/boards/bastble/board.c new file mode 100644 index 0000000000..d91a915f19 --- /dev/null +++ b/ports/nrf/boards/bastble/board.c @@ -0,0 +1,41 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "boards/board.h" +#include "nrf.h" +#include "nrf_rtc.h" + +void board_init(void) { + +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { + +} diff --git a/ports/nrf/boards/bastble/mpconfigboard.h b/ports/nrf/boards/bastble/mpconfigboard.h new file mode 100644 index 0000000000..67a62e915b --- /dev/null +++ b/ports/nrf/boards/bastble/mpconfigboard.h @@ -0,0 +1,16 @@ +#include "nrfx/hal/nrf_gpio.h" + +#define MICROPY_HW_BOARD_NAME "BastBLE" +#define MICROPY_HW_MCU_NAME "nRF52840" + +#define CIRCUITPY_AUTORELOAD_DELAY_MS 500 + +#define DEFAULT_I2C_BUS_SCL (&pin_P1_10) +#define DEFAULT_I2C_BUS_SDA (&pin_P1_11) + +#define DEFAULT_SPI_BUS_SCK (&pin_P1_00) +#define DEFAULT_SPI_BUS_MOSI (&pin_P1_06) +#define DEFAULT_SPI_BUS_MISO (&pin_P0_15) + +#define DEFAULT_UART_BUS_RX (&pin_P0_09) +#define DEFAULT_UART_BUS_TX (&pin_P0_10) diff --git a/ports/nrf/boards/bastble/mpconfigboard.mk b/ports/nrf/boards/bastble/mpconfigboard.mk new file mode 100644 index 0000000000..9441b913b7 --- /dev/null +++ b/ports/nrf/boards/bastble/mpconfigboard.mk @@ -0,0 +1,12 @@ +USB_VID = 0x2341 +USB_PID = 0x805A +USB_PRODUCT = "BastBLE" +USB_MANUFACTURER = "ElectronicCats" + +MCU_CHIP = nrf52840 + +INTERNAL_FLASH_FILESYSTEM = 1 + +QSPI_FLASH_FILESYSTEM = 1 +EXTERNAL_FLASH_DEVICE_COUNT = 1 +EXTERNAL_FLASH_DEVICES = "GD25Q16C" diff --git a/ports/nrf/boards/bastble/pins.c b/ports/nrf/boards/bastble/pins.c new file mode 100644 index 0000000000..6e4cc511b0 --- /dev/null +++ b/ports/nrf/boards/bastble/pins.c @@ -0,0 +1,48 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_P1_11) }, + { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_P1_10) }, + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_P1_00) }, + { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_P1_02) }, + { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_P1_13) }, + { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_P1_06) }, + { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_P0_15) }, + { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_P0_06) }, + { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_P1_09) }, + { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_P0_08) }, + { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_P0_26) }, + { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_P0_07) }, + + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_P0_02) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_P0_28) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_P0_05) }, + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_P0_03) }, + + { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_P0_30) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_P1_11) }, + + { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_P0_29) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_P1_10) }, + + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_P1_06) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_P0_15) }, + + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_P1_00) }, + { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_P0_24) }, + + { MP_ROM_QSTR(MP_QSTR_AREF), MP_ROM_PTR(&pin_P0_31) }, + + // voltage sense battery + { MP_ROM_QSTR(MP_QSTR_VBAT), MP_ROM_PTR(&pin_P0_26) }, + + + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_P0_10) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_P0_09) }, + + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, +}; + +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); From 78dffd8ef8d88eb88e3186f68eeb988f649a7971 Mon Sep 17 00:00:00 2001 From: Ricardo Date: Mon, 9 Nov 2020 14:17:25 -0600 Subject: [PATCH 02/70] add board on build.yml --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 404d2ea2e5..8f098cb92e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -182,6 +182,7 @@ jobs: - "arduino_nano_33_iot" - "arduino_zero" - "bast_pro_mini_m0" + - "bastBLE" - "bdmicro_vina_d21" - "bdmicro_vina_d51" - "bless_dev_board_multi_sensor" From ee57bc4d8359b6f833c6a34f3cc0dceabdf51cdb Mon Sep 17 00:00:00 2001 From: Ricardo Date: Mon, 9 Nov 2020 14:25:42 -0600 Subject: [PATCH 03/70] fix name --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8f098cb92e..f68402be8f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -182,7 +182,7 @@ jobs: - "arduino_nano_33_iot" - "arduino_zero" - "bast_pro_mini_m0" - - "bastBLE" + - "bastble" - "bdmicro_vina_d21" - "bdmicro_vina_d51" - "bless_dev_board_multi_sensor" From 7253b2eb31890d24cee10975844b8de9b4880a23 Mon Sep 17 00:00:00 2001 From: Ricardo Date: Fri, 13 Nov 2020 09:22:42 -0600 Subject: [PATCH 04/70] fix name board --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f68402be8f..70fc723761 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -182,7 +182,7 @@ jobs: - "arduino_nano_33_iot" - "arduino_zero" - "bast_pro_mini_m0" - - "bastble" + - "bastble" - "bdmicro_vina_d21" - "bdmicro_vina_d51" - "bless_dev_board_multi_sensor" From 089fa82067549b97990eaf0d61c073b852cf7636 Mon Sep 17 00:00:00 2001 From: sabas1080 Date: Mon, 16 Nov 2020 21:21:24 -0600 Subject: [PATCH 05/70] Fix pre-commit --- ports/nrf/boards/bastble/README.md | 6 +----- ports/nrf/boards/bastble/board.c | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/ports/nrf/boards/bastble/README.md b/ports/nrf/boards/bastble/README.md index c684641062..0af6209bdb 100644 --- a/ports/nrf/boards/bastble/README.md +++ b/ports/nrf/boards/bastble/README.md @@ -1,8 +1,4 @@ # Electronic Cats BastBLE The [BastBLE](https://electroniccats.com/store/bast-ble/) based on Nordic nRF 52840 and containing -a powerful Cortex M4F. This board include a external memory QSPI flash. - - -I2C pins `board.SCL1` and `board.SDA1` are not exposed and are used for onboard peripherals. - +a powerful Cortex M4F. This board include a external memory QSPI flash. diff --git a/ports/nrf/boards/bastble/board.c b/ports/nrf/boards/bastble/board.c index d91a915f19..7c42cee57d 100644 --- a/ports/nrf/boards/bastble/board.c +++ b/ports/nrf/boards/bastble/board.c @@ -29,7 +29,7 @@ #include "nrf_rtc.h" void board_init(void) { - + } bool board_requests_safe_mode(void) { From 33ca357094b58f136c3d9bdf30b73d297302cbbc Mon Sep 17 00:00:00 2001 From: sabas1080 Date: Mon, 16 Nov 2020 22:10:37 -0600 Subject: [PATCH 06/70] fix VID and PID --- ports/nrf/boards/bastble/mpconfigboard.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/nrf/boards/bastble/mpconfigboard.mk b/ports/nrf/boards/bastble/mpconfigboard.mk index 9441b913b7..0e01c4d0f3 100644 --- a/ports/nrf/boards/bastble/mpconfigboard.mk +++ b/ports/nrf/boards/bastble/mpconfigboard.mk @@ -1,4 +1,4 @@ -USB_VID = 0x2341 +USB_VID = 0x1209 USB_PID = 0x805A USB_PRODUCT = "BastBLE" USB_MANUFACTURER = "ElectronicCats" From 1553a647ca84f221fbadf1202844b91500d3ae9e Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 24 Nov 2020 10:53:37 -0600 Subject: [PATCH 07/70] build: Update to gcc10 preview --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 046598a6e2..c032b1b8a3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -341,8 +341,8 @@ jobs: run: | sudo apt-get install -y gettext pip install requests sh click setuptools awscli - wget https://adafruit-circuit-python.s3.amazonaws.com/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2 - sudo tar -C /usr --strip-components=1 -xaf gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2 + wget --no-verbose https://developer.arm.com/-/media/Files/downloads/gnu-rm/10-2020q2/gcc-arm-none-eabi-10-2020-q2-preview-x86_64-linux.tar.bz2 + sudo tar -C /usr --strip-components=1 -xaf gcc-arm-none-eabi-10-2020-q2-preview-x86_64-linux.tar.bz2 - name: Versions run: | gcc --version From fc23a0cc8ac40115047c2430c700c0832ba979eb Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Tue, 8 Dec 2020 11:30:00 +0530 Subject: [PATCH 08/70] implement ota module --- ports/esp32s2/common-hal/ota/__init__.c | 31 +++++++++++++++ ports/esp32s2/mpconfigport.mk | 1 + py/circuitpy_defns.mk | 4 ++ py/circuitpy_mpconfig.h | 8 ++++ py/circuitpy_mpconfig.mk | 3 ++ shared-bindings/ota/__init__.c | 51 +++++++++++++++++++++++++ shared-bindings/ota/__init__.h | 34 +++++++++++++++++ 7 files changed, 132 insertions(+) create mode 100644 ports/esp32s2/common-hal/ota/__init__.c create mode 100644 shared-bindings/ota/__init__.c create mode 100644 shared-bindings/ota/__init__.h diff --git a/ports/esp32s2/common-hal/ota/__init__.c b/ports/esp32s2/common-hal/ota/__init__.c new file mode 100644 index 0000000000..87daffa568 --- /dev/null +++ b/ports/esp32s2/common-hal/ota/__init__.c @@ -0,0 +1,31 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 microDev + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "shared-bindings/ota/__init__.h" + +void common_hal_ota_flash(const void *buf, const size_t len) { + +} diff --git a/ports/esp32s2/mpconfigport.mk b/ports/esp32s2/mpconfigport.mk index b3b2a6d700..da231107fb 100644 --- a/ports/esp32s2/mpconfigport.mk +++ b/ports/esp32s2/mpconfigport.mk @@ -23,6 +23,7 @@ CIRCUITPY_FREQUENCYIO = 1 CIRCUITPY_I2CPERIPHERAL = 0 CIRCUITPY_ROTARYIO = 1 CIRCUITPY_NVM = 1 +CIRCUITPY_OTA = 1 # We don't have enough endpoints to include MIDI. CIRCUITPY_USB_MIDI = 0 CIRCUITPY_WIFI = 1 diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index e9253682e0..68e806d4b2 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -205,6 +205,9 @@ endif ifeq ($(CIRCUITPY_OS),1) SRC_PATTERNS += os/% endif +ifeq ($(CIRCUITPY_OTA),1) +SRC_PATTERNS += ota/% +endif ifeq ($(CIRCUITPY_PIXELBUF),1) SRC_PATTERNS += _pixelbuf/% endif @@ -347,6 +350,7 @@ SRC_COMMON_HAL_ALL = \ nvm/ByteArray.c \ nvm/__init__.c \ os/__init__.c \ + ota/__init__.c \ ps2io/Ps2.c \ ps2io/__init__.c \ pulseio/PulseIn.c \ diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index f04112bfcd..b432757b33 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -539,6 +539,13 @@ extern const struct _mp_obj_module_t os_module; #define OS_MODULE_ALT_NAME #endif +#if CIRCUITPY_OTA +extern const struct _mp_obj_module_t ota_module; +#define OTA_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_ota), (mp_obj_t)&ota_module }, +#else +#define OTA_MODULE +#endif + #if CIRCUITPY_PEW extern const struct _mp_obj_module_t pew_module; #define PEW_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR__pew),(mp_obj_t)&pew_module }, @@ -827,6 +834,7 @@ extern const struct _mp_obj_module_t wifi_module; NETWORK_MODULE \ SOCKET_MODULE \ WIZNET_MODULE \ + OTA_MODULE \ PEW_MODULE \ PIXELBUF_MODULE \ PS2IO_MODULE \ diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index 370f133739..09074bf53c 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -179,6 +179,9 @@ CFLAGS += -DCIRCUITPY_NVM=$(CIRCUITPY_NVM) CIRCUITPY_OS ?= 1 CFLAGS += -DCIRCUITPY_OS=$(CIRCUITPY_OS) +CIRCUITPY_OTA ?= 0 +CFLAGS += -DCIRCUITPY_OTA=$(CIRCUITPY_OTA) + CIRCUITPY_PIXELBUF ?= $(CIRCUITPY_FULL_BUILD) CFLAGS += -DCIRCUITPY_PIXELBUF=$(CIRCUITPY_PIXELBUF) diff --git a/shared-bindings/ota/__init__.c b/shared-bindings/ota/__init__.c new file mode 100644 index 0000000000..a6c0424865 --- /dev/null +++ b/shared-bindings/ota/__init__.c @@ -0,0 +1,51 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 microDev + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "shared-bindings/ota/__init__.h" + +//| """ota module +//| +//| The `ota` module implements over-the-air update.""" + +STATIC mp_obj_t ota_flash(mp_obj_t program_binary_in) { + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(program_binary_in, &bufinfo, MP_BUFFER_READ); + + common_hal_ota_flash(bufinfo.buf, bufinfo.len); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(ota_flash_obj, ota_flash); + +STATIC const mp_rom_map_elem_t ota_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ota) }, + { MP_ROM_QSTR(MP_QSTR_flash), MP_ROM_PTR(&ota_flash_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(ota_module_globals, ota_module_globals_table); + +const mp_obj_module_t ota_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t*)&ota_module_globals, +}; diff --git a/shared-bindings/ota/__init__.h b/shared-bindings/ota/__init__.h new file mode 100644 index 0000000000..c4b40b2af3 --- /dev/null +++ b/shared-bindings/ota/__init__.h @@ -0,0 +1,34 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 microDev + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_OTA___INIT___H +#define MICROPY_INCLUDED_SHARED_BINDINGS_OTA___INIT___H + +#include "py/runtime.h" + +extern void common_hal_ota_flash(const void *buf, const size_t len); + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_OTA___INIT___H From 602243748bdf238ff16ffc8977e6cc18b4357dcc Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Tue, 8 Dec 2020 11:45:00 +0530 Subject: [PATCH 09/70] add ota support for esp32s2 --- locale/circuitpython.pot | 13 ++- ports/esp32s2/Makefile | 2 + ports/esp32s2/common-hal/ota/__init__.c | 101 +++++++++++++++++++++++- 3 files changed, 111 insertions(+), 5 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index b136e9dd26..5bf95043a6 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-11-27 23:57-0500\n" +"POT-Creation-Date: 2020-12-08 10:30+0530\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -498,8 +498,8 @@ msgstr "" msgid "Buffer must be a multiple of 512 bytes" msgstr "" -#: shared-bindings/bitbangio/I2C.c shared-bindings/busdevice/I2CDevice.c -#: shared-bindings/busio/I2C.c +#: shared-bindings/adafruit_bus_device/I2CDevice.c +#: shared-bindings/bitbangio/I2C.c shared-bindings/busio/I2C.c msgid "Buffer must be at least length 1" msgstr "" @@ -1296,7 +1296,7 @@ msgstr "" msgid "No DMA channel found" msgstr "" -#: shared-module/busdevice/I2CDevice.c +#: shared-module/adafruit_bus_device/I2CDevice.c #, c-format msgid "No I2C device at address: %x" msgstr "" @@ -1420,6 +1420,10 @@ msgstr "" msgid "Not settable" msgstr "" +#: ports/esp32s2/common-hal/ota/__init__.c +msgid "OTA Update Failed" +msgstr "" + #: shared-bindings/util.c msgid "" "Object has been deinitialized and can no longer be used. Create a new object." @@ -1503,6 +1507,7 @@ msgstr "" msgid "Pin does not have ADC capabilities" msgstr "" +#: shared-bindings/adafruit_bus_device/SPIDevice.c #: shared-bindings/digitalio/DigitalInOut.c msgid "Pin is input only" msgstr "" diff --git a/ports/esp32s2/Makefile b/ports/esp32s2/Makefile index 4486cb598c..ce0a4825d3 100644 --- a/ports/esp32s2/Makefile +++ b/ports/esp32s2/Makefile @@ -106,6 +106,8 @@ INC += -isystem esp-idf/components/heap/include INC += -isystem esp-idf/components/esp_system/include INC += -isystem esp-idf/components/spi_flash/include INC += -isystem esp-idf/components/nvs_flash/include +INC += -isystem esp-idf/components/app_update/include +INC += -isystem esp-idf/components/bootloader_support/include INC += -I$(BUILD)/esp-idf/config CFLAGS += -DHAVE_CONFIG_H \ diff --git a/ports/esp32s2/common-hal/ota/__init__.c b/ports/esp32s2/common-hal/ota/__init__.c index 87daffa568..727b6b107b 100644 --- a/ports/esp32s2/common-hal/ota/__init__.c +++ b/ports/esp32s2/common-hal/ota/__init__.c @@ -26,6 +26,105 @@ #include "shared-bindings/ota/__init__.h" -void common_hal_ota_flash(const void *buf, const size_t len) { +#include +#include "esp_log.h" +#include "esp_ota_ops.h" + +static const char *TAG = "OTA"; + +static void __attribute__((noreturn)) task_fatal_error(void) { + ESP_LOGE(TAG, "Exiting task due to fatal error..."); + mp_raise_RuntimeError(translate("OTA Update Failed")); +} + +void common_hal_ota_flash(const void *buf, const size_t len) { + esp_err_t err; + /* update handle : set by esp_ota_begin(), must be freed via esp_ota_end() */ + esp_ota_handle_t update_handle = 0 ; + const esp_partition_t *update_partition = NULL; + + ESP_LOGI(TAG, "Starting update"); + + const esp_partition_t *configured = esp_ota_get_boot_partition(); + const esp_partition_t *running = esp_ota_get_running_partition(); + + if (configured != running) { + ESP_LOGW(TAG, "Configured OTA boot partition at offset 0x%08x, but running from offset 0x%08x", + configured->address, running->address); + ESP_LOGW(TAG, "(This can happen if either the OTA boot data or preferred boot image become corrupted somehow.)"); + } + ESP_LOGI(TAG, "Running partition type %d subtype %d (offset 0x%08x)", + running->type, running->subtype, running->address); + + update_partition = esp_ota_get_next_update_partition(NULL); + ESP_LOGI(TAG, "Writing partition type %d subtype %d (offset 0x%08x)\n", + update_partition->type, update_partition->subtype, update_partition->address); + assert(update_partition != NULL); + + + if (len > sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t) + sizeof(esp_app_desc_t)) { + // check current version with downloading + esp_app_desc_t new_app_info; + memcpy(&new_app_info, &((char *)buf)[sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t)], sizeof(esp_app_desc_t)); + ESP_LOGI(TAG, "New firmware version: %s", new_app_info.version); + + esp_app_desc_t running_app_info; + if (esp_ota_get_partition_description(running, &running_app_info) == ESP_OK) { + ESP_LOGI(TAG, "Running firmware version: %s", running_app_info.version); + } + + const esp_partition_t* last_invalid_app = esp_ota_get_last_invalid_partition(); + esp_app_desc_t invalid_app_info; + if (esp_ota_get_partition_description(last_invalid_app, &invalid_app_info) == ESP_OK) { + ESP_LOGI(TAG, "Last invalid firmware version: %s", invalid_app_info.version); + } + + // check current version with last invalid partition + if (last_invalid_app != NULL) { + if (memcmp(invalid_app_info.version, new_app_info.version, sizeof(new_app_info.version)) == 0) { + ESP_LOGW(TAG, "New version is the same as invalid version."); + ESP_LOGW(TAG, "Previously, there was an attempt to launch the firmware with %s version, but it failed.", invalid_app_info.version); + ESP_LOGW(TAG, "The firmware has been rolled back to the previous version."); + task_fatal_error(); + } + } + + if (memcmp(new_app_info.version, running_app_info.version, sizeof(new_app_info.version)) == 0) { + ESP_LOGW(TAG, "Current running version is the same as a new. We will not continue the update."); + task_fatal_error(); + } + + err = esp_ota_begin(update_partition, OTA_WITH_SEQUENTIAL_WRITES, &update_handle); + if (err != ESP_OK) { + ESP_LOGE(TAG, "esp_ota_begin failed (%s)", esp_err_to_name(err)); + task_fatal_error(); + } + ESP_LOGI(TAG, "esp_ota_begin succeeded"); + } else { + ESP_LOGE(TAG, "received package is not fit len"); + task_fatal_error(); + } + + err = esp_ota_write( update_handle, buf, len); + if (err != ESP_OK) { + ESP_LOGE(TAG, "esp_ota_write failed (%s)", esp_err_to_name(err)); + task_fatal_error(); + } + ESP_LOGI(TAG, "Total Write binary data length: %d", len); + + err = esp_ota_end(update_handle); + if (err != ESP_OK) { + if (err == ESP_ERR_OTA_VALIDATE_FAILED) { + ESP_LOGE(TAG, "Image validation failed, image is corrupted"); + } + ESP_LOGE(TAG, "esp_ota_end failed (%s)!", esp_err_to_name(err)); + task_fatal_error(); + } + + err = esp_ota_set_boot_partition(update_partition); + if (err != ESP_OK) { + ESP_LOGE(TAG, "esp_ota_set_boot_partition failed (%s)!", esp_err_to_name(err)); + task_fatal_error(); + } } From 20c3184c87ee198f97f322ec983f04cedcb9cdcc Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Thu, 10 Dec 2020 12:34:56 +0530 Subject: [PATCH 10/70] re-organize and clean-up --- ports/esp32s2/common-hal/ota/__init__.c | 42 +++++++++---------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/ports/esp32s2/common-hal/ota/__init__.c b/ports/esp32s2/common-hal/ota/__init__.c index 727b6b107b..b83a929a27 100644 --- a/ports/esp32s2/common-hal/ota/__init__.c +++ b/ports/esp32s2/common-hal/ota/__init__.c @@ -40,31 +40,23 @@ static void __attribute__((noreturn)) task_fatal_error(void) { void common_hal_ota_flash(const void *buf, const size_t len) { esp_err_t err; - /* update handle : set by esp_ota_begin(), must be freed via esp_ota_end() */ + esp_ota_handle_t update_handle = 0 ; const esp_partition_t *update_partition = NULL; + update_partition = esp_ota_get_next_update_partition(NULL); - ESP_LOGI(TAG, "Starting update"); - - const esp_partition_t *configured = esp_ota_get_boot_partition(); const esp_partition_t *running = esp_ota_get_running_partition(); + const esp_partition_t *last_invalid = esp_ota_get_last_invalid_partition(); - if (configured != running) { - ESP_LOGW(TAG, "Configured OTA boot partition at offset 0x%08x, but running from offset 0x%08x", - configured->address, running->address); - ESP_LOGW(TAG, "(This can happen if either the OTA boot data or preferred boot image become corrupted somehow.)"); - } ESP_LOGI(TAG, "Running partition type %d subtype %d (offset 0x%08x)", running->type, running->subtype, running->address); - update_partition = esp_ota_get_next_update_partition(NULL); ESP_LOGI(TAG, "Writing partition type %d subtype %d (offset 0x%08x)\n", update_partition->type, update_partition->subtype, update_partition->address); + assert(update_partition != NULL); - if (len > sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t) + sizeof(esp_app_desc_t)) { - // check current version with downloading esp_app_desc_t new_app_info; memcpy(&new_app_info, &((char *)buf)[sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t)], sizeof(esp_app_desc_t)); ESP_LOGI(TAG, "New firmware version: %s", new_app_info.version); @@ -74,25 +66,23 @@ void common_hal_ota_flash(const void *buf, const size_t len) { ESP_LOGI(TAG, "Running firmware version: %s", running_app_info.version); } - const esp_partition_t* last_invalid_app = esp_ota_get_last_invalid_partition(); esp_app_desc_t invalid_app_info; - if (esp_ota_get_partition_description(last_invalid_app, &invalid_app_info) == ESP_OK) { + if (esp_ota_get_partition_description(last_invalid, &invalid_app_info) == ESP_OK) { ESP_LOGI(TAG, "Last invalid firmware version: %s", invalid_app_info.version); } - // check current version with last invalid partition - if (last_invalid_app != NULL) { - if (memcmp(invalid_app_info.version, new_app_info.version, sizeof(new_app_info.version)) == 0) { - ESP_LOGW(TAG, "New version is the same as invalid version."); - ESP_LOGW(TAG, "Previously, there was an attempt to launch the firmware with %s version, but it failed.", invalid_app_info.version); - ESP_LOGW(TAG, "The firmware has been rolled back to the previous version."); - task_fatal_error(); - } + // check new version with running version + if (memcmp(new_app_info.version, running_app_info.version, sizeof(new_app_info.version)) == 0) { + ESP_LOGW(TAG, "New version is the same as running version."); + task_fatal_error(); } - if (memcmp(new_app_info.version, running_app_info.version, sizeof(new_app_info.version)) == 0) { - ESP_LOGW(TAG, "Current running version is the same as a new. We will not continue the update."); - task_fatal_error(); + // check new version with last invalid partition + if (last_invalid != NULL) { + if (memcmp(new_app_info.version, invalid_app_info.version, sizeof(new_app_info.version)) == 0) { + ESP_LOGW(TAG, "New version is the same as invalid version."); + task_fatal_error(); + } } err = esp_ota_begin(update_partition, OTA_WITH_SEQUENTIAL_WRITES, &update_handle); @@ -100,7 +90,6 @@ void common_hal_ota_flash(const void *buf, const size_t len) { ESP_LOGE(TAG, "esp_ota_begin failed (%s)", esp_err_to_name(err)); task_fatal_error(); } - ESP_LOGI(TAG, "esp_ota_begin succeeded"); } else { ESP_LOGE(TAG, "received package is not fit len"); task_fatal_error(); @@ -111,7 +100,6 @@ void common_hal_ota_flash(const void *buf, const size_t len) { ESP_LOGE(TAG, "esp_ota_write failed (%s)", esp_err_to_name(err)); task_fatal_error(); } - ESP_LOGI(TAG, "Total Write binary data length: %d", len); err = esp_ota_end(update_handle); if (err != ESP_OK) { From dee86a014b783aff61a72f9915a4538a7fc97e4e Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Thu, 10 Dec 2020 14:04:24 +0530 Subject: [PATCH 11/70] factor out esp_ota_end --- ports/esp32s2/common-hal/ota/__init__.c | 9 +++++++-- shared-bindings/ota/__init__.c | 7 +++++++ shared-bindings/ota/__init__.h | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/ports/esp32s2/common-hal/ota/__init__.c b/ports/esp32s2/common-hal/ota/__init__.c index b83a929a27..2afb1904b2 100644 --- a/ports/esp32s2/common-hal/ota/__init__.c +++ b/ports/esp32s2/common-hal/ota/__init__.c @@ -31,6 +31,9 @@ #include "esp_log.h" #include "esp_ota_ops.h" +esp_ota_handle_t update_handle = 0 ; +const esp_partition_t *update_partition = NULL; + static const char *TAG = "OTA"; static void __attribute__((noreturn)) task_fatal_error(void) { @@ -41,8 +44,6 @@ static void __attribute__((noreturn)) task_fatal_error(void) { void common_hal_ota_flash(const void *buf, const size_t len) { esp_err_t err; - esp_ota_handle_t update_handle = 0 ; - const esp_partition_t *update_partition = NULL; update_partition = esp_ota_get_next_update_partition(NULL); const esp_partition_t *running = esp_ota_get_running_partition(); @@ -100,6 +101,10 @@ void common_hal_ota_flash(const void *buf, const size_t len) { ESP_LOGE(TAG, "esp_ota_write failed (%s)", esp_err_to_name(err)); task_fatal_error(); } +} + +void common_hal_ota_finish(void) { + esp_err_t err; err = esp_ota_end(update_handle); if (err != ESP_OK) { diff --git a/shared-bindings/ota/__init__.c b/shared-bindings/ota/__init__.c index a6c0424865..55858a80e9 100644 --- a/shared-bindings/ota/__init__.c +++ b/shared-bindings/ota/__init__.c @@ -30,6 +30,12 @@ //| //| The `ota` module implements over-the-air update.""" +STATIC mp_obj_t ota_finish(void) { + common_hal_ota_finish(); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(ota_finish_obj, ota_finish); + STATIC mp_obj_t ota_flash(mp_obj_t program_binary_in) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(program_binary_in, &bufinfo, MP_BUFFER_READ); @@ -41,6 +47,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(ota_flash_obj, ota_flash); STATIC const mp_rom_map_elem_t ota_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ota) }, + { MP_ROM_QSTR(MP_QSTR_finish), MP_ROM_PTR(&ota_finish_obj) }, { MP_ROM_QSTR(MP_QSTR_flash), MP_ROM_PTR(&ota_flash_obj) }, }; STATIC MP_DEFINE_CONST_DICT(ota_module_globals, ota_module_globals_table); diff --git a/shared-bindings/ota/__init__.h b/shared-bindings/ota/__init__.h index c4b40b2af3..1765c21ad7 100644 --- a/shared-bindings/ota/__init__.h +++ b/shared-bindings/ota/__init__.h @@ -29,6 +29,7 @@ #include "py/runtime.h" +extern void common_hal_ota_finish(void); extern void common_hal_ota_flash(const void *buf, const size_t len); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_OTA___INIT___H From ed5add37f6c6f6ed8e1acb6c14bd47df0fdfb0fb Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Thu, 10 Dec 2020 14:36:49 +0530 Subject: [PATCH 12/70] add ability to flash in continuous chunks --- ports/esp32s2/common-hal/ota/__init__.c | 114 ++++++++++++++---------- ports/esp32s2/common-hal/ota/__init__.h | 32 +++++++ 2 files changed, 97 insertions(+), 49 deletions(-) create mode 100644 ports/esp32s2/common-hal/ota/__init__.h diff --git a/ports/esp32s2/common-hal/ota/__init__.c b/ports/esp32s2/common-hal/ota/__init__.c index 2afb1904b2..6d0e8f11b5 100644 --- a/ports/esp32s2/common-hal/ota/__init__.c +++ b/ports/esp32s2/common-hal/ota/__init__.c @@ -31,11 +31,18 @@ #include "esp_log.h" #include "esp_ota_ops.h" -esp_ota_handle_t update_handle = 0 ; -const esp_partition_t *update_partition = NULL; +static const esp_partition_t *update_partition = NULL; +static esp_ota_handle_t update_handle = 0; +static bool ota_inited = false; static const char *TAG = "OTA"; +static void ota_reset(void) { + update_handle = 0; + update_partition = NULL; + ota_inited = false; +} + static void __attribute__((noreturn)) task_fatal_error(void) { ESP_LOGE(TAG, "Exiting task due to fatal error..."); mp_raise_RuntimeError(translate("OTA Update Failed")); @@ -44,56 +51,61 @@ static void __attribute__((noreturn)) task_fatal_error(void) { void common_hal_ota_flash(const void *buf, const size_t len) { esp_err_t err; - update_partition = esp_ota_get_next_update_partition(NULL); - const esp_partition_t *running = esp_ota_get_running_partition(); const esp_partition_t *last_invalid = esp_ota_get_last_invalid_partition(); - ESP_LOGI(TAG, "Running partition type %d subtype %d (offset 0x%08x)", - running->type, running->subtype, running->address); + if (update_partition == NULL) { + update_partition = esp_ota_get_next_update_partition(NULL); - ESP_LOGI(TAG, "Writing partition type %d subtype %d (offset 0x%08x)\n", - update_partition->type, update_partition->subtype, update_partition->address); + ESP_LOGI(TAG, "Running partition type %d subtype %d (offset 0x%08x)", + running->type, running->subtype, running->address); - assert(update_partition != NULL); + ESP_LOGI(TAG, "Writing partition type %d subtype %d (offset 0x%08x)\n", + update_partition->type, update_partition->subtype, update_partition->address); - if (len > sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t) + sizeof(esp_app_desc_t)) { - esp_app_desc_t new_app_info; - memcpy(&new_app_info, &((char *)buf)[sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t)], sizeof(esp_app_desc_t)); - ESP_LOGI(TAG, "New firmware version: %s", new_app_info.version); + assert(update_partition != NULL); + } - esp_app_desc_t running_app_info; - if (esp_ota_get_partition_description(running, &running_app_info) == ESP_OK) { - ESP_LOGI(TAG, "Running firmware version: %s", running_app_info.version); - } + if (!ota_inited) { + if (len > sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t) + sizeof(esp_app_desc_t)) { + esp_app_desc_t new_app_info; + memcpy(&new_app_info, &((char *)buf)[sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t)], sizeof(esp_app_desc_t)); + ESP_LOGI(TAG, "New firmware version: %s", new_app_info.version); - esp_app_desc_t invalid_app_info; - if (esp_ota_get_partition_description(last_invalid, &invalid_app_info) == ESP_OK) { - ESP_LOGI(TAG, "Last invalid firmware version: %s", invalid_app_info.version); - } + esp_app_desc_t running_app_info; + if (esp_ota_get_partition_description(running, &running_app_info) == ESP_OK) { + ESP_LOGI(TAG, "Running firmware version: %s", running_app_info.version); + } - // check new version with running version - if (memcmp(new_app_info.version, running_app_info.version, sizeof(new_app_info.version)) == 0) { - ESP_LOGW(TAG, "New version is the same as running version."); - task_fatal_error(); - } + esp_app_desc_t invalid_app_info; + if (esp_ota_get_partition_description(last_invalid, &invalid_app_info) == ESP_OK) { + ESP_LOGI(TAG, "Last invalid firmware version: %s", invalid_app_info.version); + } - // check new version with last invalid partition - if (last_invalid != NULL) { - if (memcmp(new_app_info.version, invalid_app_info.version, sizeof(new_app_info.version)) == 0) { - ESP_LOGW(TAG, "New version is the same as invalid version."); + // check new version with running version + if (memcmp(new_app_info.version, running_app_info.version, sizeof(new_app_info.version)) == 0) { + ESP_LOGW(TAG, "New version is the same as running version."); task_fatal_error(); } - } - err = esp_ota_begin(update_partition, OTA_WITH_SEQUENTIAL_WRITES, &update_handle); - if (err != ESP_OK) { - ESP_LOGE(TAG, "esp_ota_begin failed (%s)", esp_err_to_name(err)); + // check new version with last invalid partition + if (last_invalid != NULL) { + if (memcmp(new_app_info.version, invalid_app_info.version, sizeof(new_app_info.version)) == 0) { + ESP_LOGW(TAG, "New version is the same as invalid version."); + task_fatal_error(); + } + } + + err = esp_ota_begin(update_partition, OTA_WITH_SEQUENTIAL_WRITES, &update_handle); + if (err != ESP_OK) { + ESP_LOGE(TAG, "esp_ota_begin failed (%s)", esp_err_to_name(err)); + task_fatal_error(); + } + ota_inited = true; + } else { + ESP_LOGE(TAG, "received package is not fit len"); task_fatal_error(); } - } else { - ESP_LOGE(TAG, "received package is not fit len"); - task_fatal_error(); } err = esp_ota_write( update_handle, buf, len); @@ -104,20 +116,24 @@ void common_hal_ota_flash(const void *buf, const size_t len) { } void common_hal_ota_finish(void) { - esp_err_t err; + if (ota_inited) { + esp_err_t err; - err = esp_ota_end(update_handle); - if (err != ESP_OK) { - if (err == ESP_ERR_OTA_VALIDATE_FAILED) { - ESP_LOGE(TAG, "Image validation failed, image is corrupted"); + err = esp_ota_end(update_handle); + if (err != ESP_OK) { + if (err == ESP_ERR_OTA_VALIDATE_FAILED) { + ESP_LOGE(TAG, "Image validation failed, image is corrupted"); + } + ESP_LOGE(TAG, "esp_ota_end failed (%s)!", esp_err_to_name(err)); + task_fatal_error(); } - ESP_LOGE(TAG, "esp_ota_end failed (%s)!", esp_err_to_name(err)); - task_fatal_error(); - } - err = esp_ota_set_boot_partition(update_partition); - if (err != ESP_OK) { - ESP_LOGE(TAG, "esp_ota_set_boot_partition failed (%s)!", esp_err_to_name(err)); - task_fatal_error(); + err = esp_ota_set_boot_partition(update_partition); + if (err != ESP_OK) { + ESP_LOGE(TAG, "esp_ota_set_boot_partition failed (%s)!", esp_err_to_name(err)); + task_fatal_error(); + } + + ota_reset(); } } diff --git a/ports/esp32s2/common-hal/ota/__init__.h b/ports/esp32s2/common-hal/ota/__init__.h new file mode 100644 index 0000000000..317604a8ec --- /dev/null +++ b/ports/esp32s2/common-hal/ota/__init__.h @@ -0,0 +1,32 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 microDev + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_ESP32S2_COMMON_HAL_OTA__INIT__H +#define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_OTA__INIT__H + +extern void ota_reset(void); + +#endif //MICROPY_INCLUDED_ESP32S2_COMMON_HAL_OTA__INIT__H From bfa2c604efa213628bb33ad870b851a43f21c877 Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Thu, 10 Dec 2020 15:45:25 +0530 Subject: [PATCH 13/70] add ability to flash in discontinuous chunks --- ports/esp32s2/common-hal/ota/__init__.c | 8 ++++++-- shared-bindings/ota/__init__.c | 23 ++++++++++++++++++----- shared-bindings/ota/__init__.h | 2 +- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/ports/esp32s2/common-hal/ota/__init__.c b/ports/esp32s2/common-hal/ota/__init__.c index 6d0e8f11b5..97cc67b766 100644 --- a/ports/esp32s2/common-hal/ota/__init__.c +++ b/ports/esp32s2/common-hal/ota/__init__.c @@ -48,7 +48,7 @@ static void __attribute__((noreturn)) task_fatal_error(void) { mp_raise_RuntimeError(translate("OTA Update Failed")); } -void common_hal_ota_flash(const void *buf, const size_t len) { +void common_hal_ota_flash(const void *buf, const size_t len, const int32_t offset) { esp_err_t err; const esp_partition_t *running = esp_ota_get_running_partition(); @@ -108,7 +108,11 @@ void common_hal_ota_flash(const void *buf, const size_t len) { } } - err = esp_ota_write( update_handle, buf, len); + if (offset == -1) { + err = esp_ota_write(update_handle, buf, len); + } else { + err = esp_ota_write_with_offset(update_handle, buf, len, offset); + } if (err != ESP_OK) { ESP_LOGE(TAG, "esp_ota_write failed (%s)", esp_err_to_name(err)); task_fatal_error(); diff --git a/shared-bindings/ota/__init__.c b/shared-bindings/ota/__init__.c index 55858a80e9..84a46c83a2 100644 --- a/shared-bindings/ota/__init__.c +++ b/shared-bindings/ota/__init__.c @@ -36,14 +36,27 @@ STATIC mp_obj_t ota_finish(void) { } STATIC MP_DEFINE_CONST_FUN_OBJ_0(ota_finish_obj, ota_finish); -STATIC mp_obj_t ota_flash(mp_obj_t program_binary_in) { - mp_buffer_info_t bufinfo; - mp_get_buffer_raise(program_binary_in, &bufinfo, MP_BUFFER_READ); +STATIC mp_obj_t ota_flash(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_binary, ARG_offset }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_binary, MP_ARG_OBJ | MP_ARG_REQUIRED }, + { MP_QSTR_offset, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} }, + }; - common_hal_ota_flash(bufinfo.buf, bufinfo.len); + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + if (args[ARG_offset].u_int < -1) { + mp_raise_ValueError(translate("offset must be >= 0")); + } + + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(args[ARG_binary].u_obj, &bufinfo, MP_BUFFER_READ); + + common_hal_ota_flash(bufinfo.buf, bufinfo.len, args[ARG_offset].u_int); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(ota_flash_obj, ota_flash); +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ota_flash_obj, 1, ota_flash); STATIC const mp_rom_map_elem_t ota_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ota) }, diff --git a/shared-bindings/ota/__init__.h b/shared-bindings/ota/__init__.h index 1765c21ad7..9eec604e0b 100644 --- a/shared-bindings/ota/__init__.h +++ b/shared-bindings/ota/__init__.h @@ -30,6 +30,6 @@ #include "py/runtime.h" extern void common_hal_ota_finish(void); -extern void common_hal_ota_flash(const void *buf, const size_t len); +extern void common_hal_ota_flash(const void *buf, const size_t len, const int32_t offset); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_OTA___INIT___H From 07015ad527f81d81829190b31569a35a305676ce Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Thu, 10 Dec 2020 16:42:45 +0530 Subject: [PATCH 14/70] add ability to switch boot partition --- ports/esp32s2/common-hal/ota/__init__.c | 6 ++++++ shared-bindings/ota/__init__.c | 7 +++++++ shared-bindings/ota/__init__.h | 1 + 3 files changed, 14 insertions(+) diff --git a/ports/esp32s2/common-hal/ota/__init__.c b/ports/esp32s2/common-hal/ota/__init__.c index 97cc67b766..4ec1021317 100644 --- a/ports/esp32s2/common-hal/ota/__init__.c +++ b/ports/esp32s2/common-hal/ota/__init__.c @@ -141,3 +141,9 @@ void common_hal_ota_finish(void) { ota_reset(); } } + +void common_hal_ota_switch(void) { + if (esp_ota_set_boot_partition(esp_ota_get_next_update_partition(NULL)) != ESP_OK) { + mp_raise_RuntimeError(translate("Unable to switch partition")); + } +} diff --git a/shared-bindings/ota/__init__.c b/shared-bindings/ota/__init__.c index 84a46c83a2..46399dcb2e 100644 --- a/shared-bindings/ota/__init__.c +++ b/shared-bindings/ota/__init__.c @@ -30,6 +30,12 @@ //| //| The `ota` module implements over-the-air update.""" +STATIC mp_obj_t ota_switch(void) { + common_hal_ota_switch(); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(ota_switch_obj, ota_switch); + STATIC mp_obj_t ota_finish(void) { common_hal_ota_finish(); return mp_const_none; @@ -60,6 +66,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ota_flash_obj, 1, ota_flash); STATIC const mp_rom_map_elem_t ota_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ota) }, + { MP_ROM_QSTR(MP_QSTR_switch), MP_ROM_PTR(&ota_switch_obj) }, { MP_ROM_QSTR(MP_QSTR_finish), MP_ROM_PTR(&ota_finish_obj) }, { MP_ROM_QSTR(MP_QSTR_flash), MP_ROM_PTR(&ota_flash_obj) }, }; diff --git a/shared-bindings/ota/__init__.h b/shared-bindings/ota/__init__.h index 9eec604e0b..82273f975a 100644 --- a/shared-bindings/ota/__init__.h +++ b/shared-bindings/ota/__init__.h @@ -29,6 +29,7 @@ #include "py/runtime.h" +extern void common_hal_ota_switch(void); extern void common_hal_ota_finish(void); extern void common_hal_ota_flash(const void *buf, const size_t len, const int32_t offset); From 6a4f74946fc717f8c95c43f364290e3e9d2cd2fa Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Thu, 10 Dec 2020 16:48:58 +0530 Subject: [PATCH 15/70] reset ota module on every vm run --- ports/esp32s2/common-hal/ota/__init__.c | 3 ++- ports/esp32s2/common-hal/ota/__init__.h | 6 +++--- ports/esp32s2/supervisor/port.c | 5 +++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ports/esp32s2/common-hal/ota/__init__.c b/ports/esp32s2/common-hal/ota/__init__.c index 4ec1021317..40cfce6769 100644 --- a/ports/esp32s2/common-hal/ota/__init__.c +++ b/ports/esp32s2/common-hal/ota/__init__.c @@ -24,6 +24,7 @@ * THE SOFTWARE. */ +#include "common-hal/ota/__init__.h" #include "shared-bindings/ota/__init__.h" #include @@ -37,7 +38,7 @@ static esp_ota_handle_t update_handle = 0; static bool ota_inited = false; static const char *TAG = "OTA"; -static void ota_reset(void) { +void ota_reset(void) { update_handle = 0; update_partition = NULL; ota_inited = false; diff --git a/ports/esp32s2/common-hal/ota/__init__.h b/ports/esp32s2/common-hal/ota/__init__.h index 317604a8ec..983b57e3f2 100644 --- a/ports/esp32s2/common-hal/ota/__init__.h +++ b/ports/esp32s2/common-hal/ota/__init__.h @@ -24,9 +24,9 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_ESP32S2_COMMON_HAL_OTA__INIT__H -#define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_OTA__INIT__H +#ifndef MICROPY_INCLUDED_ESP32S2_COMMON_HAL_OTA___INIT___H +#define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_OTA___INIT___H extern void ota_reset(void); -#endif //MICROPY_INCLUDED_ESP32S2_COMMON_HAL_OTA__INIT__H +#endif //MICROPY_INCLUDED_ESP32S2_COMMON_HAL_OTA___INIT___H diff --git a/ports/esp32s2/supervisor/port.c b/ports/esp32s2/supervisor/port.c index 0841081de8..4cca862d87 100644 --- a/ports/esp32s2/supervisor/port.c +++ b/ports/esp32s2/supervisor/port.c @@ -41,6 +41,7 @@ #include "common-hal/busio/I2C.h" #include "common-hal/busio/SPI.h" #include "common-hal/busio/UART.h" +#include "common-hal/ota/__init__.h" #include "common-hal/ps2io/Ps2.h" #include "common-hal/pulseio/PulseIn.h" #include "common-hal/pwmio/PWMOut.h" @@ -107,6 +108,10 @@ void reset_port(void) { analogout_reset(); #endif +#if CIRCUITPY_OTA + ota_reset(); +#endif + #if CIRCUITPY_PS2IO ps2_reset(); #endif From cb35abfd04762871283e0323bddf0904d27913ea Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Fri, 11 Dec 2020 01:01:01 +0530 Subject: [PATCH 16/70] add docs, update translation & fix ota.flash() --- locale/circuitpython.pot | 10 +++++++++- ports/esp32s2/common-hal/ota/__init__.c | 2 +- shared-bindings/ota/__init__.c | 23 ++++++++++++++++++----- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 5bf95043a6..214b7aad16 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-12-08 10:30+0530\n" +"POT-Creation-Date: 2020-12-10 16:56+0530\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1907,6 +1907,10 @@ msgstr "" msgid "Unable to read color palette data" msgstr "" +#: ports/esp32s2/common-hal/ota/__init__.c +msgid "Unable to switch boot partition" +msgstr "" + #: shared-bindings/nvm/ByteArray.c msgid "Unable to write to nvm." msgstr "" @@ -3198,6 +3202,10 @@ msgstr "" msgid "offset is too large" msgstr "" +#: shared-bindings/ota/__init__.c +msgid "offset must be >= 0" +msgstr "" + #: py/objstr.c py/objstrunicode.c msgid "offset out of bounds" msgstr "" diff --git a/ports/esp32s2/common-hal/ota/__init__.c b/ports/esp32s2/common-hal/ota/__init__.c index 40cfce6769..5ea25fb5d4 100644 --- a/ports/esp32s2/common-hal/ota/__init__.c +++ b/ports/esp32s2/common-hal/ota/__init__.c @@ -145,6 +145,6 @@ void common_hal_ota_finish(void) { void common_hal_ota_switch(void) { if (esp_ota_set_boot_partition(esp_ota_get_next_update_partition(NULL)) != ESP_OK) { - mp_raise_RuntimeError(translate("Unable to switch partition")); + mp_raise_RuntimeError(translate("Unable to switch boot partition")); } } diff --git a/shared-bindings/ota/__init__.c b/shared-bindings/ota/__init__.c index 46399dcb2e..03636779fe 100644 --- a/shared-bindings/ota/__init__.c +++ b/shared-bindings/ota/__init__.c @@ -30,39 +30,52 @@ //| //| The `ota` module implements over-the-air update.""" +//| def switch() -> None: +//| """Switches the boot partition. +//| ... +//| STATIC mp_obj_t ota_switch(void) { common_hal_ota_switch(); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_0(ota_switch_obj, ota_switch); +//| def finish() -> None: +//| """Validates flashed firmware, sets next boot partition. +//| **Must be called after** `ota.flash()` +//| ... +//| STATIC mp_obj_t ota_finish(void) { common_hal_ota_finish(); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_0(ota_finish_obj, ota_finish); +//| def flash(*buffer: WriteableBuffer, offset: int=0) -> None: +//| """Writes one of two OTA partition at the given offset. +//| ... +//| STATIC mp_obj_t ota_flash(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_binary, ARG_offset }; + enum { ARG_buffer, ARG_offset }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_binary, MP_ARG_OBJ | MP_ARG_REQUIRED }, + { MP_QSTR_buffer, MP_ARG_OBJ | MP_ARG_REQUIRED }, { MP_QSTR_offset, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); if (args[ARG_offset].u_int < -1) { mp_raise_ValueError(translate("offset must be >= 0")); } mp_buffer_info_t bufinfo; - mp_get_buffer_raise(args[ARG_binary].u_obj, &bufinfo, MP_BUFFER_READ); + mp_get_buffer_raise(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_READ); common_hal_ota_flash(bufinfo.buf, bufinfo.len, args[ARG_offset].u_int); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ota_flash_obj, 1, ota_flash); +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ota_flash_obj, 0, ota_flash); STATIC const mp_rom_map_elem_t ota_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ota) }, From 08e94e6a204708060860a9ed3b801bf3fb5b5ecc Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Fri, 11 Dec 2020 22:55:22 +0530 Subject: [PATCH 17/70] add more docs --- shared-bindings/ota/__init__.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/shared-bindings/ota/__init__.c b/shared-bindings/ota/__init__.c index 03636779fe..152a8e802d 100644 --- a/shared-bindings/ota/__init__.c +++ b/shared-bindings/ota/__init__.c @@ -26,12 +26,26 @@ #include "shared-bindings/ota/__init__.h" -//| """ota module +//| """OTA Module +//| +//| The `ota` module implements over-the-air update. +//| +//| There are two identical ota partitions ota_0/1, these +//| contain different firmware versions. +//| Having two partitions enables rollback functionality. +//| +//| The two partitions are defined as boot partition and +//| next-update partition. Calling `ota.flash()` writes the +//| next-update partition. +//| +//| After the next-update partition is written a validation +//| check is performed and on a successful validation this +//| partition is set as the boot partition. On next reset, +//| firmware will be loaded from this partition""" //| -//| The `ota` module implements over-the-air update.""" //| def switch() -> None: -//| """Switches the boot partition. +//| """Switches the boot partition.""" //| ... //| STATIC mp_obj_t ota_switch(void) { @@ -42,7 +56,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(ota_switch_obj, ota_switch); //| def finish() -> None: //| """Validates flashed firmware, sets next boot partition. -//| **Must be called after** `ota.flash()` +//| **Must be called after** `ota.flash()`""" //| ... //| STATIC mp_obj_t ota_finish(void) { @@ -52,7 +66,10 @@ STATIC mp_obj_t ota_finish(void) { STATIC MP_DEFINE_CONST_FUN_OBJ_0(ota_finish_obj, ota_finish); //| def flash(*buffer: WriteableBuffer, offset: int=0) -> None: -//| """Writes one of two OTA partition at the given offset. +//| """Writes one of two OTA partitions at the given offset. +//| +//| The default offset is 0. It is necessary to provide the +//| offset when writing in discontinous chunks.""" //| ... //| STATIC mp_obj_t ota_flash(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { From 92098ca06b2d119db7810738ed7da262bdea5686 Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Sat, 12 Dec 2020 05:15:25 +0530 Subject: [PATCH 18/70] update docs, implement suggested changes --- shared-bindings/ota/__init__.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/shared-bindings/ota/__init__.c b/shared-bindings/ota/__init__.c index 152a8e802d..8ecc6d9c41 100644 --- a/shared-bindings/ota/__init__.c +++ b/shared-bindings/ota/__init__.c @@ -41,11 +41,24 @@ //| After the next-update partition is written a validation //| check is performed and on a successful validation this //| partition is set as the boot partition. On next reset, -//| firmware will be loaded from this partition""" +//| firmware will be loaded from this partition. +//| +//| Here is the sequence of commands to follow: +//| +//| .. code-block:: python +//| +//| import ota +//| +//| ota.flash(buffer, offset) +//| ota.finish() +//| """ +//| ... //| //| def switch() -> None: -//| """Switches the boot partition.""" +//| """Switches the boot partition. On next reset, +//| firmware will be loaded from the partition +//| just switched over to.""" //| ... //| STATIC mp_obj_t ota_switch(void) { @@ -56,7 +69,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(ota_switch_obj, ota_switch); //| def finish() -> None: //| """Validates flashed firmware, sets next boot partition. -//| **Must be called after** `ota.flash()`""" +//| **Must be called** after the firmware has been +//| completely written into the flash using `ota.flash()`. +//| +//| This is to be called only once per update.""" //| ... //| STATIC mp_obj_t ota_finish(void) { @@ -65,11 +81,14 @@ STATIC mp_obj_t ota_finish(void) { } STATIC MP_DEFINE_CONST_FUN_OBJ_0(ota_finish_obj, ota_finish); -//| def flash(*buffer: WriteableBuffer, offset: int=0) -> None: +//| def flash(*buffer: ReadableBuffer, offset: int=0) -> None: //| """Writes one of two OTA partitions at the given offset. //| //| The default offset is 0. It is necessary to provide the -//| offset when writing in discontinous chunks.""" +//| offset when writing in discontinous chunks. +//| +//| This can be called multiple times when flashing the firmware +//| in small chunks.""" //| ... //| STATIC mp_obj_t ota_flash(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { From eea8bc4999fc56990884e7854a9402b3633000d7 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 14 Dec 2020 15:41:17 -0500 Subject: [PATCH 19/70] Use Dec 11 gcc 10.2 release --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c032b1b8a3..16f7914117 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -341,7 +341,7 @@ jobs: run: | sudo apt-get install -y gettext pip install requests sh click setuptools awscli - wget --no-verbose https://developer.arm.com/-/media/Files/downloads/gnu-rm/10-2020q2/gcc-arm-none-eabi-10-2020-q2-preview-x86_64-linux.tar.bz2 + wget --no-verbose https://adafruit-circuit-python.s3.amazonaws.com/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2 sudo tar -C /usr --strip-components=1 -xaf gcc-arm-none-eabi-10-2020-q2-preview-x86_64-linux.tar.bz2 - name: Versions run: | From d2cb58a2df81ddaadaaa5f08699760885e2ecb81 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 14 Dec 2020 15:54:38 -0500 Subject: [PATCH 20/70] suod apt-get update --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 16f7914117..2cef968a4d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,6 +35,7 @@ jobs: python-version: 3.8 - name: Install deps run: | + sudo apt-get update sudo apt-get install -y eatmydata sudo eatmydata apt-get install -y gettext librsvg2-bin mingw-w64 latexmk texlive-fonts-recommended texlive-latex-recommended texlive-latex-extra pip install requests sh click setuptools cpp-coveralls "Sphinx<4" sphinx-rtd-theme recommonmark sphinx-autoapi sphinxcontrib-svg2pdfconverter polib pyyaml astroid isort black awscli mypy From 845cf03a45c098886acd62c836848194f1161d03 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 14 Dec 2020 15:55:31 -0500 Subject: [PATCH 21/70] typo --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2cef968a4d..35f1743db4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -343,7 +343,7 @@ jobs: sudo apt-get install -y gettext pip install requests sh click setuptools awscli wget --no-verbose https://adafruit-circuit-python.s3.amazonaws.com/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2 - sudo tar -C /usr --strip-components=1 -xaf gcc-arm-none-eabi-10-2020-q2-preview-x86_64-linux.tar.bz2 + sudo tar -C /usr --strip-components=1 -xaf gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2 - name: Versions run: | gcc --version From 731cdefe801633ef39c9036cda6951da50b0075c Mon Sep 17 00:00:00 2001 From: Seth Kerr Date: Mon, 14 Dec 2020 16:25:33 -0500 Subject: [PATCH 22/70] this should be it. --- supervisor/shared/external_flash/devices.h | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/supervisor/shared/external_flash/devices.h b/supervisor/shared/external_flash/devices.h index a874dbd4fd..30eb7d7212 100644 --- a/supervisor/shared/external_flash/devices.h +++ b/supervisor/shared/external_flash/devices.h @@ -94,6 +94,26 @@ typedef struct { .single_status_byte = false, \ } +// Settings for the Adesto Tech AT25DF641-SSHD-T 8MiB SPI flash +// for the Oak Dev Tech Icy Tree M0 (SAMD21) feather board. +// Source: https://www.digikey.com/product-detail/en/adesto-technologies/AT25SF641-SDHD-T/1265-1180-1-ND/ +// Datasheet: https://www.adestotech.com/wp-content/uploads/doc8693.pdf +#define AT25DF641A {\ + .total_size = (1 << 23), /* 8 MiB */ \ + .start_up_time_us = 10000, \ + .manufacturer_id = 0x1f, \ + .memory_type = 0x48, \ + .capacity = 0x00, \ + .max_clock_speed_mhz = 85, \ + .quad_enable_bit_mask = 0x00, \ + .has_sector_protection = true, \ + .supports_fast_read = true, \ + .supports_qspi = false, \ + .supports_qspi_writes = false, \ + .write_status_register_split = false, \ + .single_status_byte = false, \ +} + // Settings for the Adesto Tech AT25SF161-SSHD-T 2MiB SPI flash // for the StringCar M0 (SAMD21) Express board. // Source: https://www.digikey.com/product-detail/en/adesto-technologies/AT25SF161-SDHD-T/1265-1230-1-ND/ @@ -114,6 +134,7 @@ typedef struct { .single_status_byte = false, \ } + // Settings for the Adesto Tech AT25SF041 1MiB SPI flash. It's on the SparkFun // SAMD51 Thing Plus board // Datasheet: https://www.adestotech.com/wp-content/uploads/DS-AT25SF041_044.pdf @@ -566,6 +587,25 @@ typedef struct { .single_status_byte = true, \ } +// Settings for the Macronix MX25L51245G 64MiB SPI flash. +// Datasheet: https://www.macronix.com/Lists/Datasheet/Attachments/7437/MX25L51245G,%203V,%20512Mb,%20v1.6.pdf +// Will finish this addition in a future PR. All the stuff is there, just need to test in the wild. +//#define MX25L25645G {\ + .total_size = (1 << 25), /* 32 MiB */ \ + .start_up_time_us = 5000, \ + .manufacturer_id = 0x9f, \ + .memory_type = 0xab, \ + .capacity = 0x90, \ + .max_clock_speed_mhz = 133, \ + .quad_enable_bit_mask = 0xaf, \ + .has_sector_protection = false, \ + .supports_fast_read = true, \ + .supports_qspi = true, \ + .supports_qspi_writes = true, \ + .write_status_register_split = false, \ + .single_status_byte = true, \ +}*/ + // Settings for the Winbond W25Q128JV-PM 16MiB SPI flash. Note that JV-IM has a different .memory_type (0x70) // Datasheet: https://www.winbond.com/resource-files/w25q128jv%20revf%2003272018%20plus.pdf #define W25Q128JV_PM {\ From 6d8642bf41491610e8d76ddfdd9f055d83568e61 Mon Sep 17 00:00:00 2001 From: Seth Kerr Date: Mon, 14 Dec 2020 17:17:28 -0500 Subject: [PATCH 23/70] fixing line comment issue with CI build tests --- supervisor/shared/external_flash/devices.h | 28 +++++++++++----------- tests/pyboard 2.py | 1 + 2 files changed, 15 insertions(+), 14 deletions(-) create mode 120000 tests/pyboard 2.py diff --git a/supervisor/shared/external_flash/devices.h b/supervisor/shared/external_flash/devices.h index 30eb7d7212..fafb68ef03 100644 --- a/supervisor/shared/external_flash/devices.h +++ b/supervisor/shared/external_flash/devices.h @@ -591,20 +591,20 @@ typedef struct { // Datasheet: https://www.macronix.com/Lists/Datasheet/Attachments/7437/MX25L51245G,%203V,%20512Mb,%20v1.6.pdf // Will finish this addition in a future PR. All the stuff is there, just need to test in the wild. //#define MX25L25645G {\ - .total_size = (1 << 25), /* 32 MiB */ \ - .start_up_time_us = 5000, \ - .manufacturer_id = 0x9f, \ - .memory_type = 0xab, \ - .capacity = 0x90, \ - .max_clock_speed_mhz = 133, \ - .quad_enable_bit_mask = 0xaf, \ - .has_sector_protection = false, \ - .supports_fast_read = true, \ - .supports_qspi = true, \ - .supports_qspi_writes = true, \ - .write_status_register_split = false, \ - .single_status_byte = true, \ -}*/ +// .total_size = (1 << 25), /* 32 MiB */ \ +// .start_up_time_us = 5000, \ +// .manufacturer_id = 0x9f, \ +// .memory_type = 0xab, \ +// .capacity = 0x90, \ +// .max_clock_speed_mhz = 133, \ +// .quad_enable_bit_mask = 0xaf, \ +// .has_sector_protection = false, \ +// .supports_fast_read = true, \ +// .supports_qspi = true, \ +// .supports_qspi_writes = true, \ +// .write_status_register_split = false, \ +// .single_status_byte = true, \ +//} // Settings for the Winbond W25Q128JV-PM 16MiB SPI flash. Note that JV-IM has a different .memory_type (0x70) // Datasheet: https://www.winbond.com/resource-files/w25q128jv%20revf%2003272018%20plus.pdf diff --git a/tests/pyboard 2.py b/tests/pyboard 2.py new file mode 120000 index 0000000000..616773a313 --- /dev/null +++ b/tests/pyboard 2.py @@ -0,0 +1 @@ +../tools/cpboard.py \ No newline at end of file From c16b8f1ee5eb4cea1131ba7db4938c65fb1045d0 Mon Sep 17 00:00:00 2001 From: Seth Kerr Date: Mon, 14 Dec 2020 17:26:27 -0500 Subject: [PATCH 24/70] odd thing with a tests/pyboard\ 2.py file showing up --- tests/pyboard 2.py | 1 - 1 file changed, 1 deletion(-) delete mode 120000 tests/pyboard 2.py diff --git a/tests/pyboard 2.py b/tests/pyboard 2.py deleted file mode 120000 index 616773a313..0000000000 --- a/tests/pyboard 2.py +++ /dev/null @@ -1 +0,0 @@ -../tools/cpboard.py \ No newline at end of file From 6abe3cd0ef6c04108b1728797830ebfd1827ecaa Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 14 Dec 2020 18:57:31 -0500 Subject: [PATCH 25/70] -Os for SAMD51; fix CSUPEROPT typo --- ports/atmel-samd/Makefile | 6 +++--- py/py.mk | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile index dc7b4e4c89..c214d56f0c 100644 --- a/ports/atmel-samd/Makefile +++ b/ports/atmel-samd/Makefile @@ -94,21 +94,21 @@ endif ifeq ($(CHIP_FAMILY), samd51) PERIPHERALS_CHIP_FAMILY=sam_d5x_e5x -OPTIMIZATION_FLAGS ?= -O2 +OPTIMIZATION_FLAGS ?= -Os # TinyUSB defines CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_SAMD51 -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_CDC_RX_BUFSIZE=256 -DCFG_TUD_MIDI_TX_BUFSIZE=128 -DCFG_TUD_CDC_TX_BUFSIZE=256 -DCFG_TUD_MSC_BUFSIZE=1024 endif ifeq ($(CHIP_FAMILY), same51) PERIPHERALS_CHIP_FAMILY=sam_d5x_e5x -OPTIMIZATION_FLAGS ?= -O2 +OPTIMIZATION_FLAGS ?= -Os # TinyUSB defines CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_SAME5X -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_CDC_RX_BUFSIZE=256 -DCFG_TUD_MIDI_TX_BUFSIZE=128 -DCFG_TUD_CDC_TX_BUFSIZE=256 -DCFG_TUD_MSC_BUFSIZE=1024 endif ifeq ($(CHIP_FAMILY), same54) PERIPHERALS_CHIP_FAMILY=sam_d5x_e5x -OPTIMIZATION_FLAGS ?= -O2 +OPTIMIZATION_FLAGS ?= -Os # TinyUSB defines CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_SAME5X -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_CDC_RX_BUFSIZE=256 -DCFG_TUD_MIDI_TX_BUFSIZE=128 -DCFG_TUD_CDC_TX_BUFSIZE=256 -DCFG_TUD_MSC_BUFSIZE=1024 endif diff --git a/py/py.mk b/py/py.mk index 1a8f1219a5..3f94aa67a0 100644 --- a/py/py.mk +++ b/py/py.mk @@ -19,7 +19,7 @@ endif QSTR_GLOBAL_DEPENDENCIES += $(PY_SRC)/mpconfig.h mpconfigport.h # some code is performance bottleneck and compiled with other optimization options -_CSUPEROPT = -O3 +CSUPEROPT = -O3 # this sets the config file for FatFs CFLAGS_MOD += -DFFCONF_H=\"lib/oofatfs/ffconf.h\" From 97947b4fe9724639b57855d5b98445f4d0bacd33 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 14 Dec 2020 22:07:54 -0500 Subject: [PATCH 26/70] shrink bast_pro_mini_m0; use proper flex-array syntax --- .../_bleio/hci_include/att_internal.h | 46 +++++++++---------- .../common-hal/_bleio/hci_include/hci.h | 22 ++++----- .../common-hal/_bleio/hci_include/hci_vs.h | 20 ++++---- .../_bleio/hci_include/l2cap_internal.h | 16 +++---- .../boards/bast_pro_mini_m0/mpconfigboard.mk | 2 + 5 files changed, 54 insertions(+), 52 deletions(-) diff --git a/devices/ble_hci/common-hal/_bleio/hci_include/att_internal.h b/devices/ble_hci/common-hal/_bleio/hci_include/att_internal.h index d6a4cb79c7..678cb4201b 100644 --- a/devices/ble_hci/common-hal/_bleio/hci_include/att_internal.h +++ b/devices/ble_hci/common-hal/_bleio/hci_include/att_internal.h @@ -69,7 +69,7 @@ struct bt_att_info_128 { #define BT_ATT_OP_FIND_INFO_RSP 0x05 struct bt_att_find_info_rsp { uint8_t format; - uint8_t info[0]; + uint8_t info[]; } __packed; /* Find By Type Value Request */ @@ -78,7 +78,7 @@ struct bt_att_find_type_req { uint16_t start_handle; uint16_t end_handle; uint16_t type; - uint8_t value[0]; + uint8_t value[]; } __packed; struct bt_att_handle_group { @@ -89,7 +89,7 @@ struct bt_att_handle_group { /* Find By Type Value Response */ #define BT_ATT_OP_FIND_TYPE_RSP 0x07 struct bt_att_find_type_rsp { - struct bt_att_handle_group list[0]; + struct bt_att_handle_group list[]; } __packed; /* Read By Type Request */ @@ -97,19 +97,19 @@ struct bt_att_find_type_rsp { struct bt_att_read_type_req { uint16_t start_handle; uint16_t end_handle; - uint8_t uuid[0]; + uint8_t uuid[]; } __packed; struct bt_att_data { uint16_t handle; - uint8_t value[0]; + uint8_t value[]; } __packed; /* Read By Type Response */ #define BT_ATT_OP_READ_TYPE_RSP 0x09 struct bt_att_read_type_rsp { uint8_t len; - struct bt_att_data data[0]; + struct bt_att_data data[]; } __packed; /* Read Request */ @@ -121,7 +121,7 @@ struct bt_att_read_req { /* Read Response */ #define BT_ATT_OP_READ_RSP 0x0b struct bt_att_read_rsp { - uint8_t value[0]; + uint8_t value[]; } __packed; /* Read Blob Request */ @@ -134,7 +134,7 @@ struct bt_att_read_blob_req { /* Read Blob Response */ #define BT_ATT_OP_READ_BLOB_RSP 0x0d struct bt_att_read_blob_rsp { - uint8_t value[0]; + uint8_t value[]; } __packed; /* Read Multiple Request */ @@ -142,13 +142,13 @@ struct bt_att_read_blob_rsp { #define BT_ATT_OP_READ_MULT_REQ 0x0e struct bt_att_read_mult_req { - uint16_t handles[0]; + uint16_t handles[]; } __packed; /* Read Multiple Respose */ #define BT_ATT_OP_READ_MULT_RSP 0x0f struct bt_att_read_mult_rsp { - uint8_t value[0]; + uint8_t value[]; } __packed; /* Read by Group Type Request */ @@ -156,27 +156,27 @@ struct bt_att_read_mult_rsp { struct bt_att_read_group_req { uint16_t start_handle; uint16_t end_handle; - uint8_t uuid[0]; + uint8_t uuid[]; } __packed; struct bt_att_group_data { uint16_t start_handle; uint16_t end_handle; - uint8_t value[0]; + uint8_t value[]; } __packed; /* Read by Group Type Response */ #define BT_ATT_OP_READ_GROUP_RSP 0x11 struct bt_att_read_group_rsp { uint8_t len; - struct bt_att_group_data data[0]; + struct bt_att_group_data data[]; } __packed; /* Write Request */ #define BT_ATT_OP_WRITE_REQ 0x12 struct bt_att_write_req { uint16_t handle; - uint8_t value[0]; + uint8_t value[]; } __packed; /* Write Response */ @@ -187,7 +187,7 @@ struct bt_att_write_req { struct bt_att_prepare_write_req { uint16_t handle; uint16_t offset; - uint8_t value[0]; + uint8_t value[]; } __packed; /* Prepare Write Respond */ @@ -195,7 +195,7 @@ struct bt_att_prepare_write_req { struct bt_att_prepare_write_rsp { uint16_t handle; uint16_t offset; - uint8_t value[0]; + uint8_t value[]; } __packed; /* Execute Write Request */ @@ -214,14 +214,14 @@ struct bt_att_exec_write_req { #define BT_ATT_OP_NOTIFY 0x1b struct bt_att_notify { uint16_t handle; - uint8_t value[0]; + uint8_t value[]; } __packed; /* Handle Value Indication */ #define BT_ATT_OP_INDICATE 0x1d struct bt_att_indicate { uint16_t handle; - uint8_t value[0]; + uint8_t value[]; } __packed; /* Handle Value Confirm */ @@ -233,14 +233,14 @@ struct bt_att_signature { #define BT_ATT_OP_READ_MULT_VL_REQ 0x20 struct bt_att_read_mult_vl_req { - uint16_t handles[0]; + uint16_t handles[]; } __packed; /* Read Multiple Respose */ #define BT_ATT_OP_READ_MULT_VL_RSP 0x21 struct bt_att_read_mult_vl_rsp { uint16_t len; - uint8_t value[0]; + uint8_t value[]; } __packed; /* Handle Multiple Value Notification */ @@ -248,19 +248,19 @@ struct bt_att_read_mult_vl_rsp { struct bt_att_notify_mult { uint16_t handle; uint16_t len; - uint8_t value[0]; + uint8_t value[]; } __packed; /* Write Command */ #define BT_ATT_OP_WRITE_CMD 0x52 struct bt_att_write_cmd { uint16_t handle; - uint8_t value[0]; + uint8_t value[]; } __packed; /* Signed Write Command */ #define BT_ATT_OP_SIGNED_WRITE_CMD 0xd2 struct bt_att_signed_write_cmd { uint16_t handle; - uint8_t value[0]; + uint8_t value[]; } __packed; diff --git a/devices/ble_hci/common-hal/_bleio/hci_include/hci.h b/devices/ble_hci/common-hal/_bleio/hci_include/hci.h index 5213edbf0f..797278946a 100644 --- a/devices/ble_hci/common-hal/_bleio/hci_include/hci.h +++ b/devices/ble_hci/common-hal/_bleio/hci_include/hci.h @@ -454,7 +454,7 @@ struct bt_hci_handle_count { #define BT_HCI_OP_HOST_NUM_COMPLETED_PACKETS BT_OP(BT_OGF_BASEBAND, 0x0035) struct bt_hci_cp_host_num_completed_packets { uint8_t num_handles; - struct bt_hci_handle_count h[0]; + struct bt_hci_handle_count h[]; } __packed; #define BT_HCI_OP_WRITE_INQUIRY_MODE BT_OP(BT_OGF_BASEBAND, 0x0045) @@ -1099,7 +1099,7 @@ struct bt_hci_ext_adv_set { struct bt_hci_cp_le_set_ext_adv_enable { uint8_t enable; uint8_t set_num; - struct bt_hci_ext_adv_set s[0]; + struct bt_hci_ext_adv_set s[]; } __packed; #define BT_HCI_OP_LE_READ_MAX_ADV_DATA_LEN BT_OP(BT_OGF_LE, 0x003a) @@ -1158,7 +1158,7 @@ struct bt_hci_cp_le_set_ext_scan_param { uint8_t own_addr_type; uint8_t filter_policy; uint8_t phys; - struct bt_hci_ext_scan_phy p[0]; + struct bt_hci_ext_scan_phy p[]; } __packed; /* Extends BT_HCI_LE_SCAN_FILTER_DUP */ @@ -1189,7 +1189,7 @@ struct bt_hci_cp_le_ext_create_conn { uint8_t own_addr_type; bt_addr_le_t peer_addr; uint8_t phys; - struct bt_hci_ext_conn_phy p[0]; + struct bt_hci_ext_conn_phy p[]; } __packed; #define BT_HCI_OP_LE_PER_ADV_CREATE_SYNC BT_OP(BT_OGF_LE, 0x0044) @@ -1354,7 +1354,7 @@ struct bt_hci_evt_role_change { #define BT_HCI_EVT_NUM_COMPLETED_PACKETS 0x13 struct bt_hci_evt_num_completed_packets { uint8_t num_handles; - struct bt_hci_handle_count h[0]; + struct bt_hci_handle_count h[]; } __packed; #define BT_HCI_EVT_PIN_CODE_REQ 0x16 @@ -1510,11 +1510,11 @@ struct bt_hci_evt_le_advertising_info { uint8_t evt_type; bt_addr_le_t addr; uint8_t length; - uint8_t data[0]; + uint8_t data[]; } __packed; struct bt_hci_evt_le_advertising_report { uint8_t num_reports; - struct bt_hci_evt_le_advertising_info adv_info[0]; + struct bt_hci_evt_le_advertising_info adv_info[]; } __packed; #define BT_HCI_EVT_LE_CONN_UPDATE_COMPLETE 0x03 @@ -1593,7 +1593,7 @@ struct bt_hci_evt_le_direct_adv_info { } __packed; struct bt_hci_evt_le_direct_adv_report { uint8_t num_reports; - struct bt_hci_evt_le_direct_adv_info direct_adv_info[0]; + struct bt_hci_evt_le_direct_adv_info direct_adv_info[]; } __packed; #define BT_HCI_EVT_LE_PHY_UPDATE_COMPLETE 0x0c @@ -1628,11 +1628,11 @@ struct bt_hci_evt_le_ext_advertising_info { uint16_t interval; bt_addr_le_t direct_addr; uint8_t length; - uint8_t data[0]; + uint8_t data[]; } __packed; struct bt_hci_evt_le_ext_advertising_report { uint8_t num_reports; - struct bt_hci_evt_le_ext_advertising_info adv_info[0]; + struct bt_hci_evt_le_ext_advertising_info adv_info[]; } __packed; #define BT_HCI_EVT_LE_PER_ADV_SYNC_ESTABLISHED 0x0e @@ -1654,7 +1654,7 @@ struct bt_hci_evt_le_per_advertising_report { uint8_t unused; uint8_t data_status; uint8_t length; - uint8_t data[0]; + uint8_t data[]; } __packed; #define BT_HCI_EVT_LE_PER_ADV_SYNC_LOST 0x10 diff --git a/devices/ble_hci/common-hal/_bleio/hci_include/hci_vs.h b/devices/ble_hci/common-hal/_bleio/hci_include/hci_vs.h index e4f94b6a83..660691398e 100644 --- a/devices/ble_hci/common-hal/_bleio/hci_include/hci_vs.h +++ b/devices/ble_hci/common-hal/_bleio/hci_include/hci_vs.h @@ -104,7 +104,7 @@ struct bt_hci_cp_vs_set_trace_enable { #define BT_HCI_OP_VS_READ_BUILD_INFO BT_OP(BT_OGF_VS, 0x0008) struct bt_hci_rp_vs_read_build_info { uint8_t status; - uint8_t info[0]; + uint8_t info[]; } __packed; struct bt_hci_vs_static_addr { @@ -116,7 +116,7 @@ struct bt_hci_vs_static_addr { struct bt_hci_rp_vs_read_static_addrs { uint8_t status; uint8_t num_addrs; - struct bt_hci_vs_static_addr a[0]; + struct bt_hci_vs_static_addr a[]; } __packed; #define BT_HCI_OP_VS_READ_KEY_HIERARCHY_ROOTS BT_OP(BT_OGF_VS, 0x000a) @@ -143,7 +143,7 @@ struct bt_hci_vs_cmd { struct bt_hci_rp_vs_read_host_stack_cmds { uint8_t status; uint8_t num_cmds; - struct bt_hci_vs_cmd c[0]; + struct bt_hci_vs_cmd c[]; } __packed; #define BT_HCI_VS_SCAN_REQ_REPORTS_DISABLED 0x00 @@ -189,7 +189,7 @@ struct bt_hci_rp_vs_read_tx_power_level { struct bt_hci_rp_vs_read_usb_transport_mode { uint8_t status; uint8_t num_supported_modes; - uint8_t supported_mode[0]; + uint8_t supported_mode[]; } __packed; #define BT_HCI_VS_USB_H2_MODE 0x00 @@ -210,7 +210,7 @@ struct bt_hci_evt_vs { #define BT_HCI_EVT_VS_FATAL_ERROR 0x02 struct bt_hci_evt_vs_fatal_error { uint64_t pc; - uint8_t err_info[0]; + uint8_t err_info[]; } __packed; #define BT_HCI_VS_TRACE_LMP_TX 0x01 @@ -221,7 +221,7 @@ struct bt_hci_evt_vs_fatal_error { #define BT_HCI_EVT_VS_TRACE_INFO 0x03 struct bt_hci_evt_vs_trace_info { uint8_t type; - uint8_t data[0]; + uint8_t data[]; } __packed; #define BT_HCI_EVT_VS_SCAN_REQ_RX 0x04 @@ -267,14 +267,14 @@ struct bt_hci_rp_mesh_get_opts { #define BT_HCI_OC_MESH_SET_SCAN_FILTER 0x01 struct bt_hci_mesh_pattern { uint8_t pattern_len; - uint8_t pattern[0]; + uint8_t pattern[]; } __packed; struct bt_hci_cp_mesh_set_scan_filter { uint8_t scan_filter; uint8_t filter_dup; uint8_t num_patterns; - struct bt_hci_mesh_pattern patterns[0]; + struct bt_hci_mesh_pattern patterns[]; } __packed; struct bt_hci_rp_mesh_set_scan_filter { uint8_t status; @@ -365,11 +365,11 @@ struct bt_hci_evt_mesh_scan_report { int8_t rssi; uint32_t instant; uint8_t data_len; - uint8_t data[0]; + uint8_t data[]; } __packed; struct bt_hci_evt_mesh_scanning_report { uint8_t num_reports; - struct bt_hci_evt_mesh_scan_report reports[0]; + struct bt_hci_evt_mesh_scan_report reports[]; } __packed; #ifdef __cplusplus diff --git a/devices/ble_hci/common-hal/_bleio/hci_include/l2cap_internal.h b/devices/ble_hci/common-hal/_bleio/hci_include/l2cap_internal.h index bed311cf3c..a0a2ed056c 100644 --- a/devices/ble_hci/common-hal/_bleio/hci_include/l2cap_internal.h +++ b/devices/ble_hci/common-hal/_bleio/hci_include/l2cap_internal.h @@ -45,7 +45,7 @@ struct bt_l2cap_sig_hdr { #define BT_L2CAP_CMD_REJECT 0x01 struct bt_l2cap_cmd_reject { uint16_t reason; - uint8_t data[0]; + uint8_t data[]; } __packed; struct bt_l2cap_cmd_reject_cid_data { @@ -88,7 +88,7 @@ struct bt_l2cap_conn_rsp { struct bt_l2cap_conf_req { uint16_t dcid; uint16_t flags; - uint8_t data[0]; + uint8_t data[]; } __packed; #define BT_L2CAP_CONF_RSP 0x05 @@ -96,7 +96,7 @@ struct bt_l2cap_conf_rsp { uint16_t scid; uint16_t flags; uint16_t result; - uint8_t data[0]; + uint8_t data[]; } __packed; /* Option type used by MTU config request data */ @@ -108,7 +108,7 @@ struct bt_l2cap_conf_rsp { struct bt_l2cap_conf_opt { uint8_t type; uint8_t len; - uint8_t data[0]; + uint8_t data[]; } __packed; #define BT_L2CAP_DISCONN_REQ 0x06 @@ -139,7 +139,7 @@ struct bt_l2cap_info_req { struct bt_l2cap_info_rsp { uint16_t type; uint16_t result; - uint8_t data[0]; + uint8_t data[]; } __packed; #define BT_L2CAP_CONN_PARAM_REQ 0x12 @@ -201,7 +201,7 @@ struct bt_l2cap_ecred_conn_req { uint16_t mtu; uint16_t mps; uint16_t credits; - uint16_t scid[0]; + uint16_t scid[]; } __packed; #define BT_L2CAP_ECRED_CONN_RSP 0x18 @@ -210,14 +210,14 @@ struct bt_l2cap_ecred_conn_rsp { uint16_t mps; uint16_t credits; uint16_t result; - uint16_t dcid[0]; + uint16_t dcid[]; } __packed; #define BT_L2CAP_ECRED_RECONF_REQ 0x19 struct bt_l2cap_ecred_reconf_req { uint16_t mtu; uint16_t mps; - uint16_t scid[0]; + uint16_t scid[]; } __packed; #define BT_L2CAP_RECONF_SUCCESS 0x0000 diff --git a/ports/atmel-samd/boards/bast_pro_mini_m0/mpconfigboard.mk b/ports/atmel-samd/boards/bast_pro_mini_m0/mpconfigboard.mk index 055e6b19e2..69dee4b474 100644 --- a/ports/atmel-samd/boards/bast_pro_mini_m0/mpconfigboard.mk +++ b/ports/atmel-samd/boards/bast_pro_mini_m0/mpconfigboard.mk @@ -9,3 +9,5 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 + +#SUPEROPT_GC = 0 From 9f9ab44acc5dc118c1c68b61a73ecbef8f3a9320 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 15 Dec 2020 10:11:16 -0500 Subject: [PATCH 27/70] Avoid "error: flexible array member in a struct with no named members" --- .../ble_hci/common-hal/_bleio/hci_include/att_internal.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/devices/ble_hci/common-hal/_bleio/hci_include/att_internal.h b/devices/ble_hci/common-hal/_bleio/hci_include/att_internal.h index 678cb4201b..b8efccaf46 100644 --- a/devices/ble_hci/common-hal/_bleio/hci_include/att_internal.h +++ b/devices/ble_hci/common-hal/_bleio/hci_include/att_internal.h @@ -89,6 +89,7 @@ struct bt_att_handle_group { /* Find By Type Value Response */ #define BT_ATT_OP_FIND_TYPE_RSP 0x07 struct bt_att_find_type_rsp { + uint8_t _dummy[0]; struct bt_att_handle_group list[]; } __packed; @@ -121,6 +122,7 @@ struct bt_att_read_req { /* Read Response */ #define BT_ATT_OP_READ_RSP 0x0b struct bt_att_read_rsp { + uint8_t _dummy[0]; uint8_t value[]; } __packed; @@ -134,6 +136,7 @@ struct bt_att_read_blob_req { /* Read Blob Response */ #define BT_ATT_OP_READ_BLOB_RSP 0x0d struct bt_att_read_blob_rsp { + uint8_t _dummy[0]; uint8_t value[]; } __packed; @@ -142,12 +145,14 @@ struct bt_att_read_blob_rsp { #define BT_ATT_OP_READ_MULT_REQ 0x0e struct bt_att_read_mult_req { + uint8_t _dummy[0]; uint16_t handles[]; } __packed; /* Read Multiple Respose */ #define BT_ATT_OP_READ_MULT_RSP 0x0f struct bt_att_read_mult_rsp { + uint8_t _dummy[0]; uint8_t value[]; } __packed; @@ -233,6 +238,7 @@ struct bt_att_signature { #define BT_ATT_OP_READ_MULT_VL_REQ 0x20 struct bt_att_read_mult_vl_req { + uint8_t _dummy[0]; uint16_t handles[]; } __packed; From dc9bc8fc9a078184447292f67b0a5b17a8917117 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 15 Dec 2020 09:58:47 -0600 Subject: [PATCH 28/70] Fix flexible array declaration --- devices/ble_hci/common-hal/_bleio/att.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devices/ble_hci/common-hal/_bleio/att.c b/devices/ble_hci/common-hal/_bleio/att.c index 6528361cb1..8e9f5f017d 100644 --- a/devices/ble_hci/common-hal/_bleio/att.c +++ b/devices/ble_hci/common-hal/_bleio/att.c @@ -61,7 +61,7 @@ STATIC struct { typedef struct __packed { uint8_t properties; uint16_t value_handle; - uint8_t uuid[0]; // 2 or 16 bytes + uint8_t uuid[]; // 2 or 16 bytes } characteristic_declaration_t; STATIC uint8_t bleio_properties_to_ble_spec_properties(uint8_t bleio_properties) { From 3c4562c3caafa0590b63b32d680717363eb371bc Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 15 Dec 2020 10:39:56 -0600 Subject: [PATCH 29/70] camera: Provide correct forward-declaration of camera_imageformat_type This resolves the build error ``` arm-none-eabi-ld: build-spresense/libmpy.a(Camera.o):(.rodata.camera_imageformat_type+0x0): multiple definition of `camera_imageformat_type'; build-spresense/libmpy.a(__init__.o):(.rodata.camera_imageformat_type+0x0): first defined here arm-none-eabi-ld: build-spresense/libmpy.a(ImageFormat.o):(.rodata.camera_imageformat_type+0x0): multiple definition of `camera_imageformat_type'; build-spresense/libmpy.a(__init__.o):(.rodata.camera_imageformat_type+0x0): first defined here arm-none-eabi-ld: build-spresense/libmpy.a(Camera.o):(.rodata.camera_imageformat_type+0x0): multiple definition of `camera_imageformat_type'; build-spresense/libmpy.a(__init__.o):(.rodata.camera_imageformat_type+0x0): first defined here ``` --- shared-bindings/camera/ImageFormat.c | 1 - shared-bindings/camera/ImageFormat.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/shared-bindings/camera/ImageFormat.c b/shared-bindings/camera/ImageFormat.c index d4bdddc562..9f2f9617f6 100644 --- a/shared-bindings/camera/ImageFormat.c +++ b/shared-bindings/camera/ImageFormat.c @@ -38,7 +38,6 @@ //| RGB565: ImageFormat //| """RGB565 format.""" //| -const mp_obj_type_t camera_imageformat_type; const camera_imageformat_obj_t camera_imageformat_jpg_obj = { { &camera_imageformat_type }, diff --git a/shared-bindings/camera/ImageFormat.h b/shared-bindings/camera/ImageFormat.h index 8abc88438d..32a36354fc 100644 --- a/shared-bindings/camera/ImageFormat.h +++ b/shared-bindings/camera/ImageFormat.h @@ -35,7 +35,7 @@ typedef enum { IMAGEFORMAT_RGB565, } camera_imageformat_t; -const mp_obj_type_t camera_imageformat_type; +extern const mp_obj_type_t camera_imageformat_type; camera_imageformat_t camera_imageformat_obj_to_type(mp_obj_t obj); mp_obj_t camera_imageformat_type_to_obj(camera_imageformat_t mode); From bbbd621b184ee13740c0c8e4c94e7aed0db4f070 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 15 Dec 2020 10:54:37 -0600 Subject: [PATCH 30/70] nrf: simmel: remove some unneeded modules to make it fit --- ports/nrf/boards/simmel/mpconfigboard.mk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ports/nrf/boards/simmel/mpconfigboard.mk b/ports/nrf/boards/simmel/mpconfigboard.mk index e34739c0f3..b437fad9d2 100644 --- a/ports/nrf/boards/simmel/mpconfigboard.mk +++ b/ports/nrf/boards/simmel/mpconfigboard.mk @@ -16,12 +16,14 @@ CIRCUITPY_AUDIOMP3 = 0 CIRCUITPY_BUSIO = 1 CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_FRAMEBUFFERIO = 0 +CIRCUITPY_GAMEPAD = 0 CIRCUITPY_NEOPIXEL_WRITE = 0 CIRCUITPY_NVM = 0 CIRCUITPY_PIXELBUF = 0 CIRCUITPY_RGBMATRIX = 0 CIRCUITPY_ROTARYIO = 0 CIRCUITPY_RTC = 1 +CIRCUITPY_SDCARDIO = 0 CIRCUITPY_TOUCHIO = 0 CIRCUITPY_ULAB = 0 CIRCUITPY_WATCHDOG = 1 From fb33c4e1c0f83bce8f8cc1e8cae83695aeb2471d Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 15 Dec 2020 12:23:56 -0500 Subject: [PATCH 31/70] -ftree-vrp better diagnostics on -Os builds; -fno-inline-functions for -O2; fix struct init in HCI bleio --- devices/ble_hci/common-hal/_bleio/att.c | 46 +++++++++++++------------ ports/atmel-samd/Makefile | 9 +++-- ports/cxd56/Makefile | 2 +- ports/litex/Makefile | 2 +- ports/mimxrt10xx/Makefile | 4 +-- ports/nrf/Makefile | 2 +- ports/stm/Makefile | 5 ++- 7 files changed, 39 insertions(+), 31 deletions(-) diff --git a/devices/ble_hci/common-hal/_bleio/att.c b/devices/ble_hci/common-hal/_bleio/att.c index 8e9f5f017d..4573d5e9ff 100644 --- a/devices/ble_hci/common-hal/_bleio/att.c +++ b/devices/ble_hci/common-hal/_bleio/att.c @@ -1010,21 +1010,22 @@ void process_read_group_req(uint16_t conn_handle, uint16_t mtu, uint8_t dlen, ui } int att_read_group_req(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle, uint16_t uuid, uint8_t response_buffer[]) { - struct __packed { + + typedef struct __packed { struct bt_att_hdr h; struct bt_att_read_group_req r; - } req = { { - .code = BT_ATT_OP_READ_GROUP_REQ, - }, { - .start_handle = start_handle, - .end_handle = end_handle, - } - }; - req.r.uuid[0] = uuid & 0xff; - req.r.uuid[1] = uuid >> 8; + } req_t; + uint8_t req_bytes[sizeof(req_t) + sizeof(uuid)]; + req_t *req = (req_t *) req_bytes; - return send_req_wait_for_rsp(conn_handle, sizeof(req), (uint8_t *) &req, response_buffer); + req->h.code = BT_ATT_OP_READ_GROUP_REQ; + req->r.start_handle = start_handle; + req->r.end_handle = end_handle; + req->r.uuid[0] = uuid & 0xff; + req->r.uuid[1] = uuid >> 8; + + return send_req_wait_for_rsp(conn_handle, sizeof(req_bytes), req_bytes, response_buffer); } STATIC void process_read_group_rsp(uint16_t conn_handle, uint8_t dlen, uint8_t data[]) { @@ -1305,20 +1306,21 @@ STATIC void process_read_type_req(uint16_t conn_handle, uint16_t mtu, uint8_t dl } int att_read_type_req(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle, uint16_t type, uint8_t response_buffer[]) { - struct __packed { + typedef struct __packed { struct bt_att_hdr h; struct bt_att_read_type_req r; - } req = { { - .code = BT_ATT_OP_READ_TYPE_REQ, - }, { - .start_handle = start_handle, - .end_handle = end_handle, - } - }; - req.r.uuid[0] = type & 0xff; - req.r.uuid[1] = type >> 8; + } req_t; - return send_req_wait_for_rsp(conn_handle, sizeof(req), (uint8_t *) &req, response_buffer); + uint8_t req_bytes[sizeof(req_t) + sizeof(type)]; + req_t *req = (req_t *) req_bytes; + + req->h.code = BT_ATT_OP_READ_TYPE_REQ; + req->r.start_handle = start_handle; + req->r.end_handle = end_handle; + req->r.uuid[0] = type & 0xff; + req->r.uuid[1] = type >> 8; + + return send_req_wait_for_rsp(conn_handle, sizeof(req_bytes), req_bytes, response_buffer); } STATIC void process_read_type_rsp(uint16_t conn_handle, uint8_t dlen, uint8_t data[]) { diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile index c214d56f0c..58c1c0d60e 100644 --- a/ports/atmel-samd/Makefile +++ b/ports/atmel-samd/Makefile @@ -94,21 +94,21 @@ endif ifeq ($(CHIP_FAMILY), samd51) PERIPHERALS_CHIP_FAMILY=sam_d5x_e5x -OPTIMIZATION_FLAGS ?= -Os +OPTIMIZATION_FLAGS ?= -O2 -fno-inline-functions # TinyUSB defines CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_SAMD51 -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_CDC_RX_BUFSIZE=256 -DCFG_TUD_MIDI_TX_BUFSIZE=128 -DCFG_TUD_CDC_TX_BUFSIZE=256 -DCFG_TUD_MSC_BUFSIZE=1024 endif ifeq ($(CHIP_FAMILY), same51) PERIPHERALS_CHIP_FAMILY=sam_d5x_e5x -OPTIMIZATION_FLAGS ?= -Os +OPTIMIZATION_FLAGS ?= -O2 -fno-inline-functions # TinyUSB defines CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_SAME5X -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_CDC_RX_BUFSIZE=256 -DCFG_TUD_MIDI_TX_BUFSIZE=128 -DCFG_TUD_CDC_TX_BUFSIZE=256 -DCFG_TUD_MSC_BUFSIZE=1024 endif ifeq ($(CHIP_FAMILY), same54) PERIPHERALS_CHIP_FAMILY=sam_d5x_e5x -OPTIMIZATION_FLAGS ?= -Os +OPTIMIZATION_FLAGS ?= -O2 -fno-inline-functions # TinyUSB defines CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_SAME5X -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_CDC_RX_BUFSIZE=256 -DCFG_TUD_MIDI_TX_BUFSIZE=128 -DCFG_TUD_CDC_TX_BUFSIZE=256 -DCFG_TUD_MSC_BUFSIZE=1024 endif @@ -116,6 +116,9 @@ endif # option to override default optimization level, set in boards/$(BOARD)/mpconfigboard.mk CFLAGS += $(OPTIMIZATION_FLAGS) +# Add -ftree-vrp optimization and checking to all builds. It's not enabled for -Os by default. +CFLAGS += -ftree-vrp + $(echo PERIPHERALS_CHIP_FAMILY=$(PERIPHERALS_CHIP_FAMILY)) #Debugging/Optimization ifeq ($(DEBUG), 1) diff --git a/ports/cxd56/Makefile b/ports/cxd56/Makefile index 5201f0db56..1c48a23ca5 100644 --- a/ports/cxd56/Makefile +++ b/ports/cxd56/Makefile @@ -122,7 +122,7 @@ CFLAGS += \ -fdata-sections \ -Wall \ -OPTIMIZATION_FLAGS ?= -O2 +OPTIMIZATION_FLAGS ?= -O2 -fno-inline-functions # option to override compiler optimization level, set in boards/$(BOARD)/mpconfigboard.mk CFLAGS += $(OPTIMIZATION_FLAGS) diff --git a/ports/litex/Makefile b/ports/litex/Makefile index 612953daaf..f384f24577 100644 --- a/ports/litex/Makefile +++ b/ports/litex/Makefile @@ -80,7 +80,7 @@ ifeq ($(DEBUG), 1) OPTIMIZATION_FLAGS ?= -Og else CFLAGS += -DNDEBUG -ggdb3 - OPTIMIZATION_FLAGS ?= -O2 + OPTIMIZATION_FLAGS ?= -O2 -fno-inline-functions # TODO: Test with -flto ### CFLAGS += -flto endif diff --git a/ports/mimxrt10xx/Makefile b/ports/mimxrt10xx/Makefile index a17e5f7030..04949bf01c 100644 --- a/ports/mimxrt10xx/Makefile +++ b/ports/mimxrt10xx/Makefile @@ -75,7 +75,7 @@ INC += \ # NDEBUG disables assert() statements. This reduces code size pretty dramatically, per tannewt. -CFLAGS += -Os -DNDEBUG -ffreestanding +CFLAGS += -Os -ftree-vrp -DNDEBUG -ffreestanding # TinyUSB defines CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_MIMXRT10XX -DCFG_TUD_MIDI_RX_BUFSIZE=512 -DCFG_TUD_CDC_RX_BUFSIZE=512 -DCFG_TUD_MIDI_TX_BUFSIZE=512 -DCFG_TUD_CDC_TX_BUFSIZE=512 -DCFG_TUD_MSC_BUFSIZE=1024 @@ -108,7 +108,7 @@ CFLAGS += \ -g3 -Wno-unused-parameter \ -ffunction-sections -fdata-sections -fstack-usage -OPTIMIZATION_FLAGS ?= -O2 +OPTIMIZATION_FLAGS ?= -O2 -fno-inline-functions # option to override compiler optimization level, set in boards/$(BOARD)/mpconfigboard.mk CFLAGS += $(OPTIMIZATION_FLAGS) diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index 3fef68e88e..278625e92d 100755 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -89,7 +89,7 @@ ifeq ($(DEBUG), 1) CFLAGS += -ggdb3 OPTIMIZATION_FLAGS = -Og else - OPTIMIZATION_FLAGS ?= -O2 + OPTIMIZATION_FLAGS ?= -O2 -fno-inline-functions CFLAGS += -DNDEBUG -ggdb3 CFLAGS += -flto -flto-partition=none endif diff --git a/ports/stm/Makefile b/ports/stm/Makefile index b9426e07ec..e09fe736cc 100755 --- a/ports/stm/Makefile +++ b/ports/stm/Makefile @@ -86,7 +86,7 @@ ifeq ($(DEBUG), 1) CFLAGS += -fno-inline -fno-ipa-sra else CFLAGS += -DNDEBUG - OPTIMIZATION_FLAGS ?= -O2 + OPTIMIZATION_FLAGS ?= -O2 -fno-inline-functions CFLAGS += -ggdb3 # TODO: Test with -flto # CFLAGS += -flto @@ -95,6 +95,9 @@ endif # to override compiler optimization level, set in boards/$(BOARD)/mpconfigboard.mk CFLAGS += $(OPTIMIZATION_FLAGS) +# Add -ftree-vrp optimization and checking to all builds. It's not enabled for -Os by default. +CFLAGS += -ftree-vrp + # MCU Series is defined by the HAL package and doesn't need to be specified here C_DEFS = -D$(MCU_PACKAGE) -DUSE_HAL_DRIVER -DUSE_FULL_LL_DRIVER -D$(MCU_VARIANT) From 4521dfb73289eaa9d17cb61b29b49c10adf1f4a3 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 15 Dec 2020 13:23:49 -0500 Subject: [PATCH 32/70] squeeze some smaller boards --- ports/atmel-samd/boards/bast_pro_mini_m0/mpconfigboard.mk | 2 +- ports/atmel-samd/boards/sparkfun_lumidrive/mpconfigboard.mk | 2 ++ ports/stm/boards/espruino_pico/mpconfigboard.mk | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ports/atmel-samd/boards/bast_pro_mini_m0/mpconfigboard.mk b/ports/atmel-samd/boards/bast_pro_mini_m0/mpconfigboard.mk index 69dee4b474..6a2c896197 100644 --- a/ports/atmel-samd/boards/bast_pro_mini_m0/mpconfigboard.mk +++ b/ports/atmel-samd/boards/bast_pro_mini_m0/mpconfigboard.mk @@ -10,4 +10,4 @@ INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 -#SUPEROPT_GC = 0 +SUPEROPT_GC = 0 diff --git a/ports/atmel-samd/boards/sparkfun_lumidrive/mpconfigboard.mk b/ports/atmel-samd/boards/sparkfun_lumidrive/mpconfigboard.mk index 3f75d175c8..e71bb07395 100755 --- a/ports/atmel-samd/boards/sparkfun_lumidrive/mpconfigboard.mk +++ b/ports/atmel-samd/boards/sparkfun_lumidrive/mpconfigboard.mk @@ -16,3 +16,5 @@ CIRCUITPY_AUDIOBUSIO = 0 CIRCUITPY_VECTORIO = 0 FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_DotStar + +SUPEROPT_GC = 0 diff --git a/ports/stm/boards/espruino_pico/mpconfigboard.mk b/ports/stm/boards/espruino_pico/mpconfigboard.mk index 556ff35c45..14f9323fde 100644 --- a/ports/stm/boards/espruino_pico/mpconfigboard.mk +++ b/ports/stm/boards/espruino_pico/mpconfigboard.mk @@ -20,3 +20,5 @@ LD_FILE = boards/STM32F401xd_fs.ld # lto for this port, and if other stuff hasn't been added in the # meantime CIRCUITPY_ULAB = 0 + +SUPEROPT_GC = 0 From ca757f2ead6e84ad52b6030281b666792fb12b43 Mon Sep 17 00:00:00 2001 From: Seth Kerr Date: Wed, 16 Dec 2020 10:25:20 -0500 Subject: [PATCH 33/70] removed comments on 64MiB SPI flash causing build test issues --- .gitattributes 2 | 32 + .gitignore 2 | 88 +++ .gitmodules 2 | 155 +++++ .mailmap 2 | 112 ++++ mpy-cross/.gitignore 2 | 11 + ports/atmel-samd/.gitattributes 2 | 2 + ports/atmel-samd/.gitignore 2 | 1 + ports/atmel-samd/boards/board.h | 47 ++ supervisor/shared/external_flash/devices.h | 50 +- tests/README 2 | 18 + tests/extmod 2/btree1.py | 89 +++ tests/extmod 2/framebuf1.py | 109 ++++ tests/extmod 2/framebuf16.py | 59 ++ tests/extmod 2/framebuf2.py.exp | 57 ++ tests/extmod 2/framebuf4.py | 53 ++ tests/extmod 2/framebuf_subclass.py | 20 + tests/extmod 2/machine1.py | 28 + tests/extmod 2/machine_pinbase.py | 30 + tests/extmod 2/machine_pinbase.py.exp | 9 + tests/extmod 2/ticks_diff.py | 33 + tests/extmod 2/time_ms_us.py | 22 + tests/extmod 2/time_ms_us.py.exp | 3 + tests/extmod 2/ubinascii_a2b_base64.py | 49 ++ tests/extmod 2/ubinascii_hexlify.py | 17 + tests/extmod 2/uctypes_32bit_intbig.py.exp | 11 + .../uctypes_array_assign_native_le.py | 89 +++ .../uctypes_array_assign_native_le.py.exp | 11 + .../uctypes_array_assign_native_le_intbig.py | 43 ++ tests/extmod 2/uctypes_bytearray.py | 22 + tests/extmod 2/uctypes_byteat.py | 10 + tests/extmod 2/uctypes_byteat.py.exp | 2 + tests/extmod 2/uctypes_error.py | 37 ++ tests/extmod 2/uctypes_error.py.exp | 4 + tests/extmod 2/uctypes_le_float.py | 24 + tests/extmod 2/uctypes_native_float.py | 20 + tests/extmod 2/uctypes_ptr_le.py | 34 + tests/extmod 2/uctypes_ptr_native_le.py.exp | 6 + tests/extmod 2/uctypes_sizeof.py.exp | 7 + tests/extmod 2/uhashlib_sha1.py | 28 + tests/extmod 2/ujson_dump.py | 30 + tests/extmod 2/ujson_dumps_extra.py | 9 + tests/extmod 2/ujson_dumps_float.py | 10 + tests/extmod 2/ujson_load_readinto.py.exp | 4 + tests/extmod 2/ujson_loads.py | 74 +++ tests/extmod 2/ujson_loads_float.py | 17 + tests/extmod 2/urandom_basic.py | 29 + tests/extmod 2/ure1.py | 103 +++ tests/extmod 2/ure_debug.py.exp | 15 + tests/extmod 2/ure_error.py | 25 + tests/extmod 2/ure_namedclass.py | 32 + tests/extmod 2/ure_stack_overflow.py.exp | 1 + tests/extmod 2/ure_sub_unmatched.py.exp | 1 + tests/extmod 2/ussl_basic.py | 59 ++ tests/extmod 2/utimeq1.py | 137 ++++ tests/extmod 2/utimeq_stable.py.exp | 1 + tests/extmod 2/uzlib_decompio.py | 33 + tests/extmod 2/uzlib_decompio_gz.py.exp | 13 + tests/extmod 2/vfs_fat_fileio1.py | 139 ++++ tests/extmod 2/vfs_fat_fileio1.py.exp | 18 + tests/extmod 2/vfs_fat_more.py.exp | 29 + tests/extmod 2/vfs_fat_oldproto.py.exp | 3 + tests/extmod 2/vfs_fat_ramdisk.py.exp | 17 + tests/extmod 2/websocket_basic.py.exp | 14 + tests/feature_check 2/README | 4 + tests/feature_check 2/async_check.py | 3 + tests/feature_check 2/async_check.py.exp | 0 tests/feature_check 2/byteorder.py | 2 + tests/feature_check 2/byteorder.py.exp | 0 tests/feature_check 2/complex.py | 5 + tests/feature_check 2/complex.py.exp | 0 tests/feature_check 2/const.py | 1 + tests/feature_check 2/const.py.exp | 0 tests/feature_check 2/coverage.py | 5 + tests/feature_check 2/coverage.py.exp | 0 tests/feature_check 2/float.py | 13 + tests/feature_check 2/float.py.exp | 1 + tests/feature_check 2/int_big.py | 2 + tests/feature_check 2/int_big.py.exp | 1 + tests/feature_check 2/native_check.py | 4 + tests/feature_check 2/native_check.py.exp | 0 tests/feature_check 2/repl_emacs_check.py | 3 + tests/feature_check 2/repl_emacs_check.py.exp | 7 + tests/feature_check 2/reverse_ops.py | 9 + tests/feature_check 2/reverse_ops.py.exp | 0 tests/feature_check 2/set_check.py | 2 + tests/feature_check 2/set_check.py.exp | 0 tests/float 2/array_construct.py | 10 + tests/float 2/builtin_float_hash.py | 25 + tests/float 2/builtin_float_minmax.py | 31 + tests/float 2/builtin_float_pow.py | 11 + tests/float 2/builtin_float_round.py | 24 + tests/float 2/builtin_float_round_intbig.py | 4 + tests/float 2/bytearray_construct.py | 9 + tests/float 2/bytes_construct.py | 9 + tests/float 2/cmath_fun.py | 55 ++ tests/float 2/cmath_fun_special.py | 31 + tests/float 2/complex1.py | 116 ++++ tests/float 2/complex1_intbig.py | 4 + tests/float 2/float1.py | 119 ++++ tests/float 2/float2int_doubleprec_intbig.py | 100 +++ tests/float 2/float2int_fp30_intbig.py | 97 +++ tests/float 2/float2int_intbig.py | 99 +++ tests/float 2/float_array.py | 20 + tests/float 2/float_compare.py | 22 + tests/float 2/float_divmod.py | 25 + tests/float 2/float_divmod_relaxed.py | 33 + tests/float 2/float_format.py | 19 + tests/float 2/float_parse.py | 32 + tests/float 2/float_parse_doubleprec.py | 21 + tests/float 2/float_struct.py | 17 + tests/float 2/int_big_float.py | 28 + tests/float 2/int_divzero.py | 9 + tests/float 2/int_power.py | 8 + tests/float 2/list_index.py | 8 + tests/float 2/math_domain.py | 51 ++ tests/float 2/math_domain_special.py | 36 + tests/float 2/math_fun.py | 63 ++ tests/float 2/math_fun_bool.py | 16 + tests/float 2/math_fun_int.py | 14 + tests/float 2/math_fun_intbig.py | 11 + tests/float 2/math_fun_special.py | 35 + tests/float 2/python36.py | 10 + tests/float 2/python36.py.exp | 5 + tests/float 2/string_format.py | 41 ++ tests/float 2/string_format2.py | 106 +++ tests/float 2/string_format_fp30.py | 41 ++ tests/float 2/string_format_modulo.py | 49 ++ tests/float 2/string_format_modulo2.py | 24 + tests/float 2/string_format_modulo2_intbig.py | 21 + tests/float 2/string_format_modulo3.py | 3 + tests/float 2/string_format_modulo3.py.exp | 2 + tests/float 2/true_value.py | 7 + tests/float 2/types.py | 17 + tests/inlineasm 2/asmargs.py | 29 + tests/inlineasm 2/asmargs.py.exp | 5 + tests/inlineasm 2/asmbcc.py | 27 + tests/inlineasm 2/asmbcc.py.exp | 4 + tests/inlineasm 2/asmbitops.py | 13 + tests/inlineasm 2/asmbitops.py.exp | 4 + tests/inlineasm 2/asmblbx.py | 21 + tests/inlineasm 2/asmblbx.py.exp | 2 + tests/inlineasm 2/asmconst.py | 8 + tests/inlineasm 2/asmconst.py.exp | 1 + tests/inlineasm 2/asmdiv.py | 16 + tests/inlineasm 2/asmdiv.py.exp | 7 + tests/inlineasm 2/asmfpaddsub.py | 14 + tests/inlineasm 2/asmfpaddsub.py.exp | 1 + tests/inlineasm 2/asmfpcmp.py | 14 + tests/inlineasm 2/asmfpcmp.py.exp | 3 + tests/inlineasm 2/asmfpldrstr.py | 11 + tests/inlineasm 2/asmfpldrstr.py.exp | 1 + tests/inlineasm 2/asmfpmuldiv.py | 14 + tests/inlineasm 2/asmfpmuldiv.py.exp | 1 + tests/inlineasm 2/asmfpsqrt.py | 14 + tests/inlineasm 2/asmfpsqrt.py.exp | 1 + tests/inlineasm 2/asmit.py | 16 + tests/inlineasm 2/asmit.py.exp | 2 + tests/inlineasm 2/asmpushpop.py | 8 + tests/inlineasm 2/asmpushpop.py.exp | 1 + tests/inlineasm 2/asmrettype.py | 21 + tests/inlineasm 2/asmrettype.py.exp | 4 + tests/inlineasm 2/asmshift.py | 29 + tests/inlineasm 2/asmshift.py.exp | 6 + tests/inlineasm 2/asmspecialregs.py | 10 + tests/inlineasm 2/asmspecialregs.py.exp | 2 + tests/inlineasm 2/asmsum.py | 57 ++ tests/inlineasm 2/asmsum.py.exp | 2 + tests/io/data/file1 2 | 3 + tests/jni 2/README | 11 + tests/jni 2/list.py | 15 + tests/jni 2/list.py.exp | 4 + tests/jni 2/object.py | 15 + tests/jni 2/object.py.exp | 3 + tests/jni 2/system_out.py | 8 + tests/jni 2/system_out.py.exp | 1 + tests/net_hosted 2/README | 11 + tests/net_hosted 2/accept_nonblock.py | 16 + tests/net_hosted 2/accept_nonblock.py.exp | 1 + tests/net_hosted 2/accept_timeout.py | 22 + tests/net_hosted 2/accept_timeout.py.exp | 1 + tests/net_hosted 2/connect_nonblock.py | 20 + tests/net_hosted 2/connect_nonblock.py.exp | 1 + tests/net_hosted 2/connect_poll.py | 32 + tests/net_hosted 2/connect_poll.py.exp | 3 + tests/net_hosted 2/ssl_getpeercert.py | 21 + tests/net_hosted 2/ssl_getpeercert.py.exp | 1 + tests/net_inet 2/README | 5 + tests/net_inet 2/test_tls_sites.py | 59 ++ tests/net_inet 2/test_tls_sites.py.exp | 5 + tests/run-bench-tests 2 | 97 +++ tests/run-tests 2 | 615 ++++++++++++++++++ tests/stress 2/dict_copy.py | 7 + tests/stress 2/dict_create.py | 8 + tests/stress 2/dict_create_max.py | 13 + tests/stress 2/gc_trace.py | 17 + tests/stress 2/list_sort.py | 6 + tests/stress 2/recursion.py | 7 + tests/stress 2/recursive_data.py | 13 + tests/stress 2/recursive_data.py.exp | 1 + tests/stress 2/recursive_gen.py | 18 + tests/stress 2/recursive_iternext.py | 57 ++ tests/stress 2/recursive_iternext.py.exp | 4 + tests/thread 2/mutate_bytearray.py | 46 ++ tests/thread 2/mutate_dict.py | 44 ++ tests/thread 2/mutate_instance.py | 45 ++ tests/thread 2/mutate_list.py | 46 ++ tests/thread 2/mutate_set.py | 39 ++ tests/thread 2/stress_aes.py | 257 ++++++++ tests/thread 2/stress_create.py | 22 + tests/thread 2/stress_heap.py | 48 ++ tests/thread 2/stress_recurse.py | 27 + tests/thread 2/thread_exc1.py | 32 + tests/thread 2/thread_exc2.py | 10 + tests/thread 2/thread_exc2.py.exp | 5 + tests/thread 2/thread_exit1.py | 21 + tests/thread 2/thread_exit2.py | 21 + tests/thread 2/thread_gc1.py | 36 + tests/thread 2/thread_ident1.py | 23 + tests/thread 2/thread_lock1.py | 48 ++ tests/thread 2/thread_lock2.py | 26 + tests/thread 2/thread_lock3.py | 29 + tests/thread 2/thread_lock4.py | 53 ++ tests/thread 2/thread_qstr1.py | 41 ++ tests/thread 2/thread_shared1.py | 33 + tests/thread 2/thread_shared2.py | 34 + tests/thread 2/thread_sleep1.py | 33 + tests/thread 2/thread_stacksize1.py | 49 ++ tests/thread 2/thread_start1.py | 25 + tests/thread 2/thread_start2.py | 28 + tests/unix 2/extra_coverage.py | 74 +++ tests/unix 2/extra_coverage.py.exp | 106 +++ tests/unix 2/ffi_callback.py | 33 + tests/unix 2/ffi_callback.py.exp | 2 + tests/unix 2/ffi_float.py | 32 + tests/unix 2/ffi_float.py.exp | 8 + tests/unix 2/ffi_float2.py | 31 + tests/unix 2/ffi_float2.py.exp | 6 + tools/.gitattributes 2 | 1 + tools/.gitignore 2 | 8 + 239 files changed, 6751 insertions(+), 16 deletions(-) create mode 100644 .gitattributes 2 create mode 100644 .gitignore 2 create mode 100644 .gitmodules 2 create mode 100644 .mailmap 2 create mode 100644 mpy-cross/.gitignore 2 create mode 100644 ports/atmel-samd/.gitattributes 2 create mode 100644 ports/atmel-samd/.gitignore 2 create mode 100644 ports/atmel-samd/boards/board.h create mode 100644 tests/README 2 create mode 100644 tests/extmod 2/btree1.py create mode 100644 tests/extmod 2/framebuf1.py create mode 100644 tests/extmod 2/framebuf16.py create mode 100644 tests/extmod 2/framebuf2.py.exp create mode 100644 tests/extmod 2/framebuf4.py create mode 100644 tests/extmod 2/framebuf_subclass.py create mode 100644 tests/extmod 2/machine1.py create mode 100644 tests/extmod 2/machine_pinbase.py create mode 100644 tests/extmod 2/machine_pinbase.py.exp create mode 100644 tests/extmod 2/ticks_diff.py create mode 100644 tests/extmod 2/time_ms_us.py create mode 100644 tests/extmod 2/time_ms_us.py.exp create mode 100644 tests/extmod 2/ubinascii_a2b_base64.py create mode 100644 tests/extmod 2/ubinascii_hexlify.py create mode 100644 tests/extmod 2/uctypes_32bit_intbig.py.exp create mode 100644 tests/extmod 2/uctypes_array_assign_native_le.py create mode 100644 tests/extmod 2/uctypes_array_assign_native_le.py.exp create mode 100644 tests/extmod 2/uctypes_array_assign_native_le_intbig.py create mode 100644 tests/extmod 2/uctypes_bytearray.py create mode 100644 tests/extmod 2/uctypes_byteat.py create mode 100644 tests/extmod 2/uctypes_byteat.py.exp create mode 100644 tests/extmod 2/uctypes_error.py create mode 100644 tests/extmod 2/uctypes_error.py.exp create mode 100644 tests/extmod 2/uctypes_le_float.py create mode 100644 tests/extmod 2/uctypes_native_float.py create mode 100644 tests/extmod 2/uctypes_ptr_le.py create mode 100644 tests/extmod 2/uctypes_ptr_native_le.py.exp create mode 100644 tests/extmod 2/uctypes_sizeof.py.exp create mode 100644 tests/extmod 2/uhashlib_sha1.py create mode 100644 tests/extmod 2/ujson_dump.py create mode 100644 tests/extmod 2/ujson_dumps_extra.py create mode 100644 tests/extmod 2/ujson_dumps_float.py create mode 100644 tests/extmod 2/ujson_load_readinto.py.exp create mode 100644 tests/extmod 2/ujson_loads.py create mode 100644 tests/extmod 2/ujson_loads_float.py create mode 100644 tests/extmod 2/urandom_basic.py create mode 100644 tests/extmod 2/ure1.py create mode 100644 tests/extmod 2/ure_debug.py.exp create mode 100644 tests/extmod 2/ure_error.py create mode 100644 tests/extmod 2/ure_namedclass.py create mode 100644 tests/extmod 2/ure_stack_overflow.py.exp create mode 100644 tests/extmod 2/ure_sub_unmatched.py.exp create mode 100644 tests/extmod 2/ussl_basic.py create mode 100644 tests/extmod 2/utimeq1.py create mode 100644 tests/extmod 2/utimeq_stable.py.exp create mode 100644 tests/extmod 2/uzlib_decompio.py create mode 100644 tests/extmod 2/uzlib_decompio_gz.py.exp create mode 100644 tests/extmod 2/vfs_fat_fileio1.py create mode 100644 tests/extmod 2/vfs_fat_fileio1.py.exp create mode 100644 tests/extmod 2/vfs_fat_more.py.exp create mode 100644 tests/extmod 2/vfs_fat_oldproto.py.exp create mode 100644 tests/extmod 2/vfs_fat_ramdisk.py.exp create mode 100644 tests/extmod 2/websocket_basic.py.exp create mode 100644 tests/feature_check 2/README create mode 100644 tests/feature_check 2/async_check.py create mode 100644 tests/feature_check 2/async_check.py.exp create mode 100644 tests/feature_check 2/byteorder.py create mode 100644 tests/feature_check 2/byteorder.py.exp create mode 100644 tests/feature_check 2/complex.py create mode 100644 tests/feature_check 2/complex.py.exp create mode 100644 tests/feature_check 2/const.py create mode 100644 tests/feature_check 2/const.py.exp create mode 100644 tests/feature_check 2/coverage.py create mode 100644 tests/feature_check 2/coverage.py.exp create mode 100644 tests/feature_check 2/float.py create mode 100644 tests/feature_check 2/float.py.exp create mode 100644 tests/feature_check 2/int_big.py create mode 100644 tests/feature_check 2/int_big.py.exp create mode 100644 tests/feature_check 2/native_check.py create mode 100644 tests/feature_check 2/native_check.py.exp create mode 100644 tests/feature_check 2/repl_emacs_check.py create mode 100644 tests/feature_check 2/repl_emacs_check.py.exp create mode 100644 tests/feature_check 2/reverse_ops.py create mode 100644 tests/feature_check 2/reverse_ops.py.exp create mode 100644 tests/feature_check 2/set_check.py create mode 100644 tests/feature_check 2/set_check.py.exp create mode 100644 tests/float 2/array_construct.py create mode 100644 tests/float 2/builtin_float_hash.py create mode 100644 tests/float 2/builtin_float_minmax.py create mode 100644 tests/float 2/builtin_float_pow.py create mode 100644 tests/float 2/builtin_float_round.py create mode 100644 tests/float 2/builtin_float_round_intbig.py create mode 100644 tests/float 2/bytearray_construct.py create mode 100644 tests/float 2/bytes_construct.py create mode 100644 tests/float 2/cmath_fun.py create mode 100644 tests/float 2/cmath_fun_special.py create mode 100644 tests/float 2/complex1.py create mode 100644 tests/float 2/complex1_intbig.py create mode 100644 tests/float 2/float1.py create mode 100644 tests/float 2/float2int_doubleprec_intbig.py create mode 100644 tests/float 2/float2int_fp30_intbig.py create mode 100644 tests/float 2/float2int_intbig.py create mode 100644 tests/float 2/float_array.py create mode 100644 tests/float 2/float_compare.py create mode 100644 tests/float 2/float_divmod.py create mode 100644 tests/float 2/float_divmod_relaxed.py create mode 100644 tests/float 2/float_format.py create mode 100644 tests/float 2/float_parse.py create mode 100644 tests/float 2/float_parse_doubleprec.py create mode 100644 tests/float 2/float_struct.py create mode 100644 tests/float 2/int_big_float.py create mode 100644 tests/float 2/int_divzero.py create mode 100644 tests/float 2/int_power.py create mode 100644 tests/float 2/list_index.py create mode 100644 tests/float 2/math_domain.py create mode 100644 tests/float 2/math_domain_special.py create mode 100644 tests/float 2/math_fun.py create mode 100644 tests/float 2/math_fun_bool.py create mode 100644 tests/float 2/math_fun_int.py create mode 100644 tests/float 2/math_fun_intbig.py create mode 100644 tests/float 2/math_fun_special.py create mode 100644 tests/float 2/python36.py create mode 100644 tests/float 2/python36.py.exp create mode 100644 tests/float 2/string_format.py create mode 100644 tests/float 2/string_format2.py create mode 100644 tests/float 2/string_format_fp30.py create mode 100644 tests/float 2/string_format_modulo.py create mode 100644 tests/float 2/string_format_modulo2.py create mode 100644 tests/float 2/string_format_modulo2_intbig.py create mode 100644 tests/float 2/string_format_modulo3.py create mode 100644 tests/float 2/string_format_modulo3.py.exp create mode 100644 tests/float 2/true_value.py create mode 100644 tests/float 2/types.py create mode 100644 tests/inlineasm 2/asmargs.py create mode 100644 tests/inlineasm 2/asmargs.py.exp create mode 100644 tests/inlineasm 2/asmbcc.py create mode 100644 tests/inlineasm 2/asmbcc.py.exp create mode 100644 tests/inlineasm 2/asmbitops.py create mode 100644 tests/inlineasm 2/asmbitops.py.exp create mode 100644 tests/inlineasm 2/asmblbx.py create mode 100644 tests/inlineasm 2/asmblbx.py.exp create mode 100644 tests/inlineasm 2/asmconst.py create mode 100644 tests/inlineasm 2/asmconst.py.exp create mode 100644 tests/inlineasm 2/asmdiv.py create mode 100644 tests/inlineasm 2/asmdiv.py.exp create mode 100644 tests/inlineasm 2/asmfpaddsub.py create mode 100644 tests/inlineasm 2/asmfpaddsub.py.exp create mode 100644 tests/inlineasm 2/asmfpcmp.py create mode 100644 tests/inlineasm 2/asmfpcmp.py.exp create mode 100644 tests/inlineasm 2/asmfpldrstr.py create mode 100644 tests/inlineasm 2/asmfpldrstr.py.exp create mode 100644 tests/inlineasm 2/asmfpmuldiv.py create mode 100644 tests/inlineasm 2/asmfpmuldiv.py.exp create mode 100644 tests/inlineasm 2/asmfpsqrt.py create mode 100644 tests/inlineasm 2/asmfpsqrt.py.exp create mode 100644 tests/inlineasm 2/asmit.py create mode 100644 tests/inlineasm 2/asmit.py.exp create mode 100644 tests/inlineasm 2/asmpushpop.py create mode 100644 tests/inlineasm 2/asmpushpop.py.exp create mode 100644 tests/inlineasm 2/asmrettype.py create mode 100644 tests/inlineasm 2/asmrettype.py.exp create mode 100644 tests/inlineasm 2/asmshift.py create mode 100644 tests/inlineasm 2/asmshift.py.exp create mode 100644 tests/inlineasm 2/asmspecialregs.py create mode 100644 tests/inlineasm 2/asmspecialregs.py.exp create mode 100644 tests/inlineasm 2/asmsum.py create mode 100644 tests/inlineasm 2/asmsum.py.exp create mode 100644 tests/io/data/file1 2 create mode 100644 tests/jni 2/README create mode 100644 tests/jni 2/list.py create mode 100644 tests/jni 2/list.py.exp create mode 100644 tests/jni 2/object.py create mode 100644 tests/jni 2/object.py.exp create mode 100644 tests/jni 2/system_out.py create mode 100644 tests/jni 2/system_out.py.exp create mode 100644 tests/net_hosted 2/README create mode 100644 tests/net_hosted 2/accept_nonblock.py create mode 100644 tests/net_hosted 2/accept_nonblock.py.exp create mode 100644 tests/net_hosted 2/accept_timeout.py create mode 100644 tests/net_hosted 2/accept_timeout.py.exp create mode 100644 tests/net_hosted 2/connect_nonblock.py create mode 100644 tests/net_hosted 2/connect_nonblock.py.exp create mode 100644 tests/net_hosted 2/connect_poll.py create mode 100644 tests/net_hosted 2/connect_poll.py.exp create mode 100644 tests/net_hosted 2/ssl_getpeercert.py create mode 100644 tests/net_hosted 2/ssl_getpeercert.py.exp create mode 100644 tests/net_inet 2/README create mode 100644 tests/net_inet 2/test_tls_sites.py create mode 100644 tests/net_inet 2/test_tls_sites.py.exp create mode 100755 tests/run-bench-tests 2 create mode 100755 tests/run-tests 2 create mode 100644 tests/stress 2/dict_copy.py create mode 100644 tests/stress 2/dict_create.py create mode 100644 tests/stress 2/dict_create_max.py create mode 100644 tests/stress 2/gc_trace.py create mode 100644 tests/stress 2/list_sort.py create mode 100644 tests/stress 2/recursion.py create mode 100644 tests/stress 2/recursive_data.py create mode 100644 tests/stress 2/recursive_data.py.exp create mode 100644 tests/stress 2/recursive_gen.py create mode 100644 tests/stress 2/recursive_iternext.py create mode 100644 tests/stress 2/recursive_iternext.py.exp create mode 100644 tests/thread 2/mutate_bytearray.py create mode 100644 tests/thread 2/mutate_dict.py create mode 100644 tests/thread 2/mutate_instance.py create mode 100644 tests/thread 2/mutate_list.py create mode 100644 tests/thread 2/mutate_set.py create mode 100644 tests/thread 2/stress_aes.py create mode 100644 tests/thread 2/stress_create.py create mode 100644 tests/thread 2/stress_heap.py create mode 100644 tests/thread 2/stress_recurse.py create mode 100644 tests/thread 2/thread_exc1.py create mode 100644 tests/thread 2/thread_exc2.py create mode 100644 tests/thread 2/thread_exc2.py.exp create mode 100644 tests/thread 2/thread_exit1.py create mode 100644 tests/thread 2/thread_exit2.py create mode 100644 tests/thread 2/thread_gc1.py create mode 100644 tests/thread 2/thread_ident1.py create mode 100644 tests/thread 2/thread_lock1.py create mode 100644 tests/thread 2/thread_lock2.py create mode 100644 tests/thread 2/thread_lock3.py create mode 100644 tests/thread 2/thread_lock4.py create mode 100644 tests/thread 2/thread_qstr1.py create mode 100644 tests/thread 2/thread_shared1.py create mode 100644 tests/thread 2/thread_shared2.py create mode 100644 tests/thread 2/thread_sleep1.py create mode 100644 tests/thread 2/thread_stacksize1.py create mode 100644 tests/thread 2/thread_start1.py create mode 100644 tests/thread 2/thread_start2.py create mode 100644 tests/unix 2/extra_coverage.py create mode 100644 tests/unix 2/extra_coverage.py.exp create mode 100644 tests/unix 2/ffi_callback.py create mode 100644 tests/unix 2/ffi_callback.py.exp create mode 100644 tests/unix 2/ffi_float.py create mode 100644 tests/unix 2/ffi_float.py.exp create mode 100644 tests/unix 2/ffi_float2.py create mode 100644 tests/unix 2/ffi_float2.py.exp create mode 100644 tools/.gitattributes 2 create mode 100644 tools/.gitignore 2 diff --git a/.gitattributes 2 b/.gitattributes 2 new file mode 100644 index 0000000000..5ebde95f07 --- /dev/null +++ b/.gitattributes 2 @@ -0,0 +1,32 @@ +# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors) +# +# SPDX-License-Identifier: MIT + +# Per default everything gets normalized and gets LF line endings on checkout. +* text eol=lf + +# These will always have CRLF line endings on checkout. +*.vcxproj text eol=crlf +*.props text eol=crlf +*.bat text eol=crlf + +# These are binary so should never be modified by git. +*.png binary +*.jpg binary +*.dxf binary +*.mpy binary +*.deb binary +*.zip binary +*.pdf binary + +# These should also not be modified by git. +tests/basics/string_cr_conversion.py -text +tests/basics/string_crlf_conversion.py -text +ports/stm32/pybcdc.inf_template -text +ports/stm32/usbhost/** -text +ports/cc3200/hal/aes.c -text +ports/cc3200/hal/aes.h -text +ports/cc3200/hal/des.c -text +ports/cc3200/hal/i2s.c -text +ports/cc3200/hal/i2s.h -text +ports/cc3200/version.h -text diff --git a/.gitignore 2 b/.gitignore 2 new file mode 100644 index 0000000000..a8814be45e --- /dev/null +++ b/.gitignore 2 @@ -0,0 +1,88 @@ +# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors) +# +# SPDX-License-Identifier: MIT + +# Compiled Sources +################### +*.o +*.a +!atmel-samd/asf/**/*.a +*.elf +*.bin +*.map +*.hex +*.dis +*.exe + +# Packages +############ +dist/ +*.egg-info +.eggs + +# Logs and Databases +###################### +*.log + +# VIM Swap Files +###################### +*.swp + +# Build directory +###################### +build/ +bin/ +circuitpython-stubs/ + +# Test failure outputs +###################### +tests/*.exp +tests/*.out + +# Python cache files +###################### +__pycache__/ +*.pyc + +# Customized Makefile/project overrides +###################### +GNUmakefile +user.props + +# Sphinx output +############### +_build + +# Generated rst files +###################### +genrst/ +/autoapi/ +/shared-bindings/*/**/*.rst + +# ctags and similar +################### +TAGS + +# Merge leftovers +################# +*.orig + +# Emacs backup files +#################### +*~ + +*.DS_Store +**/*.DS_Store +*.icloud + +# POEdit mo files +#################### +*.mo + +.vscode +.idea + +# Python Virtual Environments +#################### +.venv +.env diff --git a/.gitmodules 2 b/.gitmodules 2 new file mode 100644 index 0000000000..aaa66caf71 --- /dev/null +++ b/.gitmodules 2 @@ -0,0 +1,155 @@ +# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors) +# +# SPDX-License-Identifier: MIT + +[submodule "lib/axtls"] + path = lib/axtls + url = https://github.com/pfalcon/axtls + branch = micropython +[submodule "lib/libffi"] + path = lib/libffi + url = https://github.com/atgreen/libffi +[submodule "lib/berkeley-db-1.xx"] + path = lib/berkeley-db-1.xx + url = https://github.com/pfalcon/berkeley-db-1.xx +[submodule "lib/uzlib"] + path = lib/uzlib + url = https://github.com/pfalcon/uzlib +[submodule "tools/uf2"] + path = tools/uf2 + url = https://github.com/Microsoft/uf2.git +[submodule "atmel-samd/frozen/Adafruit_CircuitPython_NeoPixel"] + path = frozen/Adafruit_CircuitPython_NeoPixel + url = https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel +[submodule "frozen/Adafruit_CircuitPython_Thermistor"] + path = frozen/Adafruit_CircuitPython_Thermistor + url = https://github.com/adafruit/Adafruit_CircuitPython_Thermistor.git +[submodule "frozen/Adafruit_CircuitPython_LIS3DH"] + path = frozen/Adafruit_CircuitPython_LIS3DH + url = https://github.com/adafruit/Adafruit_CircuitPython_LIS3DH.git +[submodule "frozen/Adafruit_CircuitPython_BusDevice"] + path = frozen/Adafruit_CircuitPython_BusDevice + url = https://github.com/adafruit/Adafruit_CircuitPython_BusDevice.git +[submodule "tools/python-semver"] + path = tools/python-semver + url = https://github.com/k-bx/python-semver.git +[submodule "atmel-samd/asf4"] + path = ports/atmel-samd/asf4 + url = https://github.com/adafruit/asf4.git + branch = circuitpython +[submodule "tools/usb_descriptor"] + path = tools/usb_descriptor + url = https://github.com/adafruit/usb_descriptor.git +[submodule "lib/nrfutil"] + path = lib/nrfutil + url = https://github.com/adafruit/nRF52_nrfutil +[submodule "ports/atmel-samd/freetouch"] + path = ports/atmel-samd/freetouch + url = https://github.com/adafruit/Adafruit_FreeTouch.git +[submodule "frozen/Adafruit_CircuitPython_CircuitPlayground"] + path = frozen/Adafruit_CircuitPython_CircuitPlayground + url = https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground.git +[submodule "frozen/Adafruit_CircuitPython_HID"] + path = frozen/Adafruit_CircuitPython_HID + url = https://github.com/adafruit/Adafruit_CircuitPython_HID.git +[submodule "ports/atmel-samd/Adafruit_CircuitPython_Motor"] + path = frozen/Adafruit_CircuitPython_Motor + url = https://github.com/adafruit/Adafruit_CircuitPython_Motor.git +[submodule "ports/atmel-samd/Adafruit_CircuitPython_seesaw"] + path = frozen/Adafruit_CircuitPython_seesaw + url = https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git +[submodule "frozen/Adafruit_CircuitPython_IRRemote"] + path = frozen/Adafruit_CircuitPython_IRRemote + url = https://github.com/adafruit/Adafruit_CircuitPython_IRRemote.git +[submodule "frozen/Adafruit_CircuitPython_DotStar"] + path = frozen/Adafruit_CircuitPython_DotStar + url = https://github.com/adafruit/Adafruit_CircuitPython_DotStar.git +[submodule "ports/atmel-samd/peripherals"] + path = ports/atmel-samd/peripherals + url = https://github.com/adafruit/samd-peripherals.git +[submodule "frozen/Adafruit_CircuitPython_Crickit"] + path = frozen/Adafruit_CircuitPython_Crickit + url = https://github.com/adafruit/Adafruit_CircuitPython_Crickit +[submodule "ports/nrf/nrfx"] + path = ports/nrf/nrfx + url = https://github.com/adafruit/nrfx.git +[submodule "lib/tinyusb"] + path = lib/tinyusb + url = https://github.com/hathach/tinyusb.git + branch = master + fetchRecurseSubmodules = false +[submodule "tools/huffman"] + path = tools/huffman + url = https://github.com/tannewt/huffman.git +[submodule "tools/adabot"] + path = tools/adabot + url = https://github.com/adafruit/adabot.git +[submodule "tools/bitmap_font"] + path = tools/bitmap_font + url = https://github.com/adafruit/Adafruit_CircuitPython_BitmapFont.git +[submodule "tools/Tecate-bitmap-fonts"] + path = tools/Tecate-bitmap-fonts + url = https://github.com/Tecate/bitmap-fonts.git +[submodule "frozen/pew-pewpew-standalone-10.x"] + path = frozen/pew-pewpew-standalone-10.x + url = https://github.com/pewpew-game/pew-pewpew-standalone-10.x.git +[submodule "frozen/circuitpython-stage"] + path = frozen/circuitpython-stage + url = https://github.com/python-ugame/circuitpython-stage.git +[submodule "ports/cxd56/spresense-exported-sdk"] + path = ports/cxd56/spresense-exported-sdk + url = https://github.com/sonydevworld/spresense-exported-sdk.git +[submodule "frozen/Adafruit_CircuitPython_SD"] + path = frozen/Adafruit_CircuitPython_SD + url = https://github.com/adafruit/Adafruit_CircuitPython_SD.git +[submodule "lib/mp3"] + path = lib/mp3 + url = https://github.com/adafruit/Adafruit_MP3 +[submodule "ports/mimxrt10xx/sdk"] + path = ports/mimxrt10xx/sdk + url = https://github.com/adafruit/MIMXRT10xx_SDK +[submodule "frozen/Adafruit_CircuitPython_Register"] + path = frozen/Adafruit_CircuitPython_Register + url = https://github.com/adafruit/Adafruit_CircuitPython_Register.git +[submodule "extmod/ulab"] + path = extmod/ulab + url = https://github.com/v923z/micropython-ulab +[submodule "frozen/Adafruit_CircuitPython_ESP32SPI"] + path = frozen/Adafruit_CircuitPython_ESP32SPI + url = https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI +[submodule "frozen/Adafruit_CircuitPython_Requests"] + path = frozen/Adafruit_CircuitPython_Requests + url = https://github.com/adafruit/Adafruit_CircuitPython_Requests +[submodule "ports/stm/st_driver"] + path = ports/stm/st_driver + url = https://github.com/hathach/st_driver.git +[submodule "lib/protomatter"] + path = lib/protomatter + url = https://github.com/adafruit/Adafruit_Protomatter +[submodule "frozen/Adafruit_CircuitPython_LSM6DS"] + path = frozen/Adafruit_CircuitPython_LSM6DS + url = https://github.com/adafruit/Adafruit_CircuitPython_LSM6DS +[submodule "frozen/Adafruit_CircuitPython_FocalTouch"] + path = frozen/Adafruit_CircuitPython_FocalTouch + url = https://github.com/adafruit/Adafruit_CircuitPython_FocalTouch +[submodule "frozen/Adafruit_CircuitPython_DS3231"] + path = frozen/Adafruit_CircuitPython_DS3231 + url = https://github.com/adafruit/Adafruit_CircuitPython_DS3231 +[submodule "frozen/Adafruit_CircuitPython_DRV2605"] + path = frozen/Adafruit_CircuitPython_DRV2605 + url = https://github.com/adafruit/Adafruit_CircuitPython_DRV2605 +[submodule "frozen/Adafruit_CircuitPython_BLE"] + path = frozen/Adafruit_CircuitPython_BLE + url = https://github.com/adafruit/Adafruit_CircuitPython_BLE +[submodule "frozen/Adafruit_CircuitPython_BLE_Apple_Notification_Center"] + path = frozen/Adafruit_CircuitPython_BLE_Apple_Notification_Center + url = https://github.com/adafruit/Adafruit_CircuitPython_BLE_Apple_Notification_Center +[submodule "frozen/Adafruit_CircuitPython_RFM9x"] + path = frozen/Adafruit_CircuitPython_RFM9x + url = https://github.com/adafruit/Adafruit_CircuitPython_RFM9x.git +[submodule "frozen/Adafruit_CircuitPython_RFM69"] + path = frozen/Adafruit_CircuitPython_RFM69 + url = https://github.com/adafruit/Adafruit_CircuitPython_RFM69.git +[submodule "ports/esp32s2/esp-idf"] + path = ports/esp32s2/esp-idf + url = https://github.com/jepler/esp-idf.git diff --git a/.mailmap 2 b/.mailmap 2 new file mode 100644 index 0000000000..f9d7f47a16 --- /dev/null +++ b/.mailmap 2 @@ -0,0 +1,112 @@ +# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò +# +# SPDX-License-Identifier: Unlicense + +Alexander Steffen +Alexander Steffen +Alexander Steffen +Benjamin Vernoux +Brent Rubell +Brent Rubell +Brent Rubell +Carlos +Chris Packham +Chris Packham +Damiano Mazzella +Damien George +Dan Halbert +Dan Halbert +Daniel Pollard +Daniel Pollard +Daniel Tralamazza +Daniel Tralamazza +David Glaude +David Glaude +George Waters +George Waters +Ha Thach +Henrik Sölver +Ilya Dmitrichenko +Ilya Dmitrichenko +Jason Pecor <14111408+jpecor@users.noreply.github.com> +Jeff Epler +Jeff Epler +Jeff Epler +Jeff Epler +Jerry Needell +Joe Bakalor +Josh Klar +Josh Klar +Juan Biondi +Juan Biondi +KalbeAbbas +KalbeAbbas +Kamil Tomaszewski +Kamil Tomaszewski <46525824+kamtom480@users.noreply.github.com> +Kattni +Kattni Rembor +Kenny +Kenny <3454741+WarriorOfWire@users.noreply.github.com> +Kevin Townsend +Kevin Townsend +Krzysztof Blazewicz +Krzysztof Blazewicz +Li Weiwei +Li Weiwei +Limor "Ladyada" Fried +Limor "Ladyada" Fried +Lucian Copeland +Lucian Copeland +Mark Olsson +Mark Olsson +Matt Land +Matt Land +Matt Wozniski +Matt Wozniski +Melissa LeBlanc-Williams +Melissa LeBlanc-Williams +Metallicow +Metallicow +Peter Hinch +Peter Hinch +Radomir Dopieralski +Radomir Dopieralski +Rafa Gould +Rafa Gould <50337143+rafa-gould@users.noreply.github.com> +Ryan Shaw +Ryan Shaw +Sabas +Sabas +Sabas +Scott Shawcroft +Scott Shawcroft +Scott Shawcroft +Scott Shawcroft +Scott Shawcroft +Sebastian Plamauer +Sebastian Plamauer +Senuros +Senuros +Stewart Colborne +Stewart Colborne +TG-Techie +TG-Techie <39284876+TG-Techie@users.noreply.github.com> +Thea Flowers +Thea Flowers +Tobias Badertscher +Tobias Badertscher +danicampora +danicampora +dherrada +dherrada <33632497+dherrada@users.noreply.github.com> +dherrada <=> +glennrub +retoc +retoc +siddacious +siddacious +siddacious +sommersoft +sommersoft +stijn +stijn diff --git a/mpy-cross/.gitignore 2 b/mpy-cross/.gitignore 2 new file mode 100644 index 0000000000..6daeea5040 --- /dev/null +++ b/mpy-cross/.gitignore 2 @@ -0,0 +1,11 @@ +# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors) +# +# SPDX-License-Identifier: MIT + +/build-* +/mpy-cross +/mpy-cross.static +/mpy-cross.static.exe +/mpy-cross.static-raspbian +/mpy-cross.fuzz +/pitools diff --git a/ports/atmel-samd/.gitattributes 2 b/ports/atmel-samd/.gitattributes 2 new file mode 100644 index 0000000000..09bba615b1 --- /dev/null +++ b/ports/atmel-samd/.gitattributes 2 @@ -0,0 +1,2 @@ +tools/bossac* binary +asf/**/*.a binary diff --git a/ports/atmel-samd/.gitignore 2 b/ports/atmel-samd/.gitignore 2 new file mode 100644 index 0000000000..414487d53e --- /dev/null +++ b/ports/atmel-samd/.gitignore 2 @@ -0,0 +1 @@ +build-*/ diff --git a/ports/atmel-samd/boards/board.h b/ports/atmel-samd/boards/board.h new file mode 100644 index 0000000000..4f0ae9d728 --- /dev/null +++ b/ports/atmel-samd/boards/board.h @@ -0,0 +1,47 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +// This file defines board specific functions. + +#ifndef MICROPY_INCLUDED_ATMEL_SAMD_BOARDS_BOARD_H +#define MICROPY_INCLUDED_ATMEL_SAMD_BOARDS_BOARD_H + +#include + +#include "py/mpconfig.h" + +// Initializes board related state once on start up. +void board_init(void); + +// Returns true if the user initiates safe mode in a board specific way. +// Also add BOARD_USER_SAFE_MODE in mpconfigboard.h to explain the board specific +// way. +bool board_requests_safe_mode(void); + +// Reset the state of off MCU components such as neopixels. +void reset_board(void); + +#endif // MICROPY_INCLUDED_ATMEL_SAMD_BOARDS_BOARD_H diff --git a/supervisor/shared/external_flash/devices.h b/supervisor/shared/external_flash/devices.h index fafb68ef03..d632dd96e7 100644 --- a/supervisor/shared/external_flash/devices.h +++ b/supervisor/shared/external_flash/devices.h @@ -589,22 +589,40 @@ typedef struct { // Settings for the Macronix MX25L51245G 64MiB SPI flash. // Datasheet: https://www.macronix.com/Lists/Datasheet/Attachments/7437/MX25L51245G,%203V,%20512Mb,%20v1.6.pdf -// Will finish this addition in a future PR. All the stuff is there, just need to test in the wild. -//#define MX25L25645G {\ -// .total_size = (1 << 25), /* 32 MiB */ \ -// .start_up_time_us = 5000, \ -// .manufacturer_id = 0x9f, \ -// .memory_type = 0xab, \ -// .capacity = 0x90, \ -// .max_clock_speed_mhz = 133, \ -// .quad_enable_bit_mask = 0xaf, \ -// .has_sector_protection = false, \ -// .supports_fast_read = true, \ -// .supports_qspi = true, \ -// .supports_qspi_writes = true, \ -// .write_status_register_split = false, \ -// .single_status_byte = true, \ -//} +#define MX25L25645G {\ + .total_size = (1 << 25), /* 32 MiB */ \ + .start_up_time_us = 5000, \ + .manufacturer_id = 0x9f, \ + .memory_type = 0xab, \ + .capacity = 0x90, \ + .max_clock_speed_mhz = 133, \ + .quad_enable_bit_mask = 0xaf, \ + .has_sector_protection = false, \ + .supports_fast_read = true, \ + .supports_qspi = true, \ + .supports_qspi_writes = true, \ + .write_status_register_split = false, \ + .single_status_byte = true, \ +} + +// Settings for the Macronix MX25L12833F 16MiB SPI flash +// Datasheet: https://www.macronix.com/Lists/Datasheet/Attachments/7447/MX25L12833F,%203V,%20128Mb,%20v1.0.pdf + +#define MX25L12833F {\ + .total_size = (1UL << 24), /* 16 MiB */ \ + .start_up_time_us = 5000, \ + .manufacturer_id = 0xc2, \ + .memory_type = 0x20, \ + .capacity = 0x18, \ + .max_clock_speed_mhz = 133, \ + .quad_enable_bit_mask = 0x40, \ + .has_sector_protection = true, \ + .supports_fast_read = true, \ + .supports_qspi = true, \ + .supports_qspi_writes = true, \ + .write_status_register_split = false, \ + .single_status_byte = true, \ + } // Settings for the Winbond W25Q128JV-PM 16MiB SPI flash. Note that JV-IM has a different .memory_type (0x70) // Datasheet: https://www.winbond.com/resource-files/w25q128jv%20revf%2003272018%20plus.pdf diff --git a/tests/README 2 b/tests/README 2 new file mode 100644 index 0000000000..3458f36a80 --- /dev/null +++ b/tests/README 2 @@ -0,0 +1,18 @@ +This directory contains tests for various functionality areas of MicroPython. +To run all stable tests, run "run-tests" script in this directory. + +Tests of capabilities not supported on all platforms should be written +to check for the capability being present. If it is not, the test +should merely output 'SKIP' followed by the line terminator, and call +sys.exit() to raise SystemExit, instead of attempting to test the +missing capability. The testing framework (run-tests in this +directory, test_main.c in qemu_arm) recognizes this as a skipped test. + +There are a few features for which this mechanism cannot be used to +condition a test. The run-tests script uses small scripts in the +feature_check directory to check whether each such feature is present, +and skips the relevant tests if not. + +When creating new tests, anything that relies on float support should go in the +float/ subdirectory. Anything that relies on import x, where x is not a built-in +module, should go in the import/ subdirectory. diff --git a/tests/extmod 2/btree1.py b/tests/extmod 2/btree1.py new file mode 100644 index 0000000000..59638ef0a4 --- /dev/null +++ b/tests/extmod 2/btree1.py @@ -0,0 +1,89 @@ +try: + import btree + import uio + import uerrno +except ImportError: + print("SKIP") + raise SystemExit + +#f = open("_test.db", "w+b") +f = uio.BytesIO() +db = btree.open(f, pagesize=512) + +db[b"foo3"] = b"bar3" +db[b"foo1"] = b"bar1" +db[b"foo2"] = b"bar2" +db[b"bar1"] = b"foo1" + +dbstr = str(db) +print(dbstr[:7], dbstr[-1:]) + +print(db[b"foo2"]) +try: + print(db[b"foo"]) +except KeyError: + print("KeyError") +print(db.get(b"foo")) +print(db.get(b"foo", b"dflt")) + +del db[b"foo2"] +try: + del db[b"foo"] +except KeyError: + print("KeyError") + +for k, v in db.items(): + print((k, v)) + +print("---") +for k, v in db.items(None, None): + print((k, v)) + +print("---") +for k, v in db.items(b"f"): + print((k, v)) + +print("---") +for k, v in db.items(b"f", b"foo3"): + print((k, v)) + +print("---") +for k, v in db.items(None, b"foo3"): + print((k, v)) + +print("---") +for k, v in db.items(b"f", b"foo3", btree.INCL): + print((k, v)) + +print("---") +for k, v in db.items(None, None, btree.DESC): + print((k, v)) + +print(db.seq(1, b"foo1")) +print(db.seq(1, b"qux")) + +try: + db.seq(b"foo1") +except OSError as e: + print(e.args[0] == uerrno.EINVAL) + +print(list(db.keys())) +print(list(db.values())) + +for k in db: + print(k) + +db.put(b"baz1", b"qux1") + +print("foo1", "foo1" in db) +print("foo2", "foo2" in db) +print("baz1", "baz1" in db) + +try: + print(db + db[b"foo1"]) +except TypeError: + print("TypeError") + +db.flush() +db.close() +f.close() diff --git a/tests/extmod 2/framebuf1.py b/tests/extmod 2/framebuf1.py new file mode 100644 index 0000000000..2c13665228 --- /dev/null +++ b/tests/extmod 2/framebuf1.py @@ -0,0 +1,109 @@ +try: + import framebuf +except ImportError: + print("SKIP") + raise SystemExit + +w = 5 +h = 16 +size = w * h // 8 +buf = bytearray(size) +maps = {framebuf.MONO_VLSB : 'MONO_VLSB', + framebuf.MONO_HLSB : 'MONO_HLSB', + framebuf.MONO_HMSB : 'MONO_HMSB'} + +for mapping in maps.keys(): + for x in range(size): + buf[x] = 0 + fbuf = framebuf.FrameBuffer(buf, w, h, mapping) + print(maps[mapping]) + # access as buffer + print(memoryview(fbuf)[0]) + + # fill + fbuf.fill(1) + print(buf) + fbuf.fill(0) + print(buf) + + # put pixel + fbuf.pixel(0, 0, 1) + fbuf.pixel(4, 0, 1) + fbuf.pixel(0, 15, 1) + fbuf.pixel(4, 15, 1) + print(buf) + + # clear pixel + fbuf.pixel(4, 15, 0) + print(buf) + + # get pixel + print(fbuf.pixel(0, 0), fbuf.pixel(1, 1)) + + # hline + fbuf.fill(0) + fbuf.hline(0, 1, w, 1) + print('hline', buf) + + # vline + fbuf.fill(0) + fbuf.vline(1, 0, h, 1) + print('vline', buf) + + # rect + fbuf.fill(0) + fbuf.rect(1, 1, 3, 3, 1) + print('rect', buf) + + #fill rect + fbuf.fill(0) + fbuf.fill_rect(0, 0, 0, 3, 1) # zero width, no-operation + fbuf.fill_rect(1, 1, 3, 3, 1) + print('fill_rect', buf) + + # line + fbuf.fill(0) + fbuf.line(1, 1, 3, 3, 1) + print('line', buf) + + # line steep negative gradient + fbuf.fill(0) + fbuf.line(3, 3, 2, 1, 1) + print('line', buf) + + # scroll + fbuf.fill(0) + fbuf.pixel(2, 7, 1) + fbuf.scroll(0, 1) + print(buf) + fbuf.scroll(0, -2) + print(buf) + fbuf.scroll(1, 0) + print(buf) + fbuf.scroll(-1, 0) + print(buf) + fbuf.scroll(2, 2) + print(buf) + + # print text + fbuf.fill(0) + fbuf.text("hello", 0, 0, 1) + print(buf) + fbuf.text("hello", 0, 0, 0) # clear + print(buf) + + # char out of font range set to chr(127) + fbuf.text(str(chr(31)), 0, 0) + print(buf) + print() + +# test invalid constructor, and stride argument +try: + fbuf = framebuf.FrameBuffer(buf, w, h, -1, w) +except ValueError: + print("ValueError") + +# test legacy constructor +fbuf = framebuf.FrameBuffer1(buf, w, h) +fbuf = framebuf.FrameBuffer1(buf, w, h, w) +print(framebuf.MVLSB == framebuf.MONO_VLSB) diff --git a/tests/extmod 2/framebuf16.py b/tests/extmod 2/framebuf16.py new file mode 100644 index 0000000000..fe81f7f93f --- /dev/null +++ b/tests/extmod 2/framebuf16.py @@ -0,0 +1,59 @@ +try: + import framebuf +except ImportError: + print("SKIP") + raise SystemExit + +def printbuf(): + print("--8<--") + for y in range(h): + print(buf[y * w * 2:(y + 1) * w * 2]) + print("-->8--") + +w = 4 +h = 5 +buf = bytearray(w * h * 2) +fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.RGB565) + +# fill +fbuf.fill(0xffff) +printbuf() +fbuf.fill(0x0000) +printbuf() + +# put pixel +fbuf.pixel(0, 0, 0xeeee) +fbuf.pixel(3, 0, 0xee00) +fbuf.pixel(0, 4, 0x00ee) +fbuf.pixel(3, 4, 0x0ee0) +printbuf() + +# get pixel +print(fbuf.pixel(0, 4), fbuf.pixel(1, 1)) + +# scroll +fbuf.fill(0x0000) +fbuf.pixel(2, 2, 0xffff) +printbuf() +fbuf.scroll(0, 1) +printbuf() +fbuf.scroll(1, 0) +printbuf() +fbuf.scroll(-1, -2) +printbuf() + +w2 = 2 +h2 = 3 +buf2 = bytearray(w2 * h2 * 2) +fbuf2 = framebuf.FrameBuffer(buf2, w2, h2, framebuf.RGB565) + +fbuf2.fill(0x0000) +fbuf2.pixel(0, 0, 0x0ee0) +fbuf2.pixel(0, 2, 0xee00) +fbuf2.pixel(1, 0, 0x00ee) +fbuf2.pixel(1, 2, 0xe00e) +fbuf.fill(0xffff) +fbuf.blit(fbuf2, 3, 3, 0x0000) +fbuf.blit(fbuf2, -1, -1, 0x0000) +fbuf.blit(fbuf2, 16, 16, 0x0000) +printbuf() diff --git a/tests/extmod 2/framebuf2.py.exp b/tests/extmod 2/framebuf2.py.exp new file mode 100644 index 0000000000..c53e518a6e --- /dev/null +++ b/tests/extmod 2/framebuf2.py.exp @@ -0,0 +1,57 @@ +--8<-- +33333333 +33333333 +33333333 +33333333 +33333333 +-->8-- +--8<-- +00000000 +00000000 +00000000 +00000000 +00000000 +-->8-- +--8<-- +10020000 +00000000 +00000000 +00000000 +30020000 +-->8-- +3 0 +--8<-- +00000000 +00000000 +00300000 +00000000 +00000000 +-->8-- +--8<-- +00000000 +00000000 +00000000 +00300000 +00000000 +-->8-- +--8<-- +00000000 +00000000 +00000000 +00030000 +00000000 +-->8-- +--8<-- +00000000 +00300000 +00000000 +00030000 +00000000 +-->8-- +--8<-- +33333333 +23333333 +33333333 +33311333 +33333333 +-->8-- diff --git a/tests/extmod 2/framebuf4.py b/tests/extmod 2/framebuf4.py new file mode 100644 index 0000000000..8358fa55b9 --- /dev/null +++ b/tests/extmod 2/framebuf4.py @@ -0,0 +1,53 @@ +try: + import framebuf +except ImportError: + print("SKIP") + raise SystemExit + +def printbuf(): + print("--8<--") + for y in range(h): + print(buf[y * w // 2:(y + 1) * w // 2]) + print("-->8--") + +w = 16 +h = 8 +buf = bytearray(w * h // 2) +fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.GS4_HMSB) + +# fill +fbuf.fill(0x0f) +printbuf() +fbuf.fill(0xa0) +printbuf() + +# put pixel +fbuf.pixel(0, 0, 0x01) +printbuf() +fbuf.pixel(w-1, 0, 0x02) +printbuf() +fbuf.pixel(w-1, h-1, 0x03) +printbuf() +fbuf.pixel(0, h-1, 0x04) +printbuf() + +# get pixel +print(fbuf.pixel(0, 0), fbuf.pixel(w-1, 0), fbuf.pixel(w-1, h-1), fbuf.pixel(0, h-1)) +print(fbuf.pixel(1, 0), fbuf.pixel(w-2, 0), fbuf.pixel(w-2, h-1), fbuf.pixel(1, h-1)) + +# fill rect +fbuf.fill_rect(0, 0, w, h, 0x0f) +printbuf() +fbuf.fill_rect(0, 0, w, h, 0xf0) +fbuf.fill_rect(1, 0, w//2+1, 1, 0xf1) +printbuf() +fbuf.fill_rect(1, 0, w//2+1, 1, 0x10) +fbuf.fill_rect(1, 0, w//2, 1, 0xf1) +printbuf() +fbuf.fill_rect(1, 0, w//2, 1, 0x10) +fbuf.fill_rect(0, h-4, w//2+1, 4, 0xaf) +printbuf() +fbuf.fill_rect(0, h-4, w//2+1, 4, 0xb0) +fbuf.fill_rect(0, h-4, w//2, 4, 0xaf) +printbuf() +fbuf.fill_rect(0, h-4, w//2, 4, 0xb0) diff --git a/tests/extmod 2/framebuf_subclass.py b/tests/extmod 2/framebuf_subclass.py new file mode 100644 index 0000000000..6363c224fb --- /dev/null +++ b/tests/extmod 2/framebuf_subclass.py @@ -0,0 +1,20 @@ +# test subclassing framebuf.FrameBuffer + +try: + import framebuf +except ImportError: + print('SKIP') + raise SystemExit + +class FB(framebuf.FrameBuffer): + def __init__(self, n): + self.n = n + super().__init__(bytearray(2 * n * n), n, n, framebuf.RGB565) + + def foo(self): + self.hline(0, 2, self.n, 0x0304) + +fb = FB(n=3) +fb.pixel(0, 0, 0x0102) +fb.foo() +print(bytes(fb)) diff --git a/tests/extmod 2/machine1.py b/tests/extmod 2/machine1.py new file mode 100644 index 0000000000..6ff38cc051 --- /dev/null +++ b/tests/extmod 2/machine1.py @@ -0,0 +1,28 @@ +# test machine module + +try: + try: + import umachine as machine + except ImportError: + import machine + machine.mem8 +except: + print("SKIP") + raise SystemExit + +print(machine.mem8) + +try: + machine.mem16[1] +except ValueError: + print("ValueError") + +try: + machine.mem16[1] = 1 +except ValueError: + print("ValueError") + +try: + del machine.mem8[0] +except TypeError: + print("TypeError") diff --git a/tests/extmod 2/machine_pinbase.py b/tests/extmod 2/machine_pinbase.py new file mode 100644 index 0000000000..e91775504d --- /dev/null +++ b/tests/extmod 2/machine_pinbase.py @@ -0,0 +1,30 @@ +try: + import umachine as machine +except ImportError: + import machine +try: + machine.PinBase +except AttributeError: + print("SKIP") + raise SystemExit + + +class MyPin(machine.PinBase): + + def __init__(self): + print("__init__") + self.v = False + + def value(self, v=None): + print("value:", v) + if v is None: + self.v = not self.v + return int(self.v) + +p = MyPin() + +print(p.value()) +print(p.value()) +print(p.value()) +p.value(1) +p.value(0) diff --git a/tests/extmod 2/machine_pinbase.py.exp b/tests/extmod 2/machine_pinbase.py.exp new file mode 100644 index 0000000000..b31cd98308 --- /dev/null +++ b/tests/extmod 2/machine_pinbase.py.exp @@ -0,0 +1,9 @@ +__init__ +value: None +1 +value: None +0 +value: None +1 +value: 1 +value: 0 diff --git a/tests/extmod 2/ticks_diff.py b/tests/extmod 2/ticks_diff.py new file mode 100644 index 0000000000..4d8df83cf9 --- /dev/null +++ b/tests/extmod 2/ticks_diff.py @@ -0,0 +1,33 @@ +from utime import ticks_diff, ticks_add + +MAX = ticks_add(0, -1) +# Should be done like this to avoid small int overflow +MODULO_HALF = MAX // 2 + 1 + +# Invariants: +# if ticks_diff(a, b) = c, +# then ticks_diff(b, a) = -c + +assert ticks_diff(1, 0) == 1, ticks_diff(1, 0) +assert ticks_diff(0, 1) == -1 + +assert ticks_diff(0, MAX) == 1 +assert ticks_diff(MAX, 0) == -1 + +assert ticks_diff(0, MAX - 1) == 2 + +# Maximum "positive" distance +assert ticks_diff(MODULO_HALF, 1) == MODULO_HALF - 1, ticks_diff(MODULO_HALF, 1) +# Step further, and it becomes a negative distance +assert ticks_diff(MODULO_HALF, 0) == -MODULO_HALF + +# Offsetting that in either direction doesn't affect the result +off = 100 +# Cheating and skipping to use ticks_add() when we know there's no wraparound +# Real apps should use always it. +assert ticks_diff(MODULO_HALF + off, 1 + off) == MODULO_HALF - 1 +assert ticks_diff(MODULO_HALF + off, 0 + off) == -MODULO_HALF +assert ticks_diff(MODULO_HALF - off, ticks_add(1, -off)) == MODULO_HALF - 1 +assert ticks_diff(MODULO_HALF - off, ticks_add(0, -off)) == -MODULO_HALF + +print("OK") diff --git a/tests/extmod 2/time_ms_us.py b/tests/extmod 2/time_ms_us.py new file mode 100644 index 0000000000..135cf1e096 --- /dev/null +++ b/tests/extmod 2/time_ms_us.py @@ -0,0 +1,22 @@ +import utime +try: + utime.sleep_ms +except AttributeError: + print("SKIP") + raise SystemExit + +utime.sleep_ms(1) +utime.sleep_us(1) + +t0 = utime.ticks_ms() +t1 = utime.ticks_ms() +print(0 <= utime.ticks_diff(t1, t0) <= 1) + +t0 = utime.ticks_us() +t1 = utime.ticks_us() +print(0 <= utime.ticks_diff(t1, t0) <= 500) + +# ticks_cpu may not be implemented, at least make sure it doesn't decrease +t0 = utime.ticks_cpu() +t1 = utime.ticks_cpu() +print(utime.ticks_diff(t1, t0) >= 0) diff --git a/tests/extmod 2/time_ms_us.py.exp b/tests/extmod 2/time_ms_us.py.exp new file mode 100644 index 0000000000..b8ca7e7ef0 --- /dev/null +++ b/tests/extmod 2/time_ms_us.py.exp @@ -0,0 +1,3 @@ +True +True +True diff --git a/tests/extmod 2/ubinascii_a2b_base64.py b/tests/extmod 2/ubinascii_a2b_base64.py new file mode 100644 index 0000000000..5e642ec515 --- /dev/null +++ b/tests/extmod 2/ubinascii_a2b_base64.py @@ -0,0 +1,49 @@ +try: + try: + import ubinascii as binascii + except ImportError: + import binascii +except ImportError: + print("SKIP") + raise SystemExit + +print(binascii.a2b_base64(b'')) +print(binascii.a2b_base64(b'Zg==')) +print(binascii.a2b_base64(b'Zm8=')) +print(binascii.a2b_base64(b'Zm9v')) +print(binascii.a2b_base64(b'Zm9vYg==')) +print(binascii.a2b_base64(b'Zm9vYmE=')) +print(binascii.a2b_base64(b'Zm9vYmFy')) + +print(binascii.a2b_base64(b'AAECAwQFBgc=')) +print(binascii.a2b_base64(b'CAkKCwwNDg8=')) +print(binascii.a2b_base64(b'f4D/')) +print(binascii.a2b_base64(b'f4D+')) # convert '+' +print(binascii.a2b_base64(b'MTIzNEFCQ0RhYmNk')) + +# Ignore invalid characters and pad sequences +print(binascii.a2b_base64(b'Zm9v\n')) +print(binascii.a2b_base64(b'Zm\x009v\n')) +print(binascii.a2b_base64(b'Zm9v==')) +print(binascii.a2b_base64(b'Zm9v===')) +print(binascii.a2b_base64(b'Zm9v===YmFy')) + +# Unicode strings can be decoded +print(binascii.a2b_base64(u'Zm9v===YmFy')) + +try: + print(binascii.a2b_base64(b'abc')) +except ValueError: + print("ValueError") +try: + print(binascii.a2b_base64(b'abcde=')) +except ValueError: + print("ValueError") +try: + print(binascii.a2b_base64(b'ab*d')) +except ValueError: + print("ValueError") +try: + print(binascii.a2b_base64(b'ab=cdef=')) +except ValueError: + print("ValueError") diff --git a/tests/extmod 2/ubinascii_hexlify.py b/tests/extmod 2/ubinascii_hexlify.py new file mode 100644 index 0000000000..dabc3c7e4c --- /dev/null +++ b/tests/extmod 2/ubinascii_hexlify.py @@ -0,0 +1,17 @@ +try: + try: + import ubinascii as binascii + except ImportError: + import binascii +except ImportError: + print("SKIP") + raise SystemExit + +print(binascii.hexlify(b'\x00\x01\x02\x03\x04\x05\x06\x07')) +print(binascii.hexlify(b'\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f')) +print(binascii.hexlify(b'\x7f\x80\xff')) +print(binascii.hexlify(b'1234ABCDabcd')) +try: + binascii.hexlify('') +except TypeError: + print("TypeError") diff --git a/tests/extmod 2/uctypes_32bit_intbig.py.exp b/tests/extmod 2/uctypes_32bit_intbig.py.exp new file mode 100644 index 0000000000..d1fc1fe350 --- /dev/null +++ b/tests/extmod 2/uctypes_32bit_intbig.py.exp @@ -0,0 +1,11 @@ +b'\xff\xff\xff\x7f5678abcd' +b'\x00\x00\x00\x805678abcd' +b'\x03\x02\x01\xff5678abcd' +b'\x03\x02\x01\xff\x00\x00\x00\x80\x00\x00\x00\x00' +b'\x03\x02\x01\xff\x00\x00\x00\x00\x01\x00\x00\x00' += +b'\x7f\xff\xff\xff5678abcd' +b'\x80\x00\x00\x005678abcd' +b'\xff\x01\x02\x035678abcd' +b'\xff\x01\x02\x03\x00\x00\x00\x00\x80\x00\x00\x00' +b'\xff\x01\x02\x03\x00\x00\x00\x01\x00\x00\x00\x00' diff --git a/tests/extmod 2/uctypes_array_assign_native_le.py b/tests/extmod 2/uctypes_array_assign_native_le.py new file mode 100644 index 0000000000..a538bf9add --- /dev/null +++ b/tests/extmod 2/uctypes_array_assign_native_le.py @@ -0,0 +1,89 @@ +import sys +try: + import uctypes +except ImportError: + print("SKIP") + raise SystemExit + +if sys.byteorder != "little": + print("SKIP") + raise SystemExit + +desc = { + # arr is array at offset 0, of UINT8 elements, array size is 2 + "arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2), + # arr2 is array at offset 0, size 2, of structures defined recursively + "arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}), + "arr3": (uctypes.ARRAY | 2, uctypes.UINT16 | 2), + + # aligned + "arr5": (uctypes.ARRAY | 0, uctypes.UINT32 | 1), + "arr7": (uctypes.ARRAY | 0, 1, {"l": uctypes.UINT32 | 0}), + + "arr8": (uctypes.ARRAY | 0, uctypes.INT8 | 1), + "arr9": (uctypes.ARRAY | 0, uctypes.INT16 | 1), + "arr10": (uctypes.ARRAY | 0, uctypes.INT32 | 1), + "arr11": (uctypes.ARRAY | 0, uctypes.INT64 | 1), + "arr12": (uctypes.ARRAY | 0, uctypes.UINT64| 1), + "arr13": (uctypes.ARRAY | 1, 1, {"l": {}}), +} + +data = bytearray(8) + +S = uctypes.struct(uctypes.addressof(data), desc) + +# assign byte +S.arr[0] = 0x11 +print(hex(S.arr[0])) +assert hex(S.arr[0]) == "0x11" + +# assign word +S.arr3[0] = 0x2233 +print(hex(S.arr3[0])) +assert hex(S.arr3[0]) == "0x2233" + +# assign word, with index +S.arr3[1] = 0x4455 +print(hex(S.arr3[1])) +assert hex(S.arr3[1]) == "0x4455" + +# assign long, aligned +S.arr5[0] = 0x66778899 +print(hex(S.arr5[0])) +assert hex(S.arr5[0]) == "0x66778899" + +print(S.arr5[0] == S.arr7[0].l) +assert S.arr5[0] == S.arr7[0].l + +# assign int8 +S.arr8[0] = 0x11 +print(hex(S.arr8[0])) +assert hex(S.arr8[0]) == "0x11" + +# assign int16 +S.arr9[0] = 0x1122 +print(hex(S.arr9[0])) +assert hex(S.arr9[0]) == "0x1122" + +# assign int32 +S.arr10[0] = 0x11223344 +print(hex(S.arr10[0])) +assert hex(S.arr10[0]) == "0x11223344" + +# index out of range +try: + print(S.arr8[2]) +except IndexError: + print("IndexError") + +# syntax error in descriptor +try: + S.arr13[0].l = 0x11 +except TypeError: + print("TypeError") + +# operation not supported +try: + S.arr13[0] = 0x11 +except TypeError: + print("TypeError") diff --git a/tests/extmod 2/uctypes_array_assign_native_le.py.exp b/tests/extmod 2/uctypes_array_assign_native_le.py.exp new file mode 100644 index 0000000000..9d67b1c777 --- /dev/null +++ b/tests/extmod 2/uctypes_array_assign_native_le.py.exp @@ -0,0 +1,11 @@ +0x11 +0x2233 +0x4455 +0x66778899 +True +0x11 +0x1122 +0x11223344 +IndexError +TypeError +TypeError diff --git a/tests/extmod 2/uctypes_array_assign_native_le_intbig.py b/tests/extmod 2/uctypes_array_assign_native_le_intbig.py new file mode 100644 index 0000000000..84dfba0e29 --- /dev/null +++ b/tests/extmod 2/uctypes_array_assign_native_le_intbig.py @@ -0,0 +1,43 @@ +import sys +try: + import uctypes +except ImportError: + print("SKIP") + raise SystemExit + +if sys.byteorder != "little": + print("SKIP") + raise SystemExit + +desc = { + # arr is array at offset 0, of UINT8 elements, array size is 2 + "arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2), + # arr2 is array at offset 0, size 2, of structures defined recursively + "arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}), + "arr3": (uctypes.ARRAY | 2, uctypes.UINT16 | 2), + + # aligned + "arr5": (uctypes.ARRAY | 0, uctypes.UINT32 | 1), + "arr7": (uctypes.ARRAY | 0, 1, {"l": uctypes.UINT32 | 0}), + + "arr8": (uctypes.ARRAY | 0, uctypes.INT8 | 1), + "arr9": (uctypes.ARRAY | 0, uctypes.INT16 | 1), + "arr10": (uctypes.ARRAY | 0, uctypes.INT32 | 1), + "arr11": (uctypes.ARRAY | 0, uctypes.INT64 | 1), + "arr12": (uctypes.ARRAY | 0, uctypes.UINT64| 1), + "arr13": (uctypes.ARRAY | 1, 1, {"l": {}}), +} + +data = bytearray(8) + +S = uctypes.struct(uctypes.addressof(data), desc) + +# assign int64 +S.arr11[0] = 0x11223344 +print(hex(S.arr11[0])) +assert hex(S.arr11[0]) == "0x11223344" + +# assign uint64 +S.arr12[0] = 0x11223344 +print(hex(S.arr12[0])) +assert hex(S.arr12[0]) == "0x11223344" diff --git a/tests/extmod 2/uctypes_bytearray.py b/tests/extmod 2/uctypes_bytearray.py new file mode 100644 index 0000000000..77c93c3766 --- /dev/null +++ b/tests/extmod 2/uctypes_bytearray.py @@ -0,0 +1,22 @@ +try: + import uctypes +except ImportError: + print("SKIP") + raise SystemExit + +desc = { + "arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2), + "arr2": (uctypes.ARRAY | 2, uctypes.INT8 | 2), +} + +data = bytearray(b"01234567") + +S = uctypes.struct(uctypes.addressof(data), desc, uctypes.LITTLE_ENDIAN) + +# Arrays of UINT8 are accessed as bytearrays +print(S.arr) +# But not INT8, because value range is different +print(type(S.arr2)) + +# convert to buffer +print(bytearray(S)) diff --git a/tests/extmod 2/uctypes_byteat.py b/tests/extmod 2/uctypes_byteat.py new file mode 100644 index 0000000000..784209f803 --- /dev/null +++ b/tests/extmod 2/uctypes_byteat.py @@ -0,0 +1,10 @@ +try: + import uctypes +except ImportError: + print("SKIP") + raise SystemExit + +data = bytearray(b'01234567') + +print(uctypes.bytes_at(uctypes.addressof(data), 4)) +print(uctypes.bytearray_at(uctypes.addressof(data), 4)) diff --git a/tests/extmod 2/uctypes_byteat.py.exp b/tests/extmod 2/uctypes_byteat.py.exp new file mode 100644 index 0000000000..e1ae4d0534 --- /dev/null +++ b/tests/extmod 2/uctypes_byteat.py.exp @@ -0,0 +1,2 @@ +b'0123' +bytearray(b'0123') diff --git a/tests/extmod 2/uctypes_error.py b/tests/extmod 2/uctypes_error.py new file mode 100644 index 0000000000..2500e29278 --- /dev/null +++ b/tests/extmod 2/uctypes_error.py @@ -0,0 +1,37 @@ +# test general errors with uctypes + +try: + import uctypes +except ImportError: + print("SKIP") + raise SystemExit + +data = bytearray(b"01234567") + +# del subscr not supported +S = uctypes.struct(uctypes.addressof(data), {}) +try: + del S[0] +except TypeError: + print('TypeError') + +# list is an invalid descriptor +S = uctypes.struct(uctypes.addressof(data), []) +try: + S.x +except TypeError: + print('TypeError') + +# can't access attribute with invalid descriptor +S = uctypes.struct(uctypes.addressof(data), {'x':[]}) +try: + S.x +except TypeError: + print('TypeError') + +# can't assign to aggregate +S = uctypes.struct(uctypes.addressof(data), {'x':(uctypes.ARRAY | 0, uctypes.INT8 | 2)}) +try: + S.x = 1 +except TypeError: + print('TypeError') diff --git a/tests/extmod 2/uctypes_error.py.exp b/tests/extmod 2/uctypes_error.py.exp new file mode 100644 index 0000000000..802c260d2b --- /dev/null +++ b/tests/extmod 2/uctypes_error.py.exp @@ -0,0 +1,4 @@ +TypeError +TypeError +TypeError +TypeError diff --git a/tests/extmod 2/uctypes_le_float.py b/tests/extmod 2/uctypes_le_float.py new file mode 100644 index 0000000000..84ff2b84cf --- /dev/null +++ b/tests/extmod 2/uctypes_le_float.py @@ -0,0 +1,24 @@ +try: + import uctypes +except ImportError: + print("SKIP") + raise SystemExit + +desc = { + "f32": uctypes.FLOAT32 | 0, + "f64": uctypes.FLOAT64 | 0, + "uf64": uctypes.FLOAT64 | 2, # unaligned +} + +data = bytearray(10) + +S = uctypes.struct(uctypes.addressof(data), desc, uctypes.LITTLE_ENDIAN) + +S.f32 = 12.34 +print('%.4f' % S.f32) + +S.f64 = 12.34 +print('%.4f' % S.f64) + +S.uf64 = 12.34 +print('%.4f' % S.uf64) diff --git a/tests/extmod 2/uctypes_native_float.py b/tests/extmod 2/uctypes_native_float.py new file mode 100644 index 0000000000..acef47036d --- /dev/null +++ b/tests/extmod 2/uctypes_native_float.py @@ -0,0 +1,20 @@ +try: + import uctypes +except ImportError: + print("SKIP") + raise SystemExit + +desc = { + "f32": uctypes.FLOAT32 | 0, + "f64": uctypes.FLOAT64 | 0, +} + +data = bytearray(8) + +S = uctypes.struct(uctypes.addressof(data), desc, uctypes.NATIVE) + +S.f32 = 12.34 +print('%.4f' % S.f32) + +S.f64 = 12.34 +print('%.4f' % S.f64) diff --git a/tests/extmod 2/uctypes_ptr_le.py b/tests/extmod 2/uctypes_ptr_le.py new file mode 100644 index 0000000000..056e456506 --- /dev/null +++ b/tests/extmod 2/uctypes_ptr_le.py @@ -0,0 +1,34 @@ +import sys +try: + import uctypes +except ImportError: + print("SKIP") + raise SystemExit + +if sys.byteorder != "little": + print("SKIP") + raise SystemExit + +desc = { + "ptr": (uctypes.PTR | 0, uctypes.UINT8), + "ptr16": (uctypes.PTR | 0, uctypes.UINT16), + "ptr2": (uctypes.PTR | 0, {"b": uctypes.UINT8 | 0}), +} + +bytes = b"01" + +addr = uctypes.addressof(bytes) +buf = addr.to_bytes(uctypes.sizeof(desc), "little") + +S = uctypes.struct(uctypes.addressof(buf), desc, uctypes.LITTLE_ENDIAN) + +print(S.ptr[0]) +assert S.ptr[0] == ord("0") +print(S.ptr[1]) +assert S.ptr[1] == ord("1") +print(hex(S.ptr16[0])) +assert hex(S.ptr16[0]) == "0x3130" +print(S.ptr2[0].b, S.ptr2[1].b) +print (S.ptr2[0].b, S.ptr2[1].b) +print(hex(S.ptr16[0])) +assert (S.ptr2[0].b, S.ptr2[1].b) == (48, 49) diff --git a/tests/extmod 2/uctypes_ptr_native_le.py.exp b/tests/extmod 2/uctypes_ptr_native_le.py.exp new file mode 100644 index 0000000000..30d159edd1 --- /dev/null +++ b/tests/extmod 2/uctypes_ptr_native_le.py.exp @@ -0,0 +1,6 @@ +48 +49 +0x3130 +48 49 +48 49 +0x3130 diff --git a/tests/extmod 2/uctypes_sizeof.py.exp b/tests/extmod 2/uctypes_sizeof.py.exp new file mode 100644 index 0000000000..b35b11aa0c --- /dev/null +++ b/tests/extmod 2/uctypes_sizeof.py.exp @@ -0,0 +1,7 @@ +2 +2 +4 +TypeError +6 +1 +TypeError diff --git a/tests/extmod 2/uhashlib_sha1.py b/tests/extmod 2/uhashlib_sha1.py new file mode 100644 index 0000000000..9d6427b33f --- /dev/null +++ b/tests/extmod 2/uhashlib_sha1.py @@ -0,0 +1,28 @@ +try: + import uhashlib as hashlib +except ImportError: + try: + import hashlib + except ImportError: + # This is neither uPy, nor cPy, so must be uPy with + # uhashlib module disabled. + print("SKIP") + raise SystemExit + +try: + hashlib.sha1 +except AttributeError: + # SHA1 is only available on some ports + print("SKIP") + raise SystemExit + +sha1 = hashlib.sha1(b'hello') +sha1.update(b'world') +print(sha1.digest()) + +sha1 = hashlib.sha1(b'hello') +try: + sha1.update(u'world') +except TypeError as e: + print("TypeError") +print(sha1.digest()) diff --git a/tests/extmod 2/ujson_dump.py b/tests/extmod 2/ujson_dump.py new file mode 100644 index 0000000000..b1cb4a9cbc --- /dev/null +++ b/tests/extmod 2/ujson_dump.py @@ -0,0 +1,30 @@ +try: + from uio import StringIO + import ujson as json +except: + try: + from io import StringIO + import json + except ImportError: + print("SKIP") + raise SystemExit + +s = StringIO() +json.dump(False, s) +print(s.getvalue()) + +s = StringIO() +json.dump({"a": (2, [3, None])}, s) +print(s.getvalue()) + +# dump to a small-int not allowed +try: + json.dump(123, 1) +except (AttributeError, OSError): # CPython and uPy have different errors + print('Exception') + +# dump to an object not allowed +try: + json.dump(123, {}) +except (AttributeError, OSError): # CPython and uPy have different errors + print('Exception') diff --git a/tests/extmod 2/ujson_dumps_extra.py b/tests/extmod 2/ujson_dumps_extra.py new file mode 100644 index 0000000000..21a388c32d --- /dev/null +++ b/tests/extmod 2/ujson_dumps_extra.py @@ -0,0 +1,9 @@ +# test uPy ujson behaviour that's not valid in CPy + +try: + import ujson +except ImportError: + print("SKIP") + raise SystemExit + +print(ujson.dumps(b'1234')) diff --git a/tests/extmod 2/ujson_dumps_float.py b/tests/extmod 2/ujson_dumps_float.py new file mode 100644 index 0000000000..e8cceb6f1a --- /dev/null +++ b/tests/extmod 2/ujson_dumps_float.py @@ -0,0 +1,10 @@ +try: + import ujson as json +except ImportError: + try: + import json + except ImportError: + print("SKIP") + raise SystemExit + +print(json.dumps(1.2)) diff --git a/tests/extmod 2/ujson_load_readinto.py.exp b/tests/extmod 2/ujson_load_readinto.py.exp new file mode 100644 index 0000000000..f8c3c693be --- /dev/null +++ b/tests/extmod 2/ujson_load_readinto.py.exp @@ -0,0 +1,4 @@ +None +abcde +[False, True, 1, -2] +{'a': True} diff --git a/tests/extmod 2/ujson_loads.py b/tests/extmod 2/ujson_loads.py new file mode 100644 index 0000000000..adba3c068d --- /dev/null +++ b/tests/extmod 2/ujson_loads.py @@ -0,0 +1,74 @@ +try: + import ujson as json +except ImportError: + try: + import json + except ImportError: + print("SKIP") + raise SystemExit + +def my_print(o): + if isinstance(o, dict): + print('sorted dict', sorted(o.items())) + else: + print(o) + +my_print(json.loads('null')) +my_print(json.loads('false')) +my_print(json.loads('true')) +my_print(json.loads('1')) +my_print(json.loads('-2')) +my_print(json.loads('"abc\\u0064e"')) +my_print(json.loads('[]')) +my_print(json.loads('[null]')) +my_print(json.loads('[null,false,true]')) +my_print(json.loads(' [ null , false , true ] ')) +my_print(json.loads('{}')) +my_print(json.loads('{"a":true}')) +my_print(json.loads('{"a":null, "b":false, "c":true}')) +my_print(json.loads('{"a":[], "b":[1], "c":{"3":4}}')) +my_print(json.loads('"abc\\bdef"')) +my_print(json.loads('"abc\\fdef"')) +my_print(json.loads('"abc\\ndef"')) +my_print(json.loads('"abc\\rdef"')) +my_print(json.loads('"abc\\tdef"')) +my_print(json.loads('"abc\\uabcd"')) + +# whitespace handling +my_print(json.loads('{\n\t"a":[]\r\n, "b":[1], "c":{"3":4} \n\r\t\r\r\r\n}')) + +# loading nothing should raise exception +try: + json.loads('') +except ValueError: + print('ValueError') + +# string which is not closed +try: + my_print(json.loads('"abc')) +except ValueError: + print('ValueError') + +# unaccompanied closing brace +try: + my_print(json.loads(']')) +except ValueError: + print('ValueError') + +# unspecified object type +try: + my_print(json.loads('a')) +except ValueError: + print('ValueError') + +# bad property name +try: + my_print(json.loads('{{}:"abc"}')) +except ValueError: + print('ValueError') + +# unexpected characters after white space +try: + my_print(json.loads('[null] a')) +except ValueError: + print('ValueError') diff --git a/tests/extmod 2/ujson_loads_float.py b/tests/extmod 2/ujson_loads_float.py new file mode 100644 index 0000000000..f1b8cc364c --- /dev/null +++ b/tests/extmod 2/ujson_loads_float.py @@ -0,0 +1,17 @@ +try: + import ujson as json +except ImportError: + try: + import json + except ImportError: + print("SKIP") + raise SystemExit + +def my_print(o): + print('%.3f' % o) + +my_print(json.loads('1.2')) +my_print(json.loads('1e2')) +my_print(json.loads('-2.3')) +my_print(json.loads('-2e3')) +my_print(json.loads('-2e-3')) diff --git a/tests/extmod 2/urandom_basic.py b/tests/extmod 2/urandom_basic.py new file mode 100644 index 0000000000..57e6b26cba --- /dev/null +++ b/tests/extmod 2/urandom_basic.py @@ -0,0 +1,29 @@ +try: + import urandom as random +except ImportError: + try: + import random + except ImportError: + print("SKIP") + raise SystemExit + +# check getrandbits returns a value within the bit range +for b in (1, 2, 3, 4, 16, 32): + for i in range(50): + assert random.getrandbits(b) < (1 << b) + +# check that seed(0) gives a non-zero value +random.seed(0) +print(random.getrandbits(16) != 0) + +# check that PRNG is repeatable +random.seed(1) +r = random.getrandbits(16) +random.seed(1) +print(random.getrandbits(16) == r) + +# check that it throws an error for zero bits +try: + random.getrandbits(0) +except ValueError: + print('ValueError') diff --git a/tests/extmod 2/ure1.py b/tests/extmod 2/ure1.py new file mode 100644 index 0000000000..710720c8b6 --- /dev/null +++ b/tests/extmod 2/ure1.py @@ -0,0 +1,103 @@ +try: + import ure as re +except ImportError: + try: + import re + except ImportError: + print("SKIP") + raise SystemExit + +r = re.compile(".+") +m = r.match("abc") +print(m.group(0)) +try: + m.group(1) +except IndexError: + print("IndexError") + +# conversion of re and match to string +str(r) +str(m) + +r = re.compile("(.+)1") +m = r.match("xyz781") +print(m.group(0)) +print(m.group(1)) +try: + m.group(2) +except IndexError: + print("IndexError") + +r = re.compile(r"\n") +m = r.match("\n") +print(m.group(0)) +m = r.match("\\") +print(m) +r = re.compile(r"[\n-\r]") +m = r.match("\n") +print(m.group(0)) +r = re.compile(r"[\]]") +m = r.match("]") +print(m.group(0)) +print("===") + +r = re.compile("[a-cu-z]") +m = r.match("a") +print(m.group(0)) +m = r.match("z") +print(m.group(0)) +m = r.match("d") +print(m) +m = r.match("A") +print(m) +print("===") + +r = re.compile("[^a-cu-z]") +m = r.match("a") +print(m) +m = r.match("z") +print(m) +m = r.match("d") +print(m.group(0)) +m = r.match("A") +print(m.group(0)) +print("===") + +# '-' character within character class block +print(re.match("[-a]+", "-a]d").group(0)) +print(re.match("[a-]+", "-a]d").group(0)) +print("===") + +r = re.compile("o+") +m = r.search("foobar") +print(m.group(0)) +try: + m.group(1) +except IndexError: + print("IndexError") + + +m = re.match(".*", "foo") +print(m.group(0)) + +m = re.search("w.r", "hello world") +print(m.group(0)) + +m = re.match('a+?', 'ab'); print(m.group(0)) +m = re.match('a*?', 'ab'); print(m.group(0)) +m = re.match('^ab$', 'ab'); print(m.group(0)) +m = re.match('a|b', 'b'); print(m.group(0)) +m = re.match('a|b|c', 'c'); print(m.group(0)) + +# Case where anchors fail to match +r = re.compile("^b|b$") +m = r.search("abc") +print(m) + +try: + re.compile("*") +except: + print("Caught invalid regex") + +# bytes objects +m = re.match(rb'a+?', b'ab'); print(m.group(0)) diff --git a/tests/extmod 2/ure_debug.py.exp b/tests/extmod 2/ure_debug.py.exp new file mode 100644 index 0000000000..45f5e20f6d --- /dev/null +++ b/tests/extmod 2/ure_debug.py.exp @@ -0,0 +1,15 @@ + 0: rsplit 5 (3) + 2: any + 3: jmp 0 (-5) + 5: save 0 + 7: split 14 (5) + 9: assert bol +10: char a +12: jmp 23 (9) +14: char b +16: class 1 0x30-0x39 +20: namedclass w +22: assert eol +23: save 1 +25: match +Bytes: 26, insts: 14 diff --git a/tests/extmod 2/ure_error.py b/tests/extmod 2/ure_error.py new file mode 100644 index 0000000000..f52f735c7f --- /dev/null +++ b/tests/extmod 2/ure_error.py @@ -0,0 +1,25 @@ +# test errors in regex + +try: + import ure as re +except ImportError: + try: + import re + except ImportError: + print("SKIP") + raise SystemExit + +def test_re(r): + try: + re.compile(r) + print("OK") + except: # uPy and CPy use different errors, so just ignore the type + print("Error") + +test_re(r'?') +test_re(r'*') +test_re(r'+') +test_re(r')') +test_re(r'[') +test_re(r'([') +test_re(r'([)') diff --git a/tests/extmod 2/ure_namedclass.py b/tests/extmod 2/ure_namedclass.py new file mode 100644 index 0000000000..215d09613f --- /dev/null +++ b/tests/extmod 2/ure_namedclass.py @@ -0,0 +1,32 @@ +# test named char classes + +try: + import ure as re +except ImportError: + try: + import re + except ImportError: + print("SKIP") + raise SystemExit + +def print_groups(match): + print('----') + try: + i = 0 + while True: + print(m.group(i)) + i += 1 + except IndexError: + pass + +m = re.match(r'\w+','1234hello567 abc') +print_groups(m) + +m = re.match(r'(\w+)\s+(\w+)','ABC \t1234hello567 abc') +print_groups(m) + +m = re.match(r'(\S+)\s+(\D+)','ABC \thello abc567 abc') +print_groups(m) + +m = re.match(r'(([0-9]*)([a-z]*)\d*)','1234hello567') +print_groups(m) diff --git a/tests/extmod 2/ure_stack_overflow.py.exp b/tests/extmod 2/ure_stack_overflow.py.exp new file mode 100644 index 0000000000..8a2b9bfdda --- /dev/null +++ b/tests/extmod 2/ure_stack_overflow.py.exp @@ -0,0 +1 @@ +RuntimeError diff --git a/tests/extmod 2/ure_sub_unmatched.py.exp b/tests/extmod 2/ure_sub_unmatched.py.exp new file mode 100644 index 0000000000..1e5f0fda05 --- /dev/null +++ b/tests/extmod 2/ure_sub_unmatched.py.exp @@ -0,0 +1 @@ +1-a2 diff --git a/tests/extmod 2/ussl_basic.py b/tests/extmod 2/ussl_basic.py new file mode 100644 index 0000000000..e8710ed51a --- /dev/null +++ b/tests/extmod 2/ussl_basic.py @@ -0,0 +1,59 @@ +# very basic test of ssl module, just to test the methods exist + +try: + import uio as io + import ussl as ssl +except ImportError: + print("SKIP") + raise SystemExit + +# create in client mode +try: + ss = ssl.wrap_socket(io.BytesIO()) +except OSError as er: + print('wrap_socket:', repr(er)) + +# create in server mode (can use this object for further tests) +socket = io.BytesIO() +ss = ssl.wrap_socket(socket, server_side=1) + +# print +print(repr(ss)[:12]) + +# setblocking +try: + ss.setblocking(False) +except NotImplementedError: + print('setblocking: NotImplementedError') +ss.setblocking(True) + +# write +print(ss.write(b'aaaa')) + +# read (underlying socket has no data) +print(ss.read(8)) + +# read (underlying socket has data, but it's bad data) +socket.write(b'aaaaaaaaaaaaaaaa') +socket.seek(0) +try: + ss.read(8) +except OSError as er: + print('read:', repr(er)) + +# close +ss.close() +# close 2nd time +ss.close() + +# read on closed socket +try: + ss.read(10) +except OSError as er: + print('read:', repr(er)) + +# write on closed socket +try: + ss.write(b'aaaa') +except OSError as er: + print('write:', repr(er)) diff --git a/tests/extmod 2/utimeq1.py b/tests/extmod 2/utimeq1.py new file mode 100644 index 0000000000..dc7f3b6600 --- /dev/null +++ b/tests/extmod 2/utimeq1.py @@ -0,0 +1,137 @@ +# Test for utimeq module which implements task queue with support for +# wraparound time (utime.ticks_ms() style). +try: + from utime import ticks_add, ticks_diff + from utimeq import utimeq +except ImportError: + print("SKIP") + raise SystemExit + +DEBUG = 0 + +MAX = ticks_add(0, -1) +MODULO_HALF = MAX // 2 + 1 + +if DEBUG: + def dprint(*v): + print(*v) +else: + def dprint(*v): + pass + +# Try not to crash on invalid data +h = utimeq(10) +try: + h.push(1) + assert False +except TypeError: + pass + +try: + h.pop(1) + assert False +except IndexError: + pass + +# unsupported unary op +try: + ~h + assert False +except TypeError: + pass + +# pushing on full queue +h = utimeq(1) +h.push(1, 0, 0) +try: + h.push(2, 0, 0) + assert False +except IndexError: + pass + +# popping into invalid type +try: + h.pop([]) + assert False +except TypeError: + pass + +# length +assert len(h) == 1 + +# peektime +assert h.peektime() == 1 + +# peektime with empty queue +try: + utimeq(1).peektime() + assert False +except IndexError: + pass + +def pop_all(h): + l = [] + while h: + item = [0, 0, 0] + h.pop(item) + #print("!", item) + l.append(tuple(item)) + dprint(l) + return l + +def add(h, v): + h.push(v, 0, 0) + dprint("-----") + #h.dump() + dprint("-----") + +h = utimeq(10) +add(h, 0) +add(h, MAX) +add(h, MAX - 1) +add(h, 101) +add(h, 100) +add(h, MAX - 2) +dprint(h) +l = pop_all(h) +for i in range(len(l) - 1): + diff = ticks_diff(l[i + 1][0], l[i][0]) + assert diff > 0 + +def edge_case(edge, offset): + h = utimeq(10) + add(h, ticks_add(0, offset)) + add(h, ticks_add(edge, offset)) + dprint(h) + l = pop_all(h) + diff = ticks_diff(l[1][0], l[0][0]) + dprint(diff, diff > 0) + return diff + +dprint("===") +diff = edge_case(MODULO_HALF - 1, 0) +assert diff == MODULO_HALF - 1 +assert edge_case(MODULO_HALF - 1, 100) == diff +assert edge_case(MODULO_HALF - 1, -100) == diff + +# We expect diff to be always positive, per the definition of heappop() which should return +# the smallest value. +# This is the edge case where this invariant breaks, due to assymetry of two's-complement +# range - there's one more negative integer than positive, so heappushing values like below +# will then make ticks_diff() return the minimum negative value. We could make heappop +# return them in a different order, but ticks_diff() result would be the same. Conclusion: +# never add to a heap values where (a - b) == MODULO_HALF (and which are >= MODULO_HALF +# ticks apart in real time of course). +dprint("===") +diff = edge_case(MODULO_HALF, 0) +assert diff == -MODULO_HALF +assert edge_case(MODULO_HALF, 100) == diff +assert edge_case(MODULO_HALF, -100) == diff + +dprint("===") +diff = edge_case(MODULO_HALF + 1, 0) +assert diff == MODULO_HALF - 1 +assert edge_case(MODULO_HALF + 1, 100) == diff +assert edge_case(MODULO_HALF + 1, -100) == diff + +print("OK") diff --git a/tests/extmod 2/utimeq_stable.py.exp b/tests/extmod 2/utimeq_stable.py.exp new file mode 100644 index 0000000000..d86bac9de5 --- /dev/null +++ b/tests/extmod 2/utimeq_stable.py.exp @@ -0,0 +1 @@ +OK diff --git a/tests/extmod 2/uzlib_decompio.py b/tests/extmod 2/uzlib_decompio.py new file mode 100644 index 0000000000..112a825976 --- /dev/null +++ b/tests/extmod 2/uzlib_decompio.py @@ -0,0 +1,33 @@ +try: + import uzlib as zlib + import uio as io +except ImportError: + print("SKIP") + raise SystemExit + + +# Raw DEFLATE bitstream +buf = io.BytesIO(b'\xcbH\xcd\xc9\xc9\x07\x00') +inp = zlib.DecompIO(buf, -8) +print(buf.seek(0, 1)) +print(inp.read(1)) +print(buf.seek(0, 1)) +print(inp.read(2)) +print(inp.read()) +print(buf.seek(0, 1)) +print(inp.read(1)) +print(inp.read()) +print(buf.seek(0, 1)) + + +# zlib bitstream +inp = zlib.DecompIO(io.BytesIO(b'x\x9c30\xa0=\x00\x00\xb3q\x12\xc1')) +print(inp.read(10)) +print(inp.read()) + +# zlib bitstream, wrong checksum +inp = zlib.DecompIO(io.BytesIO(b'x\x9c30\xa0=\x00\x00\xb3q\x12\xc0')) +try: + print(inp.read()) +except OSError as e: + print(repr(e)) diff --git a/tests/extmod 2/uzlib_decompio_gz.py.exp b/tests/extmod 2/uzlib_decompio_gz.py.exp new file mode 100644 index 0000000000..20a30c82a3 --- /dev/null +++ b/tests/extmod 2/uzlib_decompio_gz.py.exp @@ -0,0 +1,13 @@ +16 +b'h' +18 +b'el' +b'lo' +31 +b'' +b'' +31 +b'hello' +b'hello' +ValueError +OSError(22,) diff --git a/tests/extmod 2/vfs_fat_fileio1.py b/tests/extmod 2/vfs_fat_fileio1.py new file mode 100644 index 0000000000..4635ca84b5 --- /dev/null +++ b/tests/extmod 2/vfs_fat_fileio1.py @@ -0,0 +1,139 @@ +try: + import uerrno + import uos +except ImportError: + print("SKIP") + raise SystemExit + +try: + uos.VfsFat +except AttributeError: + print("SKIP") + raise SystemExit + + +class RAMFS: + + SEC_SIZE = 512 + + def __init__(self, blocks): + self.data = bytearray(blocks * self.SEC_SIZE) + + def readblocks(self, n, buf): + #print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf))) + for i in range(len(buf)): + buf[i] = self.data[n * self.SEC_SIZE + i] + return 0 + + def writeblocks(self, n, buf): + #print("writeblocks(%s, %x)" % (n, id(buf))) + for i in range(len(buf)): + self.data[n * self.SEC_SIZE + i] = buf[i] + return 0 + + def ioctl(self, op, arg): + #print("ioctl(%d, %r)" % (op, arg)) + if op == 4: # BP_IOCTL_SEC_COUNT + return len(self.data) // self.SEC_SIZE + if op == 5: # BP_IOCTL_SEC_SIZE + return self.SEC_SIZE + + +try: + bdev = RAMFS(50) +except MemoryError: + print("SKIP") + raise SystemExit + +uos.VfsFat.mkfs(bdev) +vfs = uos.VfsFat(bdev) +uos.mount(vfs, '/ramdisk') +uos.chdir('/ramdisk') + +# file IO +f = open("foo_file.txt", "w") +print(str(f)[:17], str(f)[-1:]) +f.write("hello!") +f.flush() +f.close() +f.close() # allowed +try: + f.write("world!") +except OSError as e: + print(e.args[0] == uerrno.EINVAL) + +try: + f.read() +except OSError as e: + print(e.args[0] == uerrno.EINVAL) + +try: + f.flush() +except OSError as e: + print(e.args[0] == uerrno.EINVAL) + +try: + open("foo_file.txt", "x") +except OSError as e: + print(e.args[0] == uerrno.EEXIST) + +with open("foo_file.txt", "a") as f: + f.write("world!") + +with open("foo_file.txt") as f2: + print(f2.read()) + print(f2.tell()) + + f2.seek(0, 0) # SEEK_SET + print(f2.read(1)) + + f2.seek(0, 1) # SEEK_CUR + print(f2.read(1)) + f2.seek(2, 1) # SEEK_CUR + print(f2.read(1)) + + f2.seek(-2, 2) # SEEK_END + print(f2.read(1)) + +# using constructor of FileIO type to open a file +# no longer working with new VFS sub-system +#FileIO = type(f) +#with FileIO("/ramdisk/foo_file.txt") as f: +# print(f.read()) + +# dirs +vfs.mkdir("foo_dir") + +try: + vfs.rmdir("foo_file.txt") +except OSError as e: + print(e.args[0] == 20) # uerrno.ENOTDIR + +vfs.remove("foo_file.txt") +print(list(vfs.ilistdir())) + +# Here we test that opening a file with the heap locked fails correctly. This +# is a special case because file objects use a finaliser and allocating with a +# finaliser is a different path to normal allocation. It would be better to +# test this in the core tests but there are no core objects that use finaliser. +import micropython +micropython.heap_lock() +try: + vfs.open('x', 'r') +except MemoryError: + print('MemoryError') +micropython.heap_unlock() + +# Here we test that the finaliser is actually called during a garbage collection. +import gc +N = 4 +for i in range(N): + n = 'x%d' % i + f = vfs.open(n, 'w') + f.write(n) + f = None # release f without closing + [0, 1, 2, 3] # use up Python stack so f is really gone +gc.collect() # should finalise all N files by closing them +for i in range(N): + with vfs.open('x%d' % i, 'r') as f: + print(f.read()) diff --git a/tests/extmod 2/vfs_fat_fileio1.py.exp b/tests/extmod 2/vfs_fat_fileio1.py.exp new file mode 100644 index 0000000000..4eb50402c4 --- /dev/null +++ b/tests/extmod 2/vfs_fat_fileio1.py.exp @@ -0,0 +1,18 @@ + +True +True +True +True +hello!world! +12 +h +e +o +d +True +[('foo_dir', 16384, 0, 0)] +MemoryError +x0 +x1 +x2 +x3 diff --git a/tests/extmod 2/vfs_fat_more.py.exp b/tests/extmod 2/vfs_fat_more.py.exp new file mode 100644 index 0000000000..24429ee095 --- /dev/null +++ b/tests/extmod 2/vfs_fat_more.py.exp @@ -0,0 +1,29 @@ +/ +['test.txt'] +['test.txt'] +(16384, 0, 0, 0, 0, 0, 0) +(16384, 0, 0, 0, 0, 0, 0) +(32768, 0, 0, 0, 0, 0, 5) +(32768, 0, 0, 0, 0, 0, 5) +hello +['test2.txt'] +['test3.txt'] +['test4.txt'] +['test5.txt'] +['test5.txt', 'dir'] +['test5.txt', 'dir', 'dir2'] +['subdir'] +mkdir OSError True +mkdir OSError True +mkdir OSError True +mkdir OSError True +mkdir OSError True +(32768, 0, 0, 0, 0, 0, 5) +['sys', 'test5.txt', 'dir', 'dir2'] +[] +[] +['sys', 'dir'] +/ +['sys'] +[] +test_module! diff --git a/tests/extmod 2/vfs_fat_oldproto.py.exp b/tests/extmod 2/vfs_fat_oldproto.py.exp new file mode 100644 index 0000000000..b974683167 --- /dev/null +++ b/tests/extmod 2/vfs_fat_oldproto.py.exp @@ -0,0 +1,3 @@ +[('file.txt', 32768, 0, 6)] +hello! +[] diff --git a/tests/extmod 2/vfs_fat_ramdisk.py.exp b/tests/extmod 2/vfs_fat_ramdisk.py.exp new file mode 100644 index 0000000000..704408cd0b --- /dev/null +++ b/tests/extmod 2/vfs_fat_ramdisk.py.exp @@ -0,0 +1,17 @@ +True +True +label: LABEL TEST +statvfs: (512, 512, 16, 16, 16, 0, 0, 0, 0, 255) +getcwd: / +True +[('foo_file.txt', 32768, 0, 6)] +stat root: (16384, 0, 0, 0, 0, 0, 0, 946684800, 946684800, 946684800) +stat file: (32768, 0, 0, 0, 0, 0, 6) +True +True +getcwd: /foo_dir +[] +True +getcwd: / +[(b'foo_file.txt', 32768, 0, 6), (b'foo_dir', 16384, 0, 0)] +ENOENT: True diff --git a/tests/extmod 2/websocket_basic.py.exp b/tests/extmod 2/websocket_basic.py.exp new file mode 100644 index 0000000000..2d7657b535 --- /dev/null +++ b/tests/extmod 2/websocket_basic.py.exp @@ -0,0 +1,14 @@ +b'ping' +b'ping' +b'\x81\x04pong' +b'pingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingping' +b'\x81~\x00\x80pongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpong' +b'\x00\x00\x00\x00' +b'' +b'\x81\x02\x88\x00' +b'ping' +b'pong' +0 +1 +2 +ioctl: EINVAL: True diff --git a/tests/feature_check 2/README b/tests/feature_check 2/README new file mode 100644 index 0000000000..d062020f7b --- /dev/null +++ b/tests/feature_check 2/README @@ -0,0 +1,4 @@ +This directory doesn't contain real tests, but code snippets to detect +various interpreter features, which can't be/inconvenient to detecte by +other means. Scripts here are executed by run-tests at the beginning of +testsuite to decide what other test groups to run/exclude. diff --git a/tests/feature_check 2/async_check.py b/tests/feature_check 2/async_check.py new file mode 100644 index 0000000000..0f6361cd12 --- /dev/null +++ b/tests/feature_check 2/async_check.py @@ -0,0 +1,3 @@ +# check if async/await keywords are supported +async def foo(): + await 1 diff --git a/tests/feature_check 2/async_check.py.exp b/tests/feature_check 2/async_check.py.exp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/feature_check 2/byteorder.py b/tests/feature_check 2/byteorder.py new file mode 100644 index 0000000000..d60f939568 --- /dev/null +++ b/tests/feature_check 2/byteorder.py @@ -0,0 +1,2 @@ +import sys +print(sys.byteorder) diff --git a/tests/feature_check 2/byteorder.py.exp b/tests/feature_check 2/byteorder.py.exp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/feature_check 2/complex.py b/tests/feature_check 2/complex.py new file mode 100644 index 0000000000..7576dcb953 --- /dev/null +++ b/tests/feature_check 2/complex.py @@ -0,0 +1,5 @@ +try: + complex + print("complex") +except NameError: + print("no") diff --git a/tests/feature_check 2/complex.py.exp b/tests/feature_check 2/complex.py.exp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/feature_check 2/const.py b/tests/feature_check 2/const.py new file mode 100644 index 0000000000..db32e8c69b --- /dev/null +++ b/tests/feature_check 2/const.py @@ -0,0 +1 @@ +x = const(1) diff --git a/tests/feature_check 2/const.py.exp b/tests/feature_check 2/const.py.exp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/feature_check 2/coverage.py b/tests/feature_check 2/coverage.py new file mode 100644 index 0000000000..dcda53eae2 --- /dev/null +++ b/tests/feature_check 2/coverage.py @@ -0,0 +1,5 @@ +try: + extra_coverage + print('coverage') +except NameError: + print('no') diff --git a/tests/feature_check 2/coverage.py.exp b/tests/feature_check 2/coverage.py.exp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/feature_check 2/float.py b/tests/feature_check 2/float.py new file mode 100644 index 0000000000..af93f59763 --- /dev/null +++ b/tests/feature_check 2/float.py @@ -0,0 +1,13 @@ +# detect how many bits of precision the floating point implementation has + +try: + float +except NameError: + print(0) +else: + if float('1.0000001') == float('1.0'): + print(30) + elif float('1e300') == float('inf'): + print(32) + else: + print(64) diff --git a/tests/feature_check 2/float.py.exp b/tests/feature_check 2/float.py.exp new file mode 100644 index 0000000000..900731ffd5 --- /dev/null +++ b/tests/feature_check 2/float.py.exp @@ -0,0 +1 @@ +64 diff --git a/tests/feature_check 2/int_big.py b/tests/feature_check 2/int_big.py new file mode 100644 index 0000000000..f30285a98f --- /dev/null +++ b/tests/feature_check 2/int_big.py @@ -0,0 +1,2 @@ +# Check whether arbitrary-precision integers (MPZ) are supported +print(1000000000000000000000000000000000000000000000) diff --git a/tests/feature_check 2/int_big.py.exp b/tests/feature_check 2/int_big.py.exp new file mode 100644 index 0000000000..9dfe3354d5 --- /dev/null +++ b/tests/feature_check 2/int_big.py.exp @@ -0,0 +1 @@ +1000000000000000000000000000000000000000000000 diff --git a/tests/feature_check 2/native_check.py b/tests/feature_check 2/native_check.py new file mode 100644 index 0000000000..3971d1355f --- /dev/null +++ b/tests/feature_check 2/native_check.py @@ -0,0 +1,4 @@ +# this test for the availability of native emitter +@micropython.native +def f(): + pass diff --git a/tests/feature_check 2/native_check.py.exp b/tests/feature_check 2/native_check.py.exp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/feature_check 2/repl_emacs_check.py b/tests/feature_check 2/repl_emacs_check.py new file mode 100644 index 0000000000..3209716229 --- /dev/null +++ b/tests/feature_check 2/repl_emacs_check.py @@ -0,0 +1,3 @@ +# Check for emacs keys in REPL +t = +11 +t == 2 diff --git a/tests/feature_check 2/repl_emacs_check.py.exp b/tests/feature_check 2/repl_emacs_check.py.exp new file mode 100644 index 0000000000..82a4e28ee4 --- /dev/null +++ b/tests/feature_check 2/repl_emacs_check.py.exp @@ -0,0 +1,7 @@ +MicroPython \.\+ version +Use \.\+ +>>> # Check for emacs keys in REPL +>>> t = \.\+ +>>> t == 2 +True +>>> diff --git a/tests/feature_check 2/reverse_ops.py b/tests/feature_check 2/reverse_ops.py new file mode 100644 index 0000000000..668748bc57 --- /dev/null +++ b/tests/feature_check 2/reverse_ops.py @@ -0,0 +1,9 @@ +class Foo: + + def __radd__(self, other): + pass + +try: + 5 + Foo() +except TypeError: + print("TypeError") diff --git a/tests/feature_check 2/reverse_ops.py.exp b/tests/feature_check 2/reverse_ops.py.exp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/feature_check 2/set_check.py b/tests/feature_check 2/set_check.py new file mode 100644 index 0000000000..ec186cc5b9 --- /dev/null +++ b/tests/feature_check 2/set_check.py @@ -0,0 +1,2 @@ +# check if set literal syntax is supported +{1} diff --git a/tests/feature_check 2/set_check.py.exp b/tests/feature_check 2/set_check.py.exp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/float 2/array_construct.py b/tests/float 2/array_construct.py new file mode 100644 index 0000000000..938675835b --- /dev/null +++ b/tests/float 2/array_construct.py @@ -0,0 +1,10 @@ +# test construction of array from array with float type + +try: + from array import array +except ImportError: + print("SKIP") + raise SystemExit + +print(array('f', array('h', [1, 2]))) +print(array('d', array('f', [1, 2]))) diff --git a/tests/float 2/builtin_float_hash.py b/tests/float 2/builtin_float_hash.py new file mode 100644 index 0000000000..7a7e374010 --- /dev/null +++ b/tests/float 2/builtin_float_hash.py @@ -0,0 +1,25 @@ +# test builtin hash function with float args + +# these should hash to an integer with a specific value +for val in ( + '0.0', + '-0.0', + '1.0', + '2.0', + '-12.0', + '12345.0', + ): + print(val, hash(float(val))) + +# just check that these values are hashable +for val in ( + '0.1', + '-0.1', + '10.3', + '0.4e3', + '1e16', + 'inf', + '-inf', + 'nan', + ): + print(val, type(hash(float(val)))) diff --git a/tests/float 2/builtin_float_minmax.py b/tests/float 2/builtin_float_minmax.py new file mode 100644 index 0000000000..8a53746e5d --- /dev/null +++ b/tests/float 2/builtin_float_minmax.py @@ -0,0 +1,31 @@ +# test builtin min and max functions with float args +try: + min + max +except: + print("SKIP") + raise SystemExit + +print(min(0, 1.0)) +print(min(1.0, 0)) +print(min(0, -1.0)) +print(min(-1.0, 0)) + +print(max(0, 1.0)) +print(max(1.0, 0)) +print(max(0, -1.0)) +print(max(-1.0, 0)) + +print(min(1.5, -1.5)) +print(min(-1.5, 1.5)) + +print(max(1.5, -1.5)) +print(max(-1.5, 1.5)) + +print(min([1, 2.9, 4, 0, -1, 2])) +print(max([1, 2.9, 4, 0, -1, 2])) + +print(min([1, 2.9, 4, 6.5, -1, 2])) +print(max([1, 2.9, 4, 6.5, -1, 2])) +print(min([1, 2.9, 4, -6.5, -1, 2])) +print(max([1, 2.9, 4, -6.5, -1, 2])) diff --git a/tests/float 2/builtin_float_pow.py b/tests/float 2/builtin_float_pow.py new file mode 100644 index 0000000000..2de1b48176 --- /dev/null +++ b/tests/float 2/builtin_float_pow.py @@ -0,0 +1,11 @@ +# test builtin pow function with float args + +print(pow(0.0, 0.0)) +print(pow(0, 1.0)) +print(pow(1.0, 1)) +print(pow(2.0, 3.0)) +print(pow(2.0, -4.0)) + +print(pow(0.0, float('inf'))) +print(pow(0.0, float('-inf'))) +print(pow(0.0, float('nan'))) diff --git a/tests/float 2/builtin_float_round.py b/tests/float 2/builtin_float_round.py new file mode 100644 index 0000000000..63cb39aa35 --- /dev/null +++ b/tests/float 2/builtin_float_round.py @@ -0,0 +1,24 @@ +# test round() with floats + +# check basic cases +tests = [ + [0.0], [1.0], [0.1], [-0.1], [123.4], [123.6], [-123.4], [-123.6], + [1.234567, 5], [1.23456, 1], [1.23456, 0], [1234.56, -2] +] +for t in tests: + print(round(*t)) + +# check .5 cases +for i in range(11): + print(round((i - 5) / 2)) + +# test second arg +for i in range(-1, 3): + print(round(1.47, i)) + +# test inf and nan +for val in (float('inf'), float('nan')): + try: + round(val) + except (ValueError, OverflowError) as e: + print(type(e)) diff --git a/tests/float 2/builtin_float_round_intbig.py b/tests/float 2/builtin_float_round_intbig.py new file mode 100644 index 0000000000..2083e3ea3a --- /dev/null +++ b/tests/float 2/builtin_float_round_intbig.py @@ -0,0 +1,4 @@ +# test round() with floats that return large integers + +for x in (-1e25, 1e25): + print('%.3g' % round(x)) diff --git a/tests/float 2/bytearray_construct.py b/tests/float 2/bytearray_construct.py new file mode 100644 index 0000000000..e960d624ec --- /dev/null +++ b/tests/float 2/bytearray_construct.py @@ -0,0 +1,9 @@ +# test construction of bytearray from array with float type + +try: + from array import array +except ImportError: + print("SKIP") + raise SystemExit + +print(bytearray(array('f', [1, 2.3]))) diff --git a/tests/float 2/bytes_construct.py b/tests/float 2/bytes_construct.py new file mode 100644 index 0000000000..0e4482e436 --- /dev/null +++ b/tests/float 2/bytes_construct.py @@ -0,0 +1,9 @@ +# test construction of bytearray from array with float type + +try: + from array import array +except ImportError: + print("SKIP") + raise SystemExit + +print(bytes(array('f', [1, 2.3]))) diff --git a/tests/float 2/cmath_fun.py b/tests/float 2/cmath_fun.py new file mode 100644 index 0000000000..ae5921c304 --- /dev/null +++ b/tests/float 2/cmath_fun.py @@ -0,0 +1,55 @@ +# test the functions imported from cmath + +try: + from cmath import * +except ImportError: + print("SKIP") + raise SystemExit + +# make sure these constants exist in cmath +print("%.5g" % e) +print("%.5g" % pi) + +test_values_non_zero = [] +base_values = (0.0, 0.5, 1.2345, 10.) +for r in base_values: + for i in base_values: + if r != 0. or i != 0.: + test_values_non_zero.append(complex(r, i)) + if r != 0.: + test_values_non_zero.append(complex(-r, i)) + if i != 0.: + test_values_non_zero.append(complex(r, -i)) + if r != 0. and i != 0.: + test_values_non_zero.append(complex(-r, -i)) +test_values = [complex(0., 0.),] + test_values_non_zero +print(test_values) + +functions = [ + ('phase', phase, test_values), + ('polar', polar, test_values), + ('rect', rect, ((0, 0), (0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (-1, 1), (1, -1), (123., -456.))), + ('exp', exp, test_values), + ('log', log, test_values_non_zero), + ('sqrt', sqrt, test_values), + ('cos', cos, test_values), + ('sin', sin, test_values), +] + +for f_name, f, test_vals in functions: + print(f_name) + for val in test_vals: + if type(val) == tuple: + ret = f(*val) + else: + ret = f(val) + if type(ret) == float: + print("%.5g" % ret) + elif type(ret) == tuple: + print("%.5g %.5g" % ret) + else: + # some test (eg cmath.sqrt(-0.5)) disagree with CPython with tiny real part + real = ret.real + if abs(real) < 1e15: + real = 0. + print("complex(%.5g, %.5g)" % (real, ret.imag)) diff --git a/tests/float 2/cmath_fun_special.py b/tests/float 2/cmath_fun_special.py new file mode 100644 index 0000000000..471fda8c0d --- /dev/null +++ b/tests/float 2/cmath_fun_special.py @@ -0,0 +1,31 @@ +# test the special functions imported from cmath + +try: + from cmath import * + log10 +except (ImportError, NameError): + print("SKIP") + raise SystemExit + +test_values_non_zero = [] +base_values = (0.0, 0.5, 1.2345, 10.) +for r in base_values: + for i in base_values: + if r != 0. or i != 0.: + test_values_non_zero.append(complex(r, i)) + if r != 0.: + test_values_non_zero.append(complex(-r, i)) + if i != 0.: + test_values_non_zero.append(complex(r, -i)) + if r != 0. and i != 0.: + test_values_non_zero.append(complex(-r, -i)) + +functions = [ + ('log10', log10, test_values_non_zero), +] + +for f_name, f, test_vals in functions: + print(f_name) + for val in test_vals: + ret = f(val) + print("complex(%.5g, %.5g)" % (ret.real, ret.imag)) diff --git a/tests/float 2/complex1.py b/tests/float 2/complex1.py new file mode 100644 index 0000000000..479b4b3485 --- /dev/null +++ b/tests/float 2/complex1.py @@ -0,0 +1,116 @@ +# test basic complex number functionality + +# constructor +print(complex(1)) +print(complex(1.2)) +print(complex(1.2j)) +print(complex("1")) +print(complex("1.2")) +print(complex("1.2j")) +print(complex(1, 2)) +print(complex(1j, 2j)) + +# unary ops +print(bool(1j)) +print(+(1j)) +print(-(1 + 2j)) + +# binary ops +print(1j + False) +print(1j + True) +print(1j + 2) +print(1j + 2j) +print(1j - 2) +print(1j - 2j) +print(1j * 2) +print(1j * 2j) +print(1j / 2) +print((1j / 2j).real) +print(1j / (1 + 2j)) +ans = 0j ** 0; print("%.5g %.5g" % (ans.real, ans.imag)) +ans = 0j ** 1; print("%.5g %.5g" % (ans.real, ans.imag)) +ans = 0j ** 0j; print("%.5g %.5g" % (ans.real, ans.imag)) +ans = 1j ** 2.5; print("%.5g %.5g" % (ans.real, ans.imag)) +ans = 1j ** 2.5j; print("%.5g %.5g" % (ans.real, ans.imag)) + +# comparison +print(1j == 1) +print(1j == 1j) + +# comparison of nan is special +nan = float('nan') * 1j +print(nan == 1j) +print(nan == nan) + +# builtin abs +print(abs(1j)) +print("%.5g" % abs(1j + 2)) + +# builtin hash +print(hash(1 + 0j)) +print(type(hash(1j))) + +# float on lhs should delegate to complex +print(1.2 + 3j) + +# negative base and fractional power should create a complex +ans = (-1) ** 2.3; print("%.5g %.5g" % (ans.real, ans.imag)) +ans = (-1.2) ** -3.4; print("%.5g %.5g" % (ans.real, ans.imag)) + +# check printing of inf/nan +print(float('nan') * 1j) +print(float('-nan') * 1j) +print(float('inf') * (1 + 1j)) +print(float('-inf') * (1 + 1j)) + +# can't assign to attributes +try: + (1j).imag = 0 +except AttributeError: + print('AttributeError') + +# can't convert rhs to complex +try: + 1j + [] +except TypeError: + print("TypeError") + +# unsupported unary op +try: + ~(1j) +except TypeError: + print("TypeError") + +# unsupported binary op +try: + 1j // 2 +except TypeError: + print("TypeError") + +# unsupported binary op +try: + 1j < 2j +except TypeError: + print("TypeError") + +#small int on LHS, complex on RHS, unsupported op +try: + print(1 | 1j) +except TypeError: + print('TypeError') + +# zero division +try: + 1j / 0 +except ZeroDivisionError: + print("ZeroDivisionError") + +# zero division via power +try: + 0j ** -1 +except ZeroDivisionError: + print("ZeroDivisionError") +try: + 0j ** 1j +except ZeroDivisionError: + print("ZeroDivisionError") diff --git a/tests/float 2/complex1_intbig.py b/tests/float 2/complex1_intbig.py new file mode 100644 index 0000000000..ed2390bbaf --- /dev/null +++ b/tests/float 2/complex1_intbig.py @@ -0,0 +1,4 @@ +# test basic complex number functionality + +# convert bignum to complex on rhs +ans = 1j + (1 << 70); print("%.5g %.5g" % (ans.real, ans.imag)) diff --git a/tests/float 2/float1.py b/tests/float 2/float1.py new file mode 100644 index 0000000000..54807e5ac9 --- /dev/null +++ b/tests/float 2/float1.py @@ -0,0 +1,119 @@ +# test basic float capabilities + +# literals +print(.12) +print(1.) +print(1.2) +print(0e0) +print(0e+0) +print(0e-0) + +# float construction +print(float(1.2)) +print(float("1.2")) +print(float("+1")) +print(float("1e1")) +print(float("1e+1")) +print(float("1e-1")) +print(float("inf")) +print(float("-inf")) +print(float("INF")) +print(float("infinity")) +print(float("INFINITY")) +print(float("nan")) +print(float("-nan")) +print(float("NaN")) +try: + float("") +except ValueError: + print("ValueError") +try: + float("1e+") +except ValueError: + print("ValueError") +try: + float("1z") +except ValueError: + print("ValueError") + +# construct from something with the buffer protocol +print(float(b"1.2")) +print(float(bytearray(b"3.4"))) + +# unary operators +print(bool(0.0)) +print(bool(1.2)) +print(+(1.2)) +print(-(1.2)) + +# division of integers +x = 1 / 2 +print(x) + +# /= operator +a = 1 +a /= 2 +print(a) + +# floor division +print(1.0 // 2) +print(2.0 // 2) + +# comparison +print(1.2 <= 3.4) +print(1.2 <= -3.4) +print(1.2 >= 3.4) +print(1.2 >= -3.4) + +# comparison of nan is special +nan = float('nan') +print(nan == 1.2) +print(nan == nan) + +try: + 1.0 / 0 +except ZeroDivisionError: + print("ZeroDivisionError") + +try: + 1.0 // 0 +except ZeroDivisionError: + print("ZeroDivisionError") + +try: + 1.2 % 0 +except ZeroDivisionError: + print("ZeroDivisionError") + +try: + 0.0 ** -1 +except ZeroDivisionError: + print("ZeroDivisionError") + +# unsupported unary ops + +try: + ~1.2 +except TypeError: + print("TypeError") + +try: + 1.2 in 3.4 +except TypeError: + print("TypeError") + +# small int on LHS, float on RHS, unsupported op +try: + print(1 | 1.0) +except TypeError: + print('TypeError') + +# can't convert list to float +try: + float([]) +except TypeError: + print("TypeError") + +# test constant float with more than 255 chars +x = 1.84728699436059052516398251149631771898472869943605905251639825114963177189847286994360590525163982511496317718984728699436059052516398251149631771898472869943605905251639825114963177189847286994360590525163982511496317718984728699436059052516398251149631771898472869943605905251639825114963177189 +print("%.5f" % x) diff --git a/tests/float 2/float2int_doubleprec_intbig.py b/tests/float 2/float2int_doubleprec_intbig.py new file mode 100644 index 0000000000..de2137d66c --- /dev/null +++ b/tests/float 2/float2int_doubleprec_intbig.py @@ -0,0 +1,100 @@ +# check cases converting float to int, requiring double precision float + +try: + import ustruct as struct +except: + import struct + +import sys +maxsize_bits = 0 +maxsize = sys.maxsize +while maxsize: + maxsize >>= 1 + maxsize_bits += 1 + +# work out configuration values +is_64bit = maxsize_bits > 32 +# 0 = none, 1 = long long, 2 = mpz +ll_type = None +if is_64bit: + if maxsize_bits < 63: + ll_type = 0 +else: + if maxsize_bits < 31: + ll_type = 0 +if ll_type is None: + one = 1 + if one << 65 < one << 62: + ll_type = 1 + else: + ll_type = 2 + +# This case occurs with time.time() values +if ll_type != 0: + print(int(1418774543.)) + print("%d" % 1418774543.) + if ll_type == 3: + print(int(2.**100)) + print("%d" % 2.**100) +else: + print(int(1073741823.)) + print("%d" % 1073741823.) + +testpass = True +p2_rng = ((30,63,1024),(62,63,1024))[is_64bit][ll_type] +for i in range(0,p2_rng): + bitcnt = len(bin(int(2.**i))) - 3; + if i != bitcnt: + print('fail: 2**%u was %u bits long' % (i, bitcnt)); + testpass = False +print("power of 2 test: %s" % (testpass and 'passed' or 'failed')) + +testpass = True +p10_rng = ((9,18,23),(18,18,23))[is_64bit][ll_type] +for i in range(0,p10_rng): + digcnt = len(str(int(10.**i))) - 1; + if i != digcnt: + print('fail: 10**%u was %u digits long' % (i, digcnt)); + testpass = False +print("power of 10 test: %s" % (testpass and 'passed' or 'failed')) + +def fp2int_test(num, name, should_fail): + try: + x = int(num) + passed = ~should_fail + except: + passed = should_fail + print('%s: %s' % (name, passed and 'passed' or 'failed')) + +if ll_type != 2: + if ll_type == 0: + if is_64bit: + neg_bad_fp = -1.00000005*2.**62. + pos_bad_fp = 2.**62. + neg_good_fp = -2.**62. + pos_good_fp = 0.99999993*2.**62. + else: + neg_bad_fp = -1.00000005*2.**30. + pos_bad_fp = 2.**30. + neg_good_fp = -2.**30. + pos_good_fp = 0.9999999499*2.**30. + else: + neg_bad_fp = -0.51*2.**64. + pos_bad_fp = 2.**63. + neg_good_fp = -2.**63. + pos_good_fp = 1.9999998*2.**62. + + fp2int_test(neg_bad_fp, 'neg bad', True) + fp2int_test(pos_bad_fp, 'pos bad', True) + fp2int_test(neg_good_fp, 'neg good', False) + fp2int_test(pos_good_fp, 'pos good', False) +else: + fp2int_test(-1.9999999999999981*2.**1023., 'large neg', False) + fp2int_test(1.9999999999999981*2.**1023., 'large pos', False) + +fp2int_test(float('inf'), 'inf test', True) +fp2int_test(float('nan'), 'NaN test', True) + +# test numbers < 1 (this used to fail; see issue #1044) +fp2int_test(0.0001, 'small num', False) +struct.pack('I', int(1/2)) diff --git a/tests/float 2/float2int_fp30_intbig.py b/tests/float 2/float2int_fp30_intbig.py new file mode 100644 index 0000000000..fbb94a4ccc --- /dev/null +++ b/tests/float 2/float2int_fp30_intbig.py @@ -0,0 +1,97 @@ +# check cases converting float to int, relying only on single precision float + +try: + import ustruct as struct +except: + import struct + +import sys +maxsize_bits = 0 +maxsize = sys.maxsize +while maxsize: + maxsize >>= 1 + maxsize_bits += 1 + +# work out configuration values +is_64bit = maxsize_bits > 32 +# 0 = none, 1 = long long, 2 = mpz +ll_type = None +if is_64bit: + if maxsize_bits < 63: + ll_type = 0 +else: + if maxsize_bits < 31: + ll_type = 0 +if ll_type is None: + one = 1 + if one << 65 < one << 62: + ll_type = 1 + else: + ll_type = 2 + +# basic conversion +print(int(14187744.)) +print("%d" % 14187744.) +if ll_type == 2: + print(int(2.**100)) + print("%d" % 2.**100) + +testpass = True +p2_rng = ((30,63,127),(62,63,127))[is_64bit][ll_type] +for i in range(0,p2_rng): + bitcnt = len(bin(int(2.**i))) - 3; + if i != bitcnt: + print('fail: 2.**%u was %u bits long' % (i, bitcnt)); + testpass = False +print("power of 2 test: %s" % (testpass and 'passed' or 'failed')) + +# TODO why does 10**12 fail this test for single precision float? +testpass = True +p10_rng = 9 +for i in range(0,p10_rng): + digcnt = len(str(int(10.**i))) - 1; + if i != digcnt: + print('fail: 10.**%u was %u digits long' % (i, digcnt)); + testpass = False +print("power of 10 test: %s" % (testpass and 'passed' or 'failed')) + +def fp2int_test(num, name, should_fail): + try: + x = int(num) + passed = ~should_fail + except: + passed = should_fail + print('%s: %s' % (name, passed and 'passed' or 'failed')) + +if ll_type != 2: + if ll_type == 0: + if is_64bit: + neg_bad_fp = -1.00000005*2.**62. + pos_bad_fp = 2.**62. + neg_good_fp = -2.**62. + pos_good_fp = 0.99999993*2.**62. + else: + neg_bad_fp = -1.00000005*2.**30. + pos_bad_fp = 2.**30. + neg_good_fp = -2.**30. + pos_good_fp = 0.9999999499*2.**30. + else: + neg_bad_fp = -0.51*2.**64. + pos_bad_fp = 2.**63. + neg_good_fp = -2.**63. + pos_good_fp = 1.9999998*2.**62. + + fp2int_test(neg_bad_fp, 'neg bad', True) + fp2int_test(pos_bad_fp, 'pos bad', True) + fp2int_test(neg_good_fp, 'neg good', False) + fp2int_test(pos_good_fp, 'pos good', False) +else: + fp2int_test(-1.999999879*2.**126., 'large neg', False) + fp2int_test(1.999999879*2.**126., 'large pos', False) + +fp2int_test(float('inf'), 'inf test', True) +fp2int_test(float('nan'), 'NaN test', True) + +# test numbers < 1 (this used to fail; see issue #1044) +fp2int_test(0.0001, 'small num', False) +struct.pack('I', int(1/2)) diff --git a/tests/float 2/float2int_intbig.py b/tests/float 2/float2int_intbig.py new file mode 100644 index 0000000000..3596d2f73d --- /dev/null +++ b/tests/float 2/float2int_intbig.py @@ -0,0 +1,99 @@ +# check cases converting float to int, relying only on single precision float + +try: + import ustruct as struct +except: + import struct + +import sys + +maxsize_bits = 0 +maxsize = sys.maxsize +while maxsize: + maxsize >>= 1 + maxsize_bits += 1 + +# work out configuration values +is_64bit = maxsize_bits > 32 +# 0 = none, 1 = long long, 2 = mpz +ll_type = None +if is_64bit: + if maxsize_bits < 63: + ll_type = 0 +else: + if maxsize_bits < 31: + ll_type = 0 +if ll_type is None: + one = 1 + if one << 65 < one << 62: + ll_type = 1 + else: + ll_type = 2 + + +# basic conversion +print(int(14187745.)) +print("%d" % 14187745.) +if ll_type == 2: + print(int(2.**100)) + print("%d" % 2.**100) + +testpass = True +p2_rng = ((30,63,127),(62,63,127))[is_64bit][ll_type] +for i in range(0,p2_rng): + bitcnt = len(bin(int(2.**i))) - 3; + if i != bitcnt: + print('fail: 2.**%u was %u bits long' % (i, bitcnt)); + testpass = False +print("power of 2 test: %s" % (testpass and 'passed' or 'failed')) + +# TODO why does 10**12 fail this test for single precision float? +testpass = True +p10_rng = 9 if (ll_type == 0 and ~is_64bit) else 11 +for i in range(0,p10_rng): + digcnt = len(str(int(10.**i))) - 1; + if i != digcnt: + print('fail: 10.**%u was %u digits long' % (i, digcnt)); + testpass = False +print("power of 10 test: %s" % (testpass and 'passed' or 'failed')) + +def fp2int_test(num, name, should_fail): + try: + x = int(num) + passed = ~should_fail + except: + passed = should_fail + print('%s: %s' % (name, passed and 'passed' or 'failed')) + +if ll_type != 2: + if ll_type == 0: + if is_64bit: + neg_bad_fp = -1.00000005*2.**62. + pos_bad_fp = 2.**62. + neg_good_fp = -2.**62. + pos_good_fp = 0.99999993*2.**62. + else: + neg_bad_fp = -1.00000005*2.**30. + pos_bad_fp = 2.**30. + neg_good_fp = -2.**30. + pos_good_fp = 0.9999999499*2.**30. + else: + neg_bad_fp = -0.51*2.**64. + pos_bad_fp = 2.**63. + neg_good_fp = -2.**63. + pos_good_fp = 1.9999998*2.**62. + + fp2int_test(neg_bad_fp, 'neg bad', True) + fp2int_test(pos_bad_fp, 'pos bad', True) + fp2int_test(neg_good_fp, 'neg good', False) + fp2int_test(pos_good_fp, 'pos good', False) +else: + fp2int_test(-1.999999879*2.**127., 'large neg', False) + fp2int_test(1.999999879*2.**127., 'large pos', False) + +fp2int_test(float('inf'), 'inf test', True) +fp2int_test(float('nan'), 'NaN test', True) + +# test numbers < 1 (this used to fail; see issue #1044) +fp2int_test(0.0001, 'small num', False) +struct.pack('I', int(1/2)) diff --git a/tests/float 2/float_array.py b/tests/float 2/float_array.py new file mode 100644 index 0000000000..8c8edcff7c --- /dev/null +++ b/tests/float 2/float_array.py @@ -0,0 +1,20 @@ +try: + from array import array +except ImportError: + print("SKIP") + raise SystemExit + +def test(a): + print(a) + a.append(1.2) + print(len(a), '%.3f' % a[0]) + a.append(1) + a.append(False) + print(len(a), '%.3f %.3f' % (a[1], a[2])) + a[-1] = 3.45 + print('%.3f' % a[-1]) + +test(array('f')) +test(array('d')) + +print('{:.4f}'.format(array('f', b'\xcc\xcc\xcc=')[0])) diff --git a/tests/float 2/float_compare.py b/tests/float 2/float_compare.py new file mode 100644 index 0000000000..105923ac73 --- /dev/null +++ b/tests/float 2/float_compare.py @@ -0,0 +1,22 @@ +# Extended float comparisons + +class Foo: + pass + +foo = Foo() + +print(foo == 1.0) +print(1.0 == foo) +print(1.0 == Foo) +print(1.0 == []) +print(1.0 == {}) + +try: + print(foo < 1.0) +except TypeError: + print("TypeError") + +try: + print(1.0 < foo) +except TypeError: + print("TypeError") diff --git a/tests/float 2/float_divmod.py b/tests/float 2/float_divmod.py new file mode 100644 index 0000000000..8e7cd435a5 --- /dev/null +++ b/tests/float 2/float_divmod.py @@ -0,0 +1,25 @@ +# test floating point floor divide and modulus +# it has some tricky corner cases + +def test(x, y): + div, mod = divmod(x, y) + print('%.8f %.8f %.8f %.8f' % (x // y, x % y, div, mod)) + print(div == x // y, mod == x % y, abs(div * y + mod - x) < 1e-15) + +test(1.23456, 0.7) +test(-1.23456, 0.7) +test(1.23456, -0.7) +test(-1.23456, -0.7) + +a = 1.23456 +b = 0.7 +test(a, b) +test(a, -b) +test(-a, b) +test(-a, -b) + +for i in range(25): + x = (i - 12.5) / 6 + for j in range(25): + y = (j - 12.5) / 6 + test(x, y) diff --git a/tests/float 2/float_divmod_relaxed.py b/tests/float 2/float_divmod_relaxed.py new file mode 100644 index 0000000000..a9450fa2c4 --- /dev/null +++ b/tests/float 2/float_divmod_relaxed.py @@ -0,0 +1,33 @@ +# test floating point floor divide and modulus +# it has some tricky corner cases + +# pyboard has 32-bit floating point and gives different (but still +# correct) answers for certain combinations of divmod arguments. + +def test(x, y): + div, mod = divmod(x, y) + print(div == x // y, mod == x % y, abs(div * y + mod - x) < 1e-6) + +test(1.23456, 0.7) +test(-1.23456, 0.7) +test(1.23456, -0.7) +test(-1.23456, -0.7) + +a = 1.23456 +b = 0.7 +test(a, b) +test(a, -b) +test(-a, b) +test(-a, -b) + +for i in range(25): + x = (i - 12.5) / 6 + for j in range(25): + y = (j - 12.5) / 6 + test(x, y) + +# test division by zero error +try: + divmod(1.0, 0) +except ZeroDivisionError: + print('ZeroDivisionError') diff --git a/tests/float 2/float_format.py b/tests/float 2/float_format.py new file mode 100644 index 0000000000..d43535cf2f --- /dev/null +++ b/tests/float 2/float_format.py @@ -0,0 +1,19 @@ +# test float formatting + +# general rounding +for val in (116, 1111, 1234, 5010, 11111): + print('%.0f' % val) + print('%.1f' % val) + print('%.3f' % val) + +# make sure rounding is done at the correct precision +for prec in range(8): + print(('%%.%df' % prec) % 6e-5) + +# check certain cases that had a digit value of 10 render as a ":" character +print('%.2e' % float('9' * 51 + 'e-39')) +print('%.2e' % float('9' * 40 + 'e-21')) + +# check a case that would render negative digit values, eg ")" characters +# the string is converted back to a float to check for no illegal characters +float('%.23e' % 1e-80) diff --git a/tests/float 2/float_parse.py b/tests/float 2/float_parse.py new file mode 100644 index 0000000000..4b026de1c8 --- /dev/null +++ b/tests/float 2/float_parse.py @@ -0,0 +1,32 @@ +# test parsing of floats + +inf = float('inf') + +# it shouldn't matter where the decimal point is if the exponent balances the value +print(float('1234') - float('0.1234e4')) +print(float('1.015625') - float('1015625e-6')) + +# very large integer part with a very negative exponent should cancel out +print('%.4e' % float('9' * 60 + 'e-60')) +print('%.4e' % float('9' * 60 + 'e-40')) + +# many fractional digits +print(float('.' + '9' * 70)) +print(float('.' + '9' * 70 + 'e20')) +print(float('.' + '9' * 70 + 'e-50') == float('1e-50')) + +# tiny fraction with large exponent +print(float('.' + '0' * 60 + '1e10') == float('1e-51')) +print(float('.' + '0' * 60 + '9e25') == float('9e-36')) +print(float('.' + '0' * 60 + '9e40') == float('9e-21')) + +# ensure that accuracy is retained when value is close to a subnormal +print(float('1.00000000000000000000e-37')) +print(float('10.0000000000000000000e-38')) +print(float('100.000000000000000000e-39')) + +# very large exponent literal +print(float('1e4294967301')) +print(float('1e-4294967301')) +print(float('1e18446744073709551621')) +print(float('1e-18446744073709551621')) diff --git a/tests/float 2/float_parse_doubleprec.py b/tests/float 2/float_parse_doubleprec.py new file mode 100644 index 0000000000..dcc0dd5921 --- /dev/null +++ b/tests/float 2/float_parse_doubleprec.py @@ -0,0 +1,21 @@ +# test parsing of floats, requiring double-precision + +# very large integer part with a very negative exponent should cancel out +print(float('9' * 400 + 'e-100')) +print(float('9' * 400 + 'e-200')) +print(float('9' * 400 + 'e-400')) + +# many fractional digits +print(float('.' + '9' * 400)) +print(float('.' + '9' * 400 + 'e100')) +print(float('.' + '9' * 400 + 'e-100')) + +# tiny fraction with large exponent +print('%.14e' % float('.' + '0' * 400 + '9e100')) +print('%.14e' % float('.' + '0' * 400 + '9e200')) +print('%.14e' % float('.' + '0' * 400 + '9e400')) + +# ensure that accuracy is retained when value is close to a subnormal +print(float('1.00000000000000000000e-307')) +print(float('10.0000000000000000000e-308')) +print(float('100.000000000000000000e-309')) diff --git a/tests/float 2/float_struct.py b/tests/float 2/float_struct.py new file mode 100644 index 0000000000..dd7a418ad5 --- /dev/null +++ b/tests/float 2/float_struct.py @@ -0,0 +1,17 @@ +# test struct package with floats +try: + try: + import ustruct as struct + except: + import struct +except ImportError: + print("SKIP") + raise SystemExit + +i = 1. + 1/2 +# TODO: it looks like '=' format modifier is not yet supported +# for fmt in ('f', 'd', '>f', '>d', 'f', '>d', '' + fmt.format(*args) + '<') + +test("{:10.4}", 123.456) +test("{:10.4e}", 123.456) +test("{:10.4e}", -123.456) +test("{:10.4f}", 123.456) +test("{:10.4f}", -123.456) +test("{:10.4g}", 123.456) +test("{:10.4g}", -123.456) +test("{:10.4n}", 123.456) +test("{:e}", 100) +test("{:f}", 200) +test("{:g}", 300) + +test("{:10.4E}", 123.456) +test("{:10.4E}", -123.456) +test("{:10.4F}", 123.456) +test("{:10.4F}", -123.456) +test("{:10.4G}", 123.456) +test("{:10.4G}", -123.456) + +test("{:06e}", float("inf")) +test("{:06e}", float("-inf")) +test("{:06e}", float("nan")) + +# The following fails right now +#test("{:10.1}", 0.0) + +print("%.0f" % (1.750000 % 0.08333333333)) +# Below isn't compatible with single-precision float +#print("%.1f" % (1.750000 % 0.08333333333)) +#print("%.2f" % (1.750000 % 0.08333333333)) +#print("%.12f" % (1.750000 % 0.08333333333)) + +# tests for errors in format string + +try: + '{:10.1b}'.format(0.0) +except ValueError: + print('ValueError') diff --git a/tests/float 2/string_format2.py b/tests/float 2/string_format2.py new file mode 100644 index 0000000000..269023e7ff --- /dev/null +++ b/tests/float 2/string_format2.py @@ -0,0 +1,106 @@ +# Change the following to True to get a much more comprehensive set of tests +# to run, albeit, which take considerably longer. + +full_tests = False + +def test(fmt, *args): + print('{:8s}'.format(fmt) + '>' + fmt.format(*args) + '<') + +def test_fmt(conv, fill, alignment, sign, prefix, width, precision, type, arg): + fmt = '{' + if conv: + fmt += '!' + fmt += conv + fmt += ':' + if alignment: + fmt += fill + fmt += alignment + fmt += sign + fmt += prefix + fmt += width + if precision: + fmt += '.' + fmt += precision + fmt += type + fmt += '}' + test(fmt, arg) + if fill == '0' and alignment == '=': + fmt = '{:' + fmt += sign + fmt += prefix + fmt += width + if precision: + fmt += '.' + fmt += precision + fmt += type + fmt += '}' + test(fmt, arg) + +eg_nums = (0.0, -0.0, 0.1, 1.234, 12.3459, 1.23456789, 123456789.0, -0.0, + -0.1, -1.234, -12.3459, 1e4, 1e-4, 1e5, 1e-5, 1e6, 1e-6, 1e10, + 1e37, -1e37, 1e-37, -1e-37, + 1.23456e8, 1.23456e7, 1.23456e6, 1.23456e5, 1.23456e4, 1.23456e3, 1.23456e2, 1.23456e1, 1.23456e0, + 1.23456e-1, 1.23456e-2, 1.23456e-3, 1.23456e-4, 1.23456e-5, 1.23456e-6, 1.23456e-7, 1.23456e-8, + -1.23456e8, -1.23456e7, -1.23456e6, -1.23456e5, -1.23456e4, -1.23456e3, -1.23456e2, -1.23456e1, -1.23456e0, + -1.23456e-1, -1.23456e-2, -1.23456e-3, -1.23456e-4, -1.23456e-5, -1.23456e-6, -1.23456e-7, -1.23456e-8) + +if full_tests: + for type in ('e', 'E', 'g', 'G', 'n'): + for width in ('', '4', '6', '8', '10'): + for alignment in ('', '<', '>', '=', '^'): + for fill in ('', '@', '0', ' '): + for sign in ('', '+', '-', ' '): + for prec in ('', '1', '3', '6'): + for num in eg_nums: + test_fmt('', fill, alignment, sign, '', width, prec, type, num) + +# Note: We use 1.23459 rather than 1.2345 because '{:3f}'.format(1.2345) +# rounds differently than print("%.3f", 1.2345); + +f_nums = (0.0, -0.0, 0.0001, 0.001, 0.01, 0.1, 1.0, 10.0, + 0.0012, 0.0123, 0.1234, 1.23459, 12.3456, + -0.0001, -0.001, -0.01, -0.1, -1.0, -10.0, + -0.0012, -0.0123, -0.1234, -1.23459, -12.3456) + +if full_tests: + for type in ('f', 'F'): + for width in ('', '4', '6', '8', '10'): + for alignment in ('', '<', '>', '=', '^'): + for fill in ('', ' ', '0', '@'): + for sign in ('', '+', '-', ' '): + # An empty precision defaults to 6, but when uPy is + # configured to use a float, we can only use a + # precision of 6 with numbers less than 10 and still + # get results that compare to CPython (which uses + # long doubles). + for prec in ('1', '2', '3'): + for num in f_nums: + test_fmt('', fill, alignment, sign, '', width, prec, type, num) + for num in int_nums2: + test_fmt('', fill, alignment, sign, '', width, '', type, num) + +pct_nums1 = (0.1, 0.58, 0.99, -0.1, -0.58, -0.99) +pct_nums2 = (True, False, 1, 0, -1) + +if full_tests: + type = '%' + for width in ('', '4', '6', '8', '10'): + for alignment in ('', '<', '>', '=', '^'): + for fill in ('', ' ', '0', '@'): + for sign in ('', '+', '-', ' '): + # An empty precision defaults to 6, but when uPy is + # configured to use a float, we can only use a + # precision of 6 with numbers less than 10 and still + # get results that compare to CPython (which uses + # long doubles). + for prec in ('1', '2', '3'): + for num in pct_nums1: + test_fmt('', fill, alignment, sign, '', width, prec, type, num) + for num in pct_nums2: + test_fmt('', fill, alignment, sign, '', width, '', type, num) +else: + for num in pct_nums1: + test_fmt('', '', '', '', '', '', '1', '%', num) + +# We don't currently test a type of '' with floats (see the detailed comment +# in objstr.c) diff --git a/tests/float 2/string_format_fp30.py b/tests/float 2/string_format_fp30.py new file mode 100644 index 0000000000..77b2a52885 --- /dev/null +++ b/tests/float 2/string_format_fp30.py @@ -0,0 +1,41 @@ +def test(fmt, *args): + print('{:8s}'.format(fmt) + '>' + fmt.format(*args) + '<') + +test("{:10.4}", 123.456) +test("{:10.4e}", 123.456) +test("{:10.4e}", -123.456) +#test("{:10.4f}", 123.456) +#test("{:10.4f}", -123.456) +test("{:10.4g}", 123.456) +test("{:10.4g}", -123.456) +test("{:10.4n}", 123.456) +test("{:e}", 100) +test("{:f}", 200) +test("{:g}", 300) + +test("{:10.4E}", 123.456) +test("{:10.4E}", -123.456) +#test("{:10.4F}", 123.456) +#test("{:10.4F}", -123.456) +test("{:10.4G}", 123.456) +test("{:10.4G}", -123.456) + +test("{:06e}", float("inf")) +test("{:06e}", float("-inf")) +test("{:06e}", float("nan")) + +# The following fails right now +#test("{:10.1}", 0.0) + +print("%.0f" % (1.750000 % 0.08333333333)) +# Below isn't compatible with single-precision float +#print("%.1f" % (1.750000 % 0.08333333333)) +#print("%.2f" % (1.750000 % 0.08333333333)) +#print("%.12f" % (1.750000 % 0.08333333333)) + +# tests for errors in format string + +try: + '{:10.1b}'.format(0.0) +except ValueError: + print('ValueError') diff --git a/tests/float 2/string_format_modulo.py b/tests/float 2/string_format_modulo.py new file mode 100644 index 0000000000..aea534247c --- /dev/null +++ b/tests/float 2/string_format_modulo.py @@ -0,0 +1,49 @@ +print("%s" % 1.0) +print("%r" % 1.0) + +print("%d" % 1.0) +print("%i" % 1.0) +print("%u" % 1.0) + +# these 3 have different behaviour in Python 3.x versions +# uPy raises a TypeError, following Python 3.5 (earlier versions don't) +#print("%x" % 18.0) +#print("%o" % 18.0) +#print("%X" % 18.0) + +print("%e" % 1.23456) +print("%E" % 1.23456) +print("%f" % 1.23456) +print("%F" % 1.23456) +print("%g" % 1.23456) +print("%G" % 1.23456) + +print("%06e" % float("inf")) +print("%06e" % float("-inf")) +print("%06e" % float("nan")) + +print("%02.3d" % 123) # prec > width +print("%+f %+f" % (1.23, -1.23)) # float sign +print("% f % f" % (1.23, -1.23)) # float space sign +print("%0f" % -1.23) # negative number with 0 padding + +# numbers with large negative exponents +print('%f' % 1e-10) +print('%f' % 1e-20) +print('%f' % 1e-50) +print('%f' % 1e-100) +print('%f' % 1e-300) + +# large decimal precision should be truncated and not overflow buffer +# the output depends on the FP calculation so only first 2 digits are printed +# (the 'g' with small e are printed using 'f' style, so need to be checked) +print(('%.40f' % 1e-300)[:2]) +print(('%.40g' % 1e-1)[:2]) +print(('%.40g' % 1e-2)[:2]) +print(('%.40g' % 1e-3)[:2]) +print(('%.40g' % 1e-4)[:2]) + +print("%.0g" % 1) # 0 precision 'g' + +print('%.1e' % 9.99) # round up with positive exponent +print('%.1e' % 0.999) # round up with negative exponent diff --git a/tests/float 2/string_format_modulo2.py b/tests/float 2/string_format_modulo2.py new file mode 100644 index 0000000000..f6b1ae537d --- /dev/null +++ b/tests/float 2/string_format_modulo2.py @@ -0,0 +1,24 @@ +# test formatting floats with large precision, that it doesn't overflow the buffer + +def test(num, num_str): + if num == float('inf') or num == 0.0 and num_str != '0.0': + # skip numbers that overflow or underflow the FP precision + return + for kind in ('e', 'f', 'g'): + # check precision either side of the size of the buffer (32 bytes) + for prec in range(23, 36, 2): + fmt = '%.' + '%d' % prec + kind + s = fmt % num + check = abs(float(s) - num) + if num > 1: + check /= num + if check > 1e-6: + print('FAIL', num_str, fmt, s, len(s), check) + +# check pure zero +test(0.0, '0.0') + +# check some powers of 10, making sure to include exponents with 3 digits +for e in range(-8, 8): + num = pow(10, e) + test(num, '1e%d' % e) diff --git a/tests/float 2/string_format_modulo2_intbig.py b/tests/float 2/string_format_modulo2_intbig.py new file mode 100644 index 0000000000..9992ba65d9 --- /dev/null +++ b/tests/float 2/string_format_modulo2_intbig.py @@ -0,0 +1,21 @@ +# test formatting floats with large precision, that it doesn't overflow the buffer + +def test(num, num_str): + if num == float('inf') or num == 0.0 and num_str != '0.0': + # skip numbers that overflow or underflow the FP precision + return + for kind in ('e', 'f', 'g'): + # check precision either side of the size of the buffer (32 bytes) + for prec in range(23, 36, 2): + fmt = '%.' + '%d' % prec + kind + s = fmt % num + check = abs(float(s) - num) + if num > 1: + check /= num + if check > 1e-6: + print('FAIL', num_str, fmt, s, len(s), check) + +# check most powers of 10, making sure to include exponents with 3 digits +for e in range(-101, 102): + num = pow(10, e) + test(num, '1e%d' % e) diff --git a/tests/float 2/string_format_modulo3.py b/tests/float 2/string_format_modulo3.py new file mode 100644 index 0000000000..5d26f25751 --- /dev/null +++ b/tests/float 2/string_format_modulo3.py @@ -0,0 +1,3 @@ +# uPy and CPython outputs differ for the following +print("%.1g" % -9.9) # round up 'g' with '-' sign +print("%.2g" % 99.9) # round up diff --git a/tests/float 2/string_format_modulo3.py.exp b/tests/float 2/string_format_modulo3.py.exp new file mode 100644 index 0000000000..71432b3404 --- /dev/null +++ b/tests/float 2/string_format_modulo3.py.exp @@ -0,0 +1,2 @@ +-10 +100 diff --git a/tests/float 2/true_value.py b/tests/float 2/true_value.py new file mode 100644 index 0000000000..df415f0031 --- /dev/null +++ b/tests/float 2/true_value.py @@ -0,0 +1,7 @@ +# Test true-ish value handling + +if not 0.0: + print("float 0") + +if not 0+0j: + print("complex 0") diff --git a/tests/float 2/types.py b/tests/float 2/types.py new file mode 100644 index 0000000000..75674c9246 --- /dev/null +++ b/tests/float 2/types.py @@ -0,0 +1,17 @@ +# float types + +print(float) +print(complex) + +print(type(float()) == float) +print(type(complex()) == complex) + +print(type(0.0) == float) +print(type(1j) == complex) + +# hashing float types + +d = dict() +d[float] = complex +d[complex] = float +print(len(d)) diff --git a/tests/inlineasm 2/asmargs.py b/tests/inlineasm 2/asmargs.py new file mode 100644 index 0000000000..047d9ed420 --- /dev/null +++ b/tests/inlineasm 2/asmargs.py @@ -0,0 +1,29 @@ +# test passing arguments + +@micropython.asm_thumb +def arg0(): + mov(r0, 1) +print(arg0()) + +@micropython.asm_thumb +def arg1(r0): + add(r0, r0, 1) +print(arg1(1)) + +@micropython.asm_thumb +def arg2(r0, r1): + add(r0, r0, r1) +print(arg2(1, 2)) + +@micropython.asm_thumb +def arg3(r0, r1, r2): + add(r0, r0, r1) + add(r0, r0, r2) +print(arg3(1, 2, 3)) + +@micropython.asm_thumb +def arg4(r0, r1, r2, r3): + add(r0, r0, r1) + add(r0, r0, r2) + add(r0, r0, r3) +print(arg4(1, 2, 3, 4)) diff --git a/tests/inlineasm 2/asmargs.py.exp b/tests/inlineasm 2/asmargs.py.exp new file mode 100644 index 0000000000..e33a6964f4 --- /dev/null +++ b/tests/inlineasm 2/asmargs.py.exp @@ -0,0 +1,5 @@ +1 +2 +3 +6 +10 diff --git a/tests/inlineasm 2/asmbcc.py b/tests/inlineasm 2/asmbcc.py new file mode 100644 index 0000000000..540fa6591f --- /dev/null +++ b/tests/inlineasm 2/asmbcc.py @@ -0,0 +1,27 @@ +# test bcc instructions +# at the moment only tests beq, narrow and wide versions + +@micropython.asm_thumb +def f(r0): + mov(r1, r0) + + mov(r0, 10) + cmp(r1, 1) + beq(end) + + mov(r0, 20) + cmp(r1, 2) + beq_n(end) + + mov(r0, 30) + cmp(r1, 3) + beq_w(end) + + mov(r0, 0) + + label(end) + +print(f(0)) +print(f(1)) +print(f(2)) +print(f(3)) diff --git a/tests/inlineasm 2/asmbcc.py.exp b/tests/inlineasm 2/asmbcc.py.exp new file mode 100644 index 0000000000..39da7d1a99 --- /dev/null +++ b/tests/inlineasm 2/asmbcc.py.exp @@ -0,0 +1,4 @@ +0 +10 +20 +30 diff --git a/tests/inlineasm 2/asmbitops.py b/tests/inlineasm 2/asmbitops.py new file mode 100644 index 0000000000..8cf92b301f --- /dev/null +++ b/tests/inlineasm 2/asmbitops.py @@ -0,0 +1,13 @@ +@micropython.asm_thumb +def clz(r0): + clz(r0, r0) + +print(clz(0xf0)) +print(clz(0x8000)) + +@micropython.asm_thumb +def rbit(r0): + rbit(r0, r0) + +print(hex(rbit(0xf0))) +print(hex(rbit(0x8000))) diff --git a/tests/inlineasm 2/asmbitops.py.exp b/tests/inlineasm 2/asmbitops.py.exp new file mode 100644 index 0000000000..8c560045f4 --- /dev/null +++ b/tests/inlineasm 2/asmbitops.py.exp @@ -0,0 +1,4 @@ +24 +16 +0xf000000 +0x10000 diff --git a/tests/inlineasm 2/asmblbx.py b/tests/inlineasm 2/asmblbx.py new file mode 100644 index 0000000000..d08c0ed6b3 --- /dev/null +++ b/tests/inlineasm 2/asmblbx.py @@ -0,0 +1,21 @@ +# test bl and bx instructions + +@micropython.asm_thumb +def f(r0): + # jump over the internal functions + b(entry) + + label(func1) + add(r0, 2) + bx(lr) + + label(func2) + sub(r0, 1) + bx(lr) + + label(entry) + bl(func1) + bl(func2) + +print(f(0)) +print(f(1)) diff --git a/tests/inlineasm 2/asmblbx.py.exp b/tests/inlineasm 2/asmblbx.py.exp new file mode 100644 index 0000000000..1191247b6d --- /dev/null +++ b/tests/inlineasm 2/asmblbx.py.exp @@ -0,0 +1,2 @@ +1 +2 diff --git a/tests/inlineasm 2/asmconst.py b/tests/inlineasm 2/asmconst.py new file mode 100644 index 0000000000..299a25093c --- /dev/null +++ b/tests/inlineasm 2/asmconst.py @@ -0,0 +1,8 @@ +# test constants in assembler + +@micropython.asm_thumb +def c1(): + movwt(r0, 0xffffffff) + movwt(r1, 0xf0000000) + sub(r0, r0, r1) +print(hex(c1())) diff --git a/tests/inlineasm 2/asmconst.py.exp b/tests/inlineasm 2/asmconst.py.exp new file mode 100644 index 0000000000..3ef9fcabd7 --- /dev/null +++ b/tests/inlineasm 2/asmconst.py.exp @@ -0,0 +1 @@ +0xfffffff diff --git a/tests/inlineasm 2/asmdiv.py b/tests/inlineasm 2/asmdiv.py new file mode 100644 index 0000000000..b97d566eb5 --- /dev/null +++ b/tests/inlineasm 2/asmdiv.py @@ -0,0 +1,16 @@ +@micropython.asm_thumb +def sdiv(r0, r1): + sdiv(r0, r0, r1) + +@micropython.asm_thumb +def udiv(r0, r1): + udiv(r0, r0, r1) + +print(sdiv(1234, 3)) +print(sdiv(-1234, 3)) +print(sdiv(1234, -3)) +print(sdiv(-1234, -3)) + +print(udiv(1234, 3)) +print(udiv(0xffffffff, 0x7fffffff)) +print(udiv(0xffffffff, 0xffffffff)) diff --git a/tests/inlineasm 2/asmdiv.py.exp b/tests/inlineasm 2/asmdiv.py.exp new file mode 100644 index 0000000000..f1b80deb32 --- /dev/null +++ b/tests/inlineasm 2/asmdiv.py.exp @@ -0,0 +1,7 @@ +411 +-411 +-411 +411 +411 +2 +1 diff --git a/tests/inlineasm 2/asmfpaddsub.py b/tests/inlineasm 2/asmfpaddsub.py new file mode 100644 index 0000000000..2bdfccf0e0 --- /dev/null +++ b/tests/inlineasm 2/asmfpaddsub.py @@ -0,0 +1,14 @@ +@micropython.asm_thumb # r0 = r0+r1-r2 +def add_sub(r0, r1, r2): + vmov(s0, r0) + vcvt_f32_s32(s0, s0) + vmov(s1, r1) + vcvt_f32_s32(s1, s1) + vmov(s2, r2) + vcvt_f32_s32(s2, s2) + vadd(s0, s0, s1) + vsub(s0, s0, s2) + vcvt_s32_f32(s31, s0) + vmov(r0, s31) + +print(add_sub(100, 20, 30)) diff --git a/tests/inlineasm 2/asmfpaddsub.py.exp b/tests/inlineasm 2/asmfpaddsub.py.exp new file mode 100644 index 0000000000..d61f00d8ca --- /dev/null +++ b/tests/inlineasm 2/asmfpaddsub.py.exp @@ -0,0 +1 @@ +90 diff --git a/tests/inlineasm 2/asmfpcmp.py b/tests/inlineasm 2/asmfpcmp.py new file mode 100644 index 0000000000..d4fa1f2410 --- /dev/null +++ b/tests/inlineasm 2/asmfpcmp.py @@ -0,0 +1,14 @@ +@micropython.asm_thumb # test vcmp, vmrs +def f(r0, r1): + vmov(s0, r0) + vcvt_f32_s32(s0, s0) + vmov(s1, r1) + vcvt_f32_s32(s1, s1) + vcmp(s1, s0) + vmrs(r0, FPSCR) + mov(r1, 28) + lsr(r0, r1) + +print(f(0,1)) +print(f(1,1)) +print(f(1,0)) diff --git a/tests/inlineasm 2/asmfpcmp.py.exp b/tests/inlineasm 2/asmfpcmp.py.exp new file mode 100644 index 0000000000..104b3580f7 --- /dev/null +++ b/tests/inlineasm 2/asmfpcmp.py.exp @@ -0,0 +1,3 @@ +2 +6 +8 diff --git a/tests/inlineasm 2/asmfpldrstr.py b/tests/inlineasm 2/asmfpldrstr.py new file mode 100644 index 0000000000..4c480671f9 --- /dev/null +++ b/tests/inlineasm 2/asmfpldrstr.py @@ -0,0 +1,11 @@ +import array +@micropython.asm_thumb # test vldr, vstr +def arrayadd(r0): + vldr(s0, [r0, 0]) + vldr(s1, [r0, 4]) + vadd(s2, s0, s1) + vstr(s2, [r0, 8]) + +z = array.array("f", [2, 4, 10]) +arrayadd(z) +print(z[2]) diff --git a/tests/inlineasm 2/asmfpldrstr.py.exp b/tests/inlineasm 2/asmfpldrstr.py.exp new file mode 100644 index 0000000000..e0ea36feef --- /dev/null +++ b/tests/inlineasm 2/asmfpldrstr.py.exp @@ -0,0 +1 @@ +6.0 diff --git a/tests/inlineasm 2/asmfpmuldiv.py b/tests/inlineasm 2/asmfpmuldiv.py new file mode 100644 index 0000000000..043a28e229 --- /dev/null +++ b/tests/inlineasm 2/asmfpmuldiv.py @@ -0,0 +1,14 @@ +@micropython.asm_thumb # r0 = (int)(r0*r1/r2) +def muldiv(r0, r1, r2): + vmov(s0, r0) + vcvt_f32_s32(s0, s0) + vmov(s1, r1) + vcvt_f32_s32(s1, s1) + vmov(s2, r2) + vcvt_f32_s32(s2, s2) + vmul(s7, s0, s1) + vdiv(s8, s7, s2) + vcvt_s32_f32(s31, s8) + vmov(r0, s31) + +print(muldiv(100, 10, 50)) diff --git a/tests/inlineasm 2/asmfpmuldiv.py.exp b/tests/inlineasm 2/asmfpmuldiv.py.exp new file mode 100644 index 0000000000..209e3ef4b6 --- /dev/null +++ b/tests/inlineasm 2/asmfpmuldiv.py.exp @@ -0,0 +1 @@ +20 diff --git a/tests/inlineasm 2/asmfpsqrt.py b/tests/inlineasm 2/asmfpsqrt.py new file mode 100644 index 0000000000..7b7d52e238 --- /dev/null +++ b/tests/inlineasm 2/asmfpsqrt.py @@ -0,0 +1,14 @@ +# test vsqrt, vneg +@micropython.asm_thumb # r0 = -(int)(sqrt(r0)*r1) +def sqrt_test(r0, r1): + vmov(s1, r0) + vcvt_f32_s32(s1, s1) + vsqrt(s1, s1) + vmov(s2, r1) + vcvt_f32_s32(s2, s2) + vmul(s0, s1, s2) + vneg(s7, s0) + vcvt_s32_f32(s31, s7) + vmov(r0, s31) + +print(sqrt_test(256, 10)) diff --git a/tests/inlineasm 2/asmfpsqrt.py.exp b/tests/inlineasm 2/asmfpsqrt.py.exp new file mode 100644 index 0000000000..88a1e93bab --- /dev/null +++ b/tests/inlineasm 2/asmfpsqrt.py.exp @@ -0,0 +1 @@ +-160 diff --git a/tests/inlineasm 2/asmit.py b/tests/inlineasm 2/asmit.py new file mode 100644 index 0000000000..57bfcc7f9a --- /dev/null +++ b/tests/inlineasm 2/asmit.py @@ -0,0 +1,16 @@ +# test it instruction + +@micropython.asm_thumb +def f(r0, r1): + cmp(r0, r1) + it(eq) + mov(r0, 100) +print(f(0, 0), f(1, 2)) + +@micropython.asm_thumb +def g(r0, r1): + cmp(r0, r1) + ite(eq) + mov(r0, 100) + mov(r0, 200) +print(g(0, 0), g(0, 1)) diff --git a/tests/inlineasm 2/asmit.py.exp b/tests/inlineasm 2/asmit.py.exp new file mode 100644 index 0000000000..d06c72d9bb --- /dev/null +++ b/tests/inlineasm 2/asmit.py.exp @@ -0,0 +1,2 @@ +100 1 +100 200 diff --git a/tests/inlineasm 2/asmpushpop.py b/tests/inlineasm 2/asmpushpop.py new file mode 100644 index 0000000000..c9005434ba --- /dev/null +++ b/tests/inlineasm 2/asmpushpop.py @@ -0,0 +1,8 @@ +@micropython.asm_thumb +def f(r0, r1, r2): + push({r0}) + push({r1, r2}) + pop({r0}) + pop({r1, r2}) + +print(f(0, 1, 2)) diff --git a/tests/inlineasm 2/asmpushpop.py.exp b/tests/inlineasm 2/asmpushpop.py.exp new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/inlineasm 2/asmpushpop.py.exp @@ -0,0 +1 @@ +1 diff --git a/tests/inlineasm 2/asmrettype.py b/tests/inlineasm 2/asmrettype.py new file mode 100644 index 0000000000..f1918696ee --- /dev/null +++ b/tests/inlineasm 2/asmrettype.py @@ -0,0 +1,21 @@ +# test return type of inline asm + +@micropython.asm_thumb +def ret_obj(r0) -> object: + pass +ret_obj(print)(1) + +@micropython.asm_thumb +def ret_bool(r0) -> bool: + pass +print(ret_bool(0), ret_bool(1)) + +@micropython.asm_thumb +def ret_int(r0) -> int: + lsl(r0, r0, 29) +print(ret_int(0), hex(ret_int(1)), hex(ret_int(2)), hex(ret_int(4))) + +@micropython.asm_thumb +def ret_uint(r0) -> uint: + lsl(r0, r0, 29) +print(ret_uint(0), hex(ret_uint(1)), hex(ret_uint(2)), hex(ret_uint(4))) diff --git a/tests/inlineasm 2/asmrettype.py.exp b/tests/inlineasm 2/asmrettype.py.exp new file mode 100644 index 0000000000..cbb49d2472 --- /dev/null +++ b/tests/inlineasm 2/asmrettype.py.exp @@ -0,0 +1,4 @@ +1 +False True +0 0x20000000 0x40000000 -0x80000000 +0 0x20000000 0x40000000 0x80000000 diff --git a/tests/inlineasm 2/asmshift.py b/tests/inlineasm 2/asmshift.py new file mode 100644 index 0000000000..0df2187347 --- /dev/null +++ b/tests/inlineasm 2/asmshift.py @@ -0,0 +1,29 @@ +@micropython.asm_thumb +def lsl1(r0): + lsl(r0, r0, 1) +print(hex(lsl1(0x123))) + +@micropython.asm_thumb +def lsl23(r0): + lsl(r0, r0, 23) +print(hex(lsl23(1))) + +@micropython.asm_thumb +def lsr1(r0): + lsr(r0, r0, 1) +print(hex(lsr1(0x123))) + +@micropython.asm_thumb +def lsr31(r0): + lsr(r0, r0, 31) +print(hex(lsr31(0x80000000))) + +@micropython.asm_thumb +def asr1(r0): + asr(r0, r0, 1) +print(hex(asr1(0x123))) + +@micropython.asm_thumb +def asr31(r0): + asr(r0, r0, 31) +print(hex(asr31(0x80000000))) diff --git a/tests/inlineasm 2/asmshift.py.exp b/tests/inlineasm 2/asmshift.py.exp new file mode 100644 index 0000000000..c6c3a72179 --- /dev/null +++ b/tests/inlineasm 2/asmshift.py.exp @@ -0,0 +1,6 @@ +0x246 +0x800000 +0x91 +0x1 +0x91 +-0x1 diff --git a/tests/inlineasm 2/asmspecialregs.py b/tests/inlineasm 2/asmspecialregs.py new file mode 100644 index 0000000000..2d3b0e396f --- /dev/null +++ b/tests/inlineasm 2/asmspecialregs.py @@ -0,0 +1,10 @@ +@micropython.asm_thumb +def getIPSR(): + mrs(r0, IPSR) + +@micropython.asm_thumb +def getBASEPRI(): + mrs(r0, BASEPRI) + +print(getBASEPRI()) +print(getIPSR()) diff --git a/tests/inlineasm 2/asmspecialregs.py.exp b/tests/inlineasm 2/asmspecialregs.py.exp new file mode 100644 index 0000000000..aa47d0d46d --- /dev/null +++ b/tests/inlineasm 2/asmspecialregs.py.exp @@ -0,0 +1,2 @@ +0 +0 diff --git a/tests/inlineasm 2/asmsum.py b/tests/inlineasm 2/asmsum.py new file mode 100644 index 0000000000..07e71c7384 --- /dev/null +++ b/tests/inlineasm 2/asmsum.py @@ -0,0 +1,57 @@ +@micropython.asm_thumb +def asm_sum_words(r0, r1): + + # r0 = len + # r1 = ptr + # r2 = sum + # r3 = dummy + mov(r2, 0) + + b(loop_entry) + + label(loop1) + ldr(r3, [r1, 0]) + add(r2, r2, r3) + + add(r1, r1, 4) + sub(r0, r0, 1) + + label(loop_entry) + cmp(r0, 0) + bgt(loop1) + + mov(r0, r2) + +@micropython.asm_thumb +def asm_sum_bytes(r0, r1): + + # r0 = len + # r1 = ptr + # r2 = sum + # r3 = dummy + mov(r2, 0) + + b(loop_entry) + + label(loop1) + ldrb(r3, [r1, 0]) + add(r2, r2, r3) + + add(r1, r1, 1) + sub(r0, r0, 1) + + label(loop_entry) + cmp(r0, 0) + bgt(loop1) + + mov(r0, r2) + +import array + +b = array.array('l', (100, 200, 300, 400)) +n = asm_sum_words(len(b), b) +print(b, n) + +b = array.array('b', (10, 20, 30, 40, 50, 60, 70, 80)) +n = asm_sum_bytes(len(b), b) +print(b, n) diff --git a/tests/inlineasm 2/asmsum.py.exp b/tests/inlineasm 2/asmsum.py.exp new file mode 100644 index 0000000000..d50a94c8db --- /dev/null +++ b/tests/inlineasm 2/asmsum.py.exp @@ -0,0 +1,2 @@ +array('l', [100, 200, 300, 400]) 1000 +array('b', [10, 20, 30, 40, 50, 60, 70, 80]) 360 diff --git a/tests/io/data/file1 2 b/tests/io/data/file1 2 new file mode 100644 index 0000000000..e08206337f --- /dev/null +++ b/tests/io/data/file1 2 @@ -0,0 +1,3 @@ +longer line1 +line2 +line3 diff --git a/tests/jni 2/README b/tests/jni 2/README new file mode 100644 index 0000000000..a0689e9244 --- /dev/null +++ b/tests/jni 2/README @@ -0,0 +1,11 @@ +Running "jni" module tests (as well as just using this module) requires +being able to load libjvm.so, which requires path to it set via +LD_LIBRARY_PATH environment variable. This path is not set automatically +and there is no easy way to guess it, because there can be installed +different implementations of JVM, for one implementation, there can be +different versions, and single version may include different variants +of JVM. + +For example, for OpenJDK 7 on x86_64, following may work: + +LD_LIBRARY_PATH=/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server ./run-tests jni/*.py diff --git a/tests/jni 2/list.py b/tests/jni 2/list.py new file mode 100644 index 0000000000..d58181d0ba --- /dev/null +++ b/tests/jni 2/list.py @@ -0,0 +1,15 @@ +import jni +try: + ArrayList = jni.cls("java/util/ArrayList") +except: + print("SKIP") + raise SystemExit + +l = ArrayList() +print(l) +l.add("one") +l.add("two") + +print(l.toString()) +print(l) +print(l[0], l[1]) diff --git a/tests/jni 2/list.py.exp b/tests/jni 2/list.py.exp new file mode 100644 index 0000000000..cc34bb0a21 --- /dev/null +++ b/tests/jni 2/list.py.exp @@ -0,0 +1,4 @@ +[] +[one, two] +[one, two] +one two diff --git a/tests/jni 2/object.py b/tests/jni 2/object.py new file mode 100644 index 0000000000..aa67615ec8 --- /dev/null +++ b/tests/jni 2/object.py @@ -0,0 +1,15 @@ +import jni +try: + Integer = jni.cls("java/lang/Integer") +except: + print("SKIP") + raise SystemExit + +# Create object +i = Integer(42) +print(i) +# Call object method +print(i.hashCode()) +# Pass object to another method +System = jni.cls("java/lang/System") +System.out.println(i) diff --git a/tests/jni 2/object.py.exp b/tests/jni 2/object.py.exp new file mode 100644 index 0000000000..bda709ecfb --- /dev/null +++ b/tests/jni 2/object.py.exp @@ -0,0 +1,3 @@ +42 +42 +42 diff --git a/tests/jni 2/system_out.py b/tests/jni 2/system_out.py new file mode 100644 index 0000000000..86c4b9e112 --- /dev/null +++ b/tests/jni 2/system_out.py @@ -0,0 +1,8 @@ +try: + import jni + System = jni.cls("java/lang/System") +except: + print("SKIP") + raise SystemExit + +System.out.println("Hello, Java!") diff --git a/tests/jni 2/system_out.py.exp b/tests/jni 2/system_out.py.exp new file mode 100644 index 0000000000..01dd954f90 --- /dev/null +++ b/tests/jni 2/system_out.py.exp @@ -0,0 +1 @@ +Hello, Java! diff --git a/tests/net_hosted 2/README b/tests/net_hosted 2/README new file mode 100644 index 0000000000..724dd61584 --- /dev/null +++ b/tests/net_hosted 2/README @@ -0,0 +1,11 @@ +This directory contains network tests which require just "peer to peer" +network connection between test host and device under test, instead of +full Internet connection. + +Note that setup for these tests and tests themselves are WIP, and may +not yet fully correspond to the functional specification above. + +So far, these tests are not run as part of the main testsuite and need +to be run seperately (from the main test/ directory): + + ./run-tests net_hosted/*.py diff --git a/tests/net_hosted 2/accept_nonblock.py b/tests/net_hosted 2/accept_nonblock.py new file mode 100644 index 0000000000..56f3288e28 --- /dev/null +++ b/tests/net_hosted 2/accept_nonblock.py @@ -0,0 +1,16 @@ +# test that socket.accept() on a non-blocking socket raises EAGAIN + +try: + import usocket as socket +except: + import socket + +s = socket.socket() +s.bind(socket.getaddrinfo('127.0.0.1', 8123)[0][-1]) +s.setblocking(False) +s.listen(1) +try: + s.accept() +except OSError as er: + print(er.args[0] == 11) # 11 is EAGAIN +s.close() diff --git a/tests/net_hosted 2/accept_nonblock.py.exp b/tests/net_hosted 2/accept_nonblock.py.exp new file mode 100644 index 0000000000..0ca95142bb --- /dev/null +++ b/tests/net_hosted 2/accept_nonblock.py.exp @@ -0,0 +1 @@ +True diff --git a/tests/net_hosted 2/accept_timeout.py b/tests/net_hosted 2/accept_timeout.py new file mode 100644 index 0000000000..44b3b8c7cd --- /dev/null +++ b/tests/net_hosted 2/accept_timeout.py @@ -0,0 +1,22 @@ +# test that socket.accept() on a socket with timeout raises ETIMEDOUT + +try: + import usocket as socket +except: + import socket + +try: + socket.socket.settimeout +except AttributeError: + print('SKIP') + raise SystemExit + +s = socket.socket() +s.bind(socket.getaddrinfo('127.0.0.1', 8123)[0][-1]) +s.settimeout(1) +s.listen(1) +try: + s.accept() +except OSError as er: + print(er.args[0] in (110, 'timed out')) # 110 is ETIMEDOUT; CPython uses a string +s.close() diff --git a/tests/net_hosted 2/accept_timeout.py.exp b/tests/net_hosted 2/accept_timeout.py.exp new file mode 100644 index 0000000000..0ca95142bb --- /dev/null +++ b/tests/net_hosted 2/accept_timeout.py.exp @@ -0,0 +1 @@ +True diff --git a/tests/net_hosted 2/connect_nonblock.py b/tests/net_hosted 2/connect_nonblock.py new file mode 100644 index 0000000000..6479978bea --- /dev/null +++ b/tests/net_hosted 2/connect_nonblock.py @@ -0,0 +1,20 @@ +# test that socket.connect() on a non-blocking socket raises EINPROGRESS + +try: + import usocket as socket +except: + import socket + + +def test(peer_addr): + s = socket.socket() + s.setblocking(False) + try: + s.connect(peer_addr) + except OSError as er: + print(er.args[0] == 115) # 115 is EINPROGRESS + s.close() + + +if __name__ == "__main__": + test(socket.getaddrinfo('micropython.org', 80)[0][-1]) diff --git a/tests/net_hosted 2/connect_nonblock.py.exp b/tests/net_hosted 2/connect_nonblock.py.exp new file mode 100644 index 0000000000..0ca95142bb --- /dev/null +++ b/tests/net_hosted 2/connect_nonblock.py.exp @@ -0,0 +1 @@ +True diff --git a/tests/net_hosted 2/connect_poll.py b/tests/net_hosted 2/connect_poll.py new file mode 100644 index 0000000000..ece6aa0da9 --- /dev/null +++ b/tests/net_hosted 2/connect_poll.py @@ -0,0 +1,32 @@ +# test that socket.connect() has correct polling behaviour before, during and after + +try: + import usocket as socket, uselect as select +except: + import socket, select + + +def test(peer_addr): + s = socket.socket() + poller = select.poll() + poller.register(s) + + # test poll before connect + # note: CPython can return POLLHUP, so use the IN|OUT mask + p = poller.poll(0) + print(len(p), p[0][-1] & (select.POLLIN | select.POLLOUT)) + + s.connect(peer_addr) + + # test poll during connection + print(len(poller.poll(0))) + + # test poll after connection is established + p = poller.poll(1000) + print(len(p), p[0][-1]) + + s.close() + + +if __name__ == "__main__": + test(socket.getaddrinfo('micropython.org', 80)[0][-1]) diff --git a/tests/net_hosted 2/connect_poll.py.exp b/tests/net_hosted 2/connect_poll.py.exp new file mode 100644 index 0000000000..cdf520e090 --- /dev/null +++ b/tests/net_hosted 2/connect_poll.py.exp @@ -0,0 +1,3 @@ +1 4 +1 +1 4 diff --git a/tests/net_hosted 2/ssl_getpeercert.py b/tests/net_hosted 2/ssl_getpeercert.py new file mode 100644 index 0000000000..e265c830d0 --- /dev/null +++ b/tests/net_hosted 2/ssl_getpeercert.py @@ -0,0 +1,21 @@ +# test ssl.getpeercert() method + +try: + import usocket as socket + import ussl as ssl +except: + import socket + import ssl + + +def test(peer_addr): + s = socket.socket() + s.connect(peer_addr) + s = ssl.wrap_socket(s) + cert = s.getpeercert(True) + print(type(cert), len(cert) > 100) + s.close() + + +if __name__ == "__main__": + test(socket.getaddrinfo('micropython.org', 443)[0][-1]) diff --git a/tests/net_hosted 2/ssl_getpeercert.py.exp b/tests/net_hosted 2/ssl_getpeercert.py.exp new file mode 100644 index 0000000000..ff7ef5adf1 --- /dev/null +++ b/tests/net_hosted 2/ssl_getpeercert.py.exp @@ -0,0 +1 @@ + True diff --git a/tests/net_inet 2/README b/tests/net_inet 2/README new file mode 100644 index 0000000000..9a5614efa6 --- /dev/null +++ b/tests/net_inet 2/README @@ -0,0 +1,5 @@ +This directory contains network tests which require Internet connection. +Note that these tests are not run as part of the main testsuite and need +to be run seperately (from the main test/ directory): + + ./run-tests net_inet/*.py diff --git a/tests/net_inet 2/test_tls_sites.py b/tests/net_inet 2/test_tls_sites.py new file mode 100644 index 0000000000..bf8071d087 --- /dev/null +++ b/tests/net_inet 2/test_tls_sites.py @@ -0,0 +1,59 @@ +try: + import usocket as _socket +except: + import _socket +try: + import ussl as ssl +except: + import ssl + # CPython only supports server_hostname with SSLContext + ssl = ssl.SSLContext() + + +def test_one(site, opts): + ai = _socket.getaddrinfo(site, 443) + addr = ai[0][-1] + + s = _socket.socket() + + try: + s.connect(addr) + + if "sni" in opts: + s = ssl.wrap_socket(s, server_hostname=opts["host"]) + else: + s = ssl.wrap_socket(s) + + s.write(b"GET / HTTP/1.0\r\nHost: %s\r\n\r\n" % bytes(site, 'latin')) + resp = s.read(4096) +# print(resp) + + finally: + s.close() + + +SITES = [ + "google.com", + "www.google.com", + "api.telegram.org", + {"host": "api.pushbullet.com", "sni": True}, +# "w9rybpfril.execute-api.ap-southeast-2.amazonaws.com", + {"host": "w9rybpfril.execute-api.ap-southeast-2.amazonaws.com", "sni": True}, +] + + +def main(): + for site in SITES: + opts = {} + if isinstance(site, dict): + opts = site + site = opts["host"] + + try: + test_one(site, opts) + print(site, "ok") + except Exception as e: + print(site, repr(e)) + + +main() diff --git a/tests/net_inet 2/test_tls_sites.py.exp b/tests/net_inet 2/test_tls_sites.py.exp new file mode 100644 index 0000000000..2f3c113d2f --- /dev/null +++ b/tests/net_inet 2/test_tls_sites.py.exp @@ -0,0 +1,5 @@ +google.com ok +www.google.com ok +api.telegram.org ok +api.pushbullet.com ok +w9rybpfril.execute-api.ap-southeast-2.amazonaws.com ok diff --git a/tests/run-bench-tests 2 b/tests/run-bench-tests 2 new file mode 100755 index 0000000000..f4a6776cbc --- /dev/null +++ b/tests/run-bench-tests 2 @@ -0,0 +1,97 @@ +#! /usr/bin/env python3 + +import os +import subprocess +import sys +import argparse +import re +from glob import glob +from collections import defaultdict + +# Tests require at least CPython 3.3. If your default python3 executable +# is of lower version, you can point MICROPY_CPYTHON3 environment var +# to the correct executable. +if os.name == 'nt': + CPYTHON3 = os.getenv('MICROPY_CPYTHON3', 'python3.exe') + MICROPYTHON = os.getenv('MICROPY_MICROPYTHON', '../ports/windows/micropython.exe') +else: + CPYTHON3 = os.getenv('MICROPY_CPYTHON3', 'python3') + MICROPYTHON = os.getenv('MICROPY_MICROPYTHON', '../ports/unix/micropython') + +def run_tests(pyb, test_dict): + test_count = 0 + testcase_count = 0 + + for base_test, tests in sorted(test_dict.items()): + print(base_test + ":") + for test_file in tests: + + # run MicroPython + if pyb is None: + # run on PC + try: + output_mupy = subprocess.check_output([MICROPYTHON, '-X', 'emit=bytecode', test_file[0]]) + except subprocess.CalledProcessError: + output_mupy = b'CRASH' + else: + # run on pyboard + pyb.enter_raw_repl() + try: + output_mupy = pyb.execfile(test_file).replace(b'\r\n', b'\n') + except pyboard.PyboardError: + output_mupy = b'CRASH' + + output_mupy = float(output_mupy.strip()) + test_file[1] = output_mupy + testcase_count += 1 + + test_count += 1 + baseline = None + for t in tests: + if baseline is None: + baseline = t[1] + print(" %.3fs (%+06.2f%%) %s" % (t[1], (t[1] * 100 / baseline) - 100, t[0])) + + print("{} tests performed ({} individual testcases)".format(test_count, testcase_count)) + + # all tests succeeded + return True + +def main(): + cmd_parser = argparse.ArgumentParser(description='Run tests for MicroPython.') + cmd_parser.add_argument('--pyboard', action='store_true', help='run the tests on the pyboard') + cmd_parser.add_argument('files', nargs='*', help='input test files') + args = cmd_parser.parse_args() + + # Note pyboard support is copied over from run-tests, not testes, and likely needs revamping + if args.pyboard: + import pyboard + pyb = pyboard.Pyboard('/dev/ttyACM0') + pyb.enter_raw_repl() + else: + pyb = None + + if len(args.files) == 0: + if pyb is None: + # run PC tests + test_dirs = ('bench',) + else: + # run pyboard tests + test_dirs = ('basics', 'float', 'pyb') + tests = sorted(test_file for test_files in (glob('{}/*.py'.format(dir)) for dir in test_dirs) for test_file in test_files) + else: + # tests explicitly given + tests = sorted(args.files) + + test_dict = defaultdict(lambda: []) + for t in tests: + m = re.match(r"(.+?)-(.+)\.py", t) + if not m: + continue + test_dict[m.group(1)].append([t, None]) + + if not run_tests(pyb, test_dict): + sys.exit(1) + +if __name__ == "__main__": + main() diff --git a/tests/run-tests 2 b/tests/run-tests 2 new file mode 100755 index 0000000000..e28600361b --- /dev/null +++ b/tests/run-tests 2 @@ -0,0 +1,615 @@ +#! /usr/bin/env python3 + +import os +import subprocess +import sys +import platform +import argparse +import re +import threading +import multiprocessing +from multiprocessing.pool import ThreadPool +from glob import glob + +# Tests require at least CPython 3.3. If your default python3 executable +# is of lower version, you can point MICROPY_CPYTHON3 environment var +# to the correct executable. +if os.name == 'nt': + CPYTHON3 = os.getenv('MICROPY_CPYTHON3', 'python3.exe') + MICROPYTHON = os.getenv('MICROPY_MICROPYTHON', '../ports/windows/micropython.exe') +else: + CPYTHON3 = os.getenv('MICROPY_CPYTHON3', 'python3') + MICROPYTHON = os.getenv('MICROPY_MICROPYTHON', '../ports/unix/micropython') + +# mpy-cross is only needed if --via-mpy command-line arg is passed +MPYCROSS = os.getenv('MICROPY_MPYCROSS', '../mpy-cross/mpy-cross') + +# Set PYTHONIOENCODING so that CPython will use utf-8 on systems which set another encoding in the locale +os.environ['PYTHONIOENCODING'] = 'utf-8' + +def rm_f(fname): + if os.path.exists(fname): + os.remove(fname) + + +# unescape wanted regex chars and escape unwanted ones +def convert_regex_escapes(line): + cs = [] + escape = False + for c in str(line, 'utf8'): + if escape: + escape = False + cs.append(c) + elif c == '\\': + escape = True + elif c in ('(', ')', '[', ']', '{', '}', '.', '*', '+', '^', '$'): + cs.append('\\' + c) + else: + cs.append(c) + # accept carriage-return(s) before final newline + if cs[-1] == '\n': + cs[-1] = '\r*\n' + return bytes(''.join(cs), 'utf8') + + +def run_micropython(pyb, args, test_file, is_special=False): + special_tests = ( + 'micropython/meminfo.py', 'basics/bytes_compare3.py', + 'basics/builtin_help.py', 'thread/thread_exc2.py', + ) + had_crash = False + if pyb is None: + # run on PC + if test_file.startswith(('cmdline/', 'feature_check/')) or test_file in special_tests: + # special handling for tests of the unix cmdline program + is_special = True + + if is_special: + # check for any cmdline options needed for this test + args = [MICROPYTHON] + with open(test_file, 'rb') as f: + line = f.readline() + if line.startswith(b'# cmdline:'): + # subprocess.check_output on Windows only accepts strings, not bytes + args += [str(c, 'utf-8') for c in line[10:].strip().split()] + + # run the test, possibly with redirected input + try: + if 'repl_' in test_file: + # Need to use a PTY to test command line editing + try: + import pty + except ImportError: + # in case pty module is not available, like on Windows + return b'SKIP\n' + import select + + def get(required=False): + rv = b'' + while True: + ready = select.select([emulator], [], [], 0.02) + if ready[0] == [emulator]: + rv += os.read(emulator, 1024) + else: + if not required or rv: + return rv + + def send_get(what): + os.write(emulator, what) + return get() + + with open(test_file, 'rb') as f: + # instead of: output_mupy = subprocess.check_output(args, stdin=f) + # openpty returns two read/write file descriptors. The first one is + # used by the program which provides the virtual + # terminal service, and the second one is used by the + # subprogram which requires a tty to work. + emulator, subterminal = pty.openpty() + p = subprocess.Popen(args, stdin=subterminal, stdout=subterminal, + stderr=subprocess.STDOUT, bufsize=0) + banner = get(True) + output_mupy = banner + b''.join(send_get(line) for line in f) + send_get(b'\x04') # exit the REPL, so coverage info is saved + p.kill() + os.close(emulator) + os.close(subterminal) + else: + output_mupy = subprocess.check_output(args + [test_file], stderr=subprocess.STDOUT) + except subprocess.CalledProcessError: + return b'CRASH' + + else: + # a standard test run on PC + + # create system command + cmdlist = [MICROPYTHON, '-X', 'emit=' + args.emit] + if args.heapsize is not None: + cmdlist.extend(['-X', 'heapsize=' + args.heapsize]) + + # if running via .mpy, first compile the .py file + if args.via_mpy: + subprocess.check_output([MPYCROSS, '-mcache-lookup-bc', '-o', 'mpytest.mpy', test_file]) + cmdlist.extend(['-m', 'mpytest']) + else: + cmdlist.append(test_file) + + # run the actual test + e = {"MICROPYPATH": os.getcwd() + ":", "LANG": "en_US.UTF-8"} + p = subprocess.Popen(cmdlist, env=e, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + output_mupy = b'' + while p.poll() is None: + output_mupy += p.stdout.read() + output_mupy += p.stdout.read() + if p.returncode != 0: + output_mupy = b'CRASH' + + # clean up if we had an intermediate .mpy file + if args.via_mpy: + rm_f('mpytest.mpy') + + else: + # run on pyboard + import pyboard + pyb.enter_raw_repl() + try: + output_mupy = pyb.execfile(test_file) + except pyboard.PyboardError: + had_crash = True + output_mupy = b'CRASH' + + # canonical form for all ports/platforms is to use \n for end-of-line + output_mupy = output_mupy.replace(b'\r\n', b'\n') + + # don't try to convert the output if we should skip this test + if had_crash or output_mupy in (b'SKIP\n', b'CRASH'): + return output_mupy + + if is_special or test_file in special_tests: + # convert parts of the output that are not stable across runs + with open(test_file + '.exp', 'rb') as f: + lines_exp = [] + for line in f.readlines(): + if line == b'########\n': + line = (line,) + else: + line = (line, re.compile(convert_regex_escapes(line))) + lines_exp.append(line) + lines_mupy = [line + b'\n' for line in output_mupy.split(b'\n')] + if output_mupy.endswith(b'\n'): + lines_mupy = lines_mupy[:-1] # remove erroneous last empty line + i_mupy = 0 + for i in range(len(lines_exp)): + if lines_exp[i][0] == b'########\n': + # 8x #'s means match 0 or more whole lines + line_exp = lines_exp[i + 1] + skip = 0 + while i_mupy + skip < len(lines_mupy) and not line_exp[1].match(lines_mupy[i_mupy + skip]): + skip += 1 + if i_mupy + skip >= len(lines_mupy): + lines_mupy[i_mupy] = b'######## FAIL\n' + break + del lines_mupy[i_mupy:i_mupy + skip] + lines_mupy.insert(i_mupy, b'########\n') + i_mupy += 1 + else: + # a regex + if lines_exp[i][1].match(lines_mupy[i_mupy]): + lines_mupy[i_mupy] = lines_exp[i][0] + else: + #print("don't match: %r %s" % (lines_exp[i][1], lines_mupy[i_mupy])) # DEBUG + pass + i_mupy += 1 + if i_mupy >= len(lines_mupy): + break + output_mupy = b''.join(lines_mupy) + + return output_mupy + + +def run_feature_check(pyb, args, base_path, test_file): + return run_micropython(pyb, args, base_path + "/feature_check/" + test_file, is_special=True) + +class ThreadSafeCounter: + def __init__(self, start=0): + self._value = start + self._lock = threading.Lock() + + def add(self, to_add): + with self._lock: self._value += to_add + + def append(self, arg): + self.add([arg]) + + @property + def value(self): + return self._value + +def run_tests(pyb, tests, args, base_path=".", num_threads=1): + test_count = ThreadSafeCounter() + testcase_count = ThreadSafeCounter() + passed_count = ThreadSafeCounter() + failed_tests = ThreadSafeCounter([]) + skipped_tests = ThreadSafeCounter([]) + + skip_tests = set() + skip_native = False + skip_int_big = False + skip_set_type = False + skip_async = False + skip_const = False + skip_revops = False + skip_endian = False + has_complex = True + has_coverage = False + + upy_float_precision = 32 + + # If we're asked to --list-tests, we can't assume that there's a + # connection to target, so we can't run feature checks usefully. + if not (args.list_tests or args.write_exp): + # Check if micropython.native is supported, and skip such tests if it's not + output = run_feature_check(pyb, args, base_path, 'native_check.py') + if output == b'CRASH': + skip_native = True + + # Check if arbitrary-precision integers are supported, and skip such tests if it's not + output = run_feature_check(pyb, args, base_path, 'int_big.py') + if output != b'1000000000000000000000000000000000000000000000\n': + skip_int_big = True + + # Check if set type (and set literals) is supported, and skip such tests if it's not + output = run_feature_check(pyb, args, base_path, 'set_check.py') + if output == b'CRASH': + skip_set_type = True + + # Check if async/await keywords are supported, and skip such tests if it's not + output = run_feature_check(pyb, args, base_path, 'async_check.py') + if output == b'CRASH': + skip_async = True + + # Check if const keyword (MicroPython extension) is supported, and skip such tests if it's not + output = run_feature_check(pyb, args, base_path, 'const.py') + if output == b'CRASH': + skip_const = True + + # Check if __rOP__ special methods are supported, and skip such tests if it's not + output = run_feature_check(pyb, args, base_path, 'reverse_ops.py') + if output == b'TypeError\n': + skip_revops = True + + # Check if emacs repl is supported, and skip such tests if it's not + t = run_feature_check(pyb, args, base_path, 'repl_emacs_check.py') + if not 'True' in str(t, 'ascii'): + skip_tests.add('cmdline/repl_emacs_keys.py') + + upy_byteorder = run_feature_check(pyb, args, base_path, 'byteorder.py') + upy_float_precision = int(run_feature_check(pyb, args, base_path, 'float.py')) + has_complex = run_feature_check(pyb, args, base_path, 'complex.py') == b'complex\n' + has_coverage = run_feature_check(pyb, args, base_path, 'coverage.py') == b'coverage\n' + cpy_byteorder = subprocess.check_output([CPYTHON3, base_path + '/feature_check/byteorder.py']) + skip_endian = (upy_byteorder != cpy_byteorder) + + # Some tests shouldn't be run under Travis CI + if os.getenv('TRAVIS') == 'true': + skip_tests.add('basics/memoryerror.py') + skip_tests.add('thread/thread_gc1.py') # has reliability issues + skip_tests.add('thread/thread_lock4.py') # has reliability issues + skip_tests.add('thread/stress_heap.py') # has reliability issues + skip_tests.add('thread/stress_recurse.py') # has reliability issues + + if upy_float_precision == 0: + skip_tests.add('extmod/ujson_dumps_float.py') + skip_tests.add('extmod/ujson_loads_float.py') + skip_tests.add('misc/rge_sm.py') + if upy_float_precision < 32: + skip_tests.add('float/float2int_intbig.py') # requires fp32, there's float2int_fp30_intbig.py instead + skip_tests.add('float/string_format.py') # requires fp32, there's string_format_fp30.py instead + skip_tests.add('float/bytes_construct.py') # requires fp32 + skip_tests.add('float/bytearray_construct.py') # requires fp32 + if upy_float_precision < 64: + skip_tests.add('float/float_divmod.py') # tested by float/float_divmod_relaxed.py instead + skip_tests.add('float/float2int_doubleprec_intbig.py') + skip_tests.add('float/float_parse_doubleprec.py') + + if not has_complex: + skip_tests.add('float/complex1.py') + skip_tests.add('float/complex1_intbig.py') + skip_tests.add('float/int_big_float.py') + skip_tests.add('float/true_value.py') + skip_tests.add('float/types.py') + + if not has_coverage: + skip_tests.add('cmdline/cmd_parsetree.py') + + # Some tests shouldn't be run on a PC + if args.target == 'unix': + # unix build does not have the GIL so can't run thread mutation tests + for t in tests: + if t.startswith('thread/mutate_'): + skip_tests.add(t) + + # Some tests shouldn't be run on pyboard + if args.target != 'unix': + skip_tests.add('basics/exception_chain.py') # warning is not printed + skip_tests.add('micropython/meminfo.py') # output is very different to PC output + skip_tests.add('extmod/machine_mem.py') # raw memory access not supported + + if args.target == 'wipy': + skip_tests.add('misc/print_exception.py') # requires error reporting full + skip_tests.update({'extmod/uctypes_%s.py' % t for t in 'bytearray le native_le ptr_le ptr_native_le sizeof sizeof_native array_assign_le array_assign_native_le'.split()}) # requires uctypes + skip_tests.add('extmod/zlibd_decompress.py') # requires zlib + skip_tests.add('extmod/uheapq1.py') # uheapq not supported by WiPy + skip_tests.add('extmod/urandom_basic.py') # requires urandom + skip_tests.add('extmod/urandom_extra.py') # requires urandom + elif args.target == 'esp8266': + skip_tests.add('misc/rge_sm.py') # too large + elif args.target == 'minimal': + skip_tests.add('basics/class_inplace_op.py') # all special methods not supported + skip_tests.add('basics/subclass_native_init.py')# native subclassing corner cases not support + skip_tests.add('misc/rge_sm.py') # too large + skip_tests.add('micropython/opt_level.py') # don't assume line numbers are stored + + # Some tests are known to fail on 64-bit machines + if pyb is None and platform.architecture()[0] == '64bit': + pass + + # Some tests use unsupported features on Windows + if os.name == 'nt': + skip_tests.add('import/import_file.py') # works but CPython prints forward slashes + + # Some tests are known to fail with native emitter + # Remove them from the below when they work + if args.emit == 'native': + skip_tests.update({'basics/%s.py' % t for t in 'gen_yield_from gen_yield_from_close gen_yield_from_ducktype gen_yield_from_exc gen_yield_from_executing gen_yield_from_iter gen_yield_from_send gen_yield_from_stopped gen_yield_from_throw gen_yield_from_throw2 gen_yield_from_throw3 generator1 generator2 generator_args generator_close generator_closure generator_exc generator_pend_throw generator_return generator_send'.split()}) # require yield + skip_tests.update({'basics/%s.py' % t for t in 'bytes_gen class_store_class globals_del string_join gen_stack_overflow'.split()}) # require yield + skip_tests.update({'basics/async_%s.py' % t for t in 'def await await2 for for2 with with2 coroutine'.split()}) # require yield + skip_tests.update({'basics/%s.py' % t for t in 'try_reraise try_reraise2'.split()}) # require raise_varargs + skip_tests.update({'basics/%s.py' % t for t in 'with_break with_continue with_return'.split()}) # require complete with support + skip_tests.add('basics/array_construct2.py') # requires generators + skip_tests.add('basics/bool1.py') # seems to randomly fail + skip_tests.add('basics/builtin_hash_gen.py') # requires yield + skip_tests.add('basics/class_bind_self.py') # requires yield + skip_tests.add('basics/del_deref.py') # requires checking for unbound local + skip_tests.add('basics/del_local.py') # requires checking for unbound local + skip_tests.add('basics/exception_chain.py') # raise from is not supported + skip_tests.add('basics/for_range.py') # requires yield_value + skip_tests.add('basics/try_finally_loops.py') # requires proper try finally code + skip_tests.add('basics/try_finally_return.py') # requires proper try finally code + skip_tests.add('basics/try_finally_return2.py') # requires proper try finally code + skip_tests.add('basics/unboundlocal.py') # requires checking for unbound local + skip_tests.add('import/gen_context.py') # requires yield_value + skip_tests.add('misc/features.py') # requires raise_varargs + skip_tests.add('misc/rge_sm.py') # requires yield + skip_tests.add('misc/print_exception.py') # because native doesn't have proper traceback info + skip_tests.add('misc/sys_exc_info.py') # sys.exc_info() is not supported for native + skip_tests.add('micropython/emg_exc.py') # because native doesn't have proper traceback info + skip_tests.add('micropython/heapalloc_traceback.py') # because native doesn't have proper traceback info + skip_tests.add('micropython/heapalloc_iter.py') # requires generators + skip_tests.add('micropython/schedule.py') # native code doesn't check pending events + skip_tests.add('stress/gc_trace.py') # requires yield + skip_tests.add('stress/recursive_gen.py') # requires yield + skip_tests.add('extmod/vfs_userfs.py') # because native doesn't properly handle globals across different modules + skip_tests.add('../extmod/ulab/tests/argminmax.py') # requires yield + + def run_one_test(test_file): + test_file = test_file.replace('\\', '/') + + if args.filters: + # Default verdict is the opposit of the first action + verdict = "include" if args.filters[0][0] == "exclude" else "exclude" + for action, pat in args.filters: + if pat.search(test_file): + verdict = action + if verdict == "exclude": + return + + test_basename = os.path.basename(test_file) + test_name = os.path.splitext(test_basename)[0] + is_native = test_name.startswith("native_") or test_name.startswith("viper_") + is_endian = test_name.endswith("_endian") + is_int_big = test_name.startswith("int_big") or test_name.endswith("_intbig") + is_set_type = test_name.startswith("set_") or test_name.startswith("frozenset") + is_async = test_name.startswith("async_") + is_const = test_name.startswith("const") + + skip_it = test_file in skip_tests + skip_it |= skip_native and is_native + skip_it |= skip_endian and is_endian + skip_it |= skip_int_big and is_int_big + skip_it |= skip_set_type and is_set_type + skip_it |= skip_async and is_async + skip_it |= skip_const and is_const + skip_it |= skip_revops and test_name.startswith("class_reverse_op") + + if args.list_tests: + if not skip_it: + print(test_file) + return + + if skip_it: + print("skip ", test_file) + skipped_tests.append(test_name) + return + + # get expected output + test_file_expected = test_file + '.exp' + if os.path.isfile(test_file_expected): + # expected output given by a file, so read that in + with open(test_file_expected, 'rb') as f: + output_expected = f.read() + else: + # run CPython to work out expected output + e = {"PYTHONPATH": os.getcwd(), + "PATH": os.environ["PATH"], + "LANG": "en_US.UTF-8"} + p = subprocess.Popen([CPYTHON3, '-B', test_file], env=e, stdout=subprocess.PIPE) + output_expected = b'' + while p.poll() is None: + output_expected += p.stdout.read() + output_expected += p.stdout.read() + if p.returncode != 0: + output_expected = b'CPYTHON3 CRASH' + elif args.write_exp: + with open(test_file_expected, 'wb') as f: + f.write(output_expected) + + # canonical form for all host platforms is to use \n for end-of-line + output_expected = output_expected.replace(b'\r\n', b'\n') + + if args.write_exp: + return + + # run MicroPython + output_mupy = run_micropython(pyb, args, test_file) + + if output_mupy == b'SKIP\n': + print("skip ", test_file) + skipped_tests.append(test_name) + return + + testcase_count.add(len(output_expected.splitlines())) + + filename_expected = test_basename + ".exp" + filename_mupy = test_basename + ".out" + + if output_expected == output_mupy: + print("pass ", test_file) + passed_count.add(1) + rm_f(filename_expected) + rm_f(filename_mupy) + else: + with open(filename_expected, "wb") as f: + f.write(output_expected) + with open(filename_mupy, "wb") as f: + f.write(output_mupy) + print("### Expected") + print(output_expected) + print("### Actual") + print(output_mupy) + print("FAIL ", test_file) + failed_tests.append(test_name) + + test_count.add(1) + + if args.list_tests: + return True + + if num_threads > 1: + pool = ThreadPool(num_threads) + pool.map(run_one_test, tests) + else: + for test in tests: + run_one_test(test) + + print("{} tests performed ({} individual testcases)".format(test_count.value, testcase_count.value)) + print("{} tests passed".format(passed_count.value)) + + if len(skipped_tests.value) > 0: + print("{} tests skipped: {}".format(len(skipped_tests.value), ' '.join(sorted(skipped_tests.value)))) + if len(failed_tests.value) > 0: + print("{} tests failed: {}".format(len(failed_tests.value), ' '.join(sorted(failed_tests.value)))) + return False + + # all tests succeeded + return True + + +class append_filter(argparse.Action): + + def __init__(self, option_strings, dest, **kwargs): + super().__init__(option_strings, dest, default=[], **kwargs) + + def __call__(self, parser, args, value, option): + if not hasattr(args, self.dest): + args.filters = [] + if option.startswith(("-e", "--e")): + option = "exclude" + else: + option = "include" + args.filters.append((option, re.compile(value))) + + +def main(): + cmd_parser = argparse.ArgumentParser( + formatter_class=argparse.RawDescriptionHelpFormatter, + description='Run and manage tests for MicroPython.', + epilog='''\ +Options -i and -e can be multiple and processed in the order given. Regex +"search" (vs "match") operation is used. An action (include/exclude) of +the last matching regex is used: + run-tests -i async - exclude all, then include tests containg "async" anywhere + run-tests -e '/big.+int' - include all, then exclude by regex + run-tests -e async -i async_foo - include all, exclude async, yet still include async_foo +''') + cmd_parser.add_argument('--target', default='unix', help='the target platform') + cmd_parser.add_argument('--device', default='/dev/ttyACM0', help='the serial device or the IP address of the pyboard') + cmd_parser.add_argument('-b', '--baudrate', default=115200, help='the baud rate of the serial device') + cmd_parser.add_argument('-u', '--user', default='micro', help='the telnet login username') + cmd_parser.add_argument('-p', '--password', default='python', help='the telnet login password') + cmd_parser.add_argument('-d', '--test-dirs', nargs='*', help='input test directories (if no files given)') + cmd_parser.add_argument('-e', '--exclude', action=append_filter, metavar='REGEX', dest='filters', help='exclude test by regex on path/name.py') + cmd_parser.add_argument('-i', '--include', action=append_filter, metavar='REGEX', dest='filters', help='include test by regex on path/name.py') + cmd_parser.add_argument('--write-exp', action='store_true', help='save .exp files to run tests w/o CPython') + cmd_parser.add_argument('--list-tests', action='store_true', help='list tests instead of running them') + cmd_parser.add_argument('--emit', default='bytecode', help='MicroPython emitter to use (bytecode or native)') + cmd_parser.add_argument('--heapsize', help='heapsize to use (use default if not specified)') + cmd_parser.add_argument('--via-mpy', action='store_true', help='compile .py files to .mpy first') + cmd_parser.add_argument('--keep-path', action='store_true', help='do not clear MICROPYPATH when running tests') + cmd_parser.add_argument('-j', '--jobs', default=1, metavar='N', type=int, help='Number of tests to run simultaneously') + cmd_parser.add_argument('--auto-jobs', action='store_const', dest='jobs', const=multiprocessing.cpu_count(), help='Set the -j values to the CPU (thread) count') + cmd_parser.add_argument('files', nargs='*', help='input test files') + args = cmd_parser.parse_args() + + EXTERNAL_TARGETS = ('pyboard', 'wipy', 'esp8266', 'esp32', 'minimal') + if args.target == 'unix' or args.list_tests: + pyb = None + elif args.target in EXTERNAL_TARGETS: + import pyboard + pyb = pyboard.Pyboard(args.device, args.baudrate, args.user, args.password) + pyb.enter_raw_repl() + else: + raise ValueError('target must be either %s or unix' % ", ".join(EXTERNAL_TARGETS)) + + if len(args.files) == 0: + if args.test_dirs is None: + if args.target == 'pyboard': + # run pyboard tests + test_dirs = ('basics', 'micropython', 'float', 'misc', 'stress', 'extmod', 'pyb', 'pybnative', 'inlineasm') + elif args.target in ('esp8266', 'esp32', 'minimal'): + test_dirs = ('basics', 'micropython', 'float', 'misc', 'extmod') + elif args.target == 'wipy': + # run WiPy tests + test_dirs = ('basics', 'micropython', 'misc', 'extmod', 'wipy') + else: + # run PC tests + test_dirs = ( + 'basics', 'micropython', 'float', 'import', 'io', 'misc', + 'stress', 'unicode', 'extmod', '../extmod/ulab/tests', 'unix', 'cmdline', + ) + else: + # run tests from these directories + test_dirs = args.test_dirs + tests = sorted(test_file for test_files in (glob('{}/*.py'.format(dir)) for dir in test_dirs) for test_file in test_files) + else: + # tests explicitly given + tests = args.files + + if not args.keep_path: + # clear search path to make sure tests use only builtin modules + os.environ['MICROPYPATH'] = '' + + # Even if we run completely different tests in a different directory, + # we need to access feature_check's from the same directory as the + # run-tests script itself. + base_path = os.path.dirname(sys.argv[0]) or "." + try: + res = run_tests(pyb, tests, args, base_path, args.jobs) + finally: + if pyb: + pyb.close() + + if not res: + sys.exit(1) + +if __name__ == "__main__": + main() diff --git a/tests/stress 2/dict_copy.py b/tests/stress 2/dict_copy.py new file mode 100644 index 0000000000..36db9bb7e8 --- /dev/null +++ b/tests/stress 2/dict_copy.py @@ -0,0 +1,7 @@ +# copying a large dictionary + +a = {i:2*i for i in range(1000)} +b = a.copy() +for i in range(1000): + print(i, b[i]) +print(len(b)) diff --git a/tests/stress 2/dict_create.py b/tests/stress 2/dict_create.py new file mode 100644 index 0000000000..e9db40a8e6 --- /dev/null +++ b/tests/stress 2/dict_create.py @@ -0,0 +1,8 @@ +# create a large dictionary + +d = {} +x = 1 +while x < 1000: + d[x] = x + x += 1 +print(d[500]) diff --git a/tests/stress 2/dict_create_max.py b/tests/stress 2/dict_create_max.py new file mode 100644 index 0000000000..3c75db20da --- /dev/null +++ b/tests/stress 2/dict_create_max.py @@ -0,0 +1,13 @@ +# The aim with this test is to hit the maximum resize/rehash size of a dict, +# where there are no more primes in the table of growing allocation sizes. +# This value is 54907 items. + +d = {} +try: + for i in range(54908): + d[i] = i +except MemoryError: + pass + +# Just check the dict still has the first value +print(d[0]) diff --git a/tests/stress 2/gc_trace.py b/tests/stress 2/gc_trace.py new file mode 100644 index 0000000000..72dc7b6276 --- /dev/null +++ b/tests/stress 2/gc_trace.py @@ -0,0 +1,17 @@ +# test that the GC can trace nested objects + +try: + import gc +except ImportError: + print("SKIP") + raise SystemExit + +# test a big shallow object pointing to many unique objects +lst = [[i] for i in range(200)] +gc.collect() +print(lst) + +# test a deep object +lst = [[[[[(i, j, k, l)] for i in range(3)] for j in range(3)] for k in range(3)] for l in range(3)] +gc.collect() +print(lst) diff --git a/tests/stress 2/list_sort.py b/tests/stress 2/list_sort.py new file mode 100644 index 0000000000..3a7701a1e4 --- /dev/null +++ b/tests/stress 2/list_sort.py @@ -0,0 +1,6 @@ +# test large list sorting (should not stack overflow) +l = list(range(2000)) +l.sort() +print(l[0], l[-1]) +l.sort(reverse=True) +print(l[0], l[-1]) diff --git a/tests/stress 2/recursion.py b/tests/stress 2/recursion.py new file mode 100644 index 0000000000..227f48396a --- /dev/null +++ b/tests/stress 2/recursion.py @@ -0,0 +1,7 @@ +def foo(): + foo() + +try: + foo() +except RuntimeError: + print("RuntimeError") diff --git a/tests/stress 2/recursive_data.py b/tests/stress 2/recursive_data.py new file mode 100644 index 0000000000..3b7fa50952 --- /dev/null +++ b/tests/stress 2/recursive_data.py @@ -0,0 +1,13 @@ +# This tests that printing recursive data structure doesn't lead to segfault. +try: + import uio as io +except ImportError: + print("SKIP") + raise SystemExit + +l = [1, 2, 3, None] +l[-1] = l +try: + print(l, file=io.StringIO()) +except RuntimeError: + print("RuntimeError") diff --git a/tests/stress 2/recursive_data.py.exp b/tests/stress 2/recursive_data.py.exp new file mode 100644 index 0000000000..8a2b9bfdda --- /dev/null +++ b/tests/stress 2/recursive_data.py.exp @@ -0,0 +1 @@ +RuntimeError diff --git a/tests/stress 2/recursive_gen.py b/tests/stress 2/recursive_gen.py new file mode 100644 index 0000000000..0e0d3914ee --- /dev/null +++ b/tests/stress 2/recursive_gen.py @@ -0,0 +1,18 @@ +# test deeply recursive generators + +# simple "yield from" recursion +def gen(): + yield from gen() +try: + list(gen()) +except RuntimeError: + print('RuntimeError') + +# recursion via an iterator over a generator +def gen2(): + for x in gen2(): + yield x +try: + next(gen2()) +except RuntimeError: + print('RuntimeError') diff --git a/tests/stress 2/recursive_iternext.py b/tests/stress 2/recursive_iternext.py new file mode 100644 index 0000000000..edb5a843f2 --- /dev/null +++ b/tests/stress 2/recursive_iternext.py @@ -0,0 +1,57 @@ +# This tests that recursion with iternext doesn't lead to segfault. +try: + enumerate + filter + map + max + zip +except: + print("SKIP") + raise SystemExit + +# We need to pick an N that is large enough to hit the recursion +# limit, but not too large that we run out of heap memory. +try: + # large stack/heap, eg unix + [0] * 80000 + N = 2400 +except: + try: + # medium, eg pyboard + [0] * 10000 + N = 1000 + except: + # small, eg esp8266 + N = 100 + +try: + x = (1, 2) + for i in range(N): + x = enumerate(x) + tuple(x) +except RuntimeError: + print("RuntimeError") + +try: + x = (1, 2) + for i in range(N): + x = filter(None, x) + tuple(x) +except RuntimeError: + print("RuntimeError") + +try: + x = (1, 2) + for i in range(N): + x = map(max, x, ()) + tuple(x) +except RuntimeError: + print("RuntimeError") + +try: + x = (1, 2) + for i in range(N): + x = zip(x) + tuple(x) +except RuntimeError: + print("RuntimeError") diff --git a/tests/stress 2/recursive_iternext.py.exp b/tests/stress 2/recursive_iternext.py.exp new file mode 100644 index 0000000000..80d1488a37 --- /dev/null +++ b/tests/stress 2/recursive_iternext.py.exp @@ -0,0 +1,4 @@ +RuntimeError +RuntimeError +RuntimeError +RuntimeError diff --git a/tests/thread 2/mutate_bytearray.py b/tests/thread 2/mutate_bytearray.py new file mode 100644 index 0000000000..5015c3f9cf --- /dev/null +++ b/tests/thread 2/mutate_bytearray.py @@ -0,0 +1,46 @@ +# test concurrent mutating access to a shared bytearray object +# +# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +# +# SPDX-License-Identifier: MIT + +import _thread + +# the shared bytearray +ba = bytearray() + +# main thread function +def th(n, lo, hi): + for repeat in range(n): + for i in range(lo, hi): + l = len(ba) + ba.append(i) + assert len(ba) >= l + 1 + + l = len(ba) + ba.extend(bytearray([i])) + assert len(ba) >= l + 1 + + with lock: + global n_finished + n_finished += 1 + +lock = _thread.allocate_lock() +n_thread = 4 +n_finished = 0 +n_repeat = 4 # use 40 for more stressful test (uses more heap) + +# spawn threads +for i in range(n_thread): + _thread.start_new_thread(th, (n_repeat, i * 256 // n_thread, (i + 1) * 256 // n_thread)) + +# busy wait for threads to finish +while n_finished < n_thread: + pass + +# check bytearray has correct contents +print(len(ba)) +count = [0 for _ in range(256)] +for b in ba: + count[b] += 1 +print(count) diff --git a/tests/thread 2/mutate_dict.py b/tests/thread 2/mutate_dict.py new file mode 100644 index 0000000000..563fce39de --- /dev/null +++ b/tests/thread 2/mutate_dict.py @@ -0,0 +1,44 @@ +# test concurrent mutating access to a shared dict object +# +# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +# +# SPDX-License-Identifier: MIT + +import _thread + +# the shared dict +di = {'a':'A', 'b':'B', 'c':'C', 'd':'D'} + +# main thread function +def th(n, lo, hi): + for repeat in range(n): + for i in range(lo, hi): + di[i] = repeat + i + assert di[i] == repeat + i + + del di[i] + assert i not in di + + di[i] = repeat + i + assert di[i] == repeat + i + + assert di.pop(i) == repeat + i + + with lock: + global n_finished + n_finished += 1 + +lock = _thread.allocate_lock() +n_thread = 4 +n_finished = 0 + +# spawn threads +for i in range(n_thread): + _thread.start_new_thread(th, (30, i * 300, (i + 1) * 300)) + +# busy wait for threads to finish +while n_finished < n_thread: + pass + +# check dict has correct contents +print(sorted(di.items())) diff --git a/tests/thread 2/mutate_instance.py b/tests/thread 2/mutate_instance.py new file mode 100644 index 0000000000..2ecfbe1092 --- /dev/null +++ b/tests/thread 2/mutate_instance.py @@ -0,0 +1,45 @@ +# test concurrent mutating access to a shared user instance +# +# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +# +# SPDX-License-Identifier: MIT + +import _thread + +# the shared user class and instance +class User: + def __init__(self): + self.a = 'A' + self.b = 'B' + self.c = 'C' +user = User() + +# main thread function +def th(n, lo, hi): + for repeat in range(n): + for i in range(lo, hi): + setattr(user, 'attr_%u' % i, repeat + i) + assert getattr(user, 'attr_%u' % i) == repeat + i + + with lock: + global n_finished + n_finished += 1 + +lock = _thread.allocate_lock() +n_repeat = 30 +n_range = 50 # 300 for stressful test (uses more heap) +n_thread = 4 +n_finished = 0 + +# spawn threads +for i in range(n_thread): + _thread.start_new_thread(th, (n_repeat, i * n_range, (i + 1) * n_range)) + +# busy wait for threads to finish +while n_finished < n_thread: + pass + +# check user instance has correct contents +print(user.a, user.b, user.c) +for i in range(n_thread * n_range): + assert getattr(user, 'attr_%u' % i) == n_repeat - 1 + i diff --git a/tests/thread 2/mutate_list.py b/tests/thread 2/mutate_list.py new file mode 100644 index 0000000000..d70e8a8a38 --- /dev/null +++ b/tests/thread 2/mutate_list.py @@ -0,0 +1,46 @@ +# test concurrent mutating access to a shared list object +# +# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +# +# SPDX-License-Identifier: MIT + +import _thread + +# the shared list +li = list() + +# main thread function +def th(n, lo, hi): + for repeat in range(n): + for i in range(lo, hi): + li.append(i) + assert li.count(i) == repeat + 1 + + li.extend([i, i]) + assert li.count(i) == repeat + 3 + + li.remove(i) + assert li.count(i) == repeat + 2 + + li.remove(i) + assert li.count(i) == repeat + 1 + + with lock: + global n_finished + n_finished += 1 + +lock = _thread.allocate_lock() +n_thread = 4 +n_finished = 0 + +# spawn threads +for i in range(n_thread): + _thread.start_new_thread(th, (4, i * 60, (i + 1) * 60)) + +# busy wait for threads to finish +while n_finished < n_thread: + pass + +# check list has correct contents +li.sort() +print(li) diff --git a/tests/thread 2/mutate_set.py b/tests/thread 2/mutate_set.py new file mode 100644 index 0000000000..c4529f3562 --- /dev/null +++ b/tests/thread 2/mutate_set.py @@ -0,0 +1,39 @@ +# test concurrent mutating access to a shared set object +# +# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +# +# SPDX-License-Identifier: MIT + +import _thread + +# the shared set +se = set([-1, -2, -3, -4]) + +# main thread function +def th(n, lo, hi): + for repeat in range(n): + for i in range(lo, hi): + se.add(i) + assert i in se + + se.remove(i) + assert i not in se + + with lock: + global n_finished + n_finished += 1 + +lock = _thread.allocate_lock() +n_thread = 4 +n_finished = 0 + +# spawn threads +for i in range(n_thread): + _thread.start_new_thread(th, (50, i * 500, (i + 1) * 500)) + +# busy wait for threads to finish +while n_finished < n_thread: + pass + +# check set has correct contents +print(sorted(se)) diff --git a/tests/thread 2/stress_aes.py b/tests/thread 2/stress_aes.py new file mode 100644 index 0000000000..ebf7af371b --- /dev/null +++ b/tests/thread 2/stress_aes.py @@ -0,0 +1,257 @@ +# Stress test for threads using AES encryption routines. +# +# AES was chosen because it is integer based and inplace so doesn't use the +# heap. It is therefore a good test of raw performance and correctness of the +# VM/runtime. It can be used to measure threading performance (concurrency is +# in principle possible) and correctness (it's non trivial for the encryption/ +# decryption to give the correct answer). +# +# The AES code comes first (code originates from a C version authored by D.P.George) +# and then the test harness at the bottom. It can be tuned to be more/less +# aggressive by changing the amount of data to encrypt, the number of loops and +# the number of threads. +# +# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +# +# SPDX-License-Identifier: MIT + +################################################################## +# discrete arithmetic routines, mostly from a precomputed table + +# non-linear, invertible, substitution box +aes_s_box_table = bytes(( + 0x63,0x7c,0x77,0x7b,0xf2,0x6b,0x6f,0xc5,0x30,0x01,0x67,0x2b,0xfe,0xd7,0xab,0x76, + 0xca,0x82,0xc9,0x7d,0xfa,0x59,0x47,0xf0,0xad,0xd4,0xa2,0xaf,0x9c,0xa4,0x72,0xc0, + 0xb7,0xfd,0x93,0x26,0x36,0x3f,0xf7,0xcc,0x34,0xa5,0xe5,0xf1,0x71,0xd8,0x31,0x15, + 0x04,0xc7,0x23,0xc3,0x18,0x96,0x05,0x9a,0x07,0x12,0x80,0xe2,0xeb,0x27,0xb2,0x75, + 0x09,0x83,0x2c,0x1a,0x1b,0x6e,0x5a,0xa0,0x52,0x3b,0xd6,0xb3,0x29,0xe3,0x2f,0x84, + 0x53,0xd1,0x00,0xed,0x20,0xfc,0xb1,0x5b,0x6a,0xcb,0xbe,0x39,0x4a,0x4c,0x58,0xcf, + 0xd0,0xef,0xaa,0xfb,0x43,0x4d,0x33,0x85,0x45,0xf9,0x02,0x7f,0x50,0x3c,0x9f,0xa8, + 0x51,0xa3,0x40,0x8f,0x92,0x9d,0x38,0xf5,0xbc,0xb6,0xda,0x21,0x10,0xff,0xf3,0xd2, + 0xcd,0x0c,0x13,0xec,0x5f,0x97,0x44,0x17,0xc4,0xa7,0x7e,0x3d,0x64,0x5d,0x19,0x73, + 0x60,0x81,0x4f,0xdc,0x22,0x2a,0x90,0x88,0x46,0xee,0xb8,0x14,0xde,0x5e,0x0b,0xdb, + 0xe0,0x32,0x3a,0x0a,0x49,0x06,0x24,0x5c,0xc2,0xd3,0xac,0x62,0x91,0x95,0xe4,0x79, + 0xe7,0xc8,0x37,0x6d,0x8d,0xd5,0x4e,0xa9,0x6c,0x56,0xf4,0xea,0x65,0x7a,0xae,0x08, + 0xba,0x78,0x25,0x2e,0x1c,0xa6,0xb4,0xc6,0xe8,0xdd,0x74,0x1f,0x4b,0xbd,0x8b,0x8a, + 0x70,0x3e,0xb5,0x66,0x48,0x03,0xf6,0x0e,0x61,0x35,0x57,0xb9,0x86,0xc1,0x1d,0x9e, + 0xe1,0xf8,0x98,0x11,0x69,0xd9,0x8e,0x94,0x9b,0x1e,0x87,0xe9,0xce,0x55,0x28,0xdf, + 0x8c,0xa1,0x89,0x0d,0xbf,0xe6,0x42,0x68,0x41,0x99,0x2d,0x0f,0xb0,0x54,0xbb,0x16, +)) + +# multiplication of polynomials modulo x^8 + x^4 + x^3 + x + 1 = 0x11b +def aes_gf8_mul_2(x): + if x & 0x80: + return (x << 1) ^ 0x11b + else: + return x << 1 + +def aes_gf8_mul_3(x): + return x ^ aes_gf8_mul_2(x) + +# non-linear, invertible, substitution box +def aes_s_box(a): + return aes_s_box_table[a & 0xff] + +# return 0x02^(a-1) in GF(2^8) +def aes_r_con(a): + ans = 1 + while a > 1: + ans <<= 1; + if ans & 0x100: + ans ^= 0x11b + a -= 1 + return ans + +################################################################## +# basic AES algorithm; see FIPS-197 +# +# Think of it as a pseudo random number generator, with each +# symbol in the sequence being a 16 byte block (the state). The +# key is a parameter of the algorithm and tells which particular +# sequence of random symbols you want. The initial vector, IV, +# sets the start of the sequence. The idea of a strong cipher +# is that it's very difficult to guess the key even if you know +# a large part of the sequence. The basic AES algorithm simply +# provides such a sequence. En/de-cryption is implemented here +# using OCB, where the sequence is xored against the plaintext. +# Care must be taken to (almost) always choose a different IV. + +# all inputs must be size 16 +def aes_add_round_key(state, w): + for i in range(16): + state[i] ^= w[i] + +# combined sub_bytes, shift_rows, mix_columns, add_round_key +# all inputs must be size 16 +def aes_sb_sr_mc_ark(state, w, w_idx, temp): + temp_idx = 0 + for i in range(4): + x0 = aes_s_box_table[state[i * 4]] + x1 = aes_s_box_table[state[1 + ((i + 1) & 3) * 4]] + x2 = aes_s_box_table[state[2 + ((i + 2) & 3) * 4]] + x3 = aes_s_box_table[state[3 + ((i + 3) & 3) * 4]] + temp[temp_idx] = aes_gf8_mul_2(x0) ^ aes_gf8_mul_3(x1) ^ x2 ^ x3 ^ w[w_idx] + temp[temp_idx + 1] = x0 ^ aes_gf8_mul_2(x1) ^ aes_gf8_mul_3(x2) ^ x3 ^ w[w_idx + 1] + temp[temp_idx + 2] = x0 ^ x1 ^ aes_gf8_mul_2(x2) ^ aes_gf8_mul_3(x3) ^ w[w_idx + 2] + temp[temp_idx + 3] = aes_gf8_mul_3(x0) ^ x1 ^ x2 ^ aes_gf8_mul_2(x3) ^ w[w_idx + 3] + w_idx += 4 + temp_idx += 4 + for i in range(16): + state[i] = temp[i] + +# combined sub_bytes, shift_rows, add_round_key +# all inputs must be size 16 +def aes_sb_sr_ark(state, w, w_idx, temp): + temp_idx = 0 + for i in range(4): + x0 = aes_s_box_table[state[i * 4]] + x1 = aes_s_box_table[state[1 + ((i + 1) & 3) * 4]] + x2 = aes_s_box_table[state[2 + ((i + 2) & 3) * 4]] + x3 = aes_s_box_table[state[3 + ((i + 3) & 3) * 4]] + temp[temp_idx] = x0 ^ w[w_idx] + temp[temp_idx + 1] = x1 ^ w[w_idx + 1] + temp[temp_idx + 2] = x2 ^ w[w_idx + 2] + temp[temp_idx + 3] = x3 ^ w[w_idx + 3] + w_idx += 4 + temp_idx += 4 + for i in range(16): + state[i] = temp[i] + +# take state as input and change it to the next state in the sequence +# state and temp have size 16, w has size 16 * (Nr + 1), Nr >= 1 +def aes_state(state, w, temp, nr): + aes_add_round_key(state, w) + w_idx = 16 + for i in range(nr - 1): + aes_sb_sr_mc_ark(state, w, w_idx, temp) + w_idx += 16 + aes_sb_sr_ark(state, w, w_idx, temp) + +# expand 'key' to 'w' for use with aes_state +# key has size 4 * Nk, w has size 16 * (Nr + 1), temp has size 16 +def aes_key_expansion(key, w, temp, nk, nr): + for i in range(4 * nk): + w[i] = key[i] + w_idx = 4 * nk - 4 + for i in range(nk, 4 * (nr + 1)): + t = temp + t_idx = 0 + if i % nk == 0: + t[0] = aes_s_box(w[w_idx + 1]) ^ aes_r_con(i // nk) + for j in range(1, 4): + t[j] = aes_s_box(w[w_idx + (j + 1) % 4]) + elif nk > 6 and i % nk == 4: + for j in range(0, 4): + t[j] = aes_s_box(w[w_idx + j]) + else: + t = w + t_idx = w_idx + w_idx += 4 + for j in range(4): + w[w_idx + j] = w[w_idx + j - 4 * nk] ^ t[t_idx + j] + +################################################################## +# simple use of AES algorithm, using output feedback (OFB) mode + +class AES: + def __init__(self, keysize): + if keysize == 128: + self.nk = 4 + self.nr = 10 + elif keysize == 192: + self.nk = 6 + self.nr = 12 + else: + assert keysize == 256 + self.nk = 8 + self.nr = 14 + + self.state = bytearray(16) + self.w = bytearray(16 * (self.nr + 1)) + self.temp = bytearray(16) + self.state_pos = 16 + + def set_key(self, key): + aes_key_expansion(key, self.w, self.temp, self.nk, self.nr) + self.state_pos = 16 + + def set_iv(self, iv): + for i in range(16): + self.state[i] = iv[i] + self.state_pos = 16; + + def get_some_state(self, n_needed): + if self.state_pos >= 16: + aes_state(self.state, self.w, self.temp, self.nr) + self.state_pos = 0 + n = 16 - self.state_pos + if n > n_needed: + n = n_needed + return n + + def apply_to(self, data): + idx = 0 + n = len(data) + while n > 0: + ln = self.get_some_state(n) + n -= ln + for i in range(ln): + data[idx + i] ^= self.state[self.state_pos + i] + idx += ln + self.state_pos += n + +################################################################## +# test code + +try: + import utime as time +except ImportError: + import time +import _thread + +class LockedCounter: + def __init__(self): + self.lock = _thread.allocate_lock() + self.value = 0 + + def add(self, val): + self.lock.acquire() + self.value += val + self.lock.release() + +count = LockedCounter() + +def thread_entry(): + global count + + aes = AES(256) + key = bytearray(256 // 8) + iv = bytearray(16) + data = bytearray(128) + # from now on we don't use the heap + + for loop in range(5): + # encrypt + aes.set_key(key) + aes.set_iv(iv) + for i in range(8): + aes.apply_to(data) + + # decrypt + aes.set_key(key) + aes.set_iv(iv) + for i in range(8): + aes.apply_to(data) + + # verify + for i in range(len(data)): + assert data[i] == 0 + + count.add(1) + +if __name__ == '__main__': + n_thread = 20 + for i in range(n_thread): + _thread.start_new_thread(thread_entry, ()) + while count.value < n_thread: + time.sleep(1) diff --git a/tests/thread 2/stress_create.py b/tests/thread 2/stress_create.py new file mode 100644 index 0000000000..2399746cca --- /dev/null +++ b/tests/thread 2/stress_create.py @@ -0,0 +1,22 @@ +# stress test for creating many threads + +try: + import utime as time +except ImportError: + import time +import _thread + +def thread_entry(n): + pass + +thread_num = 0 +while thread_num < 500: + try: + _thread.start_new_thread(thread_entry, (thread_num,)) + thread_num += 1 + except MemoryError: + pass + +# wait for the last threads to terminate +time.sleep(1) +print('done') diff --git a/tests/thread 2/stress_heap.py b/tests/thread 2/stress_heap.py new file mode 100644 index 0000000000..206cf1a860 --- /dev/null +++ b/tests/thread 2/stress_heap.py @@ -0,0 +1,48 @@ +# stress test for the heap by allocating lots of objects within threads +# allocates about 5mb on the heap +# +# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +# +# SPDX-License-Identifier: MIT + +try: + import utime as time +except ImportError: + import time +import _thread + +def last(l): + return l[-1] + +def thread_entry(n): + # allocate a bytearray and fill it + data = bytearray(i for i in range(256)) + + # run a loop which allocates a small list and uses it each iteration + lst = 8 * [0] + sum = 0 + for i in range(n): + sum += last(lst) + lst = [0, 0, 0, 0, 0, 0, 0, i + 1] + + # check that the bytearray still has the right data + for i, b in enumerate(data): + assert i == b + + # print the result of the loop and indicate we are finished + with lock: + print(sum, lst[-1]) + global n_finished + n_finished += 1 + +lock = _thread.allocate_lock() +n_thread = 10 +n_finished = 0 + +# spawn threads +for i in range(n_thread): + _thread.start_new_thread(thread_entry, (10000,)) + +# wait for threads to finish +while n_finished < n_thread: + time.sleep(1) diff --git a/tests/thread 2/stress_recurse.py b/tests/thread 2/stress_recurse.py new file mode 100644 index 0000000000..8edee246ad --- /dev/null +++ b/tests/thread 2/stress_recurse.py @@ -0,0 +1,27 @@ +# test hitting the function recursion limit within a thread +# +# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +# +# SPDX-License-Identifier: MIT + +import _thread + +def foo(): + foo() + +def thread_entry(): + try: + foo() + except RuntimeError: + print('RuntimeError') + global finished + finished = True + +finished = False + +_thread.start_new_thread(thread_entry, ()) + +# busy wait for thread to finish +while not finished: + pass +print('done') diff --git a/tests/thread 2/thread_exc1.py b/tests/thread 2/thread_exc1.py new file mode 100644 index 0000000000..e00a16bd26 --- /dev/null +++ b/tests/thread 2/thread_exc1.py @@ -0,0 +1,32 @@ +# test raising and catching an exception within a thread +# +# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +# +# SPDX-License-Identifier: MIT + +import _thread + +def foo(): + raise ValueError + +def thread_entry(): + try: + foo() + except ValueError: + pass + with lock: + global n_finished + n_finished += 1 + +lock = _thread.allocate_lock() +n_thread = 4 +n_finished = 0 + +# spawn threads +for i in range(n_thread): + _thread.start_new_thread(thread_entry, ()) + +# busy wait for threads to finish +while n_finished < n_thread: + pass +print('done') diff --git a/tests/thread 2/thread_exc2.py b/tests/thread 2/thread_exc2.py new file mode 100644 index 0000000000..35cb324412 --- /dev/null +++ b/tests/thread 2/thread_exc2.py @@ -0,0 +1,10 @@ +# test raising exception within thread which is not caught +import utime +import _thread + +def thread_entry(): + raise ValueError + +_thread.start_new_thread(thread_entry, ()) +utime.sleep(1) +print('done') diff --git a/tests/thread 2/thread_exc2.py.exp b/tests/thread 2/thread_exc2.py.exp new file mode 100644 index 0000000000..cc7a20aa26 --- /dev/null +++ b/tests/thread 2/thread_exc2.py.exp @@ -0,0 +1,5 @@ +Unhandled exception in thread started by +Traceback (most recent call last): + File \.\+, line 6, in thread_entry +ValueError: +done diff --git a/tests/thread 2/thread_exit1.py b/tests/thread 2/thread_exit1.py new file mode 100644 index 0000000000..ad7b01d89b --- /dev/null +++ b/tests/thread 2/thread_exit1.py @@ -0,0 +1,21 @@ +# test _thread.exit() function +# +# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +# +# SPDX-License-Identifier: MIT + +try: + import utime as time +except ImportError: + import time +import _thread + +def thread_entry(): + _thread.exit() + +_thread.start_new_thread(thread_entry, ()) +_thread.start_new_thread(thread_entry, ()) + +# wait for threads to finish +time.sleep(1) +print('done') diff --git a/tests/thread 2/thread_exit2.py b/tests/thread 2/thread_exit2.py new file mode 100644 index 0000000000..6bff8a1736 --- /dev/null +++ b/tests/thread 2/thread_exit2.py @@ -0,0 +1,21 @@ +# test raising SystemExit to finish a thread +# +# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +# +# SPDX-License-Identifier: MIT + +try: + import utime as time +except ImportError: + import time +import _thread + +def thread_entry(): + raise SystemExit + +_thread.start_new_thread(thread_entry, ()) +_thread.start_new_thread(thread_entry, ()) + +# wait for threads to finish +time.sleep(1) +print('done') diff --git a/tests/thread 2/thread_gc1.py b/tests/thread 2/thread_gc1.py new file mode 100644 index 0000000000..2ea1891615 --- /dev/null +++ b/tests/thread 2/thread_gc1.py @@ -0,0 +1,36 @@ +# test that we can run the garbage collector within threads +# +# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +# +# SPDX-License-Identifier: MIT + +import gc +import _thread + +def thread_entry(n): + # allocate a bytearray and fill it + data = bytearray(i for i in range(256)) + + # do some work and call gc.collect() a few times + for i in range(n): + for i in range(len(data)): + data[i] = data[i] + gc.collect() + + # print whether the data remains intact and indicate we are finished + with lock: + print(list(data) == list(range(256))) + global n_finished + n_finished += 1 + +lock = _thread.allocate_lock() +n_thread = 4 +n_finished = 0 + +# spawn threads +for i in range(n_thread): + _thread.start_new_thread(thread_entry, (10,)) + +# busy wait for threads to finish +while n_finished < n_thread: + pass diff --git a/tests/thread 2/thread_ident1.py b/tests/thread 2/thread_ident1.py new file mode 100644 index 0000000000..9a6f89ff5f --- /dev/null +++ b/tests/thread 2/thread_ident1.py @@ -0,0 +1,23 @@ +# test _thread.get_ident() function +# +# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +# +# SPDX-License-Identifier: MIT + +import _thread + +def thread_entry(): + tid = _thread.get_ident() + print('thread', type(tid) == int, tid != 0, tid != tid_main) + global finished + finished = True + +tid_main = _thread.get_ident() +print('main', type(tid_main) == int, tid_main != 0) + +finished = False +_thread.start_new_thread(thread_entry, ()) + +while not finished: + pass +print('done') diff --git a/tests/thread 2/thread_lock1.py b/tests/thread 2/thread_lock1.py new file mode 100644 index 0000000000..c2d7c9d1ed --- /dev/null +++ b/tests/thread 2/thread_lock1.py @@ -0,0 +1,48 @@ +# test _thread lock object using a single thread +# +# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +# +# SPDX-License-Identifier: MIT + +import _thread + +# create lock +lock = _thread.allocate_lock() + +print(type(lock) == _thread.LockType) + +# should be unlocked +print(lock.locked()) + +# basic acquire and release +print(lock.acquire()) +print(lock.locked()) +lock.release() +print(lock.locked()) + +# try acquire twice (second should fail) +print(lock.acquire()) +print(lock.locked()) +print(lock.acquire(0)) +print(lock.locked()) +lock.release() +print(lock.locked()) + +# test with capabilities of lock +with lock: + print(lock.locked()) + +# test that lock is unlocked if an error is rasied +try: + with lock: + print(lock.locked()) + raise KeyError +except KeyError: + print('KeyError') + print(lock.locked()) + +# test that we can't release an unlocked lock +try: + lock.release() +except RuntimeError: + print('RuntimeError') diff --git a/tests/thread 2/thread_lock2.py b/tests/thread 2/thread_lock2.py new file mode 100644 index 0000000000..4ef912dff5 --- /dev/null +++ b/tests/thread 2/thread_lock2.py @@ -0,0 +1,26 @@ +# test _thread lock objects with multiple threads +# +# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +# +# SPDX-License-Identifier: MIT + +try: + import utime as time +except ImportError: + import time +import _thread + +lock = _thread.allocate_lock() + +def thread_entry(): + lock.acquire() + print('have it') + lock.release() + +# spawn the threads +for i in range(4): + _thread.start_new_thread(thread_entry, ()) + +# wait for threads to finish +time.sleep(1) +print('done') diff --git a/tests/thread 2/thread_lock3.py b/tests/thread 2/thread_lock3.py new file mode 100644 index 0000000000..35808d99cb --- /dev/null +++ b/tests/thread 2/thread_lock3.py @@ -0,0 +1,29 @@ +# test thread coordination using a lock object +# +# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +# +# SPDX-License-Identifier: MIT + +import _thread + +lock = _thread.allocate_lock() +n_thread = 10 +n_finished = 0 + +def thread_entry(idx): + global n_finished + while True: + with lock: + if n_finished == idx: + break + print('my turn:', idx) + with lock: + n_finished += 1 + +# spawn threads +for i in range(n_thread): + _thread.start_new_thread(thread_entry, (i,)) + +# busy wait for threads to finish +while n_finished < n_thread: + pass diff --git a/tests/thread 2/thread_lock4.py b/tests/thread 2/thread_lock4.py new file mode 100644 index 0000000000..440f3e90c6 --- /dev/null +++ b/tests/thread 2/thread_lock4.py @@ -0,0 +1,53 @@ +# test using lock to coordinate access to global mutable objects +# +# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +# +# SPDX-License-Identifier: MIT + +try: + import utime as time +except ImportError: + import time +import _thread + +def fac(n): + x = 1 + for i in range(1, n + 1): + x *= i + return x + +def thread_entry(): + while True: + with jobs_lock: + try: + f, arg = jobs.pop(0) + except IndexError: + return + ans = f(arg) + with output_lock: + output.append((arg, ans)) + +# create a list of jobs +jobs = [(fac, i) for i in range(20, 80)] +jobs_lock = _thread.allocate_lock() +n_jobs = len(jobs) + +# create a list to store the results +output = [] +output_lock = _thread.allocate_lock() + +# spawn threads to do the jobs +for i in range(4): + _thread.start_new_thread(thread_entry, ()) + +# wait for the jobs to complete +while True: + with jobs_lock: + if len(output) == n_jobs: + break + time.sleep(1) + +# sort and print the results +output.sort(key=lambda x: x[0]) +for arg, ans in output: + print(arg, ans) diff --git a/tests/thread 2/thread_qstr1.py b/tests/thread 2/thread_qstr1.py new file mode 100644 index 0000000000..dccfb7f517 --- /dev/null +++ b/tests/thread 2/thread_qstr1.py @@ -0,0 +1,41 @@ +# test concurrent interning of strings +# +# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +# +# SPDX-License-Identifier: MIT + +try: + import utime as time +except ImportError: + import time +import _thread + +# function to check the interned string +def check(s, val): + assert type(s) == str + assert int(s) == val + +# main thread function +def th(base, n): + for i in range(n): + # this will intern the string and check it + exec("check('%u', %u)" % (base + i, base + i)) + + with lock: + global n_finished + n_finished += 1 + +lock = _thread.allocate_lock() +n_thread = 4 +n_finished = 0 +n_qstr_per_thread = 100 # make 1000 for a more stressful test (uses more heap) + +# spawn threads +for i in range(n_thread): + _thread.start_new_thread(th, (i * n_qstr_per_thread, n_qstr_per_thread)) + +# wait for threads to finish +while n_finished < n_thread: + time.sleep(1) + +print('pass') diff --git a/tests/thread 2/thread_shared1.py b/tests/thread 2/thread_shared1.py new file mode 100644 index 0000000000..de339ad7f8 --- /dev/null +++ b/tests/thread 2/thread_shared1.py @@ -0,0 +1,33 @@ +# test capability for threads to access a shared immutable data structure +# +# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +# +# SPDX-License-Identifier: MIT + +import _thread + +def foo(i): + pass + +def thread_entry(n, tup): + for i in tup: + foo(i) + with lock: + global n_finished + n_finished += 1 + +lock = _thread.allocate_lock() +n_thread = 2 +n_finished = 0 + +# the shared data structure +tup = (1, 2, 3, 4) + +# spawn threads +for i in range(n_thread): + _thread.start_new_thread(thread_entry, (100, tup)) + +# busy wait for threads to finish +while n_finished < n_thread: + pass +print(tup) diff --git a/tests/thread 2/thread_shared2.py b/tests/thread 2/thread_shared2.py new file mode 100644 index 0000000000..2c749e6883 --- /dev/null +++ b/tests/thread 2/thread_shared2.py @@ -0,0 +1,34 @@ +# test capability for threads to access a shared mutable data structure +# (without contention because they access different parts of the structure) +# +# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +# +# SPDX-License-Identifier: MIT + +import _thread + +def foo(lst, i): + lst[i] += 1 + +def thread_entry(n, lst, idx): + for i in range(n): + foo(lst, idx) + with lock: + global n_finished + n_finished += 1 + +lock = _thread.allocate_lock() +n_thread = 2 +n_finished = 0 + +# the shared data structure +lst = [0, 0] + +# spawn threads +for i in range(n_thread): + _thread.start_new_thread(thread_entry, ((i + 1) * 10, lst, i)) + +# busy wait for threads to finish +while n_finished < n_thread: + pass +print(lst) diff --git a/tests/thread 2/thread_sleep1.py b/tests/thread 2/thread_sleep1.py new file mode 100644 index 0000000000..d5aa99f977 --- /dev/null +++ b/tests/thread 2/thread_sleep1.py @@ -0,0 +1,33 @@ +# test threads sleeping +# +# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +# +# SPDX-License-Identifier: MIT + +try: + import utime + sleep_ms = utime.sleep_ms +except ImportError: + import time + sleep_ms = lambda t: time.sleep(t / 1000) + +import _thread + +lock = _thread.allocate_lock() +n_thread = 4 +n_finished = 0 + +def thread_entry(t): + global n_finished + sleep_ms(t) + sleep_ms(2 * t) + with lock: + n_finished += 1 + +for i in range(n_thread): + _thread.start_new_thread(thread_entry, (10 * i,)) + +# wait for threads to finish +while n_finished < n_thread: + sleep_ms(100) +print('done', n_thread) diff --git a/tests/thread 2/thread_stacksize1.py b/tests/thread 2/thread_stacksize1.py new file mode 100644 index 0000000000..e7189fafbc --- /dev/null +++ b/tests/thread 2/thread_stacksize1.py @@ -0,0 +1,49 @@ +# test setting the thread stack size +# +# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +# +# SPDX-License-Identifier: MIT + +import sys +import _thread + +# different implementations have different minimum sizes +if sys.implementation.name == 'micropython': + sz = 2 * 1024 +else: + sz = 32 * 1024 + +def foo(): + pass + +def thread_entry(): + foo() + with lock: + global n_finished + n_finished += 1 + +# reset stack size to default +_thread.stack_size() + +# test set/get of stack size +print(_thread.stack_size()) +print(_thread.stack_size(sz)) +print(_thread.stack_size() == sz) +print(_thread.stack_size()) + +lock = _thread.allocate_lock() +n_thread = 2 +n_finished = 0 + +# set stack size and spawn a few threads +_thread.stack_size(sz) +for i in range(n_thread): + _thread.start_new_thread(thread_entry, ()) + +# reset stack size to default (for subsequent scripts on baremetal) +_thread.stack_size() + +# busy wait for threads to finish +while n_finished < n_thread: + pass +print('done') diff --git a/tests/thread 2/thread_start1.py b/tests/thread 2/thread_start1.py new file mode 100644 index 0000000000..94df6dc625 --- /dev/null +++ b/tests/thread 2/thread_start1.py @@ -0,0 +1,25 @@ +# test basic capability to start a new thread +# +# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +# +# SPDX-License-Identifier: MIT + +try: + import utime as time +except ImportError: + import time +import _thread + +def foo(): + pass + +def thread_entry(n): + for i in range(n): + foo() + +_thread.start_new_thread(thread_entry, (10,)) +_thread.start_new_thread(thread_entry, (20,)) + +# wait for threads to finish +time.sleep(1) +print('done') diff --git a/tests/thread 2/thread_start2.py b/tests/thread 2/thread_start2.py new file mode 100644 index 0000000000..9412bb6183 --- /dev/null +++ b/tests/thread 2/thread_start2.py @@ -0,0 +1,28 @@ +# test capability to start a thread with keyword args +# +# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd +# +# SPDX-License-Identifier: MIT + +try: + import utime as time +except ImportError: + import time +import _thread + +def thread_entry(a0, a1, a2, a3): + print('thread', a0, a1, a2, a3) + +# spawn thread using kw args +_thread.start_new_thread(thread_entry, (10, 20), {'a2': 0, 'a3': 1}) + +# wait for thread to finish +time.sleep(1) + +# incorrect argument where dictionary is needed for keyword args +try: + _thread.start_new_thread(thread_entry, (), ()) +except TypeError: + print('TypeError') + +print('done') diff --git a/tests/unix 2/extra_coverage.py b/tests/unix 2/extra_coverage.py new file mode 100644 index 0000000000..13721f1f47 --- /dev/null +++ b/tests/unix 2/extra_coverage.py @@ -0,0 +1,74 @@ +try: + extra_coverage +except NameError: + print("SKIP") + raise SystemExit + +import uerrno +import uio + +data = extra_coverage() + +# test hashing of str/bytes that have an invalid hash +print(data[0], data[1]) +print(hash(data[0])) +print(hash(data[1])) +print(hash(bytes(data[0], 'utf8'))) +print(hash(str(data[1], 'utf8'))) + +# test streams +stream = data[2] # has set_error and set_buf. Write always returns error +stream.set_error(uerrno.EAGAIN) # non-blocking error +print(stream.read()) # read all encounters non-blocking error +print(stream.read(1)) # read 1 byte encounters non-blocking error +print(stream.readline()) # readline encounters non-blocking error +print(stream.readinto(bytearray(10))) # readinto encounters non-blocking error +print(stream.write(b'1')) # write encounters non-blocking error +print(stream.write1(b'1')) # write1 encounters non-blocking error +stream.set_buf(b'123') +print(stream.read(4)) # read encounters non-blocking error after successful reads +stream.set_buf(b'123') +print(stream.read1(4)) # read1 encounters non-blocking error after successful reads +stream.set_buf(b'123') +print(stream.readline(4)) # readline encounters non-blocking error after successful reads +try: + print(stream.ioctl(0, 0)) # ioctl encounters non-blocking error; raises OSError +except OSError: + print('OSError') +stream.set_error(0) +print(stream.ioctl(0, bytearray(10))) # successful ioctl call + +stream2 = data[3] # is textio +print(stream2.read(1)) # read 1 byte encounters non-blocking error with textio stream + +# test BufferedWriter with stream errors +stream.set_error(uerrno.EAGAIN) +buf = uio.BufferedWriter(stream, 8) +print(buf.write(bytearray(16))) + +# test basic import of frozen scripts +import frzstr1 +import frzmpy1 + +# test import of frozen packages with __init__.py +import frzstr_pkg1 +print(frzstr_pkg1.x) +import frzmpy_pkg1 +print(frzmpy_pkg1.x) + +# test import of frozen packages without __init__.py +from frzstr_pkg2.mod import Foo +print(Foo.x) +from frzmpy_pkg2.mod import Foo +print(Foo.x) + +# test raising exception in frozen script +try: + import frzmpy2 +except ZeroDivisionError: + print('ZeroDivisionError') + +# test loading a resource from a frozen string +import uio +buf = uio.resource_stream('frzstr_pkg2', 'mod.py') +print(buf.read(21)) diff --git a/tests/unix 2/extra_coverage.py.exp b/tests/unix 2/extra_coverage.py.exp new file mode 100644 index 0000000000..06b5d37903 --- /dev/null +++ b/tests/unix 2/extra_coverage.py.exp @@ -0,0 +1,106 @@ +# mp_printf +-123 +123 123 +-0123 +123 +123 +1ABCDEF +ab abc + +false true +(null) +-2147483648 +2147483648 +80000000 +80000000 +abc +# GC +0 +0 +# vstr +tests +sts + +test +tes +RuntimeError: +RuntimeError: +# repl +ame__ + +argv byteorder exc_info exit +getsizeof implementation maxsize modules +path platform print_exception +stderr stdin stdout version +version_info +ementation +# attrtuple +(start=1, stop=2, step=3) +# str +1 +# bytearray +data +# mpz +1 +12345678 +0 +0 +0 +0 +0 +1 +12345 +6 +# runtime utils +TypeError: unsupported type for __abs__: 'str' +TypeError: unsupported types for __divmod__: 'str', 'str' +Warning: test +# format float +? ++1e+00 ++1e+00 +# binary +123 +456 +# VM +2 1 +# scheduler +sched(0)=1 +sched(1)=1 +sched(2)=1 +sched(3)=1 +sched(4)=0 +unlocked +3 +2 +1 +0 +0123456789 b'0123456789' +7300 +7300 +7300 +7300 +None +None +None +None +None +None +b'123' +b'123' +b'123' +OSError +0 +None +None +frzstr1 +frzmpy1 +frzstr_pkg1.__init__ +1 +frzmpy_pkg1.__init__ +1 +frzstr_pkg2.mod +1 +frzmpy_pkg2.mod +1 +ZeroDivisionError +b'# test frozen package' diff --git a/tests/unix 2/ffi_callback.py b/tests/unix 2/ffi_callback.py new file mode 100644 index 0000000000..23b058bcec --- /dev/null +++ b/tests/unix 2/ffi_callback.py @@ -0,0 +1,33 @@ +try: + import ffi +except ImportError: + print("SKIP") + raise SystemExit + + +def ffi_open(names): + err = None + for n in names: + try: + mod = ffi.open(n) + return mod + except OSError as e: + err = e + raise err + +libc = ffi_open(('libc.so', 'libc.so.0', 'libc.so.6', 'libc.dylib')) + +qsort = libc.func("v", "qsort", "piip") + +def cmp(pa, pb): + a = ffi.as_bytearray(pa, 1) + b = ffi.as_bytearray(pb, 1) + #print("cmp:", a, b) + return a[0] - b[0] + +cmp_c = ffi.callback("i", cmp, "pp") + +s = bytearray(b"foobar") +print("org string:", s) +qsort(s, len(s), 1, cmp_c) +print("qsort'ed:", s) diff --git a/tests/unix 2/ffi_callback.py.exp b/tests/unix 2/ffi_callback.py.exp new file mode 100644 index 0000000000..d06fec52fb --- /dev/null +++ b/tests/unix 2/ffi_callback.py.exp @@ -0,0 +1,2 @@ +org string: bytearray(b'foobar') +qsort'ed: bytearray(b'abfoor') diff --git a/tests/unix 2/ffi_float.py b/tests/unix 2/ffi_float.py new file mode 100644 index 0000000000..c92a39bcdc --- /dev/null +++ b/tests/unix 2/ffi_float.py @@ -0,0 +1,32 @@ +# test ffi float support +try: + import ffi +except ImportError: + print("SKIP") + raise SystemExit + + +def ffi_open(names): + err = None + for n in names: + try: + mod = ffi.open(n) + return mod + except OSError as e: + err = e + raise err + +libc = ffi_open(('libc.so', 'libc.so.0', 'libc.so.6', 'libc.dylib')) + +strtof = libc.func("f", "strtof", "sp") +print('%.6f' % strtof('1.23', None)) + +strtod = libc.func("d", "strtod", "sp") +print('%.6f' % strtod('1.23', None)) + +# test passing double and float args +libm = ffi_open(('libm.so', 'libm.so.6', 'libc.so.0', 'libc.so.6', 'libc.dylib')) +tgamma = libm.func('d', 'tgamma', 'd') +for fun in (tgamma,): + for val in (0.5, 1, 1.0, 1.5, 4, 4.0): + print('%.6f' % fun(val)) diff --git a/tests/unix 2/ffi_float.py.exp b/tests/unix 2/ffi_float.py.exp new file mode 100644 index 0000000000..b9d7da2bdb --- /dev/null +++ b/tests/unix 2/ffi_float.py.exp @@ -0,0 +1,8 @@ +1.230000 +1.230000 +1.772454 +1.000000 +1.000000 +0.886227 +6.000000 +6.000000 diff --git a/tests/unix 2/ffi_float2.py b/tests/unix 2/ffi_float2.py new file mode 100644 index 0000000000..721eb4d192 --- /dev/null +++ b/tests/unix 2/ffi_float2.py @@ -0,0 +1,31 @@ +# test ffi float support +try: + import ffi +except ImportError: + print("SKIP") + raise SystemExit + + +def ffi_open(names): + err = None + for n in names: + try: + mod = ffi.open(n) + return mod + except OSError as e: + err = e + raise err + +libm = ffi_open(('libm.so', 'libm.so.6', 'libc.so.0', 'libc.so.6', 'libc.dylib')) + +# Some libc's implement tgammaf as header macro with tgamma(), so don't assume +# it'll be in library. +try: + tgammaf = libm.func('f', 'tgammaf', 'f') +except OSError: + print("SKIP") + raise SystemExit + +for fun in (tgammaf,): + for val in (0.5, 1, 1.0, 1.5, 4, 4.0): + print('%.6f' % fun(val)) diff --git a/tests/unix 2/ffi_float2.py.exp b/tests/unix 2/ffi_float2.py.exp new file mode 100644 index 0000000000..58fc6a01ac --- /dev/null +++ b/tests/unix 2/ffi_float2.py.exp @@ -0,0 +1,6 @@ +1.772454 +1.000000 +1.000000 +0.886227 +6.000000 +6.000000 diff --git a/tools/.gitattributes 2 b/tools/.gitattributes 2 new file mode 100644 index 0000000000..9206a0bfc1 --- /dev/null +++ b/tools/.gitattributes 2 @@ -0,0 +1 @@ +*.tar.gz binary diff --git a/tools/.gitignore 2 b/tools/.gitignore 2 new file mode 100644 index 0000000000..9f65f493bc --- /dev/null +++ b/tools/.gitignore 2 @@ -0,0 +1,8 @@ +tinytest/.gitignore +tinytest/.travis.yml +tinytest/Makefile +tinytest/Makefile.arm-cortex-m3-qemu +tinytest/Makefile.avr +tinytest/TODO +tinytest/portable_demo.c +tinytest/tinytest_demo.c From 2f476731ecd8bc108f00210b81a0c3e0333d8982 Mon Sep 17 00:00:00 2001 From: Seth Kerr Date: Wed, 16 Dec 2020 10:35:41 -0500 Subject: [PATCH 34/70] removing pesky directories --- tests/README 2 | 18 - tests/extmod 2/btree1.py | 89 --- tests/extmod 2/framebuf1.py | 109 ---- tests/extmod 2/framebuf16.py | 59 -- tests/extmod 2/framebuf2.py.exp | 57 -- tests/extmod 2/framebuf4.py | 53 -- tests/extmod 2/framebuf_subclass.py | 20 - tests/extmod 2/machine1.py | 28 - tests/extmod 2/machine_pinbase.py | 30 - tests/extmod 2/machine_pinbase.py.exp | 9 - tests/extmod 2/ticks_diff.py | 33 - tests/extmod 2/time_ms_us.py | 22 - tests/extmod 2/time_ms_us.py.exp | 3 - tests/extmod 2/ubinascii_a2b_base64.py | 49 -- tests/extmod 2/ubinascii_hexlify.py | 17 - tests/extmod 2/uctypes_32bit_intbig.py.exp | 11 - .../uctypes_array_assign_native_le.py | 89 --- .../uctypes_array_assign_native_le.py.exp | 11 - .../uctypes_array_assign_native_le_intbig.py | 43 -- tests/extmod 2/uctypes_bytearray.py | 22 - tests/extmod 2/uctypes_byteat.py | 10 - tests/extmod 2/uctypes_byteat.py.exp | 2 - tests/extmod 2/uctypes_error.py | 37 -- tests/extmod 2/uctypes_error.py.exp | 4 - tests/extmod 2/uctypes_le_float.py | 24 - tests/extmod 2/uctypes_native_float.py | 20 - tests/extmod 2/uctypes_ptr_le.py | 34 - tests/extmod 2/uctypes_ptr_native_le.py.exp | 6 - tests/extmod 2/uctypes_sizeof.py.exp | 7 - tests/extmod 2/uhashlib_sha1.py | 28 - tests/extmod 2/ujson_dump.py | 30 - tests/extmod 2/ujson_dumps_extra.py | 9 - tests/extmod 2/ujson_dumps_float.py | 10 - tests/extmod 2/ujson_load_readinto.py.exp | 4 - tests/extmod 2/ujson_loads.py | 74 --- tests/extmod 2/ujson_loads_float.py | 17 - tests/extmod 2/urandom_basic.py | 29 - tests/extmod 2/ure1.py | 103 --- tests/extmod 2/ure_debug.py.exp | 15 - tests/extmod 2/ure_error.py | 25 - tests/extmod 2/ure_namedclass.py | 32 - tests/extmod 2/ure_stack_overflow.py.exp | 1 - tests/extmod 2/ure_sub_unmatched.py.exp | 1 - tests/extmod 2/ussl_basic.py | 59 -- tests/extmod 2/utimeq1.py | 137 ---- tests/extmod 2/utimeq_stable.py.exp | 1 - tests/extmod 2/uzlib_decompio.py | 33 - tests/extmod 2/uzlib_decompio_gz.py.exp | 13 - tests/extmod 2/vfs_fat_fileio1.py | 139 ---- tests/extmod 2/vfs_fat_fileio1.py.exp | 18 - tests/extmod 2/vfs_fat_more.py.exp | 29 - tests/extmod 2/vfs_fat_oldproto.py.exp | 3 - tests/extmod 2/vfs_fat_ramdisk.py.exp | 17 - tests/extmod 2/websocket_basic.py.exp | 14 - tests/feature_check 2/README | 4 - tests/feature_check 2/async_check.py | 3 - tests/feature_check 2/async_check.py.exp | 0 tests/feature_check 2/byteorder.py | 2 - tests/feature_check 2/byteorder.py.exp | 0 tests/feature_check 2/complex.py | 5 - tests/feature_check 2/complex.py.exp | 0 tests/feature_check 2/const.py | 1 - tests/feature_check 2/const.py.exp | 0 tests/feature_check 2/coverage.py | 5 - tests/feature_check 2/coverage.py.exp | 0 tests/feature_check 2/float.py | 13 - tests/feature_check 2/float.py.exp | 1 - tests/feature_check 2/int_big.py | 2 - tests/feature_check 2/int_big.py.exp | 1 - tests/feature_check 2/native_check.py | 4 - tests/feature_check 2/native_check.py.exp | 0 tests/feature_check 2/repl_emacs_check.py | 3 - tests/feature_check 2/repl_emacs_check.py.exp | 7 - tests/feature_check 2/reverse_ops.py | 9 - tests/feature_check 2/reverse_ops.py.exp | 0 tests/feature_check 2/set_check.py | 2 - tests/feature_check 2/set_check.py.exp | 0 tests/float 2/array_construct.py | 10 - tests/float 2/builtin_float_hash.py | 25 - tests/float 2/builtin_float_minmax.py | 31 - tests/float 2/builtin_float_pow.py | 11 - tests/float 2/builtin_float_round.py | 24 - tests/float 2/builtin_float_round_intbig.py | 4 - tests/float 2/bytearray_construct.py | 9 - tests/float 2/bytes_construct.py | 9 - tests/float 2/cmath_fun.py | 55 -- tests/float 2/cmath_fun_special.py | 31 - tests/float 2/complex1.py | 116 ---- tests/float 2/complex1_intbig.py | 4 - tests/float 2/float1.py | 119 ---- tests/float 2/float2int_doubleprec_intbig.py | 100 --- tests/float 2/float2int_fp30_intbig.py | 97 --- tests/float 2/float2int_intbig.py | 99 --- tests/float 2/float_array.py | 20 - tests/float 2/float_compare.py | 22 - tests/float 2/float_divmod.py | 25 - tests/float 2/float_divmod_relaxed.py | 33 - tests/float 2/float_format.py | 19 - tests/float 2/float_parse.py | 32 - tests/float 2/float_parse_doubleprec.py | 21 - tests/float 2/float_struct.py | 17 - tests/float 2/int_big_float.py | 28 - tests/float 2/int_divzero.py | 9 - tests/float 2/int_power.py | 8 - tests/float 2/list_index.py | 8 - tests/float 2/math_domain.py | 51 -- tests/float 2/math_domain_special.py | 36 - tests/float 2/math_fun.py | 63 -- tests/float 2/math_fun_bool.py | 16 - tests/float 2/math_fun_int.py | 14 - tests/float 2/math_fun_intbig.py | 11 - tests/float 2/math_fun_special.py | 35 - tests/float 2/python36.py | 10 - tests/float 2/python36.py.exp | 5 - tests/float 2/string_format.py | 41 -- tests/float 2/string_format2.py | 106 --- tests/float 2/string_format_fp30.py | 41 -- tests/float 2/string_format_modulo.py | 49 -- tests/float 2/string_format_modulo2.py | 24 - tests/float 2/string_format_modulo2_intbig.py | 21 - tests/float 2/string_format_modulo3.py | 3 - tests/float 2/string_format_modulo3.py.exp | 2 - tests/float 2/true_value.py | 7 - tests/float 2/types.py | 17 - tests/inlineasm 2/asmargs.py | 29 - tests/inlineasm 2/asmargs.py.exp | 5 - tests/inlineasm 2/asmbcc.py | 27 - tests/inlineasm 2/asmbcc.py.exp | 4 - tests/inlineasm 2/asmbitops.py | 13 - tests/inlineasm 2/asmbitops.py.exp | 4 - tests/inlineasm 2/asmblbx.py | 21 - tests/inlineasm 2/asmblbx.py.exp | 2 - tests/inlineasm 2/asmconst.py | 8 - tests/inlineasm 2/asmconst.py.exp | 1 - tests/inlineasm 2/asmdiv.py | 16 - tests/inlineasm 2/asmdiv.py.exp | 7 - tests/inlineasm 2/asmfpaddsub.py | 14 - tests/inlineasm 2/asmfpaddsub.py.exp | 1 - tests/inlineasm 2/asmfpcmp.py | 14 - tests/inlineasm 2/asmfpcmp.py.exp | 3 - tests/inlineasm 2/asmfpldrstr.py | 11 - tests/inlineasm 2/asmfpldrstr.py.exp | 1 - tests/inlineasm 2/asmfpmuldiv.py | 14 - tests/inlineasm 2/asmfpmuldiv.py.exp | 1 - tests/inlineasm 2/asmfpsqrt.py | 14 - tests/inlineasm 2/asmfpsqrt.py.exp | 1 - tests/inlineasm 2/asmit.py | 16 - tests/inlineasm 2/asmit.py.exp | 2 - tests/inlineasm 2/asmpushpop.py | 8 - tests/inlineasm 2/asmpushpop.py.exp | 1 - tests/inlineasm 2/asmrettype.py | 21 - tests/inlineasm 2/asmrettype.py.exp | 4 - tests/inlineasm 2/asmshift.py | 29 - tests/inlineasm 2/asmshift.py.exp | 6 - tests/inlineasm 2/asmspecialregs.py | 10 - tests/inlineasm 2/asmspecialregs.py.exp | 2 - tests/inlineasm 2/asmsum.py | 57 -- tests/inlineasm 2/asmsum.py.exp | 2 - tests/jni 2/README | 11 - tests/jni 2/list.py | 15 - tests/jni 2/list.py.exp | 4 - tests/jni 2/object.py | 15 - tests/jni 2/object.py.exp | 3 - tests/jni 2/system_out.py | 8 - tests/jni 2/system_out.py.exp | 1 - tests/net_hosted 2/README | 11 - tests/net_hosted 2/accept_nonblock.py | 16 - tests/net_hosted 2/accept_nonblock.py.exp | 1 - tests/net_hosted 2/accept_timeout.py | 22 - tests/net_hosted 2/accept_timeout.py.exp | 1 - tests/net_hosted 2/connect_nonblock.py | 20 - tests/net_hosted 2/connect_nonblock.py.exp | 1 - tests/net_hosted 2/connect_poll.py | 32 - tests/net_hosted 2/connect_poll.py.exp | 3 - tests/net_hosted 2/ssl_getpeercert.py | 21 - tests/net_hosted 2/ssl_getpeercert.py.exp | 1 - tests/net_inet 2/README | 5 - tests/net_inet 2/test_tls_sites.py | 59 -- tests/net_inet 2/test_tls_sites.py.exp | 5 - tests/run-bench-tests 2 | 97 --- tests/run-tests 2 | 615 ------------------ tests/stress 2/dict_copy.py | 7 - tests/stress 2/dict_create.py | 8 - tests/stress 2/dict_create_max.py | 13 - tests/stress 2/gc_trace.py | 17 - tests/stress 2/list_sort.py | 6 - tests/stress 2/recursion.py | 7 - tests/stress 2/recursive_data.py | 13 - tests/stress 2/recursive_data.py.exp | 1 - tests/stress 2/recursive_gen.py | 18 - tests/stress 2/recursive_iternext.py | 57 -- tests/stress 2/recursive_iternext.py.exp | 4 - tests/thread 2/mutate_bytearray.py | 46 -- tests/thread 2/mutate_dict.py | 44 -- tests/thread 2/mutate_instance.py | 45 -- tests/thread 2/mutate_list.py | 46 -- tests/thread 2/mutate_set.py | 39 -- tests/thread 2/stress_aes.py | 257 -------- tests/thread 2/stress_create.py | 22 - tests/thread 2/stress_heap.py | 48 -- tests/thread 2/stress_recurse.py | 27 - tests/thread 2/thread_exc1.py | 32 - tests/thread 2/thread_exc2.py | 10 - tests/thread 2/thread_exc2.py.exp | 5 - tests/thread 2/thread_exit1.py | 21 - tests/thread 2/thread_exit2.py | 21 - tests/thread 2/thread_gc1.py | 36 - tests/thread 2/thread_ident1.py | 23 - tests/thread 2/thread_lock1.py | 48 -- tests/thread 2/thread_lock2.py | 26 - tests/thread 2/thread_lock3.py | 29 - tests/thread 2/thread_lock4.py | 53 -- tests/thread 2/thread_qstr1.py | 41 -- tests/thread 2/thread_shared1.py | 33 - tests/thread 2/thread_shared2.py | 34 - tests/thread 2/thread_sleep1.py | 33 - tests/thread 2/thread_stacksize1.py | 49 -- tests/thread 2/thread_start1.py | 25 - tests/thread 2/thread_start2.py | 28 - tests/unix 2/extra_coverage.py | 74 --- tests/unix 2/extra_coverage.py.exp | 106 --- tests/unix 2/ffi_callback.py | 33 - tests/unix 2/ffi_callback.py.exp | 2 - tests/unix 2/ffi_float.py | 32 - tests/unix 2/ffi_float.py.exp | 8 - tests/unix 2/ffi_float2.py | 31 - tests/unix 2/ffi_float2.py.exp | 6 - 227 files changed, 6257 deletions(-) delete mode 100644 tests/README 2 delete mode 100644 tests/extmod 2/btree1.py delete mode 100644 tests/extmod 2/framebuf1.py delete mode 100644 tests/extmod 2/framebuf16.py delete mode 100644 tests/extmod 2/framebuf2.py.exp delete mode 100644 tests/extmod 2/framebuf4.py delete mode 100644 tests/extmod 2/framebuf_subclass.py delete mode 100644 tests/extmod 2/machine1.py delete mode 100644 tests/extmod 2/machine_pinbase.py delete mode 100644 tests/extmod 2/machine_pinbase.py.exp delete mode 100644 tests/extmod 2/ticks_diff.py delete mode 100644 tests/extmod 2/time_ms_us.py delete mode 100644 tests/extmod 2/time_ms_us.py.exp delete mode 100644 tests/extmod 2/ubinascii_a2b_base64.py delete mode 100644 tests/extmod 2/ubinascii_hexlify.py delete mode 100644 tests/extmod 2/uctypes_32bit_intbig.py.exp delete mode 100644 tests/extmod 2/uctypes_array_assign_native_le.py delete mode 100644 tests/extmod 2/uctypes_array_assign_native_le.py.exp delete mode 100644 tests/extmod 2/uctypes_array_assign_native_le_intbig.py delete mode 100644 tests/extmod 2/uctypes_bytearray.py delete mode 100644 tests/extmod 2/uctypes_byteat.py delete mode 100644 tests/extmod 2/uctypes_byteat.py.exp delete mode 100644 tests/extmod 2/uctypes_error.py delete mode 100644 tests/extmod 2/uctypes_error.py.exp delete mode 100644 tests/extmod 2/uctypes_le_float.py delete mode 100644 tests/extmod 2/uctypes_native_float.py delete mode 100644 tests/extmod 2/uctypes_ptr_le.py delete mode 100644 tests/extmod 2/uctypes_ptr_native_le.py.exp delete mode 100644 tests/extmod 2/uctypes_sizeof.py.exp delete mode 100644 tests/extmod 2/uhashlib_sha1.py delete mode 100644 tests/extmod 2/ujson_dump.py delete mode 100644 tests/extmod 2/ujson_dumps_extra.py delete mode 100644 tests/extmod 2/ujson_dumps_float.py delete mode 100644 tests/extmod 2/ujson_load_readinto.py.exp delete mode 100644 tests/extmod 2/ujson_loads.py delete mode 100644 tests/extmod 2/ujson_loads_float.py delete mode 100644 tests/extmod 2/urandom_basic.py delete mode 100644 tests/extmod 2/ure1.py delete mode 100644 tests/extmod 2/ure_debug.py.exp delete mode 100644 tests/extmod 2/ure_error.py delete mode 100644 tests/extmod 2/ure_namedclass.py delete mode 100644 tests/extmod 2/ure_stack_overflow.py.exp delete mode 100644 tests/extmod 2/ure_sub_unmatched.py.exp delete mode 100644 tests/extmod 2/ussl_basic.py delete mode 100644 tests/extmod 2/utimeq1.py delete mode 100644 tests/extmod 2/utimeq_stable.py.exp delete mode 100644 tests/extmod 2/uzlib_decompio.py delete mode 100644 tests/extmod 2/uzlib_decompio_gz.py.exp delete mode 100644 tests/extmod 2/vfs_fat_fileio1.py delete mode 100644 tests/extmod 2/vfs_fat_fileio1.py.exp delete mode 100644 tests/extmod 2/vfs_fat_more.py.exp delete mode 100644 tests/extmod 2/vfs_fat_oldproto.py.exp delete mode 100644 tests/extmod 2/vfs_fat_ramdisk.py.exp delete mode 100644 tests/extmod 2/websocket_basic.py.exp delete mode 100644 tests/feature_check 2/README delete mode 100644 tests/feature_check 2/async_check.py delete mode 100644 tests/feature_check 2/async_check.py.exp delete mode 100644 tests/feature_check 2/byteorder.py delete mode 100644 tests/feature_check 2/byteorder.py.exp delete mode 100644 tests/feature_check 2/complex.py delete mode 100644 tests/feature_check 2/complex.py.exp delete mode 100644 tests/feature_check 2/const.py delete mode 100644 tests/feature_check 2/const.py.exp delete mode 100644 tests/feature_check 2/coverage.py delete mode 100644 tests/feature_check 2/coverage.py.exp delete mode 100644 tests/feature_check 2/float.py delete mode 100644 tests/feature_check 2/float.py.exp delete mode 100644 tests/feature_check 2/int_big.py delete mode 100644 tests/feature_check 2/int_big.py.exp delete mode 100644 tests/feature_check 2/native_check.py delete mode 100644 tests/feature_check 2/native_check.py.exp delete mode 100644 tests/feature_check 2/repl_emacs_check.py delete mode 100644 tests/feature_check 2/repl_emacs_check.py.exp delete mode 100644 tests/feature_check 2/reverse_ops.py delete mode 100644 tests/feature_check 2/reverse_ops.py.exp delete mode 100644 tests/feature_check 2/set_check.py delete mode 100644 tests/feature_check 2/set_check.py.exp delete mode 100644 tests/float 2/array_construct.py delete mode 100644 tests/float 2/builtin_float_hash.py delete mode 100644 tests/float 2/builtin_float_minmax.py delete mode 100644 tests/float 2/builtin_float_pow.py delete mode 100644 tests/float 2/builtin_float_round.py delete mode 100644 tests/float 2/builtin_float_round_intbig.py delete mode 100644 tests/float 2/bytearray_construct.py delete mode 100644 tests/float 2/bytes_construct.py delete mode 100644 tests/float 2/cmath_fun.py delete mode 100644 tests/float 2/cmath_fun_special.py delete mode 100644 tests/float 2/complex1.py delete mode 100644 tests/float 2/complex1_intbig.py delete mode 100644 tests/float 2/float1.py delete mode 100644 tests/float 2/float2int_doubleprec_intbig.py delete mode 100644 tests/float 2/float2int_fp30_intbig.py delete mode 100644 tests/float 2/float2int_intbig.py delete mode 100644 tests/float 2/float_array.py delete mode 100644 tests/float 2/float_compare.py delete mode 100644 tests/float 2/float_divmod.py delete mode 100644 tests/float 2/float_divmod_relaxed.py delete mode 100644 tests/float 2/float_format.py delete mode 100644 tests/float 2/float_parse.py delete mode 100644 tests/float 2/float_parse_doubleprec.py delete mode 100644 tests/float 2/float_struct.py delete mode 100644 tests/float 2/int_big_float.py delete mode 100644 tests/float 2/int_divzero.py delete mode 100644 tests/float 2/int_power.py delete mode 100644 tests/float 2/list_index.py delete mode 100644 tests/float 2/math_domain.py delete mode 100644 tests/float 2/math_domain_special.py delete mode 100644 tests/float 2/math_fun.py delete mode 100644 tests/float 2/math_fun_bool.py delete mode 100644 tests/float 2/math_fun_int.py delete mode 100644 tests/float 2/math_fun_intbig.py delete mode 100644 tests/float 2/math_fun_special.py delete mode 100644 tests/float 2/python36.py delete mode 100644 tests/float 2/python36.py.exp delete mode 100644 tests/float 2/string_format.py delete mode 100644 tests/float 2/string_format2.py delete mode 100644 tests/float 2/string_format_fp30.py delete mode 100644 tests/float 2/string_format_modulo.py delete mode 100644 tests/float 2/string_format_modulo2.py delete mode 100644 tests/float 2/string_format_modulo2_intbig.py delete mode 100644 tests/float 2/string_format_modulo3.py delete mode 100644 tests/float 2/string_format_modulo3.py.exp delete mode 100644 tests/float 2/true_value.py delete mode 100644 tests/float 2/types.py delete mode 100644 tests/inlineasm 2/asmargs.py delete mode 100644 tests/inlineasm 2/asmargs.py.exp delete mode 100644 tests/inlineasm 2/asmbcc.py delete mode 100644 tests/inlineasm 2/asmbcc.py.exp delete mode 100644 tests/inlineasm 2/asmbitops.py delete mode 100644 tests/inlineasm 2/asmbitops.py.exp delete mode 100644 tests/inlineasm 2/asmblbx.py delete mode 100644 tests/inlineasm 2/asmblbx.py.exp delete mode 100644 tests/inlineasm 2/asmconst.py delete mode 100644 tests/inlineasm 2/asmconst.py.exp delete mode 100644 tests/inlineasm 2/asmdiv.py delete mode 100644 tests/inlineasm 2/asmdiv.py.exp delete mode 100644 tests/inlineasm 2/asmfpaddsub.py delete mode 100644 tests/inlineasm 2/asmfpaddsub.py.exp delete mode 100644 tests/inlineasm 2/asmfpcmp.py delete mode 100644 tests/inlineasm 2/asmfpcmp.py.exp delete mode 100644 tests/inlineasm 2/asmfpldrstr.py delete mode 100644 tests/inlineasm 2/asmfpldrstr.py.exp delete mode 100644 tests/inlineasm 2/asmfpmuldiv.py delete mode 100644 tests/inlineasm 2/asmfpmuldiv.py.exp delete mode 100644 tests/inlineasm 2/asmfpsqrt.py delete mode 100644 tests/inlineasm 2/asmfpsqrt.py.exp delete mode 100644 tests/inlineasm 2/asmit.py delete mode 100644 tests/inlineasm 2/asmit.py.exp delete mode 100644 tests/inlineasm 2/asmpushpop.py delete mode 100644 tests/inlineasm 2/asmpushpop.py.exp delete mode 100644 tests/inlineasm 2/asmrettype.py delete mode 100644 tests/inlineasm 2/asmrettype.py.exp delete mode 100644 tests/inlineasm 2/asmshift.py delete mode 100644 tests/inlineasm 2/asmshift.py.exp delete mode 100644 tests/inlineasm 2/asmspecialregs.py delete mode 100644 tests/inlineasm 2/asmspecialregs.py.exp delete mode 100644 tests/inlineasm 2/asmsum.py delete mode 100644 tests/inlineasm 2/asmsum.py.exp delete mode 100644 tests/jni 2/README delete mode 100644 tests/jni 2/list.py delete mode 100644 tests/jni 2/list.py.exp delete mode 100644 tests/jni 2/object.py delete mode 100644 tests/jni 2/object.py.exp delete mode 100644 tests/jni 2/system_out.py delete mode 100644 tests/jni 2/system_out.py.exp delete mode 100644 tests/net_hosted 2/README delete mode 100644 tests/net_hosted 2/accept_nonblock.py delete mode 100644 tests/net_hosted 2/accept_nonblock.py.exp delete mode 100644 tests/net_hosted 2/accept_timeout.py delete mode 100644 tests/net_hosted 2/accept_timeout.py.exp delete mode 100644 tests/net_hosted 2/connect_nonblock.py delete mode 100644 tests/net_hosted 2/connect_nonblock.py.exp delete mode 100644 tests/net_hosted 2/connect_poll.py delete mode 100644 tests/net_hosted 2/connect_poll.py.exp delete mode 100644 tests/net_hosted 2/ssl_getpeercert.py delete mode 100644 tests/net_hosted 2/ssl_getpeercert.py.exp delete mode 100644 tests/net_inet 2/README delete mode 100644 tests/net_inet 2/test_tls_sites.py delete mode 100644 tests/net_inet 2/test_tls_sites.py.exp delete mode 100755 tests/run-bench-tests 2 delete mode 100755 tests/run-tests 2 delete mode 100644 tests/stress 2/dict_copy.py delete mode 100644 tests/stress 2/dict_create.py delete mode 100644 tests/stress 2/dict_create_max.py delete mode 100644 tests/stress 2/gc_trace.py delete mode 100644 tests/stress 2/list_sort.py delete mode 100644 tests/stress 2/recursion.py delete mode 100644 tests/stress 2/recursive_data.py delete mode 100644 tests/stress 2/recursive_data.py.exp delete mode 100644 tests/stress 2/recursive_gen.py delete mode 100644 tests/stress 2/recursive_iternext.py delete mode 100644 tests/stress 2/recursive_iternext.py.exp delete mode 100644 tests/thread 2/mutate_bytearray.py delete mode 100644 tests/thread 2/mutate_dict.py delete mode 100644 tests/thread 2/mutate_instance.py delete mode 100644 tests/thread 2/mutate_list.py delete mode 100644 tests/thread 2/mutate_set.py delete mode 100644 tests/thread 2/stress_aes.py delete mode 100644 tests/thread 2/stress_create.py delete mode 100644 tests/thread 2/stress_heap.py delete mode 100644 tests/thread 2/stress_recurse.py delete mode 100644 tests/thread 2/thread_exc1.py delete mode 100644 tests/thread 2/thread_exc2.py delete mode 100644 tests/thread 2/thread_exc2.py.exp delete mode 100644 tests/thread 2/thread_exit1.py delete mode 100644 tests/thread 2/thread_exit2.py delete mode 100644 tests/thread 2/thread_gc1.py delete mode 100644 tests/thread 2/thread_ident1.py delete mode 100644 tests/thread 2/thread_lock1.py delete mode 100644 tests/thread 2/thread_lock2.py delete mode 100644 tests/thread 2/thread_lock3.py delete mode 100644 tests/thread 2/thread_lock4.py delete mode 100644 tests/thread 2/thread_qstr1.py delete mode 100644 tests/thread 2/thread_shared1.py delete mode 100644 tests/thread 2/thread_shared2.py delete mode 100644 tests/thread 2/thread_sleep1.py delete mode 100644 tests/thread 2/thread_stacksize1.py delete mode 100644 tests/thread 2/thread_start1.py delete mode 100644 tests/thread 2/thread_start2.py delete mode 100644 tests/unix 2/extra_coverage.py delete mode 100644 tests/unix 2/extra_coverage.py.exp delete mode 100644 tests/unix 2/ffi_callback.py delete mode 100644 tests/unix 2/ffi_callback.py.exp delete mode 100644 tests/unix 2/ffi_float.py delete mode 100644 tests/unix 2/ffi_float.py.exp delete mode 100644 tests/unix 2/ffi_float2.py delete mode 100644 tests/unix 2/ffi_float2.py.exp diff --git a/tests/README 2 b/tests/README 2 deleted file mode 100644 index 3458f36a80..0000000000 --- a/tests/README 2 +++ /dev/null @@ -1,18 +0,0 @@ -This directory contains tests for various functionality areas of MicroPython. -To run all stable tests, run "run-tests" script in this directory. - -Tests of capabilities not supported on all platforms should be written -to check for the capability being present. If it is not, the test -should merely output 'SKIP' followed by the line terminator, and call -sys.exit() to raise SystemExit, instead of attempting to test the -missing capability. The testing framework (run-tests in this -directory, test_main.c in qemu_arm) recognizes this as a skipped test. - -There are a few features for which this mechanism cannot be used to -condition a test. The run-tests script uses small scripts in the -feature_check directory to check whether each such feature is present, -and skips the relevant tests if not. - -When creating new tests, anything that relies on float support should go in the -float/ subdirectory. Anything that relies on import x, where x is not a built-in -module, should go in the import/ subdirectory. diff --git a/tests/extmod 2/btree1.py b/tests/extmod 2/btree1.py deleted file mode 100644 index 59638ef0a4..0000000000 --- a/tests/extmod 2/btree1.py +++ /dev/null @@ -1,89 +0,0 @@ -try: - import btree - import uio - import uerrno -except ImportError: - print("SKIP") - raise SystemExit - -#f = open("_test.db", "w+b") -f = uio.BytesIO() -db = btree.open(f, pagesize=512) - -db[b"foo3"] = b"bar3" -db[b"foo1"] = b"bar1" -db[b"foo2"] = b"bar2" -db[b"bar1"] = b"foo1" - -dbstr = str(db) -print(dbstr[:7], dbstr[-1:]) - -print(db[b"foo2"]) -try: - print(db[b"foo"]) -except KeyError: - print("KeyError") -print(db.get(b"foo")) -print(db.get(b"foo", b"dflt")) - -del db[b"foo2"] -try: - del db[b"foo"] -except KeyError: - print("KeyError") - -for k, v in db.items(): - print((k, v)) - -print("---") -for k, v in db.items(None, None): - print((k, v)) - -print("---") -for k, v in db.items(b"f"): - print((k, v)) - -print("---") -for k, v in db.items(b"f", b"foo3"): - print((k, v)) - -print("---") -for k, v in db.items(None, b"foo3"): - print((k, v)) - -print("---") -for k, v in db.items(b"f", b"foo3", btree.INCL): - print((k, v)) - -print("---") -for k, v in db.items(None, None, btree.DESC): - print((k, v)) - -print(db.seq(1, b"foo1")) -print(db.seq(1, b"qux")) - -try: - db.seq(b"foo1") -except OSError as e: - print(e.args[0] == uerrno.EINVAL) - -print(list(db.keys())) -print(list(db.values())) - -for k in db: - print(k) - -db.put(b"baz1", b"qux1") - -print("foo1", "foo1" in db) -print("foo2", "foo2" in db) -print("baz1", "baz1" in db) - -try: - print(db + db[b"foo1"]) -except TypeError: - print("TypeError") - -db.flush() -db.close() -f.close() diff --git a/tests/extmod 2/framebuf1.py b/tests/extmod 2/framebuf1.py deleted file mode 100644 index 2c13665228..0000000000 --- a/tests/extmod 2/framebuf1.py +++ /dev/null @@ -1,109 +0,0 @@ -try: - import framebuf -except ImportError: - print("SKIP") - raise SystemExit - -w = 5 -h = 16 -size = w * h // 8 -buf = bytearray(size) -maps = {framebuf.MONO_VLSB : 'MONO_VLSB', - framebuf.MONO_HLSB : 'MONO_HLSB', - framebuf.MONO_HMSB : 'MONO_HMSB'} - -for mapping in maps.keys(): - for x in range(size): - buf[x] = 0 - fbuf = framebuf.FrameBuffer(buf, w, h, mapping) - print(maps[mapping]) - # access as buffer - print(memoryview(fbuf)[0]) - - # fill - fbuf.fill(1) - print(buf) - fbuf.fill(0) - print(buf) - - # put pixel - fbuf.pixel(0, 0, 1) - fbuf.pixel(4, 0, 1) - fbuf.pixel(0, 15, 1) - fbuf.pixel(4, 15, 1) - print(buf) - - # clear pixel - fbuf.pixel(4, 15, 0) - print(buf) - - # get pixel - print(fbuf.pixel(0, 0), fbuf.pixel(1, 1)) - - # hline - fbuf.fill(0) - fbuf.hline(0, 1, w, 1) - print('hline', buf) - - # vline - fbuf.fill(0) - fbuf.vline(1, 0, h, 1) - print('vline', buf) - - # rect - fbuf.fill(0) - fbuf.rect(1, 1, 3, 3, 1) - print('rect', buf) - - #fill rect - fbuf.fill(0) - fbuf.fill_rect(0, 0, 0, 3, 1) # zero width, no-operation - fbuf.fill_rect(1, 1, 3, 3, 1) - print('fill_rect', buf) - - # line - fbuf.fill(0) - fbuf.line(1, 1, 3, 3, 1) - print('line', buf) - - # line steep negative gradient - fbuf.fill(0) - fbuf.line(3, 3, 2, 1, 1) - print('line', buf) - - # scroll - fbuf.fill(0) - fbuf.pixel(2, 7, 1) - fbuf.scroll(0, 1) - print(buf) - fbuf.scroll(0, -2) - print(buf) - fbuf.scroll(1, 0) - print(buf) - fbuf.scroll(-1, 0) - print(buf) - fbuf.scroll(2, 2) - print(buf) - - # print text - fbuf.fill(0) - fbuf.text("hello", 0, 0, 1) - print(buf) - fbuf.text("hello", 0, 0, 0) # clear - print(buf) - - # char out of font range set to chr(127) - fbuf.text(str(chr(31)), 0, 0) - print(buf) - print() - -# test invalid constructor, and stride argument -try: - fbuf = framebuf.FrameBuffer(buf, w, h, -1, w) -except ValueError: - print("ValueError") - -# test legacy constructor -fbuf = framebuf.FrameBuffer1(buf, w, h) -fbuf = framebuf.FrameBuffer1(buf, w, h, w) -print(framebuf.MVLSB == framebuf.MONO_VLSB) diff --git a/tests/extmod 2/framebuf16.py b/tests/extmod 2/framebuf16.py deleted file mode 100644 index fe81f7f93f..0000000000 --- a/tests/extmod 2/framebuf16.py +++ /dev/null @@ -1,59 +0,0 @@ -try: - import framebuf -except ImportError: - print("SKIP") - raise SystemExit - -def printbuf(): - print("--8<--") - for y in range(h): - print(buf[y * w * 2:(y + 1) * w * 2]) - print("-->8--") - -w = 4 -h = 5 -buf = bytearray(w * h * 2) -fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.RGB565) - -# fill -fbuf.fill(0xffff) -printbuf() -fbuf.fill(0x0000) -printbuf() - -# put pixel -fbuf.pixel(0, 0, 0xeeee) -fbuf.pixel(3, 0, 0xee00) -fbuf.pixel(0, 4, 0x00ee) -fbuf.pixel(3, 4, 0x0ee0) -printbuf() - -# get pixel -print(fbuf.pixel(0, 4), fbuf.pixel(1, 1)) - -# scroll -fbuf.fill(0x0000) -fbuf.pixel(2, 2, 0xffff) -printbuf() -fbuf.scroll(0, 1) -printbuf() -fbuf.scroll(1, 0) -printbuf() -fbuf.scroll(-1, -2) -printbuf() - -w2 = 2 -h2 = 3 -buf2 = bytearray(w2 * h2 * 2) -fbuf2 = framebuf.FrameBuffer(buf2, w2, h2, framebuf.RGB565) - -fbuf2.fill(0x0000) -fbuf2.pixel(0, 0, 0x0ee0) -fbuf2.pixel(0, 2, 0xee00) -fbuf2.pixel(1, 0, 0x00ee) -fbuf2.pixel(1, 2, 0xe00e) -fbuf.fill(0xffff) -fbuf.blit(fbuf2, 3, 3, 0x0000) -fbuf.blit(fbuf2, -1, -1, 0x0000) -fbuf.blit(fbuf2, 16, 16, 0x0000) -printbuf() diff --git a/tests/extmod 2/framebuf2.py.exp b/tests/extmod 2/framebuf2.py.exp deleted file mode 100644 index c53e518a6e..0000000000 --- a/tests/extmod 2/framebuf2.py.exp +++ /dev/null @@ -1,57 +0,0 @@ ---8<-- -33333333 -33333333 -33333333 -33333333 -33333333 --->8-- ---8<-- -00000000 -00000000 -00000000 -00000000 -00000000 --->8-- ---8<-- -10020000 -00000000 -00000000 -00000000 -30020000 --->8-- -3 0 ---8<-- -00000000 -00000000 -00300000 -00000000 -00000000 --->8-- ---8<-- -00000000 -00000000 -00000000 -00300000 -00000000 --->8-- ---8<-- -00000000 -00000000 -00000000 -00030000 -00000000 --->8-- ---8<-- -00000000 -00300000 -00000000 -00030000 -00000000 --->8-- ---8<-- -33333333 -23333333 -33333333 -33311333 -33333333 --->8-- diff --git a/tests/extmod 2/framebuf4.py b/tests/extmod 2/framebuf4.py deleted file mode 100644 index 8358fa55b9..0000000000 --- a/tests/extmod 2/framebuf4.py +++ /dev/null @@ -1,53 +0,0 @@ -try: - import framebuf -except ImportError: - print("SKIP") - raise SystemExit - -def printbuf(): - print("--8<--") - for y in range(h): - print(buf[y * w // 2:(y + 1) * w // 2]) - print("-->8--") - -w = 16 -h = 8 -buf = bytearray(w * h // 2) -fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.GS4_HMSB) - -# fill -fbuf.fill(0x0f) -printbuf() -fbuf.fill(0xa0) -printbuf() - -# put pixel -fbuf.pixel(0, 0, 0x01) -printbuf() -fbuf.pixel(w-1, 0, 0x02) -printbuf() -fbuf.pixel(w-1, h-1, 0x03) -printbuf() -fbuf.pixel(0, h-1, 0x04) -printbuf() - -# get pixel -print(fbuf.pixel(0, 0), fbuf.pixel(w-1, 0), fbuf.pixel(w-1, h-1), fbuf.pixel(0, h-1)) -print(fbuf.pixel(1, 0), fbuf.pixel(w-2, 0), fbuf.pixel(w-2, h-1), fbuf.pixel(1, h-1)) - -# fill rect -fbuf.fill_rect(0, 0, w, h, 0x0f) -printbuf() -fbuf.fill_rect(0, 0, w, h, 0xf0) -fbuf.fill_rect(1, 0, w//2+1, 1, 0xf1) -printbuf() -fbuf.fill_rect(1, 0, w//2+1, 1, 0x10) -fbuf.fill_rect(1, 0, w//2, 1, 0xf1) -printbuf() -fbuf.fill_rect(1, 0, w//2, 1, 0x10) -fbuf.fill_rect(0, h-4, w//2+1, 4, 0xaf) -printbuf() -fbuf.fill_rect(0, h-4, w//2+1, 4, 0xb0) -fbuf.fill_rect(0, h-4, w//2, 4, 0xaf) -printbuf() -fbuf.fill_rect(0, h-4, w//2, 4, 0xb0) diff --git a/tests/extmod 2/framebuf_subclass.py b/tests/extmod 2/framebuf_subclass.py deleted file mode 100644 index 6363c224fb..0000000000 --- a/tests/extmod 2/framebuf_subclass.py +++ /dev/null @@ -1,20 +0,0 @@ -# test subclassing framebuf.FrameBuffer - -try: - import framebuf -except ImportError: - print('SKIP') - raise SystemExit - -class FB(framebuf.FrameBuffer): - def __init__(self, n): - self.n = n - super().__init__(bytearray(2 * n * n), n, n, framebuf.RGB565) - - def foo(self): - self.hline(0, 2, self.n, 0x0304) - -fb = FB(n=3) -fb.pixel(0, 0, 0x0102) -fb.foo() -print(bytes(fb)) diff --git a/tests/extmod 2/machine1.py b/tests/extmod 2/machine1.py deleted file mode 100644 index 6ff38cc051..0000000000 --- a/tests/extmod 2/machine1.py +++ /dev/null @@ -1,28 +0,0 @@ -# test machine module - -try: - try: - import umachine as machine - except ImportError: - import machine - machine.mem8 -except: - print("SKIP") - raise SystemExit - -print(machine.mem8) - -try: - machine.mem16[1] -except ValueError: - print("ValueError") - -try: - machine.mem16[1] = 1 -except ValueError: - print("ValueError") - -try: - del machine.mem8[0] -except TypeError: - print("TypeError") diff --git a/tests/extmod 2/machine_pinbase.py b/tests/extmod 2/machine_pinbase.py deleted file mode 100644 index e91775504d..0000000000 --- a/tests/extmod 2/machine_pinbase.py +++ /dev/null @@ -1,30 +0,0 @@ -try: - import umachine as machine -except ImportError: - import machine -try: - machine.PinBase -except AttributeError: - print("SKIP") - raise SystemExit - - -class MyPin(machine.PinBase): - - def __init__(self): - print("__init__") - self.v = False - - def value(self, v=None): - print("value:", v) - if v is None: - self.v = not self.v - return int(self.v) - -p = MyPin() - -print(p.value()) -print(p.value()) -print(p.value()) -p.value(1) -p.value(0) diff --git a/tests/extmod 2/machine_pinbase.py.exp b/tests/extmod 2/machine_pinbase.py.exp deleted file mode 100644 index b31cd98308..0000000000 --- a/tests/extmod 2/machine_pinbase.py.exp +++ /dev/null @@ -1,9 +0,0 @@ -__init__ -value: None -1 -value: None -0 -value: None -1 -value: 1 -value: 0 diff --git a/tests/extmod 2/ticks_diff.py b/tests/extmod 2/ticks_diff.py deleted file mode 100644 index 4d8df83cf9..0000000000 --- a/tests/extmod 2/ticks_diff.py +++ /dev/null @@ -1,33 +0,0 @@ -from utime import ticks_diff, ticks_add - -MAX = ticks_add(0, -1) -# Should be done like this to avoid small int overflow -MODULO_HALF = MAX // 2 + 1 - -# Invariants: -# if ticks_diff(a, b) = c, -# then ticks_diff(b, a) = -c - -assert ticks_diff(1, 0) == 1, ticks_diff(1, 0) -assert ticks_diff(0, 1) == -1 - -assert ticks_diff(0, MAX) == 1 -assert ticks_diff(MAX, 0) == -1 - -assert ticks_diff(0, MAX - 1) == 2 - -# Maximum "positive" distance -assert ticks_diff(MODULO_HALF, 1) == MODULO_HALF - 1, ticks_diff(MODULO_HALF, 1) -# Step further, and it becomes a negative distance -assert ticks_diff(MODULO_HALF, 0) == -MODULO_HALF - -# Offsetting that in either direction doesn't affect the result -off = 100 -# Cheating and skipping to use ticks_add() when we know there's no wraparound -# Real apps should use always it. -assert ticks_diff(MODULO_HALF + off, 1 + off) == MODULO_HALF - 1 -assert ticks_diff(MODULO_HALF + off, 0 + off) == -MODULO_HALF -assert ticks_diff(MODULO_HALF - off, ticks_add(1, -off)) == MODULO_HALF - 1 -assert ticks_diff(MODULO_HALF - off, ticks_add(0, -off)) == -MODULO_HALF - -print("OK") diff --git a/tests/extmod 2/time_ms_us.py b/tests/extmod 2/time_ms_us.py deleted file mode 100644 index 135cf1e096..0000000000 --- a/tests/extmod 2/time_ms_us.py +++ /dev/null @@ -1,22 +0,0 @@ -import utime -try: - utime.sleep_ms -except AttributeError: - print("SKIP") - raise SystemExit - -utime.sleep_ms(1) -utime.sleep_us(1) - -t0 = utime.ticks_ms() -t1 = utime.ticks_ms() -print(0 <= utime.ticks_diff(t1, t0) <= 1) - -t0 = utime.ticks_us() -t1 = utime.ticks_us() -print(0 <= utime.ticks_diff(t1, t0) <= 500) - -# ticks_cpu may not be implemented, at least make sure it doesn't decrease -t0 = utime.ticks_cpu() -t1 = utime.ticks_cpu() -print(utime.ticks_diff(t1, t0) >= 0) diff --git a/tests/extmod 2/time_ms_us.py.exp b/tests/extmod 2/time_ms_us.py.exp deleted file mode 100644 index b8ca7e7ef0..0000000000 --- a/tests/extmod 2/time_ms_us.py.exp +++ /dev/null @@ -1,3 +0,0 @@ -True -True -True diff --git a/tests/extmod 2/ubinascii_a2b_base64.py b/tests/extmod 2/ubinascii_a2b_base64.py deleted file mode 100644 index 5e642ec515..0000000000 --- a/tests/extmod 2/ubinascii_a2b_base64.py +++ /dev/null @@ -1,49 +0,0 @@ -try: - try: - import ubinascii as binascii - except ImportError: - import binascii -except ImportError: - print("SKIP") - raise SystemExit - -print(binascii.a2b_base64(b'')) -print(binascii.a2b_base64(b'Zg==')) -print(binascii.a2b_base64(b'Zm8=')) -print(binascii.a2b_base64(b'Zm9v')) -print(binascii.a2b_base64(b'Zm9vYg==')) -print(binascii.a2b_base64(b'Zm9vYmE=')) -print(binascii.a2b_base64(b'Zm9vYmFy')) - -print(binascii.a2b_base64(b'AAECAwQFBgc=')) -print(binascii.a2b_base64(b'CAkKCwwNDg8=')) -print(binascii.a2b_base64(b'f4D/')) -print(binascii.a2b_base64(b'f4D+')) # convert '+' -print(binascii.a2b_base64(b'MTIzNEFCQ0RhYmNk')) - -# Ignore invalid characters and pad sequences -print(binascii.a2b_base64(b'Zm9v\n')) -print(binascii.a2b_base64(b'Zm\x009v\n')) -print(binascii.a2b_base64(b'Zm9v==')) -print(binascii.a2b_base64(b'Zm9v===')) -print(binascii.a2b_base64(b'Zm9v===YmFy')) - -# Unicode strings can be decoded -print(binascii.a2b_base64(u'Zm9v===YmFy')) - -try: - print(binascii.a2b_base64(b'abc')) -except ValueError: - print("ValueError") -try: - print(binascii.a2b_base64(b'abcde=')) -except ValueError: - print("ValueError") -try: - print(binascii.a2b_base64(b'ab*d')) -except ValueError: - print("ValueError") -try: - print(binascii.a2b_base64(b'ab=cdef=')) -except ValueError: - print("ValueError") diff --git a/tests/extmod 2/ubinascii_hexlify.py b/tests/extmod 2/ubinascii_hexlify.py deleted file mode 100644 index dabc3c7e4c..0000000000 --- a/tests/extmod 2/ubinascii_hexlify.py +++ /dev/null @@ -1,17 +0,0 @@ -try: - try: - import ubinascii as binascii - except ImportError: - import binascii -except ImportError: - print("SKIP") - raise SystemExit - -print(binascii.hexlify(b'\x00\x01\x02\x03\x04\x05\x06\x07')) -print(binascii.hexlify(b'\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f')) -print(binascii.hexlify(b'\x7f\x80\xff')) -print(binascii.hexlify(b'1234ABCDabcd')) -try: - binascii.hexlify('') -except TypeError: - print("TypeError") diff --git a/tests/extmod 2/uctypes_32bit_intbig.py.exp b/tests/extmod 2/uctypes_32bit_intbig.py.exp deleted file mode 100644 index d1fc1fe350..0000000000 --- a/tests/extmod 2/uctypes_32bit_intbig.py.exp +++ /dev/null @@ -1,11 +0,0 @@ -b'\xff\xff\xff\x7f5678abcd' -b'\x00\x00\x00\x805678abcd' -b'\x03\x02\x01\xff5678abcd' -b'\x03\x02\x01\xff\x00\x00\x00\x80\x00\x00\x00\x00' -b'\x03\x02\x01\xff\x00\x00\x00\x00\x01\x00\x00\x00' -= -b'\x7f\xff\xff\xff5678abcd' -b'\x80\x00\x00\x005678abcd' -b'\xff\x01\x02\x035678abcd' -b'\xff\x01\x02\x03\x00\x00\x00\x00\x80\x00\x00\x00' -b'\xff\x01\x02\x03\x00\x00\x00\x01\x00\x00\x00\x00' diff --git a/tests/extmod 2/uctypes_array_assign_native_le.py b/tests/extmod 2/uctypes_array_assign_native_le.py deleted file mode 100644 index a538bf9add..0000000000 --- a/tests/extmod 2/uctypes_array_assign_native_le.py +++ /dev/null @@ -1,89 +0,0 @@ -import sys -try: - import uctypes -except ImportError: - print("SKIP") - raise SystemExit - -if sys.byteorder != "little": - print("SKIP") - raise SystemExit - -desc = { - # arr is array at offset 0, of UINT8 elements, array size is 2 - "arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2), - # arr2 is array at offset 0, size 2, of structures defined recursively - "arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}), - "arr3": (uctypes.ARRAY | 2, uctypes.UINT16 | 2), - - # aligned - "arr5": (uctypes.ARRAY | 0, uctypes.UINT32 | 1), - "arr7": (uctypes.ARRAY | 0, 1, {"l": uctypes.UINT32 | 0}), - - "arr8": (uctypes.ARRAY | 0, uctypes.INT8 | 1), - "arr9": (uctypes.ARRAY | 0, uctypes.INT16 | 1), - "arr10": (uctypes.ARRAY | 0, uctypes.INT32 | 1), - "arr11": (uctypes.ARRAY | 0, uctypes.INT64 | 1), - "arr12": (uctypes.ARRAY | 0, uctypes.UINT64| 1), - "arr13": (uctypes.ARRAY | 1, 1, {"l": {}}), -} - -data = bytearray(8) - -S = uctypes.struct(uctypes.addressof(data), desc) - -# assign byte -S.arr[0] = 0x11 -print(hex(S.arr[0])) -assert hex(S.arr[0]) == "0x11" - -# assign word -S.arr3[0] = 0x2233 -print(hex(S.arr3[0])) -assert hex(S.arr3[0]) == "0x2233" - -# assign word, with index -S.arr3[1] = 0x4455 -print(hex(S.arr3[1])) -assert hex(S.arr3[1]) == "0x4455" - -# assign long, aligned -S.arr5[0] = 0x66778899 -print(hex(S.arr5[0])) -assert hex(S.arr5[0]) == "0x66778899" - -print(S.arr5[0] == S.arr7[0].l) -assert S.arr5[0] == S.arr7[0].l - -# assign int8 -S.arr8[0] = 0x11 -print(hex(S.arr8[0])) -assert hex(S.arr8[0]) == "0x11" - -# assign int16 -S.arr9[0] = 0x1122 -print(hex(S.arr9[0])) -assert hex(S.arr9[0]) == "0x1122" - -# assign int32 -S.arr10[0] = 0x11223344 -print(hex(S.arr10[0])) -assert hex(S.arr10[0]) == "0x11223344" - -# index out of range -try: - print(S.arr8[2]) -except IndexError: - print("IndexError") - -# syntax error in descriptor -try: - S.arr13[0].l = 0x11 -except TypeError: - print("TypeError") - -# operation not supported -try: - S.arr13[0] = 0x11 -except TypeError: - print("TypeError") diff --git a/tests/extmod 2/uctypes_array_assign_native_le.py.exp b/tests/extmod 2/uctypes_array_assign_native_le.py.exp deleted file mode 100644 index 9d67b1c777..0000000000 --- a/tests/extmod 2/uctypes_array_assign_native_le.py.exp +++ /dev/null @@ -1,11 +0,0 @@ -0x11 -0x2233 -0x4455 -0x66778899 -True -0x11 -0x1122 -0x11223344 -IndexError -TypeError -TypeError diff --git a/tests/extmod 2/uctypes_array_assign_native_le_intbig.py b/tests/extmod 2/uctypes_array_assign_native_le_intbig.py deleted file mode 100644 index 84dfba0e29..0000000000 --- a/tests/extmod 2/uctypes_array_assign_native_le_intbig.py +++ /dev/null @@ -1,43 +0,0 @@ -import sys -try: - import uctypes -except ImportError: - print("SKIP") - raise SystemExit - -if sys.byteorder != "little": - print("SKIP") - raise SystemExit - -desc = { - # arr is array at offset 0, of UINT8 elements, array size is 2 - "arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2), - # arr2 is array at offset 0, size 2, of structures defined recursively - "arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}), - "arr3": (uctypes.ARRAY | 2, uctypes.UINT16 | 2), - - # aligned - "arr5": (uctypes.ARRAY | 0, uctypes.UINT32 | 1), - "arr7": (uctypes.ARRAY | 0, 1, {"l": uctypes.UINT32 | 0}), - - "arr8": (uctypes.ARRAY | 0, uctypes.INT8 | 1), - "arr9": (uctypes.ARRAY | 0, uctypes.INT16 | 1), - "arr10": (uctypes.ARRAY | 0, uctypes.INT32 | 1), - "arr11": (uctypes.ARRAY | 0, uctypes.INT64 | 1), - "arr12": (uctypes.ARRAY | 0, uctypes.UINT64| 1), - "arr13": (uctypes.ARRAY | 1, 1, {"l": {}}), -} - -data = bytearray(8) - -S = uctypes.struct(uctypes.addressof(data), desc) - -# assign int64 -S.arr11[0] = 0x11223344 -print(hex(S.arr11[0])) -assert hex(S.arr11[0]) == "0x11223344" - -# assign uint64 -S.arr12[0] = 0x11223344 -print(hex(S.arr12[0])) -assert hex(S.arr12[0]) == "0x11223344" diff --git a/tests/extmod 2/uctypes_bytearray.py b/tests/extmod 2/uctypes_bytearray.py deleted file mode 100644 index 77c93c3766..0000000000 --- a/tests/extmod 2/uctypes_bytearray.py +++ /dev/null @@ -1,22 +0,0 @@ -try: - import uctypes -except ImportError: - print("SKIP") - raise SystemExit - -desc = { - "arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2), - "arr2": (uctypes.ARRAY | 2, uctypes.INT8 | 2), -} - -data = bytearray(b"01234567") - -S = uctypes.struct(uctypes.addressof(data), desc, uctypes.LITTLE_ENDIAN) - -# Arrays of UINT8 are accessed as bytearrays -print(S.arr) -# But not INT8, because value range is different -print(type(S.arr2)) - -# convert to buffer -print(bytearray(S)) diff --git a/tests/extmod 2/uctypes_byteat.py b/tests/extmod 2/uctypes_byteat.py deleted file mode 100644 index 784209f803..0000000000 --- a/tests/extmod 2/uctypes_byteat.py +++ /dev/null @@ -1,10 +0,0 @@ -try: - import uctypes -except ImportError: - print("SKIP") - raise SystemExit - -data = bytearray(b'01234567') - -print(uctypes.bytes_at(uctypes.addressof(data), 4)) -print(uctypes.bytearray_at(uctypes.addressof(data), 4)) diff --git a/tests/extmod 2/uctypes_byteat.py.exp b/tests/extmod 2/uctypes_byteat.py.exp deleted file mode 100644 index e1ae4d0534..0000000000 --- a/tests/extmod 2/uctypes_byteat.py.exp +++ /dev/null @@ -1,2 +0,0 @@ -b'0123' -bytearray(b'0123') diff --git a/tests/extmod 2/uctypes_error.py b/tests/extmod 2/uctypes_error.py deleted file mode 100644 index 2500e29278..0000000000 --- a/tests/extmod 2/uctypes_error.py +++ /dev/null @@ -1,37 +0,0 @@ -# test general errors with uctypes - -try: - import uctypes -except ImportError: - print("SKIP") - raise SystemExit - -data = bytearray(b"01234567") - -# del subscr not supported -S = uctypes.struct(uctypes.addressof(data), {}) -try: - del S[0] -except TypeError: - print('TypeError') - -# list is an invalid descriptor -S = uctypes.struct(uctypes.addressof(data), []) -try: - S.x -except TypeError: - print('TypeError') - -# can't access attribute with invalid descriptor -S = uctypes.struct(uctypes.addressof(data), {'x':[]}) -try: - S.x -except TypeError: - print('TypeError') - -# can't assign to aggregate -S = uctypes.struct(uctypes.addressof(data), {'x':(uctypes.ARRAY | 0, uctypes.INT8 | 2)}) -try: - S.x = 1 -except TypeError: - print('TypeError') diff --git a/tests/extmod 2/uctypes_error.py.exp b/tests/extmod 2/uctypes_error.py.exp deleted file mode 100644 index 802c260d2b..0000000000 --- a/tests/extmod 2/uctypes_error.py.exp +++ /dev/null @@ -1,4 +0,0 @@ -TypeError -TypeError -TypeError -TypeError diff --git a/tests/extmod 2/uctypes_le_float.py b/tests/extmod 2/uctypes_le_float.py deleted file mode 100644 index 84ff2b84cf..0000000000 --- a/tests/extmod 2/uctypes_le_float.py +++ /dev/null @@ -1,24 +0,0 @@ -try: - import uctypes -except ImportError: - print("SKIP") - raise SystemExit - -desc = { - "f32": uctypes.FLOAT32 | 0, - "f64": uctypes.FLOAT64 | 0, - "uf64": uctypes.FLOAT64 | 2, # unaligned -} - -data = bytearray(10) - -S = uctypes.struct(uctypes.addressof(data), desc, uctypes.LITTLE_ENDIAN) - -S.f32 = 12.34 -print('%.4f' % S.f32) - -S.f64 = 12.34 -print('%.4f' % S.f64) - -S.uf64 = 12.34 -print('%.4f' % S.uf64) diff --git a/tests/extmod 2/uctypes_native_float.py b/tests/extmod 2/uctypes_native_float.py deleted file mode 100644 index acef47036d..0000000000 --- a/tests/extmod 2/uctypes_native_float.py +++ /dev/null @@ -1,20 +0,0 @@ -try: - import uctypes -except ImportError: - print("SKIP") - raise SystemExit - -desc = { - "f32": uctypes.FLOAT32 | 0, - "f64": uctypes.FLOAT64 | 0, -} - -data = bytearray(8) - -S = uctypes.struct(uctypes.addressof(data), desc, uctypes.NATIVE) - -S.f32 = 12.34 -print('%.4f' % S.f32) - -S.f64 = 12.34 -print('%.4f' % S.f64) diff --git a/tests/extmod 2/uctypes_ptr_le.py b/tests/extmod 2/uctypes_ptr_le.py deleted file mode 100644 index 056e456506..0000000000 --- a/tests/extmod 2/uctypes_ptr_le.py +++ /dev/null @@ -1,34 +0,0 @@ -import sys -try: - import uctypes -except ImportError: - print("SKIP") - raise SystemExit - -if sys.byteorder != "little": - print("SKIP") - raise SystemExit - -desc = { - "ptr": (uctypes.PTR | 0, uctypes.UINT8), - "ptr16": (uctypes.PTR | 0, uctypes.UINT16), - "ptr2": (uctypes.PTR | 0, {"b": uctypes.UINT8 | 0}), -} - -bytes = b"01" - -addr = uctypes.addressof(bytes) -buf = addr.to_bytes(uctypes.sizeof(desc), "little") - -S = uctypes.struct(uctypes.addressof(buf), desc, uctypes.LITTLE_ENDIAN) - -print(S.ptr[0]) -assert S.ptr[0] == ord("0") -print(S.ptr[1]) -assert S.ptr[1] == ord("1") -print(hex(S.ptr16[0])) -assert hex(S.ptr16[0]) == "0x3130" -print(S.ptr2[0].b, S.ptr2[1].b) -print (S.ptr2[0].b, S.ptr2[1].b) -print(hex(S.ptr16[0])) -assert (S.ptr2[0].b, S.ptr2[1].b) == (48, 49) diff --git a/tests/extmod 2/uctypes_ptr_native_le.py.exp b/tests/extmod 2/uctypes_ptr_native_le.py.exp deleted file mode 100644 index 30d159edd1..0000000000 --- a/tests/extmod 2/uctypes_ptr_native_le.py.exp +++ /dev/null @@ -1,6 +0,0 @@ -48 -49 -0x3130 -48 49 -48 49 -0x3130 diff --git a/tests/extmod 2/uctypes_sizeof.py.exp b/tests/extmod 2/uctypes_sizeof.py.exp deleted file mode 100644 index b35b11aa0c..0000000000 --- a/tests/extmod 2/uctypes_sizeof.py.exp +++ /dev/null @@ -1,7 +0,0 @@ -2 -2 -4 -TypeError -6 -1 -TypeError diff --git a/tests/extmod 2/uhashlib_sha1.py b/tests/extmod 2/uhashlib_sha1.py deleted file mode 100644 index 9d6427b33f..0000000000 --- a/tests/extmod 2/uhashlib_sha1.py +++ /dev/null @@ -1,28 +0,0 @@ -try: - import uhashlib as hashlib -except ImportError: - try: - import hashlib - except ImportError: - # This is neither uPy, nor cPy, so must be uPy with - # uhashlib module disabled. - print("SKIP") - raise SystemExit - -try: - hashlib.sha1 -except AttributeError: - # SHA1 is only available on some ports - print("SKIP") - raise SystemExit - -sha1 = hashlib.sha1(b'hello') -sha1.update(b'world') -print(sha1.digest()) - -sha1 = hashlib.sha1(b'hello') -try: - sha1.update(u'world') -except TypeError as e: - print("TypeError") -print(sha1.digest()) diff --git a/tests/extmod 2/ujson_dump.py b/tests/extmod 2/ujson_dump.py deleted file mode 100644 index b1cb4a9cbc..0000000000 --- a/tests/extmod 2/ujson_dump.py +++ /dev/null @@ -1,30 +0,0 @@ -try: - from uio import StringIO - import ujson as json -except: - try: - from io import StringIO - import json - except ImportError: - print("SKIP") - raise SystemExit - -s = StringIO() -json.dump(False, s) -print(s.getvalue()) - -s = StringIO() -json.dump({"a": (2, [3, None])}, s) -print(s.getvalue()) - -# dump to a small-int not allowed -try: - json.dump(123, 1) -except (AttributeError, OSError): # CPython and uPy have different errors - print('Exception') - -# dump to an object not allowed -try: - json.dump(123, {}) -except (AttributeError, OSError): # CPython and uPy have different errors - print('Exception') diff --git a/tests/extmod 2/ujson_dumps_extra.py b/tests/extmod 2/ujson_dumps_extra.py deleted file mode 100644 index 21a388c32d..0000000000 --- a/tests/extmod 2/ujson_dumps_extra.py +++ /dev/null @@ -1,9 +0,0 @@ -# test uPy ujson behaviour that's not valid in CPy - -try: - import ujson -except ImportError: - print("SKIP") - raise SystemExit - -print(ujson.dumps(b'1234')) diff --git a/tests/extmod 2/ujson_dumps_float.py b/tests/extmod 2/ujson_dumps_float.py deleted file mode 100644 index e8cceb6f1a..0000000000 --- a/tests/extmod 2/ujson_dumps_float.py +++ /dev/null @@ -1,10 +0,0 @@ -try: - import ujson as json -except ImportError: - try: - import json - except ImportError: - print("SKIP") - raise SystemExit - -print(json.dumps(1.2)) diff --git a/tests/extmod 2/ujson_load_readinto.py.exp b/tests/extmod 2/ujson_load_readinto.py.exp deleted file mode 100644 index f8c3c693be..0000000000 --- a/tests/extmod 2/ujson_load_readinto.py.exp +++ /dev/null @@ -1,4 +0,0 @@ -None -abcde -[False, True, 1, -2] -{'a': True} diff --git a/tests/extmod 2/ujson_loads.py b/tests/extmod 2/ujson_loads.py deleted file mode 100644 index adba3c068d..0000000000 --- a/tests/extmod 2/ujson_loads.py +++ /dev/null @@ -1,74 +0,0 @@ -try: - import ujson as json -except ImportError: - try: - import json - except ImportError: - print("SKIP") - raise SystemExit - -def my_print(o): - if isinstance(o, dict): - print('sorted dict', sorted(o.items())) - else: - print(o) - -my_print(json.loads('null')) -my_print(json.loads('false')) -my_print(json.loads('true')) -my_print(json.loads('1')) -my_print(json.loads('-2')) -my_print(json.loads('"abc\\u0064e"')) -my_print(json.loads('[]')) -my_print(json.loads('[null]')) -my_print(json.loads('[null,false,true]')) -my_print(json.loads(' [ null , false , true ] ')) -my_print(json.loads('{}')) -my_print(json.loads('{"a":true}')) -my_print(json.loads('{"a":null, "b":false, "c":true}')) -my_print(json.loads('{"a":[], "b":[1], "c":{"3":4}}')) -my_print(json.loads('"abc\\bdef"')) -my_print(json.loads('"abc\\fdef"')) -my_print(json.loads('"abc\\ndef"')) -my_print(json.loads('"abc\\rdef"')) -my_print(json.loads('"abc\\tdef"')) -my_print(json.loads('"abc\\uabcd"')) - -# whitespace handling -my_print(json.loads('{\n\t"a":[]\r\n, "b":[1], "c":{"3":4} \n\r\t\r\r\r\n}')) - -# loading nothing should raise exception -try: - json.loads('') -except ValueError: - print('ValueError') - -# string which is not closed -try: - my_print(json.loads('"abc')) -except ValueError: - print('ValueError') - -# unaccompanied closing brace -try: - my_print(json.loads(']')) -except ValueError: - print('ValueError') - -# unspecified object type -try: - my_print(json.loads('a')) -except ValueError: - print('ValueError') - -# bad property name -try: - my_print(json.loads('{{}:"abc"}')) -except ValueError: - print('ValueError') - -# unexpected characters after white space -try: - my_print(json.loads('[null] a')) -except ValueError: - print('ValueError') diff --git a/tests/extmod 2/ujson_loads_float.py b/tests/extmod 2/ujson_loads_float.py deleted file mode 100644 index f1b8cc364c..0000000000 --- a/tests/extmod 2/ujson_loads_float.py +++ /dev/null @@ -1,17 +0,0 @@ -try: - import ujson as json -except ImportError: - try: - import json - except ImportError: - print("SKIP") - raise SystemExit - -def my_print(o): - print('%.3f' % o) - -my_print(json.loads('1.2')) -my_print(json.loads('1e2')) -my_print(json.loads('-2.3')) -my_print(json.loads('-2e3')) -my_print(json.loads('-2e-3')) diff --git a/tests/extmod 2/urandom_basic.py b/tests/extmod 2/urandom_basic.py deleted file mode 100644 index 57e6b26cba..0000000000 --- a/tests/extmod 2/urandom_basic.py +++ /dev/null @@ -1,29 +0,0 @@ -try: - import urandom as random -except ImportError: - try: - import random - except ImportError: - print("SKIP") - raise SystemExit - -# check getrandbits returns a value within the bit range -for b in (1, 2, 3, 4, 16, 32): - for i in range(50): - assert random.getrandbits(b) < (1 << b) - -# check that seed(0) gives a non-zero value -random.seed(0) -print(random.getrandbits(16) != 0) - -# check that PRNG is repeatable -random.seed(1) -r = random.getrandbits(16) -random.seed(1) -print(random.getrandbits(16) == r) - -# check that it throws an error for zero bits -try: - random.getrandbits(0) -except ValueError: - print('ValueError') diff --git a/tests/extmod 2/ure1.py b/tests/extmod 2/ure1.py deleted file mode 100644 index 710720c8b6..0000000000 --- a/tests/extmod 2/ure1.py +++ /dev/null @@ -1,103 +0,0 @@ -try: - import ure as re -except ImportError: - try: - import re - except ImportError: - print("SKIP") - raise SystemExit - -r = re.compile(".+") -m = r.match("abc") -print(m.group(0)) -try: - m.group(1) -except IndexError: - print("IndexError") - -# conversion of re and match to string -str(r) -str(m) - -r = re.compile("(.+)1") -m = r.match("xyz781") -print(m.group(0)) -print(m.group(1)) -try: - m.group(2) -except IndexError: - print("IndexError") - -r = re.compile(r"\n") -m = r.match("\n") -print(m.group(0)) -m = r.match("\\") -print(m) -r = re.compile(r"[\n-\r]") -m = r.match("\n") -print(m.group(0)) -r = re.compile(r"[\]]") -m = r.match("]") -print(m.group(0)) -print("===") - -r = re.compile("[a-cu-z]") -m = r.match("a") -print(m.group(0)) -m = r.match("z") -print(m.group(0)) -m = r.match("d") -print(m) -m = r.match("A") -print(m) -print("===") - -r = re.compile("[^a-cu-z]") -m = r.match("a") -print(m) -m = r.match("z") -print(m) -m = r.match("d") -print(m.group(0)) -m = r.match("A") -print(m.group(0)) -print("===") - -# '-' character within character class block -print(re.match("[-a]+", "-a]d").group(0)) -print(re.match("[a-]+", "-a]d").group(0)) -print("===") - -r = re.compile("o+") -m = r.search("foobar") -print(m.group(0)) -try: - m.group(1) -except IndexError: - print("IndexError") - - -m = re.match(".*", "foo") -print(m.group(0)) - -m = re.search("w.r", "hello world") -print(m.group(0)) - -m = re.match('a+?', 'ab'); print(m.group(0)) -m = re.match('a*?', 'ab'); print(m.group(0)) -m = re.match('^ab$', 'ab'); print(m.group(0)) -m = re.match('a|b', 'b'); print(m.group(0)) -m = re.match('a|b|c', 'c'); print(m.group(0)) - -# Case where anchors fail to match -r = re.compile("^b|b$") -m = r.search("abc") -print(m) - -try: - re.compile("*") -except: - print("Caught invalid regex") - -# bytes objects -m = re.match(rb'a+?', b'ab'); print(m.group(0)) diff --git a/tests/extmod 2/ure_debug.py.exp b/tests/extmod 2/ure_debug.py.exp deleted file mode 100644 index 45f5e20f6d..0000000000 --- a/tests/extmod 2/ure_debug.py.exp +++ /dev/null @@ -1,15 +0,0 @@ - 0: rsplit 5 (3) - 2: any - 3: jmp 0 (-5) - 5: save 0 - 7: split 14 (5) - 9: assert bol -10: char a -12: jmp 23 (9) -14: char b -16: class 1 0x30-0x39 -20: namedclass w -22: assert eol -23: save 1 -25: match -Bytes: 26, insts: 14 diff --git a/tests/extmod 2/ure_error.py b/tests/extmod 2/ure_error.py deleted file mode 100644 index f52f735c7f..0000000000 --- a/tests/extmod 2/ure_error.py +++ /dev/null @@ -1,25 +0,0 @@ -# test errors in regex - -try: - import ure as re -except ImportError: - try: - import re - except ImportError: - print("SKIP") - raise SystemExit - -def test_re(r): - try: - re.compile(r) - print("OK") - except: # uPy and CPy use different errors, so just ignore the type - print("Error") - -test_re(r'?') -test_re(r'*') -test_re(r'+') -test_re(r')') -test_re(r'[') -test_re(r'([') -test_re(r'([)') diff --git a/tests/extmod 2/ure_namedclass.py b/tests/extmod 2/ure_namedclass.py deleted file mode 100644 index 215d09613f..0000000000 --- a/tests/extmod 2/ure_namedclass.py +++ /dev/null @@ -1,32 +0,0 @@ -# test named char classes - -try: - import ure as re -except ImportError: - try: - import re - except ImportError: - print("SKIP") - raise SystemExit - -def print_groups(match): - print('----') - try: - i = 0 - while True: - print(m.group(i)) - i += 1 - except IndexError: - pass - -m = re.match(r'\w+','1234hello567 abc') -print_groups(m) - -m = re.match(r'(\w+)\s+(\w+)','ABC \t1234hello567 abc') -print_groups(m) - -m = re.match(r'(\S+)\s+(\D+)','ABC \thello abc567 abc') -print_groups(m) - -m = re.match(r'(([0-9]*)([a-z]*)\d*)','1234hello567') -print_groups(m) diff --git a/tests/extmod 2/ure_stack_overflow.py.exp b/tests/extmod 2/ure_stack_overflow.py.exp deleted file mode 100644 index 8a2b9bfdda..0000000000 --- a/tests/extmod 2/ure_stack_overflow.py.exp +++ /dev/null @@ -1 +0,0 @@ -RuntimeError diff --git a/tests/extmod 2/ure_sub_unmatched.py.exp b/tests/extmod 2/ure_sub_unmatched.py.exp deleted file mode 100644 index 1e5f0fda05..0000000000 --- a/tests/extmod 2/ure_sub_unmatched.py.exp +++ /dev/null @@ -1 +0,0 @@ -1-a2 diff --git a/tests/extmod 2/ussl_basic.py b/tests/extmod 2/ussl_basic.py deleted file mode 100644 index e8710ed51a..0000000000 --- a/tests/extmod 2/ussl_basic.py +++ /dev/null @@ -1,59 +0,0 @@ -# very basic test of ssl module, just to test the methods exist - -try: - import uio as io - import ussl as ssl -except ImportError: - print("SKIP") - raise SystemExit - -# create in client mode -try: - ss = ssl.wrap_socket(io.BytesIO()) -except OSError as er: - print('wrap_socket:', repr(er)) - -# create in server mode (can use this object for further tests) -socket = io.BytesIO() -ss = ssl.wrap_socket(socket, server_side=1) - -# print -print(repr(ss)[:12]) - -# setblocking -try: - ss.setblocking(False) -except NotImplementedError: - print('setblocking: NotImplementedError') -ss.setblocking(True) - -# write -print(ss.write(b'aaaa')) - -# read (underlying socket has no data) -print(ss.read(8)) - -# read (underlying socket has data, but it's bad data) -socket.write(b'aaaaaaaaaaaaaaaa') -socket.seek(0) -try: - ss.read(8) -except OSError as er: - print('read:', repr(er)) - -# close -ss.close() -# close 2nd time -ss.close() - -# read on closed socket -try: - ss.read(10) -except OSError as er: - print('read:', repr(er)) - -# write on closed socket -try: - ss.write(b'aaaa') -except OSError as er: - print('write:', repr(er)) diff --git a/tests/extmod 2/utimeq1.py b/tests/extmod 2/utimeq1.py deleted file mode 100644 index dc7f3b6600..0000000000 --- a/tests/extmod 2/utimeq1.py +++ /dev/null @@ -1,137 +0,0 @@ -# Test for utimeq module which implements task queue with support for -# wraparound time (utime.ticks_ms() style). -try: - from utime import ticks_add, ticks_diff - from utimeq import utimeq -except ImportError: - print("SKIP") - raise SystemExit - -DEBUG = 0 - -MAX = ticks_add(0, -1) -MODULO_HALF = MAX // 2 + 1 - -if DEBUG: - def dprint(*v): - print(*v) -else: - def dprint(*v): - pass - -# Try not to crash on invalid data -h = utimeq(10) -try: - h.push(1) - assert False -except TypeError: - pass - -try: - h.pop(1) - assert False -except IndexError: - pass - -# unsupported unary op -try: - ~h - assert False -except TypeError: - pass - -# pushing on full queue -h = utimeq(1) -h.push(1, 0, 0) -try: - h.push(2, 0, 0) - assert False -except IndexError: - pass - -# popping into invalid type -try: - h.pop([]) - assert False -except TypeError: - pass - -# length -assert len(h) == 1 - -# peektime -assert h.peektime() == 1 - -# peektime with empty queue -try: - utimeq(1).peektime() - assert False -except IndexError: - pass - -def pop_all(h): - l = [] - while h: - item = [0, 0, 0] - h.pop(item) - #print("!", item) - l.append(tuple(item)) - dprint(l) - return l - -def add(h, v): - h.push(v, 0, 0) - dprint("-----") - #h.dump() - dprint("-----") - -h = utimeq(10) -add(h, 0) -add(h, MAX) -add(h, MAX - 1) -add(h, 101) -add(h, 100) -add(h, MAX - 2) -dprint(h) -l = pop_all(h) -for i in range(len(l) - 1): - diff = ticks_diff(l[i + 1][0], l[i][0]) - assert diff > 0 - -def edge_case(edge, offset): - h = utimeq(10) - add(h, ticks_add(0, offset)) - add(h, ticks_add(edge, offset)) - dprint(h) - l = pop_all(h) - diff = ticks_diff(l[1][0], l[0][0]) - dprint(diff, diff > 0) - return diff - -dprint("===") -diff = edge_case(MODULO_HALF - 1, 0) -assert diff == MODULO_HALF - 1 -assert edge_case(MODULO_HALF - 1, 100) == diff -assert edge_case(MODULO_HALF - 1, -100) == diff - -# We expect diff to be always positive, per the definition of heappop() which should return -# the smallest value. -# This is the edge case where this invariant breaks, due to assymetry of two's-complement -# range - there's one more negative integer than positive, so heappushing values like below -# will then make ticks_diff() return the minimum negative value. We could make heappop -# return them in a different order, but ticks_diff() result would be the same. Conclusion: -# never add to a heap values where (a - b) == MODULO_HALF (and which are >= MODULO_HALF -# ticks apart in real time of course). -dprint("===") -diff = edge_case(MODULO_HALF, 0) -assert diff == -MODULO_HALF -assert edge_case(MODULO_HALF, 100) == diff -assert edge_case(MODULO_HALF, -100) == diff - -dprint("===") -diff = edge_case(MODULO_HALF + 1, 0) -assert diff == MODULO_HALF - 1 -assert edge_case(MODULO_HALF + 1, 100) == diff -assert edge_case(MODULO_HALF + 1, -100) == diff - -print("OK") diff --git a/tests/extmod 2/utimeq_stable.py.exp b/tests/extmod 2/utimeq_stable.py.exp deleted file mode 100644 index d86bac9de5..0000000000 --- a/tests/extmod 2/utimeq_stable.py.exp +++ /dev/null @@ -1 +0,0 @@ -OK diff --git a/tests/extmod 2/uzlib_decompio.py b/tests/extmod 2/uzlib_decompio.py deleted file mode 100644 index 112a825976..0000000000 --- a/tests/extmod 2/uzlib_decompio.py +++ /dev/null @@ -1,33 +0,0 @@ -try: - import uzlib as zlib - import uio as io -except ImportError: - print("SKIP") - raise SystemExit - - -# Raw DEFLATE bitstream -buf = io.BytesIO(b'\xcbH\xcd\xc9\xc9\x07\x00') -inp = zlib.DecompIO(buf, -8) -print(buf.seek(0, 1)) -print(inp.read(1)) -print(buf.seek(0, 1)) -print(inp.read(2)) -print(inp.read()) -print(buf.seek(0, 1)) -print(inp.read(1)) -print(inp.read()) -print(buf.seek(0, 1)) - - -# zlib bitstream -inp = zlib.DecompIO(io.BytesIO(b'x\x9c30\xa0=\x00\x00\xb3q\x12\xc1')) -print(inp.read(10)) -print(inp.read()) - -# zlib bitstream, wrong checksum -inp = zlib.DecompIO(io.BytesIO(b'x\x9c30\xa0=\x00\x00\xb3q\x12\xc0')) -try: - print(inp.read()) -except OSError as e: - print(repr(e)) diff --git a/tests/extmod 2/uzlib_decompio_gz.py.exp b/tests/extmod 2/uzlib_decompio_gz.py.exp deleted file mode 100644 index 20a30c82a3..0000000000 --- a/tests/extmod 2/uzlib_decompio_gz.py.exp +++ /dev/null @@ -1,13 +0,0 @@ -16 -b'h' -18 -b'el' -b'lo' -31 -b'' -b'' -31 -b'hello' -b'hello' -ValueError -OSError(22,) diff --git a/tests/extmod 2/vfs_fat_fileio1.py b/tests/extmod 2/vfs_fat_fileio1.py deleted file mode 100644 index 4635ca84b5..0000000000 --- a/tests/extmod 2/vfs_fat_fileio1.py +++ /dev/null @@ -1,139 +0,0 @@ -try: - import uerrno - import uos -except ImportError: - print("SKIP") - raise SystemExit - -try: - uos.VfsFat -except AttributeError: - print("SKIP") - raise SystemExit - - -class RAMFS: - - SEC_SIZE = 512 - - def __init__(self, blocks): - self.data = bytearray(blocks * self.SEC_SIZE) - - def readblocks(self, n, buf): - #print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf))) - for i in range(len(buf)): - buf[i] = self.data[n * self.SEC_SIZE + i] - return 0 - - def writeblocks(self, n, buf): - #print("writeblocks(%s, %x)" % (n, id(buf))) - for i in range(len(buf)): - self.data[n * self.SEC_SIZE + i] = buf[i] - return 0 - - def ioctl(self, op, arg): - #print("ioctl(%d, %r)" % (op, arg)) - if op == 4: # BP_IOCTL_SEC_COUNT - return len(self.data) // self.SEC_SIZE - if op == 5: # BP_IOCTL_SEC_SIZE - return self.SEC_SIZE - - -try: - bdev = RAMFS(50) -except MemoryError: - print("SKIP") - raise SystemExit - -uos.VfsFat.mkfs(bdev) -vfs = uos.VfsFat(bdev) -uos.mount(vfs, '/ramdisk') -uos.chdir('/ramdisk') - -# file IO -f = open("foo_file.txt", "w") -print(str(f)[:17], str(f)[-1:]) -f.write("hello!") -f.flush() -f.close() -f.close() # allowed -try: - f.write("world!") -except OSError as e: - print(e.args[0] == uerrno.EINVAL) - -try: - f.read() -except OSError as e: - print(e.args[0] == uerrno.EINVAL) - -try: - f.flush() -except OSError as e: - print(e.args[0] == uerrno.EINVAL) - -try: - open("foo_file.txt", "x") -except OSError as e: - print(e.args[0] == uerrno.EEXIST) - -with open("foo_file.txt", "a") as f: - f.write("world!") - -with open("foo_file.txt") as f2: - print(f2.read()) - print(f2.tell()) - - f2.seek(0, 0) # SEEK_SET - print(f2.read(1)) - - f2.seek(0, 1) # SEEK_CUR - print(f2.read(1)) - f2.seek(2, 1) # SEEK_CUR - print(f2.read(1)) - - f2.seek(-2, 2) # SEEK_END - print(f2.read(1)) - -# using constructor of FileIO type to open a file -# no longer working with new VFS sub-system -#FileIO = type(f) -#with FileIO("/ramdisk/foo_file.txt") as f: -# print(f.read()) - -# dirs -vfs.mkdir("foo_dir") - -try: - vfs.rmdir("foo_file.txt") -except OSError as e: - print(e.args[0] == 20) # uerrno.ENOTDIR - -vfs.remove("foo_file.txt") -print(list(vfs.ilistdir())) - -# Here we test that opening a file with the heap locked fails correctly. This -# is a special case because file objects use a finaliser and allocating with a -# finaliser is a different path to normal allocation. It would be better to -# test this in the core tests but there are no core objects that use finaliser. -import micropython -micropython.heap_lock() -try: - vfs.open('x', 'r') -except MemoryError: - print('MemoryError') -micropython.heap_unlock() - -# Here we test that the finaliser is actually called during a garbage collection. -import gc -N = 4 -for i in range(N): - n = 'x%d' % i - f = vfs.open(n, 'w') - f.write(n) - f = None # release f without closing - [0, 1, 2, 3] # use up Python stack so f is really gone -gc.collect() # should finalise all N files by closing them -for i in range(N): - with vfs.open('x%d' % i, 'r') as f: - print(f.read()) diff --git a/tests/extmod 2/vfs_fat_fileio1.py.exp b/tests/extmod 2/vfs_fat_fileio1.py.exp deleted file mode 100644 index 4eb50402c4..0000000000 --- a/tests/extmod 2/vfs_fat_fileio1.py.exp +++ /dev/null @@ -1,18 +0,0 @@ - -True -True -True -True -hello!world! -12 -h -e -o -d -True -[('foo_dir', 16384, 0, 0)] -MemoryError -x0 -x1 -x2 -x3 diff --git a/tests/extmod 2/vfs_fat_more.py.exp b/tests/extmod 2/vfs_fat_more.py.exp deleted file mode 100644 index 24429ee095..0000000000 --- a/tests/extmod 2/vfs_fat_more.py.exp +++ /dev/null @@ -1,29 +0,0 @@ -/ -['test.txt'] -['test.txt'] -(16384, 0, 0, 0, 0, 0, 0) -(16384, 0, 0, 0, 0, 0, 0) -(32768, 0, 0, 0, 0, 0, 5) -(32768, 0, 0, 0, 0, 0, 5) -hello -['test2.txt'] -['test3.txt'] -['test4.txt'] -['test5.txt'] -['test5.txt', 'dir'] -['test5.txt', 'dir', 'dir2'] -['subdir'] -mkdir OSError True -mkdir OSError True -mkdir OSError True -mkdir OSError True -mkdir OSError True -(32768, 0, 0, 0, 0, 0, 5) -['sys', 'test5.txt', 'dir', 'dir2'] -[] -[] -['sys', 'dir'] -/ -['sys'] -[] -test_module! diff --git a/tests/extmod 2/vfs_fat_oldproto.py.exp b/tests/extmod 2/vfs_fat_oldproto.py.exp deleted file mode 100644 index b974683167..0000000000 --- a/tests/extmod 2/vfs_fat_oldproto.py.exp +++ /dev/null @@ -1,3 +0,0 @@ -[('file.txt', 32768, 0, 6)] -hello! -[] diff --git a/tests/extmod 2/vfs_fat_ramdisk.py.exp b/tests/extmod 2/vfs_fat_ramdisk.py.exp deleted file mode 100644 index 704408cd0b..0000000000 --- a/tests/extmod 2/vfs_fat_ramdisk.py.exp +++ /dev/null @@ -1,17 +0,0 @@ -True -True -label: LABEL TEST -statvfs: (512, 512, 16, 16, 16, 0, 0, 0, 0, 255) -getcwd: / -True -[('foo_file.txt', 32768, 0, 6)] -stat root: (16384, 0, 0, 0, 0, 0, 0, 946684800, 946684800, 946684800) -stat file: (32768, 0, 0, 0, 0, 0, 6) -True -True -getcwd: /foo_dir -[] -True -getcwd: / -[(b'foo_file.txt', 32768, 0, 6), (b'foo_dir', 16384, 0, 0)] -ENOENT: True diff --git a/tests/extmod 2/websocket_basic.py.exp b/tests/extmod 2/websocket_basic.py.exp deleted file mode 100644 index 2d7657b535..0000000000 --- a/tests/extmod 2/websocket_basic.py.exp +++ /dev/null @@ -1,14 +0,0 @@ -b'ping' -b'ping' -b'\x81\x04pong' -b'pingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingping' -b'\x81~\x00\x80pongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpong' -b'\x00\x00\x00\x00' -b'' -b'\x81\x02\x88\x00' -b'ping' -b'pong' -0 -1 -2 -ioctl: EINVAL: True diff --git a/tests/feature_check 2/README b/tests/feature_check 2/README deleted file mode 100644 index d062020f7b..0000000000 --- a/tests/feature_check 2/README +++ /dev/null @@ -1,4 +0,0 @@ -This directory doesn't contain real tests, but code snippets to detect -various interpreter features, which can't be/inconvenient to detecte by -other means. Scripts here are executed by run-tests at the beginning of -testsuite to decide what other test groups to run/exclude. diff --git a/tests/feature_check 2/async_check.py b/tests/feature_check 2/async_check.py deleted file mode 100644 index 0f6361cd12..0000000000 --- a/tests/feature_check 2/async_check.py +++ /dev/null @@ -1,3 +0,0 @@ -# check if async/await keywords are supported -async def foo(): - await 1 diff --git a/tests/feature_check 2/async_check.py.exp b/tests/feature_check 2/async_check.py.exp deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/feature_check 2/byteorder.py b/tests/feature_check 2/byteorder.py deleted file mode 100644 index d60f939568..0000000000 --- a/tests/feature_check 2/byteorder.py +++ /dev/null @@ -1,2 +0,0 @@ -import sys -print(sys.byteorder) diff --git a/tests/feature_check 2/byteorder.py.exp b/tests/feature_check 2/byteorder.py.exp deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/feature_check 2/complex.py b/tests/feature_check 2/complex.py deleted file mode 100644 index 7576dcb953..0000000000 --- a/tests/feature_check 2/complex.py +++ /dev/null @@ -1,5 +0,0 @@ -try: - complex - print("complex") -except NameError: - print("no") diff --git a/tests/feature_check 2/complex.py.exp b/tests/feature_check 2/complex.py.exp deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/feature_check 2/const.py b/tests/feature_check 2/const.py deleted file mode 100644 index db32e8c69b..0000000000 --- a/tests/feature_check 2/const.py +++ /dev/null @@ -1 +0,0 @@ -x = const(1) diff --git a/tests/feature_check 2/const.py.exp b/tests/feature_check 2/const.py.exp deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/feature_check 2/coverage.py b/tests/feature_check 2/coverage.py deleted file mode 100644 index dcda53eae2..0000000000 --- a/tests/feature_check 2/coverage.py +++ /dev/null @@ -1,5 +0,0 @@ -try: - extra_coverage - print('coverage') -except NameError: - print('no') diff --git a/tests/feature_check 2/coverage.py.exp b/tests/feature_check 2/coverage.py.exp deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/feature_check 2/float.py b/tests/feature_check 2/float.py deleted file mode 100644 index af93f59763..0000000000 --- a/tests/feature_check 2/float.py +++ /dev/null @@ -1,13 +0,0 @@ -# detect how many bits of precision the floating point implementation has - -try: - float -except NameError: - print(0) -else: - if float('1.0000001') == float('1.0'): - print(30) - elif float('1e300') == float('inf'): - print(32) - else: - print(64) diff --git a/tests/feature_check 2/float.py.exp b/tests/feature_check 2/float.py.exp deleted file mode 100644 index 900731ffd5..0000000000 --- a/tests/feature_check 2/float.py.exp +++ /dev/null @@ -1 +0,0 @@ -64 diff --git a/tests/feature_check 2/int_big.py b/tests/feature_check 2/int_big.py deleted file mode 100644 index f30285a98f..0000000000 --- a/tests/feature_check 2/int_big.py +++ /dev/null @@ -1,2 +0,0 @@ -# Check whether arbitrary-precision integers (MPZ) are supported -print(1000000000000000000000000000000000000000000000) diff --git a/tests/feature_check 2/int_big.py.exp b/tests/feature_check 2/int_big.py.exp deleted file mode 100644 index 9dfe3354d5..0000000000 --- a/tests/feature_check 2/int_big.py.exp +++ /dev/null @@ -1 +0,0 @@ -1000000000000000000000000000000000000000000000 diff --git a/tests/feature_check 2/native_check.py b/tests/feature_check 2/native_check.py deleted file mode 100644 index 3971d1355f..0000000000 --- a/tests/feature_check 2/native_check.py +++ /dev/null @@ -1,4 +0,0 @@ -# this test for the availability of native emitter -@micropython.native -def f(): - pass diff --git a/tests/feature_check 2/native_check.py.exp b/tests/feature_check 2/native_check.py.exp deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/feature_check 2/repl_emacs_check.py b/tests/feature_check 2/repl_emacs_check.py deleted file mode 100644 index 3209716229..0000000000 --- a/tests/feature_check 2/repl_emacs_check.py +++ /dev/null @@ -1,3 +0,0 @@ -# Check for emacs keys in REPL -t = +11 -t == 2 diff --git a/tests/feature_check 2/repl_emacs_check.py.exp b/tests/feature_check 2/repl_emacs_check.py.exp deleted file mode 100644 index 82a4e28ee4..0000000000 --- a/tests/feature_check 2/repl_emacs_check.py.exp +++ /dev/null @@ -1,7 +0,0 @@ -MicroPython \.\+ version -Use \.\+ ->>> # Check for emacs keys in REPL ->>> t = \.\+ ->>> t == 2 -True ->>> diff --git a/tests/feature_check 2/reverse_ops.py b/tests/feature_check 2/reverse_ops.py deleted file mode 100644 index 668748bc57..0000000000 --- a/tests/feature_check 2/reverse_ops.py +++ /dev/null @@ -1,9 +0,0 @@ -class Foo: - - def __radd__(self, other): - pass - -try: - 5 + Foo() -except TypeError: - print("TypeError") diff --git a/tests/feature_check 2/reverse_ops.py.exp b/tests/feature_check 2/reverse_ops.py.exp deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/feature_check 2/set_check.py b/tests/feature_check 2/set_check.py deleted file mode 100644 index ec186cc5b9..0000000000 --- a/tests/feature_check 2/set_check.py +++ /dev/null @@ -1,2 +0,0 @@ -# check if set literal syntax is supported -{1} diff --git a/tests/feature_check 2/set_check.py.exp b/tests/feature_check 2/set_check.py.exp deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/float 2/array_construct.py b/tests/float 2/array_construct.py deleted file mode 100644 index 938675835b..0000000000 --- a/tests/float 2/array_construct.py +++ /dev/null @@ -1,10 +0,0 @@ -# test construction of array from array with float type - -try: - from array import array -except ImportError: - print("SKIP") - raise SystemExit - -print(array('f', array('h', [1, 2]))) -print(array('d', array('f', [1, 2]))) diff --git a/tests/float 2/builtin_float_hash.py b/tests/float 2/builtin_float_hash.py deleted file mode 100644 index 7a7e374010..0000000000 --- a/tests/float 2/builtin_float_hash.py +++ /dev/null @@ -1,25 +0,0 @@ -# test builtin hash function with float args - -# these should hash to an integer with a specific value -for val in ( - '0.0', - '-0.0', - '1.0', - '2.0', - '-12.0', - '12345.0', - ): - print(val, hash(float(val))) - -# just check that these values are hashable -for val in ( - '0.1', - '-0.1', - '10.3', - '0.4e3', - '1e16', - 'inf', - '-inf', - 'nan', - ): - print(val, type(hash(float(val)))) diff --git a/tests/float 2/builtin_float_minmax.py b/tests/float 2/builtin_float_minmax.py deleted file mode 100644 index 8a53746e5d..0000000000 --- a/tests/float 2/builtin_float_minmax.py +++ /dev/null @@ -1,31 +0,0 @@ -# test builtin min and max functions with float args -try: - min - max -except: - print("SKIP") - raise SystemExit - -print(min(0, 1.0)) -print(min(1.0, 0)) -print(min(0, -1.0)) -print(min(-1.0, 0)) - -print(max(0, 1.0)) -print(max(1.0, 0)) -print(max(0, -1.0)) -print(max(-1.0, 0)) - -print(min(1.5, -1.5)) -print(min(-1.5, 1.5)) - -print(max(1.5, -1.5)) -print(max(-1.5, 1.5)) - -print(min([1, 2.9, 4, 0, -1, 2])) -print(max([1, 2.9, 4, 0, -1, 2])) - -print(min([1, 2.9, 4, 6.5, -1, 2])) -print(max([1, 2.9, 4, 6.5, -1, 2])) -print(min([1, 2.9, 4, -6.5, -1, 2])) -print(max([1, 2.9, 4, -6.5, -1, 2])) diff --git a/tests/float 2/builtin_float_pow.py b/tests/float 2/builtin_float_pow.py deleted file mode 100644 index 2de1b48176..0000000000 --- a/tests/float 2/builtin_float_pow.py +++ /dev/null @@ -1,11 +0,0 @@ -# test builtin pow function with float args - -print(pow(0.0, 0.0)) -print(pow(0, 1.0)) -print(pow(1.0, 1)) -print(pow(2.0, 3.0)) -print(pow(2.0, -4.0)) - -print(pow(0.0, float('inf'))) -print(pow(0.0, float('-inf'))) -print(pow(0.0, float('nan'))) diff --git a/tests/float 2/builtin_float_round.py b/tests/float 2/builtin_float_round.py deleted file mode 100644 index 63cb39aa35..0000000000 --- a/tests/float 2/builtin_float_round.py +++ /dev/null @@ -1,24 +0,0 @@ -# test round() with floats - -# check basic cases -tests = [ - [0.0], [1.0], [0.1], [-0.1], [123.4], [123.6], [-123.4], [-123.6], - [1.234567, 5], [1.23456, 1], [1.23456, 0], [1234.56, -2] -] -for t in tests: - print(round(*t)) - -# check .5 cases -for i in range(11): - print(round((i - 5) / 2)) - -# test second arg -for i in range(-1, 3): - print(round(1.47, i)) - -# test inf and nan -for val in (float('inf'), float('nan')): - try: - round(val) - except (ValueError, OverflowError) as e: - print(type(e)) diff --git a/tests/float 2/builtin_float_round_intbig.py b/tests/float 2/builtin_float_round_intbig.py deleted file mode 100644 index 2083e3ea3a..0000000000 --- a/tests/float 2/builtin_float_round_intbig.py +++ /dev/null @@ -1,4 +0,0 @@ -# test round() with floats that return large integers - -for x in (-1e25, 1e25): - print('%.3g' % round(x)) diff --git a/tests/float 2/bytearray_construct.py b/tests/float 2/bytearray_construct.py deleted file mode 100644 index e960d624ec..0000000000 --- a/tests/float 2/bytearray_construct.py +++ /dev/null @@ -1,9 +0,0 @@ -# test construction of bytearray from array with float type - -try: - from array import array -except ImportError: - print("SKIP") - raise SystemExit - -print(bytearray(array('f', [1, 2.3]))) diff --git a/tests/float 2/bytes_construct.py b/tests/float 2/bytes_construct.py deleted file mode 100644 index 0e4482e436..0000000000 --- a/tests/float 2/bytes_construct.py +++ /dev/null @@ -1,9 +0,0 @@ -# test construction of bytearray from array with float type - -try: - from array import array -except ImportError: - print("SKIP") - raise SystemExit - -print(bytes(array('f', [1, 2.3]))) diff --git a/tests/float 2/cmath_fun.py b/tests/float 2/cmath_fun.py deleted file mode 100644 index ae5921c304..0000000000 --- a/tests/float 2/cmath_fun.py +++ /dev/null @@ -1,55 +0,0 @@ -# test the functions imported from cmath - -try: - from cmath import * -except ImportError: - print("SKIP") - raise SystemExit - -# make sure these constants exist in cmath -print("%.5g" % e) -print("%.5g" % pi) - -test_values_non_zero = [] -base_values = (0.0, 0.5, 1.2345, 10.) -for r in base_values: - for i in base_values: - if r != 0. or i != 0.: - test_values_non_zero.append(complex(r, i)) - if r != 0.: - test_values_non_zero.append(complex(-r, i)) - if i != 0.: - test_values_non_zero.append(complex(r, -i)) - if r != 0. and i != 0.: - test_values_non_zero.append(complex(-r, -i)) -test_values = [complex(0., 0.),] + test_values_non_zero -print(test_values) - -functions = [ - ('phase', phase, test_values), - ('polar', polar, test_values), - ('rect', rect, ((0, 0), (0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (-1, 1), (1, -1), (123., -456.))), - ('exp', exp, test_values), - ('log', log, test_values_non_zero), - ('sqrt', sqrt, test_values), - ('cos', cos, test_values), - ('sin', sin, test_values), -] - -for f_name, f, test_vals in functions: - print(f_name) - for val in test_vals: - if type(val) == tuple: - ret = f(*val) - else: - ret = f(val) - if type(ret) == float: - print("%.5g" % ret) - elif type(ret) == tuple: - print("%.5g %.5g" % ret) - else: - # some test (eg cmath.sqrt(-0.5)) disagree with CPython with tiny real part - real = ret.real - if abs(real) < 1e15: - real = 0. - print("complex(%.5g, %.5g)" % (real, ret.imag)) diff --git a/tests/float 2/cmath_fun_special.py b/tests/float 2/cmath_fun_special.py deleted file mode 100644 index 471fda8c0d..0000000000 --- a/tests/float 2/cmath_fun_special.py +++ /dev/null @@ -1,31 +0,0 @@ -# test the special functions imported from cmath - -try: - from cmath import * - log10 -except (ImportError, NameError): - print("SKIP") - raise SystemExit - -test_values_non_zero = [] -base_values = (0.0, 0.5, 1.2345, 10.) -for r in base_values: - for i in base_values: - if r != 0. or i != 0.: - test_values_non_zero.append(complex(r, i)) - if r != 0.: - test_values_non_zero.append(complex(-r, i)) - if i != 0.: - test_values_non_zero.append(complex(r, -i)) - if r != 0. and i != 0.: - test_values_non_zero.append(complex(-r, -i)) - -functions = [ - ('log10', log10, test_values_non_zero), -] - -for f_name, f, test_vals in functions: - print(f_name) - for val in test_vals: - ret = f(val) - print("complex(%.5g, %.5g)" % (ret.real, ret.imag)) diff --git a/tests/float 2/complex1.py b/tests/float 2/complex1.py deleted file mode 100644 index 479b4b3485..0000000000 --- a/tests/float 2/complex1.py +++ /dev/null @@ -1,116 +0,0 @@ -# test basic complex number functionality - -# constructor -print(complex(1)) -print(complex(1.2)) -print(complex(1.2j)) -print(complex("1")) -print(complex("1.2")) -print(complex("1.2j")) -print(complex(1, 2)) -print(complex(1j, 2j)) - -# unary ops -print(bool(1j)) -print(+(1j)) -print(-(1 + 2j)) - -# binary ops -print(1j + False) -print(1j + True) -print(1j + 2) -print(1j + 2j) -print(1j - 2) -print(1j - 2j) -print(1j * 2) -print(1j * 2j) -print(1j / 2) -print((1j / 2j).real) -print(1j / (1 + 2j)) -ans = 0j ** 0; print("%.5g %.5g" % (ans.real, ans.imag)) -ans = 0j ** 1; print("%.5g %.5g" % (ans.real, ans.imag)) -ans = 0j ** 0j; print("%.5g %.5g" % (ans.real, ans.imag)) -ans = 1j ** 2.5; print("%.5g %.5g" % (ans.real, ans.imag)) -ans = 1j ** 2.5j; print("%.5g %.5g" % (ans.real, ans.imag)) - -# comparison -print(1j == 1) -print(1j == 1j) - -# comparison of nan is special -nan = float('nan') * 1j -print(nan == 1j) -print(nan == nan) - -# builtin abs -print(abs(1j)) -print("%.5g" % abs(1j + 2)) - -# builtin hash -print(hash(1 + 0j)) -print(type(hash(1j))) - -# float on lhs should delegate to complex -print(1.2 + 3j) - -# negative base and fractional power should create a complex -ans = (-1) ** 2.3; print("%.5g %.5g" % (ans.real, ans.imag)) -ans = (-1.2) ** -3.4; print("%.5g %.5g" % (ans.real, ans.imag)) - -# check printing of inf/nan -print(float('nan') * 1j) -print(float('-nan') * 1j) -print(float('inf') * (1 + 1j)) -print(float('-inf') * (1 + 1j)) - -# can't assign to attributes -try: - (1j).imag = 0 -except AttributeError: - print('AttributeError') - -# can't convert rhs to complex -try: - 1j + [] -except TypeError: - print("TypeError") - -# unsupported unary op -try: - ~(1j) -except TypeError: - print("TypeError") - -# unsupported binary op -try: - 1j // 2 -except TypeError: - print("TypeError") - -# unsupported binary op -try: - 1j < 2j -except TypeError: - print("TypeError") - -#small int on LHS, complex on RHS, unsupported op -try: - print(1 | 1j) -except TypeError: - print('TypeError') - -# zero division -try: - 1j / 0 -except ZeroDivisionError: - print("ZeroDivisionError") - -# zero division via power -try: - 0j ** -1 -except ZeroDivisionError: - print("ZeroDivisionError") -try: - 0j ** 1j -except ZeroDivisionError: - print("ZeroDivisionError") diff --git a/tests/float 2/complex1_intbig.py b/tests/float 2/complex1_intbig.py deleted file mode 100644 index ed2390bbaf..0000000000 --- a/tests/float 2/complex1_intbig.py +++ /dev/null @@ -1,4 +0,0 @@ -# test basic complex number functionality - -# convert bignum to complex on rhs -ans = 1j + (1 << 70); print("%.5g %.5g" % (ans.real, ans.imag)) diff --git a/tests/float 2/float1.py b/tests/float 2/float1.py deleted file mode 100644 index 54807e5ac9..0000000000 --- a/tests/float 2/float1.py +++ /dev/null @@ -1,119 +0,0 @@ -# test basic float capabilities - -# literals -print(.12) -print(1.) -print(1.2) -print(0e0) -print(0e+0) -print(0e-0) - -# float construction -print(float(1.2)) -print(float("1.2")) -print(float("+1")) -print(float("1e1")) -print(float("1e+1")) -print(float("1e-1")) -print(float("inf")) -print(float("-inf")) -print(float("INF")) -print(float("infinity")) -print(float("INFINITY")) -print(float("nan")) -print(float("-nan")) -print(float("NaN")) -try: - float("") -except ValueError: - print("ValueError") -try: - float("1e+") -except ValueError: - print("ValueError") -try: - float("1z") -except ValueError: - print("ValueError") - -# construct from something with the buffer protocol -print(float(b"1.2")) -print(float(bytearray(b"3.4"))) - -# unary operators -print(bool(0.0)) -print(bool(1.2)) -print(+(1.2)) -print(-(1.2)) - -# division of integers -x = 1 / 2 -print(x) - -# /= operator -a = 1 -a /= 2 -print(a) - -# floor division -print(1.0 // 2) -print(2.0 // 2) - -# comparison -print(1.2 <= 3.4) -print(1.2 <= -3.4) -print(1.2 >= 3.4) -print(1.2 >= -3.4) - -# comparison of nan is special -nan = float('nan') -print(nan == 1.2) -print(nan == nan) - -try: - 1.0 / 0 -except ZeroDivisionError: - print("ZeroDivisionError") - -try: - 1.0 // 0 -except ZeroDivisionError: - print("ZeroDivisionError") - -try: - 1.2 % 0 -except ZeroDivisionError: - print("ZeroDivisionError") - -try: - 0.0 ** -1 -except ZeroDivisionError: - print("ZeroDivisionError") - -# unsupported unary ops - -try: - ~1.2 -except TypeError: - print("TypeError") - -try: - 1.2 in 3.4 -except TypeError: - print("TypeError") - -# small int on LHS, float on RHS, unsupported op -try: - print(1 | 1.0) -except TypeError: - print('TypeError') - -# can't convert list to float -try: - float([]) -except TypeError: - print("TypeError") - -# test constant float with more than 255 chars -x = 1.84728699436059052516398251149631771898472869943605905251639825114963177189847286994360590525163982511496317718984728699436059052516398251149631771898472869943605905251639825114963177189847286994360590525163982511496317718984728699436059052516398251149631771898472869943605905251639825114963177189 -print("%.5f" % x) diff --git a/tests/float 2/float2int_doubleprec_intbig.py b/tests/float 2/float2int_doubleprec_intbig.py deleted file mode 100644 index de2137d66c..0000000000 --- a/tests/float 2/float2int_doubleprec_intbig.py +++ /dev/null @@ -1,100 +0,0 @@ -# check cases converting float to int, requiring double precision float - -try: - import ustruct as struct -except: - import struct - -import sys -maxsize_bits = 0 -maxsize = sys.maxsize -while maxsize: - maxsize >>= 1 - maxsize_bits += 1 - -# work out configuration values -is_64bit = maxsize_bits > 32 -# 0 = none, 1 = long long, 2 = mpz -ll_type = None -if is_64bit: - if maxsize_bits < 63: - ll_type = 0 -else: - if maxsize_bits < 31: - ll_type = 0 -if ll_type is None: - one = 1 - if one << 65 < one << 62: - ll_type = 1 - else: - ll_type = 2 - -# This case occurs with time.time() values -if ll_type != 0: - print(int(1418774543.)) - print("%d" % 1418774543.) - if ll_type == 3: - print(int(2.**100)) - print("%d" % 2.**100) -else: - print(int(1073741823.)) - print("%d" % 1073741823.) - -testpass = True -p2_rng = ((30,63,1024),(62,63,1024))[is_64bit][ll_type] -for i in range(0,p2_rng): - bitcnt = len(bin(int(2.**i))) - 3; - if i != bitcnt: - print('fail: 2**%u was %u bits long' % (i, bitcnt)); - testpass = False -print("power of 2 test: %s" % (testpass and 'passed' or 'failed')) - -testpass = True -p10_rng = ((9,18,23),(18,18,23))[is_64bit][ll_type] -for i in range(0,p10_rng): - digcnt = len(str(int(10.**i))) - 1; - if i != digcnt: - print('fail: 10**%u was %u digits long' % (i, digcnt)); - testpass = False -print("power of 10 test: %s" % (testpass and 'passed' or 'failed')) - -def fp2int_test(num, name, should_fail): - try: - x = int(num) - passed = ~should_fail - except: - passed = should_fail - print('%s: %s' % (name, passed and 'passed' or 'failed')) - -if ll_type != 2: - if ll_type == 0: - if is_64bit: - neg_bad_fp = -1.00000005*2.**62. - pos_bad_fp = 2.**62. - neg_good_fp = -2.**62. - pos_good_fp = 0.99999993*2.**62. - else: - neg_bad_fp = -1.00000005*2.**30. - pos_bad_fp = 2.**30. - neg_good_fp = -2.**30. - pos_good_fp = 0.9999999499*2.**30. - else: - neg_bad_fp = -0.51*2.**64. - pos_bad_fp = 2.**63. - neg_good_fp = -2.**63. - pos_good_fp = 1.9999998*2.**62. - - fp2int_test(neg_bad_fp, 'neg bad', True) - fp2int_test(pos_bad_fp, 'pos bad', True) - fp2int_test(neg_good_fp, 'neg good', False) - fp2int_test(pos_good_fp, 'pos good', False) -else: - fp2int_test(-1.9999999999999981*2.**1023., 'large neg', False) - fp2int_test(1.9999999999999981*2.**1023., 'large pos', False) - -fp2int_test(float('inf'), 'inf test', True) -fp2int_test(float('nan'), 'NaN test', True) - -# test numbers < 1 (this used to fail; see issue #1044) -fp2int_test(0.0001, 'small num', False) -struct.pack('I', int(1/2)) diff --git a/tests/float 2/float2int_fp30_intbig.py b/tests/float 2/float2int_fp30_intbig.py deleted file mode 100644 index fbb94a4ccc..0000000000 --- a/tests/float 2/float2int_fp30_intbig.py +++ /dev/null @@ -1,97 +0,0 @@ -# check cases converting float to int, relying only on single precision float - -try: - import ustruct as struct -except: - import struct - -import sys -maxsize_bits = 0 -maxsize = sys.maxsize -while maxsize: - maxsize >>= 1 - maxsize_bits += 1 - -# work out configuration values -is_64bit = maxsize_bits > 32 -# 0 = none, 1 = long long, 2 = mpz -ll_type = None -if is_64bit: - if maxsize_bits < 63: - ll_type = 0 -else: - if maxsize_bits < 31: - ll_type = 0 -if ll_type is None: - one = 1 - if one << 65 < one << 62: - ll_type = 1 - else: - ll_type = 2 - -# basic conversion -print(int(14187744.)) -print("%d" % 14187744.) -if ll_type == 2: - print(int(2.**100)) - print("%d" % 2.**100) - -testpass = True -p2_rng = ((30,63,127),(62,63,127))[is_64bit][ll_type] -for i in range(0,p2_rng): - bitcnt = len(bin(int(2.**i))) - 3; - if i != bitcnt: - print('fail: 2.**%u was %u bits long' % (i, bitcnt)); - testpass = False -print("power of 2 test: %s" % (testpass and 'passed' or 'failed')) - -# TODO why does 10**12 fail this test for single precision float? -testpass = True -p10_rng = 9 -for i in range(0,p10_rng): - digcnt = len(str(int(10.**i))) - 1; - if i != digcnt: - print('fail: 10.**%u was %u digits long' % (i, digcnt)); - testpass = False -print("power of 10 test: %s" % (testpass and 'passed' or 'failed')) - -def fp2int_test(num, name, should_fail): - try: - x = int(num) - passed = ~should_fail - except: - passed = should_fail - print('%s: %s' % (name, passed and 'passed' or 'failed')) - -if ll_type != 2: - if ll_type == 0: - if is_64bit: - neg_bad_fp = -1.00000005*2.**62. - pos_bad_fp = 2.**62. - neg_good_fp = -2.**62. - pos_good_fp = 0.99999993*2.**62. - else: - neg_bad_fp = -1.00000005*2.**30. - pos_bad_fp = 2.**30. - neg_good_fp = -2.**30. - pos_good_fp = 0.9999999499*2.**30. - else: - neg_bad_fp = -0.51*2.**64. - pos_bad_fp = 2.**63. - neg_good_fp = -2.**63. - pos_good_fp = 1.9999998*2.**62. - - fp2int_test(neg_bad_fp, 'neg bad', True) - fp2int_test(pos_bad_fp, 'pos bad', True) - fp2int_test(neg_good_fp, 'neg good', False) - fp2int_test(pos_good_fp, 'pos good', False) -else: - fp2int_test(-1.999999879*2.**126., 'large neg', False) - fp2int_test(1.999999879*2.**126., 'large pos', False) - -fp2int_test(float('inf'), 'inf test', True) -fp2int_test(float('nan'), 'NaN test', True) - -# test numbers < 1 (this used to fail; see issue #1044) -fp2int_test(0.0001, 'small num', False) -struct.pack('I', int(1/2)) diff --git a/tests/float 2/float2int_intbig.py b/tests/float 2/float2int_intbig.py deleted file mode 100644 index 3596d2f73d..0000000000 --- a/tests/float 2/float2int_intbig.py +++ /dev/null @@ -1,99 +0,0 @@ -# check cases converting float to int, relying only on single precision float - -try: - import ustruct as struct -except: - import struct - -import sys - -maxsize_bits = 0 -maxsize = sys.maxsize -while maxsize: - maxsize >>= 1 - maxsize_bits += 1 - -# work out configuration values -is_64bit = maxsize_bits > 32 -# 0 = none, 1 = long long, 2 = mpz -ll_type = None -if is_64bit: - if maxsize_bits < 63: - ll_type = 0 -else: - if maxsize_bits < 31: - ll_type = 0 -if ll_type is None: - one = 1 - if one << 65 < one << 62: - ll_type = 1 - else: - ll_type = 2 - - -# basic conversion -print(int(14187745.)) -print("%d" % 14187745.) -if ll_type == 2: - print(int(2.**100)) - print("%d" % 2.**100) - -testpass = True -p2_rng = ((30,63,127),(62,63,127))[is_64bit][ll_type] -for i in range(0,p2_rng): - bitcnt = len(bin(int(2.**i))) - 3; - if i != bitcnt: - print('fail: 2.**%u was %u bits long' % (i, bitcnt)); - testpass = False -print("power of 2 test: %s" % (testpass and 'passed' or 'failed')) - -# TODO why does 10**12 fail this test for single precision float? -testpass = True -p10_rng = 9 if (ll_type == 0 and ~is_64bit) else 11 -for i in range(0,p10_rng): - digcnt = len(str(int(10.**i))) - 1; - if i != digcnt: - print('fail: 10.**%u was %u digits long' % (i, digcnt)); - testpass = False -print("power of 10 test: %s" % (testpass and 'passed' or 'failed')) - -def fp2int_test(num, name, should_fail): - try: - x = int(num) - passed = ~should_fail - except: - passed = should_fail - print('%s: %s' % (name, passed and 'passed' or 'failed')) - -if ll_type != 2: - if ll_type == 0: - if is_64bit: - neg_bad_fp = -1.00000005*2.**62. - pos_bad_fp = 2.**62. - neg_good_fp = -2.**62. - pos_good_fp = 0.99999993*2.**62. - else: - neg_bad_fp = -1.00000005*2.**30. - pos_bad_fp = 2.**30. - neg_good_fp = -2.**30. - pos_good_fp = 0.9999999499*2.**30. - else: - neg_bad_fp = -0.51*2.**64. - pos_bad_fp = 2.**63. - neg_good_fp = -2.**63. - pos_good_fp = 1.9999998*2.**62. - - fp2int_test(neg_bad_fp, 'neg bad', True) - fp2int_test(pos_bad_fp, 'pos bad', True) - fp2int_test(neg_good_fp, 'neg good', False) - fp2int_test(pos_good_fp, 'pos good', False) -else: - fp2int_test(-1.999999879*2.**127., 'large neg', False) - fp2int_test(1.999999879*2.**127., 'large pos', False) - -fp2int_test(float('inf'), 'inf test', True) -fp2int_test(float('nan'), 'NaN test', True) - -# test numbers < 1 (this used to fail; see issue #1044) -fp2int_test(0.0001, 'small num', False) -struct.pack('I', int(1/2)) diff --git a/tests/float 2/float_array.py b/tests/float 2/float_array.py deleted file mode 100644 index 8c8edcff7c..0000000000 --- a/tests/float 2/float_array.py +++ /dev/null @@ -1,20 +0,0 @@ -try: - from array import array -except ImportError: - print("SKIP") - raise SystemExit - -def test(a): - print(a) - a.append(1.2) - print(len(a), '%.3f' % a[0]) - a.append(1) - a.append(False) - print(len(a), '%.3f %.3f' % (a[1], a[2])) - a[-1] = 3.45 - print('%.3f' % a[-1]) - -test(array('f')) -test(array('d')) - -print('{:.4f}'.format(array('f', b'\xcc\xcc\xcc=')[0])) diff --git a/tests/float 2/float_compare.py b/tests/float 2/float_compare.py deleted file mode 100644 index 105923ac73..0000000000 --- a/tests/float 2/float_compare.py +++ /dev/null @@ -1,22 +0,0 @@ -# Extended float comparisons - -class Foo: - pass - -foo = Foo() - -print(foo == 1.0) -print(1.0 == foo) -print(1.0 == Foo) -print(1.0 == []) -print(1.0 == {}) - -try: - print(foo < 1.0) -except TypeError: - print("TypeError") - -try: - print(1.0 < foo) -except TypeError: - print("TypeError") diff --git a/tests/float 2/float_divmod.py b/tests/float 2/float_divmod.py deleted file mode 100644 index 8e7cd435a5..0000000000 --- a/tests/float 2/float_divmod.py +++ /dev/null @@ -1,25 +0,0 @@ -# test floating point floor divide and modulus -# it has some tricky corner cases - -def test(x, y): - div, mod = divmod(x, y) - print('%.8f %.8f %.8f %.8f' % (x // y, x % y, div, mod)) - print(div == x // y, mod == x % y, abs(div * y + mod - x) < 1e-15) - -test(1.23456, 0.7) -test(-1.23456, 0.7) -test(1.23456, -0.7) -test(-1.23456, -0.7) - -a = 1.23456 -b = 0.7 -test(a, b) -test(a, -b) -test(-a, b) -test(-a, -b) - -for i in range(25): - x = (i - 12.5) / 6 - for j in range(25): - y = (j - 12.5) / 6 - test(x, y) diff --git a/tests/float 2/float_divmod_relaxed.py b/tests/float 2/float_divmod_relaxed.py deleted file mode 100644 index a9450fa2c4..0000000000 --- a/tests/float 2/float_divmod_relaxed.py +++ /dev/null @@ -1,33 +0,0 @@ -# test floating point floor divide and modulus -# it has some tricky corner cases - -# pyboard has 32-bit floating point and gives different (but still -# correct) answers for certain combinations of divmod arguments. - -def test(x, y): - div, mod = divmod(x, y) - print(div == x // y, mod == x % y, abs(div * y + mod - x) < 1e-6) - -test(1.23456, 0.7) -test(-1.23456, 0.7) -test(1.23456, -0.7) -test(-1.23456, -0.7) - -a = 1.23456 -b = 0.7 -test(a, b) -test(a, -b) -test(-a, b) -test(-a, -b) - -for i in range(25): - x = (i - 12.5) / 6 - for j in range(25): - y = (j - 12.5) / 6 - test(x, y) - -# test division by zero error -try: - divmod(1.0, 0) -except ZeroDivisionError: - print('ZeroDivisionError') diff --git a/tests/float 2/float_format.py b/tests/float 2/float_format.py deleted file mode 100644 index d43535cf2f..0000000000 --- a/tests/float 2/float_format.py +++ /dev/null @@ -1,19 +0,0 @@ -# test float formatting - -# general rounding -for val in (116, 1111, 1234, 5010, 11111): - print('%.0f' % val) - print('%.1f' % val) - print('%.3f' % val) - -# make sure rounding is done at the correct precision -for prec in range(8): - print(('%%.%df' % prec) % 6e-5) - -# check certain cases that had a digit value of 10 render as a ":" character -print('%.2e' % float('9' * 51 + 'e-39')) -print('%.2e' % float('9' * 40 + 'e-21')) - -# check a case that would render negative digit values, eg ")" characters -# the string is converted back to a float to check for no illegal characters -float('%.23e' % 1e-80) diff --git a/tests/float 2/float_parse.py b/tests/float 2/float_parse.py deleted file mode 100644 index 4b026de1c8..0000000000 --- a/tests/float 2/float_parse.py +++ /dev/null @@ -1,32 +0,0 @@ -# test parsing of floats - -inf = float('inf') - -# it shouldn't matter where the decimal point is if the exponent balances the value -print(float('1234') - float('0.1234e4')) -print(float('1.015625') - float('1015625e-6')) - -# very large integer part with a very negative exponent should cancel out -print('%.4e' % float('9' * 60 + 'e-60')) -print('%.4e' % float('9' * 60 + 'e-40')) - -# many fractional digits -print(float('.' + '9' * 70)) -print(float('.' + '9' * 70 + 'e20')) -print(float('.' + '9' * 70 + 'e-50') == float('1e-50')) - -# tiny fraction with large exponent -print(float('.' + '0' * 60 + '1e10') == float('1e-51')) -print(float('.' + '0' * 60 + '9e25') == float('9e-36')) -print(float('.' + '0' * 60 + '9e40') == float('9e-21')) - -# ensure that accuracy is retained when value is close to a subnormal -print(float('1.00000000000000000000e-37')) -print(float('10.0000000000000000000e-38')) -print(float('100.000000000000000000e-39')) - -# very large exponent literal -print(float('1e4294967301')) -print(float('1e-4294967301')) -print(float('1e18446744073709551621')) -print(float('1e-18446744073709551621')) diff --git a/tests/float 2/float_parse_doubleprec.py b/tests/float 2/float_parse_doubleprec.py deleted file mode 100644 index dcc0dd5921..0000000000 --- a/tests/float 2/float_parse_doubleprec.py +++ /dev/null @@ -1,21 +0,0 @@ -# test parsing of floats, requiring double-precision - -# very large integer part with a very negative exponent should cancel out -print(float('9' * 400 + 'e-100')) -print(float('9' * 400 + 'e-200')) -print(float('9' * 400 + 'e-400')) - -# many fractional digits -print(float('.' + '9' * 400)) -print(float('.' + '9' * 400 + 'e100')) -print(float('.' + '9' * 400 + 'e-100')) - -# tiny fraction with large exponent -print('%.14e' % float('.' + '0' * 400 + '9e100')) -print('%.14e' % float('.' + '0' * 400 + '9e200')) -print('%.14e' % float('.' + '0' * 400 + '9e400')) - -# ensure that accuracy is retained when value is close to a subnormal -print(float('1.00000000000000000000e-307')) -print(float('10.0000000000000000000e-308')) -print(float('100.000000000000000000e-309')) diff --git a/tests/float 2/float_struct.py b/tests/float 2/float_struct.py deleted file mode 100644 index dd7a418ad5..0000000000 --- a/tests/float 2/float_struct.py +++ /dev/null @@ -1,17 +0,0 @@ -# test struct package with floats -try: - try: - import ustruct as struct - except: - import struct -except ImportError: - print("SKIP") - raise SystemExit - -i = 1. + 1/2 -# TODO: it looks like '=' format modifier is not yet supported -# for fmt in ('f', 'd', '>f', '>d', 'f', '>d', '' + fmt.format(*args) + '<') - -test("{:10.4}", 123.456) -test("{:10.4e}", 123.456) -test("{:10.4e}", -123.456) -test("{:10.4f}", 123.456) -test("{:10.4f}", -123.456) -test("{:10.4g}", 123.456) -test("{:10.4g}", -123.456) -test("{:10.4n}", 123.456) -test("{:e}", 100) -test("{:f}", 200) -test("{:g}", 300) - -test("{:10.4E}", 123.456) -test("{:10.4E}", -123.456) -test("{:10.4F}", 123.456) -test("{:10.4F}", -123.456) -test("{:10.4G}", 123.456) -test("{:10.4G}", -123.456) - -test("{:06e}", float("inf")) -test("{:06e}", float("-inf")) -test("{:06e}", float("nan")) - -# The following fails right now -#test("{:10.1}", 0.0) - -print("%.0f" % (1.750000 % 0.08333333333)) -# Below isn't compatible with single-precision float -#print("%.1f" % (1.750000 % 0.08333333333)) -#print("%.2f" % (1.750000 % 0.08333333333)) -#print("%.12f" % (1.750000 % 0.08333333333)) - -# tests for errors in format string - -try: - '{:10.1b}'.format(0.0) -except ValueError: - print('ValueError') diff --git a/tests/float 2/string_format2.py b/tests/float 2/string_format2.py deleted file mode 100644 index 269023e7ff..0000000000 --- a/tests/float 2/string_format2.py +++ /dev/null @@ -1,106 +0,0 @@ -# Change the following to True to get a much more comprehensive set of tests -# to run, albeit, which take considerably longer. - -full_tests = False - -def test(fmt, *args): - print('{:8s}'.format(fmt) + '>' + fmt.format(*args) + '<') - -def test_fmt(conv, fill, alignment, sign, prefix, width, precision, type, arg): - fmt = '{' - if conv: - fmt += '!' - fmt += conv - fmt += ':' - if alignment: - fmt += fill - fmt += alignment - fmt += sign - fmt += prefix - fmt += width - if precision: - fmt += '.' - fmt += precision - fmt += type - fmt += '}' - test(fmt, arg) - if fill == '0' and alignment == '=': - fmt = '{:' - fmt += sign - fmt += prefix - fmt += width - if precision: - fmt += '.' - fmt += precision - fmt += type - fmt += '}' - test(fmt, arg) - -eg_nums = (0.0, -0.0, 0.1, 1.234, 12.3459, 1.23456789, 123456789.0, -0.0, - -0.1, -1.234, -12.3459, 1e4, 1e-4, 1e5, 1e-5, 1e6, 1e-6, 1e10, - 1e37, -1e37, 1e-37, -1e-37, - 1.23456e8, 1.23456e7, 1.23456e6, 1.23456e5, 1.23456e4, 1.23456e3, 1.23456e2, 1.23456e1, 1.23456e0, - 1.23456e-1, 1.23456e-2, 1.23456e-3, 1.23456e-4, 1.23456e-5, 1.23456e-6, 1.23456e-7, 1.23456e-8, - -1.23456e8, -1.23456e7, -1.23456e6, -1.23456e5, -1.23456e4, -1.23456e3, -1.23456e2, -1.23456e1, -1.23456e0, - -1.23456e-1, -1.23456e-2, -1.23456e-3, -1.23456e-4, -1.23456e-5, -1.23456e-6, -1.23456e-7, -1.23456e-8) - -if full_tests: - for type in ('e', 'E', 'g', 'G', 'n'): - for width in ('', '4', '6', '8', '10'): - for alignment in ('', '<', '>', '=', '^'): - for fill in ('', '@', '0', ' '): - for sign in ('', '+', '-', ' '): - for prec in ('', '1', '3', '6'): - for num in eg_nums: - test_fmt('', fill, alignment, sign, '', width, prec, type, num) - -# Note: We use 1.23459 rather than 1.2345 because '{:3f}'.format(1.2345) -# rounds differently than print("%.3f", 1.2345); - -f_nums = (0.0, -0.0, 0.0001, 0.001, 0.01, 0.1, 1.0, 10.0, - 0.0012, 0.0123, 0.1234, 1.23459, 12.3456, - -0.0001, -0.001, -0.01, -0.1, -1.0, -10.0, - -0.0012, -0.0123, -0.1234, -1.23459, -12.3456) - -if full_tests: - for type in ('f', 'F'): - for width in ('', '4', '6', '8', '10'): - for alignment in ('', '<', '>', '=', '^'): - for fill in ('', ' ', '0', '@'): - for sign in ('', '+', '-', ' '): - # An empty precision defaults to 6, but when uPy is - # configured to use a float, we can only use a - # precision of 6 with numbers less than 10 and still - # get results that compare to CPython (which uses - # long doubles). - for prec in ('1', '2', '3'): - for num in f_nums: - test_fmt('', fill, alignment, sign, '', width, prec, type, num) - for num in int_nums2: - test_fmt('', fill, alignment, sign, '', width, '', type, num) - -pct_nums1 = (0.1, 0.58, 0.99, -0.1, -0.58, -0.99) -pct_nums2 = (True, False, 1, 0, -1) - -if full_tests: - type = '%' - for width in ('', '4', '6', '8', '10'): - for alignment in ('', '<', '>', '=', '^'): - for fill in ('', ' ', '0', '@'): - for sign in ('', '+', '-', ' '): - # An empty precision defaults to 6, but when uPy is - # configured to use a float, we can only use a - # precision of 6 with numbers less than 10 and still - # get results that compare to CPython (which uses - # long doubles). - for prec in ('1', '2', '3'): - for num in pct_nums1: - test_fmt('', fill, alignment, sign, '', width, prec, type, num) - for num in pct_nums2: - test_fmt('', fill, alignment, sign, '', width, '', type, num) -else: - for num in pct_nums1: - test_fmt('', '', '', '', '', '', '1', '%', num) - -# We don't currently test a type of '' with floats (see the detailed comment -# in objstr.c) diff --git a/tests/float 2/string_format_fp30.py b/tests/float 2/string_format_fp30.py deleted file mode 100644 index 77b2a52885..0000000000 --- a/tests/float 2/string_format_fp30.py +++ /dev/null @@ -1,41 +0,0 @@ -def test(fmt, *args): - print('{:8s}'.format(fmt) + '>' + fmt.format(*args) + '<') - -test("{:10.4}", 123.456) -test("{:10.4e}", 123.456) -test("{:10.4e}", -123.456) -#test("{:10.4f}", 123.456) -#test("{:10.4f}", -123.456) -test("{:10.4g}", 123.456) -test("{:10.4g}", -123.456) -test("{:10.4n}", 123.456) -test("{:e}", 100) -test("{:f}", 200) -test("{:g}", 300) - -test("{:10.4E}", 123.456) -test("{:10.4E}", -123.456) -#test("{:10.4F}", 123.456) -#test("{:10.4F}", -123.456) -test("{:10.4G}", 123.456) -test("{:10.4G}", -123.456) - -test("{:06e}", float("inf")) -test("{:06e}", float("-inf")) -test("{:06e}", float("nan")) - -# The following fails right now -#test("{:10.1}", 0.0) - -print("%.0f" % (1.750000 % 0.08333333333)) -# Below isn't compatible with single-precision float -#print("%.1f" % (1.750000 % 0.08333333333)) -#print("%.2f" % (1.750000 % 0.08333333333)) -#print("%.12f" % (1.750000 % 0.08333333333)) - -# tests for errors in format string - -try: - '{:10.1b}'.format(0.0) -except ValueError: - print('ValueError') diff --git a/tests/float 2/string_format_modulo.py b/tests/float 2/string_format_modulo.py deleted file mode 100644 index aea534247c..0000000000 --- a/tests/float 2/string_format_modulo.py +++ /dev/null @@ -1,49 +0,0 @@ -print("%s" % 1.0) -print("%r" % 1.0) - -print("%d" % 1.0) -print("%i" % 1.0) -print("%u" % 1.0) - -# these 3 have different behaviour in Python 3.x versions -# uPy raises a TypeError, following Python 3.5 (earlier versions don't) -#print("%x" % 18.0) -#print("%o" % 18.0) -#print("%X" % 18.0) - -print("%e" % 1.23456) -print("%E" % 1.23456) -print("%f" % 1.23456) -print("%F" % 1.23456) -print("%g" % 1.23456) -print("%G" % 1.23456) - -print("%06e" % float("inf")) -print("%06e" % float("-inf")) -print("%06e" % float("nan")) - -print("%02.3d" % 123) # prec > width -print("%+f %+f" % (1.23, -1.23)) # float sign -print("% f % f" % (1.23, -1.23)) # float space sign -print("%0f" % -1.23) # negative number with 0 padding - -# numbers with large negative exponents -print('%f' % 1e-10) -print('%f' % 1e-20) -print('%f' % 1e-50) -print('%f' % 1e-100) -print('%f' % 1e-300) - -# large decimal precision should be truncated and not overflow buffer -# the output depends on the FP calculation so only first 2 digits are printed -# (the 'g' with small e are printed using 'f' style, so need to be checked) -print(('%.40f' % 1e-300)[:2]) -print(('%.40g' % 1e-1)[:2]) -print(('%.40g' % 1e-2)[:2]) -print(('%.40g' % 1e-3)[:2]) -print(('%.40g' % 1e-4)[:2]) - -print("%.0g" % 1) # 0 precision 'g' - -print('%.1e' % 9.99) # round up with positive exponent -print('%.1e' % 0.999) # round up with negative exponent diff --git a/tests/float 2/string_format_modulo2.py b/tests/float 2/string_format_modulo2.py deleted file mode 100644 index f6b1ae537d..0000000000 --- a/tests/float 2/string_format_modulo2.py +++ /dev/null @@ -1,24 +0,0 @@ -# test formatting floats with large precision, that it doesn't overflow the buffer - -def test(num, num_str): - if num == float('inf') or num == 0.0 and num_str != '0.0': - # skip numbers that overflow or underflow the FP precision - return - for kind in ('e', 'f', 'g'): - # check precision either side of the size of the buffer (32 bytes) - for prec in range(23, 36, 2): - fmt = '%.' + '%d' % prec + kind - s = fmt % num - check = abs(float(s) - num) - if num > 1: - check /= num - if check > 1e-6: - print('FAIL', num_str, fmt, s, len(s), check) - -# check pure zero -test(0.0, '0.0') - -# check some powers of 10, making sure to include exponents with 3 digits -for e in range(-8, 8): - num = pow(10, e) - test(num, '1e%d' % e) diff --git a/tests/float 2/string_format_modulo2_intbig.py b/tests/float 2/string_format_modulo2_intbig.py deleted file mode 100644 index 9992ba65d9..0000000000 --- a/tests/float 2/string_format_modulo2_intbig.py +++ /dev/null @@ -1,21 +0,0 @@ -# test formatting floats with large precision, that it doesn't overflow the buffer - -def test(num, num_str): - if num == float('inf') or num == 0.0 and num_str != '0.0': - # skip numbers that overflow or underflow the FP precision - return - for kind in ('e', 'f', 'g'): - # check precision either side of the size of the buffer (32 bytes) - for prec in range(23, 36, 2): - fmt = '%.' + '%d' % prec + kind - s = fmt % num - check = abs(float(s) - num) - if num > 1: - check /= num - if check > 1e-6: - print('FAIL', num_str, fmt, s, len(s), check) - -# check most powers of 10, making sure to include exponents with 3 digits -for e in range(-101, 102): - num = pow(10, e) - test(num, '1e%d' % e) diff --git a/tests/float 2/string_format_modulo3.py b/tests/float 2/string_format_modulo3.py deleted file mode 100644 index 5d26f25751..0000000000 --- a/tests/float 2/string_format_modulo3.py +++ /dev/null @@ -1,3 +0,0 @@ -# uPy and CPython outputs differ for the following -print("%.1g" % -9.9) # round up 'g' with '-' sign -print("%.2g" % 99.9) # round up diff --git a/tests/float 2/string_format_modulo3.py.exp b/tests/float 2/string_format_modulo3.py.exp deleted file mode 100644 index 71432b3404..0000000000 --- a/tests/float 2/string_format_modulo3.py.exp +++ /dev/null @@ -1,2 +0,0 @@ --10 -100 diff --git a/tests/float 2/true_value.py b/tests/float 2/true_value.py deleted file mode 100644 index df415f0031..0000000000 --- a/tests/float 2/true_value.py +++ /dev/null @@ -1,7 +0,0 @@ -# Test true-ish value handling - -if not 0.0: - print("float 0") - -if not 0+0j: - print("complex 0") diff --git a/tests/float 2/types.py b/tests/float 2/types.py deleted file mode 100644 index 75674c9246..0000000000 --- a/tests/float 2/types.py +++ /dev/null @@ -1,17 +0,0 @@ -# float types - -print(float) -print(complex) - -print(type(float()) == float) -print(type(complex()) == complex) - -print(type(0.0) == float) -print(type(1j) == complex) - -# hashing float types - -d = dict() -d[float] = complex -d[complex] = float -print(len(d)) diff --git a/tests/inlineasm 2/asmargs.py b/tests/inlineasm 2/asmargs.py deleted file mode 100644 index 047d9ed420..0000000000 --- a/tests/inlineasm 2/asmargs.py +++ /dev/null @@ -1,29 +0,0 @@ -# test passing arguments - -@micropython.asm_thumb -def arg0(): - mov(r0, 1) -print(arg0()) - -@micropython.asm_thumb -def arg1(r0): - add(r0, r0, 1) -print(arg1(1)) - -@micropython.asm_thumb -def arg2(r0, r1): - add(r0, r0, r1) -print(arg2(1, 2)) - -@micropython.asm_thumb -def arg3(r0, r1, r2): - add(r0, r0, r1) - add(r0, r0, r2) -print(arg3(1, 2, 3)) - -@micropython.asm_thumb -def arg4(r0, r1, r2, r3): - add(r0, r0, r1) - add(r0, r0, r2) - add(r0, r0, r3) -print(arg4(1, 2, 3, 4)) diff --git a/tests/inlineasm 2/asmargs.py.exp b/tests/inlineasm 2/asmargs.py.exp deleted file mode 100644 index e33a6964f4..0000000000 --- a/tests/inlineasm 2/asmargs.py.exp +++ /dev/null @@ -1,5 +0,0 @@ -1 -2 -3 -6 -10 diff --git a/tests/inlineasm 2/asmbcc.py b/tests/inlineasm 2/asmbcc.py deleted file mode 100644 index 540fa6591f..0000000000 --- a/tests/inlineasm 2/asmbcc.py +++ /dev/null @@ -1,27 +0,0 @@ -# test bcc instructions -# at the moment only tests beq, narrow and wide versions - -@micropython.asm_thumb -def f(r0): - mov(r1, r0) - - mov(r0, 10) - cmp(r1, 1) - beq(end) - - mov(r0, 20) - cmp(r1, 2) - beq_n(end) - - mov(r0, 30) - cmp(r1, 3) - beq_w(end) - - mov(r0, 0) - - label(end) - -print(f(0)) -print(f(1)) -print(f(2)) -print(f(3)) diff --git a/tests/inlineasm 2/asmbcc.py.exp b/tests/inlineasm 2/asmbcc.py.exp deleted file mode 100644 index 39da7d1a99..0000000000 --- a/tests/inlineasm 2/asmbcc.py.exp +++ /dev/null @@ -1,4 +0,0 @@ -0 -10 -20 -30 diff --git a/tests/inlineasm 2/asmbitops.py b/tests/inlineasm 2/asmbitops.py deleted file mode 100644 index 8cf92b301f..0000000000 --- a/tests/inlineasm 2/asmbitops.py +++ /dev/null @@ -1,13 +0,0 @@ -@micropython.asm_thumb -def clz(r0): - clz(r0, r0) - -print(clz(0xf0)) -print(clz(0x8000)) - -@micropython.asm_thumb -def rbit(r0): - rbit(r0, r0) - -print(hex(rbit(0xf0))) -print(hex(rbit(0x8000))) diff --git a/tests/inlineasm 2/asmbitops.py.exp b/tests/inlineasm 2/asmbitops.py.exp deleted file mode 100644 index 8c560045f4..0000000000 --- a/tests/inlineasm 2/asmbitops.py.exp +++ /dev/null @@ -1,4 +0,0 @@ -24 -16 -0xf000000 -0x10000 diff --git a/tests/inlineasm 2/asmblbx.py b/tests/inlineasm 2/asmblbx.py deleted file mode 100644 index d08c0ed6b3..0000000000 --- a/tests/inlineasm 2/asmblbx.py +++ /dev/null @@ -1,21 +0,0 @@ -# test bl and bx instructions - -@micropython.asm_thumb -def f(r0): - # jump over the internal functions - b(entry) - - label(func1) - add(r0, 2) - bx(lr) - - label(func2) - sub(r0, 1) - bx(lr) - - label(entry) - bl(func1) - bl(func2) - -print(f(0)) -print(f(1)) diff --git a/tests/inlineasm 2/asmblbx.py.exp b/tests/inlineasm 2/asmblbx.py.exp deleted file mode 100644 index 1191247b6d..0000000000 --- a/tests/inlineasm 2/asmblbx.py.exp +++ /dev/null @@ -1,2 +0,0 @@ -1 -2 diff --git a/tests/inlineasm 2/asmconst.py b/tests/inlineasm 2/asmconst.py deleted file mode 100644 index 299a25093c..0000000000 --- a/tests/inlineasm 2/asmconst.py +++ /dev/null @@ -1,8 +0,0 @@ -# test constants in assembler - -@micropython.asm_thumb -def c1(): - movwt(r0, 0xffffffff) - movwt(r1, 0xf0000000) - sub(r0, r0, r1) -print(hex(c1())) diff --git a/tests/inlineasm 2/asmconst.py.exp b/tests/inlineasm 2/asmconst.py.exp deleted file mode 100644 index 3ef9fcabd7..0000000000 --- a/tests/inlineasm 2/asmconst.py.exp +++ /dev/null @@ -1 +0,0 @@ -0xfffffff diff --git a/tests/inlineasm 2/asmdiv.py b/tests/inlineasm 2/asmdiv.py deleted file mode 100644 index b97d566eb5..0000000000 --- a/tests/inlineasm 2/asmdiv.py +++ /dev/null @@ -1,16 +0,0 @@ -@micropython.asm_thumb -def sdiv(r0, r1): - sdiv(r0, r0, r1) - -@micropython.asm_thumb -def udiv(r0, r1): - udiv(r0, r0, r1) - -print(sdiv(1234, 3)) -print(sdiv(-1234, 3)) -print(sdiv(1234, -3)) -print(sdiv(-1234, -3)) - -print(udiv(1234, 3)) -print(udiv(0xffffffff, 0x7fffffff)) -print(udiv(0xffffffff, 0xffffffff)) diff --git a/tests/inlineasm 2/asmdiv.py.exp b/tests/inlineasm 2/asmdiv.py.exp deleted file mode 100644 index f1b80deb32..0000000000 --- a/tests/inlineasm 2/asmdiv.py.exp +++ /dev/null @@ -1,7 +0,0 @@ -411 --411 --411 -411 -411 -2 -1 diff --git a/tests/inlineasm 2/asmfpaddsub.py b/tests/inlineasm 2/asmfpaddsub.py deleted file mode 100644 index 2bdfccf0e0..0000000000 --- a/tests/inlineasm 2/asmfpaddsub.py +++ /dev/null @@ -1,14 +0,0 @@ -@micropython.asm_thumb # r0 = r0+r1-r2 -def add_sub(r0, r1, r2): - vmov(s0, r0) - vcvt_f32_s32(s0, s0) - vmov(s1, r1) - vcvt_f32_s32(s1, s1) - vmov(s2, r2) - vcvt_f32_s32(s2, s2) - vadd(s0, s0, s1) - vsub(s0, s0, s2) - vcvt_s32_f32(s31, s0) - vmov(r0, s31) - -print(add_sub(100, 20, 30)) diff --git a/tests/inlineasm 2/asmfpaddsub.py.exp b/tests/inlineasm 2/asmfpaddsub.py.exp deleted file mode 100644 index d61f00d8ca..0000000000 --- a/tests/inlineasm 2/asmfpaddsub.py.exp +++ /dev/null @@ -1 +0,0 @@ -90 diff --git a/tests/inlineasm 2/asmfpcmp.py b/tests/inlineasm 2/asmfpcmp.py deleted file mode 100644 index d4fa1f2410..0000000000 --- a/tests/inlineasm 2/asmfpcmp.py +++ /dev/null @@ -1,14 +0,0 @@ -@micropython.asm_thumb # test vcmp, vmrs -def f(r0, r1): - vmov(s0, r0) - vcvt_f32_s32(s0, s0) - vmov(s1, r1) - vcvt_f32_s32(s1, s1) - vcmp(s1, s0) - vmrs(r0, FPSCR) - mov(r1, 28) - lsr(r0, r1) - -print(f(0,1)) -print(f(1,1)) -print(f(1,0)) diff --git a/tests/inlineasm 2/asmfpcmp.py.exp b/tests/inlineasm 2/asmfpcmp.py.exp deleted file mode 100644 index 104b3580f7..0000000000 --- a/tests/inlineasm 2/asmfpcmp.py.exp +++ /dev/null @@ -1,3 +0,0 @@ -2 -6 -8 diff --git a/tests/inlineasm 2/asmfpldrstr.py b/tests/inlineasm 2/asmfpldrstr.py deleted file mode 100644 index 4c480671f9..0000000000 --- a/tests/inlineasm 2/asmfpldrstr.py +++ /dev/null @@ -1,11 +0,0 @@ -import array -@micropython.asm_thumb # test vldr, vstr -def arrayadd(r0): - vldr(s0, [r0, 0]) - vldr(s1, [r0, 4]) - vadd(s2, s0, s1) - vstr(s2, [r0, 8]) - -z = array.array("f", [2, 4, 10]) -arrayadd(z) -print(z[2]) diff --git a/tests/inlineasm 2/asmfpldrstr.py.exp b/tests/inlineasm 2/asmfpldrstr.py.exp deleted file mode 100644 index e0ea36feef..0000000000 --- a/tests/inlineasm 2/asmfpldrstr.py.exp +++ /dev/null @@ -1 +0,0 @@ -6.0 diff --git a/tests/inlineasm 2/asmfpmuldiv.py b/tests/inlineasm 2/asmfpmuldiv.py deleted file mode 100644 index 043a28e229..0000000000 --- a/tests/inlineasm 2/asmfpmuldiv.py +++ /dev/null @@ -1,14 +0,0 @@ -@micropython.asm_thumb # r0 = (int)(r0*r1/r2) -def muldiv(r0, r1, r2): - vmov(s0, r0) - vcvt_f32_s32(s0, s0) - vmov(s1, r1) - vcvt_f32_s32(s1, s1) - vmov(s2, r2) - vcvt_f32_s32(s2, s2) - vmul(s7, s0, s1) - vdiv(s8, s7, s2) - vcvt_s32_f32(s31, s8) - vmov(r0, s31) - -print(muldiv(100, 10, 50)) diff --git a/tests/inlineasm 2/asmfpmuldiv.py.exp b/tests/inlineasm 2/asmfpmuldiv.py.exp deleted file mode 100644 index 209e3ef4b6..0000000000 --- a/tests/inlineasm 2/asmfpmuldiv.py.exp +++ /dev/null @@ -1 +0,0 @@ -20 diff --git a/tests/inlineasm 2/asmfpsqrt.py b/tests/inlineasm 2/asmfpsqrt.py deleted file mode 100644 index 7b7d52e238..0000000000 --- a/tests/inlineasm 2/asmfpsqrt.py +++ /dev/null @@ -1,14 +0,0 @@ -# test vsqrt, vneg -@micropython.asm_thumb # r0 = -(int)(sqrt(r0)*r1) -def sqrt_test(r0, r1): - vmov(s1, r0) - vcvt_f32_s32(s1, s1) - vsqrt(s1, s1) - vmov(s2, r1) - vcvt_f32_s32(s2, s2) - vmul(s0, s1, s2) - vneg(s7, s0) - vcvt_s32_f32(s31, s7) - vmov(r0, s31) - -print(sqrt_test(256, 10)) diff --git a/tests/inlineasm 2/asmfpsqrt.py.exp b/tests/inlineasm 2/asmfpsqrt.py.exp deleted file mode 100644 index 88a1e93bab..0000000000 --- a/tests/inlineasm 2/asmfpsqrt.py.exp +++ /dev/null @@ -1 +0,0 @@ --160 diff --git a/tests/inlineasm 2/asmit.py b/tests/inlineasm 2/asmit.py deleted file mode 100644 index 57bfcc7f9a..0000000000 --- a/tests/inlineasm 2/asmit.py +++ /dev/null @@ -1,16 +0,0 @@ -# test it instruction - -@micropython.asm_thumb -def f(r0, r1): - cmp(r0, r1) - it(eq) - mov(r0, 100) -print(f(0, 0), f(1, 2)) - -@micropython.asm_thumb -def g(r0, r1): - cmp(r0, r1) - ite(eq) - mov(r0, 100) - mov(r0, 200) -print(g(0, 0), g(0, 1)) diff --git a/tests/inlineasm 2/asmit.py.exp b/tests/inlineasm 2/asmit.py.exp deleted file mode 100644 index d06c72d9bb..0000000000 --- a/tests/inlineasm 2/asmit.py.exp +++ /dev/null @@ -1,2 +0,0 @@ -100 1 -100 200 diff --git a/tests/inlineasm 2/asmpushpop.py b/tests/inlineasm 2/asmpushpop.py deleted file mode 100644 index c9005434ba..0000000000 --- a/tests/inlineasm 2/asmpushpop.py +++ /dev/null @@ -1,8 +0,0 @@ -@micropython.asm_thumb -def f(r0, r1, r2): - push({r0}) - push({r1, r2}) - pop({r0}) - pop({r1, r2}) - -print(f(0, 1, 2)) diff --git a/tests/inlineasm 2/asmpushpop.py.exp b/tests/inlineasm 2/asmpushpop.py.exp deleted file mode 100644 index d00491fd7e..0000000000 --- a/tests/inlineasm 2/asmpushpop.py.exp +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/tests/inlineasm 2/asmrettype.py b/tests/inlineasm 2/asmrettype.py deleted file mode 100644 index f1918696ee..0000000000 --- a/tests/inlineasm 2/asmrettype.py +++ /dev/null @@ -1,21 +0,0 @@ -# test return type of inline asm - -@micropython.asm_thumb -def ret_obj(r0) -> object: - pass -ret_obj(print)(1) - -@micropython.asm_thumb -def ret_bool(r0) -> bool: - pass -print(ret_bool(0), ret_bool(1)) - -@micropython.asm_thumb -def ret_int(r0) -> int: - lsl(r0, r0, 29) -print(ret_int(0), hex(ret_int(1)), hex(ret_int(2)), hex(ret_int(4))) - -@micropython.asm_thumb -def ret_uint(r0) -> uint: - lsl(r0, r0, 29) -print(ret_uint(0), hex(ret_uint(1)), hex(ret_uint(2)), hex(ret_uint(4))) diff --git a/tests/inlineasm 2/asmrettype.py.exp b/tests/inlineasm 2/asmrettype.py.exp deleted file mode 100644 index cbb49d2472..0000000000 --- a/tests/inlineasm 2/asmrettype.py.exp +++ /dev/null @@ -1,4 +0,0 @@ -1 -False True -0 0x20000000 0x40000000 -0x80000000 -0 0x20000000 0x40000000 0x80000000 diff --git a/tests/inlineasm 2/asmshift.py b/tests/inlineasm 2/asmshift.py deleted file mode 100644 index 0df2187347..0000000000 --- a/tests/inlineasm 2/asmshift.py +++ /dev/null @@ -1,29 +0,0 @@ -@micropython.asm_thumb -def lsl1(r0): - lsl(r0, r0, 1) -print(hex(lsl1(0x123))) - -@micropython.asm_thumb -def lsl23(r0): - lsl(r0, r0, 23) -print(hex(lsl23(1))) - -@micropython.asm_thumb -def lsr1(r0): - lsr(r0, r0, 1) -print(hex(lsr1(0x123))) - -@micropython.asm_thumb -def lsr31(r0): - lsr(r0, r0, 31) -print(hex(lsr31(0x80000000))) - -@micropython.asm_thumb -def asr1(r0): - asr(r0, r0, 1) -print(hex(asr1(0x123))) - -@micropython.asm_thumb -def asr31(r0): - asr(r0, r0, 31) -print(hex(asr31(0x80000000))) diff --git a/tests/inlineasm 2/asmshift.py.exp b/tests/inlineasm 2/asmshift.py.exp deleted file mode 100644 index c6c3a72179..0000000000 --- a/tests/inlineasm 2/asmshift.py.exp +++ /dev/null @@ -1,6 +0,0 @@ -0x246 -0x800000 -0x91 -0x1 -0x91 --0x1 diff --git a/tests/inlineasm 2/asmspecialregs.py b/tests/inlineasm 2/asmspecialregs.py deleted file mode 100644 index 2d3b0e396f..0000000000 --- a/tests/inlineasm 2/asmspecialregs.py +++ /dev/null @@ -1,10 +0,0 @@ -@micropython.asm_thumb -def getIPSR(): - mrs(r0, IPSR) - -@micropython.asm_thumb -def getBASEPRI(): - mrs(r0, BASEPRI) - -print(getBASEPRI()) -print(getIPSR()) diff --git a/tests/inlineasm 2/asmspecialregs.py.exp b/tests/inlineasm 2/asmspecialregs.py.exp deleted file mode 100644 index aa47d0d46d..0000000000 --- a/tests/inlineasm 2/asmspecialregs.py.exp +++ /dev/null @@ -1,2 +0,0 @@ -0 -0 diff --git a/tests/inlineasm 2/asmsum.py b/tests/inlineasm 2/asmsum.py deleted file mode 100644 index 07e71c7384..0000000000 --- a/tests/inlineasm 2/asmsum.py +++ /dev/null @@ -1,57 +0,0 @@ -@micropython.asm_thumb -def asm_sum_words(r0, r1): - - # r0 = len - # r1 = ptr - # r2 = sum - # r3 = dummy - mov(r2, 0) - - b(loop_entry) - - label(loop1) - ldr(r3, [r1, 0]) - add(r2, r2, r3) - - add(r1, r1, 4) - sub(r0, r0, 1) - - label(loop_entry) - cmp(r0, 0) - bgt(loop1) - - mov(r0, r2) - -@micropython.asm_thumb -def asm_sum_bytes(r0, r1): - - # r0 = len - # r1 = ptr - # r2 = sum - # r3 = dummy - mov(r2, 0) - - b(loop_entry) - - label(loop1) - ldrb(r3, [r1, 0]) - add(r2, r2, r3) - - add(r1, r1, 1) - sub(r0, r0, 1) - - label(loop_entry) - cmp(r0, 0) - bgt(loop1) - - mov(r0, r2) - -import array - -b = array.array('l', (100, 200, 300, 400)) -n = asm_sum_words(len(b), b) -print(b, n) - -b = array.array('b', (10, 20, 30, 40, 50, 60, 70, 80)) -n = asm_sum_bytes(len(b), b) -print(b, n) diff --git a/tests/inlineasm 2/asmsum.py.exp b/tests/inlineasm 2/asmsum.py.exp deleted file mode 100644 index d50a94c8db..0000000000 --- a/tests/inlineasm 2/asmsum.py.exp +++ /dev/null @@ -1,2 +0,0 @@ -array('l', [100, 200, 300, 400]) 1000 -array('b', [10, 20, 30, 40, 50, 60, 70, 80]) 360 diff --git a/tests/jni 2/README b/tests/jni 2/README deleted file mode 100644 index a0689e9244..0000000000 --- a/tests/jni 2/README +++ /dev/null @@ -1,11 +0,0 @@ -Running "jni" module tests (as well as just using this module) requires -being able to load libjvm.so, which requires path to it set via -LD_LIBRARY_PATH environment variable. This path is not set automatically -and there is no easy way to guess it, because there can be installed -different implementations of JVM, for one implementation, there can be -different versions, and single version may include different variants -of JVM. - -For example, for OpenJDK 7 on x86_64, following may work: - -LD_LIBRARY_PATH=/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server ./run-tests jni/*.py diff --git a/tests/jni 2/list.py b/tests/jni 2/list.py deleted file mode 100644 index d58181d0ba..0000000000 --- a/tests/jni 2/list.py +++ /dev/null @@ -1,15 +0,0 @@ -import jni -try: - ArrayList = jni.cls("java/util/ArrayList") -except: - print("SKIP") - raise SystemExit - -l = ArrayList() -print(l) -l.add("one") -l.add("two") - -print(l.toString()) -print(l) -print(l[0], l[1]) diff --git a/tests/jni 2/list.py.exp b/tests/jni 2/list.py.exp deleted file mode 100644 index cc34bb0a21..0000000000 --- a/tests/jni 2/list.py.exp +++ /dev/null @@ -1,4 +0,0 @@ -[] -[one, two] -[one, two] -one two diff --git a/tests/jni 2/object.py b/tests/jni 2/object.py deleted file mode 100644 index aa67615ec8..0000000000 --- a/tests/jni 2/object.py +++ /dev/null @@ -1,15 +0,0 @@ -import jni -try: - Integer = jni.cls("java/lang/Integer") -except: - print("SKIP") - raise SystemExit - -# Create object -i = Integer(42) -print(i) -# Call object method -print(i.hashCode()) -# Pass object to another method -System = jni.cls("java/lang/System") -System.out.println(i) diff --git a/tests/jni 2/object.py.exp b/tests/jni 2/object.py.exp deleted file mode 100644 index bda709ecfb..0000000000 --- a/tests/jni 2/object.py.exp +++ /dev/null @@ -1,3 +0,0 @@ -42 -42 -42 diff --git a/tests/jni 2/system_out.py b/tests/jni 2/system_out.py deleted file mode 100644 index 86c4b9e112..0000000000 --- a/tests/jni 2/system_out.py +++ /dev/null @@ -1,8 +0,0 @@ -try: - import jni - System = jni.cls("java/lang/System") -except: - print("SKIP") - raise SystemExit - -System.out.println("Hello, Java!") diff --git a/tests/jni 2/system_out.py.exp b/tests/jni 2/system_out.py.exp deleted file mode 100644 index 01dd954f90..0000000000 --- a/tests/jni 2/system_out.py.exp +++ /dev/null @@ -1 +0,0 @@ -Hello, Java! diff --git a/tests/net_hosted 2/README b/tests/net_hosted 2/README deleted file mode 100644 index 724dd61584..0000000000 --- a/tests/net_hosted 2/README +++ /dev/null @@ -1,11 +0,0 @@ -This directory contains network tests which require just "peer to peer" -network connection between test host and device under test, instead of -full Internet connection. - -Note that setup for these tests and tests themselves are WIP, and may -not yet fully correspond to the functional specification above. - -So far, these tests are not run as part of the main testsuite and need -to be run seperately (from the main test/ directory): - - ./run-tests net_hosted/*.py diff --git a/tests/net_hosted 2/accept_nonblock.py b/tests/net_hosted 2/accept_nonblock.py deleted file mode 100644 index 56f3288e28..0000000000 --- a/tests/net_hosted 2/accept_nonblock.py +++ /dev/null @@ -1,16 +0,0 @@ -# test that socket.accept() on a non-blocking socket raises EAGAIN - -try: - import usocket as socket -except: - import socket - -s = socket.socket() -s.bind(socket.getaddrinfo('127.0.0.1', 8123)[0][-1]) -s.setblocking(False) -s.listen(1) -try: - s.accept() -except OSError as er: - print(er.args[0] == 11) # 11 is EAGAIN -s.close() diff --git a/tests/net_hosted 2/accept_nonblock.py.exp b/tests/net_hosted 2/accept_nonblock.py.exp deleted file mode 100644 index 0ca95142bb..0000000000 --- a/tests/net_hosted 2/accept_nonblock.py.exp +++ /dev/null @@ -1 +0,0 @@ -True diff --git a/tests/net_hosted 2/accept_timeout.py b/tests/net_hosted 2/accept_timeout.py deleted file mode 100644 index 44b3b8c7cd..0000000000 --- a/tests/net_hosted 2/accept_timeout.py +++ /dev/null @@ -1,22 +0,0 @@ -# test that socket.accept() on a socket with timeout raises ETIMEDOUT - -try: - import usocket as socket -except: - import socket - -try: - socket.socket.settimeout -except AttributeError: - print('SKIP') - raise SystemExit - -s = socket.socket() -s.bind(socket.getaddrinfo('127.0.0.1', 8123)[0][-1]) -s.settimeout(1) -s.listen(1) -try: - s.accept() -except OSError as er: - print(er.args[0] in (110, 'timed out')) # 110 is ETIMEDOUT; CPython uses a string -s.close() diff --git a/tests/net_hosted 2/accept_timeout.py.exp b/tests/net_hosted 2/accept_timeout.py.exp deleted file mode 100644 index 0ca95142bb..0000000000 --- a/tests/net_hosted 2/accept_timeout.py.exp +++ /dev/null @@ -1 +0,0 @@ -True diff --git a/tests/net_hosted 2/connect_nonblock.py b/tests/net_hosted 2/connect_nonblock.py deleted file mode 100644 index 6479978bea..0000000000 --- a/tests/net_hosted 2/connect_nonblock.py +++ /dev/null @@ -1,20 +0,0 @@ -# test that socket.connect() on a non-blocking socket raises EINPROGRESS - -try: - import usocket as socket -except: - import socket - - -def test(peer_addr): - s = socket.socket() - s.setblocking(False) - try: - s.connect(peer_addr) - except OSError as er: - print(er.args[0] == 115) # 115 is EINPROGRESS - s.close() - - -if __name__ == "__main__": - test(socket.getaddrinfo('micropython.org', 80)[0][-1]) diff --git a/tests/net_hosted 2/connect_nonblock.py.exp b/tests/net_hosted 2/connect_nonblock.py.exp deleted file mode 100644 index 0ca95142bb..0000000000 --- a/tests/net_hosted 2/connect_nonblock.py.exp +++ /dev/null @@ -1 +0,0 @@ -True diff --git a/tests/net_hosted 2/connect_poll.py b/tests/net_hosted 2/connect_poll.py deleted file mode 100644 index ece6aa0da9..0000000000 --- a/tests/net_hosted 2/connect_poll.py +++ /dev/null @@ -1,32 +0,0 @@ -# test that socket.connect() has correct polling behaviour before, during and after - -try: - import usocket as socket, uselect as select -except: - import socket, select - - -def test(peer_addr): - s = socket.socket() - poller = select.poll() - poller.register(s) - - # test poll before connect - # note: CPython can return POLLHUP, so use the IN|OUT mask - p = poller.poll(0) - print(len(p), p[0][-1] & (select.POLLIN | select.POLLOUT)) - - s.connect(peer_addr) - - # test poll during connection - print(len(poller.poll(0))) - - # test poll after connection is established - p = poller.poll(1000) - print(len(p), p[0][-1]) - - s.close() - - -if __name__ == "__main__": - test(socket.getaddrinfo('micropython.org', 80)[0][-1]) diff --git a/tests/net_hosted 2/connect_poll.py.exp b/tests/net_hosted 2/connect_poll.py.exp deleted file mode 100644 index cdf520e090..0000000000 --- a/tests/net_hosted 2/connect_poll.py.exp +++ /dev/null @@ -1,3 +0,0 @@ -1 4 -1 -1 4 diff --git a/tests/net_hosted 2/ssl_getpeercert.py b/tests/net_hosted 2/ssl_getpeercert.py deleted file mode 100644 index e265c830d0..0000000000 --- a/tests/net_hosted 2/ssl_getpeercert.py +++ /dev/null @@ -1,21 +0,0 @@ -# test ssl.getpeercert() method - -try: - import usocket as socket - import ussl as ssl -except: - import socket - import ssl - - -def test(peer_addr): - s = socket.socket() - s.connect(peer_addr) - s = ssl.wrap_socket(s) - cert = s.getpeercert(True) - print(type(cert), len(cert) > 100) - s.close() - - -if __name__ == "__main__": - test(socket.getaddrinfo('micropython.org', 443)[0][-1]) diff --git a/tests/net_hosted 2/ssl_getpeercert.py.exp b/tests/net_hosted 2/ssl_getpeercert.py.exp deleted file mode 100644 index ff7ef5adf1..0000000000 --- a/tests/net_hosted 2/ssl_getpeercert.py.exp +++ /dev/null @@ -1 +0,0 @@ - True diff --git a/tests/net_inet 2/README b/tests/net_inet 2/README deleted file mode 100644 index 9a5614efa6..0000000000 --- a/tests/net_inet 2/README +++ /dev/null @@ -1,5 +0,0 @@ -This directory contains network tests which require Internet connection. -Note that these tests are not run as part of the main testsuite and need -to be run seperately (from the main test/ directory): - - ./run-tests net_inet/*.py diff --git a/tests/net_inet 2/test_tls_sites.py b/tests/net_inet 2/test_tls_sites.py deleted file mode 100644 index bf8071d087..0000000000 --- a/tests/net_inet 2/test_tls_sites.py +++ /dev/null @@ -1,59 +0,0 @@ -try: - import usocket as _socket -except: - import _socket -try: - import ussl as ssl -except: - import ssl - # CPython only supports server_hostname with SSLContext - ssl = ssl.SSLContext() - - -def test_one(site, opts): - ai = _socket.getaddrinfo(site, 443) - addr = ai[0][-1] - - s = _socket.socket() - - try: - s.connect(addr) - - if "sni" in opts: - s = ssl.wrap_socket(s, server_hostname=opts["host"]) - else: - s = ssl.wrap_socket(s) - - s.write(b"GET / HTTP/1.0\r\nHost: %s\r\n\r\n" % bytes(site, 'latin')) - resp = s.read(4096) -# print(resp) - - finally: - s.close() - - -SITES = [ - "google.com", - "www.google.com", - "api.telegram.org", - {"host": "api.pushbullet.com", "sni": True}, -# "w9rybpfril.execute-api.ap-southeast-2.amazonaws.com", - {"host": "w9rybpfril.execute-api.ap-southeast-2.amazonaws.com", "sni": True}, -] - - -def main(): - for site in SITES: - opts = {} - if isinstance(site, dict): - opts = site - site = opts["host"] - - try: - test_one(site, opts) - print(site, "ok") - except Exception as e: - print(site, repr(e)) - - -main() diff --git a/tests/net_inet 2/test_tls_sites.py.exp b/tests/net_inet 2/test_tls_sites.py.exp deleted file mode 100644 index 2f3c113d2f..0000000000 --- a/tests/net_inet 2/test_tls_sites.py.exp +++ /dev/null @@ -1,5 +0,0 @@ -google.com ok -www.google.com ok -api.telegram.org ok -api.pushbullet.com ok -w9rybpfril.execute-api.ap-southeast-2.amazonaws.com ok diff --git a/tests/run-bench-tests 2 b/tests/run-bench-tests 2 deleted file mode 100755 index f4a6776cbc..0000000000 --- a/tests/run-bench-tests 2 +++ /dev/null @@ -1,97 +0,0 @@ -#! /usr/bin/env python3 - -import os -import subprocess -import sys -import argparse -import re -from glob import glob -from collections import defaultdict - -# Tests require at least CPython 3.3. If your default python3 executable -# is of lower version, you can point MICROPY_CPYTHON3 environment var -# to the correct executable. -if os.name == 'nt': - CPYTHON3 = os.getenv('MICROPY_CPYTHON3', 'python3.exe') - MICROPYTHON = os.getenv('MICROPY_MICROPYTHON', '../ports/windows/micropython.exe') -else: - CPYTHON3 = os.getenv('MICROPY_CPYTHON3', 'python3') - MICROPYTHON = os.getenv('MICROPY_MICROPYTHON', '../ports/unix/micropython') - -def run_tests(pyb, test_dict): - test_count = 0 - testcase_count = 0 - - for base_test, tests in sorted(test_dict.items()): - print(base_test + ":") - for test_file in tests: - - # run MicroPython - if pyb is None: - # run on PC - try: - output_mupy = subprocess.check_output([MICROPYTHON, '-X', 'emit=bytecode', test_file[0]]) - except subprocess.CalledProcessError: - output_mupy = b'CRASH' - else: - # run on pyboard - pyb.enter_raw_repl() - try: - output_mupy = pyb.execfile(test_file).replace(b'\r\n', b'\n') - except pyboard.PyboardError: - output_mupy = b'CRASH' - - output_mupy = float(output_mupy.strip()) - test_file[1] = output_mupy - testcase_count += 1 - - test_count += 1 - baseline = None - for t in tests: - if baseline is None: - baseline = t[1] - print(" %.3fs (%+06.2f%%) %s" % (t[1], (t[1] * 100 / baseline) - 100, t[0])) - - print("{} tests performed ({} individual testcases)".format(test_count, testcase_count)) - - # all tests succeeded - return True - -def main(): - cmd_parser = argparse.ArgumentParser(description='Run tests for MicroPython.') - cmd_parser.add_argument('--pyboard', action='store_true', help='run the tests on the pyboard') - cmd_parser.add_argument('files', nargs='*', help='input test files') - args = cmd_parser.parse_args() - - # Note pyboard support is copied over from run-tests, not testes, and likely needs revamping - if args.pyboard: - import pyboard - pyb = pyboard.Pyboard('/dev/ttyACM0') - pyb.enter_raw_repl() - else: - pyb = None - - if len(args.files) == 0: - if pyb is None: - # run PC tests - test_dirs = ('bench',) - else: - # run pyboard tests - test_dirs = ('basics', 'float', 'pyb') - tests = sorted(test_file for test_files in (glob('{}/*.py'.format(dir)) for dir in test_dirs) for test_file in test_files) - else: - # tests explicitly given - tests = sorted(args.files) - - test_dict = defaultdict(lambda: []) - for t in tests: - m = re.match(r"(.+?)-(.+)\.py", t) - if not m: - continue - test_dict[m.group(1)].append([t, None]) - - if not run_tests(pyb, test_dict): - sys.exit(1) - -if __name__ == "__main__": - main() diff --git a/tests/run-tests 2 b/tests/run-tests 2 deleted file mode 100755 index e28600361b..0000000000 --- a/tests/run-tests 2 +++ /dev/null @@ -1,615 +0,0 @@ -#! /usr/bin/env python3 - -import os -import subprocess -import sys -import platform -import argparse -import re -import threading -import multiprocessing -from multiprocessing.pool import ThreadPool -from glob import glob - -# Tests require at least CPython 3.3. If your default python3 executable -# is of lower version, you can point MICROPY_CPYTHON3 environment var -# to the correct executable. -if os.name == 'nt': - CPYTHON3 = os.getenv('MICROPY_CPYTHON3', 'python3.exe') - MICROPYTHON = os.getenv('MICROPY_MICROPYTHON', '../ports/windows/micropython.exe') -else: - CPYTHON3 = os.getenv('MICROPY_CPYTHON3', 'python3') - MICROPYTHON = os.getenv('MICROPY_MICROPYTHON', '../ports/unix/micropython') - -# mpy-cross is only needed if --via-mpy command-line arg is passed -MPYCROSS = os.getenv('MICROPY_MPYCROSS', '../mpy-cross/mpy-cross') - -# Set PYTHONIOENCODING so that CPython will use utf-8 on systems which set another encoding in the locale -os.environ['PYTHONIOENCODING'] = 'utf-8' - -def rm_f(fname): - if os.path.exists(fname): - os.remove(fname) - - -# unescape wanted regex chars and escape unwanted ones -def convert_regex_escapes(line): - cs = [] - escape = False - for c in str(line, 'utf8'): - if escape: - escape = False - cs.append(c) - elif c == '\\': - escape = True - elif c in ('(', ')', '[', ']', '{', '}', '.', '*', '+', '^', '$'): - cs.append('\\' + c) - else: - cs.append(c) - # accept carriage-return(s) before final newline - if cs[-1] == '\n': - cs[-1] = '\r*\n' - return bytes(''.join(cs), 'utf8') - - -def run_micropython(pyb, args, test_file, is_special=False): - special_tests = ( - 'micropython/meminfo.py', 'basics/bytes_compare3.py', - 'basics/builtin_help.py', 'thread/thread_exc2.py', - ) - had_crash = False - if pyb is None: - # run on PC - if test_file.startswith(('cmdline/', 'feature_check/')) or test_file in special_tests: - # special handling for tests of the unix cmdline program - is_special = True - - if is_special: - # check for any cmdline options needed for this test - args = [MICROPYTHON] - with open(test_file, 'rb') as f: - line = f.readline() - if line.startswith(b'# cmdline:'): - # subprocess.check_output on Windows only accepts strings, not bytes - args += [str(c, 'utf-8') for c in line[10:].strip().split()] - - # run the test, possibly with redirected input - try: - if 'repl_' in test_file: - # Need to use a PTY to test command line editing - try: - import pty - except ImportError: - # in case pty module is not available, like on Windows - return b'SKIP\n' - import select - - def get(required=False): - rv = b'' - while True: - ready = select.select([emulator], [], [], 0.02) - if ready[0] == [emulator]: - rv += os.read(emulator, 1024) - else: - if not required or rv: - return rv - - def send_get(what): - os.write(emulator, what) - return get() - - with open(test_file, 'rb') as f: - # instead of: output_mupy = subprocess.check_output(args, stdin=f) - # openpty returns two read/write file descriptors. The first one is - # used by the program which provides the virtual - # terminal service, and the second one is used by the - # subprogram which requires a tty to work. - emulator, subterminal = pty.openpty() - p = subprocess.Popen(args, stdin=subterminal, stdout=subterminal, - stderr=subprocess.STDOUT, bufsize=0) - banner = get(True) - output_mupy = banner + b''.join(send_get(line) for line in f) - send_get(b'\x04') # exit the REPL, so coverage info is saved - p.kill() - os.close(emulator) - os.close(subterminal) - else: - output_mupy = subprocess.check_output(args + [test_file], stderr=subprocess.STDOUT) - except subprocess.CalledProcessError: - return b'CRASH' - - else: - # a standard test run on PC - - # create system command - cmdlist = [MICROPYTHON, '-X', 'emit=' + args.emit] - if args.heapsize is not None: - cmdlist.extend(['-X', 'heapsize=' + args.heapsize]) - - # if running via .mpy, first compile the .py file - if args.via_mpy: - subprocess.check_output([MPYCROSS, '-mcache-lookup-bc', '-o', 'mpytest.mpy', test_file]) - cmdlist.extend(['-m', 'mpytest']) - else: - cmdlist.append(test_file) - - # run the actual test - e = {"MICROPYPATH": os.getcwd() + ":", "LANG": "en_US.UTF-8"} - p = subprocess.Popen(cmdlist, env=e, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - output_mupy = b'' - while p.poll() is None: - output_mupy += p.stdout.read() - output_mupy += p.stdout.read() - if p.returncode != 0: - output_mupy = b'CRASH' - - # clean up if we had an intermediate .mpy file - if args.via_mpy: - rm_f('mpytest.mpy') - - else: - # run on pyboard - import pyboard - pyb.enter_raw_repl() - try: - output_mupy = pyb.execfile(test_file) - except pyboard.PyboardError: - had_crash = True - output_mupy = b'CRASH' - - # canonical form for all ports/platforms is to use \n for end-of-line - output_mupy = output_mupy.replace(b'\r\n', b'\n') - - # don't try to convert the output if we should skip this test - if had_crash or output_mupy in (b'SKIP\n', b'CRASH'): - return output_mupy - - if is_special or test_file in special_tests: - # convert parts of the output that are not stable across runs - with open(test_file + '.exp', 'rb') as f: - lines_exp = [] - for line in f.readlines(): - if line == b'########\n': - line = (line,) - else: - line = (line, re.compile(convert_regex_escapes(line))) - lines_exp.append(line) - lines_mupy = [line + b'\n' for line in output_mupy.split(b'\n')] - if output_mupy.endswith(b'\n'): - lines_mupy = lines_mupy[:-1] # remove erroneous last empty line - i_mupy = 0 - for i in range(len(lines_exp)): - if lines_exp[i][0] == b'########\n': - # 8x #'s means match 0 or more whole lines - line_exp = lines_exp[i + 1] - skip = 0 - while i_mupy + skip < len(lines_mupy) and not line_exp[1].match(lines_mupy[i_mupy + skip]): - skip += 1 - if i_mupy + skip >= len(lines_mupy): - lines_mupy[i_mupy] = b'######## FAIL\n' - break - del lines_mupy[i_mupy:i_mupy + skip] - lines_mupy.insert(i_mupy, b'########\n') - i_mupy += 1 - else: - # a regex - if lines_exp[i][1].match(lines_mupy[i_mupy]): - lines_mupy[i_mupy] = lines_exp[i][0] - else: - #print("don't match: %r %s" % (lines_exp[i][1], lines_mupy[i_mupy])) # DEBUG - pass - i_mupy += 1 - if i_mupy >= len(lines_mupy): - break - output_mupy = b''.join(lines_mupy) - - return output_mupy - - -def run_feature_check(pyb, args, base_path, test_file): - return run_micropython(pyb, args, base_path + "/feature_check/" + test_file, is_special=True) - -class ThreadSafeCounter: - def __init__(self, start=0): - self._value = start - self._lock = threading.Lock() - - def add(self, to_add): - with self._lock: self._value += to_add - - def append(self, arg): - self.add([arg]) - - @property - def value(self): - return self._value - -def run_tests(pyb, tests, args, base_path=".", num_threads=1): - test_count = ThreadSafeCounter() - testcase_count = ThreadSafeCounter() - passed_count = ThreadSafeCounter() - failed_tests = ThreadSafeCounter([]) - skipped_tests = ThreadSafeCounter([]) - - skip_tests = set() - skip_native = False - skip_int_big = False - skip_set_type = False - skip_async = False - skip_const = False - skip_revops = False - skip_endian = False - has_complex = True - has_coverage = False - - upy_float_precision = 32 - - # If we're asked to --list-tests, we can't assume that there's a - # connection to target, so we can't run feature checks usefully. - if not (args.list_tests or args.write_exp): - # Check if micropython.native is supported, and skip such tests if it's not - output = run_feature_check(pyb, args, base_path, 'native_check.py') - if output == b'CRASH': - skip_native = True - - # Check if arbitrary-precision integers are supported, and skip such tests if it's not - output = run_feature_check(pyb, args, base_path, 'int_big.py') - if output != b'1000000000000000000000000000000000000000000000\n': - skip_int_big = True - - # Check if set type (and set literals) is supported, and skip such tests if it's not - output = run_feature_check(pyb, args, base_path, 'set_check.py') - if output == b'CRASH': - skip_set_type = True - - # Check if async/await keywords are supported, and skip such tests if it's not - output = run_feature_check(pyb, args, base_path, 'async_check.py') - if output == b'CRASH': - skip_async = True - - # Check if const keyword (MicroPython extension) is supported, and skip such tests if it's not - output = run_feature_check(pyb, args, base_path, 'const.py') - if output == b'CRASH': - skip_const = True - - # Check if __rOP__ special methods are supported, and skip such tests if it's not - output = run_feature_check(pyb, args, base_path, 'reverse_ops.py') - if output == b'TypeError\n': - skip_revops = True - - # Check if emacs repl is supported, and skip such tests if it's not - t = run_feature_check(pyb, args, base_path, 'repl_emacs_check.py') - if not 'True' in str(t, 'ascii'): - skip_tests.add('cmdline/repl_emacs_keys.py') - - upy_byteorder = run_feature_check(pyb, args, base_path, 'byteorder.py') - upy_float_precision = int(run_feature_check(pyb, args, base_path, 'float.py')) - has_complex = run_feature_check(pyb, args, base_path, 'complex.py') == b'complex\n' - has_coverage = run_feature_check(pyb, args, base_path, 'coverage.py') == b'coverage\n' - cpy_byteorder = subprocess.check_output([CPYTHON3, base_path + '/feature_check/byteorder.py']) - skip_endian = (upy_byteorder != cpy_byteorder) - - # Some tests shouldn't be run under Travis CI - if os.getenv('TRAVIS') == 'true': - skip_tests.add('basics/memoryerror.py') - skip_tests.add('thread/thread_gc1.py') # has reliability issues - skip_tests.add('thread/thread_lock4.py') # has reliability issues - skip_tests.add('thread/stress_heap.py') # has reliability issues - skip_tests.add('thread/stress_recurse.py') # has reliability issues - - if upy_float_precision == 0: - skip_tests.add('extmod/ujson_dumps_float.py') - skip_tests.add('extmod/ujson_loads_float.py') - skip_tests.add('misc/rge_sm.py') - if upy_float_precision < 32: - skip_tests.add('float/float2int_intbig.py') # requires fp32, there's float2int_fp30_intbig.py instead - skip_tests.add('float/string_format.py') # requires fp32, there's string_format_fp30.py instead - skip_tests.add('float/bytes_construct.py') # requires fp32 - skip_tests.add('float/bytearray_construct.py') # requires fp32 - if upy_float_precision < 64: - skip_tests.add('float/float_divmod.py') # tested by float/float_divmod_relaxed.py instead - skip_tests.add('float/float2int_doubleprec_intbig.py') - skip_tests.add('float/float_parse_doubleprec.py') - - if not has_complex: - skip_tests.add('float/complex1.py') - skip_tests.add('float/complex1_intbig.py') - skip_tests.add('float/int_big_float.py') - skip_tests.add('float/true_value.py') - skip_tests.add('float/types.py') - - if not has_coverage: - skip_tests.add('cmdline/cmd_parsetree.py') - - # Some tests shouldn't be run on a PC - if args.target == 'unix': - # unix build does not have the GIL so can't run thread mutation tests - for t in tests: - if t.startswith('thread/mutate_'): - skip_tests.add(t) - - # Some tests shouldn't be run on pyboard - if args.target != 'unix': - skip_tests.add('basics/exception_chain.py') # warning is not printed - skip_tests.add('micropython/meminfo.py') # output is very different to PC output - skip_tests.add('extmod/machine_mem.py') # raw memory access not supported - - if args.target == 'wipy': - skip_tests.add('misc/print_exception.py') # requires error reporting full - skip_tests.update({'extmod/uctypes_%s.py' % t for t in 'bytearray le native_le ptr_le ptr_native_le sizeof sizeof_native array_assign_le array_assign_native_le'.split()}) # requires uctypes - skip_tests.add('extmod/zlibd_decompress.py') # requires zlib - skip_tests.add('extmod/uheapq1.py') # uheapq not supported by WiPy - skip_tests.add('extmod/urandom_basic.py') # requires urandom - skip_tests.add('extmod/urandom_extra.py') # requires urandom - elif args.target == 'esp8266': - skip_tests.add('misc/rge_sm.py') # too large - elif args.target == 'minimal': - skip_tests.add('basics/class_inplace_op.py') # all special methods not supported - skip_tests.add('basics/subclass_native_init.py')# native subclassing corner cases not support - skip_tests.add('misc/rge_sm.py') # too large - skip_tests.add('micropython/opt_level.py') # don't assume line numbers are stored - - # Some tests are known to fail on 64-bit machines - if pyb is None and platform.architecture()[0] == '64bit': - pass - - # Some tests use unsupported features on Windows - if os.name == 'nt': - skip_tests.add('import/import_file.py') # works but CPython prints forward slashes - - # Some tests are known to fail with native emitter - # Remove them from the below when they work - if args.emit == 'native': - skip_tests.update({'basics/%s.py' % t for t in 'gen_yield_from gen_yield_from_close gen_yield_from_ducktype gen_yield_from_exc gen_yield_from_executing gen_yield_from_iter gen_yield_from_send gen_yield_from_stopped gen_yield_from_throw gen_yield_from_throw2 gen_yield_from_throw3 generator1 generator2 generator_args generator_close generator_closure generator_exc generator_pend_throw generator_return generator_send'.split()}) # require yield - skip_tests.update({'basics/%s.py' % t for t in 'bytes_gen class_store_class globals_del string_join gen_stack_overflow'.split()}) # require yield - skip_tests.update({'basics/async_%s.py' % t for t in 'def await await2 for for2 with with2 coroutine'.split()}) # require yield - skip_tests.update({'basics/%s.py' % t for t in 'try_reraise try_reraise2'.split()}) # require raise_varargs - skip_tests.update({'basics/%s.py' % t for t in 'with_break with_continue with_return'.split()}) # require complete with support - skip_tests.add('basics/array_construct2.py') # requires generators - skip_tests.add('basics/bool1.py') # seems to randomly fail - skip_tests.add('basics/builtin_hash_gen.py') # requires yield - skip_tests.add('basics/class_bind_self.py') # requires yield - skip_tests.add('basics/del_deref.py') # requires checking for unbound local - skip_tests.add('basics/del_local.py') # requires checking for unbound local - skip_tests.add('basics/exception_chain.py') # raise from is not supported - skip_tests.add('basics/for_range.py') # requires yield_value - skip_tests.add('basics/try_finally_loops.py') # requires proper try finally code - skip_tests.add('basics/try_finally_return.py') # requires proper try finally code - skip_tests.add('basics/try_finally_return2.py') # requires proper try finally code - skip_tests.add('basics/unboundlocal.py') # requires checking for unbound local - skip_tests.add('import/gen_context.py') # requires yield_value - skip_tests.add('misc/features.py') # requires raise_varargs - skip_tests.add('misc/rge_sm.py') # requires yield - skip_tests.add('misc/print_exception.py') # because native doesn't have proper traceback info - skip_tests.add('misc/sys_exc_info.py') # sys.exc_info() is not supported for native - skip_tests.add('micropython/emg_exc.py') # because native doesn't have proper traceback info - skip_tests.add('micropython/heapalloc_traceback.py') # because native doesn't have proper traceback info - skip_tests.add('micropython/heapalloc_iter.py') # requires generators - skip_tests.add('micropython/schedule.py') # native code doesn't check pending events - skip_tests.add('stress/gc_trace.py') # requires yield - skip_tests.add('stress/recursive_gen.py') # requires yield - skip_tests.add('extmod/vfs_userfs.py') # because native doesn't properly handle globals across different modules - skip_tests.add('../extmod/ulab/tests/argminmax.py') # requires yield - - def run_one_test(test_file): - test_file = test_file.replace('\\', '/') - - if args.filters: - # Default verdict is the opposit of the first action - verdict = "include" if args.filters[0][0] == "exclude" else "exclude" - for action, pat in args.filters: - if pat.search(test_file): - verdict = action - if verdict == "exclude": - return - - test_basename = os.path.basename(test_file) - test_name = os.path.splitext(test_basename)[0] - is_native = test_name.startswith("native_") or test_name.startswith("viper_") - is_endian = test_name.endswith("_endian") - is_int_big = test_name.startswith("int_big") or test_name.endswith("_intbig") - is_set_type = test_name.startswith("set_") or test_name.startswith("frozenset") - is_async = test_name.startswith("async_") - is_const = test_name.startswith("const") - - skip_it = test_file in skip_tests - skip_it |= skip_native and is_native - skip_it |= skip_endian and is_endian - skip_it |= skip_int_big and is_int_big - skip_it |= skip_set_type and is_set_type - skip_it |= skip_async and is_async - skip_it |= skip_const and is_const - skip_it |= skip_revops and test_name.startswith("class_reverse_op") - - if args.list_tests: - if not skip_it: - print(test_file) - return - - if skip_it: - print("skip ", test_file) - skipped_tests.append(test_name) - return - - # get expected output - test_file_expected = test_file + '.exp' - if os.path.isfile(test_file_expected): - # expected output given by a file, so read that in - with open(test_file_expected, 'rb') as f: - output_expected = f.read() - else: - # run CPython to work out expected output - e = {"PYTHONPATH": os.getcwd(), - "PATH": os.environ["PATH"], - "LANG": "en_US.UTF-8"} - p = subprocess.Popen([CPYTHON3, '-B', test_file], env=e, stdout=subprocess.PIPE) - output_expected = b'' - while p.poll() is None: - output_expected += p.stdout.read() - output_expected += p.stdout.read() - if p.returncode != 0: - output_expected = b'CPYTHON3 CRASH' - elif args.write_exp: - with open(test_file_expected, 'wb') as f: - f.write(output_expected) - - # canonical form for all host platforms is to use \n for end-of-line - output_expected = output_expected.replace(b'\r\n', b'\n') - - if args.write_exp: - return - - # run MicroPython - output_mupy = run_micropython(pyb, args, test_file) - - if output_mupy == b'SKIP\n': - print("skip ", test_file) - skipped_tests.append(test_name) - return - - testcase_count.add(len(output_expected.splitlines())) - - filename_expected = test_basename + ".exp" - filename_mupy = test_basename + ".out" - - if output_expected == output_mupy: - print("pass ", test_file) - passed_count.add(1) - rm_f(filename_expected) - rm_f(filename_mupy) - else: - with open(filename_expected, "wb") as f: - f.write(output_expected) - with open(filename_mupy, "wb") as f: - f.write(output_mupy) - print("### Expected") - print(output_expected) - print("### Actual") - print(output_mupy) - print("FAIL ", test_file) - failed_tests.append(test_name) - - test_count.add(1) - - if args.list_tests: - return True - - if num_threads > 1: - pool = ThreadPool(num_threads) - pool.map(run_one_test, tests) - else: - for test in tests: - run_one_test(test) - - print("{} tests performed ({} individual testcases)".format(test_count.value, testcase_count.value)) - print("{} tests passed".format(passed_count.value)) - - if len(skipped_tests.value) > 0: - print("{} tests skipped: {}".format(len(skipped_tests.value), ' '.join(sorted(skipped_tests.value)))) - if len(failed_tests.value) > 0: - print("{} tests failed: {}".format(len(failed_tests.value), ' '.join(sorted(failed_tests.value)))) - return False - - # all tests succeeded - return True - - -class append_filter(argparse.Action): - - def __init__(self, option_strings, dest, **kwargs): - super().__init__(option_strings, dest, default=[], **kwargs) - - def __call__(self, parser, args, value, option): - if not hasattr(args, self.dest): - args.filters = [] - if option.startswith(("-e", "--e")): - option = "exclude" - else: - option = "include" - args.filters.append((option, re.compile(value))) - - -def main(): - cmd_parser = argparse.ArgumentParser( - formatter_class=argparse.RawDescriptionHelpFormatter, - description='Run and manage tests for MicroPython.', - epilog='''\ -Options -i and -e can be multiple and processed in the order given. Regex -"search" (vs "match") operation is used. An action (include/exclude) of -the last matching regex is used: - run-tests -i async - exclude all, then include tests containg "async" anywhere - run-tests -e '/big.+int' - include all, then exclude by regex - run-tests -e async -i async_foo - include all, exclude async, yet still include async_foo -''') - cmd_parser.add_argument('--target', default='unix', help='the target platform') - cmd_parser.add_argument('--device', default='/dev/ttyACM0', help='the serial device or the IP address of the pyboard') - cmd_parser.add_argument('-b', '--baudrate', default=115200, help='the baud rate of the serial device') - cmd_parser.add_argument('-u', '--user', default='micro', help='the telnet login username') - cmd_parser.add_argument('-p', '--password', default='python', help='the telnet login password') - cmd_parser.add_argument('-d', '--test-dirs', nargs='*', help='input test directories (if no files given)') - cmd_parser.add_argument('-e', '--exclude', action=append_filter, metavar='REGEX', dest='filters', help='exclude test by regex on path/name.py') - cmd_parser.add_argument('-i', '--include', action=append_filter, metavar='REGEX', dest='filters', help='include test by regex on path/name.py') - cmd_parser.add_argument('--write-exp', action='store_true', help='save .exp files to run tests w/o CPython') - cmd_parser.add_argument('--list-tests', action='store_true', help='list tests instead of running them') - cmd_parser.add_argument('--emit', default='bytecode', help='MicroPython emitter to use (bytecode or native)') - cmd_parser.add_argument('--heapsize', help='heapsize to use (use default if not specified)') - cmd_parser.add_argument('--via-mpy', action='store_true', help='compile .py files to .mpy first') - cmd_parser.add_argument('--keep-path', action='store_true', help='do not clear MICROPYPATH when running tests') - cmd_parser.add_argument('-j', '--jobs', default=1, metavar='N', type=int, help='Number of tests to run simultaneously') - cmd_parser.add_argument('--auto-jobs', action='store_const', dest='jobs', const=multiprocessing.cpu_count(), help='Set the -j values to the CPU (thread) count') - cmd_parser.add_argument('files', nargs='*', help='input test files') - args = cmd_parser.parse_args() - - EXTERNAL_TARGETS = ('pyboard', 'wipy', 'esp8266', 'esp32', 'minimal') - if args.target == 'unix' or args.list_tests: - pyb = None - elif args.target in EXTERNAL_TARGETS: - import pyboard - pyb = pyboard.Pyboard(args.device, args.baudrate, args.user, args.password) - pyb.enter_raw_repl() - else: - raise ValueError('target must be either %s or unix' % ", ".join(EXTERNAL_TARGETS)) - - if len(args.files) == 0: - if args.test_dirs is None: - if args.target == 'pyboard': - # run pyboard tests - test_dirs = ('basics', 'micropython', 'float', 'misc', 'stress', 'extmod', 'pyb', 'pybnative', 'inlineasm') - elif args.target in ('esp8266', 'esp32', 'minimal'): - test_dirs = ('basics', 'micropython', 'float', 'misc', 'extmod') - elif args.target == 'wipy': - # run WiPy tests - test_dirs = ('basics', 'micropython', 'misc', 'extmod', 'wipy') - else: - # run PC tests - test_dirs = ( - 'basics', 'micropython', 'float', 'import', 'io', 'misc', - 'stress', 'unicode', 'extmod', '../extmod/ulab/tests', 'unix', 'cmdline', - ) - else: - # run tests from these directories - test_dirs = args.test_dirs - tests = sorted(test_file for test_files in (glob('{}/*.py'.format(dir)) for dir in test_dirs) for test_file in test_files) - else: - # tests explicitly given - tests = args.files - - if not args.keep_path: - # clear search path to make sure tests use only builtin modules - os.environ['MICROPYPATH'] = '' - - # Even if we run completely different tests in a different directory, - # we need to access feature_check's from the same directory as the - # run-tests script itself. - base_path = os.path.dirname(sys.argv[0]) or "." - try: - res = run_tests(pyb, tests, args, base_path, args.jobs) - finally: - if pyb: - pyb.close() - - if not res: - sys.exit(1) - -if __name__ == "__main__": - main() diff --git a/tests/stress 2/dict_copy.py b/tests/stress 2/dict_copy.py deleted file mode 100644 index 36db9bb7e8..0000000000 --- a/tests/stress 2/dict_copy.py +++ /dev/null @@ -1,7 +0,0 @@ -# copying a large dictionary - -a = {i:2*i for i in range(1000)} -b = a.copy() -for i in range(1000): - print(i, b[i]) -print(len(b)) diff --git a/tests/stress 2/dict_create.py b/tests/stress 2/dict_create.py deleted file mode 100644 index e9db40a8e6..0000000000 --- a/tests/stress 2/dict_create.py +++ /dev/null @@ -1,8 +0,0 @@ -# create a large dictionary - -d = {} -x = 1 -while x < 1000: - d[x] = x - x += 1 -print(d[500]) diff --git a/tests/stress 2/dict_create_max.py b/tests/stress 2/dict_create_max.py deleted file mode 100644 index 3c75db20da..0000000000 --- a/tests/stress 2/dict_create_max.py +++ /dev/null @@ -1,13 +0,0 @@ -# The aim with this test is to hit the maximum resize/rehash size of a dict, -# where there are no more primes in the table of growing allocation sizes. -# This value is 54907 items. - -d = {} -try: - for i in range(54908): - d[i] = i -except MemoryError: - pass - -# Just check the dict still has the first value -print(d[0]) diff --git a/tests/stress 2/gc_trace.py b/tests/stress 2/gc_trace.py deleted file mode 100644 index 72dc7b6276..0000000000 --- a/tests/stress 2/gc_trace.py +++ /dev/null @@ -1,17 +0,0 @@ -# test that the GC can trace nested objects - -try: - import gc -except ImportError: - print("SKIP") - raise SystemExit - -# test a big shallow object pointing to many unique objects -lst = [[i] for i in range(200)] -gc.collect() -print(lst) - -# test a deep object -lst = [[[[[(i, j, k, l)] for i in range(3)] for j in range(3)] for k in range(3)] for l in range(3)] -gc.collect() -print(lst) diff --git a/tests/stress 2/list_sort.py b/tests/stress 2/list_sort.py deleted file mode 100644 index 3a7701a1e4..0000000000 --- a/tests/stress 2/list_sort.py +++ /dev/null @@ -1,6 +0,0 @@ -# test large list sorting (should not stack overflow) -l = list(range(2000)) -l.sort() -print(l[0], l[-1]) -l.sort(reverse=True) -print(l[0], l[-1]) diff --git a/tests/stress 2/recursion.py b/tests/stress 2/recursion.py deleted file mode 100644 index 227f48396a..0000000000 --- a/tests/stress 2/recursion.py +++ /dev/null @@ -1,7 +0,0 @@ -def foo(): - foo() - -try: - foo() -except RuntimeError: - print("RuntimeError") diff --git a/tests/stress 2/recursive_data.py b/tests/stress 2/recursive_data.py deleted file mode 100644 index 3b7fa50952..0000000000 --- a/tests/stress 2/recursive_data.py +++ /dev/null @@ -1,13 +0,0 @@ -# This tests that printing recursive data structure doesn't lead to segfault. -try: - import uio as io -except ImportError: - print("SKIP") - raise SystemExit - -l = [1, 2, 3, None] -l[-1] = l -try: - print(l, file=io.StringIO()) -except RuntimeError: - print("RuntimeError") diff --git a/tests/stress 2/recursive_data.py.exp b/tests/stress 2/recursive_data.py.exp deleted file mode 100644 index 8a2b9bfdda..0000000000 --- a/tests/stress 2/recursive_data.py.exp +++ /dev/null @@ -1 +0,0 @@ -RuntimeError diff --git a/tests/stress 2/recursive_gen.py b/tests/stress 2/recursive_gen.py deleted file mode 100644 index 0e0d3914ee..0000000000 --- a/tests/stress 2/recursive_gen.py +++ /dev/null @@ -1,18 +0,0 @@ -# test deeply recursive generators - -# simple "yield from" recursion -def gen(): - yield from gen() -try: - list(gen()) -except RuntimeError: - print('RuntimeError') - -# recursion via an iterator over a generator -def gen2(): - for x in gen2(): - yield x -try: - next(gen2()) -except RuntimeError: - print('RuntimeError') diff --git a/tests/stress 2/recursive_iternext.py b/tests/stress 2/recursive_iternext.py deleted file mode 100644 index edb5a843f2..0000000000 --- a/tests/stress 2/recursive_iternext.py +++ /dev/null @@ -1,57 +0,0 @@ -# This tests that recursion with iternext doesn't lead to segfault. -try: - enumerate - filter - map - max - zip -except: - print("SKIP") - raise SystemExit - -# We need to pick an N that is large enough to hit the recursion -# limit, but not too large that we run out of heap memory. -try: - # large stack/heap, eg unix - [0] * 80000 - N = 2400 -except: - try: - # medium, eg pyboard - [0] * 10000 - N = 1000 - except: - # small, eg esp8266 - N = 100 - -try: - x = (1, 2) - for i in range(N): - x = enumerate(x) - tuple(x) -except RuntimeError: - print("RuntimeError") - -try: - x = (1, 2) - for i in range(N): - x = filter(None, x) - tuple(x) -except RuntimeError: - print("RuntimeError") - -try: - x = (1, 2) - for i in range(N): - x = map(max, x, ()) - tuple(x) -except RuntimeError: - print("RuntimeError") - -try: - x = (1, 2) - for i in range(N): - x = zip(x) - tuple(x) -except RuntimeError: - print("RuntimeError") diff --git a/tests/stress 2/recursive_iternext.py.exp b/tests/stress 2/recursive_iternext.py.exp deleted file mode 100644 index 80d1488a37..0000000000 --- a/tests/stress 2/recursive_iternext.py.exp +++ /dev/null @@ -1,4 +0,0 @@ -RuntimeError -RuntimeError -RuntimeError -RuntimeError diff --git a/tests/thread 2/mutate_bytearray.py b/tests/thread 2/mutate_bytearray.py deleted file mode 100644 index 5015c3f9cf..0000000000 --- a/tests/thread 2/mutate_bytearray.py +++ /dev/null @@ -1,46 +0,0 @@ -# test concurrent mutating access to a shared bytearray object -# -# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -# -# SPDX-License-Identifier: MIT - -import _thread - -# the shared bytearray -ba = bytearray() - -# main thread function -def th(n, lo, hi): - for repeat in range(n): - for i in range(lo, hi): - l = len(ba) - ba.append(i) - assert len(ba) >= l + 1 - - l = len(ba) - ba.extend(bytearray([i])) - assert len(ba) >= l + 1 - - with lock: - global n_finished - n_finished += 1 - -lock = _thread.allocate_lock() -n_thread = 4 -n_finished = 0 -n_repeat = 4 # use 40 for more stressful test (uses more heap) - -# spawn threads -for i in range(n_thread): - _thread.start_new_thread(th, (n_repeat, i * 256 // n_thread, (i + 1) * 256 // n_thread)) - -# busy wait for threads to finish -while n_finished < n_thread: - pass - -# check bytearray has correct contents -print(len(ba)) -count = [0 for _ in range(256)] -for b in ba: - count[b] += 1 -print(count) diff --git a/tests/thread 2/mutate_dict.py b/tests/thread 2/mutate_dict.py deleted file mode 100644 index 563fce39de..0000000000 --- a/tests/thread 2/mutate_dict.py +++ /dev/null @@ -1,44 +0,0 @@ -# test concurrent mutating access to a shared dict object -# -# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -# -# SPDX-License-Identifier: MIT - -import _thread - -# the shared dict -di = {'a':'A', 'b':'B', 'c':'C', 'd':'D'} - -# main thread function -def th(n, lo, hi): - for repeat in range(n): - for i in range(lo, hi): - di[i] = repeat + i - assert di[i] == repeat + i - - del di[i] - assert i not in di - - di[i] = repeat + i - assert di[i] == repeat + i - - assert di.pop(i) == repeat + i - - with lock: - global n_finished - n_finished += 1 - -lock = _thread.allocate_lock() -n_thread = 4 -n_finished = 0 - -# spawn threads -for i in range(n_thread): - _thread.start_new_thread(th, (30, i * 300, (i + 1) * 300)) - -# busy wait for threads to finish -while n_finished < n_thread: - pass - -# check dict has correct contents -print(sorted(di.items())) diff --git a/tests/thread 2/mutate_instance.py b/tests/thread 2/mutate_instance.py deleted file mode 100644 index 2ecfbe1092..0000000000 --- a/tests/thread 2/mutate_instance.py +++ /dev/null @@ -1,45 +0,0 @@ -# test concurrent mutating access to a shared user instance -# -# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -# -# SPDX-License-Identifier: MIT - -import _thread - -# the shared user class and instance -class User: - def __init__(self): - self.a = 'A' - self.b = 'B' - self.c = 'C' -user = User() - -# main thread function -def th(n, lo, hi): - for repeat in range(n): - for i in range(lo, hi): - setattr(user, 'attr_%u' % i, repeat + i) - assert getattr(user, 'attr_%u' % i) == repeat + i - - with lock: - global n_finished - n_finished += 1 - -lock = _thread.allocate_lock() -n_repeat = 30 -n_range = 50 # 300 for stressful test (uses more heap) -n_thread = 4 -n_finished = 0 - -# spawn threads -for i in range(n_thread): - _thread.start_new_thread(th, (n_repeat, i * n_range, (i + 1) * n_range)) - -# busy wait for threads to finish -while n_finished < n_thread: - pass - -# check user instance has correct contents -print(user.a, user.b, user.c) -for i in range(n_thread * n_range): - assert getattr(user, 'attr_%u' % i) == n_repeat - 1 + i diff --git a/tests/thread 2/mutate_list.py b/tests/thread 2/mutate_list.py deleted file mode 100644 index d70e8a8a38..0000000000 --- a/tests/thread 2/mutate_list.py +++ /dev/null @@ -1,46 +0,0 @@ -# test concurrent mutating access to a shared list object -# -# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -# -# SPDX-License-Identifier: MIT - -import _thread - -# the shared list -li = list() - -# main thread function -def th(n, lo, hi): - for repeat in range(n): - for i in range(lo, hi): - li.append(i) - assert li.count(i) == repeat + 1 - - li.extend([i, i]) - assert li.count(i) == repeat + 3 - - li.remove(i) - assert li.count(i) == repeat + 2 - - li.remove(i) - assert li.count(i) == repeat + 1 - - with lock: - global n_finished - n_finished += 1 - -lock = _thread.allocate_lock() -n_thread = 4 -n_finished = 0 - -# spawn threads -for i in range(n_thread): - _thread.start_new_thread(th, (4, i * 60, (i + 1) * 60)) - -# busy wait for threads to finish -while n_finished < n_thread: - pass - -# check list has correct contents -li.sort() -print(li) diff --git a/tests/thread 2/mutate_set.py b/tests/thread 2/mutate_set.py deleted file mode 100644 index c4529f3562..0000000000 --- a/tests/thread 2/mutate_set.py +++ /dev/null @@ -1,39 +0,0 @@ -# test concurrent mutating access to a shared set object -# -# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -# -# SPDX-License-Identifier: MIT - -import _thread - -# the shared set -se = set([-1, -2, -3, -4]) - -# main thread function -def th(n, lo, hi): - for repeat in range(n): - for i in range(lo, hi): - se.add(i) - assert i in se - - se.remove(i) - assert i not in se - - with lock: - global n_finished - n_finished += 1 - -lock = _thread.allocate_lock() -n_thread = 4 -n_finished = 0 - -# spawn threads -for i in range(n_thread): - _thread.start_new_thread(th, (50, i * 500, (i + 1) * 500)) - -# busy wait for threads to finish -while n_finished < n_thread: - pass - -# check set has correct contents -print(sorted(se)) diff --git a/tests/thread 2/stress_aes.py b/tests/thread 2/stress_aes.py deleted file mode 100644 index ebf7af371b..0000000000 --- a/tests/thread 2/stress_aes.py +++ /dev/null @@ -1,257 +0,0 @@ -# Stress test for threads using AES encryption routines. -# -# AES was chosen because it is integer based and inplace so doesn't use the -# heap. It is therefore a good test of raw performance and correctness of the -# VM/runtime. It can be used to measure threading performance (concurrency is -# in principle possible) and correctness (it's non trivial for the encryption/ -# decryption to give the correct answer). -# -# The AES code comes first (code originates from a C version authored by D.P.George) -# and then the test harness at the bottom. It can be tuned to be more/less -# aggressive by changing the amount of data to encrypt, the number of loops and -# the number of threads. -# -# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -# -# SPDX-License-Identifier: MIT - -################################################################## -# discrete arithmetic routines, mostly from a precomputed table - -# non-linear, invertible, substitution box -aes_s_box_table = bytes(( - 0x63,0x7c,0x77,0x7b,0xf2,0x6b,0x6f,0xc5,0x30,0x01,0x67,0x2b,0xfe,0xd7,0xab,0x76, - 0xca,0x82,0xc9,0x7d,0xfa,0x59,0x47,0xf0,0xad,0xd4,0xa2,0xaf,0x9c,0xa4,0x72,0xc0, - 0xb7,0xfd,0x93,0x26,0x36,0x3f,0xf7,0xcc,0x34,0xa5,0xe5,0xf1,0x71,0xd8,0x31,0x15, - 0x04,0xc7,0x23,0xc3,0x18,0x96,0x05,0x9a,0x07,0x12,0x80,0xe2,0xeb,0x27,0xb2,0x75, - 0x09,0x83,0x2c,0x1a,0x1b,0x6e,0x5a,0xa0,0x52,0x3b,0xd6,0xb3,0x29,0xe3,0x2f,0x84, - 0x53,0xd1,0x00,0xed,0x20,0xfc,0xb1,0x5b,0x6a,0xcb,0xbe,0x39,0x4a,0x4c,0x58,0xcf, - 0xd0,0xef,0xaa,0xfb,0x43,0x4d,0x33,0x85,0x45,0xf9,0x02,0x7f,0x50,0x3c,0x9f,0xa8, - 0x51,0xa3,0x40,0x8f,0x92,0x9d,0x38,0xf5,0xbc,0xb6,0xda,0x21,0x10,0xff,0xf3,0xd2, - 0xcd,0x0c,0x13,0xec,0x5f,0x97,0x44,0x17,0xc4,0xa7,0x7e,0x3d,0x64,0x5d,0x19,0x73, - 0x60,0x81,0x4f,0xdc,0x22,0x2a,0x90,0x88,0x46,0xee,0xb8,0x14,0xde,0x5e,0x0b,0xdb, - 0xe0,0x32,0x3a,0x0a,0x49,0x06,0x24,0x5c,0xc2,0xd3,0xac,0x62,0x91,0x95,0xe4,0x79, - 0xe7,0xc8,0x37,0x6d,0x8d,0xd5,0x4e,0xa9,0x6c,0x56,0xf4,0xea,0x65,0x7a,0xae,0x08, - 0xba,0x78,0x25,0x2e,0x1c,0xa6,0xb4,0xc6,0xe8,0xdd,0x74,0x1f,0x4b,0xbd,0x8b,0x8a, - 0x70,0x3e,0xb5,0x66,0x48,0x03,0xf6,0x0e,0x61,0x35,0x57,0xb9,0x86,0xc1,0x1d,0x9e, - 0xe1,0xf8,0x98,0x11,0x69,0xd9,0x8e,0x94,0x9b,0x1e,0x87,0xe9,0xce,0x55,0x28,0xdf, - 0x8c,0xa1,0x89,0x0d,0xbf,0xe6,0x42,0x68,0x41,0x99,0x2d,0x0f,0xb0,0x54,0xbb,0x16, -)) - -# multiplication of polynomials modulo x^8 + x^4 + x^3 + x + 1 = 0x11b -def aes_gf8_mul_2(x): - if x & 0x80: - return (x << 1) ^ 0x11b - else: - return x << 1 - -def aes_gf8_mul_3(x): - return x ^ aes_gf8_mul_2(x) - -# non-linear, invertible, substitution box -def aes_s_box(a): - return aes_s_box_table[a & 0xff] - -# return 0x02^(a-1) in GF(2^8) -def aes_r_con(a): - ans = 1 - while a > 1: - ans <<= 1; - if ans & 0x100: - ans ^= 0x11b - a -= 1 - return ans - -################################################################## -# basic AES algorithm; see FIPS-197 -# -# Think of it as a pseudo random number generator, with each -# symbol in the sequence being a 16 byte block (the state). The -# key is a parameter of the algorithm and tells which particular -# sequence of random symbols you want. The initial vector, IV, -# sets the start of the sequence. The idea of a strong cipher -# is that it's very difficult to guess the key even if you know -# a large part of the sequence. The basic AES algorithm simply -# provides such a sequence. En/de-cryption is implemented here -# using OCB, where the sequence is xored against the plaintext. -# Care must be taken to (almost) always choose a different IV. - -# all inputs must be size 16 -def aes_add_round_key(state, w): - for i in range(16): - state[i] ^= w[i] - -# combined sub_bytes, shift_rows, mix_columns, add_round_key -# all inputs must be size 16 -def aes_sb_sr_mc_ark(state, w, w_idx, temp): - temp_idx = 0 - for i in range(4): - x0 = aes_s_box_table[state[i * 4]] - x1 = aes_s_box_table[state[1 + ((i + 1) & 3) * 4]] - x2 = aes_s_box_table[state[2 + ((i + 2) & 3) * 4]] - x3 = aes_s_box_table[state[3 + ((i + 3) & 3) * 4]] - temp[temp_idx] = aes_gf8_mul_2(x0) ^ aes_gf8_mul_3(x1) ^ x2 ^ x3 ^ w[w_idx] - temp[temp_idx + 1] = x0 ^ aes_gf8_mul_2(x1) ^ aes_gf8_mul_3(x2) ^ x3 ^ w[w_idx + 1] - temp[temp_idx + 2] = x0 ^ x1 ^ aes_gf8_mul_2(x2) ^ aes_gf8_mul_3(x3) ^ w[w_idx + 2] - temp[temp_idx + 3] = aes_gf8_mul_3(x0) ^ x1 ^ x2 ^ aes_gf8_mul_2(x3) ^ w[w_idx + 3] - w_idx += 4 - temp_idx += 4 - for i in range(16): - state[i] = temp[i] - -# combined sub_bytes, shift_rows, add_round_key -# all inputs must be size 16 -def aes_sb_sr_ark(state, w, w_idx, temp): - temp_idx = 0 - for i in range(4): - x0 = aes_s_box_table[state[i * 4]] - x1 = aes_s_box_table[state[1 + ((i + 1) & 3) * 4]] - x2 = aes_s_box_table[state[2 + ((i + 2) & 3) * 4]] - x3 = aes_s_box_table[state[3 + ((i + 3) & 3) * 4]] - temp[temp_idx] = x0 ^ w[w_idx] - temp[temp_idx + 1] = x1 ^ w[w_idx + 1] - temp[temp_idx + 2] = x2 ^ w[w_idx + 2] - temp[temp_idx + 3] = x3 ^ w[w_idx + 3] - w_idx += 4 - temp_idx += 4 - for i in range(16): - state[i] = temp[i] - -# take state as input and change it to the next state in the sequence -# state and temp have size 16, w has size 16 * (Nr + 1), Nr >= 1 -def aes_state(state, w, temp, nr): - aes_add_round_key(state, w) - w_idx = 16 - for i in range(nr - 1): - aes_sb_sr_mc_ark(state, w, w_idx, temp) - w_idx += 16 - aes_sb_sr_ark(state, w, w_idx, temp) - -# expand 'key' to 'w' for use with aes_state -# key has size 4 * Nk, w has size 16 * (Nr + 1), temp has size 16 -def aes_key_expansion(key, w, temp, nk, nr): - for i in range(4 * nk): - w[i] = key[i] - w_idx = 4 * nk - 4 - for i in range(nk, 4 * (nr + 1)): - t = temp - t_idx = 0 - if i % nk == 0: - t[0] = aes_s_box(w[w_idx + 1]) ^ aes_r_con(i // nk) - for j in range(1, 4): - t[j] = aes_s_box(w[w_idx + (j + 1) % 4]) - elif nk > 6 and i % nk == 4: - for j in range(0, 4): - t[j] = aes_s_box(w[w_idx + j]) - else: - t = w - t_idx = w_idx - w_idx += 4 - for j in range(4): - w[w_idx + j] = w[w_idx + j - 4 * nk] ^ t[t_idx + j] - -################################################################## -# simple use of AES algorithm, using output feedback (OFB) mode - -class AES: - def __init__(self, keysize): - if keysize == 128: - self.nk = 4 - self.nr = 10 - elif keysize == 192: - self.nk = 6 - self.nr = 12 - else: - assert keysize == 256 - self.nk = 8 - self.nr = 14 - - self.state = bytearray(16) - self.w = bytearray(16 * (self.nr + 1)) - self.temp = bytearray(16) - self.state_pos = 16 - - def set_key(self, key): - aes_key_expansion(key, self.w, self.temp, self.nk, self.nr) - self.state_pos = 16 - - def set_iv(self, iv): - for i in range(16): - self.state[i] = iv[i] - self.state_pos = 16; - - def get_some_state(self, n_needed): - if self.state_pos >= 16: - aes_state(self.state, self.w, self.temp, self.nr) - self.state_pos = 0 - n = 16 - self.state_pos - if n > n_needed: - n = n_needed - return n - - def apply_to(self, data): - idx = 0 - n = len(data) - while n > 0: - ln = self.get_some_state(n) - n -= ln - for i in range(ln): - data[idx + i] ^= self.state[self.state_pos + i] - idx += ln - self.state_pos += n - -################################################################## -# test code - -try: - import utime as time -except ImportError: - import time -import _thread - -class LockedCounter: - def __init__(self): - self.lock = _thread.allocate_lock() - self.value = 0 - - def add(self, val): - self.lock.acquire() - self.value += val - self.lock.release() - -count = LockedCounter() - -def thread_entry(): - global count - - aes = AES(256) - key = bytearray(256 // 8) - iv = bytearray(16) - data = bytearray(128) - # from now on we don't use the heap - - for loop in range(5): - # encrypt - aes.set_key(key) - aes.set_iv(iv) - for i in range(8): - aes.apply_to(data) - - # decrypt - aes.set_key(key) - aes.set_iv(iv) - for i in range(8): - aes.apply_to(data) - - # verify - for i in range(len(data)): - assert data[i] == 0 - - count.add(1) - -if __name__ == '__main__': - n_thread = 20 - for i in range(n_thread): - _thread.start_new_thread(thread_entry, ()) - while count.value < n_thread: - time.sleep(1) diff --git a/tests/thread 2/stress_create.py b/tests/thread 2/stress_create.py deleted file mode 100644 index 2399746cca..0000000000 --- a/tests/thread 2/stress_create.py +++ /dev/null @@ -1,22 +0,0 @@ -# stress test for creating many threads - -try: - import utime as time -except ImportError: - import time -import _thread - -def thread_entry(n): - pass - -thread_num = 0 -while thread_num < 500: - try: - _thread.start_new_thread(thread_entry, (thread_num,)) - thread_num += 1 - except MemoryError: - pass - -# wait for the last threads to terminate -time.sleep(1) -print('done') diff --git a/tests/thread 2/stress_heap.py b/tests/thread 2/stress_heap.py deleted file mode 100644 index 206cf1a860..0000000000 --- a/tests/thread 2/stress_heap.py +++ /dev/null @@ -1,48 +0,0 @@ -# stress test for the heap by allocating lots of objects within threads -# allocates about 5mb on the heap -# -# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -# -# SPDX-License-Identifier: MIT - -try: - import utime as time -except ImportError: - import time -import _thread - -def last(l): - return l[-1] - -def thread_entry(n): - # allocate a bytearray and fill it - data = bytearray(i for i in range(256)) - - # run a loop which allocates a small list and uses it each iteration - lst = 8 * [0] - sum = 0 - for i in range(n): - sum += last(lst) - lst = [0, 0, 0, 0, 0, 0, 0, i + 1] - - # check that the bytearray still has the right data - for i, b in enumerate(data): - assert i == b - - # print the result of the loop and indicate we are finished - with lock: - print(sum, lst[-1]) - global n_finished - n_finished += 1 - -lock = _thread.allocate_lock() -n_thread = 10 -n_finished = 0 - -# spawn threads -for i in range(n_thread): - _thread.start_new_thread(thread_entry, (10000,)) - -# wait for threads to finish -while n_finished < n_thread: - time.sleep(1) diff --git a/tests/thread 2/stress_recurse.py b/tests/thread 2/stress_recurse.py deleted file mode 100644 index 8edee246ad..0000000000 --- a/tests/thread 2/stress_recurse.py +++ /dev/null @@ -1,27 +0,0 @@ -# test hitting the function recursion limit within a thread -# -# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -# -# SPDX-License-Identifier: MIT - -import _thread - -def foo(): - foo() - -def thread_entry(): - try: - foo() - except RuntimeError: - print('RuntimeError') - global finished - finished = True - -finished = False - -_thread.start_new_thread(thread_entry, ()) - -# busy wait for thread to finish -while not finished: - pass -print('done') diff --git a/tests/thread 2/thread_exc1.py b/tests/thread 2/thread_exc1.py deleted file mode 100644 index e00a16bd26..0000000000 --- a/tests/thread 2/thread_exc1.py +++ /dev/null @@ -1,32 +0,0 @@ -# test raising and catching an exception within a thread -# -# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -# -# SPDX-License-Identifier: MIT - -import _thread - -def foo(): - raise ValueError - -def thread_entry(): - try: - foo() - except ValueError: - pass - with lock: - global n_finished - n_finished += 1 - -lock = _thread.allocate_lock() -n_thread = 4 -n_finished = 0 - -# spawn threads -for i in range(n_thread): - _thread.start_new_thread(thread_entry, ()) - -# busy wait for threads to finish -while n_finished < n_thread: - pass -print('done') diff --git a/tests/thread 2/thread_exc2.py b/tests/thread 2/thread_exc2.py deleted file mode 100644 index 35cb324412..0000000000 --- a/tests/thread 2/thread_exc2.py +++ /dev/null @@ -1,10 +0,0 @@ -# test raising exception within thread which is not caught -import utime -import _thread - -def thread_entry(): - raise ValueError - -_thread.start_new_thread(thread_entry, ()) -utime.sleep(1) -print('done') diff --git a/tests/thread 2/thread_exc2.py.exp b/tests/thread 2/thread_exc2.py.exp deleted file mode 100644 index cc7a20aa26..0000000000 --- a/tests/thread 2/thread_exc2.py.exp +++ /dev/null @@ -1,5 +0,0 @@ -Unhandled exception in thread started by -Traceback (most recent call last): - File \.\+, line 6, in thread_entry -ValueError: -done diff --git a/tests/thread 2/thread_exit1.py b/tests/thread 2/thread_exit1.py deleted file mode 100644 index ad7b01d89b..0000000000 --- a/tests/thread 2/thread_exit1.py +++ /dev/null @@ -1,21 +0,0 @@ -# test _thread.exit() function -# -# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -# -# SPDX-License-Identifier: MIT - -try: - import utime as time -except ImportError: - import time -import _thread - -def thread_entry(): - _thread.exit() - -_thread.start_new_thread(thread_entry, ()) -_thread.start_new_thread(thread_entry, ()) - -# wait for threads to finish -time.sleep(1) -print('done') diff --git a/tests/thread 2/thread_exit2.py b/tests/thread 2/thread_exit2.py deleted file mode 100644 index 6bff8a1736..0000000000 --- a/tests/thread 2/thread_exit2.py +++ /dev/null @@ -1,21 +0,0 @@ -# test raising SystemExit to finish a thread -# -# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -# -# SPDX-License-Identifier: MIT - -try: - import utime as time -except ImportError: - import time -import _thread - -def thread_entry(): - raise SystemExit - -_thread.start_new_thread(thread_entry, ()) -_thread.start_new_thread(thread_entry, ()) - -# wait for threads to finish -time.sleep(1) -print('done') diff --git a/tests/thread 2/thread_gc1.py b/tests/thread 2/thread_gc1.py deleted file mode 100644 index 2ea1891615..0000000000 --- a/tests/thread 2/thread_gc1.py +++ /dev/null @@ -1,36 +0,0 @@ -# test that we can run the garbage collector within threads -# -# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -# -# SPDX-License-Identifier: MIT - -import gc -import _thread - -def thread_entry(n): - # allocate a bytearray and fill it - data = bytearray(i for i in range(256)) - - # do some work and call gc.collect() a few times - for i in range(n): - for i in range(len(data)): - data[i] = data[i] - gc.collect() - - # print whether the data remains intact and indicate we are finished - with lock: - print(list(data) == list(range(256))) - global n_finished - n_finished += 1 - -lock = _thread.allocate_lock() -n_thread = 4 -n_finished = 0 - -# spawn threads -for i in range(n_thread): - _thread.start_new_thread(thread_entry, (10,)) - -# busy wait for threads to finish -while n_finished < n_thread: - pass diff --git a/tests/thread 2/thread_ident1.py b/tests/thread 2/thread_ident1.py deleted file mode 100644 index 9a6f89ff5f..0000000000 --- a/tests/thread 2/thread_ident1.py +++ /dev/null @@ -1,23 +0,0 @@ -# test _thread.get_ident() function -# -# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -# -# SPDX-License-Identifier: MIT - -import _thread - -def thread_entry(): - tid = _thread.get_ident() - print('thread', type(tid) == int, tid != 0, tid != tid_main) - global finished - finished = True - -tid_main = _thread.get_ident() -print('main', type(tid_main) == int, tid_main != 0) - -finished = False -_thread.start_new_thread(thread_entry, ()) - -while not finished: - pass -print('done') diff --git a/tests/thread 2/thread_lock1.py b/tests/thread 2/thread_lock1.py deleted file mode 100644 index c2d7c9d1ed..0000000000 --- a/tests/thread 2/thread_lock1.py +++ /dev/null @@ -1,48 +0,0 @@ -# test _thread lock object using a single thread -# -# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -# -# SPDX-License-Identifier: MIT - -import _thread - -# create lock -lock = _thread.allocate_lock() - -print(type(lock) == _thread.LockType) - -# should be unlocked -print(lock.locked()) - -# basic acquire and release -print(lock.acquire()) -print(lock.locked()) -lock.release() -print(lock.locked()) - -# try acquire twice (second should fail) -print(lock.acquire()) -print(lock.locked()) -print(lock.acquire(0)) -print(lock.locked()) -lock.release() -print(lock.locked()) - -# test with capabilities of lock -with lock: - print(lock.locked()) - -# test that lock is unlocked if an error is rasied -try: - with lock: - print(lock.locked()) - raise KeyError -except KeyError: - print('KeyError') - print(lock.locked()) - -# test that we can't release an unlocked lock -try: - lock.release() -except RuntimeError: - print('RuntimeError') diff --git a/tests/thread 2/thread_lock2.py b/tests/thread 2/thread_lock2.py deleted file mode 100644 index 4ef912dff5..0000000000 --- a/tests/thread 2/thread_lock2.py +++ /dev/null @@ -1,26 +0,0 @@ -# test _thread lock objects with multiple threads -# -# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -# -# SPDX-License-Identifier: MIT - -try: - import utime as time -except ImportError: - import time -import _thread - -lock = _thread.allocate_lock() - -def thread_entry(): - lock.acquire() - print('have it') - lock.release() - -# spawn the threads -for i in range(4): - _thread.start_new_thread(thread_entry, ()) - -# wait for threads to finish -time.sleep(1) -print('done') diff --git a/tests/thread 2/thread_lock3.py b/tests/thread 2/thread_lock3.py deleted file mode 100644 index 35808d99cb..0000000000 --- a/tests/thread 2/thread_lock3.py +++ /dev/null @@ -1,29 +0,0 @@ -# test thread coordination using a lock object -# -# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -# -# SPDX-License-Identifier: MIT - -import _thread - -lock = _thread.allocate_lock() -n_thread = 10 -n_finished = 0 - -def thread_entry(idx): - global n_finished - while True: - with lock: - if n_finished == idx: - break - print('my turn:', idx) - with lock: - n_finished += 1 - -# spawn threads -for i in range(n_thread): - _thread.start_new_thread(thread_entry, (i,)) - -# busy wait for threads to finish -while n_finished < n_thread: - pass diff --git a/tests/thread 2/thread_lock4.py b/tests/thread 2/thread_lock4.py deleted file mode 100644 index 440f3e90c6..0000000000 --- a/tests/thread 2/thread_lock4.py +++ /dev/null @@ -1,53 +0,0 @@ -# test using lock to coordinate access to global mutable objects -# -# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -# -# SPDX-License-Identifier: MIT - -try: - import utime as time -except ImportError: - import time -import _thread - -def fac(n): - x = 1 - for i in range(1, n + 1): - x *= i - return x - -def thread_entry(): - while True: - with jobs_lock: - try: - f, arg = jobs.pop(0) - except IndexError: - return - ans = f(arg) - with output_lock: - output.append((arg, ans)) - -# create a list of jobs -jobs = [(fac, i) for i in range(20, 80)] -jobs_lock = _thread.allocate_lock() -n_jobs = len(jobs) - -# create a list to store the results -output = [] -output_lock = _thread.allocate_lock() - -# spawn threads to do the jobs -for i in range(4): - _thread.start_new_thread(thread_entry, ()) - -# wait for the jobs to complete -while True: - with jobs_lock: - if len(output) == n_jobs: - break - time.sleep(1) - -# sort and print the results -output.sort(key=lambda x: x[0]) -for arg, ans in output: - print(arg, ans) diff --git a/tests/thread 2/thread_qstr1.py b/tests/thread 2/thread_qstr1.py deleted file mode 100644 index dccfb7f517..0000000000 --- a/tests/thread 2/thread_qstr1.py +++ /dev/null @@ -1,41 +0,0 @@ -# test concurrent interning of strings -# -# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -# -# SPDX-License-Identifier: MIT - -try: - import utime as time -except ImportError: - import time -import _thread - -# function to check the interned string -def check(s, val): - assert type(s) == str - assert int(s) == val - -# main thread function -def th(base, n): - for i in range(n): - # this will intern the string and check it - exec("check('%u', %u)" % (base + i, base + i)) - - with lock: - global n_finished - n_finished += 1 - -lock = _thread.allocate_lock() -n_thread = 4 -n_finished = 0 -n_qstr_per_thread = 100 # make 1000 for a more stressful test (uses more heap) - -# spawn threads -for i in range(n_thread): - _thread.start_new_thread(th, (i * n_qstr_per_thread, n_qstr_per_thread)) - -# wait for threads to finish -while n_finished < n_thread: - time.sleep(1) - -print('pass') diff --git a/tests/thread 2/thread_shared1.py b/tests/thread 2/thread_shared1.py deleted file mode 100644 index de339ad7f8..0000000000 --- a/tests/thread 2/thread_shared1.py +++ /dev/null @@ -1,33 +0,0 @@ -# test capability for threads to access a shared immutable data structure -# -# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -# -# SPDX-License-Identifier: MIT - -import _thread - -def foo(i): - pass - -def thread_entry(n, tup): - for i in tup: - foo(i) - with lock: - global n_finished - n_finished += 1 - -lock = _thread.allocate_lock() -n_thread = 2 -n_finished = 0 - -# the shared data structure -tup = (1, 2, 3, 4) - -# spawn threads -for i in range(n_thread): - _thread.start_new_thread(thread_entry, (100, tup)) - -# busy wait for threads to finish -while n_finished < n_thread: - pass -print(tup) diff --git a/tests/thread 2/thread_shared2.py b/tests/thread 2/thread_shared2.py deleted file mode 100644 index 2c749e6883..0000000000 --- a/tests/thread 2/thread_shared2.py +++ /dev/null @@ -1,34 +0,0 @@ -# test capability for threads to access a shared mutable data structure -# (without contention because they access different parts of the structure) -# -# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -# -# SPDX-License-Identifier: MIT - -import _thread - -def foo(lst, i): - lst[i] += 1 - -def thread_entry(n, lst, idx): - for i in range(n): - foo(lst, idx) - with lock: - global n_finished - n_finished += 1 - -lock = _thread.allocate_lock() -n_thread = 2 -n_finished = 0 - -# the shared data structure -lst = [0, 0] - -# spawn threads -for i in range(n_thread): - _thread.start_new_thread(thread_entry, ((i + 1) * 10, lst, i)) - -# busy wait for threads to finish -while n_finished < n_thread: - pass -print(lst) diff --git a/tests/thread 2/thread_sleep1.py b/tests/thread 2/thread_sleep1.py deleted file mode 100644 index d5aa99f977..0000000000 --- a/tests/thread 2/thread_sleep1.py +++ /dev/null @@ -1,33 +0,0 @@ -# test threads sleeping -# -# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -# -# SPDX-License-Identifier: MIT - -try: - import utime - sleep_ms = utime.sleep_ms -except ImportError: - import time - sleep_ms = lambda t: time.sleep(t / 1000) - -import _thread - -lock = _thread.allocate_lock() -n_thread = 4 -n_finished = 0 - -def thread_entry(t): - global n_finished - sleep_ms(t) - sleep_ms(2 * t) - with lock: - n_finished += 1 - -for i in range(n_thread): - _thread.start_new_thread(thread_entry, (10 * i,)) - -# wait for threads to finish -while n_finished < n_thread: - sleep_ms(100) -print('done', n_thread) diff --git a/tests/thread 2/thread_stacksize1.py b/tests/thread 2/thread_stacksize1.py deleted file mode 100644 index e7189fafbc..0000000000 --- a/tests/thread 2/thread_stacksize1.py +++ /dev/null @@ -1,49 +0,0 @@ -# test setting the thread stack size -# -# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -# -# SPDX-License-Identifier: MIT - -import sys -import _thread - -# different implementations have different minimum sizes -if sys.implementation.name == 'micropython': - sz = 2 * 1024 -else: - sz = 32 * 1024 - -def foo(): - pass - -def thread_entry(): - foo() - with lock: - global n_finished - n_finished += 1 - -# reset stack size to default -_thread.stack_size() - -# test set/get of stack size -print(_thread.stack_size()) -print(_thread.stack_size(sz)) -print(_thread.stack_size() == sz) -print(_thread.stack_size()) - -lock = _thread.allocate_lock() -n_thread = 2 -n_finished = 0 - -# set stack size and spawn a few threads -_thread.stack_size(sz) -for i in range(n_thread): - _thread.start_new_thread(thread_entry, ()) - -# reset stack size to default (for subsequent scripts on baremetal) -_thread.stack_size() - -# busy wait for threads to finish -while n_finished < n_thread: - pass -print('done') diff --git a/tests/thread 2/thread_start1.py b/tests/thread 2/thread_start1.py deleted file mode 100644 index 94df6dc625..0000000000 --- a/tests/thread 2/thread_start1.py +++ /dev/null @@ -1,25 +0,0 @@ -# test basic capability to start a new thread -# -# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -# -# SPDX-License-Identifier: MIT - -try: - import utime as time -except ImportError: - import time -import _thread - -def foo(): - pass - -def thread_entry(n): - for i in range(n): - foo() - -_thread.start_new_thread(thread_entry, (10,)) -_thread.start_new_thread(thread_entry, (20,)) - -# wait for threads to finish -time.sleep(1) -print('done') diff --git a/tests/thread 2/thread_start2.py b/tests/thread 2/thread_start2.py deleted file mode 100644 index 9412bb6183..0000000000 --- a/tests/thread 2/thread_start2.py +++ /dev/null @@ -1,28 +0,0 @@ -# test capability to start a thread with keyword args -# -# SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd -# -# SPDX-License-Identifier: MIT - -try: - import utime as time -except ImportError: - import time -import _thread - -def thread_entry(a0, a1, a2, a3): - print('thread', a0, a1, a2, a3) - -# spawn thread using kw args -_thread.start_new_thread(thread_entry, (10, 20), {'a2': 0, 'a3': 1}) - -# wait for thread to finish -time.sleep(1) - -# incorrect argument where dictionary is needed for keyword args -try: - _thread.start_new_thread(thread_entry, (), ()) -except TypeError: - print('TypeError') - -print('done') diff --git a/tests/unix 2/extra_coverage.py b/tests/unix 2/extra_coverage.py deleted file mode 100644 index 13721f1f47..0000000000 --- a/tests/unix 2/extra_coverage.py +++ /dev/null @@ -1,74 +0,0 @@ -try: - extra_coverage -except NameError: - print("SKIP") - raise SystemExit - -import uerrno -import uio - -data = extra_coverage() - -# test hashing of str/bytes that have an invalid hash -print(data[0], data[1]) -print(hash(data[0])) -print(hash(data[1])) -print(hash(bytes(data[0], 'utf8'))) -print(hash(str(data[1], 'utf8'))) - -# test streams -stream = data[2] # has set_error and set_buf. Write always returns error -stream.set_error(uerrno.EAGAIN) # non-blocking error -print(stream.read()) # read all encounters non-blocking error -print(stream.read(1)) # read 1 byte encounters non-blocking error -print(stream.readline()) # readline encounters non-blocking error -print(stream.readinto(bytearray(10))) # readinto encounters non-blocking error -print(stream.write(b'1')) # write encounters non-blocking error -print(stream.write1(b'1')) # write1 encounters non-blocking error -stream.set_buf(b'123') -print(stream.read(4)) # read encounters non-blocking error after successful reads -stream.set_buf(b'123') -print(stream.read1(4)) # read1 encounters non-blocking error after successful reads -stream.set_buf(b'123') -print(stream.readline(4)) # readline encounters non-blocking error after successful reads -try: - print(stream.ioctl(0, 0)) # ioctl encounters non-blocking error; raises OSError -except OSError: - print('OSError') -stream.set_error(0) -print(stream.ioctl(0, bytearray(10))) # successful ioctl call - -stream2 = data[3] # is textio -print(stream2.read(1)) # read 1 byte encounters non-blocking error with textio stream - -# test BufferedWriter with stream errors -stream.set_error(uerrno.EAGAIN) -buf = uio.BufferedWriter(stream, 8) -print(buf.write(bytearray(16))) - -# test basic import of frozen scripts -import frzstr1 -import frzmpy1 - -# test import of frozen packages with __init__.py -import frzstr_pkg1 -print(frzstr_pkg1.x) -import frzmpy_pkg1 -print(frzmpy_pkg1.x) - -# test import of frozen packages without __init__.py -from frzstr_pkg2.mod import Foo -print(Foo.x) -from frzmpy_pkg2.mod import Foo -print(Foo.x) - -# test raising exception in frozen script -try: - import frzmpy2 -except ZeroDivisionError: - print('ZeroDivisionError') - -# test loading a resource from a frozen string -import uio -buf = uio.resource_stream('frzstr_pkg2', 'mod.py') -print(buf.read(21)) diff --git a/tests/unix 2/extra_coverage.py.exp b/tests/unix 2/extra_coverage.py.exp deleted file mode 100644 index 06b5d37903..0000000000 --- a/tests/unix 2/extra_coverage.py.exp +++ /dev/null @@ -1,106 +0,0 @@ -# mp_printf --123 +123 123 --0123 -123 -123 -1ABCDEF -ab abc - -false true -(null) --2147483648 -2147483648 -80000000 -80000000 -abc -# GC -0 -0 -# vstr -tests -sts - -test -tes -RuntimeError: -RuntimeError: -# repl -ame__ - -argv byteorder exc_info exit -getsizeof implementation maxsize modules -path platform print_exception -stderr stdin stdout version -version_info -ementation -# attrtuple -(start=1, stop=2, step=3) -# str -1 -# bytearray -data -# mpz -1 -12345678 -0 -0 -0 -0 -0 -1 -12345 -6 -# runtime utils -TypeError: unsupported type for __abs__: 'str' -TypeError: unsupported types for __divmod__: 'str', 'str' -Warning: test -# format float -? -+1e+00 -+1e+00 -# binary -123 -456 -# VM -2 1 -# scheduler -sched(0)=1 -sched(1)=1 -sched(2)=1 -sched(3)=1 -sched(4)=0 -unlocked -3 -2 -1 -0 -0123456789 b'0123456789' -7300 -7300 -7300 -7300 -None -None -None -None -None -None -b'123' -b'123' -b'123' -OSError -0 -None -None -frzstr1 -frzmpy1 -frzstr_pkg1.__init__ -1 -frzmpy_pkg1.__init__ -1 -frzstr_pkg2.mod -1 -frzmpy_pkg2.mod -1 -ZeroDivisionError -b'# test frozen package' diff --git a/tests/unix 2/ffi_callback.py b/tests/unix 2/ffi_callback.py deleted file mode 100644 index 23b058bcec..0000000000 --- a/tests/unix 2/ffi_callback.py +++ /dev/null @@ -1,33 +0,0 @@ -try: - import ffi -except ImportError: - print("SKIP") - raise SystemExit - - -def ffi_open(names): - err = None - for n in names: - try: - mod = ffi.open(n) - return mod - except OSError as e: - err = e - raise err - -libc = ffi_open(('libc.so', 'libc.so.0', 'libc.so.6', 'libc.dylib')) - -qsort = libc.func("v", "qsort", "piip") - -def cmp(pa, pb): - a = ffi.as_bytearray(pa, 1) - b = ffi.as_bytearray(pb, 1) - #print("cmp:", a, b) - return a[0] - b[0] - -cmp_c = ffi.callback("i", cmp, "pp") - -s = bytearray(b"foobar") -print("org string:", s) -qsort(s, len(s), 1, cmp_c) -print("qsort'ed:", s) diff --git a/tests/unix 2/ffi_callback.py.exp b/tests/unix 2/ffi_callback.py.exp deleted file mode 100644 index d06fec52fb..0000000000 --- a/tests/unix 2/ffi_callback.py.exp +++ /dev/null @@ -1,2 +0,0 @@ -org string: bytearray(b'foobar') -qsort'ed: bytearray(b'abfoor') diff --git a/tests/unix 2/ffi_float.py b/tests/unix 2/ffi_float.py deleted file mode 100644 index c92a39bcdc..0000000000 --- a/tests/unix 2/ffi_float.py +++ /dev/null @@ -1,32 +0,0 @@ -# test ffi float support -try: - import ffi -except ImportError: - print("SKIP") - raise SystemExit - - -def ffi_open(names): - err = None - for n in names: - try: - mod = ffi.open(n) - return mod - except OSError as e: - err = e - raise err - -libc = ffi_open(('libc.so', 'libc.so.0', 'libc.so.6', 'libc.dylib')) - -strtof = libc.func("f", "strtof", "sp") -print('%.6f' % strtof('1.23', None)) - -strtod = libc.func("d", "strtod", "sp") -print('%.6f' % strtod('1.23', None)) - -# test passing double and float args -libm = ffi_open(('libm.so', 'libm.so.6', 'libc.so.0', 'libc.so.6', 'libc.dylib')) -tgamma = libm.func('d', 'tgamma', 'd') -for fun in (tgamma,): - for val in (0.5, 1, 1.0, 1.5, 4, 4.0): - print('%.6f' % fun(val)) diff --git a/tests/unix 2/ffi_float.py.exp b/tests/unix 2/ffi_float.py.exp deleted file mode 100644 index b9d7da2bdb..0000000000 --- a/tests/unix 2/ffi_float.py.exp +++ /dev/null @@ -1,8 +0,0 @@ -1.230000 -1.230000 -1.772454 -1.000000 -1.000000 -0.886227 -6.000000 -6.000000 diff --git a/tests/unix 2/ffi_float2.py b/tests/unix 2/ffi_float2.py deleted file mode 100644 index 721eb4d192..0000000000 --- a/tests/unix 2/ffi_float2.py +++ /dev/null @@ -1,31 +0,0 @@ -# test ffi float support -try: - import ffi -except ImportError: - print("SKIP") - raise SystemExit - - -def ffi_open(names): - err = None - for n in names: - try: - mod = ffi.open(n) - return mod - except OSError as e: - err = e - raise err - -libm = ffi_open(('libm.so', 'libm.so.6', 'libc.so.0', 'libc.so.6', 'libc.dylib')) - -# Some libc's implement tgammaf as header macro with tgamma(), so don't assume -# it'll be in library. -try: - tgammaf = libm.func('f', 'tgammaf', 'f') -except OSError: - print("SKIP") - raise SystemExit - -for fun in (tgammaf,): - for val in (0.5, 1, 1.0, 1.5, 4, 4.0): - print('%.6f' % fun(val)) diff --git a/tests/unix 2/ffi_float2.py.exp b/tests/unix 2/ffi_float2.py.exp deleted file mode 100644 index 58fc6a01ac..0000000000 --- a/tests/unix 2/ffi_float2.py.exp +++ /dev/null @@ -1,6 +0,0 @@ -1.772454 -1.000000 -1.000000 -0.886227 -6.000000 -6.000000 From 8fcb28e89eda64daf6d4a91ef5dd12a6ebb8c87e Mon Sep 17 00:00:00 2001 From: Seth Kerr Date: Wed, 16 Dec 2020 10:44:21 -0500 Subject: [PATCH 35/70] hopefully this gets rid of all the funny files --- .gitattributes 2 | 32 --------- .gitignore 2 | 88 ----------------------- .gitmodules 2 | 155 ----------------------------------------- tests/io/data/file1 2 | 3 - tools/.gitattributes 2 | 1 - tools/.gitignore 2 | 8 --- 6 files changed, 287 deletions(-) delete mode 100644 .gitattributes 2 delete mode 100644 .gitignore 2 delete mode 100644 .gitmodules 2 delete mode 100644 tests/io/data/file1 2 delete mode 100644 tools/.gitattributes 2 delete mode 100644 tools/.gitignore 2 diff --git a/.gitattributes 2 b/.gitattributes 2 deleted file mode 100644 index 5ebde95f07..0000000000 --- a/.gitattributes 2 +++ /dev/null @@ -1,32 +0,0 @@ -# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors) -# -# SPDX-License-Identifier: MIT - -# Per default everything gets normalized and gets LF line endings on checkout. -* text eol=lf - -# These will always have CRLF line endings on checkout. -*.vcxproj text eol=crlf -*.props text eol=crlf -*.bat text eol=crlf - -# These are binary so should never be modified by git. -*.png binary -*.jpg binary -*.dxf binary -*.mpy binary -*.deb binary -*.zip binary -*.pdf binary - -# These should also not be modified by git. -tests/basics/string_cr_conversion.py -text -tests/basics/string_crlf_conversion.py -text -ports/stm32/pybcdc.inf_template -text -ports/stm32/usbhost/** -text -ports/cc3200/hal/aes.c -text -ports/cc3200/hal/aes.h -text -ports/cc3200/hal/des.c -text -ports/cc3200/hal/i2s.c -text -ports/cc3200/hal/i2s.h -text -ports/cc3200/version.h -text diff --git a/.gitignore 2 b/.gitignore 2 deleted file mode 100644 index a8814be45e..0000000000 --- a/.gitignore 2 +++ /dev/null @@ -1,88 +0,0 @@ -# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors) -# -# SPDX-License-Identifier: MIT - -# Compiled Sources -################### -*.o -*.a -!atmel-samd/asf/**/*.a -*.elf -*.bin -*.map -*.hex -*.dis -*.exe - -# Packages -############ -dist/ -*.egg-info -.eggs - -# Logs and Databases -###################### -*.log - -# VIM Swap Files -###################### -*.swp - -# Build directory -###################### -build/ -bin/ -circuitpython-stubs/ - -# Test failure outputs -###################### -tests/*.exp -tests/*.out - -# Python cache files -###################### -__pycache__/ -*.pyc - -# Customized Makefile/project overrides -###################### -GNUmakefile -user.props - -# Sphinx output -############### -_build - -# Generated rst files -###################### -genrst/ -/autoapi/ -/shared-bindings/*/**/*.rst - -# ctags and similar -################### -TAGS - -# Merge leftovers -################# -*.orig - -# Emacs backup files -#################### -*~ - -*.DS_Store -**/*.DS_Store -*.icloud - -# POEdit mo files -#################### -*.mo - -.vscode -.idea - -# Python Virtual Environments -#################### -.venv -.env diff --git a/.gitmodules 2 b/.gitmodules 2 deleted file mode 100644 index aaa66caf71..0000000000 --- a/.gitmodules 2 +++ /dev/null @@ -1,155 +0,0 @@ -# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors) -# -# SPDX-License-Identifier: MIT - -[submodule "lib/axtls"] - path = lib/axtls - url = https://github.com/pfalcon/axtls - branch = micropython -[submodule "lib/libffi"] - path = lib/libffi - url = https://github.com/atgreen/libffi -[submodule "lib/berkeley-db-1.xx"] - path = lib/berkeley-db-1.xx - url = https://github.com/pfalcon/berkeley-db-1.xx -[submodule "lib/uzlib"] - path = lib/uzlib - url = https://github.com/pfalcon/uzlib -[submodule "tools/uf2"] - path = tools/uf2 - url = https://github.com/Microsoft/uf2.git -[submodule "atmel-samd/frozen/Adafruit_CircuitPython_NeoPixel"] - path = frozen/Adafruit_CircuitPython_NeoPixel - url = https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel -[submodule "frozen/Adafruit_CircuitPython_Thermistor"] - path = frozen/Adafruit_CircuitPython_Thermistor - url = https://github.com/adafruit/Adafruit_CircuitPython_Thermistor.git -[submodule "frozen/Adafruit_CircuitPython_LIS3DH"] - path = frozen/Adafruit_CircuitPython_LIS3DH - url = https://github.com/adafruit/Adafruit_CircuitPython_LIS3DH.git -[submodule "frozen/Adafruit_CircuitPython_BusDevice"] - path = frozen/Adafruit_CircuitPython_BusDevice - url = https://github.com/adafruit/Adafruit_CircuitPython_BusDevice.git -[submodule "tools/python-semver"] - path = tools/python-semver - url = https://github.com/k-bx/python-semver.git -[submodule "atmel-samd/asf4"] - path = ports/atmel-samd/asf4 - url = https://github.com/adafruit/asf4.git - branch = circuitpython -[submodule "tools/usb_descriptor"] - path = tools/usb_descriptor - url = https://github.com/adafruit/usb_descriptor.git -[submodule "lib/nrfutil"] - path = lib/nrfutil - url = https://github.com/adafruit/nRF52_nrfutil -[submodule "ports/atmel-samd/freetouch"] - path = ports/atmel-samd/freetouch - url = https://github.com/adafruit/Adafruit_FreeTouch.git -[submodule "frozen/Adafruit_CircuitPython_CircuitPlayground"] - path = frozen/Adafruit_CircuitPython_CircuitPlayground - url = https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground.git -[submodule "frozen/Adafruit_CircuitPython_HID"] - path = frozen/Adafruit_CircuitPython_HID - url = https://github.com/adafruit/Adafruit_CircuitPython_HID.git -[submodule "ports/atmel-samd/Adafruit_CircuitPython_Motor"] - path = frozen/Adafruit_CircuitPython_Motor - url = https://github.com/adafruit/Adafruit_CircuitPython_Motor.git -[submodule "ports/atmel-samd/Adafruit_CircuitPython_seesaw"] - path = frozen/Adafruit_CircuitPython_seesaw - url = https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git -[submodule "frozen/Adafruit_CircuitPython_IRRemote"] - path = frozen/Adafruit_CircuitPython_IRRemote - url = https://github.com/adafruit/Adafruit_CircuitPython_IRRemote.git -[submodule "frozen/Adafruit_CircuitPython_DotStar"] - path = frozen/Adafruit_CircuitPython_DotStar - url = https://github.com/adafruit/Adafruit_CircuitPython_DotStar.git -[submodule "ports/atmel-samd/peripherals"] - path = ports/atmel-samd/peripherals - url = https://github.com/adafruit/samd-peripherals.git -[submodule "frozen/Adafruit_CircuitPython_Crickit"] - path = frozen/Adafruit_CircuitPython_Crickit - url = https://github.com/adafruit/Adafruit_CircuitPython_Crickit -[submodule "ports/nrf/nrfx"] - path = ports/nrf/nrfx - url = https://github.com/adafruit/nrfx.git -[submodule "lib/tinyusb"] - path = lib/tinyusb - url = https://github.com/hathach/tinyusb.git - branch = master - fetchRecurseSubmodules = false -[submodule "tools/huffman"] - path = tools/huffman - url = https://github.com/tannewt/huffman.git -[submodule "tools/adabot"] - path = tools/adabot - url = https://github.com/adafruit/adabot.git -[submodule "tools/bitmap_font"] - path = tools/bitmap_font - url = https://github.com/adafruit/Adafruit_CircuitPython_BitmapFont.git -[submodule "tools/Tecate-bitmap-fonts"] - path = tools/Tecate-bitmap-fonts - url = https://github.com/Tecate/bitmap-fonts.git -[submodule "frozen/pew-pewpew-standalone-10.x"] - path = frozen/pew-pewpew-standalone-10.x - url = https://github.com/pewpew-game/pew-pewpew-standalone-10.x.git -[submodule "frozen/circuitpython-stage"] - path = frozen/circuitpython-stage - url = https://github.com/python-ugame/circuitpython-stage.git -[submodule "ports/cxd56/spresense-exported-sdk"] - path = ports/cxd56/spresense-exported-sdk - url = https://github.com/sonydevworld/spresense-exported-sdk.git -[submodule "frozen/Adafruit_CircuitPython_SD"] - path = frozen/Adafruit_CircuitPython_SD - url = https://github.com/adafruit/Adafruit_CircuitPython_SD.git -[submodule "lib/mp3"] - path = lib/mp3 - url = https://github.com/adafruit/Adafruit_MP3 -[submodule "ports/mimxrt10xx/sdk"] - path = ports/mimxrt10xx/sdk - url = https://github.com/adafruit/MIMXRT10xx_SDK -[submodule "frozen/Adafruit_CircuitPython_Register"] - path = frozen/Adafruit_CircuitPython_Register - url = https://github.com/adafruit/Adafruit_CircuitPython_Register.git -[submodule "extmod/ulab"] - path = extmod/ulab - url = https://github.com/v923z/micropython-ulab -[submodule "frozen/Adafruit_CircuitPython_ESP32SPI"] - path = frozen/Adafruit_CircuitPython_ESP32SPI - url = https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI -[submodule "frozen/Adafruit_CircuitPython_Requests"] - path = frozen/Adafruit_CircuitPython_Requests - url = https://github.com/adafruit/Adafruit_CircuitPython_Requests -[submodule "ports/stm/st_driver"] - path = ports/stm/st_driver - url = https://github.com/hathach/st_driver.git -[submodule "lib/protomatter"] - path = lib/protomatter - url = https://github.com/adafruit/Adafruit_Protomatter -[submodule "frozen/Adafruit_CircuitPython_LSM6DS"] - path = frozen/Adafruit_CircuitPython_LSM6DS - url = https://github.com/adafruit/Adafruit_CircuitPython_LSM6DS -[submodule "frozen/Adafruit_CircuitPython_FocalTouch"] - path = frozen/Adafruit_CircuitPython_FocalTouch - url = https://github.com/adafruit/Adafruit_CircuitPython_FocalTouch -[submodule "frozen/Adafruit_CircuitPython_DS3231"] - path = frozen/Adafruit_CircuitPython_DS3231 - url = https://github.com/adafruit/Adafruit_CircuitPython_DS3231 -[submodule "frozen/Adafruit_CircuitPython_DRV2605"] - path = frozen/Adafruit_CircuitPython_DRV2605 - url = https://github.com/adafruit/Adafruit_CircuitPython_DRV2605 -[submodule "frozen/Adafruit_CircuitPython_BLE"] - path = frozen/Adafruit_CircuitPython_BLE - url = https://github.com/adafruit/Adafruit_CircuitPython_BLE -[submodule "frozen/Adafruit_CircuitPython_BLE_Apple_Notification_Center"] - path = frozen/Adafruit_CircuitPython_BLE_Apple_Notification_Center - url = https://github.com/adafruit/Adafruit_CircuitPython_BLE_Apple_Notification_Center -[submodule "frozen/Adafruit_CircuitPython_RFM9x"] - path = frozen/Adafruit_CircuitPython_RFM9x - url = https://github.com/adafruit/Adafruit_CircuitPython_RFM9x.git -[submodule "frozen/Adafruit_CircuitPython_RFM69"] - path = frozen/Adafruit_CircuitPython_RFM69 - url = https://github.com/adafruit/Adafruit_CircuitPython_RFM69.git -[submodule "ports/esp32s2/esp-idf"] - path = ports/esp32s2/esp-idf - url = https://github.com/jepler/esp-idf.git diff --git a/tests/io/data/file1 2 b/tests/io/data/file1 2 deleted file mode 100644 index e08206337f..0000000000 --- a/tests/io/data/file1 2 +++ /dev/null @@ -1,3 +0,0 @@ -longer line1 -line2 -line3 diff --git a/tools/.gitattributes 2 b/tools/.gitattributes 2 deleted file mode 100644 index 9206a0bfc1..0000000000 --- a/tools/.gitattributes 2 +++ /dev/null @@ -1 +0,0 @@ -*.tar.gz binary diff --git a/tools/.gitignore 2 b/tools/.gitignore 2 deleted file mode 100644 index 9f65f493bc..0000000000 --- a/tools/.gitignore 2 +++ /dev/null @@ -1,8 +0,0 @@ -tinytest/.gitignore -tinytest/.travis.yml -tinytest/Makefile -tinytest/Makefile.arm-cortex-m3-qemu -tinytest/Makefile.avr -tinytest/TODO -tinytest/portable_demo.c -tinytest/tinytest_demo.c From 1f58795c56d35d6a50ecbea3fa8744e7b73f54b6 Mon Sep 17 00:00:00 2001 From: Seth Kerr Date: Wed, 16 Dec 2020 10:47:37 -0500 Subject: [PATCH 36/70] still removing doubles. should be the last --- .mailmap 2 | 112 ------------------------------ mpy-cross/.gitignore 2 | 11 --- ports/atmel-samd/.gitattributes 2 | 2 - ports/atmel-samd/.gitignore 2 | 1 - 4 files changed, 126 deletions(-) delete mode 100644 .mailmap 2 delete mode 100644 mpy-cross/.gitignore 2 delete mode 100644 ports/atmel-samd/.gitattributes 2 delete mode 100644 ports/atmel-samd/.gitignore 2 diff --git a/.mailmap 2 b/.mailmap 2 deleted file mode 100644 index f9d7f47a16..0000000000 --- a/.mailmap 2 +++ /dev/null @@ -1,112 +0,0 @@ -# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò -# -# SPDX-License-Identifier: Unlicense - -Alexander Steffen -Alexander Steffen -Alexander Steffen -Benjamin Vernoux -Brent Rubell -Brent Rubell -Brent Rubell -Carlos -Chris Packham -Chris Packham -Damiano Mazzella -Damien George -Dan Halbert -Dan Halbert -Daniel Pollard -Daniel Pollard -Daniel Tralamazza -Daniel Tralamazza -David Glaude -David Glaude -George Waters -George Waters -Ha Thach -Henrik Sölver -Ilya Dmitrichenko -Ilya Dmitrichenko -Jason Pecor <14111408+jpecor@users.noreply.github.com> -Jeff Epler -Jeff Epler -Jeff Epler -Jeff Epler -Jerry Needell -Joe Bakalor -Josh Klar -Josh Klar -Juan Biondi -Juan Biondi -KalbeAbbas -KalbeAbbas -Kamil Tomaszewski -Kamil Tomaszewski <46525824+kamtom480@users.noreply.github.com> -Kattni -Kattni Rembor -Kenny -Kenny <3454741+WarriorOfWire@users.noreply.github.com> -Kevin Townsend -Kevin Townsend -Krzysztof Blazewicz -Krzysztof Blazewicz -Li Weiwei -Li Weiwei -Limor "Ladyada" Fried -Limor "Ladyada" Fried -Lucian Copeland -Lucian Copeland -Mark Olsson -Mark Olsson -Matt Land -Matt Land -Matt Wozniski -Matt Wozniski -Melissa LeBlanc-Williams -Melissa LeBlanc-Williams -Metallicow -Metallicow -Peter Hinch -Peter Hinch -Radomir Dopieralski -Radomir Dopieralski -Rafa Gould -Rafa Gould <50337143+rafa-gould@users.noreply.github.com> -Ryan Shaw -Ryan Shaw -Sabas -Sabas -Sabas -Scott Shawcroft -Scott Shawcroft -Scott Shawcroft -Scott Shawcroft -Scott Shawcroft -Sebastian Plamauer -Sebastian Plamauer -Senuros -Senuros -Stewart Colborne -Stewart Colborne -TG-Techie -TG-Techie <39284876+TG-Techie@users.noreply.github.com> -Thea Flowers -Thea Flowers -Tobias Badertscher -Tobias Badertscher -danicampora -danicampora -dherrada -dherrada <33632497+dherrada@users.noreply.github.com> -dherrada <=> -glennrub -retoc -retoc -siddacious -siddacious -siddacious -sommersoft -sommersoft -stijn -stijn diff --git a/mpy-cross/.gitignore 2 b/mpy-cross/.gitignore 2 deleted file mode 100644 index 6daeea5040..0000000000 --- a/mpy-cross/.gitignore 2 +++ /dev/null @@ -1,11 +0,0 @@ -# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors) -# -# SPDX-License-Identifier: MIT - -/build-* -/mpy-cross -/mpy-cross.static -/mpy-cross.static.exe -/mpy-cross.static-raspbian -/mpy-cross.fuzz -/pitools diff --git a/ports/atmel-samd/.gitattributes 2 b/ports/atmel-samd/.gitattributes 2 deleted file mode 100644 index 09bba615b1..0000000000 --- a/ports/atmel-samd/.gitattributes 2 +++ /dev/null @@ -1,2 +0,0 @@ -tools/bossac* binary -asf/**/*.a binary diff --git a/ports/atmel-samd/.gitignore 2 b/ports/atmel-samd/.gitignore 2 deleted file mode 100644 index 414487d53e..0000000000 --- a/ports/atmel-samd/.gitignore 2 +++ /dev/null @@ -1 +0,0 @@ -build-*/ From 74805527e8616076fc65e2875747ce269256528b Mon Sep 17 00:00:00 2001 From: Seth Kerr <41877068+skerr92@users.noreply.github.com> Date: Wed, 16 Dec 2020 10:52:18 -0500 Subject: [PATCH 37/70] Delete board.h not supposed to be here. --- ports/atmel-samd/boards/board.h | 47 --------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 ports/atmel-samd/boards/board.h diff --git a/ports/atmel-samd/boards/board.h b/ports/atmel-samd/boards/board.h deleted file mode 100644 index 4f0ae9d728..0000000000 --- a/ports/atmel-samd/boards/board.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -// This file defines board specific functions. - -#ifndef MICROPY_INCLUDED_ATMEL_SAMD_BOARDS_BOARD_H -#define MICROPY_INCLUDED_ATMEL_SAMD_BOARDS_BOARD_H - -#include - -#include "py/mpconfig.h" - -// Initializes board related state once on start up. -void board_init(void); - -// Returns true if the user initiates safe mode in a board specific way. -// Also add BOARD_USER_SAFE_MODE in mpconfigboard.h to explain the board specific -// way. -bool board_requests_safe_mode(void); - -// Reset the state of off MCU components such as neopixels. -void reset_board(void); - -#endif // MICROPY_INCLUDED_ATMEL_SAMD_BOARDS_BOARD_H From 109b6baee45629e3c072eb17b6c96ac06d7df842 Mon Sep 17 00:00:00 2001 From: Wellington Terumi Uemura Date: Wed, 16 Dec 2020 14:04:31 +0000 Subject: [PATCH 38/70] Translated using Weblate (Portuguese (Brazil)) Currently translated at 100.0% (879 of 879 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/pt_BR/ --- locale/pt_BR.po | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/locale/pt_BR.po b/locale/pt_BR.po index eb73928502..8d3d54fabc 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -6,7 +6,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2020-12-14 12:59-0500\n" -"PO-Revision-Date: 2020-12-11 19:08+0000\n" +"PO-Revision-Date: 2020-12-16 17:00+0000\n" "Last-Translator: Wellington Terumi Uemura \n" "Language-Team: \n" "Language: pt_BR\n" @@ -1107,7 +1107,7 @@ msgstr "Frequência PWM inválida" #: ports/esp32s2/common-hal/analogio/AnalogIn.c msgid "Invalid Pin" -msgstr "" +msgstr "Pino inválido" #: py/moduerrno.c shared-module/rgbmatrix/RGBMatrix.c msgid "Invalid argument" @@ -1977,7 +1977,7 @@ msgstr "Não é possível gravar no nvm." #: shared-bindings/alarm/SleepMemory.c msgid "Unable to write to sleep_memory." -msgstr "" +msgstr "Não foi possível escrever no sleep_memory." #: ports/nrf/common-hal/_bleio/UUID.c msgid "Unexpected nrfx uuid type" From 28bd29eb42d61d0a7116b6c4295e166fcfbe7145 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 16 Dec 2020 13:48:07 -0600 Subject: [PATCH 39/70] displayio: ColorConverter: fix logic errors about transparent pixels The transparent_color field was never initialized. I _think_ this means its value was always set to 0, or the blackest of blacks. Instead, initialize it to the sentinel value, newly given the name NO_TRANSPARENT_COLOR. This exposed a second problem: The test for whether there was an existing transparent color was wrong (backwards). I am guessing that this was not found due to the first bug; since the converter had a transparent color, the correct test would have led to always getting the error "Only one color can be transparent at a time". Closes #3723 --- shared-module/displayio/ColorConverter.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/shared-module/displayio/ColorConverter.c b/shared-module/displayio/ColorConverter.c index 80558d037a..40dcd9d167 100644 --- a/shared-module/displayio/ColorConverter.c +++ b/shared-module/displayio/ColorConverter.c @@ -29,6 +29,8 @@ #include "py/misc.h" #include "py/runtime.h" +#define NO_TRANSPARENT_COLOR (0x1000000) + uint32_t displayio_colorconverter_dither_noise_1 (uint32_t n) { n = (n >> 13) ^ n; @@ -42,6 +44,7 @@ uint32_t displayio_colorconverter_dither_noise_2(uint32_t x, uint32_t y) { void common_hal_displayio_colorconverter_construct(displayio_colorconverter_t* self, bool dither) { self->dither = dither; + self->transparent_color = NO_TRANSPARENT_COLOR; } uint16_t displayio_colorconverter_compute_rgb565(uint32_t color_rgb888) { @@ -130,7 +133,7 @@ bool common_hal_displayio_colorconverter_get_dither(displayio_colorconverter_t* } void common_hal_displayio_colorconverter_make_transparent(displayio_colorconverter_t* self, uint32_t transparent_color) { - if (self->transparent_color >= 0x1000000) { + if (self->transparent_color != NO_TRANSPARENT_COLOR) { mp_raise_RuntimeError(translate("Only one color can be transparent at a time")); } self->transparent_color = transparent_color; @@ -138,8 +141,8 @@ void common_hal_displayio_colorconverter_make_transparent(displayio_colorconvert void common_hal_displayio_colorconverter_make_opaque(displayio_colorconverter_t* self, uint32_t transparent_color) { (void) transparent_color; - // 0x1000000 will never equal a valid color - self->transparent_color = 0x1000000; + // NO_TRANSPARENT_COLOR will never equal a valid color + self->transparent_color = NO_TRANSPARENT_COLOR; } void displayio_colorconverter_convert(displayio_colorconverter_t *self, const _displayio_colorspace_t* colorspace, const displayio_input_pixel_t *input_pixel, displayio_output_pixel_t *output_color) { From fac0bf1db8adb4caeba9d3bbec10a670a989ce7d Mon Sep 17 00:00:00 2001 From: Hany Elkomy Date: Thu, 17 Dec 2020 12:37:32 +0800 Subject: [PATCH 40/70] Add files via upload --- .../boards/stackrduino_m0_pro/board.c | 37 +++++++++++++++++ .../boards/stackrduino_m0_pro/mpconfigboard.h | 36 +++++++++++++++++ .../stackrduino_m0_pro/mpconfigboard.mk | 26 ++++++++++++ .../boards/stackrduino_m0_pro/pins.c | 40 +++++++++++++++++++ 4 files changed, 139 insertions(+) create mode 100644 ports/atmel-samd/boards/stackrduino_m0_pro/board.c create mode 100644 ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.h create mode 100644 ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk create mode 100644 ports/atmel-samd/boards/stackrduino_m0_pro/pins.c diff --git a/ports/atmel-samd/boards/stackrduino_m0_pro/board.c b/ports/atmel-samd/boards/stackrduino_m0_pro/board.c new file mode 100644 index 0000000000..d7e856d611 --- /dev/null +++ b/ports/atmel-samd/boards/stackrduino_m0_pro/board.c @@ -0,0 +1,37 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "boards/board.h" + +void board_init(void) { +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { +} diff --git a/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.h b/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.h new file mode 100644 index 0000000000..8f23e82d48 --- /dev/null +++ b/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.h @@ -0,0 +1,36 @@ +#define MICROPY_HW_BOARD_NAME "StackRduino M0 PRO" +#define MICROPY_HW_MCU_NAME "samd21g18" + +#define MICROPY_HW_LED_STATUS (&pin_PA17) +#define MICROPY_HW_NEOPIXEL (&pin_PA06) + +#define SPI_FLASH_BAUDRATE (8000000) + +#define SPI_FLASH_MOSI_PIN &pin_PB22 +#define SPI_FLASH_MISO_PIN &pin_PB03 +#define SPI_FLASH_SCK_PIN &pin_PB23 +#define SPI_FLASH_CS_PIN &pin_PA27 + +// These are pins not to reset. +#define MICROPY_PORT_A (PORT_PA06) +#define MICROPY_PORT_B (0) +#define MICROPY_PORT_C (0) + +#define BOARD_HAS_CRYSTAL 1 + +#define DEFAULT_I2C_BUS_SCL (&pin_PA23) +#define DEFAULT_I2C_BUS_SDA (&pin_PA22) + +#define DEFAULT_SPI_BUS_SCK (&pin_PB11) +#define DEFAULT_SPI_BUS_MOSI (&pin_PB10) +#define DEFAULT_SPI_BUS_MISO (&pin_PA12) + +#define DEFAULT_UART_BUS_RX (&pin_PA11) +#define DEFAULT_UART_BUS_TX (&pin_PA10) + +// USB is always used internally so skip the pin objects for it. +#define IGNORE_PIN_PA24 1 +#define IGNORE_PIN_PA25 1 + + + diff --git a/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk b/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk new file mode 100644 index 0000000000..a7caf5bc81 --- /dev/null +++ b/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk @@ -0,0 +1,26 @@ +LD_FILE = boards/samd21x18-bootloader-external-flash.ld +USB_VID = 0x1209 +USB_PID = 0xE3E3 +USB_PRODUCT = "StackRduino M0 PRO" +USB_MANUFACTURER = "StackRduino" + +CHIP_VARIANT = SAMD21G18A +CHIP_FAMILY = samd21 + +SPI_FLASH_FILESYSTEM = 1 +EXTERNAL_FLASH_DEVICE_COUNT = 1 +EXTERNAL_FLASH_DEVICES = "W25Q64JV_IQ" +LONGINT_IMPL = MPZ + + +CIRCUITPY_BITBANGIO = 0 +CIRCUITPY_FREQUENCYIO = 0 +CIRCUITPY_COUNTIO = 0 +CIRCUITPY_I2CPERIPHERAL = 0 +CIRCUITPY_VECTORIO = 0 + +CFLAGS_INLINE_LIMIT = 60 +SUPEROPT_GC = 0 + +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_BusDevice +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel diff --git a/ports/atmel-samd/boards/stackrduino_m0_pro/pins.c b/ports/atmel-samd/boards/stackrduino_m0_pro/pins.c new file mode 100644 index 0000000000..50dc341f9e --- /dev/null +++ b/ports/atmel-samd/boards/stackrduino_m0_pro/pins.c @@ -0,0 +1,40 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_global_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PB08) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PB09) }, + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA04) }, + { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PA05) }, + { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PB02) }, + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PB11) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PB10) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA12) }, + { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA11) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PA11) }, + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PA10) }, + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PA10) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA22) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA23) }, + { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_PA08) }, + { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PA09) }, + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PA14) }, + { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PA15) }, + { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PA20) }, + { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_PA21) }, + { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PA07) }, + { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA18) }, + { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA16) }, + { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA19) }, + { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA17) }, + { MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_PA28) }, + { MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_PA28) }, + { MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_PA13) }, + { MP_ROM_QSTR(MP_QSTR_CHRG_EN), MP_ROM_PTR(&pin_PA13) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); From 70a9c601a8461717effdfd543697778922a3a0c9 Mon Sep 17 00:00:00 2001 From: Hany Elkomy Date: Thu, 17 Dec 2020 12:52:51 +0800 Subject: [PATCH 41/70] Update devices.h Correct capacity value for the MX25R1635F from 0x18 to 0x15 (tested and working) refer to https://github.com/adafruit/circuitpython/issues/3558 --- supervisor/shared/external_flash/devices.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supervisor/shared/external_flash/devices.h b/supervisor/shared/external_flash/devices.h index a874dbd4fd..6797f86f08 100644 --- a/supervisor/shared/external_flash/devices.h +++ b/supervisor/shared/external_flash/devices.h @@ -537,7 +537,7 @@ typedef struct { .start_up_time_us = 800, \ .manufacturer_id = 0xc2, \ .memory_type = 0x28, \ - .capacity = 0x18, \ + .capacity = 0x15, \ .max_clock_speed_mhz = 33, /* 8 mhz for dual/quad */ \ .quad_enable_bit_mask = 0x80, \ .has_sector_protection = false, \ From 70739ff639f53d00473a69b892771e95995b1c5d Mon Sep 17 00:00:00 2001 From: Hany Elkomy Date: Thu, 17 Dec 2020 13:11:53 +0800 Subject: [PATCH 42/70] Update pins.c --- ports/atmel-samd/boards/stackrduino_m0_pro/pins.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ports/atmel-samd/boards/stackrduino_m0_pro/pins.c b/ports/atmel-samd/boards/stackrduino_m0_pro/pins.c index 50dc341f9e..7ddaec4113 100644 --- a/ports/atmel-samd/boards/stackrduino_m0_pro/pins.c +++ b/ports/atmel-samd/boards/stackrduino_m0_pro/pins.c @@ -23,16 +23,16 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PA20) }, { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_PA21) }, { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_PA06) }, - { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PA06) }, { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PA07) }, { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA18) }, { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA16) }, { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA19) }, { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA17) }, - { MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_PA28) }, - { MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_PA28) }, - { MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_PA13) }, - { MP_ROM_QSTR(MP_QSTR_CHRG_EN), MP_ROM_PTR(&pin_PA13) }, + { MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_PA28) }, + { MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_PA28) }, + { MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_PA13) }, + { MP_ROM_QSTR(MP_QSTR_CHRG_EN), MP_ROM_PTR(&pin_PA13) }, { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, From f3b7cd6a5d15ec82c4a9d06a65fbf5dc444ef3e0 Mon Sep 17 00:00:00 2001 From: Hany Elkomy Date: Thu, 17 Dec 2020 14:24:07 +0800 Subject: [PATCH 43/70] Delete pins.c --- .../boards/stackrduino_m0_pro/pins.c | 40 ------------------- 1 file changed, 40 deletions(-) delete mode 100644 ports/atmel-samd/boards/stackrduino_m0_pro/pins.c diff --git a/ports/atmel-samd/boards/stackrduino_m0_pro/pins.c b/ports/atmel-samd/boards/stackrduino_m0_pro/pins.c deleted file mode 100644 index 7ddaec4113..0000000000 --- a/ports/atmel-samd/boards/stackrduino_m0_pro/pins.c +++ /dev/null @@ -1,40 +0,0 @@ -#include "shared-bindings/board/__init__.h" - -STATIC const mp_rom_map_elem_t board_global_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, - { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PB08) }, - { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PB09) }, - { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA04) }, - { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PA05) }, - { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PB02) }, - { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PB11) }, - { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PB10) }, - { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA12) }, - { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA11) }, - { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PA11) }, - { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PA10) }, - { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PA10) }, - { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA22) }, - { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA23) }, - { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_PA08) }, - { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PA09) }, - { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PA14) }, - { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PA15) }, - { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PA20) }, - { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_PA21) }, - { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_PA06) }, - { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PA06) }, - { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PA07) }, - { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA18) }, - { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA16) }, - { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA19) }, - { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA17) }, - { MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_PA28) }, - { MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_PA28) }, - { MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_PA13) }, - { MP_ROM_QSTR(MP_QSTR_CHRG_EN), MP_ROM_PTR(&pin_PA13) }, - { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, - { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, - { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, -}; -MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); From 3d9e4958c5c7d9373c373aa3be5947aaeb504330 Mon Sep 17 00:00:00 2001 From: Hany Elkomy Date: Thu, 17 Dec 2020 14:24:24 +0800 Subject: [PATCH 44/70] Add files via upload --- .../boards/stackrduino_m0_pro/pins.c | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 ports/atmel-samd/boards/stackrduino_m0_pro/pins.c diff --git a/ports/atmel-samd/boards/stackrduino_m0_pro/pins.c b/ports/atmel-samd/boards/stackrduino_m0_pro/pins.c new file mode 100644 index 0000000000..95d2eb5a3d --- /dev/null +++ b/ports/atmel-samd/boards/stackrduino_m0_pro/pins.c @@ -0,0 +1,40 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_global_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PB08) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PB09) }, + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA04) }, + { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PA05) }, + { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PB02) }, + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PB11) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PB10) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA12) }, + { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA11) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PA11) }, + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PA10) }, + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PA10) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA22) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA23) }, + { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_PA08) }, + { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PA09) }, + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PA14) }, + { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PA15) }, + { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PA20) }, + { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_PA21) }, + { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PA07) }, + { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA18) }, + { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA16) }, + { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA19) }, + { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA17) }, + { MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_PA28) }, + { MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_PA28) }, + { MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_PA13) }, + { MP_ROM_QSTR(MP_QSTR_CHRG_EN), MP_ROM_PTR(&pin_PA13) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); From 23ad9c7402325cf50e7f09db11f0aad4e396b935 Mon Sep 17 00:00:00 2001 From: Hany Elkomy Date: Thu, 17 Dec 2020 15:17:04 +0800 Subject: [PATCH 45/70] Update mpconfigboard.h removed whitespace --- ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.h b/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.h index 8f23e82d48..f0b2764a49 100644 --- a/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.h +++ b/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.h @@ -31,6 +31,3 @@ // USB is always used internally so skip the pin objects for it. #define IGNORE_PIN_PA24 1 #define IGNORE_PIN_PA25 1 - - - From 109e147b46838ee0b97b825d91de8d2dc6834e6c Mon Sep 17 00:00:00 2001 From: Hany Elkomy Date: Thu, 17 Dec 2020 16:22:47 +0800 Subject: [PATCH 46/70] Update board.c updated path to board.h --- ports/atmel-samd/boards/stackrduino_m0_pro/board.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/atmel-samd/boards/stackrduino_m0_pro/board.c b/ports/atmel-samd/boards/stackrduino_m0_pro/board.c index d7e856d611..84960e73cf 100644 --- a/ports/atmel-samd/boards/stackrduino_m0_pro/board.c +++ b/ports/atmel-samd/boards/stackrduino_m0_pro/board.c @@ -24,7 +24,7 @@ * THE SOFTWARE. */ -#include "boards/board.h" +#include "supervisor/board.h" void board_init(void) { } From 0a7c74230c9cee04785e906cbe8160f6d7d40ddb Mon Sep 17 00:00:00 2001 From: Hany Elkomy Date: Thu, 17 Dec 2020 16:26:54 +0800 Subject: [PATCH 47/70] Update mpconfigboard.mk updated for 6.1 --- ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk b/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk index a7caf5bc81..955f3d593b 100644 --- a/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk +++ b/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk @@ -1,4 +1,3 @@ -LD_FILE = boards/samd21x18-bootloader-external-flash.ld USB_VID = 0x1209 USB_PID = 0xE3E3 USB_PRODUCT = "StackRduino M0 PRO" @@ -18,9 +17,9 @@ CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_COUNTIO = 0 CIRCUITPY_I2CPERIPHERAL = 0 CIRCUITPY_VECTORIO = 0 +CIRCUITPY_BUSDEVICE = 0 CFLAGS_INLINE_LIMIT = 60 SUPEROPT_GC = 0 -FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_BusDevice FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel From 736c0d4c3d880664aab0e82c26bd7d92cf6e5b6a Mon Sep 17 00:00:00 2001 From: Hany Elkomy Date: Thu, 17 Dec 2020 17:08:46 +0800 Subject: [PATCH 48/70] Delete pins.c --- .../boards/stackrduino_m0_pro/pins.c | 40 ------------------- 1 file changed, 40 deletions(-) delete mode 100644 ports/atmel-samd/boards/stackrduino_m0_pro/pins.c diff --git a/ports/atmel-samd/boards/stackrduino_m0_pro/pins.c b/ports/atmel-samd/boards/stackrduino_m0_pro/pins.c deleted file mode 100644 index 95d2eb5a3d..0000000000 --- a/ports/atmel-samd/boards/stackrduino_m0_pro/pins.c +++ /dev/null @@ -1,40 +0,0 @@ -#include "shared-bindings/board/__init__.h" - -STATIC const mp_rom_map_elem_t board_global_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, - { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PB08) }, - { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PB09) }, - { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA04) }, - { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PA05) }, - { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PB02) }, - { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PB11) }, - { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PB10) }, - { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA12) }, - { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA11) }, - { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PA11) }, - { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PA10) }, - { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PA10) }, - { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA22) }, - { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA23) }, - { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_PA08) }, - { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PA09) }, - { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PA14) }, - { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PA15) }, - { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PA20) }, - { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_PA21) }, - { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_PA06) }, - { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PA06) }, - { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PA07) }, - { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA18) }, - { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA16) }, - { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA19) }, - { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA17) }, - { MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_PA28) }, - { MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_PA28) }, - { MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_PA13) }, - { MP_ROM_QSTR(MP_QSTR_CHRG_EN), MP_ROM_PTR(&pin_PA13) }, - { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, - { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, - { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, -}; -MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); From 1284418fa7df4683074a3ad020dac27967c9819e Mon Sep 17 00:00:00 2001 From: Hany Elkomy Date: Thu, 17 Dec 2020 17:08:48 +0800 Subject: [PATCH 49/70] Delete mpconfigboard.mk --- .../stackrduino_m0_pro/mpconfigboard.mk | 25 ------------------- 1 file changed, 25 deletions(-) delete mode 100644 ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk diff --git a/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk b/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk deleted file mode 100644 index 955f3d593b..0000000000 --- a/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk +++ /dev/null @@ -1,25 +0,0 @@ -USB_VID = 0x1209 -USB_PID = 0xE3E3 -USB_PRODUCT = "StackRduino M0 PRO" -USB_MANUFACTURER = "StackRduino" - -CHIP_VARIANT = SAMD21G18A -CHIP_FAMILY = samd21 - -SPI_FLASH_FILESYSTEM = 1 -EXTERNAL_FLASH_DEVICE_COUNT = 1 -EXTERNAL_FLASH_DEVICES = "W25Q64JV_IQ" -LONGINT_IMPL = MPZ - - -CIRCUITPY_BITBANGIO = 0 -CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_COUNTIO = 0 -CIRCUITPY_I2CPERIPHERAL = 0 -CIRCUITPY_VECTORIO = 0 -CIRCUITPY_BUSDEVICE = 0 - -CFLAGS_INLINE_LIMIT = 60 -SUPEROPT_GC = 0 - -FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel From f3fb01416679132e52a401226a1df7408b621903 Mon Sep 17 00:00:00 2001 From: Hany Elkomy Date: Thu, 17 Dec 2020 17:08:50 +0800 Subject: [PATCH 50/70] Delete mpconfigboard.h --- .../boards/stackrduino_m0_pro/mpconfigboard.h | 33 ------------------- 1 file changed, 33 deletions(-) delete mode 100644 ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.h diff --git a/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.h b/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.h deleted file mode 100644 index f0b2764a49..0000000000 --- a/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.h +++ /dev/null @@ -1,33 +0,0 @@ -#define MICROPY_HW_BOARD_NAME "StackRduino M0 PRO" -#define MICROPY_HW_MCU_NAME "samd21g18" - -#define MICROPY_HW_LED_STATUS (&pin_PA17) -#define MICROPY_HW_NEOPIXEL (&pin_PA06) - -#define SPI_FLASH_BAUDRATE (8000000) - -#define SPI_FLASH_MOSI_PIN &pin_PB22 -#define SPI_FLASH_MISO_PIN &pin_PB03 -#define SPI_FLASH_SCK_PIN &pin_PB23 -#define SPI_FLASH_CS_PIN &pin_PA27 - -// These are pins not to reset. -#define MICROPY_PORT_A (PORT_PA06) -#define MICROPY_PORT_B (0) -#define MICROPY_PORT_C (0) - -#define BOARD_HAS_CRYSTAL 1 - -#define DEFAULT_I2C_BUS_SCL (&pin_PA23) -#define DEFAULT_I2C_BUS_SDA (&pin_PA22) - -#define DEFAULT_SPI_BUS_SCK (&pin_PB11) -#define DEFAULT_SPI_BUS_MOSI (&pin_PB10) -#define DEFAULT_SPI_BUS_MISO (&pin_PA12) - -#define DEFAULT_UART_BUS_RX (&pin_PA11) -#define DEFAULT_UART_BUS_TX (&pin_PA10) - -// USB is always used internally so skip the pin objects for it. -#define IGNORE_PIN_PA24 1 -#define IGNORE_PIN_PA25 1 From bc95c7f2190939e43995d7bf331c66f08f11ef80 Mon Sep 17 00:00:00 2001 From: Hany Elkomy Date: Thu, 17 Dec 2020 17:08:52 +0800 Subject: [PATCH 51/70] Delete board.c --- .../boards/stackrduino_m0_pro/board.c | 37 ------------------- 1 file changed, 37 deletions(-) delete mode 100644 ports/atmel-samd/boards/stackrduino_m0_pro/board.c diff --git a/ports/atmel-samd/boards/stackrduino_m0_pro/board.c b/ports/atmel-samd/boards/stackrduino_m0_pro/board.c deleted file mode 100644 index 84960e73cf..0000000000 --- a/ports/atmel-samd/boards/stackrduino_m0_pro/board.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "supervisor/board.h" - -void board_init(void) { -} - -bool board_requests_safe_mode(void) { - return false; -} - -void reset_board(void) { -} From c6de41b4ea809770b3e19b6bbe017827ff7aa320 Mon Sep 17 00:00:00 2001 From: Hany Elkomy Date: Thu, 17 Dec 2020 17:14:49 +0800 Subject: [PATCH 52/70] Update build.yml added stackrduino_m0_pro board --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0edc8c023d..fff8e826fa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -301,6 +301,7 @@ jobs: - "sparkfun_samd21_mini" - "sparkfun_samd51_thing_plus" - "spresense" + - "stackrduino_m0_pro" - "stm32f411ce_blackpill" - "stm32f411ve_discovery" - "stm32f412zg_discovery" From 81ff95a8eb6364072113ba203131d897a9c7f171 Mon Sep 17 00:00:00 2001 From: Hany Elkomy Date: Thu, 17 Dec 2020 20:29:54 +0800 Subject: [PATCH 53/70] Add files via upload --- .../boards/stackrduino_m0_pro/board.c | 37 +++++++++++++++++ .../boards/stackrduino_m0_pro/mpconfigboard.h | 33 +++++++++++++++ .../stackrduino_m0_pro/mpconfigboard.mk | 25 ++++++++++++ .../boards/stackrduino_m0_pro/pins.c | 40 +++++++++++++++++++ 4 files changed, 135 insertions(+) create mode 100644 ports/atmel-samd/boards/stackrduino_m0_pro/board.c create mode 100644 ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.h create mode 100644 ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk create mode 100644 ports/atmel-samd/boards/stackrduino_m0_pro/pins.c diff --git a/ports/atmel-samd/boards/stackrduino_m0_pro/board.c b/ports/atmel-samd/boards/stackrduino_m0_pro/board.c new file mode 100644 index 0000000000..84960e73cf --- /dev/null +++ b/ports/atmel-samd/boards/stackrduino_m0_pro/board.c @@ -0,0 +1,37 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "supervisor/board.h" + +void board_init(void) { +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { +} diff --git a/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.h b/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.h new file mode 100644 index 0000000000..f0b2764a49 --- /dev/null +++ b/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.h @@ -0,0 +1,33 @@ +#define MICROPY_HW_BOARD_NAME "StackRduino M0 PRO" +#define MICROPY_HW_MCU_NAME "samd21g18" + +#define MICROPY_HW_LED_STATUS (&pin_PA17) +#define MICROPY_HW_NEOPIXEL (&pin_PA06) + +#define SPI_FLASH_BAUDRATE (8000000) + +#define SPI_FLASH_MOSI_PIN &pin_PB22 +#define SPI_FLASH_MISO_PIN &pin_PB03 +#define SPI_FLASH_SCK_PIN &pin_PB23 +#define SPI_FLASH_CS_PIN &pin_PA27 + +// These are pins not to reset. +#define MICROPY_PORT_A (PORT_PA06) +#define MICROPY_PORT_B (0) +#define MICROPY_PORT_C (0) + +#define BOARD_HAS_CRYSTAL 1 + +#define DEFAULT_I2C_BUS_SCL (&pin_PA23) +#define DEFAULT_I2C_BUS_SDA (&pin_PA22) + +#define DEFAULT_SPI_BUS_SCK (&pin_PB11) +#define DEFAULT_SPI_BUS_MOSI (&pin_PB10) +#define DEFAULT_SPI_BUS_MISO (&pin_PA12) + +#define DEFAULT_UART_BUS_RX (&pin_PA11) +#define DEFAULT_UART_BUS_TX (&pin_PA10) + +// USB is always used internally so skip the pin objects for it. +#define IGNORE_PIN_PA24 1 +#define IGNORE_PIN_PA25 1 diff --git a/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk b/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk new file mode 100644 index 0000000000..955f3d593b --- /dev/null +++ b/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk @@ -0,0 +1,25 @@ +USB_VID = 0x1209 +USB_PID = 0xE3E3 +USB_PRODUCT = "StackRduino M0 PRO" +USB_MANUFACTURER = "StackRduino" + +CHIP_VARIANT = SAMD21G18A +CHIP_FAMILY = samd21 + +SPI_FLASH_FILESYSTEM = 1 +EXTERNAL_FLASH_DEVICE_COUNT = 1 +EXTERNAL_FLASH_DEVICES = "W25Q64JV_IQ" +LONGINT_IMPL = MPZ + + +CIRCUITPY_BITBANGIO = 0 +CIRCUITPY_FREQUENCYIO = 0 +CIRCUITPY_COUNTIO = 0 +CIRCUITPY_I2CPERIPHERAL = 0 +CIRCUITPY_VECTORIO = 0 +CIRCUITPY_BUSDEVICE = 0 + +CFLAGS_INLINE_LIMIT = 60 +SUPEROPT_GC = 0 + +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel diff --git a/ports/atmel-samd/boards/stackrduino_m0_pro/pins.c b/ports/atmel-samd/boards/stackrduino_m0_pro/pins.c new file mode 100644 index 0000000000..95d2eb5a3d --- /dev/null +++ b/ports/atmel-samd/boards/stackrduino_m0_pro/pins.c @@ -0,0 +1,40 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_global_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PB08) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PB09) }, + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA04) }, + { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PA05) }, + { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PB02) }, + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PB11) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PB10) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA12) }, + { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA11) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PA11) }, + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PA10) }, + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PA10) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA22) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA23) }, + { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_PA08) }, + { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PA09) }, + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PA14) }, + { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PA15) }, + { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PA20) }, + { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_PA21) }, + { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PA07) }, + { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA18) }, + { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA16) }, + { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA19) }, + { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA17) }, + { MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_PA28) }, + { MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_PA28) }, + { MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_PA13) }, + { MP_ROM_QSTR(MP_QSTR_CHRG_EN), MP_ROM_PTR(&pin_PA13) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); From 06022a5e9145dbe5213802edbe6dd7a2b5ff5f81 Mon Sep 17 00:00:00 2001 From: Hany Elkomy Date: Thu, 17 Dec 2020 21:58:24 +0800 Subject: [PATCH 54/70] Update mpconfigboard.mk changed CFLAGS_INLINE_LIMIT = 55 --- ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk b/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk index 955f3d593b..4a8b85e2f3 100644 --- a/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk +++ b/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk @@ -19,7 +19,7 @@ CIRCUITPY_I2CPERIPHERAL = 0 CIRCUITPY_VECTORIO = 0 CIRCUITPY_BUSDEVICE = 0 -CFLAGS_INLINE_LIMIT = 60 +CFLAGS_INLINE_LIMIT = 55 SUPEROPT_GC = 0 FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel From 7afa1a1d766bb7fb8f4afe2c8d4de336e0be566c Mon Sep 17 00:00:00 2001 From: Hany Elkomy Date: Thu, 17 Dec 2020 22:47:01 +0800 Subject: [PATCH 55/70] Update mpconfigboard.mk reduced to CFLAGS_INLINE_LIMIT = 35 for tranaslations --- .../stackrduino_m0_pro/mpconfigboard.mk | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk b/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk index 4a8b85e2f3..704d265141 100644 --- a/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk +++ b/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk @@ -22,4 +22,37 @@ CIRCUITPY_BUSDEVICE = 0 CFLAGS_INLINE_LIMIT = 55 SUPEROPT_GC = 0 -FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel +CFLAGS_BOARD = --param max-inline-insns-auto=15 +ifeq ($(TRANSLATION), ja) +RELEASE_NEEDS_CLEAN_BUILD = 1 +CFLAGS_INLINE_LIMIT = 35 +endif +ifeq ($(TRANSLATION), zh_Latn_pinyin) +RELEASE_NEEDS_CLEAN_BUILD = 1 +CFLAGS_INLINE_LIMIT = 35 +endif +ifeq ($(TRANSLATION), de_DE) +RELEASE_NEEDS_CLEAN_BUILD = 1 +CFLAGS_INLINE_LIMIT = 35 +SUPEROPT_VM = 0 +endif +ifeq ($(TRANSLATION), pl) +RELEASE_NEEDS_CLEAN_BUILD = 1 +CFLAGS_INLINE_LIMIT = 35 +SUPEROPT_VM = 0 +endif +ifeq ($(TRANSLATION), fr) +RELEASE_NEEDS_CLEAN_BUILD = 1 +CFLAGS_INLINE_LIMIT = 35 +SUPEROPT_VM = 0 +endif +ifeq ($(TRANSLATION), pt_BR) +RELEASE_NEEDS_CLEAN_BUILD = 1 +CFLAGS_INLINE_LIMIT = 35 +SUPEROPT_VM = 0 +endif +ifeq ($(TRANSLATION), es) +RELEASE_NEEDS_CLEAN_BUILD = 1 +CFLAGS_INLINE_LIMIT = 35 +SUPEROPT_VM = 0 +endif From f224ed18488b1e92b6d13b09b696769a2ac380ce Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 17 Dec 2020 10:54:37 -0600 Subject: [PATCH 56/70] OnDiskBitmap: Correct handling of "0 color palette" images Microsoft documentation says: > If biCompression equals BI_RGB and the bitmap uses 8 bpp or less, the bitmap has a color table immediatelly following the BITMAPINFOHEADER structure. The color table consists of an array of RGBQUAD values. The size of the array is given by the biClrUsed member. If biClrUsed is zero, the array contains the maximum number of colors for the given bitdepth; that is, 2^biBitCount colors. Formerly, we treated 0 colors as "no image palette" during construction, but then during common_hal_displayio_ondiskbitmap_get_pixel indexed into the palette anyway. This could have unpredictable results. On a pygamer, it gave an image that was blue and black. On magtag, it gave a crash. --- shared-module/displayio/OnDiskBitmap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/shared-module/displayio/OnDiskBitmap.c b/shared-module/displayio/OnDiskBitmap.c index 993fc03de6..c1a0ddeb7e 100644 --- a/shared-module/displayio/OnDiskBitmap.c +++ b/shared-module/displayio/OnDiskBitmap.c @@ -57,7 +57,7 @@ void common_hal_displayio_ondiskbitmap_construct(displayio_ondiskbitmap_t *self, uint32_t compression = read_word(bmp_header, 15); uint32_t number_of_colors = read_word(bmp_header, 23); - bool indexed = ((bits_per_pixel <= 8) && (number_of_colors != 0)); + bool indexed = bits_per_pixel <= 8; self->bitfield_compressed = (compression == 3); self->bits_per_pixel = bits_per_pixel; self->width = read_word(bmp_header, 9); @@ -75,6 +75,9 @@ void common_hal_displayio_ondiskbitmap_construct(displayio_ondiskbitmap_t *self, self->b_bitmask = 0x1f; } } else if (indexed && self->bits_per_pixel != 1) { + if (number_of_colors == 0) { + number_of_colors = 1 << bits_per_pixel; + } uint16_t palette_size = number_of_colors * sizeof(uint32_t); uint16_t palette_offset = 0xe + header_size; From 4863413bc9aa3104f2c983efa43bf3afa028b80b Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Fri, 18 Dec 2020 00:34:56 +0530 Subject: [PATCH 57/70] rename ota to dualbank --- locale/circuitpython.pot | 20 ++-- .../common-hal/{ota => dualbank}/__init__.c | 65 ++++++------- .../common-hal/{ota => dualbank}/__init__.h | 8 +- ports/esp32s2/mpconfigport.mk | 2 +- ports/esp32s2/supervisor/port.c | 6 +- py/circuitpy_defns.mk | 6 +- py/circuitpy_mpconfig.h | 10 +- py/circuitpy_mpconfig.mk | 4 +- shared-bindings/{ota => dualbank}/__init__.c | 96 ++++++++----------- shared-bindings/{ota => dualbank}/__init__.h | 11 +-- 10 files changed, 102 insertions(+), 126 deletions(-) rename ports/esp32s2/common-hal/{ota => dualbank}/__init__.c (76%) rename ports/esp32s2/common-hal/{ota => dualbank}/__init__.h (84%) rename shared-bindings/{ota => dualbank}/__init__.c (55%) rename shared-bindings/{ota => dualbank}/__init__.h (78%) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 6ee4d816a5..d7f95091c8 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-12-10 16:56+0530\n" +"POT-Creation-Date: 2020-12-17 19:42+0530\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -936,6 +936,10 @@ msgstr "" msgid "Filters too complex" msgstr "" +#: ports/esp32s2/common-hal/dualbank/__init__.c +msgid "Firmware image is invalid" +msgstr "" + #: ports/cxd56/common-hal/camera/Camera.c msgid "Format not supported" msgstr "" @@ -1420,10 +1424,6 @@ msgstr "" msgid "Not settable" msgstr "" -#: ports/esp32s2/common-hal/ota/__init__.c -msgid "OTA Update Failed" -msgstr "" - #: shared-bindings/util.c msgid "" "Object has been deinitialized and can no longer be used. Create a new object." @@ -1911,10 +1911,6 @@ msgstr "" msgid "Unable to read color palette data" msgstr "" -#: ports/esp32s2/common-hal/ota/__init__.c -msgid "Unable to switch boot partition" -msgstr "" - #: shared-bindings/nvm/ByteArray.c msgid "Unable to write to nvm." msgstr "" @@ -1983,6 +1979,10 @@ msgstr "" msgid "Unsupported pull value." msgstr "" +#: ports/esp32s2/common-hal/dualbank/__init__.c +msgid "Update Failed" +msgstr "" + #: ports/nrf/common-hal/_bleio/Characteristic.c #: ports/nrf/common-hal/_bleio/Descriptor.c msgid "Value length != required fixed length" @@ -3210,7 +3210,7 @@ msgstr "" msgid "offset is too large" msgstr "" -#: shared-bindings/ota/__init__.c +#: shared-bindings/dualbank/__init__.c msgid "offset must be >= 0" msgstr "" diff --git a/ports/esp32s2/common-hal/ota/__init__.c b/ports/esp32s2/common-hal/dualbank/__init__.c similarity index 76% rename from ports/esp32s2/common-hal/ota/__init__.c rename to ports/esp32s2/common-hal/dualbank/__init__.c index 5ea25fb5d4..0f468a036b 100644 --- a/ports/esp32s2/common-hal/ota/__init__.c +++ b/ports/esp32s2/common-hal/dualbank/__init__.c @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#include "common-hal/ota/__init__.h" -#include "shared-bindings/ota/__init__.h" +#include "common-hal/dualbank/__init__.h" +#include "shared-bindings/dualbank/__init__.h" #include @@ -35,21 +35,24 @@ static const esp_partition_t *update_partition = NULL; static esp_ota_handle_t update_handle = 0; -static bool ota_inited = false; -static const char *TAG = "OTA"; +static const char *TAG = "dualbank"; -void ota_reset(void) { - update_handle = 0; - update_partition = NULL; - ota_inited = false; +void dualbank_reset(void) { + // should use `abort` instead of `end` + // but not in idf v4.2 + // esp_ota_abort(update_handle); + if (esp_ota_end(update_handle) == ESP_OK) { + update_handle = 0; + update_partition = NULL; + } } static void __attribute__((noreturn)) task_fatal_error(void) { ESP_LOGE(TAG, "Exiting task due to fatal error..."); - mp_raise_RuntimeError(translate("OTA Update Failed")); + mp_raise_RuntimeError(translate("Update Failed")); } -void common_hal_ota_flash(const void *buf, const size_t len, const int32_t offset) { +void common_hal_dualbank_flash(const void *buf, const size_t len, const size_t offset) { esp_err_t err; const esp_partition_t *running = esp_ota_get_running_partition(); @@ -67,7 +70,7 @@ void common_hal_ota_flash(const void *buf, const size_t len, const int32_t offse assert(update_partition != NULL); } - if (!ota_inited) { + if (update_handle == 0) { if (len > sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t) + sizeof(esp_app_desc_t)) { esp_app_desc_t new_app_info; memcpy(&new_app_info, &((char *)buf)[sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t)], sizeof(esp_app_desc_t)); @@ -102,14 +105,13 @@ void common_hal_ota_flash(const void *buf, const size_t len, const int32_t offse ESP_LOGE(TAG, "esp_ota_begin failed (%s)", esp_err_to_name(err)); task_fatal_error(); } - ota_inited = true; } else { ESP_LOGE(TAG, "received package is not fit len"); task_fatal_error(); } } - if (offset == -1) { + if (offset == 0) { err = esp_ota_write(update_handle, buf, len); } else { err = esp_ota_write_with_offset(update_handle, buf, len, offset); @@ -120,31 +122,18 @@ void common_hal_ota_flash(const void *buf, const size_t len, const int32_t offse } } -void common_hal_ota_finish(void) { - if (ota_inited) { - esp_err_t err; - - err = esp_ota_end(update_handle); - if (err != ESP_OK) { - if (err == ESP_ERR_OTA_VALIDATE_FAILED) { - ESP_LOGE(TAG, "Image validation failed, image is corrupted"); - } - ESP_LOGE(TAG, "esp_ota_end failed (%s)!", esp_err_to_name(err)); - task_fatal_error(); +void common_hal_dualbank_switch(void) { + if (esp_ota_end(update_handle) == ESP_OK) { + update_handle = 0; + update_partition = NULL; + } + esp_err_t err = esp_ota_set_boot_partition(esp_ota_get_next_update_partition(NULL)); + if (err != ESP_OK) { + if (err == ESP_ERR_OTA_VALIDATE_FAILED) { + ESP_LOGE(TAG, "Image validation failed, image is corrupted"); + mp_raise_RuntimeError(translate("Firmware image is invalid")); } - - err = esp_ota_set_boot_partition(update_partition); - if (err != ESP_OK) { - ESP_LOGE(TAG, "esp_ota_set_boot_partition failed (%s)!", esp_err_to_name(err)); - task_fatal_error(); - } - - ota_reset(); - } -} - -void common_hal_ota_switch(void) { - if (esp_ota_set_boot_partition(esp_ota_get_next_update_partition(NULL)) != ESP_OK) { - mp_raise_RuntimeError(translate("Unable to switch boot partition")); + ESP_LOGE(TAG, "esp_ota_set_boot_partition failed (%s)!", esp_err_to_name(err)); + task_fatal_error(); } } diff --git a/ports/esp32s2/common-hal/ota/__init__.h b/ports/esp32s2/common-hal/dualbank/__init__.h similarity index 84% rename from ports/esp32s2/common-hal/ota/__init__.h rename to ports/esp32s2/common-hal/dualbank/__init__.h index 983b57e3f2..8b18336c94 100644 --- a/ports/esp32s2/common-hal/ota/__init__.h +++ b/ports/esp32s2/common-hal/dualbank/__init__.h @@ -24,9 +24,9 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_ESP32S2_COMMON_HAL_OTA___INIT___H -#define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_OTA___INIT___H +#ifndef MICROPY_INCLUDED_ESP32S2_COMMON_HAL_DUALBANK___INIT___H +#define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_DUALBANK___INIT___H -extern void ota_reset(void); +extern void dualbank_reset(void); -#endif //MICROPY_INCLUDED_ESP32S2_COMMON_HAL_OTA___INIT___H +#endif //MICROPY_INCLUDED_ESP32S2_COMMON_HAL_DUALBANK___INIT___H diff --git a/ports/esp32s2/mpconfigport.mk b/ports/esp32s2/mpconfigport.mk index da231107fb..2ad8afb51c 100644 --- a/ports/esp32s2/mpconfigport.mk +++ b/ports/esp32s2/mpconfigport.mk @@ -19,11 +19,11 @@ CIRCUITPY_AUDIOBUSIO = 0 CIRCUITPY_AUDIOIO = 0 CIRCUITPY_CANIO = 1 CIRCUITPY_COUNTIO = 1 +CIRCUITPY_DUALBANK = 1 CIRCUITPY_FREQUENCYIO = 1 CIRCUITPY_I2CPERIPHERAL = 0 CIRCUITPY_ROTARYIO = 1 CIRCUITPY_NVM = 1 -CIRCUITPY_OTA = 1 # We don't have enough endpoints to include MIDI. CIRCUITPY_USB_MIDI = 0 CIRCUITPY_WIFI = 1 diff --git a/ports/esp32s2/supervisor/port.c b/ports/esp32s2/supervisor/port.c index 201d9962e2..a56ac61c81 100644 --- a/ports/esp32s2/supervisor/port.c +++ b/ports/esp32s2/supervisor/port.c @@ -41,7 +41,7 @@ #include "common-hal/busio/I2C.h" #include "common-hal/busio/SPI.h" #include "common-hal/busio/UART.h" -#include "common-hal/ota/__init__.h" +#include "common-hal/dualbank/__init__.h" #include "common-hal/ps2io/Ps2.h" #include "common-hal/pulseio/PulseIn.h" #include "common-hal/pwmio/PWMOut.h" @@ -124,8 +124,8 @@ void reset_port(void) { analogout_reset(); #endif -#if CIRCUITPY_OTA - ota_reset(); +#if CIRCUITPY_DUALBANK + dualbank_reset(); #endif #if CIRCUITPY_PS2IO diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 68e806d4b2..a871479141 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -205,8 +205,8 @@ endif ifeq ($(CIRCUITPY_OS),1) SRC_PATTERNS += os/% endif -ifeq ($(CIRCUITPY_OTA),1) -SRC_PATTERNS += ota/% +ifeq ($(CIRCUITPY_DUALBANK),1) +SRC_PATTERNS += dualbank/% endif ifeq ($(CIRCUITPY_PIXELBUF),1) SRC_PATTERNS += _pixelbuf/% @@ -350,7 +350,7 @@ SRC_COMMON_HAL_ALL = \ nvm/ByteArray.c \ nvm/__init__.c \ os/__init__.c \ - ota/__init__.c \ + dualbank/__init__.c \ ps2io/Ps2.c \ ps2io/__init__.c \ pulseio/PulseIn.c \ diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index 6a0daa7e9b..08c92a77ef 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -539,11 +539,11 @@ extern const struct _mp_obj_module_t os_module; #define OS_MODULE_ALT_NAME #endif -#if CIRCUITPY_OTA -extern const struct _mp_obj_module_t ota_module; -#define OTA_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_ota), (mp_obj_t)&ota_module }, +#if CIRCUITPY_DUALBANK +extern const struct _mp_obj_module_t dualbank_module; +#define DUALBANK_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_dualbank), (mp_obj_t)&dualbank_module }, #else -#define OTA_MODULE +#define DUALBANK_MODULE #endif #if CIRCUITPY_PEW @@ -834,7 +834,7 @@ extern const struct _mp_obj_module_t wifi_module; NETWORK_MODULE \ SOCKET_MODULE \ WIZNET_MODULE \ - OTA_MODULE \ + DUALBANK_MODULE \ PEW_MODULE \ PIXELBUF_MODULE \ PS2IO_MODULE \ diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index 09074bf53c..af1dccf024 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -179,8 +179,8 @@ CFLAGS += -DCIRCUITPY_NVM=$(CIRCUITPY_NVM) CIRCUITPY_OS ?= 1 CFLAGS += -DCIRCUITPY_OS=$(CIRCUITPY_OS) -CIRCUITPY_OTA ?= 0 -CFLAGS += -DCIRCUITPY_OTA=$(CIRCUITPY_OTA) +CIRCUITPY_DUALBANK ?= 0 +CFLAGS += -DCIRCUITPY_DUALBANK=$(CIRCUITPY_DUALBANK) CIRCUITPY_PIXELBUF ?= $(CIRCUITPY_FULL_BUILD) CFLAGS += -DCIRCUITPY_PIXELBUF=$(CIRCUITPY_PIXELBUF) diff --git a/shared-bindings/ota/__init__.c b/shared-bindings/dualbank/__init__.c similarity index 55% rename from shared-bindings/ota/__init__.c rename to shared-bindings/dualbank/__init__.c index 8ecc6d9c41..8021ab18b9 100644 --- a/shared-bindings/ota/__init__.c +++ b/shared-bindings/dualbank/__init__.c @@ -24,19 +24,20 @@ * THE SOFTWARE. */ -#include "shared-bindings/ota/__init__.h" +#include "shared-bindings/dualbank/__init__.h" -//| """OTA Module +//| """DUALBANK Module //| -//| The `ota` module implements over-the-air update. +//| The `dualbank` module adds ability to update and switch +//| between the two app partitions. //| -//| There are two identical ota partitions ota_0/1, these -//| contain different firmware versions. +//| There are two identical partitions, these contain different +//| firmware versions. //| Having two partitions enables rollback functionality. //| //| The two partitions are defined as boot partition and -//| next-update partition. Calling `ota.flash()` writes the -//| next-update partition. +//| next-update partition. Calling `dualbank.flash()` writes +//| the next-update partition. //| //| After the next-update partition is written a validation //| check is performed and on a successful validation this @@ -47,81 +48,68 @@ //| //| .. code-block:: python //| -//| import ota +//| import dualbank //| -//| ota.flash(buffer, offset) -//| ota.finish() +//| dualbank.flash(buffer, offset) +//| dualbank.switch() //| """ //| ... //| -//| def switch() -> None: -//| """Switches the boot partition. On next reset, -//| firmware will be loaded from the partition -//| just switched over to.""" -//| ... -//| -STATIC mp_obj_t ota_switch(void) { - common_hal_ota_switch(); - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_0(ota_switch_obj, ota_switch); - -//| def finish() -> None: -//| """Validates flashed firmware, sets next boot partition. -//| **Must be called** after the firmware has been -//| completely written into the flash using `ota.flash()`. -//| -//| This is to be called only once per update.""" -//| ... -//| -STATIC mp_obj_t ota_finish(void) { - common_hal_ota_finish(); - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_0(ota_finish_obj, ota_finish); - //| def flash(*buffer: ReadableBuffer, offset: int=0) -> None: -//| """Writes one of two OTA partitions at the given offset. -//| -//| The default offset is 0. It is necessary to provide the -//| offset when writing in discontinous chunks. +//| """Writes one of two app partitions at the given offset. //| //| This can be called multiple times when flashing the firmware -//| in small chunks.""" +//| in small chunks. +//| """ //| ... //| -STATIC mp_obj_t ota_flash(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t dualbank_flash(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_buffer, ARG_offset }; static const mp_arg_t allowed_args[] = { { MP_QSTR_buffer, MP_ARG_OBJ | MP_ARG_REQUIRED }, - { MP_QSTR_offset, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} }, + { MP_QSTR_offset, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - if (args[ARG_offset].u_int < -1) { + if (args[ARG_offset].u_int < 0) { mp_raise_ValueError(translate("offset must be >= 0")); } mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_READ); - common_hal_ota_flash(bufinfo.buf, bufinfo.len, args[ARG_offset].u_int); + common_hal_dualbank_flash(bufinfo.buf, bufinfo.len, args[ARG_offset].u_int); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ota_flash_obj, 0, ota_flash); +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(dualbank_flash_obj, 0, dualbank_flash); -STATIC const mp_rom_map_elem_t ota_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ota) }, - { MP_ROM_QSTR(MP_QSTR_switch), MP_ROM_PTR(&ota_switch_obj) }, - { MP_ROM_QSTR(MP_QSTR_finish), MP_ROM_PTR(&ota_finish_obj) }, - { MP_ROM_QSTR(MP_QSTR_flash), MP_ROM_PTR(&ota_flash_obj) }, +//| def switch() -> None: +//| """Switches the boot partition. +//| +//| On next reset, firmware will be loaded from the partition +//| just switched over to. +//| """ +//| ... +//| +STATIC mp_obj_t dualbank_switch(void) { + common_hal_dualbank_switch(); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(dualbank_switch_obj, dualbank_switch); + +STATIC const mp_rom_map_elem_t dualbank_module_globals_table[] = { + // module name + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_dualbank) }, + // module functions + { MP_ROM_QSTR(MP_QSTR_flash), MP_ROM_PTR(&dualbank_flash_obj) }, + { MP_ROM_QSTR(MP_QSTR_switch), MP_ROM_PTR(&dualbank_switch_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(ota_module_globals, ota_module_globals_table); +STATIC MP_DEFINE_CONST_DICT(dualbank_module_globals, dualbank_module_globals_table); -const mp_obj_module_t ota_module = { +const mp_obj_module_t dualbank_module = { .base = { &mp_type_module }, - .globals = (mp_obj_dict_t*)&ota_module_globals, + .globals = (mp_obj_dict_t*)&dualbank_module_globals, }; diff --git a/shared-bindings/ota/__init__.h b/shared-bindings/dualbank/__init__.h similarity index 78% rename from shared-bindings/ota/__init__.h rename to shared-bindings/dualbank/__init__.h index 82273f975a..7edbc6d68a 100644 --- a/shared-bindings/ota/__init__.h +++ b/shared-bindings/dualbank/__init__.h @@ -24,13 +24,12 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_OTA___INIT___H -#define MICROPY_INCLUDED_SHARED_BINDINGS_OTA___INIT___H +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_DUALBANK___INIT___H +#define MICROPY_INCLUDED_SHARED_BINDINGS_DUALBANK___INIT___H #include "py/runtime.h" -extern void common_hal_ota_switch(void); -extern void common_hal_ota_finish(void); -extern void common_hal_ota_flash(const void *buf, const size_t len, const int32_t offset); +extern void common_hal_dualbank_switch(void); +extern void common_hal_dualbank_flash(const void *buf, const size_t len, const size_t offset); -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_OTA___INIT___H +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DUALBANK___INIT___H From 6c4df5a8b45c6b20e00b5499c5db1d4f5da444a2 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Fri, 18 Dec 2020 11:13:28 -0600 Subject: [PATCH 58/70] adafruit_bus_device: Don't transmit STOP condition in write_then_readinto Closes #3795 --- shared-bindings/adafruit_bus_device/I2CDevice.c | 8 ++++---- shared-bindings/adafruit_bus_device/I2CDevice.h | 2 +- shared-module/adafruit_bus_device/I2CDevice.c | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/shared-bindings/adafruit_bus_device/I2CDevice.c b/shared-bindings/adafruit_bus_device/I2CDevice.c index 4c9086162d..a4c04e198c 100644 --- a/shared-bindings/adafruit_bus_device/I2CDevice.c +++ b/shared-bindings/adafruit_bus_device/I2CDevice.c @@ -163,7 +163,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(adafruit_bus_device_i2cdevice_readinto_obj, 2, //| """ //| ... //| -STATIC void write(adafruit_bus_device_i2cdevice_obj_t *self, mp_obj_t buffer, int32_t start, mp_int_t end) { +STATIC void write(adafruit_bus_device_i2cdevice_obj_t *self, mp_obj_t buffer, int32_t start, mp_int_t end, bool transmit_stop_bit) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(buffer, &bufinfo, MP_BUFFER_READ); @@ -173,7 +173,7 @@ STATIC void write(adafruit_bus_device_i2cdevice_obj_t *self, mp_obj_t buffer, in mp_raise_ValueError(translate("Buffer must be at least length 1")); } - uint8_t status = common_hal_adafruit_bus_device_i2cdevice_write(MP_OBJ_TO_PTR(self), ((uint8_t*)bufinfo.buf) + start, length); + uint8_t status = common_hal_adafruit_bus_device_i2cdevice_write(MP_OBJ_TO_PTR(self), ((uint8_t*)bufinfo.buf) + start, length, transmit_stop_bit); if (status != 0) { mp_raise_OSError(status); } @@ -191,7 +191,7 @@ STATIC mp_obj_t adafruit_bus_device_i2cdevice_write(size_t n_args, const mp_obj_ mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - write(self, args[ARG_buffer].u_obj, args[ARG_start].u_int, args[ARG_end].u_int); + write(self, args[ARG_buffer].u_obj, args[ARG_start].u_int, args[ARG_end].u_int, true); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_KW(adafruit_bus_device_i2cdevice_write_obj, 2, adafruit_bus_device_i2cdevice_write); @@ -233,7 +233,7 @@ STATIC mp_obj_t adafruit_bus_device_i2cdevice_write_then_readinto(size_t n_args, mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - write(self, args[ARG_out_buffer].u_obj, args[ARG_out_start].u_int, args[ARG_out_end].u_int); + write(self, args[ARG_out_buffer].u_obj, args[ARG_out_start].u_int, args[ARG_out_end].u_int, false); readinto(self, args[ARG_in_buffer].u_obj, args[ARG_in_start].u_int, args[ARG_in_end].u_int); diff --git a/shared-bindings/adafruit_bus_device/I2CDevice.h b/shared-bindings/adafruit_bus_device/I2CDevice.h index 7b2182ff03..cf7b1321a0 100644 --- a/shared-bindings/adafruit_bus_device/I2CDevice.h +++ b/shared-bindings/adafruit_bus_device/I2CDevice.h @@ -45,7 +45,7 @@ extern const mp_obj_type_t adafruit_bus_device_i2cdevice_type; // Initializes the hardware peripheral. extern void common_hal_adafruit_bus_device_i2cdevice_construct(adafruit_bus_device_i2cdevice_obj_t *self, busio_i2c_obj_t *i2c, uint8_t device_address); extern uint8_t common_hal_adafruit_bus_device_i2cdevice_readinto(adafruit_bus_device_i2cdevice_obj_t *self, mp_obj_t buffer, size_t length); -extern uint8_t common_hal_adafruit_bus_device_i2cdevice_write(adafruit_bus_device_i2cdevice_obj_t *self, mp_obj_t buffer, size_t length); +extern uint8_t common_hal_adafruit_bus_device_i2cdevice_write(adafruit_bus_device_i2cdevice_obj_t *self, mp_obj_t buffer, size_t length, bool transmit_stop_bit); extern void common_hal_adafruit_bus_device_i2cdevice_lock(adafruit_bus_device_i2cdevice_obj_t *self); extern void common_hal_adafruit_bus_device_i2cdevice_unlock(adafruit_bus_device_i2cdevice_obj_t *self); extern void common_hal_adafruit_bus_device_i2cdevice_probe_for_device(adafruit_bus_device_i2cdevice_obj_t *self); diff --git a/shared-module/adafruit_bus_device/I2CDevice.c b/shared-module/adafruit_bus_device/I2CDevice.c index ee4b4fa554..83abe80d64 100644 --- a/shared-module/adafruit_bus_device/I2CDevice.c +++ b/shared-module/adafruit_bus_device/I2CDevice.c @@ -57,8 +57,8 @@ uint8_t common_hal_adafruit_bus_device_i2cdevice_readinto(adafruit_bus_device_i2 return common_hal_busio_i2c_read(self->i2c, self->device_address, buffer, length); } -uint8_t common_hal_adafruit_bus_device_i2cdevice_write(adafruit_bus_device_i2cdevice_obj_t *self, mp_obj_t buffer, size_t length) { - return common_hal_busio_i2c_write(self->i2c, self->device_address, buffer, length, true); +uint8_t common_hal_adafruit_bus_device_i2cdevice_write(adafruit_bus_device_i2cdevice_obj_t *self, mp_obj_t buffer, size_t length, bool transmit_stop_bit) { + return common_hal_busio_i2c_write(self->i2c, self->device_address, buffer, length, transmit_stop_bit); } void common_hal_adafruit_bus_device_i2cdevice_probe_for_device(adafruit_bus_device_i2cdevice_obj_t *self) { From 88b1e2fe61d68c4a4d2ef9e48147c20a929e779e Mon Sep 17 00:00:00 2001 From: sabas1080 Date: Sun, 20 Dec 2020 13:35:15 -0600 Subject: [PATCH 59/70] remove Internal flash unnecessary --- ports/nrf/boards/bastble/mpconfigboard.mk | 2 -- ports/nrf/boards/bastble/pins.c | 1 - 2 files changed, 3 deletions(-) diff --git a/ports/nrf/boards/bastble/mpconfigboard.mk b/ports/nrf/boards/bastble/mpconfigboard.mk index 0e01c4d0f3..eca900de77 100644 --- a/ports/nrf/boards/bastble/mpconfigboard.mk +++ b/ports/nrf/boards/bastble/mpconfigboard.mk @@ -5,8 +5,6 @@ USB_MANUFACTURER = "ElectronicCats" MCU_CHIP = nrf52840 -INTERNAL_FLASH_FILESYSTEM = 1 - QSPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICE_COUNT = 1 EXTERNAL_FLASH_DEVICES = "GD25Q16C" diff --git a/ports/nrf/boards/bastble/pins.c b/ports/nrf/boards/bastble/pins.c index 6e4cc511b0..b35dad43de 100644 --- a/ports/nrf/boards/bastble/pins.c +++ b/ports/nrf/boards/bastble/pins.c @@ -36,7 +36,6 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { // voltage sense battery { MP_ROM_QSTR(MP_QSTR_VBAT), MP_ROM_PTR(&pin_P0_26) }, - { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_P0_10) }, { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_P0_09) }, From bd3c5c33fb0d49f420410e3a949a093d235db81c Mon Sep 17 00:00:00 2001 From: sabas1080 Date: Sun, 20 Dec 2020 14:57:10 -0600 Subject: [PATCH 60/70] define QSPI pinout --- ports/nrf/boards/bastble/mpconfigboard.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ports/nrf/boards/bastble/mpconfigboard.h b/ports/nrf/boards/bastble/mpconfigboard.h index 67a62e915b..e36227c6bc 100644 --- a/ports/nrf/boards/bastble/mpconfigboard.h +++ b/ports/nrf/boards/bastble/mpconfigboard.h @@ -5,6 +5,15 @@ #define CIRCUITPY_AUTORELOAD_DELAY_MS 500 +#if QSPI_FLASH_FILESYSTEM +#define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(0, 30) +#define MICROPY_QSPI_DATA1 NRF_GPIO_PIN_MAP(0, 29) +#define MICROPY_QSPI_DATA2 NRF_GPIO_PIN_MAP(0, 28) +#define MICROPY_QSPI_DATA3 NRF_GPIO_PIN_MAP(0, 2) +#define MICROPY_QSPI_SCK NRF_GPIO_PIN_MAP(0, 3) +#define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(0, 26) +#endif + #define DEFAULT_I2C_BUS_SCL (&pin_P1_10) #define DEFAULT_I2C_BUS_SDA (&pin_P1_11) From d24a5d62700252a49152ed2bc6af0b9b3025344e Mon Sep 17 00:00:00 2001 From: sabas1080 Date: Sun, 20 Dec 2020 15:52:19 -0600 Subject: [PATCH 61/70] update path board.h --- ports/nrf/boards/bastble/board.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/nrf/boards/bastble/board.c b/ports/nrf/boards/bastble/board.c index 7c42cee57d..b6fb04f06c 100644 --- a/ports/nrf/boards/bastble/board.c +++ b/ports/nrf/boards/bastble/board.c @@ -24,7 +24,7 @@ * THE SOFTWARE. */ -#include "boards/board.h" +#include "supervisor/board.h" #include "nrf.h" #include "nrf_rtc.h" From 3b4c14f3ec8b36a00a7eeba562baa7647b82f2e2 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 21 Dec 2020 20:43:46 -0500 Subject: [PATCH 62/70] unmounted filesystems start as ejected --- supervisor/shared/usb/usb_msc_flash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supervisor/shared/usb/usb_msc_flash.c b/supervisor/shared/usb/usb_msc_flash.c index b39f60dcd2..7532b6aead 100644 --- a/supervisor/shared/usb/usb_msc_flash.c +++ b/supervisor/shared/usb/usb_msc_flash.c @@ -39,7 +39,7 @@ #define MSC_FLASH_BLOCK_SIZE 512 -static bool ejected[1] = {false}; +static bool ejected[1] = {true}; void usb_msc_mount(void) { // Reset the ejection tracking every time we're plugged into USB. This allows for us to battery From 39ca406a31f630f9e169ab18ce2fa223aa60077a Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 21 Dec 2020 23:32:11 -0500 Subject: [PATCH 63/70] Add Adafruit to MICROPY_HW_BOARD_NAME for various boards --- .../boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h | 2 +- ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h | 2 +- ports/mimxrt10xx/boards/feather_m7_1011/mpconfigboard.h | 2 +- ports/stm/boards/feather_stm32f405_express/mpconfigboard.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h b/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h index be376e5a94..8dfe912712 100644 --- a/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h +++ b/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h @@ -26,7 +26,7 @@ //Micropython setup -#define MICROPY_HW_BOARD_NAME "MagTag" +#define MICROPY_HW_BOARD_NAME "Adafruit MagTag" #define MICROPY_HW_MCU_NAME "ESP32S2" #define MICROPY_HW_NEOPIXEL (&pin_GPIO1) diff --git a/ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h b/ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h index 7280aab9c2..b25d7d1169 100644 --- a/ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h +++ b/ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h @@ -26,7 +26,7 @@ //Micropython setup -#define MICROPY_HW_BOARD_NAME "Metro ESP32S2" +#define MICROPY_HW_BOARD_NAME "Adafruit Metro ESP32S2" #define MICROPY_HW_MCU_NAME "ESP32S2" #define MICROPY_HW_NEOPIXEL (&pin_GPIO45) diff --git a/ports/mimxrt10xx/boards/feather_m7_1011/mpconfigboard.h b/ports/mimxrt10xx/boards/feather_m7_1011/mpconfigboard.h index e96ec13dd9..e027e2b5ee 100644 --- a/ports/mimxrt10xx/boards/feather_m7_1011/mpconfigboard.h +++ b/ports/mimxrt10xx/boards/feather_m7_1011/mpconfigboard.h @@ -1,4 +1,4 @@ -#define MICROPY_HW_BOARD_NAME "Feather MIMXRT1011" +#define MICROPY_HW_BOARD_NAME "Adafruit Feather MIMXRT1011" #define MICROPY_HW_MCU_NAME "IMXRT1011DAE5A" #define MICROPY_HW_NEOPIXEL (&pin_GPIO_00) diff --git a/ports/stm/boards/feather_stm32f405_express/mpconfigboard.h b/ports/stm/boards/feather_stm32f405_express/mpconfigboard.h index 0d49748c84..e69be6cf95 100644 --- a/ports/stm/boards/feather_stm32f405_express/mpconfigboard.h +++ b/ports/stm/boards/feather_stm32f405_express/mpconfigboard.h @@ -26,7 +26,7 @@ //Micropython setup -#define MICROPY_HW_BOARD_NAME "Feather STM32F405 Express" +#define MICROPY_HW_BOARD_NAME "Adafruit Feather STM32F405 Express" #define MICROPY_HW_MCU_NAME "STM32F405RG" #define FLASH_SIZE (0x100000) From 17e7973ff2028536034c8c8898044ac93fa10b51 Mon Sep 17 00:00:00 2001 From: Jonathan Giles Date: Mon, 21 Dec 2020 08:38:37 -0500 Subject: [PATCH 64/70] Add support for Winbond W25Q64FV --- supervisor/shared/external_flash/devices.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/supervisor/shared/external_flash/devices.h b/supervisor/shared/external_flash/devices.h index 466ab49eb8..be18647953 100644 --- a/supervisor/shared/external_flash/devices.h +++ b/supervisor/shared/external_flash/devices.h @@ -363,6 +363,24 @@ typedef struct { .write_status_register_split = false, \ } +// Settings for the Winbond W25Q64FV 8MiB SPI flash. +// Datasheet: https://www.winbond.com/resource-files/w25q64fv%20revs%2007182017.pdf +#define W25Q64FV {\ + .total_size = (1 << 23), /* 8 MiB */ \ + .start_up_time_us = 5000, \ + .manufacturer_id = 0xef, \ + .memory_type = 0x40, \ + .capacity = 0x17, \ + .max_clock_speed_mhz = 104, \ + .quad_enable_bit_mask = 0x02, \ + .has_sector_protection = false, \ + .supports_fast_read = true, \ + .supports_qspi = true, \ + .supports_qspi_writes = true, \ + .write_status_register_split = false, \ + .single_status_byte = false, \ +} + // Settings for the Winbond W25Q64JV-IM 8MiB SPI flash. Note that JV-IQ has a different .memory_type (0x40) // Datasheet: http://www.winbond.com/resource-files/w25q64jv%20revj%2003272018%20plus.pdf #define W25Q64JV_IM {\ From aaa3c61819bc0c819df88df00d6fe8b52d677356 Mon Sep 17 00:00:00 2001 From: Jonathan Giles Date: Tue, 22 Dec 2020 09:07:50 -0500 Subject: [PATCH 65/70] Add default I2C pins for STM32F411CE --- ports/stm/boards/stm32f411ce_blackpill/mpconfigboard.h | 3 +++ ports/stm/boards/stm32f411ce_blackpill/pins.c | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/ports/stm/boards/stm32f411ce_blackpill/mpconfigboard.h b/ports/stm/boards/stm32f411ce_blackpill/mpconfigboard.h index 83a8bded39..4351339540 100644 --- a/ports/stm/boards/stm32f411ce_blackpill/mpconfigboard.h +++ b/ports/stm/boards/stm32f411ce_blackpill/mpconfigboard.h @@ -42,6 +42,9 @@ // #define SPI_FLASH_SCK_PIN (&pin_PA05) // #define SPI_FLASH_CS_PIN (&pin_PA04) +#define DEFAULT_I2C_BUS_SCL (&pin_PB06) +#define DEFAULT_I2C_BUS_SDA (&pin_PB07) + #define CIRCUITPY_AUTORELOAD_DELAY_MS (500) #define BOARD_FLASH_SIZE (FLASH_SIZE - 0x2000 - 0xC000) diff --git a/ports/stm/boards/stm32f411ce_blackpill/pins.c b/ports/stm/boards/stm32f411ce_blackpill/pins.c index 2f8aab6e8e..16946b8bee 100644 --- a/ports/stm/boards/stm32f411ce_blackpill/pins.c +++ b/ports/stm/boards/stm32f411ce_blackpill/pins.c @@ -35,5 +35,10 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_C14), MP_ROM_PTR(&pin_PC14) }, { MP_ROM_QSTR(MP_QSTR_C13), MP_ROM_PTR(&pin_PC13) }, { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_PC13) }, + + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PB07) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PB06) }, + + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); From da8f02366544d3a9fd5553c52f592a5fa7d74305 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 22 Dec 2020 10:27:42 -0600 Subject: [PATCH 66/70] esp32s2: make flash: use the stub Very long ago, this was apparently not supported in esptool yet, at least when operating over USB CDC. This now works just fine, and our esp webtool relies on it as well. It makes flashing faster, too. --- ports/esp32s2/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/esp32s2/Makefile b/ports/esp32s2/Makefile index 35f82dd8a1..4334e6b10e 100644 --- a/ports/esp32s2/Makefile +++ b/ports/esp32s2/Makefile @@ -338,10 +338,10 @@ $(BUILD)/firmware.uf2: $(BUILD)/circuitpython-firmware.bin $(Q)$(PYTHON3) $(TOP)/tools/uf2/utils/uf2conv.py -f 0xbfdd4eee -b 0x0000 -c -o $@ $^ flash: $(BUILD)/firmware.bin - esptool.py --chip esp32s2 -p $(PORT) --no-stub -b 460800 --before=default_reset --after=no_reset write_flash $(FLASH_FLAGS) 0x0000 $^ + esptool.py --chip esp32s2 -p $(PORT) -b 460800 --before=default_reset --after=no_reset write_flash $(FLASH_FLAGS) 0x0000 $^ flash-circuitpython-only: $(BUILD)/circuitpython-firmware.bin - esptool.py --chip esp32s2 -p $(PORT) --no-stub -b 460800 --before=default_reset --after=no_reset write_flash $(FLASH_FLAGS) 0x10000 $^ + esptool.py --chip esp32s2 -p $(PORT) -b 460800 --before=default_reset --after=no_reset write_flash $(FLASH_FLAGS) 0x10000 $^ include $(TOP)/py/mkrules.mk From 89079039adadac7c73fe03892ac2114dcc567429 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 22 Dec 2020 18:54:42 -0500 Subject: [PATCH 67/70] FrequencyIn: do not raise in interrupt handler --- ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c b/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c index 02d0482dca..f973db90b0 100644 --- a/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +++ b/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c @@ -82,7 +82,8 @@ void frequencyin_emergency_cancel_capture(uint8_t index) { #ifdef SAM_D5X_E5X NVIC_EnableIRQ(EIC_0_IRQn + self->channel); #endif - mp_raise_RuntimeError(translate("Frequency captured is above capability. Capture Paused.")); + // Frequency captured is above capability. Capture paused. + // We can't raise an error here; we're in an interrupt handler. } void frequencyin_interrupt_handler(uint8_t index) { From 42a229c08b6b5d64af8d4bc5ec99f3e285befd14 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 23 Dec 2020 10:43:04 -0600 Subject: [PATCH 68/70] circuitpy_mpconfig.mk: Unconditionally disable CIRCUITPY_BUSDEVICE Several issues have been found in the implementation. While they're unresolved, it may be better to disable the built-in module. (This means that to work on fixing the module, it'll be necessary to revert this commit) --- py/circuitpy_mpconfig.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index af1dccf024..e588c41e0d 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -96,7 +96,7 @@ CFLAGS += -DCIRCUITPY_BLEIO=$(CIRCUITPY_BLEIO) CIRCUITPY_BOARD ?= 1 CFLAGS += -DCIRCUITPY_BOARD=$(CIRCUITPY_BOARD) -CIRCUITPY_BUSDEVICE ?= $(CIRCUITPY_FULL_BUILD) +CIRCUITPY_BUSDEVICE = 0 CFLAGS += -DCIRCUITPY_BUSDEVICE=$(CIRCUITPY_BUSDEVICE) CIRCUITPY_BUILTINS_POW3 ?= $(CIRCUITPY_FULL_BUILD) From a11ad2572761bc4900994fbf42361efb387cd059 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 21 Dec 2020 22:58:17 -0500 Subject: [PATCH 69/70] BLE fixes --- ports/nrf/common-hal/_bleio/Adapter.c | 11 ++++++++++- shared-bindings/_bleio/Adapter.c | 13 ++++++++++--- shared-bindings/_bleio/Characteristic.c | 4 ++-- shared-bindings/_bleio/Descriptor.c | 4 ++-- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/ports/nrf/common-hal/_bleio/Adapter.c b/ports/nrf/common-hal/_bleio/Adapter.c index 537f43f237..53a40f9a67 100644 --- a/ports/nrf/common-hal/_bleio/Adapter.c +++ b/ports/nrf/common-hal/_bleio/Adapter.c @@ -470,7 +470,16 @@ mp_obj_t common_hal_bleio_adapter_start_scan(bleio_adapter_obj_t *self, uint8_t* ble_drv_add_event_handler(scan_on_ble_evt, self->scan_results); uint32_t nrf_timeout = SEC_TO_UNITS(timeout, UNIT_10_MS); - if (timeout <= 0.0001) { + if (nrf_timeout > UINT16_MAX) { + // 0xffff / 100 + mp_raise_ValueError(translate("timeout must be < 655.35 secs")); + } + if (nrf_timeout == 0 && timeout > 0.0f) { + // Make sure converted timeout is > 0 if original timeout is > 0. + mp_raise_ValueError(translate("non-zero timeout must be > 0.01")); + } + + if (nrf_timeout) { nrf_timeout = BLE_GAP_SCAN_TIMEOUT_UNLIMITED; } diff --git a/shared-bindings/_bleio/Adapter.c b/shared-bindings/_bleio/Adapter.c index 682177093d..7d7076aab6 100644 --- a/shared-bindings/_bleio/Adapter.c +++ b/shared-bindings/_bleio/Adapter.c @@ -33,8 +33,8 @@ #include "shared-bindings/_bleio/Address.h" #include "shared-bindings/_bleio/Adapter.h" -#define ADV_INTERVAL_MIN (0.0020f) -#define ADV_INTERVAL_MIN_STRING "0.0020" +#define ADV_INTERVAL_MIN (0.02001f) +#define ADV_INTERVAL_MIN_STRING "0.02001" #define ADV_INTERVAL_MAX (10.24f) #define ADV_INTERVAL_MAX_STRING "10.24" // 20ms is recommended by Apple @@ -307,7 +307,7 @@ STATIC mp_obj_t bleio_adapter_start_scan(size_t n_args, const mp_obj_t *pos_args mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - mp_float_t timeout = 0; + mp_float_t timeout = 0.0f; if (args[ARG_timeout].u_obj != mp_const_none) { timeout = mp_obj_get_float(args[ARG_timeout].u_obj); } @@ -325,6 +325,13 @@ STATIC mp_obj_t bleio_adapter_start_scan(size_t n_args, const mp_obj_t *pos_args mp_raise_ValueError_varg(translate("interval must be in range %s-%s"), INTERVAL_MIN_STRING, INTERVAL_MAX_STRING); } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wfloat-equal" + if (timeout != 0.0f && timeout < interval) { + mp_raise_ValueError(translate("non-zero timeout must be >= interval")); + } +#pragma GCC diagnostic pop + const mp_float_t window = mp_obj_float_get(args[ARG_window].u_obj); if (window > interval) { mp_raise_ValueError(translate("window must be <= interval")); diff --git a/shared-bindings/_bleio/Characteristic.c b/shared-bindings/_bleio/Characteristic.c index 5e384a44ca..a0751b7e34 100644 --- a/shared-bindings/_bleio/Characteristic.c +++ b/shared-bindings/_bleio/Characteristic.c @@ -110,8 +110,8 @@ STATIC mp_obj_t bleio_characteristic_add_to_service(size_t n_args, const mp_obj_ common_hal_bleio_attribute_security_mode_check_valid(write_perm); const mp_int_t max_length_int = args[ARG_max_length].u_int; - if (max_length_int <= 0) { - mp_raise_ValueError(translate("max_length must be > 0")); + if (max_length_int < 0) { + mp_raise_ValueError(translate("max_length must be >= 0")); } const size_t max_length = (size_t) max_length_int; const bool fixed_length = args[ARG_fixed_length].u_bool; diff --git a/shared-bindings/_bleio/Descriptor.c b/shared-bindings/_bleio/Descriptor.c index c313007c6d..60f0acf44b 100644 --- a/shared-bindings/_bleio/Descriptor.c +++ b/shared-bindings/_bleio/Descriptor.c @@ -101,8 +101,8 @@ STATIC mp_obj_t bleio_descriptor_add_to_characteristic(size_t n_args, const mp_o common_hal_bleio_attribute_security_mode_check_valid(write_perm); const mp_int_t max_length_int = args[ARG_max_length].u_int; - if (max_length_int <= 0) { - mp_raise_ValueError(translate("max_length must be > 0")); + if (max_length_int < 0) { + mp_raise_ValueError(translate("max_length must be >= 0")); } const size_t max_length = (size_t) max_length_int; const bool fixed_length = args[ARG_fixed_length].u_bool; From 153a686837638ce8722769156610313efca0e559 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 23 Dec 2020 16:41:56 -0500 Subject: [PATCH 70/70] make translate for main --- locale/circuitpython.pot | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index e44892fc3b..4a25ec4853 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-12-14 12:59-0500\n" +"POT-Creation-Date: 2020-12-23 16:41-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -949,10 +949,6 @@ msgstr "" msgid "Framebuffer requires %d bytes" msgstr "" -#: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c -msgid "Frequency captured is above capability. Capture Paused." -msgstr "" - #: ports/stm/common-hal/pwmio/PWMOut.c msgid "Frequency must match existing PWMOut using this timer" msgstr "" @@ -3009,7 +3005,7 @@ msgid "max_length must be 0-%d when fixed_length is %s" msgstr "" #: shared-bindings/_bleio/Characteristic.c shared-bindings/_bleio/Descriptor.c -msgid "max_length must be > 0" +msgid "max_length must be >= 0" msgstr "" #: extmod/ulab/code/ndarray.c @@ -3147,6 +3143,14 @@ msgstr "" msgid "non-keyword arg after keyword arg" msgstr "" +#: ports/nrf/common-hal/_bleio/Adapter.c +msgid "non-zero timeout must be > 0.01" +msgstr "" + +#: shared-bindings/_bleio/Adapter.c +msgid "non-zero timeout must be >= interval" +msgstr "" + #: extmod/ulab/code/linalg/linalg.c msgid "norm is defined for 1D and 2D arrays" msgstr "" @@ -3568,6 +3572,10 @@ msgstr "" msgid "timeout must be 0.0-100.0 seconds" msgstr "" +#: ports/nrf/common-hal/_bleio/Adapter.c +msgid "timeout must be < 655.35 secs" +msgstr "" + #: shared-bindings/_bleio/CharacteristicBuffer.c msgid "timeout must be >= 0.0" msgstr ""