Loading system/osi/src/alarm.c +2 −2 Original line number Diff line number Diff line Loading @@ -434,7 +434,7 @@ static void schedule_next_instance(alarm_t *alarm) { // Calculate the next deadline for this alarm period_ms_t just_now = now(); period_ms_t ms_into_period = 0; if (alarm->is_periodic) if ((alarm->is_periodic) && (alarm->period != 0)) ms_into_period = ((just_now - alarm->creation_time) % alarm->period); alarm->deadline = just_now + (alarm->period - ms_into_period); Loading Loading @@ -729,7 +729,7 @@ void alarm_debug_dump(int fd) (alarm->is_periodic) ? "PERIODIC" : "SINGLE"); dprintf(fd, "%-51s: %zu / %zu / %zu / %zu\n", " Action counts (sched/resched/exec/cancel", " Action counts (sched/resched/exec/cancel)", stats->scheduled_count, stats->rescheduled_count, stats->callback_execution.count, stats->canceled_count); Loading system/osi/test/alarm_test.cpp +20 −0 Original line number Diff line number Diff line Loading @@ -140,6 +140,26 @@ TEST_F(AlarmTest, test_set_short_periodic) { alarm_free(alarm); } TEST_F(AlarmTest, test_set_zero_periodic) { alarm_t *alarm = alarm_new_periodic("alarm_test.test_set_zero_periodic"); alarm_set(alarm, 0, cb, NULL); EXPECT_EQ(cb_counter, 0); EXPECT_TRUE(WakeLockHeld()); for (int i = 1; i <= 10; i++) { semaphore_wait(semaphore); EXPECT_GE(cb_counter, i); EXPECT_TRUE(WakeLockHeld()); } alarm_cancel(alarm); EXPECT_FALSE(WakeLockHeld()); alarm_free(alarm); } TEST_F(AlarmTest, test_set_long) { alarm_t *alarm = alarm_new("alarm_test.test_set_long"); alarm_set(alarm, TIMER_INTERVAL_FOR_WAKELOCK_IN_MS + EPSILON_MS, cb, NULL); Loading Loading
system/osi/src/alarm.c +2 −2 Original line number Diff line number Diff line Loading @@ -434,7 +434,7 @@ static void schedule_next_instance(alarm_t *alarm) { // Calculate the next deadline for this alarm period_ms_t just_now = now(); period_ms_t ms_into_period = 0; if (alarm->is_periodic) if ((alarm->is_periodic) && (alarm->period != 0)) ms_into_period = ((just_now - alarm->creation_time) % alarm->period); alarm->deadline = just_now + (alarm->period - ms_into_period); Loading Loading @@ -729,7 +729,7 @@ void alarm_debug_dump(int fd) (alarm->is_periodic) ? "PERIODIC" : "SINGLE"); dprintf(fd, "%-51s: %zu / %zu / %zu / %zu\n", " Action counts (sched/resched/exec/cancel", " Action counts (sched/resched/exec/cancel)", stats->scheduled_count, stats->rescheduled_count, stats->callback_execution.count, stats->canceled_count); Loading
system/osi/test/alarm_test.cpp +20 −0 Original line number Diff line number Diff line Loading @@ -140,6 +140,26 @@ TEST_F(AlarmTest, test_set_short_periodic) { alarm_free(alarm); } TEST_F(AlarmTest, test_set_zero_periodic) { alarm_t *alarm = alarm_new_periodic("alarm_test.test_set_zero_periodic"); alarm_set(alarm, 0, cb, NULL); EXPECT_EQ(cb_counter, 0); EXPECT_TRUE(WakeLockHeld()); for (int i = 1; i <= 10; i++) { semaphore_wait(semaphore); EXPECT_GE(cb_counter, i); EXPECT_TRUE(WakeLockHeld()); } alarm_cancel(alarm); EXPECT_FALSE(WakeLockHeld()); alarm_free(alarm); } TEST_F(AlarmTest, test_set_long) { alarm_t *alarm = alarm_new("alarm_test.test_set_long"); alarm_set(alarm, TIMER_INTERVAL_FOR_WAKELOCK_IN_MS + EPSILON_MS, cb, NULL); Loading