Skip to content

Commit 8204853

Browse files
pi-anldpgeorge
authored andcommitted
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 <[email protected]> Signed-off-by: Andrew Leech <[email protected]>
1 parent 7f274c7 commit 8204853

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

ports/unix/coverage.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,18 @@ static void pairheap_test(size_t nops, int *ops) {
184184
mp_printf(&mp_plat_print, "\n");
185185
}
186186

187+
static mp_sched_node_t mp_coverage_sched_node;
188+
static bool coverage_sched_function_continue;
189+
190+
static void coverage_sched_function(mp_sched_node_t *node) {
191+
(void)node;
192+
mp_printf(&mp_plat_print, "scheduled function\n");
193+
if (coverage_sched_function_continue) {
194+
// Re-scheduling node will cause it to run again next time scheduled functions are run
195+
mp_sched_schedule_node(&mp_coverage_sched_node, coverage_sched_function);
196+
}
197+
}
198+
187199
// function to run extra tests for things that can't be checked by scripts
188200
static mp_obj_t extra_coverage(void) {
189201
// mp_printf (used by ports that don't have a native printf)
@@ -621,6 +633,19 @@ static mp_obj_t extra_coverage(void) {
621633
mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val));
622634
}
623635
mp_handle_pending(true);
636+
637+
coverage_sched_function_continue = true;
638+
mp_sched_schedule_node(&mp_coverage_sched_node, coverage_sched_function);
639+
for (int i = 0; i < 3; ++i) {
640+
mp_printf(&mp_plat_print, "loop\n");
641+
mp_handle_pending(true);
642+
}
643+
// Clear this flag to prevent the function scheduling itself again
644+
coverage_sched_function_continue = false;
645+
// Will only run the first time through this loop, then not scheduled again
646+
for (int i = 0; i < 3; ++i) {
647+
mp_handle_pending(true);
648+
}
624649
}
625650

626651
// ringbuf

ports/unix/variants/coverage/mpconfigvariant.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#undef MICROPY_VFS_ROM_IOCTL
4545
#define MICROPY_VFS_ROM_IOCTL (1)
4646
#define MICROPY_PY_CRYPTOLIB_CTR (1)
47+
#define MICROPY_SCHEDULER_STATIC_NODES (1)
4748

4849
// Enable os.uname for attrtuple coverage test
4950
#define MICROPY_PY_OS_UNAME (1)

tests/ports/unix/extra_coverage.py.exp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ unlocked
122122
KeyboardInterrupt:
123123
KeyboardInterrupt:
124124
10
125+
loop
126+
scheduled function
127+
loop
128+
scheduled function
129+
loop
130+
scheduled function
131+
scheduled function
125132
# ringbuf
126133
99 0
127134
98 1

0 commit comments

Comments
 (0)