10000 unix: Enable MICROPY_GC_SPLIT_HEAP on coverage build. · micropython/micropython@d2e4cf0 · GitHub
[go: up one dir, main page]

Skip to content

Commit d2e4cf0

Browse files
rknegjensdpgeorge
authored andcommitted
unix: Enable MICROPY_GC_SPLIT_HEAP on coverage build.
With a new option to evenly split the GC heap over multiple areas. This adds code coverage for gc_add() and code associated with MICROPY_GC_SPLIT_HEAP.
1 parent 4a48531 commit d2e4cf0

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

ports/unix/main.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,22 @@ MP_NOINLINE int main_(int argc, char **argv) {
477477
pre_process_options(argc, argv);
478478

479479
#if MICROPY_ENABLE_GC
480+
#if !MICROPY_GC_SPLIT_HEAP
480481
char *heap = malloc(heap_size);
481482
gc_init(heap, heap + heap_size);
483+
#else
484+
assert(MICROPY_GC_SPLIT_HEAP_N_HEAPS > 0);
485+
char *heaps[MICROPY_GC_SPLIT_HEAP_N_HEAPS];
486+
long multi_heap_size = heap_size / MICROPY_GC_SPLIT_HEAP_N_HEAPS;
487+
for (size_t i = 0; i < MICROPY_GC_SPLIT_HEAP_N_HEAPS; i++) {
488+
heaps[i] = malloc(multi_heap_size);
489+
if (i == 0) {
490+
gc_init(heaps[i], heaps[i] + multi_heap_size);
491+
} else {
492+
gc_add(heaps[i], heaps[i] + multi_heap_size);
493+
}
494+
}
495+
#endif
482496
#endif
483497

484498
#if MICROPY_ENABLE_PYSTACK
@@ -729,7 +743,13 @@ MP_NOINLINE int main_(int argc, char **argv) {
729743
#if MICROPY_ENABLE_GC && !defined(NDEBUG)
730744
// We don't really need to free memory since we are about to exit the
731745
// process, but doing so helps to find memory leaks.
746+
#if !MICROPY_GC_SPLIT_HEAP
732747
free(heap);
748+
#else
749+
for (size_t i = 0; i < MICROPY_GC_SPLIT_HEAP_N_HEAPS; i++) {
750+
free(heaps[i]);
751+
}
752+
#endif
733753
#endif
734754

735755
// printf("total bytes = %d\n", m_get_total_bytes_allocated());

ports/unix/mpconfigport.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@
120120
#define MICROPY_EMIT_ARM (1)
121121
#endif
122122
#define MICROPY_ENABLE_GC (1)
123+
// Number of heaps to assign if MICROPY_GC_SPLIT_HEAP=1
124+
#ifndef MICROPY_GC_SPLIT_HEAP_N_HEAPS
125+
#define MICROPY_GC_SPLIT_HEAP_N_HEAPS (1)
126+
#endif
123127
#define MICROPY_MALLOC_USES_ALLOCATED_SIZE (1)
124128
#define MICROPY_MEM_STATS (1)
125129
#define MICROPY_DEBUG_PRINTERS (1)

ports/unix/variants/coverage/mpconfigvariant.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
// Enable additional features.
3434
#define MICROPY_DEBUG_PARSE_RULE_NAME (1)
35+
#define MICROPY_GC_SPLIT_HEAP (1)
36+
#define MICROPY_GC_SPLIT_HEAP_N_HEAPS (4)
3537
#define MICROPY_TRACKED_ALLOC (1)
3638
#define MICROPY_FLOAT_HIGH_QUALITY_HASH (1)
3739
#define MICROPY_REPL_EMACS_WORDS_MOVE (1)

0 commit comments

Comments
 (0)
0