Skip to content
Snippets Groups Projects
Commit 1ded19d4 authored by Damien George's avatar Damien George
Browse files

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.
parent 157056ec
Branches
No related tags found
No related merge requests found
...@@ -15,8 +15,14 @@ ...@@ -15,8 +15,14 @@
#include "tinytest.h" #include "tinytest.h"
#include "tinytest_macros.h" #include "tinytest_macros.h"
#define HEAP_SIZE (128 * 1024)
STATIC void *heap;
void do_str(const char *src); void do_str(const char *src);
inline 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); mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0);
if (lex == NULL) { if (lex == NULL) {
tt_abort_msg("Lexer initialization error"); tt_abort_msg("Lexer initialization error");
...@@ -36,13 +42,13 @@ inline void do_str(const char *src) { ...@@ -36,13 +42,13 @@ inline void do_str(const char *src) {
// TODO: That can be always true, we should set up convention to // TODO: That can be always true, we should set up convention to
// use specific exit code as skip indicator. // use specific exit code as skip indicator.
tinytest_set_test_skipped_(); tinytest_set_test_skipped_();
return; goto end;
} }
mp_obj_print_exception(&mp_plat_print, exc); mp_obj_print_exception(&mp_plat_print, exc);
tt_abort_msg("Uncaught exception"); tt_abort_msg("Uncaught exception");
} }
end: end:
; mp_deinit();
} }
#include "genhdr/tests.h" #include "genhdr/tests.h"
...@@ -51,11 +57,8 @@ int main() { ...@@ -51,11 +57,8 @@ int main() {
const char a[] = {"sim"}; const char a[] = {"sim"};
mp_stack_ctrl_init(); mp_stack_ctrl_init();
mp_stack_set_limit(10240); mp_stack_set_limit(10240);
void *heap = malloc(256 * 1024); heap = malloc(HEAP_SIZE);
gc_init(heap, (char*)heap + 256 * 1024);
mp_init();
int r = tinytest_main(1, (const char **) a, groups); int r = tinytest_main(1, (const char **) a, groups);
mp_deinit();
printf( "status: %i\n", r); printf( "status: %i\n", r);
return r; return r;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment