Skip to content

Commit d3cac18

Browse files
committed
tests/unix: Add coverage test for VM executing invalid bytecode.
1 parent a9f6d49 commit d3cac18

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

ports/unix/coverage.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "py/formatfloat.h"
1212
#include "py/stream.h"
1313
#include "py/binary.h"
14+
#include "py/bc.h"
1415

1516
#if defined(MICROPY_UNIX_COVERAGE)
1617

@@ -350,6 +351,23 @@ STATIC mp_obj_t extra_coverage(void) {
350351
mp_printf(&mp_plat_print, "%.0lf\n", dar[0]);
351352
}
352353

354+
// VM
355+
{
356+
mp_printf(&mp_plat_print, "# VM\n");
357+
358+
// call mp_execute_bytecode with invalide bytecode (should raise NotImplementedError)
359+
mp_obj_fun_bc_t fun_bc;
360+
fun_bc.bytecode = (const byte*)"\x01"; // just needed for n_state
361+
mp_code_state_t *code_state = m_new_obj_var(mp_code_state_t, mp_obj_t, 1);
362+
code_state->fun_bc = &fun_bc;
363+
code_state->ip = (const byte*)"\x00"; // just needed for an invalid opcode
364+
code_state->sp = &code_state->state[0];
365+
code_state->exc_sp = NULL;
366+
code_state->old_globals = NULL;
367+
mp_vm_return_kind_t ret = mp_execute_bytecode(code_state, MP_OBJ_NULL);
368+
mp_printf(&mp_plat_print, "%d %d\n", ret, mp_obj_get_type(code_state->state[0]) == &mp_type_NotImplementedError);
369+
}
370+
353371
// scheduler
354372
{
355373
mp_printf(&mp_plat_print, "# scheduler\n");

tests/unix/extra_coverage.py.exp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ Warning: test
5858
# binary
5959
122
6060
456
61+
# VM
62+
2 1
6163
# scheduler
6264
sched(0)=1
6365
sched(1)=1

0 commit comments

Comments
 (0)