Skip to content

Commit 74faf4c

Browse files
committed
unix/coverage: Enable scheduler and add tests for it.
1 parent c772817 commit 74faf4c

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

tests/unix/extra_coverage.py.exp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ Warning: test
4646
# binary
4747
122
4848
456
49+
# scheduler
50+
sched(0)=1
51+
sched(1)=1
52+
sched(2)=1
53+
sched(3)=1
54+
sched(4)=0
55+
unlocked
56+
3
57+
2
58+
1
59+
0
4960
0123456789 b'0123456789'
5061
7300
5162
7300

unix/coverage.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,35 @@ STATIC mp_obj_t extra_coverage(void) {
292292
mp_printf(&mp_plat_print, "%.0lf\n", dar[0]);
293293
}
294294

295+
// scheduler
296+
{
297+
mp_printf(&mp_plat_print, "# scheduler\n");
298+
299+
// lock scheduler
300+
mp_sched_lock();
301+
302+
// schedule multiple callbacks; last one should fail
303+
for (int i = 0; i < 5; ++i) {
304+
mp_printf(&mp_plat_print, "sched(%d)=%d\n", i, mp_sched_schedule(MP_OBJ_FROM_PTR(&mp_builtin_print_obj), MP_OBJ_NEW_SMALL_INT(i)));
305+
}
306+
307+
// test nested locking/unlocking
308+
mp_sched_lock();
309+
mp_sched_unlock();
310+
311+
// shouldn't do anything while scheduler is locked
312+
mp_handle_pending();
313+
314+
// unlock scheduler
315+
mp_sched_unlock();
316+
mp_printf(&mp_plat_print, "unlocked\n");
317+
318+
// drain pending callbacks
319+
while (mp_sched_num_pending()) {
320+
mp_handle_pending();
321+
}
322+
}
323+
295324
mp_obj_streamtest_t *s = m_new_obj(mp_obj_streamtest_t);
296325
s->base.type = &mp_type_stest_fileio;
297326
s->buf = NULL;

unix/mpconfigport_coverage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include <mpconfigport.h>
3434

35+
#define MICROPY_ENABLE_SCHEDULER (1)
3536
#define MICROPY_PY_DELATTR_SETATTR (1)
3637
#define MICROPY_PY_BUILTINS_HELP (1)
3738
#define MICROPY_PY_BUILTINS_HELP_MODULES (1)

0 commit comments

Comments
 (0)