Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 60606278 authored by Pavlin Radoslavov's avatar Pavlin Radoslavov
Browse files

Fix a Floating point exception for periodic timers

Fix a Floating point exception for periodic timers that are
scheduled with interval of 0ms, and add a corresponding unit test.
Also, fix a typo when printing "Action counts" statistics.

Bug: 28278593
Change-Id: Ic381efc573ed9954c36980c26a89318d2de40b29
parent 4b7600eb
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -431,7 +431,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);

@@ -726,7 +726,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);

+20 −0
Original line number Diff line number Diff line
@@ -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);