test_main.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include <stdint.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <malloc.h>
  6. #include <setjmp.h>
  7. #include "py/obj.h"
  8. #include "py/compile.h"
  9. #include "py/runtime.h"
  10. #include "py/stackctrl.h"
  11. #include "py/gc.h"
  12. #include "py/mperrno.h"
  13. #include "tinytest.h"
  14. #include "tinytest_macros.h"
  15. #define HEAP_SIZE (128 * 1024)
  16. STATIC void *heap;
  17. #include "genhdr/tests.h"
  18. int main() {
  19. mp_stack_ctrl_init();
  20. mp_stack_set_limit(10240);
  21. heap = malloc(HEAP_SIZE);
  22. upytest_set_heap(heap, (char*)heap + HEAP_SIZE);
  23. int r = tinytest_main(0, NULL, groups);
  24. printf("status: %d\n", r);
  25. return r;
  26. }
  27. void gc_collect(void) {
  28. gc_collect_start();
  29. // get the registers and the sp
  30. jmp_buf env;
  31. setjmp(env);
  32. volatile mp_uint_t dummy;
  33. void *sp = (void*)&dummy;
  34. // trace the stack, including the registers (since they live on the stack in this function)
  35. gc_collect_root((void**)sp, ((uint32_t)MP_STATE_THREAD(stack_top) - (uint32_t)sp) / sizeof(uint32_t));
  36. gc_collect_end();
  37. }
  38. mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
  39. mp_raise_OSError(MP_ENOENT);
  40. }
  41. mp_import_stat_t mp_import_stat(const char *path) {
  42. return MP_IMPORT_STAT_NO_EXIST;
  43. }
  44. mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
  45. return mp_const_none;
  46. }
  47. MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
  48. void nlr_jump_fail(void *val) {
  49. printf("uncaught NLR\n");
  50. exit(1);
  51. }