From edd04ffcdbf29977df70ff7b071acaa95a27b956 Mon Sep 17 00:00:00 2001 From: Martin Milata Date: Tue, 27 Oct 2020 13:24:24 +0100 Subject: [PATCH 01/22] gc: add optional allocation counter (#3) Co-authored-by: matejcik --- py/gc.c | 8 ++++++++ py/gc.h | 4 ++++ py/modmicropython.c | 10 ++++++++++ py/mpconfig.h | 5 +++++ 4 files changed, 27 insertions(+) diff --git a/py/gc.c b/py/gc.c index 5fe26ef8905..ac76b4b93e2 100644 --- a/py/gc.c +++ b/py/gc.c @@ -38,6 +38,10 @@ #if MICROPY_ENABLE_GC +#if MICROPY_TREZOR_MEMPERF +size_t alloc_count = 0; +#endif + #if MICROPY_DEBUG_VERBOSE // print debugging info #define DEBUG_PRINT (1) #define DEBUG_printf DEBUG_printf @@ -998,6 +1002,10 @@ void *gc_alloc(size_t n_bytes, unsigned int alloc_flags) { gc_dump_alloc_table(&mp_plat_print); #endif + #if MICROPY_TREZOR_MEMPERF + ++alloc_count; + #endif + return ret_ptr; } diff --git a/py/gc.h b/py/gc.h index 4679d6dc863..1e361d733e5 100644 --- a/py/gc.h +++ b/py/gc.h @@ -89,4 +89,8 @@ void gc_info(gc_info_t *info); void gc_dump_info(const mp_print_t *print); void gc_dump_alloc_table(const mp_print_t *print); +#if MICROPY_TREZOR_MEMPERF +extern size_t alloc_count; +#endif + #endif // MICROPY_INCLUDED_PY_GC_H diff --git a/py/modmicropython.c b/py/modmicropython.c index 4d676cb4ab2..eae3a4418c8 100644 --- a/py/modmicropython.c +++ b/py/modmicropython.c @@ -166,6 +166,13 @@ static mp_obj_t mp_micropython_schedule(mp_obj_t function, mp_obj_t arg) { static MP_DEFINE_CONST_FUN_OBJ_2(mp_micropython_schedule_obj, mp_micropython_schedule); #endif +#if MICROPY_TREZOR_MEMPERF +static mp_obj_t mp_micropython_alloc_count(void) { + return mp_obj_new_int_from_uint((mp_uint_t)alloc_count); +} +static MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_alloc_count_obj, mp_micropython_alloc_count); +#endif + static const mp_rom_map_elem_t mp_module_micropython_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_micropython) }, { MP_ROM_QSTR(MP_QSTR_const), MP_ROM_PTR(&mp_identity_obj) }, @@ -206,6 +213,9 @@ static const mp_rom_map_elem_t mp_module_micropython_globals_table[] = { #if MICROPY_ENABLE_SCHEDULER { MP_ROM_QSTR(MP_QSTR_schedule), MP_ROM_PTR(&mp_micropython_schedule_obj) }, #endif + #if MICROPY_TREZOR_MEMPERF + { MP_ROM_QSTR(MP_QSTR_alloc_count), MP_ROM_PTR(&mp_micropython_alloc_count_obj) }, + #endif }; static MP_DEFINE_CONST_DICT(mp_module_micropython_globals, mp_module_micropython_globals_table); diff --git a/py/mpconfig.h b/py/mpconfig.h index 8d28775c8c4..791f1afc1ef 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -623,6 +623,11 @@ typedef uint64_t mp_uint_t; #define MICROPY_MEM_STATS (0) #endif +// Whether to count GC allocations +#ifndef MICROPY_TREZOR_MEMPERF +#define MICROPY_TREZOR_MEMPERF (0) +#endif + // The mp_print_t printer used for debugging output #ifndef MICROPY_DEBUG_PRINTER #define MICROPY_DEBUG_PRINTER (&mp_plat_print) From 252ba4c082852ab88ca3b7dcafb6adf10cf43232 Mon Sep 17 00:00:00 2001 From: Ondrej Mikle Date: Fri, 11 Dec 2020 17:26:28 +0100 Subject: [PATCH 02/22] py/runtime: systemview debug print redirection --- py/modbuiltins.c | 6 ++++-- py/mpprint.c | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/py/modbuiltins.c b/py/modbuiltins.c index 6f085f2df38..21cf57b983a 100644 --- a/py/modbuiltins.c +++ b/py/modbuiltins.c @@ -401,17 +401,19 @@ static mp_obj_t mp_builtin_print(size_t n_args, const mp_obj_t *pos_args, mp_map mp_print_t print = {MP_OBJ_TO_PTR(u.args[ARG_file].u_obj), mp_stream_write_adaptor}; #endif + #if !defined(SYSTEMVIEW_DEST_SYSTEMVIEW) // extract the objects first because we are going to use the other part of the union mp_obj_t sep = u.args[ARG_sep].u_obj; mp_obj_t end = u.args[ARG_end].u_obj; const char *sep_data = mp_obj_str_get_data(sep, &u.len[0]); const char *end_data = mp_obj_str_get_data(end, &u.len[1]); + #endif for (size_t i = 0; i < n_args; i++) { if (i > 0) { #if MICROPY_PY_IO && MICROPY_PY_SYS_STDFILES mp_stream_write_adaptor(print.data, sep_data, u.len[0]); - #else + #elif !defined(SYSTEMVIEW_DEST_SYSTEMVIEW) mp_print_strn(&mp_plat_print, sep_data, u.len[0], 0, 0, 0); #endif } @@ -423,7 +425,7 @@ static mp_obj_t mp_builtin_print(size_t n_args, const mp_obj_t *pos_args, mp_map } #if MICROPY_PY_IO && MICROPY_PY_SYS_STDFILES mp_stream_write_adaptor(print.data, end_data, u.len[1]); - #else + #elif !defined(SYSTEMVIEW_DEST_SYSTEMVIEW) mp_print_strn(&mp_plat_print, end_data, u.len[1], 0, 0, 0); #endif return mp_const_none; diff --git a/py/mpprint.c b/py/mpprint.c index fa37a4d07ff..20fe0430f9a 100644 --- a/py/mpprint.c +++ b/py/mpprint.c @@ -55,6 +55,10 @@ static const char pad_common[23] = {'0', '0', '0', '0', '0', '0', '0', '0', '0', #define pad_zeroes_comma (pad_common + 17) #define pad_zeroes_comma_size (4) +#ifdef SYSTEM_VIEW +size_t segger_print(const char* str, size_t len); +#endif + static void plat_print_strn(void *env, const char *str, size_t len) { (void)env; MP_PLAT_PRINT_STRN(str, len); From 1b0e245e82e45bfa5b196e16f539c9ff6bd0d64a Mon Sep 17 00:00:00 2001 From: matejcik Date: Wed, 4 Aug 2021 11:23:55 +0200 Subject: [PATCH 03/22] trezor: forward-portable script to drop unwanted submodules --- lib/drop-unwanted-submodules.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 lib/drop-unwanted-submodules.sh diff --git a/lib/drop-unwanted-submodules.sh b/lib/drop-unwanted-submodules.sh new file mode 100644 index 00000000000..3d1c5c0fe8a --- /dev/null +++ b/lib/drop-unwanted-submodules.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +UNWANTED_SUBMODULES="alif_ensemble-cmsis-dfp alif-security-toolkit \ + arduino-lib asf4 axtls berkeley-db-1.xx btstack cyw43-driver \ + fsp libffi libhydrogen libmetal lwip mbedtls micropython-lib \ + mynewt-nimble nrfx nxp_driver open-amp pico-sdk protobuf-c \ + tinyusb wiznet5k" + +cd $(dirname $0) + +for SUBMODULE in $UNWANTED_SUBMODULES; do + git submodule deinit -f -- ./$SUBMODULE + rm -rf ../.git/modules/lib/$SUBMODULE + git rm -f ./$SUBMODULE +done From 86c202fb3c051afce9b84f7a0de80def364814be Mon Sep 17 00:00:00 2001 From: Martin Milata Date: Mon, 13 Jul 2026 22:16:32 +0200 Subject: [PATCH 04/22] chore(trezor): drop unwanted submodules --- .gitmodules | 72 ------------------------------------- lib/alif-security-toolkit | 1 - lib/alif_ensemble-cmsis-dfp | 1 - lib/arduino-lib | 1 - lib/asf4 | 1 - lib/axtls | 1 - lib/berkeley-db-1.xx | 1 - lib/btstack | 1 - lib/cyw43-driver | 1 - lib/fsp | 1 - lib/libffi | 1 - lib/libhydrogen | 1 - lib/libmetal | 1 - lib/lwip | 1 - lib/mbedtls | 1 - lib/micropython-lib | 1 - lib/mynewt-nimble | 1 - lib/nrfx | 1 - lib/nxp_driver | 1 - lib/open-amp | 1 - lib/pico-sdk | 1 - lib/protobuf-c | 1 - lib/tinyusb | 1 - lib/wiznet5k | 1 - 24 files changed, 95 deletions(-) delete mode 160000 lib/alif-security-toolkit delete mode 160000 lib/alif_ensemble-cmsis-dfp delete mode 160000 lib/arduino-lib delete mode 160000 lib/asf4 delete mode 160000 lib/axtls delete mode 160000 lib/berkeley-db-1.xx delete mode 160000 lib/btstack delete mode 160000 lib/cyw43-driver delete mode 160000 lib/fsp delete mode 160000 lib/libffi delete mode 160000 lib/libhydrogen delete mode 160000 lib/libmetal delete mode 160000 lib/lwip delete mode 160000 lib/mbedtls delete mode 160000 lib/micropython-lib delete mode 160000 lib/mynewt-nimble delete mode 160000 lib/nrfx delete mode 160000 lib/nxp_driver delete mode 160000 lib/open-amp delete mode 160000 lib/pico-sdk delete mode 160000 lib/protobuf-c delete mode 160000 lib/tinyusb delete mode 160000 lib/wiznet5k diff --git a/.gitmodules b/.gitmodules index d2c229dd6d7..390cf7a64d8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,76 +1,4 @@ -[submodule "lib/axtls"] - path = lib/axtls - url = https://github.com/micropython/axtls.git -[submodule "lib/libffi"] - path = lib/libffi - url = https://github.com/libffi/libffi -[submodule "lib/lwip"] - path = lib/lwip - url = https://github.com/lwip-tcpip/lwip.git -[submodule "lib/berkeley-db-1.xx"] - path = lib/berkeley-db-1.xx - url = https://github.com/micropython/berkeley-db-1.xx [submodule "lib/stm32lib"] path = lib/stm32lib url = https://github.com/micropython/stm32lib branch = work-F0-1.9.0+F4-1.16.0+F7-1.7.0+G0-1.5.1+G4-1.3.0+H7-1.6.0+L0-1.11.2+L1-1.10.3+L4-1.17.0+WB-1.10.0+WL-1.1.0 -[submodule "lib/nrfx"] - path = lib/nrfx - url = https://github.com/NordicSemiconductor/nrfx.git -[submodule "lib/mbedtls"] - path = lib/mbedtls - url = https://github.com/ARMmbed/mbedtls.git -[submodule "lib/asf4"] - path = lib/asf4 - url = https://github.com/adafruit/asf4 - branch = circuitpython -[submodule "lib/tinyusb"] - path = lib/tinyusb - url = https://github.com/hathach/tinyusb -[submodule "lib/mynewt-nimble"] - path = lib/mynewt-nimble - url = https://github.com/micropython/mynewt-nimble.git -[submodule "lib/btstack"] - path = lib/btstack - url = https://github.com/bluekitchen/btstack.git -[submodule "lib/nxp_driver"] - path = lib/nxp_driver - url = https://github.com/micropython/nxp_driver.git -[submodule "lib/libhydrogen"] - path = lib/libhydrogen - url = https://github.com/jedisct1/libhydrogen.git -[submodule "lib/pico-sdk"] - path = lib/pico-sdk - url = https://github.com/raspberrypi/pico-sdk.git -[submodule "lib/fsp"] - path = lib/fsp - url = https://github.com/renesas/fsp.git -[submodule "lib/wiznet"] - path = lib/wiznet5k - url = https://github.com/andrewleech/wiznet_ioLibrary_Driver.git - # Requires https://github.com/Wiznet/ioLibrary_Driver/pull/120 - # url = https://github.com/Wiznet/ioLibrary_Driver.git -[submodule "lib/cyw43-driver"] - path = lib/cyw43-driver - url = https://github.com/georgerobotics/cyw43-driver.git -[submodule "lib/micropython-lib"] - path = lib/micropython-lib - url = https://github.com/micropython/micropython-lib.git -[submodule "lib/protobuf-c"] - path = lib/protobuf-c - url = https://github.com/protobuf-c/protobuf-c.git -[submodule "lib/open-amp"] - path = lib/open-amp - url = https://github.com/OpenAMP/open-amp.git -[submodule "lib/libmetal"] - path = lib/libmetal - url = https://github.com/OpenAMP/libmetal.git -[submodule "lib/arduino-lib"] - path = lib/arduino-lib - url = https://github.com/arduino/arduino-lib-mpy.git -[submodule "lib/alif_ensemble-cmsis-dfp"] - path = lib/alif_ensemble-cmsis-dfp - url = https://github.com/alifsemi/alif_ensemble-cmsis-dfp.git -[submodule "lib/alif-security-toolkit"] - path = lib/alif-security-toolkit - url = https://github.com/micropython/alif-security-toolkit.git diff --git a/lib/alif-security-toolkit b/lib/alif-security-toolkit deleted file mode 160000 index 63698efe856..00000000000 --- a/lib/alif-security-toolkit +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 63698efe8567eed115fe620d5e5de75f460310d7 diff --git a/lib/alif_ensemble-cmsis-dfp b/lib/alif_ensemble-cmsis-dfp deleted file mode 160000 index 45031404464..00000000000 --- a/lib/alif_ensemble-cmsis-dfp +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 450314044646ad4b56c588b52b68eb6fe7d7caa7 diff --git a/lib/arduino-lib b/lib/arduino-lib deleted file mode 160000 index 8312406d6cd..00000000000 --- a/lib/arduino-lib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8312406d6cd1a19683500f153b33fba7a8414127 diff --git a/lib/asf4 b/lib/asf4 deleted file mode 160000 index 84f56af1329..00000000000 --- a/lib/asf4 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 84f56af13292d8f32c40acbd949bde698ddd4507 diff --git a/lib/axtls b/lib/axtls deleted file mode 160000 index 531cab9c278..00000000000 --- a/lib/axtls +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 531cab9c278c947d268bd4c94ecab9153a961b43 diff --git a/lib/berkeley-db-1.xx b/lib/berkeley-db-1.xx deleted file mode 160000 index 0f3bb6947c2..00000000000 --- a/lib/berkeley-db-1.xx +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0f3bb6947c2f57233916dccd7bb425d7bf86e5a6 diff --git a/lib/btstack b/lib/btstack deleted file mode 160000 index 77e752abd6a..00000000000 --- a/lib/btstack +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 77e752abd6a0992334047a48038a5a3960e5c6bc diff --git a/lib/cyw43-driver b/lib/cyw43-driver deleted file mode 160000 index 055d64274b0..00000000000 --- a/lib/cyw43-driver +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 055d64274b014dd7b1c2fc94d26e8a18face7124 diff --git a/lib/fsp b/lib/fsp deleted file mode 160000 index e78939d32d1..00000000000 --- a/lib/fsp +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e78939d32d1ccea9f0ba8bb42c51aceffd386b9b diff --git a/lib/libffi b/lib/libffi deleted file mode 160000 index 3d0ce1e6fcf..00000000000 --- a/lib/libffi +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3d0ce1e6fcf19f853894862abcbac0ae78a7be60 diff --git a/lib/libhydrogen b/lib/libhydrogen deleted file mode 160000 index 173f728ee2c..00000000000 --- a/lib/libhydrogen +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 173f728ee2c627f80fd0322473e16467f259558d diff --git a/lib/libmetal b/lib/libmetal deleted file mode 160000 index 0cb7d293a7f..00000000000 --- a/lib/libmetal +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0cb7d293a7f25394a06847a28d0f0ace9862936e diff --git a/lib/lwip b/lib/lwip deleted file mode 160000 index 77dcd25a725..00000000000 --- a/lib/lwip +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 77dcd25a72509eb83f72b033d219b1d40cd8eb95 diff --git a/lib/mbedtls b/lib/mbedtls deleted file mode 160000 index 107ea89daae..00000000000 --- a/lib/mbedtls +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 107ea89daaefb9867ea9121002fbbdf926780e98 diff --git a/lib/micropython-lib b/lib/micropython-lib deleted file mode 160000 index 8380c7bb8f9..00000000000 --- a/lib/micropython-lib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8380c7bb8f9e5e5260e9539156742925e00366b2 diff --git a/lib/mynewt-nimble b/lib/mynewt-nimble deleted file mode 160000 index 42849560ba7..00000000000 --- a/lib/mynewt-nimble +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 42849560ba7906f023f61e5f7ff3709ba2c1dfca diff --git a/lib/nrfx b/lib/nrfx deleted file mode 160000 index 7a4c9d946cf..00000000000 --- a/lib/nrfx +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7a4c9d946cf1801771fc180acdbf7b878f270093 diff --git a/lib/nxp_driver b/lib/nxp_driver deleted file mode 160000 index a298e8a3cad..00000000000 --- a/lib/nxp_driver +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a298e8a3cad2df737de020bbeac4ee2147d189ca diff --git a/lib/open-amp b/lib/open-amp deleted file mode 160000 index 1904dee18da..00000000000 --- a/lib/open-amp +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1904dee18da85400e72b8f55c5c99e872a486573 diff --git a/lib/pico-sdk b/lib/pico-sdk deleted file mode 160000 index a1438dff1d3..00000000000 --- a/lib/pico-sdk +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a1438dff1d38bd9c65dbd693f0e5db4b9ae91779 diff --git a/lib/protobuf-c b/lib/protobuf-c deleted file mode 160000 index abc67a11c6d..00000000000 --- a/lib/protobuf-c +++ /dev/null @@ -1 +0,0 @@ -Subproject commit abc67a11c6db271bedbb9f58be85d6f4e2ea8389 diff --git a/lib/tinyusb b/lib/tinyusb deleted file mode 160000 index aa0fc2e08f1..00000000000 --- a/lib/tinyusb +++ /dev/null @@ -1 +0,0 @@ -Subproject commit aa0fc2e08f1c2dd6f026a431e8989357fbb4c5bf diff --git a/lib/wiznet5k b/lib/wiznet5k deleted file mode 160000 index 0803fc519ad..00000000000 --- a/lib/wiznet5k +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0803fc519ad7227e841287fb3638d6c8b2f111a1 From aa4342b601ee0f15d1fce934bd78a5540ccfb7df Mon Sep 17 00:00:00 2001 From: tychovrahe Date: Tue, 25 Apr 2023 11:24:34 +0200 Subject: [PATCH 05/22] uzlib(trezor): partially optimize decompression for speed Co-Authored-By: Martin Milata --- lib/uzlib/tinflate.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/uzlib/tinflate.c b/lib/uzlib/tinflate.c index 53536272f32..71aafa4dad8 100644 --- a/lib/uzlib/tinflate.c +++ b/lib/uzlib/tinflate.c @@ -38,6 +38,12 @@ #include #include "uzlib.h" +#if defined(__GNUC__) && (__GNUC__ >= 5) + #define OPTIMIZE_O3 __attribute__((optimize("-O3"))) +#else + #define OPTIMIZE_O3 +#endif + #define UZLIB_DUMP_ARRAY(heading, arr, size) \ { \ printf("%s", heading); \ @@ -519,6 +525,7 @@ void uzlib_uncompress_init(uzlib_uncomp_t *d, void *dict, unsigned int dictLen) } /* inflate next output bytes from compressed stream */ +OPTIMIZE_O3 int uzlib_uncompress(uzlib_uncomp_t *d) { do { From 5db7036db6b7f63651628dc46d1e4703521fee98 Mon Sep 17 00:00:00 2001 From: cepetr Date: Tue, 7 May 2024 09:38:50 +0200 Subject: [PATCH 06/22] uzlib(trezor): add user context for source callback --- lib/uzlib/uzlib.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/uzlib/uzlib.h b/lib/uzlib/uzlib.h index 16984a77d3e..c653c83f86b 100644 --- a/lib/uzlib/uzlib.h +++ b/lib/uzlib/uzlib.h @@ -86,6 +86,9 @@ typedef struct _uzlib_uncomp_t { source_limit fields, thus allowing for buffered operation. */ void *source_read_data; int (*source_read_cb)(void *); + /* Source callback context parameter not used by the library itself. + User can use it to pass additional data to source_read_cb. */ + void *source_read_cb_context; unsigned int tag; unsigned int bitcount; From 95ae10c8c85766026960edea1d48074dc2d47bb5 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Thu, 6 Mar 2025 19:55:47 +0200 Subject: [PATCH 07/22] mpprint: prefix pointer with `0x` --- py/mpprint.c | 1 + 1 file changed, 1 insertion(+) diff --git a/py/mpprint.c b/py/mpprint.c index 20fe0430f9a..31baf77eb02 100644 --- a/py/mpprint.c +++ b/py/mpprint.c @@ -570,6 +570,7 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args) { mp_uint_t val; if (fmt_chr == 'p' || fmt_chr == 'P') { val = va_arg(args, uintptr_t); + chrs += mp_print_str(print, "0x"); // used by meminfo JSON dumps } #if SUPPORT_LL_FORMAT else if (long_long_arg) { From 4c7034638c01fb8f1903113d7bb0bf253b56712d Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Sun, 16 Mar 2025 10:48:07 +0200 Subject: [PATCH 08/22] gc: support user-defined OOM callback --- py/gc.c | 14 ++++++++++++++ py/gc.h | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/py/gc.c b/py/gc.c index ac76b4b93e2..7158fcbf9ca 100644 --- a/py/gc.c +++ b/py/gc.c @@ -848,6 +848,15 @@ void gc_weakref_mark(void *ptr) { } #endif +#if MICROPY_OOM_CALLBACK +static gc_oom_callback_t gc_oom_callback = NULL; + +void gc_set_oom_callback(gc_oom_callback_t func) +{ + gc_oom_callback = func; +} +#endif + void *gc_alloc(size_t n_bytes, unsigned int alloc_flags) { bool has_finaliser = alloc_flags & GC_ALLOC_FLAG_HAS_FINALISER; size_t n_blocks = ((n_bytes + BYTES_PER_BLOCK - 1) & (~(BYTES_PER_BLOCK - 1))) / BYTES_PER_BLOCK; @@ -925,6 +934,11 @@ void *gc_alloc(size_t n_bytes, unsigned int alloc_flags) { continue; } #endif + #if MICROPY_OOM_CALLBACK + if (gc_oom_callback) { + gc_oom_callback(); + } + #endif return NULL; } DEBUG_printf("gc_alloc(" UINT_FMT "): no free mem, triggering GC\n", n_bytes); diff --git a/py/gc.h b/py/gc.h index 1e361d733e5..052c69fbd17 100644 --- a/py/gc.h +++ b/py/gc.h @@ -93,4 +93,10 @@ void gc_dump_alloc_table(const mp_print_t *print); extern size_t alloc_count; #endif +#if MICROPY_OOM_CALLBACK +typedef void (*gc_oom_callback_t)(void); + +void gc_set_oom_callback(gc_oom_callback_t func); +#endif + #endif // MICROPY_INCLUDED_PY_GC_H From cfb83f5a992841e6f66421c724077f2d83de5b10 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Tue, 25 Mar 2025 11:32:56 +0200 Subject: [PATCH 09/22] py/runtime: make `__main__` preallocate to a configurable size --- py/mpconfig.h | 5 +++++ py/runtime.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/py/mpconfig.h b/py/mpconfig.h index 791f1afc1ef..da2b520d8b1 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -356,6 +356,11 @@ typedef uint64_t mp_uint_t; #define MICROPY_LOADED_MODULES_DICT_SIZE (3) #endif +// Initial size of __main__ dict +#ifndef MICROPY_MAIN_DICT_SIZE +#define MICROPY_MAIN_DICT_SIZE (1) +#endif + // Whether realloc/free should be passed allocated memory region size // You must enable this if MICROPY_MEM_STATS is enabled #ifndef MICROPY_MALLOC_USES_ALLOCATED_SIZE diff --git a/py/runtime.c b/py/runtime.c index 618e9b5ae41..9ba04ff860b 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -111,7 +111,7 @@ void mp_init(void) { mp_obj_dict_init(&MP_STATE_VM(mp_loaded_modules_dict), MICROPY_LOADED_MODULES_DICT_SIZE); // initialise the __main__ module - mp_obj_dict_init(&MP_STATE_VM(dict_main), 1); + mp_obj_dict_init(&MP_STATE_VM(dict_main), MICROPY_MAIN_DICT_SIZE); mp_obj_dict_store(MP_OBJ_FROM_PTR(&MP_STATE_VM(dict_main)), MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR___main__)); // locals = globals for outer module (see Objects/frameobject.c/PyFrame_New()) From c2658621677aacff6bbdb47dc6ae2f3f31daabef Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Thu, 3 Apr 2025 11:15:06 +0300 Subject: [PATCH 10/22] py/misc: zero stack memory allocated by `VSTR_FIXED` Otherwise, it may result in `gc_helper_collect_regs_and_stack()` false-positives. --- py/misc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/misc.h b/py/misc.h index a9c02a4dd96..2328f542e7b 100644 --- a/py/misc.h +++ b/py/misc.h @@ -208,7 +208,7 @@ typedef struct _vstr_t { } vstr_t; // convenience macro to declare a vstr with a fixed size buffer on the stack -#define VSTR_FIXED(vstr, alloc) vstr_t vstr; char vstr##_buf[(alloc)]; vstr_init_fixed_buf(&vstr, (alloc), vstr##_buf); +#define VSTR_FIXED(vstr, alloc) vstr_t vstr; char vstr##_buf[(alloc)] = {0}; vstr_init_fixed_buf(&vstr, (alloc), vstr##_buf); void vstr_init(vstr_t *vstr, size_t alloc); void vstr_init_len(vstr_t *vstr, size_t len); From 9e786fe55372ca2b75cdddbf73a2444ab0539ade Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Mon, 21 Apr 2025 10:47:37 +0300 Subject: [PATCH 11/22] py: allow presizing dicts --- py/map.c | 11 +++++++++-- py/obj.h | 2 ++ py/objdict.c | 4 ++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/py/map.c b/py/map.c index d40e3dc4d02..45455472c4f 100644 --- a/py/map.c +++ b/py/map.c @@ -129,9 +129,16 @@ void mp_map_clear(mp_map_t *map) { } static void mp_map_rehash(mp_map_t *map) { - size_t old_alloc = map->alloc; size_t new_alloc = get_hash_alloc_greater_or_equal_to(map->alloc + 1); - DEBUG_printf("mp_map_rehash(%p): " UINT_FMT " -> " UINT_FMT "\n", map, old_alloc, new_alloc); + DEBUG_printf("mp_map_rehash(%p): " UINT_FMT " -> " UINT_FMT "\n", map, map->alloc, new_alloc); + mp_map_presize(map, new_alloc); +} + +void mp_map_presize(mp_map_t *map, size_t new_alloc) { + size_t old_alloc = map->alloc; + if (new_alloc < old_alloc) { + mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("Map capacity (%d) must not decrease: %d"), old_alloc, new_alloc); + } mp_map_elem_t *old_table = map->table; mp_map_elem_t *new_table = m_new0(mp_map_elem_t, new_alloc); // If we reach this point, table resizing succeeded, now we can edit the old map. diff --git a/py/obj.h b/py/obj.h index 3c9122a69c0..4dfab666f9b 100644 --- a/py/obj.h +++ b/py/obj.h @@ -506,6 +506,7 @@ void mp_map_deinit(mp_map_t *map); mp_map_elem_t *mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t lookup_kind); void mp_map_clear(mp_map_t *map); void mp_map_dump(mp_map_t *map); +void mp_map_presize(mp_map_t *map, size_t n); // Underlying set implementation (not set object) @@ -1191,6 +1192,7 @@ typedef struct _mp_obj_dict_t { } mp_obj_dict_t; mp_obj_t mp_obj_dict_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args); void mp_obj_dict_init(mp_obj_dict_t *dict, size_t n_args); +void mp_obj_dict_presize(mp_obj_dict_t *dict, size_t n_args); size_t mp_obj_dict_len(mp_obj_t self_in); mp_obj_t mp_obj_dict_get(mp_obj_t self_in, mp_obj_t index); mp_obj_t mp_obj_dict_store(mp_obj_t self_in, mp_obj_t key, mp_obj_t value); diff --git a/py/objdict.c b/py/objdict.c index 692a7de4275..45746740db8 100644 --- a/py/objdict.c +++ b/py/objdict.c @@ -646,6 +646,10 @@ void mp_obj_dict_init(mp_obj_dict_t *dict, size_t n_args) { mp_map_init(&dict->map, n_args); } +void mp_obj_dict_presize(mp_obj_dict_t *dict, size_t n_args) { + mp_map_presize(&dict->map, n_args); +} + mp_obj_t mp_obj_new_dict(size_t n_args) { mp_obj_dict_t *o = m_new_obj(mp_obj_dict_t); mp_obj_dict_init(o, n_args); From 8048dee32625fd16faa064774cb4f6bf96a771bb Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Fri, 16 May 2025 17:51:15 +0300 Subject: [PATCH 12/22] py/objstr: export `str_modulo_format` for efficient logging from Rust --- py/objstr.c | 6 +----- py/objstr.h | 4 ++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/py/objstr.c b/py/objstr.c index e8b2512a246..c4c19474583 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -35,10 +35,6 @@ #include "py/cstack.h" #include "py/objtuple.h" -#if MICROPY_PY_BUILTINS_STR_OP_MODULO -static mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_t *args, mp_obj_t dict); -#endif - static mp_obj_t mp_obj_new_bytes_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf); static MP_NORETURN void bad_implicit_conversion(mp_obj_t self_in); @@ -1470,7 +1466,7 @@ mp_obj_t mp_obj_str_format(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs MP_DEFINE_CONST_FUN_OBJ_KW(str_format_obj, 1, mp_obj_str_format); #if MICROPY_PY_BUILTINS_STR_OP_MODULO -static mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_t *args, mp_obj_t dict) { +mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_t *args, mp_obj_t dict) { check_is_str_or_bytes(pattern); GET_STR_DATA_LEN(pattern, str, len); diff --git a/py/objstr.h b/py/objstr.h index 028fc9597ff..a359492d6bd 100644 --- a/py/objstr.h +++ b/py/objstr.h @@ -96,6 +96,10 @@ mp_int_t mp_obj_str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_u void mp_obj_str_set_data(mp_obj_str_t *str, const byte *data, size_t len); +#if MICROPY_PY_BUILTINS_STR_OP_MODULO +mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_t *args, mp_obj_t dict); +#endif + const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, size_t self_len, mp_obj_t index, bool is_slice); const byte *find_subbytes(const byte *haystack, size_t hlen, const byte *needle, size_t nlen, int direction); From 9b3ec27b1cdcb232a12503082015b1ad9dada0d1 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Thu, 11 Sep 2025 11:49:36 +0300 Subject: [PATCH 13/22] py/obj: allow disabling traceback allocation Since the existing code handles `NULL` `traceback_data` correctly, it would avoid heap allocation in builds that don't access traceback data. --- py/mpconfig.h | 5 +++++ py/obj.h | 4 ++++ py/objexcept.c | 2 ++ 3 files changed, 11 insertions(+) diff --git a/py/mpconfig.h b/py/mpconfig.h index da2b520d8b1..b65050a5d05 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1844,6 +1844,11 @@ typedef time_t mp_timestamp_t; #define MICROPY_PY_SYS_TRACEBACKLIMIT (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING) #endif +// Whether to disable traceback allocation +#ifndef MICROPY_PY_SYS_TRACEBACK_DISABLE +#define MICROPY_PY_SYS_TRACEBACK_DISABLE 0 +#endif + // Whether the sys module supports attribute delegation // This is enabled automatically when needed by other features #ifndef MICROPY_PY_SYS_ATTR_DELEGATION diff --git a/py/obj.h b/py/obj.h index 4dfab666f9b..f62b8c8feff 100644 --- a/py/obj.h +++ b/py/obj.h @@ -1114,7 +1114,11 @@ bool mp_obj_is_exception_type(mp_obj_t self_in); bool mp_obj_is_exception_instance(mp_obj_t self_in); bool mp_obj_exception_match(mp_obj_t exc, mp_const_obj_t exc_type); void mp_obj_exception_clear_traceback(mp_obj_t self_in); +#if MICROPY_PY_SYS_TRACEBACK_DISABLE +static inline void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qstr block) {} +#else void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qstr block); +#endif void mp_obj_exception_get_traceback(mp_obj_t self_in, size_t *n, size_t **values); mp_obj_t mp_obj_exception_get_value(mp_obj_t self_in); mp_obj_t mp_obj_exception_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args); diff --git a/py/objexcept.c b/py/objexcept.c index d43cf979e69..ff05be92008 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -583,6 +583,7 @@ void mp_obj_exception_clear_traceback(mp_obj_t self_in) { self->traceback_data = NULL; } +#if !MICROPY_PY_SYS_TRACEBACK_DISABLE void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qstr block) { mp_obj_exception_t *self = get_native_exception(self_in); @@ -645,6 +646,7 @@ void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qs tb_data[1] = line; tb_data[2] = block; } +#endif // !MICROPY_PY_SYS_TRACEBACK_DISABLE void mp_obj_exception_get_traceback(mp_obj_t self_in, size_t *n, size_t **values) { mp_obj_exception_t *self = get_native_exception(self_in); From 589b37c7d6d2a2f3745f237a6ab267eb7698da92 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Thu, 9 Apr 2026 13:50:58 +0200 Subject: [PATCH 14/22] py: Allow mpy-cross to exclude source lines. This would allow building debug FW without source line data. Signed-off-by: Roman Zeyde --- mpy-cross/main.c | 22 ++++++++++++++++++++++ py/emitbc.c | 2 +- py/mpstate.h | 3 +++ py/runtime.c | 3 +++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/mpy-cross/main.c b/mpy-cross/main.c index c9109788fb3..89078896b95 100644 --- a/mpy-cross/main.c +++ b/mpy-cross/main.c @@ -50,6 +50,10 @@ static asm_rv32_backend_options_t rv32_options = { 0 }; static uint emit_opt = MP_EMIT_OPT_NONE; mp_uint_t mp_verbose_flag = 0; +#if MICROPY_ENABLE_SOURCE_LINE +static bool include_source_lines = true; +#endif + // Heap size of GC heap (if enabled) // Make it larger on a 64 bit machine, because pointers are larger. long heap_size = 1024 * 1024 * (sizeof(mp_uint_t) / 4); @@ -163,6 +167,12 @@ static int usage(char **argv) { " heapsize= -- set the heap size for the GC (default %ld)\n" , heap_size); impl_opts_cnt++; + #if MICROPY_ENABLE_SOURCE_LINE + printf( + " source-lines -- include source line numbers (default)\n" + " no-source-lines -- exclude source line numbers\n"); + impl_opts_cnt += 2; + #endif if (impl_opts_cnt == 0) { printf(" (none)\n"); @@ -186,6 +196,14 @@ static void pre_process_options(int argc, char **argv) { emit_opt = MP_EMIT_OPT_NATIVE_PYTHON; } else if (strcmp(argv[a + 1], "emit=viper") == 0) { emit_opt = MP_EMIT_OPT_VIPER; + #if MICROPY_ENABLE_SOURCE_LINE + } else if (strcmp(argv[a + 1], "source-lines") == 0) { + // Allow excluding source lines for debug builds. + include_source_lines = true; + } else if (strcmp(argv[a + 1], "no-source-lines") == 0) { + // Allow excluding source lines for debug builds. + include_source_lines = false; + #endif #endif } else if (strncmp(argv[a + 1], "heapsize=", sizeof("heapsize=") - 1) == 0) { char *end; @@ -305,6 +323,10 @@ MP_NOINLINE int main_(int argc, char **argv) { (void)emit_opt; #endif + #if MICROPY_ENABLE_SOURCE_LINE + MP_STATE_VM(include_source_lines) = include_source_lines; + #endif + // set default compiler configuration mp_dynamic_compiler.small_int_bits = 31; // don't support native emitter unless -march is specified diff --git a/py/emitbc.c b/py/emitbc.c index 0fbda56fdb0..e67344ea5a7 100644 --- a/py/emitbc.c +++ b/py/emitbc.c @@ -430,7 +430,7 @@ void mp_emit_bc_set_source_line(emit_t *emit, mp_uint_t source_line) { // If we compile with -O3, don't store line numbers. return; } - if (source_line > emit->last_source_line) { + if (MP_STATE_VM(include_source_lines) && source_line > emit->last_source_line) { mp_uint_t bytes_to_skip = emit->bytecode_offset - emit->last_source_line_offset; mp_uint_t lines_to_skip = source_line - emit->last_source_line; emit_write_code_info_bytes_lines(emit, bytes_to_skip, lines_to_skip); diff --git a/py/mpstate.h b/py/mpstate.h index 32d1adb13ed..3a80a72d87a 100644 --- a/py/mpstate.h +++ b/py/mpstate.h @@ -231,6 +231,9 @@ typedef struct _mp_state_vm_t { #if MICROPY_EMIT_NATIVE uint8_t default_emit_opt; // one of MP_EMIT_OPT_xxx #endif + #if MICROPY_ENABLE_SOURCE_LINE + bool include_source_lines; + #endif #endif // size of the emergency exception buf, if it's dynamically allocated diff --git a/py/runtime.c b/py/runtime.c index 9ba04ff860b..67dda4e8383 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -105,6 +105,9 @@ void mp_init(void) { #if MICROPY_EMIT_NATIVE MP_STATE_VM(default_emit_opt) = MP_EMIT_OPT_NONE; #endif + #if MICROPY_ENABLE_SOURCE_LINE + MP_STATE_VM(include_source_lines) = true; + #endif #endif // init global module dict From 51d712cd882569d4e6b0fa92305302fc3834890c Mon Sep 17 00:00:00 2001 From: Martin Milata Date: Thu, 9 Jul 2026 21:43:57 +0200 Subject: [PATCH 15/22] py: export mp_type_cell for modtrezorutils-meminfo.h --- py/objcell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/objcell.c b/py/objcell.c index 5c030c7405a..481a38bd4f6 100644 --- a/py/objcell.c +++ b/py/objcell.c @@ -46,7 +46,7 @@ static void cell_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t k #define CELL_TYPE_PRINT #endif -static MP_DEFINE_CONST_OBJ_TYPE( +MP_DEFINE_CONST_OBJ_TYPE( // cell representation is just value in < > mp_type_cell, MP_QSTR_, MP_TYPE_FLAG_NONE CELL_TYPE_PRINT From d307a6403c3ee7b2e786403ed7b64b5b8d8f1b92 Mon Sep 17 00:00:00 2001 From: Martin Milata Date: Fri, 10 Jul 2026 15:37:01 +0200 Subject: [PATCH 16/22] py/builtinimport: fix compilation with -Werror Signed-off-by: Martin Milata --- py/builtinimport.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/py/builtinimport.c b/py/builtinimport.c index 2c7d796680f..8e81d0151ff 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -238,7 +238,9 @@ static void do_load(mp_module_context_t *module_obj, vstr_t *file) { #endif // MICROPY_MODULE_FROZEN + #if (MICROPY_HAS_FILE_READER && MICROPY_PERSISTENT_CODE_LOAD) || MICROPY_ENABLE_COMPILER qstr file_qstr = qstr_from_str(file_str); + #endif // If we support loading .mpy files then check if the file extension is of // the correct format and, if so, load and execute the file. From c5ef7ea2edd0f7430f26befc871b21fe3b0fe3ec Mon Sep 17 00:00:00 2001 From: Martin Milata Date: Fri, 17 Jul 2026 18:12:47 +0200 Subject: [PATCH 17/22] fixup! gc: support user-defined OOM callback --- py/gc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/py/gc.c b/py/gc.c index 7158fcbf9ca..c043c424f3f 100644 --- a/py/gc.c +++ b/py/gc.c @@ -851,8 +851,7 @@ void gc_weakref_mark(void *ptr) { #if MICROPY_OOM_CALLBACK static gc_oom_callback_t gc_oom_callback = NULL; -void gc_set_oom_callback(gc_oom_callback_t func) -{ +void gc_set_oom_callback(gc_oom_callback_t func) { gc_oom_callback = func; } #endif From 57349367f030b58a98cfa5dc39a455fd2bcb8dca Mon Sep 17 00:00:00 2001 From: Martin Milata Date: Fri, 17 Jul 2026 18:13:01 +0200 Subject: [PATCH 18/22] fixup! py/runtime: systemview debug print redirection --- py/mpprint.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/mpprint.c b/py/mpprint.c index 31baf77eb02..0a54637f0e4 100644 --- a/py/mpprint.c +++ b/py/mpprint.c @@ -56,7 +56,7 @@ static const char pad_common[23] = {'0', '0', '0', '0', '0', '0', '0', '0', '0', #define pad_zeroes_comma_size (4) #ifdef SYSTEM_VIEW -size_t segger_print(const char* str, size_t len); +size_t segger_print(const char *str, size_t len); #endif static void plat_print_strn(void *env, const char *str, size_t len) { From 980c2f639195d3c466463e408b113e612fa14619 Mon Sep 17 00:00:00 2001 From: Martin Milata Date: Fri, 17 Jul 2026 18:13:27 +0200 Subject: [PATCH 19/22] fixup! py/obj: allow disabling traceback allocation --- py/obj.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/py/obj.h b/py/obj.h index f62b8c8feff..83cd5a3abe5 100644 --- a/py/obj.h +++ b/py/obj.h @@ -1115,7 +1115,8 @@ bool mp_obj_is_exception_instance(mp_obj_t self_in); bool mp_obj_exception_match(mp_obj_t exc, mp_const_obj_t exc_type); void mp_obj_exception_clear_traceback(mp_obj_t self_in); #if MICROPY_PY_SYS_TRACEBACK_DISABLE -static inline void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qstr block) {} +static inline void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qstr block) { +} #else void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qstr block); #endif From bd6e2f1fc06eb25ccbed4e74027215a462c7a7fa Mon Sep 17 00:00:00 2001 From: Martin Milata Date: Fri, 17 Jul 2026 17:31:41 +0200 Subject: [PATCH 20/22] trezor: run subset of CI workflows --- .github/workflows/biome.yml | 16 -- .github/workflows/code_size.yml | 64 ------ .github/workflows/code_size_comment.yml | 105 ---------- .github/workflows/commit_formatting.yml | 18 -- .github/workflows/docs.yml | 27 --- .github/workflows/mpremote.yml | 29 --- .github/workflows/mpy_format.yml | 3 + .github/workflows/ports_alif.yml | 33 ---- .github/workflows/ports_cc3200.yml | 28 --- .github/workflows/ports_esp32.yml | 63 ------ .github/workflows/ports_esp8266.yml | 28 --- .github/workflows/ports_mimxrt.yml | 33 ---- .github/workflows/ports_nrf.yml | 28 --- .github/workflows/ports_powerpc.yml | 28 --- .github/workflows/ports_qemu.yml | 27 +-- .github/workflows/ports_renesas-ra.yml | 29 --- .github/workflows/ports_rp2.yml | 33 ---- .github/workflows/ports_samd.yml | 28 --- .github/workflows/ports_stm32.yml | 3 + .github/workflows/ports_unix.yml | 66 ++++++- .github/workflows/ports_webassembly.yml | 33 ---- .github/workflows/ports_windows.yml | 157 --------------- .github/workflows/ports_zephyr.yml | 64 ------ tests/extmod/btree_closed.py.exp | 2 +- tests/extmod/deflate_compress.py | 154 --------------- tests/extmod/deflate_compress.py.exp | 42 ---- tests/extmod/deflate_compress_memory_error.py | 39 ---- .../deflate_compress_memory_error.py.exp | 2 - tests/extmod/deflate_decompress.py | 185 ------------------ tests/extmod/deflate_decompress.py.exp | 80 -------- tests/extmod/deflate_stream_error.py | 89 --------- tests/extmod/deflate_stream_error.py.exp | 25 --- tests/extmod/uctypes_print.py.exp | 8 +- tests/micropython/meminfo.py.exp | 2 +- tests/misc/sys_settrace_cov.py.exp | 2 +- tests/ports/unix/extra_coverage.py.exp | 12 +- tests/thread/thread_exc2.py.exp | 2 +- tests/thread/thread_exc2.py.native.exp | 2 +- tools/ci.sh | 2 +- tools/undrop_submodules.sh | 6 + 40 files changed, 91 insertions(+), 1506 deletions(-) delete mode 100644 .github/workflows/biome.yml delete mode 100644 .github/workflows/code_size.yml delete mode 100644 .github/workflows/code_size_comment.yml delete mode 100644 .github/workflows/commit_formatting.yml delete mode 100644 .github/workflows/docs.yml delete mode 100644 .github/workflows/mpremote.yml delete mode 100644 .github/workflows/ports_alif.yml delete mode 100644 .github/workflows/ports_cc3200.yml delete mode 100644 .github/workflows/ports_esp32.yml delete mode 100644 .github/workflows/ports_esp8266.yml delete mode 100644 .github/workflows/ports_mimxrt.yml delete mode 100644 .github/workflows/ports_nrf.yml delete mode 100644 .github/workflows/ports_powerpc.yml delete mode 100644 .github/workflows/ports_renesas-ra.yml delete mode 100644 .github/workflows/ports_rp2.yml delete mode 100644 .github/workflows/ports_samd.yml delete mode 100644 .github/workflows/ports_webassembly.yml delete mode 100644 .github/workflows/ports_windows.yml delete mode 100644 .github/workflows/ports_zephyr.yml delete mode 100644 tests/extmod/deflate_compress.py delete mode 100644 tests/extmod/deflate_compress.py.exp delete mode 100644 tests/extmod/deflate_compress_memory_error.py delete mode 100644 tests/extmod/deflate_compress_memory_error.py.exp delete mode 100644 tests/extmod/deflate_decompress.py delete mode 100644 tests/extmod/deflate_decompress.py.exp delete mode 100644 tests/extmod/deflate_stream_error.py delete mode 100644 tests/extmod/deflate_stream_error.py.exp create mode 100755 tools/undrop_submodules.sh diff --git a/.github/workflows/biome.yml b/.github/workflows/biome.yml deleted file mode 100644 index 0cde10acc91..00000000000 --- a/.github/workflows/biome.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: JavaScript code lint and formatting with Biome - -on: [push, pull_request] - -jobs: - eslint: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v6 - - name: Setup Biome - uses: biomejs/setup-biome@v2 - with: - version: 1.5.3 - - name: Run Biome - run: biome ci --indent-style=space --indent-width=4 tests/ ports/webassembly diff --git a/.github/workflows/code_size.yml b/.github/workflows/code_size.yml deleted file mode 100644 index f3238a85d9a..00000000000 --- a/.github/workflows/code_size.yml +++ /dev/null @@ -1,64 +0,0 @@ -name: Check code size - -on: - pull_request: - paths: - - '.github/workflows/*.yml' - - 'tools/**' - - 'py/**' - - 'extmod/**' - - 'shared/**' - - 'lib/**' - - 'ports/bare-arm/**' - - 'ports/esp32/**' - - 'ports/mimxrt/**' - - 'ports/minimal/**' - - 'ports/rp2/**' - - 'ports/samd/**' - - 'ports/stm32/**' - - 'ports/unix/**' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - with: - fetch-depth: 100 - - name: Install packages - run: tools/ci.sh code_size_setup - - - name: Find IDF_NEWEST_VER - id: idf_ver - run: | - echo "IDF_VER="$(yq .env.IDF_NEWEST_VER < .github/workflows/ports_esp32.yml) \ - | tee "${GITHUB_OUTPUT}" - - - name: Setup ESP-IDF - uses: ./.github/actions/setup_esp32 - with: - idf_ver: ${{ steps.idf_ver.outputs.IDF_VER }} - ccache_key: code_size - - - name: Build - run: tools/ci.sh code_size_build - - name: Compute code size difference - run: source tools/ci.sh && ci_code_size_report - - name: Save PR number - if: github.event_name == 'pull_request' - env: - PR_NUMBER: ${{ github.event.number }} - run: echo $PR_NUMBER > pr_number - - name: Upload diff - if: github.event_name == 'pull_request' - uses: actions/upload-artifact@v7 - with: - name: code-size-report - path: | - diff - pr_number - retention-days: 1 diff --git a/.github/workflows/code_size_comment.yml b/.github/workflows/code_size_comment.yml deleted file mode 100644 index 2eed0b06b8e..00000000000 --- a/.github/workflows/code_size_comment.yml +++ /dev/null @@ -1,105 +0,0 @@ -name: Code size comment - -on: - workflow_run: - workflows: [Check code size] - types: [completed] - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - comment: - runs-on: ubuntu-22.04 - steps: - - name: 'Download artifact' - id: download-artifact - uses: actions/github-script@v8 - with: - result-encoding: string - script: | - const fs = require('fs'); - - const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ - owner: context.repo.owner, - repo: context.repo.repo, - run_id: context.payload.workflow_run.id, - }); - - const matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { - return artifact.name == "code-size-report" - }); - - if (matchArtifact.length === 0) { - console.log('no matching artifact found'); - console.log('result: "skip"'); - - return 'skip'; - } - - const download = await github.rest.actions.downloadArtifact({ - owner: context.repo.owner, - repo: context.repo.repo, - artifact_id: matchArtifact[0].id, - archive_format: 'zip', - }); - - fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/code-size-report.zip`, Buffer.from(download.data)); - - console.log('artifact downloaded to `code-size-report.zip`'); - console.log('result: "ok"'); - - return 'ok'; - - name: 'Unzip artifact' - if: steps.download-artifact.outputs.result == 'ok' - run: unzip code-size-report.zip - - name: Post comment to pull request - if: steps.download-artifact.outputs.result == 'ok' - uses: actions/github-script@v8 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - script: | - const fs = require('fs'); - - const prNumber = Number(fs.readFileSync('pr_number')); - const codeSizeReport = `Code size report: - - \`\`\` - ${fs.readFileSync('diff')} - \`\`\` - `; - - const comments = await github.paginate( - github.rest.issues.listComments, - { - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber, - } - ); - - comments.reverse(); - - const previousComment = comments.find(comment => - comment.user.login === 'github-actions[bot]' - ) - - // if github-actions[bot] already made a comment, update it, - // otherwise create a new comment. - - if (previousComment) { - await github.rest.issues.updateComment({ - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: previousComment.id, - body: codeSizeReport, - }); - } else { - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber, - body: codeSizeReport, - }); - } diff --git a/.github/workflows/commit_formatting.yml b/.github/workflows/commit_formatting.yml deleted file mode 100644 index 6abc3612a00..00000000000 --- a/.github/workflows/commit_formatting.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: Check commit message formatting - -on: [pull_request] - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - with: - fetch-depth: 100 - - uses: actions/setup-python@v6 - - name: Check commit message formatting - run: tools/ci.sh commit_formatting_run diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml deleted file mode 100644 index 79755b74197..00000000000 --- a/.github/workflows/docs.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Build docs - -on: - push: - pull_request: - paths: - - docs/** - - py/** - - tests/cpydiff/** - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v6 - - uses: actions/setup-python@v6 - - name: Install Python packages - run: pip install -r docs/requirements.txt - - name: Build unix port - run: tools/ci.sh unix_build_helper - - name: Build docs - run: make -C docs/ html diff --git a/.github/workflows/mpremote.yml b/.github/workflows/mpremote.yml deleted file mode 100644 index 9f837c9902e..00000000000 --- a/.github/workflows/mpremote.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Package mpremote - -on: - push: - pull_request: - paths: - - '.github/workflows/*.yml' - - 'tools/**' - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - with: - # Setting this to zero means fetch all history and tags, - # which hatch-vcs can use to discover the version tag. - fetch-depth: 0 - - uses: actions/setup-python@v6 - - name: Install build tools - run: pip install build - - name: Build mpremote wheel - run: cd tools/mpremote && python -m build --wheel - - name: Archive mpremote wheel - uses: actions/upload-artifact@v7 - with: - name: mpremote - path: | - tools/mpremote/dist/mpremote*.whl diff --git a/.github/workflows/mpy_format.yml b/.github/workflows/mpy_format.yml index ab668c1cb5e..a6f7eb1ce6b 100644 --- a/.github/workflows/mpy_format.yml +++ b/.github/workflows/mpy_format.yml @@ -20,6 +20,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + with: + fetch-depth: 30 + - run: tools/undrop_submodules.sh - name: Install packages run: tools/ci.sh mpy_format_setup - name: Test mpy-tool.py diff --git a/.github/workflows/ports_alif.yml b/.github/workflows/ports_alif.yml deleted file mode 100644 index 6fb225937a9..00000000000 --- a/.github/workflows/ports_alif.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: alif port - -on: - push: - pull_request: - paths: - - '.github/workflows/*.yml' - - 'tools/**' - - 'py/**' - - 'extmod/**' - - 'shared/**' - - 'lib/**' - - 'drivers/**' - - 'ports/alif/**' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - build_alif: - strategy: - fail-fast: false - matrix: - ci_func: # names are functions in ci.sh - - alif_ae3_build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - - name: Install packages - run: tools/ci.sh alif_setup - - name: Build ci_${{matrix.ci_func }} - run: tools/ci.sh ${{ matrix.ci_func }} diff --git a/.github/workflows/ports_cc3200.yml b/.github/workflows/ports_cc3200.yml deleted file mode 100644 index 194483ec218..00000000000 --- a/.github/workflows/ports_cc3200.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: cc3200 port - -on: - push: - pull_request: - paths: - - '.github/workflows/*.yml' - - 'tools/**' - - 'py/**' - - 'extmod/**' - - 'shared/**' - - 'lib/**' - - 'drivers/**' - - 'ports/cc3200/**' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - - name: Install packages - run: tools/ci.sh cc3200_setup - - name: Build - run: tools/ci.sh cc3200_build diff --git a/.github/workflows/ports_esp32.yml b/.github/workflows/ports_esp32.yml deleted file mode 100644 index 56dce3b69d9..00000000000 --- a/.github/workflows/ports_esp32.yml +++ /dev/null @@ -1,63 +0,0 @@ -name: esp32 port - -on: - push: - pull_request: - paths: - - '.github/workflows/*.yml' - - 'tools/**' - - 'py/**' - - 'extmod/**' - - 'shared/**' - - 'lib/**' - - 'drivers/**' - - 'ports/esp32/**' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -env: - # Oldest and newest supported ESP-IDF versions, should match ports/esp32/README.md - IDF_OLDEST_VER: &oldest "v5.3" - IDF_NEWEST_VER: &newest "v5.5.1" - -jobs: - build_idf: - strategy: - fail-fast: false - matrix: - idf_ver: - - *oldest - - *newest - ci_func: # names are functions in ci.sh - - esp32_build_cmod_spiram_s2 - - esp32_build_s3_c3 - - esp32_build_c2_c5_c6 - - esp32_build_p4 - exclude: - # Exclude some jobs on the oldest IDF version, to save resources - - idf_ver: *oldest - ci_func: esp32_build_c2_c5_c6 - - idf_ver: *oldest - ci_func: esp32_build_p4 - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - - # Only the newest IDF version will build the ESP-IDF lockfiles correctly, - # so we need to disable MICROPY_MAINTAINER_BUILD on older versions. - - name: Disable extra checks for older ESP-IDF - id: check_newest_ver - if: ${{ matrix.idf_ver != env.IDF_NEWEST_VER }} - run: echo "MICROPY_MAINTAINER_BUILD=0" >> ${GITHUB_ENV} - - - name: Setup ESP-IDF - uses: ./.github/actions/setup_esp32 - with: - idf_ver: ${{ matrix.idf_ver }} - ccache_key: ${{ matrix.ci_func }} - - - - name: Build ci_${{matrix.ci_func }} on ESP-IDF ${{ matrix.idf_ver }} - run: tools/ci.sh ${{ matrix.ci_func }} diff --git a/.github/workflows/ports_esp8266.yml b/.github/workflows/ports_esp8266.yml deleted file mode 100644 index eb7f59cdc49..00000000000 --- a/.github/workflows/ports_esp8266.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: esp8266 port - -on: - push: - pull_request: - paths: - - '.github/workflows/*.yml' - - 'tools/**' - - 'py/**' - - 'extmod/**' - - 'shared/**' - - 'lib/**' - - 'drivers/**' - - 'ports/esp8266/**' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - - name: Install packages - run: tools/ci.sh esp8266_setup && tools/ci.sh esp8266_path >> $GITHUB_PATH - - name: Build - run: tools/ci.sh esp8266_build diff --git a/.github/workflows/ports_mimxrt.yml b/.github/workflows/ports_mimxrt.yml deleted file mode 100644 index fd80f3f6329..00000000000 --- a/.github/workflows/ports_mimxrt.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: mimxrt port - -on: - push: - pull_request: - paths: - - '.github/workflows/*.yml' - - 'tools/**' - - 'py/**' - - 'extmod/**' - - 'shared/**' - - 'lib/**' - - 'drivers/**' - - 'ports/mimxrt/**' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - build: - runs-on: ubuntu-latest - defaults: - run: - working-directory: 'micropython repo' # test build with space in path - steps: - - uses: actions/checkout@v6 - with: - path: 'micropython repo' - - name: Install packages - run: tools/ci.sh mimxrt_setup - - name: Build - run: tools/ci.sh mimxrt_build diff --git a/.github/workflows/ports_nrf.yml b/.github/workflows/ports_nrf.yml deleted file mode 100644 index bec9a5dfb5b..00000000000 --- a/.github/workflows/ports_nrf.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: nrf port - -on: - push: - pull_request: - paths: - - '.github/workflows/*.yml' - - 'tools/**' - - 'py/**' - - 'extmod/**' - - 'shared/**' - - 'lib/**' - - 'drivers/**' - - 'ports/nrf/**' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - - name: Install packages - run: tools/ci.sh nrf_setup - - name: Build - run: tools/ci.sh nrf_build diff --git a/.github/workflows/ports_powerpc.yml b/.github/workflows/ports_powerpc.yml deleted file mode 100644 index a883d026806..00000000000 --- a/.github/workflows/ports_powerpc.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: powerpc port - -on: - push: - pull_request: - paths: - - '.github/workflows/*.yml' - - 'tools/**' - - 'py/**' - - 'extmod/**' - - 'shared/**' - - 'lib/**' - - 'drivers/**' - - 'ports/powerpc/**' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - - name: Install packages - run: tools/ci.sh powerpc_setup - - name: Build - run: tools/ci.sh powerpc_build diff --git a/.github/workflows/ports_qemu.yml b/.github/workflows/ports_qemu.yml index 0ed95dbe5f9..ce94d9726ff 100644 --- a/.github/workflows/ports_qemu.yml +++ b/.github/workflows/ports_qemu.yml @@ -31,6 +31,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + with: + fetch-depth: 30 + - run: tools/undrop_submodules.sh - name: Install packages run: tools/ci.sh qemu_setup_arm - name: Build and run test suite ci_qemu_build_arm_${{ matrix.ci_func }} @@ -38,27 +41,3 @@ jobs: - name: Print failures if: failure() run: tests/run-tests.py --print-failures - - build_and_test_rv32: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - - name: Install packages - run: tools/ci.sh qemu_setup_rv32 - - name: Build and run test suite - run: tools/ci.sh qemu_build_rv32 - - name: Print failures - if: failure() - run: tests/run-tests.py --print-failures - - build_and_test_rv64: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - - name: Install packages - run: tools/ci.sh qemu_setup_rv64 - - name: Build and run test suite - run: tools/ci.sh qemu_build_rv64 - - name: Print failures - if: failure() - run: tests/run-tests.py --print-failures diff --git a/.github/workflows/ports_renesas-ra.yml b/.github/workflows/ports_renesas-ra.yml deleted file mode 100644 index 920691eca70..00000000000 --- a/.github/workflows/ports_renesas-ra.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: renesas-ra port - -on: - push: - pull_request: - paths: - - '.github/workflows/*.yml' - - 'tools/**' - - 'py/**' - - 'extmod/**' - - 'shared/**' - - 'lib/**' - - 'drivers/**' - - 'ports/renesas-ra/**' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - build_renesas_ra_board: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - - name: Install packages - run: tools/ci.sh renesas_ra_setup - - name: Build - run: tools/ci.sh renesas_ra_board_build - diff --git a/.github/workflows/ports_rp2.yml b/.github/workflows/ports_rp2.yml deleted file mode 100644 index ea19e2da7ff..00000000000 --- a/.github/workflows/ports_rp2.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: rp2 port - -on: - push: - pull_request: - paths: - - '.github/workflows/*.yml' - - 'tools/**' - - 'py/**' - - 'extmod/**' - - 'shared/**' - - 'lib/**' - - 'drivers/**' - - 'ports/rp2/**' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - build: - runs-on: ubuntu-latest - defaults: - run: - working-directory: 'micropython repo' # test build with space in path - steps: - - uses: actions/checkout@v6 - with: - path: 'micropython repo' - - name: Install packages - run: tools/ci.sh rp2_setup - - name: Build - run: tools/ci.sh rp2_build diff --git a/.github/workflows/ports_samd.yml b/.github/workflows/ports_samd.yml deleted file mode 100644 index eb806ceb044..00000000000 --- a/.github/workflows/ports_samd.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: samd port - -on: - push: - pull_request: - paths: - - '.github/workflows/*.yml' - - 'tools/**' - - 'py/**' - - 'extmod/**' - - 'shared/**' - - 'lib/**' - - 'drivers/**' - - 'ports/samd/**' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - - name: Install packages - run: tools/ci.sh samd_setup - - name: Build - run: tools/ci.sh samd_build diff --git a/.github/workflows/ports_stm32.yml b/.github/workflows/ports_stm32.yml index 2ed730eb4e8..fcca70ecc2f 100644 --- a/.github/workflows/ports_stm32.yml +++ b/.github/workflows/ports_stm32.yml @@ -29,6 +29,9 @@ jobs: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v6 + with: + fetch-depth: 30 + - run: tools/undrop_submodules.sh - name: Install packages run: tools/ci.sh stm32_setup && tools/ci.sh stm32_path >> $GITHUB_PATH - name: Build ci_${{matrix.ci_func }} diff --git a/.github/workflows/ports_unix.yml b/.github/workflows/ports_unix.yml index bd04163ded8..2b0ae1d5744 100644 --- a/.github/workflows/ports_unix.yml +++ b/.github/workflows/ports_unix.yml @@ -24,6 +24,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + with: + fetch-depth: 30 + - run: tools/undrop_submodules.sh - name: Build run: tools/ci.sh unix_minimal_build - name: Run main test suite @@ -36,6 +39,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + with: + fetch-depth: 30 + - run: tools/undrop_submodules.sh - name: Build with reproducible date run: tools/ci.sh unix_minimal_build env: @@ -47,6 +53,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + with: + fetch-depth: 30 + - run: tools/undrop_submodules.sh - name: Build run: tools/ci.sh unix_standard_build - name: Run main test suite @@ -59,6 +68,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + with: + fetch-depth: 30 + - run: tools/undrop_submodules.sh - name: Build run: tools/ci.sh unix_standard_v2_build - name: Run main test suite @@ -71,6 +83,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + with: + fetch-depth: 30 + - run: tools/undrop_submodules.sh - uses: actions/setup-python@v6 # Python 3.12 is the default for ubuntu-24.04, but that has compatibility issues with settrace tests. # Can remove this step when ubuntu-latest uses a more recent Python 3.x as the default. @@ -92,12 +107,6 @@ jobs: run: | (cd ports/unix && gcov -o build-coverage/py ../../py/*.c || true) (cd ports/unix && gcov -o build-coverage/extmod ../../extmod/*.c || true) - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v5 - with: - fail_ci_if_error: true - verbose: true - token: ${{ secrets.CODECOV_TOKEN }} - name: Print failures if: failure() run: tests/run-tests.py --print-failures @@ -106,6 +115,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + with: + fetch-depth: 30 + - run: tools/undrop_submodules.sh - uses: actions/setup-python@v6 # Python 3.12 is the default for ubuntu-24.04, but that has compatibility issues with settrace tests. # Can remove this step when ubuntu-latest uses a more recent Python 3.x as the default. @@ -129,6 +141,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + with: + fetch-depth: 30 + - run: tools/undrop_submodules.sh - uses: actions/setup-python@v6 # Python 3.12 is the default for ubuntu-24.04, but that has compatibility issues with settrace tests. # Can remove this step when ubuntu-latest uses a more recent Python 3.x as the default. @@ -148,6 +163,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + with: + fetch-depth: 30 + - run: tools/undrop_submodules.sh - uses: actions/setup-python@v6 # Python 3.12 is the default for ubuntu-24.04, but that has compatibility issues with settrace tests. # Can remove this step when ubuntu-latest uses a more recent Python 3.x as the default. @@ -167,6 +185,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + with: + fetch-depth: 30 + - run: tools/undrop_submodules.sh - name: Build run: tools/ci.sh unix_float_build - name: Run main test suite @@ -179,6 +200,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + with: + fetch-depth: 30 + - run: tools/undrop_submodules.sh - name: Build run: tools/ci.sh unix_gil_enabled_build - name: Run main test suite @@ -191,6 +215,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + with: + fetch-depth: 30 + - run: tools/undrop_submodules.sh - name: Install packages run: tools/ci.sh unix_clang_setup - name: Build @@ -205,6 +232,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + with: + fetch-depth: 30 + - run: tools/undrop_submodules.sh - name: Install packages run: tools/ci.sh unix_clang_setup - name: Build @@ -219,6 +249,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + with: + fetch-depth: 30 + - run: tools/undrop_submodules.sh - uses: actions/setup-python@v6 # Python 3.12 is the default for ubuntu-24.04, but that has compatibility issues with settrace tests. # Can remove this step when ubuntu-latest uses a more recent Python 3.x as the default. @@ -236,6 +269,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + with: + fetch-depth: 30 + - run: tools/undrop_submodules.sh - uses: actions/setup-python@v6 # Python 3.12 is the default for ubuntu-24.04, but that has compatibility issues with settrace tests. # Can remove this step when ubuntu-latest uses a more recent Python 3.x as the default. @@ -255,6 +291,9 @@ jobs: runs-on: macos-26 steps: - uses: actions/checkout@v6 + with: + fetch-depth: 30 + - run: tools/undrop_submodules.sh - uses: actions/setup-python@v6 with: python-version: '3.8' @@ -270,6 +309,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + with: + fetch-depth: 30 + - run: tools/undrop_submodules.sh - uses: actions/setup-python@v6 # Python 3.12 is the default for ubuntu-24.04, but that has compatibility issues with settrace tests. # Can remove this step when ubuntu-latest uses a more recent Python 3.x as the default. @@ -289,6 +331,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + with: + fetch-depth: 30 + - run: tools/undrop_submodules.sh - uses: actions/setup-python@v6 # Python 3.12 is the default for ubuntu-24.04, but that has compatibility issues with settrace tests. # Can remove this step when ubuntu-latest uses a more recent Python 3.x as the default. @@ -308,6 +353,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + with: + fetch-depth: 30 + - run: tools/undrop_submodules.sh - uses: actions/setup-python@v6 # Python 3.12 is the default for ubuntu-24.04, but that has compatibility issues with settrace tests. # Can remove this step when ubuntu-latest uses a more recent Python 3.x as the default. @@ -327,6 +375,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + with: + fetch-depth: 30 + - run: tools/undrop_submodules.sh - uses: actions/setup-python@v6 # Python 3.12 is the default for ubuntu-24.04, but that has compatibility issues with settrace tests. # Can remove this step when ubuntu-latest uses a more recent Python 3.x as the default. @@ -352,6 +403,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + with: + fetch-depth: 30 + - run: tools/undrop_submodules.sh - uses: actions/setup-python@v6 # Python 3.12 is the default for ubuntu-24.04, but that has compatibility issues with settrace tests. # Can remove this step when ubuntu-latest uses a more recent Python 3.x as the default. diff --git a/.github/workflows/ports_webassembly.yml b/.github/workflows/ports_webassembly.yml deleted file mode 100644 index f6619cc8976..00000000000 --- a/.github/workflows/ports_webassembly.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: webassembly port - -on: - push: - pull_request: - paths: - - '.github/workflows/*.yml' - - 'tools/**' - - 'py/**' - - 'extmod/**' - - 'shared/**' - - 'lib/**' - - 'ports/webassembly/**' - - 'tests/**' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - - name: Install packages - run: tools/ci.sh webassembly_setup - - name: Build - run: tools/ci.sh webassembly_build - - name: Run tests - run: tools/ci.sh webassembly_run_tests - - name: Print failures - if: failure() - run: tests/run-tests.py --print-failures diff --git a/.github/workflows/ports_windows.yml b/.github/workflows/ports_windows.yml deleted file mode 100644 index 5318a851981..00000000000 --- a/.github/workflows/ports_windows.yml +++ /dev/null @@ -1,157 +0,0 @@ -name: windows port - -on: - push: - pull_request: - paths: - - '.github/workflows/*.yml' - - 'tools/**' - - 'py/**' - - 'extmod/**' - - 'shared/**' - - 'lib/**' - - 'ports/unix/**' - - 'ports/windows/**' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - build-vs: - strategy: - fail-fast: false - matrix: - platform: [x86, x64] - configuration: [Debug, Release] - variant: [dev, standard] - visualstudio: ['2017', '2019', '2022'] - include: - - visualstudio: '2017' - vs_version: '[15, 16)' - custom_vs_install: true - - visualstudio: '2019' - vs_version: '[16, 17)' - custom_vs_install: true - - visualstudio: '2022' - vs_version: '[17, 18)' - # trim down the number of jobs in the matrix - exclude: - - variant: standard - configuration: Debug - - visualstudio: '2019' - configuration: Debug - runs-on: windows-latest - env: - CI_BUILD_CONFIGURATION: ${{ matrix.configuration }} - steps: - - name: Install Python 3.11 - # As of 20260112 the default Python version in Windows image is 3.12, which breaks settrace tests - # Use 3.11 for now - uses: actions/setup-python@v6 - with: - python-version: '3.11' - - name: Install Visual Studio ${{ matrix.visualstudio }} - if: matrix.custom_vs_install - shell: bash - # Shell functions in this block are to retry intermittent corrupt - # downloads (with a clean download dir) before failing the job outright - run: | - try () { ($@) || ($@) || ($@) || ($@) } - clean_install () ( rm -rf $TEMP/chocolatey; choco install $1 ) - try clean_install visualstudio${{ matrix.visualstudio }}buildtools - try clean_install visualstudio${{ matrix.visualstudio }}-workload-vctools - try clean_install windows-sdk-8.1 - - uses: microsoft/setup-msbuild@v2 - with: - vs-version: ${{ matrix.vs_version }} - - uses: actions/checkout@v6 - - name: Build mpy-cross.exe - run: msbuild mpy-cross\mpy-cross.vcxproj -maxcpucount -property:Configuration=${{ matrix.configuration }} -property:Platform=${{ matrix.platform }} - - name: Update submodules - run: git submodule update --init lib/micropython-lib - - name: Build micropython.exe - run: msbuild ports\windows\micropython.vcxproj -maxcpucount -property:Configuration=${{ matrix.configuration }} -property:Platform=${{ matrix.platform }} -property:PyVariant=${{ matrix.variant }} - - name: Get micropython.exe path - id: get_path - run: | - $exePath="$(msbuild ports\windows\micropython.vcxproj -nologo -v:m -t:ShowTargetPath -property:Configuration=${{ matrix.configuration }} -property:Platform=${{ matrix.platform }} -property:PyVariant=${{ matrix.variant }})" - echo ("micropython=" + $exePath.Trim()) >> $env:GITHUB_OUTPUT - - name: Run tests - id: test - env: - MICROPY_MICROPYTHON: ${{ steps.get_path.outputs.micropython }} - working-directory: tests - run: python run-tests.py - - name: Print failures - if: failure() && steps.test.conclusion == 'failure' - working-directory: tests - run: python run-tests.py --print-failures - - name: Run mpy tests - id: test_mpy - env: - MICROPY_MICROPYTHON: ${{ steps.get_path.outputs.micropython }} - working-directory: tests - run: python run-tests.py --via-mpy -d basics float micropython - - name: Print mpy failures - if: failure() && steps.test_mpy.conclusion == 'failure' - working-directory: tests - run: python run-tests.py --print-failures - - build-mingw: - strategy: - fail-fast: false - matrix: - variant: [dev, standard] - sys: [mingw32, mingw64] - include: - - sys: mingw32 - env: i686 - - sys: mingw64 - env: x86_64 - runs-on: windows-latest - env: - CHERE_INVOKING: enabled_from_arguments - defaults: - run: - shell: msys2 {0} - steps: - - uses: actions/setup-python@v6 - # note: can go back to installing mingw-w64-${{ matrix.env }}-python after - # MSYS2 updates to Python >3.12 (due to settrace compatibility issue) - with: - python-version: '3.11' - - uses: msys2/setup-msys2@v2 - with: - msystem: ${{ matrix.sys }} - update: true - install: >- - make - mingw-w64-${{ matrix.env }}-gcc - pkg-config - git - diffutils - path-type: inherit # Remove when setup-python is removed - - uses: actions/checkout@v6 - - name: Build mpy-cross.exe - run: make -C mpy-cross -j2 - - name: Update submodules - run: make -C ports/windows VARIANT=${{ matrix.variant }} submodules - - name: Build micropython.exe - run: make -C ports/windows -j2 VARIANT=${{ matrix.variant }} - - name: Run tests - id: test - run: make -C ports/windows test_full VARIANT=${{ matrix.variant }} - - name: Print failures - if: failure() && steps.test.conclusion == 'failure' - working-directory: tests - run: python run-tests.py --print-failures - - cross-build-on-linux: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - - name: Install packages - run: tools/ci.sh windows_setup - - name: Build - run: tools/ci.sh windows_build diff --git a/.github/workflows/ports_zephyr.yml b/.github/workflows/ports_zephyr.yml deleted file mode 100644 index 330121d1de6..00000000000 --- a/.github/workflows/ports_zephyr.yml +++ /dev/null @@ -1,64 +0,0 @@ -name: zephyr port - -on: - push: - pull_request: - paths: - - '.github/workflows/ports_zephyr.yml' - - 'tools/**' - - 'py/**' - - 'extmod/**' - - 'shared/**' - - 'lib/**' - - 'ports/zephyr/**' - - 'tests/**' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: jlumbroso/free-disk-space@main - with: - # Only free up a few things so this step runs quickly. - # (android would save 9.6GiB, but takes about 13m) - # (large-packages would save 4.6GiB, but takes about 3m) - android: false - dotnet: true - haskell: true - large-packages: false - docker-images: false - tool-cache: true - swap-storage: false - - uses: actions/checkout@v6 - - id: versions - name: Read Zephyr version - run: source tools/ci.sh && echo "ZEPHYR=$ZEPHYR_VERSION" | tee "$GITHUB_OUTPUT" - - name: Cached Zephyr Workspace - id: cache_workspace - uses: actions/cache@v5 - with: - # note that the Zephyr CI docker image is 15GB. At time of writing - # GitHub caches are limited to 10GB total for a project. So we only - # cache the "workspace" - path: ./zephyrproject - key: zephyr-workspace-${{ steps.versions.outputs.ZEPHYR }} - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: zephyr - - name: Install packages - run: tools/ci.sh zephyr_setup - - name: Install Zephyr - if: steps.cache_workspace.outputs.cache-hit != 'true' - run: tools/ci.sh zephyr_install - - name: Build - run: tools/ci.sh zephyr_build - - name: Run main test suite - run: tools/ci.sh zephyr_run_tests - - name: Print failures - if: failure() - run: tests/run-tests.py --print-failures diff --git a/tests/extmod/btree_closed.py.exp b/tests/extmod/btree_closed.py.exp index 312edfd13db..13789685553 100644 --- a/tests/extmod/btree_closed.py.exp +++ b/tests/extmod/btree_closed.py.exp @@ -2,4 +2,4 @@ ValueError ValueError ValueError ValueError - + diff --git a/tests/extmod/deflate_compress.py b/tests/extmod/deflate_compress.py deleted file mode 100644 index 981a986cbf5..00000000000 --- a/tests/extmod/deflate_compress.py +++ /dev/null @@ -1,154 +0,0 @@ -try: - # Check if deflate is available. - import deflate - import io -except ImportError: - print("SKIP") - raise SystemExit - -# Check if compression is enabled. -if not hasattr(deflate.DeflateIO, "write"): - print("SKIP") - raise SystemExit - -# Simple compression & decompression. -b = io.BytesIO() -g = deflate.DeflateIO(b, deflate.RAW) -data = b"micropython" -N = 10 -for i in range(N): - g.write(data) -g.close() -result_raw = b.getvalue() -print(len(result_raw) < len(data) * N) -b = io.BytesIO(result_raw) -g = deflate.DeflateIO(b, deflate.RAW) -print(g.read()) - -# Same, but using a context manager. -b = io.BytesIO() -with deflate.DeflateIO(b, deflate.RAW) as g: - for i in range(N): - g.write(data) -result_raw = b.getvalue() -print(len(result_raw) < len(data) * N) -b = io.BytesIO(result_raw) -with deflate.DeflateIO(b, deflate.RAW) as g: - print(g.read()) - -# Writing to a closed underlying stream. -b = io.BytesIO() -g = deflate.DeflateIO(b, deflate.RAW) -g.write(b"micropython") -b.close() -try: - g.write(b"micropython") -except ValueError: - print("ValueError") - -# Writing to a closed DeflateIO. -b = io.BytesIO() -g = deflate.DeflateIO(b, deflate.RAW) -g.write(b"micropython") -g.close() -try: - g.write(b"micropython") -except OSError: - print("OSError") - - -def decompress(data, *args): - buf = io.BytesIO(data) - with deflate.DeflateIO(buf, *args) as g: - return g.read() - - -def compress(data, *args): - b = io.BytesIO() - with deflate.DeflateIO(b, *args) as g: - g.write(data) - return b.getvalue() - - -def compress_error(data, *args): - try: - compress(data, *args) - except OSError: - print("OSError") - except ValueError: - print("ValueError") - - -# More test patterns. -PATTERNS_RAW = ( - (b"0", b"3\x00\x00"), - (b"a", b"K\x04\x00"), - (b"0" * 100, b"3\xa0\x03\x00\x00"), - ( - bytes(range(64)), - b"c`dbfaec\xe7\xe0\xe4\xe2\xe6\xe1\xe5\xe3\x17\x10\x14\x12\x16\x11\x15\x13\x97\x90\x94\x92\x96\x91\x95\x93WPTRVQUS\xd7\xd0\xd4\xd2\xd6\xd1\xd5\xd370426153\xb7\xb0\xb4\xb2\xb6\xb1\xb5\xb3\x07\x00", - ), -) -for unpacked, packed in PATTERNS_RAW: - print(compress(unpacked) == packed) - print(compress(unpacked, deflate.RAW) == packed) - -# Verify header and checksum format. -unpacked = b"hello" -packed = b"\xcbH\xcd\xc9\xc9\x07\x00" - - -def check_header(n, a, b): - if a == b: - print(n) - else: - print(n, a, b) - - -check_header("RAW", compress(unpacked, deflate.RAW), packed) -check_header( - "ZLIB(9)", compress(unpacked, deflate.ZLIB, 9), b"\x18\x95" + packed + b"\x06,\x02\x15" -) -check_header( - "ZLIB(15)", compress(unpacked, deflate.ZLIB, 15), b"\x78\x9c" + packed + b"\x06,\x02\x15" -) -check_header( - "GZIP", - compress(unpacked, deflate.GZIP, 9), - b"\x1f\x8b\x08\x00\x00\x00\x00\x00\x04\x03" + packed + b"\x86\xa6\x106\x05\x00\x00\x00", -) - -# Valid wbits values. -compress_error(unpacked, deflate.RAW, -1) -print(len(compress(unpacked, deflate.RAW, 0))) -compress_error(unpacked, deflate.RAW, 1) -compress_error(unpacked, deflate.RAW, 4) -for i in range(5, 16): - print(len(compress(unpacked, deflate.RAW, i))) -compress_error(unpacked, deflate.RAW, 16) - -# Invalid values for format. -compress_error(unpacked, -1) -compress_error(unpacked, 5) - -# Fill buf with a predictable pseudorandom sequence. -buf = bytearray(1024) -lfsr = 1 << 15 | 1 -for i in range(len(buf)): - bit = (lfsr ^ (lfsr >> 1) ^ (lfsr >> 3) ^ (lfsr >> 12)) & 1 - lfsr = (lfsr >> 1) | (bit << 15) - buf[i] = lfsr & 0xFF - -# Verify that compression improves as the window size increases. -prev_len = len(buf) -for wbits in range(5, 10): - result = compress(buf, deflate.RAW, wbits) - next_len = len(result) - print(next_len < prev_len and decompress(result, deflate.RAW, wbits) == buf) - prev_len = next_len - -# Verify that compression is optimal: in the bytes below, the final "123" should be -# compressed by referencing the "123" just before it, and not the one all the way back -# at the start of the bytes. -compressed = compress(b"1234567890abcdefghijklmnopqrstuvwxyz123123", deflate.RAW) -print(len(compressed), compressed) diff --git a/tests/extmod/deflate_compress.py.exp b/tests/extmod/deflate_compress.py.exp deleted file mode 100644 index 7b00fa3cb29..00000000000 --- a/tests/extmod/deflate_compress.py.exp +++ /dev/null @@ -1,42 +0,0 @@ -True -b'micropythonmicropythonmicropythonmicropythonmicropythonmicropythonmicropythonmicropythonmicropythonmicropython' -True -b'micropythonmicropythonmicropythonmicropythonmicropythonmicropythonmicropythonmicropythonmicropythonmicropython' -ValueError -OSError -True -True -True -True -True -True -True -True -RAW -ZLIB(9) -ZLIB(15) -GZIP -ValueError -7 -ValueError -ValueError -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -ValueError -ValueError -ValueError -False -True -True -True -True -41 b'3426153\xb7\xb04HLJNIMK\xcf\xc8\xcc\xca\xce\xc9\xcd\xcb/(,*.)-+\xaf\xa8\xac\x02\xaa\x01"\x00' diff --git a/tests/extmod/deflate_compress_memory_error.py b/tests/extmod/deflate_compress_memory_error.py deleted file mode 100644 index 19bef87bff3..00000000000 --- a/tests/extmod/deflate_compress_memory_error.py +++ /dev/null @@ -1,39 +0,0 @@ -# Test deflate.DeflateIO compression, with out-of-memory errors. - -try: - # Check if deflate is available. - import deflate - import io -except ImportError: - print("SKIP") - raise SystemExit - -# Check if compression is enabled. -if not hasattr(deflate.DeflateIO, "write"): - print("SKIP") - raise SystemExit - -# Create a compressor object. -b = io.BytesIO() -g = deflate.DeflateIO(b, deflate.RAW, 15) - -# Then, use up most of the heap. -l = [] -while True: - try: - l.append(bytearray(1000)) - except: - break -l.pop() - -# Try to compress. This will try to allocate a large window and fail. -try: - g.write("test") -except MemoryError: - print("MemoryError") - -# Should still be able to close the stream. -g.close() - -# The underlying output stream should be unchanged. -print(b.getvalue()) diff --git a/tests/extmod/deflate_compress_memory_error.py.exp b/tests/extmod/deflate_compress_memory_error.py.exp deleted file mode 100644 index 606315c1460..00000000000 --- a/tests/extmod/deflate_compress_memory_error.py.exp +++ /dev/null @@ -1,2 +0,0 @@ -MemoryError -b'' diff --git a/tests/extmod/deflate_decompress.py b/tests/extmod/deflate_decompress.py deleted file mode 100644 index 3ac8880af26..00000000000 --- a/tests/extmod/deflate_decompress.py +++ /dev/null @@ -1,185 +0,0 @@ -try: - # Check if deflate is available. - import deflate - import io -except ImportError: - print("SKIP") - raise SystemExit - -try: - # Check there's enough memory to deflate gzip streams. - # zlib.compress(b'', wbits=25) - empty_gzip = ( - b"\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00" - ) - deflate.DeflateIO(io.BytesIO(empty_gzip)).read() -except MemoryError: - print("SKIP") - raise SystemExit - -# zlib.compress(b'micropython hello world hello world micropython', wbits=-9) -data_raw = b'\xcb\xcdL.\xca/\xa8,\xc9\xc8\xcfS\xc8H\xcd\xc9\xc9W(\xcf/\xcaIAa\xe7"\xd4\x00\x00' -# zlib.compress(b'micropython hello world hello world micropython', wbits=9) -data_zlib = b'\x18\x95\xcb\xcdL.\xca/\xa8,\xc9\xc8\xcfS\xc8H\xcd\xc9\xc9W(\xcf/\xcaIAa\xe7"\xd4\x00\x00\xbc\xfa\x12\x91' -# zlib.compress(b'micropython hello world hello world micropython', wbits=25) -data_gzip = b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\xcb\xcdL.\xca/\xa8,\xc9\xc8\xcfS\xc8H\xcd\xc9\xc9W(\xcf/\xcaIAa\xe7"\xd4\x00\x00"\xeb\xc4\x98/\x00\x00\x00' - -# compress(b'hello' + bytearray(300) + b'hello', format=deflate.RAW, 5) -data_wbits_5 = b"\xcbH\xcd\xc9\xc9g\x18\xe9\x00\x08\x88\x95\xcfH\xcd\xc9\xc9\x07\x00" -# compress(b'hello' + bytearray(300) + b'hello', format=deflate.RAW, 6) -data_wbits_6 = b"\xcbH\xcd\xc9\xc9g\x18\xe9\x00\x08\x88\xd5\x9f\x91\x9a\x93\x93\x0f\x00" -# compress(b'hello' + bytearray(300) + b'hello', format=deflate.RAW, 8) -data_wbits_8 = b"\xcbH\xcd\xc9\xc9g\x18\xe9\x00\x08\x88\xf5\x7fFjNN>\x00" -# compress(b'hello' + bytearray(2000) + b'hello', format=deflate.RAW, 10) -data_wbits_10 = b"\xcbH\xcd\xc9\xc9g\x18\xe9\x00\x08Fz\x18\x00\xc3`\xa4'\x03`2\x18\xe99\x01\x98\x13Fz\xfe\x07\xe6\xff\x91\x9e\xff\x81\xf9\x7f\xa4\xe7\x7f`\xfe\x1f\xba\xf9?#5''\x1f\x00" - - -def decompress(data, *args): - buf = io.BytesIO(data) - with deflate.DeflateIO(buf, *args) as g: - return g.read() - - -def decompress_error(data, *args): - try: - decompress(data, *args) - except OSError: - print("OSError") - except EOFError: - print("EOFError") - except ValueError: - print("ValueError") - - -# Basic handling of format and detection. -print(decompress(data_raw, deflate.RAW)) -print(decompress(data_zlib, deflate.ZLIB)) -print(decompress(data_gzip, deflate.GZIP)) -print(decompress(data_zlib)) # detect zlib/gzip. -print(decompress(data_gzip)) # detect zlib/gzip. - -decompress_error(data_raw) # cannot detect zlib/gzip from raw stream -decompress_error(data_raw, deflate.ZLIB) -decompress_error(data_raw, deflate.GZIP) -decompress_error(data_zlib, deflate.RAW) -decompress_error(data_zlib, deflate.GZIP) -decompress_error(data_gzip, deflate.RAW) -decompress_error(data_gzip, deflate.ZLIB) - -# Invalid data stream. -decompress_error(b"abcef", deflate.RAW) - -# Invalid block type. final-block, block-type=3. -decompress_error(b"\x07", deflate.RAW) - -# Truncated stream. -decompress_error(data_raw[:10], deflate.RAW) - -# Partial reads. -buf = io.BytesIO(data_zlib) -with deflate.DeflateIO(buf) as g: - print(buf.seek(0, 1)) # verify stream is not read until first read of the DeflateIO stream. - print(g.read(1)) - print(buf.seek(0, 1)) # verify that only the minimal amount is read from the source - print(g.read(1)) - print(buf.seek(0, 1)) - print(g.read(2)) - print(buf.seek(0, 1)) - print(g.read()) - print(buf.seek(0, 1)) - print(g.read(1)) - print(buf.seek(0, 1)) - print(g.read()) - -# Invalid zlib checksum (+ length for gzip). Note: only checksum errors are -# currently detected, see the end of uzlib_uncompress_chksum(). -decompress_error(data_zlib[:-4] + b"\x00\x00\x00\x00") -decompress_error(data_gzip[:-8] + b"\x00\x00\x00\x00\x00\x00\x00\x00") -decompress_error(data_zlib[:-4] + b"\x00\x00\x00\x00", deflate.ZLIB) -decompress_error(data_gzip[:-8] + b"\x00\x00\x00\x00\x00\x00\x00\x00", deflate.GZIP) - -# Reading from a closed underlying stream. -b = io.BytesIO(data_raw) -g = deflate.DeflateIO(b, deflate.RAW) -g.read(4) -b.close() -try: - g.read(4) -except ValueError: - print("ValueError") - -# Reading from a closed DeflateIO. -b = io.BytesIO(data_raw) -g = deflate.DeflateIO(b, deflate.RAW) -g.read(4) -g.close() -try: - g.read(4) -except OSError: - print("OSError") - -# Gzip header with extra flags (FCOMMENT FNAME FEXTRA FHCRC) enabled. -data_gzip_header_extra = b"\x1f\x8b\x08\x1e}\x9a\x9bd\x02\x00\x00\x00\x00\x00\x00\xff\xcb\xcdL.\xca/\xa8,\xc9\xc8\xcf\x03\x00\xf2KF>\x0b\x00\x00\x00" -print(decompress(data_gzip_header_extra)) - -# Test patterns. -PATTERNS_ZLIB = [ - # Packed results produced by CPy's zlib.compress() - (b"0", b"x\x9c3\x00\x00\x001\x001"), - (b"a", b"x\x9cK\x04\x00\x00b\x00b"), - (b"0" * 100, b"x\x9c30\xa0=\x00\x00\xb3q\x12\xc1"), - ( - bytes(range(64)), - b"x\x9cc`dbfaec\xe7\xe0\xe4\xe2\xe6\xe1\xe5\xe3\x17\x10\x14\x12\x16\x11\x15\x13\x97\x90\x94\x92\x96\x91\x95\x93WPTRVQUS\xd7\xd0\xd4\xd2\xd6\xd1\xd5\xd370426153\xb7\xb0\xb4\xb2\xb6\xb1\xb5\xb3\x07\x00\xaa\xe0\x07\xe1", - ), - (b"hello", b"x\x01\x01\x05\x00\xfa\xffhello\x06,\x02\x15"), # compression level 0 - # adaptive/dynamic huffman tree - ( - b"13371813150|13764518736|12345678901", - b"x\x9c\x05\xc1\x81\x01\x000\x04\x04\xb1\x95\\\x1f\xcfn\x86o\x82d\x06Qq\xc8\x9d\xc5X}I}\x00\x951D>I}\x00\x951D>I}\x00\x951D>I}\x00\x951D", - b"x\x9c\x05\xc11\x01\x00\x00\x00\x010\x95\x14py\x84\x12C_\x9bR\x8cV\x8a\xd1J1Z)F\x1fw`\x089", - ), -] -for unpacked, packed in PATTERNS_ZLIB: - print(decompress(packed) == unpacked) - print(decompress(packed, deflate.ZLIB) == unpacked) - -# Older version's of CPython's zlib module still included the checksum and length (as if it were a zlib/gzip stream). -# Make sure there're no problem decompressing this. -data_raw_with_footer = data_raw + b"\x00\x00\x00\x00\x00\x00\x00\x00" -print(decompress(data_raw_with_footer, deflate.RAW)) - -# Valid wbits values. -decompress_error(data_wbits_5, deflate.RAW, -1) -print(len(decompress(data_wbits_5, deflate.RAW, 0))) -decompress_error(data_wbits_5, deflate.RAW, 1) -decompress_error(data_wbits_5, deflate.RAW, 4) -for i in range(5, 16): - print(len(decompress(data_wbits_5, deflate.RAW, i))) -decompress_error(data_wbits_5, deflate.RAW, 16) - -# Invalid values for format. -decompress_error(data_raw, -1) -decompress_error(data_raw, 5) - -# Data that requires a higher wbits value. -decompress_error(data_wbits_6, deflate.RAW, 5) -print(len(decompress(data_wbits_6, deflate.RAW, 6))) -print(len(decompress(data_wbits_6, deflate.RAW, 7))) -decompress_error(data_wbits_8, deflate.RAW, 7) -print(len(decompress(data_wbits_8, deflate.RAW, 8))) -print(len(decompress(data_wbits_8, deflate.RAW, 9))) -decompress_error(data_wbits_10, deflate.RAW) -decompress_error(data_wbits_10, deflate.RAW, 9) -print(len(decompress(data_wbits_10, deflate.RAW, 10))) - -# zlib header sets the size, so works with wbits unset or wbits >= 10. -data_wbits_10_zlib = b"(\x91\xcbH\xcd\xc9\xc9g\x18\xe9\x00\x08Fz\x18\x00\xc3`\xa4'\x03`2\x18\xe99\x01\x98\x13Fz\xfe\x07\xe6\xff\x91\x9e\xff\x81\xf9\x7f\xa4\xe7\x7f`\xfe\x1f\xba\xf9?#5''\x1f\x00[\xbc\x04)" -print(len(decompress(data_wbits_10_zlib, deflate.ZLIB))) -decompress_error(data_wbits_10_zlib, deflate.ZLIB, 9) -print(len(decompress(data_wbits_10_zlib, deflate.ZLIB, 10))) -print(len(decompress(data_wbits_10_zlib))) diff --git a/tests/extmod/deflate_decompress.py.exp b/tests/extmod/deflate_decompress.py.exp deleted file mode 100644 index 381f2b06859..00000000000 --- a/tests/extmod/deflate_decompress.py.exp +++ /dev/null @@ -1,80 +0,0 @@ -b'micropython hello world hello world micropython' -b'micropython hello world hello world micropython' -b'micropython hello world hello world micropython' -b'micropython hello world hello world micropython' -b'micropython hello world hello world micropython' -OSError -OSError -OSError -OSError -OSError -OSError -OSError -OSError -OSError -EOFError -0 -b'm' -4 -b'i' -5 -b'cr' -7 -b'opython hello world hello world micropython' -36 -b'' -36 -b'' -OSError -OSError -OSError -OSError -ValueError -OSError -b'micropython' -True -True -True -True -True -True -True -True -True -True -True -True -True -True -b'micropython hello world hello world micropython' -ValueError -310 -ValueError -ValueError -310 -310 -310 -310 -310 -310 -310 -310 -310 -310 -310 -ValueError -ValueError -ValueError -OSError -310 -310 -OSError -310 -310 -OSError -OSError -2010 -2010 -OSError -2010 -2010 diff --git a/tests/extmod/deflate_stream_error.py b/tests/extmod/deflate_stream_error.py deleted file mode 100644 index aee6b280333..00000000000 --- a/tests/extmod/deflate_stream_error.py +++ /dev/null @@ -1,89 +0,0 @@ -# Test deflate module with stream errors. - -try: - # Check if deflate & IOBase are available. - import deflate, io - - io.IOBase -except (ImportError, AttributeError): - print("SKIP") - raise SystemExit - -# Check if compression is enabled. -if not hasattr(deflate.DeflateIO, "write"): - print("SKIP") - raise SystemExit - -formats = (deflate.RAW, deflate.ZLIB, deflate.GZIP) - -# Test error on read when decompressing. - - -class Stream(io.IOBase): - def readinto(self, buf): - print("Stream.readinto", len(buf)) - return -1 - - -try: - deflate.DeflateIO(Stream()).read() -except OSError as er: - print(repr(er)) - -# Test error on write when compressing. - - -class Stream(io.IOBase): - def write(self, buf): - print("Stream.write", buf) - return -1 - - -for format in formats: - try: - deflate.DeflateIO(Stream(), format).write("a") - except OSError as er: - print(repr(er)) - -# Test write after close. - - -class Stream(io.IOBase): - def write(self, buf): - print("Stream.write", buf) - return -1 - - def ioctl(self, cmd, arg): - print("Stream.ioctl", cmd, arg) - return 0 - - -try: - d = deflate.DeflateIO(Stream(), deflate.RAW, 0, True) - d.close() - d.write("a") -except OSError as er: - print(repr(er)) - -# Test error on write when closing. - - -class Stream(io.IOBase): - def __init__(self): - self.num_writes = 0 - - def write(self, buf): - print("Stream.write", buf) - if self.num_writes >= 4: - return -1 - self.num_writes += 1 - return len(buf) - - -for format in formats: - d = deflate.DeflateIO(Stream(), format) - d.write("a") - try: - d.close() - except OSError as er: - print(repr(er)) diff --git a/tests/extmod/deflate_stream_error.py.exp b/tests/extmod/deflate_stream_error.py.exp deleted file mode 100644 index 4ec90d79977..00000000000 --- a/tests/extmod/deflate_stream_error.py.exp +++ /dev/null @@ -1,25 +0,0 @@ -Stream.readinto 1 -OSError(1,) -Stream.write bytearray(b'K') -OSError(1,) -Stream.write bytearray(b'\x18\x95') -OSError(22,) -Stream.write bytearray(b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x04\x03') -OSError(22,) -Stream.ioctl 4 0 -OSError(22,) -Stream.write bytearray(b'K') -Stream.write bytearray(b'\x04') -Stream.write bytearray(b'\x00') -Stream.write bytearray(b'\x18\x95') -Stream.write bytearray(b'K') -Stream.write bytearray(b'\x04') -Stream.write bytearray(b'\x00') -Stream.write bytearray(b'\x00b\x00b') -OSError(1,) -Stream.write bytearray(b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x04\x03') -Stream.write bytearray(b'K') -Stream.write bytearray(b'\x04') -Stream.write bytearray(b'\x00') -Stream.write bytearray(b'C\xbe\xb7\xe8\x01\x00\x00\x00') -OSError(1,) diff --git a/tests/extmod/uctypes_print.py.exp b/tests/extmod/uctypes_print.py.exp index 63daefc848e..b1c730d44f8 100644 --- a/tests/extmod/uctypes_print.py.exp +++ b/tests/extmod/uctypes_print.py.exp @@ -1,4 +1,4 @@ - - - - + + + + diff --git a/tests/micropython/meminfo.py.exp b/tests/micropython/meminfo.py.exp index a229a7fa4ca..fb9eaa890aa 100644 --- a/tests/micropython/meminfo.py.exp +++ b/tests/micropython/meminfo.py.exp @@ -6,7 +6,7 @@ mem: total=\\d\+, current=\\d\+, peak=\\d\+ stack: \\d\+ out of \\d\+ GC: total: \\d\+, used: \\d\+, free: \\d\+ No. of 1-blocks: \\d\+, 2-blocks: \\d\+, max blk sz: \\d\+, max free sz: \\d\+ -GC memory layout; from \[0-9a-f\]\+: +GC memory layout; from 0x\[0-9a-f\]\+: ######## qstr pool: n_pool=1, n_qstr=\\d, n_str_data_bytes=\\d\+, n_total_bytes=\\d\+ qstr pool: n_pool=1, n_qstr=\\d, n_str_data_bytes=\\d\+, n_total_bytes=\\d\+ diff --git a/tests/misc/sys_settrace_cov.py.exp b/tests/misc/sys_settrace_cov.py.exp index 423d78ec42b..4e8e54c3881 100644 --- a/tests/misc/sys_settrace_cov.py.exp +++ b/tests/misc/sys_settrace_cov.py.exp @@ -1,2 +1,2 @@ -FRAME +FRAME LASTI \\d\+ diff --git a/tests/ports/unix/extra_coverage.py.exp b/tests/ports/unix/extra_coverage.py.exp index 1c3fe1558f2..21db6835e08 100644 --- a/tests/ports/unix/extra_coverage.py.exp +++ b/tests/ports/unix/extra_coverage.py.exp @@ -7,8 +7,8 @@ 7fffffffffffffff 7FFFFFFFFFFFFFFF 18446744073709551615 -789f -789F +0x789f +0x789F ab abc ' abc' ' True' 'Tru' false true @@ -21,7 +21,7 @@ abc % .a . <%> - +<0xaaaa> <43690> <43690> @@ -31,12 +31,12 @@ abc <9223372036854775807> # GC -0 +0x0 0 # GC part 2 pass # tracked allocation -m_tracked_head = 0 +m_tracked_head = 0x0 0 1 1 1 2 1 @@ -53,7 +53,7 @@ m_tracked_head = 0 5 1 6 1 7 1 -m_tracked_head = 0 +m_tracked_head = 0x0 # vstr tests sts diff --git a/tests/thread/thread_exc2.py.exp b/tests/thread/thread_exc2.py.exp index 469516dacc0..8869403e8f7 100644 --- a/tests/thread/thread_exc2.py.exp +++ b/tests/thread/thread_exc2.py.exp @@ -1,4 +1,4 @@ -Unhandled exception in thread started by +Unhandled exception in thread started by Traceback (most recent call last): File \.\+, line 7, in thread_entry ValueError: diff --git a/tests/thread/thread_exc2.py.native.exp b/tests/thread/thread_exc2.py.native.exp index 9b2e715ef8d..e9cb04f668a 100644 --- a/tests/thread/thread_exc2.py.native.exp +++ b/tests/thread/thread_exc2.py.native.exp @@ -1,3 +1,3 @@ -Unhandled exception in thread started by +Unhandled exception in thread started by ValueError: done diff --git a/tools/ci.sh b/tools/ci.sh index 056f6a6102d..36baf54397b 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -967,7 +967,7 @@ function ci_unix_qemu_riscv64_run_tests { file ./ports/unix/build-coverage/micropython pushd tests MICROPY_MICROPYTHON=../ports/unix/build-coverage/micropython ./run-tests.py --exclude 'thread/stress_aes.py' - MICROPY_MICROPYTHON=../ports/unix/build-coverage/micropython ./run-natmodtests.py extmod/btree*.py extmod/deflate*.py extmod/framebuf*.py extmod/heapq*.py extmod/random_basic*.py extmod/re*.py + MICROPY_MICROPYTHON=../ports/unix/build-coverage/micropython ./run-natmodtests.py extmod/btree*.py extmod/framebuf*.py extmod/heapq*.py extmod/random_basic*.py extmod/re*.py popd } diff --git a/tools/undrop_submodules.sh b/tools/undrop_submodules.sh new file mode 100755 index 00000000000..f443a84c932 --- /dev/null +++ b/tools/undrop_submodules.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +git config --global user.email "nobody@satoshilabs.com" +git config --global user.name "nobody" +COMMIT=`git log --pretty=oneline | grep "drop unwanted submodules" | head -n1 | grep -v Revert | cut -d ' ' -f 1` +git revert --no-edit "$COMMIT" From 8841470bfbc3d2af0052366d04aea6265fb57c74 Mon Sep 17 00:00:00 2001 From: Martin Milata Date: Wed, 29 Jul 2026 22:31:14 +0200 Subject: [PATCH 21/22] extmod/modvfs: Fix build without FFCONF_H Signed-off-by: Martin Milata --- extmod/modvfs.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/extmod/modvfs.c b/extmod/modvfs.c index 41841f05569..01afb95e21e 100644 --- a/extmod/modvfs.c +++ b/extmod/modvfs.c @@ -29,10 +29,22 @@ #if MICROPY_PY_VFS #include "extmod/vfs.h" + +#if MICROPY_VFS_FAT #include "extmod/vfs_fat.h" +#endif + +#if MICROPY_VFS_LFS1 || MICROPY_VFS_LFS2 #include "extmod/vfs_lfs.h" +#endif + +#if MICROPY_VFS_POSIX #include "extmod/vfs_posix.h" +#endif + +#if MICROPY_VFS_ROM #include "extmod/vfs_rom.h" +#endif #if !MICROPY_VFS #error "MICROPY_PY_VFS requires MICROPY_VFS" From dac0a232ff40dd64a4a865d928765a749a221e00 Mon Sep 17 00:00:00 2001 From: Martin Milata Date: Wed, 29 Jul 2026 23:07:20 +0200 Subject: [PATCH 22/22] fixup! uzlib(trezor): partially optimize decompression for speed --- lib/uzlib/tinflate.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/uzlib/tinflate.c b/lib/uzlib/tinflate.c index 71aafa4dad8..87ff336f68a 100644 --- a/lib/uzlib/tinflate.c +++ b/lib/uzlib/tinflate.c @@ -41,6 +41,7 @@ #if defined(__GNUC__) && (__GNUC__ >= 5) #define OPTIMIZE_O3 __attribute__((optimize("-O3"))) #else + #pragma message("WARNING: skipping uzlib_uncompress optimization") #define OPTIMIZE_O3 #endif