diff options
author | Damien George <damien.p.george@gmail.com> | 2018-02-27 16:17:10 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2018-02-27 16:18:11 +1100 |
commit | d3cac18d4914af4549437ef3fd0d62f1fc05ff27 (patch) | |
tree | dc31be2801a87d4f24f467dd4913375aa6d3bb35 | |
parent | a9f6d4921829195d7310aa8b07a4a705577161a5 (diff) |
tests/unix: Add coverage test for VM executing invalid bytecode.
-rw-r--r-- | ports/unix/coverage.c | 18 | ||||
-rw-r--r-- | tests/unix/extra_coverage.py.exp | 2 |
2 files changed, 20 insertions, 0 deletions
diff --git a/ports/unix/coverage.c b/ports/unix/coverage.c index 25376edc0..f0d9406c6 100644 --- a/ports/unix/coverage.c +++ b/ports/unix/coverage.c @@ -11,6 +11,7 @@ #include "py/formatfloat.h" #include "py/stream.h" #include "py/binary.h" +#include "py/bc.h" #if defined(MICROPY_UNIX_COVERAGE) @@ -350,6 +351,23 @@ STATIC mp_obj_t extra_coverage(void) { mp_printf(&mp_plat_print, "%.0lf\n", dar[0]); } + // VM + { + mp_printf(&mp_plat_print, "# VM\n"); + + // call mp_execute_bytecode with invalide bytecode (should raise NotImplementedError) + mp_obj_fun_bc_t fun_bc; + fun_bc.bytecode = (const byte*)"\x01"; // just needed for n_state + mp_code_state_t *code_state = m_new_obj_var(mp_code_state_t, mp_obj_t, 1); + code_state->fun_bc = &fun_bc; + code_state->ip = (const byte*)"\x00"; // just needed for an invalid opcode + code_state->sp = &code_state->state[0]; + code_state->exc_sp = NULL; + code_state->old_globals = NULL; + mp_vm_return_kind_t ret = mp_execute_bytecode(code_state, MP_OBJ_NULL); + mp_printf(&mp_plat_print, "%d %d\n", ret, mp_obj_get_type(code_state->state[0]) == &mp_type_NotImplementedError); + } + // scheduler { mp_printf(&mp_plat_print, "# scheduler\n"); diff --git a/tests/unix/extra_coverage.py.exp b/tests/unix/extra_coverage.py.exp index 71b6867ca..a030155ba 100644 --- a/tests/unix/extra_coverage.py.exp +++ b/tests/unix/extra_coverage.py.exp @@ -58,6 +58,8 @@ Warning: test # binary 122 456 +# VM +2 1 # scheduler sched(0)=1 sched(1)=1 |