mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 09:50:15 +01:00
unix/coverage: Add coverage test for mp_sched_schedule_node.
Test modified to reschedule itself based on a flag setting. Without the change in the parent commit, this test executes the callback indefinitely and hangs but with the change it runs only once each time mp_handle_pending() is called. Modified-by: Angus Gratton <angus@redyak.com.au> Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
This commit is contained in:
committed by
Damien George
parent
7f274c7550
commit
820485358d
@@ -184,6 +184,18 @@ static void pairheap_test(size_t nops, int *ops) {
|
||||
mp_printf(&mp_plat_print, "\n");
|
||||
}
|
||||
|
||||
static mp_sched_node_t mp_coverage_sched_node;
|
||||
static bool coverage_sched_function_continue;
|
||||
|
||||
static void coverage_sched_function(mp_sched_node_t *node) {
|
||||
(void)node;
|
||||
mp_printf(&mp_plat_print, "scheduled function\n");
|
||||
if (coverage_sched_function_continue) {
|
||||
// Re-scheduling node will cause it to run again next time scheduled functions are run
|
||||
mp_sched_schedule_node(&mp_coverage_sched_node, coverage_sched_function);
|
||||
}
|
||||
}
|
||||
|
||||
// function to run extra tests for things that can't be checked by scripts
|
||||
static mp_obj_t extra_coverage(void) {
|
||||
// mp_printf (used by ports that don't have a native printf)
|
||||
@@ -621,6 +633,19 @@ static mp_obj_t extra_coverage(void) {
|
||||
mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val));
|
||||
}
|
||||
mp_handle_pending(true);
|
||||
|
||||
coverage_sched_function_continue = true;
|
||||
mp_sched_schedule_node(&mp_coverage_sched_node, coverage_sched_function);
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
mp_printf(&mp_plat_print, "loop\n");
|
||||
mp_handle_pending(true);
|
||||
}
|
||||
// Clear this flag to prevent the function scheduling itself again
|
||||
coverage_sched_function_continue = false;
|
||||
// Will only run the first time through this loop, then not scheduled again
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
mp_handle_pending(true);
|
||||
}
|
||||
}
|
||||
|
||||
// ringbuf
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#undef MICROPY_VFS_ROM_IOCTL
|
||||
#define MICROPY_VFS_ROM_IOCTL (1)
|
||||
#define MICROPY_PY_CRYPTOLIB_CTR (1)
|
||||
#define MICROPY_SCHEDULER_STATIC_NODES (1)
|
||||
|
||||
// Enable os.uname for attrtuple coverage test
|
||||
#define MICROPY_PY_OS_UNAME (1)
|
||||
|
||||
@@ -122,6 +122,13 @@ unlocked
|
||||
KeyboardInterrupt:
|
||||
KeyboardInterrupt:
|
||||
10
|
||||
loop
|
||||
scheduled function
|
||||
loop
|
||||
scheduled function
|
||||
loop
|
||||
scheduled function
|
||||
scheduled function
|
||||
# ringbuf
|
||||
99 0
|
||||
98 1
|
||||
|
||||
Reference in New Issue
Block a user