static char* test_two_duplicate(void *context) { while(fire_head()); fire_mask = 0; nx_timer_schedule(timers[0], 2); nx_timer_schedule(timers[1], 2); sys_mutex_lock(lock); nx_timer_visit_LH(time++); nx_timer_visit_LH(time++); sys_mutex_unlock(lock); int count = fire_head(); if (count != 2) return "Expected two firings"; fire_head(); if (fire_mask != 3) return "Incorrect fire mask 3"; sys_mutex_lock(lock); nx_timer_visit_LH(time++); nx_timer_visit_LH(time++); sys_mutex_unlock(lock); if (fire_head() > 0) return "Spurious timer fires"; return 0; }
static char* test_two_reverse(void *context) { while(fire_head()); fire_mask = 0; nx_timer_schedule(timers[0], 4); nx_timer_schedule(timers[1], 2); sys_mutex_lock(lock); nx_timer_visit_LH(time++); nx_timer_visit_LH(time++); sys_mutex_unlock(lock); int count = fire_head(); if (count < 1) return "First failed to fire"; if (count > 1) return "Second fired prematurely"; if (fire_mask != 2) return "Incorrect fire mask 2"; sys_mutex_lock(lock); nx_timer_visit_LH(time++); nx_timer_visit_LH(time++); sys_mutex_unlock(lock); if (fire_head() < 1) return "Second failed to fire"; if (fire_mask != 3) return "Incorrect fire mask 3"; return 0; }
static char* test_single(void *context) { while(fire_head()); fire_mask = 0; nx_timer_schedule(timers[0], 2); if (fire_head() > 0) return "Premature firing 1"; sys_mutex_lock(lock); nx_timer_visit_LH(time++); sys_mutex_unlock(lock); if (fire_head() > 0) return "Premature firing 2"; sys_mutex_lock(lock); nx_timer_visit_LH(time++); sys_mutex_unlock(lock); if (fire_head() < 1) return "Failed to fire"; sys_mutex_lock(lock); nx_timer_visit_LH(time++); nx_timer_visit_LH(time++); nx_timer_visit_LH(time++); sys_mutex_unlock(lock); if (fire_head() != 0) return "Spurious fires"; if (fire_mask != 1) return "Incorrect fire mask"; if (timers[0]->state != TIMER_IDLE) return "Expected idle timer state"; return 0; }
static char* test_immediate(void *context) { while(fire_head()); fire_mask = 0; nx_timer_schedule(timers[0], 0); if (fire_mask != 0) return "Premature firing"; if (fire_head() > 1) return "Too many firings"; if (fire_mask != 1) return "Incorrect fire mask"; return 0; }
static char* test_big(void *context) { while(fire_head()); fire_mask = 0; long durations[16] = { 5, 8, 7, 6, 14, 10, 16, 15, 11, 12, 9, 12, 1, 2, 3, 4}; unsigned long masks[18] = { 0x1000, 0x3000, 0x7000, 0xf000, 0xf001, 0xf009, 0xf00d, 0xf00f, 0xf40f, 0xf42f, 0xf52f, 0xff2f, 0xff2f, 0xff3f, 0xffbf, 0xffff, 0xffff, 0xffff }; int i; for (i = 0; i < 16; i++) nx_timer_schedule(timers[i], durations[i]); for (i = 0; i < 18; i++) { sys_mutex_lock(lock); nx_timer_visit_LH(time++); sys_mutex_unlock(lock); while(fire_head()); if (fire_mask != masks[i]) { static char error[100]; sprintf(error, "Iteration %d: expected mask %04lx, got %04lx", i, masks[i], fire_mask); return error; } } return 0; }
static char* test_immediate_reschedule(void *context) { while(fire_head()); fire_mask = 0; qd_timer_schedule(timers[0], 0); qd_timer_schedule(timers[0], 0); if (fire_mask != 0) return "pass 1 - Premature firing"; if (fire_head() > 1) return "pass 1 - Too many firings"; if (fire_mask != 1) return "pass 1 - Incorrect fire mask"; fire_mask = 0; qd_timer_schedule(timers[0], 0); qd_timer_schedule(timers[0], 0); if (fire_mask != 0) return "pass 2 - Premature firing"; if (fire_head() > 1) return "pass 2 - Too many firings"; if (fire_mask != 1) return "pass 2 - Incorrect fire mask"; return 0; }
static char* test_immediate_plus_delayed(void *context) { while(fire_head()); fire_mask = 0; nx_timer_schedule(timers[0], 0); nx_timer_schedule(timers[1], 5); if (fire_mask != 0) return "Premature firing"; if (fire_head() > 1) return "Too many firings"; if (fire_mask != 1) return "Incorrect fire mask 1"; sys_mutex_lock(lock); nx_timer_visit_LH(time++); time += 8; nx_timer_visit_LH(time++); sys_mutex_unlock(lock); if (fire_head() < 1) return "Delayed Failed to fire"; if (fire_mask != 3) return "Incorrect fire mask 3"; return 0; }
static char* test_separated(void *context) { int count; while(fire_head()); fire_mask = 0; nx_timer_schedule(timers[0], 2); nx_timer_schedule(timers[1], 4); sys_mutex_lock(lock); nx_timer_visit_LH(time++); nx_timer_visit_LH(time++); sys_mutex_unlock(lock); count = fire_head(); if (count < 1) return "First failed to fire"; if (count > 1) return "Second fired prematurely"; if (fire_mask != 1) return "Incorrect fire mask 1"; nx_timer_schedule(timers[2], 2); nx_timer_schedule(timers[3], 4); sys_mutex_lock(lock); nx_timer_visit_LH(time++); nx_timer_visit_LH(time++); sys_mutex_unlock(lock); count = fire_head(); fire_head(); if (count < 1) return "Second failed to fire"; if (count < 2) return "Third failed to fire"; if (fire_mask != 7) return "Incorrect fire mask 7"; sys_mutex_lock(lock); nx_timer_visit_LH(time++); nx_timer_visit_LH(time++); sys_mutex_unlock(lock); count = fire_head(); if (count < 1) return "Fourth failed to fire"; if (fire_mask != 15) return "Incorrect fire mask 15"; sys_mutex_lock(lock); nx_timer_visit_LH(time++); nx_timer_visit_LH(time++); nx_timer_visit_LH(time++); nx_timer_visit_LH(time++); nx_timer_visit_LH(time++); nx_timer_visit_LH(time++); sys_mutex_unlock(lock); count = fire_head(); if (count > 0) return "Spurious fire"; return 0; }
static char* test_quiet(void *context) { fire_mask = 0; sys_mutex_lock(lock); nx_timer_visit_LH(time++); nx_timer_visit_LH(time++); nx_timer_visit_LH(time++); nx_timer_visit_LH(time++); nx_timer_visit_LH(time++); sys_mutex_unlock(lock); while(fire_head()); if (fire_mask != 0) return "Expected zero timers fired"; return 0; }