summaryrefslogtreecommitdiffstatshomepage
path: root/unix/coverage.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-03-16 18:05:33 +1100
committerDamien George <damien.p.george@gmail.com>2017-03-20 15:20:26 +1100
commit74faf4c5fc2245e33a0deed840716a36249eb683 (patch)
treec74eb78f267a3ecbf839f70fb70aabe42a093629 /unix/coverage.c
parentc772817deea6f3e5fe63483db77a98b65974d833 (diff)
downloadmicropython-74faf4c5fc2245e33a0deed840716a36249eb683.tar.gz
micropython-74faf4c5fc2245e33a0deed840716a36249eb683.zip
unix/coverage: Enable scheduler and add tests for it.
Diffstat (limited to 'unix/coverage.c')
-rw-r--r--unix/coverage.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/unix/coverage.c b/unix/coverage.c
index ca236c4303..09959525a0 100644
--- a/unix/coverage.c
+++ b/unix/coverage.c
@@ -292,6 +292,35 @@ STATIC mp_obj_t extra_coverage(void) {
mp_printf(&mp_plat_print, "%.0lf\n", dar[0]);
}
+ // scheduler
+ {
+ mp_printf(&mp_plat_print, "# scheduler\n");
+
+ // lock scheduler
+ mp_sched_lock();
+
+ // schedule multiple callbacks; last one should fail
+ for (int i = 0; i < 5; ++i) {
+ 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)));
+ }
+
+ // test nested locking/unlocking
+ mp_sched_lock();
+ mp_sched_unlock();
+
+ // shouldn't do anything while scheduler is locked
+ mp_handle_pending();
+
+ // unlock scheduler
+ mp_sched_unlock();
+ mp_printf(&mp_plat_print, "unlocked\n");
+
+ // drain pending callbacks
+ while (mp_sched_num_pending()) {
+ mp_handle_pending();
+ }
+ }
+
mp_obj_streamtest_t *s = m_new_obj(mp_obj_streamtest_t);
s->base.type = &mp_type_stest_fileio;
s->buf = NULL;