tests/unix: Add coverage tests for various GC calls.

This commit is contained in:
Damien George 2018-03-01 22:49:15 +11:00
parent 955ee6477f
commit c3f1b22338
2 changed files with 28 additions and 0 deletions

View File

@ -4,6 +4,7 @@
#include "py/obj.h" #include "py/obj.h"
#include "py/objstr.h" #include "py/objstr.h"
#include "py/runtime.h" #include "py/runtime.h"
#include "py/gc.h"
#include "py/repl.h" #include "py/repl.h"
#include "py/mpz.h" #include "py/mpz.h"
#include "py/builtin.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 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 // vstr
{ {
mp_printf(&mp_plat_print, "# vstr\n"); mp_printf(&mp_plat_print, "# vstr\n");

View File

@ -13,6 +13,10 @@ false true
80000000 80000000
80000000 80000000
abc abc
# GC
0
0
0
# vstr # vstr
tests tests
sts sts