summaryrefslogtreecommitdiff
path: root/osi
diff options
context:
space:
mode:
authorPavlin Radoslavov <pavlin@google.com>2016-04-19 17:30:19 -0700
committerPavlin Radoslavov <pavlin@google.com>2016-04-22 16:03:09 -0700
commit8e4577f7b48aad4c4a36a0d5787139a36ca2be94 (patch)
tree01979efbb79e680da069c2e9419edb9390c3f172 /osi
parent4d602cc8c972c781ba23e7945a2dcd20fee40de3 (diff)
downloadandroid-system-bt-8e4577f7b48aad4c4a36a0d5787139a36ca2be94.tar.gz
android-system-bt-8e4577f7b48aad4c4a36a0d5787139a36ca2be94.tar.xz
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
Diffstat (limited to 'osi')
-rw-r--r--osi/src/alarm.c4
-rw-r--r--osi/test/alarm_test.cpp20
2 files changed, 22 insertions, 2 deletions
diff --git a/osi/src/alarm.c b/osi/src/alarm.c
index 2a115e6..786be38 100644
--- a/osi/src/alarm.c
+++ b/osi/src/alarm.c
@@ -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);
diff --git a/osi/test/alarm_test.cpp b/osi/test/alarm_test.cpp
index c4a2dca..8d72776 100644
--- a/osi/test/alarm_test.cpp
+++ b/osi/test/alarm_test.cpp
@@ -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);