Skip to content

Commit c3f1b22

Browse files
committed
tests/unix: Add coverage tests for various GC calls.
1 parent 955ee64 commit c3f1b22

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

ports/unix/coverage.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "py/obj.h"
55
#include "py/objstr.h"
66
#include "py/runtime.h"
7+
#include "py/gc.h"
78
#include "py/repl.h"
89
#include "py/mpz.h"
910
#include "py/builtin.h"
@@ -159,6 +160,29 @@ STATIC mp_obj_t extra_coverage(void) {
159160
mp_printf(&mp_plat_print, "abc\n%"); // string ends in middle of format specifier
160161
}
161162

163+
// GC
164+
{
165+
mp_printf(&mp_plat_print, "# GC\n");
166+
167+
// calling gc_free while GC is locked
168+
gc_lock();
169+
gc_free(NULL);
170+
gc_unlock();
171+
172+
// calling gc_realloc while GC is locked
173+
void *p = gc_alloc(4, false);
174+
gc_lock();
175+
mp_printf(&mp_plat_print, "%p\n", gc_realloc(p, 8, true));
176+
gc_unlock();
177+
178+
// using gc_realloc to resize to 0, which means free the memory
179+
p = gc_alloc(4, false);
180+
mp_printf(&mp_plat_print, "%p\n", gc_realloc(p, 0, false));
181+
182+
// calling gc_nbytes with a non-heap pointer
183+
mp_printf(&mp_plat_print, "%p\n", gc_nbytes(NULL));
184+
}
185+
162186
// vstr
163187
{
164188
mp_printf(&mp_plat_print, "# vstr\n");

tests/unix/extra_coverage.py.exp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ false true
1313
80000000
1414
80000000
1515
abc
16+
# GC
17+
0
18+
0
19+
0
1620
# vstr
1721
tests
1822
sts

0 commit comments

Comments
 (0)