summaryrefslogtreecommitdiff
path: root/qemu-arm/test_main.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-03-15 13:42:36 +0000
committerDamien George <damien.p.george@gmail.com>2016-03-15 13:42:36 +0000
commit1ded19d4b3c9710c123a65fd7f369e0022eac02d (patch)
treee8c3d58b238e7de03a5c7c2933bb07dd3066bda5 /qemu-arm/test_main.c
parent157056ecdf378898996ba095c3d7bcf625368103 (diff)
qemu-arm: Reinitialise uPy heap and runtime at start of each test.
Previous to this patch, all qemu-arm tests were running in the same session, and global variables could be left over from the previous test. This patch makes it so that the heap and runtime are reinitialised at the start of each test.
Diffstat (limited to 'qemu-arm/test_main.c')
-rw-r--r--qemu-arm/test_main.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/qemu-arm/test_main.c b/qemu-arm/test_main.c
index 44f9cc666..6b935bbab 100644
--- a/qemu-arm/test_main.c
+++ b/qemu-arm/test_main.c
@@ -15,8 +15,14 @@
#include "tinytest.h"
#include "tinytest_macros.h"
+#define HEAP_SIZE (128 * 1024)
+STATIC void *heap;
+
void do_str(const char *src);
inline void do_str(const char *src) {
+ gc_init(heap, (char*)heap + HEAP_SIZE);
+ mp_init();
+
mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0);
if (lex == NULL) {
tt_abort_msg("Lexer initialization error");
@@ -36,13 +42,13 @@ inline void do_str(const char *src) {
// TODO: That can be always true, we should set up convention to
// use specific exit code as skip indicator.
tinytest_set_test_skipped_();
- return;
+ goto end;
}
mp_obj_print_exception(&mp_plat_print, exc);
tt_abort_msg("Uncaught exception");
}
end:
- ;
+ mp_deinit();
}
#include "genhdr/tests.h"
@@ -51,11 +57,8 @@ int main() {
const char a[] = {"sim"};
mp_stack_ctrl_init();
mp_stack_set_limit(10240);
- void *heap = malloc(256 * 1024);
- gc_init(heap, (char*)heap + 256 * 1024);
- mp_init();
+ heap = malloc(HEAP_SIZE);
int r = tinytest_main(1, (const char **) a, groups);
- mp_deinit();
printf( "status: %i\n", r);
return r;
}