tests/unix: Add coverage test for VM executing invalid bytecode.

This commit is contained in:
Damien George 2018-02-27 16:17:10 +11:00
parent a9f6d49218
commit d3cac18d49
2 changed files with 20 additions and 0 deletions

View File

@ -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");

View File

@ -58,6 +58,8 @@ Warning: test
# binary
122
456
# VM
2 1
# scheduler
sched(0)=1
sched(1)=1