diff options
author | Damien George <damien.p.george@gmail.com> | 2018-03-01 22:49:15 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2018-03-01 22:49:15 +1100 |
commit | c3f1b2233865f4e7f3016ca22a65ef9f4d4ec4db (patch) | |
tree | aa06851d4667622614546d4f1618d33b8a83ebed | |
parent | 955ee6477f4b1d3a70bfe97a1e7727848bf2d06d (diff) |
tests/unix: Add coverage tests for various GC calls.
-rw-r--r-- | ports/unix/coverage.c | 24 | ||||
-rw-r--r-- | tests/unix/extra_coverage.py.exp | 4 |
2 files changed, 28 insertions, 0 deletions
diff --git a/ports/unix/coverage.c b/ports/unix/coverage.c index f0d9406c6..db97f4f77 100644 --- a/ports/unix/coverage.c +++ b/ports/unix/coverage.c @@ -4,6 +4,7 @@ #include "py/obj.h" #include "py/objstr.h" #include "py/runtime.h" +#include "py/gc.h" #include "py/repl.h" #include "py/mpz.h" #include "py/builtin.h" @@ -159,6 +160,29 @@ STATIC mp_obj_t extra_coverage(void) { mp_printf(&mp_plat_print, "abc\n%"); // string ends in middle of format specifier } + // GC + { + mp_printf(&mp_plat_print, "# GC\n"); + + // calling gc_free while GC is locked + gc_lock(); + gc_free(NULL); + gc_unlock(); + + // calling gc_realloc while GC is locked + void *p = gc_alloc(4, false); + gc_lock(); + mp_printf(&mp_plat_print, "%p\n", gc_realloc(p, 8, true)); + gc_unlock(); + + // using gc_realloc to resize to 0, which means free the memory + p = gc_alloc(4, false); + mp_printf(&mp_plat_print, "%p\n", gc_realloc(p, 0, false)); + + // calling gc_nbytes with a non-heap pointer + mp_printf(&mp_plat_print, "%p\n", gc_nbytes(NULL)); + } + // vstr { mp_printf(&mp_plat_print, "# vstr\n"); diff --git a/tests/unix/extra_coverage.py.exp b/tests/unix/extra_coverage.py.exp index 54e19d14a..a686e7161 100644 --- a/tests/unix/extra_coverage.py.exp +++ b/tests/unix/extra_coverage.py.exp @@ -13,6 +13,10 @@ false true 80000000 80000000 abc +# GC +0 +0 +0 # vstr tests sts |