summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2016-04-23 00:33:11 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2016-04-23 00:33:12 +0000
commitff868423456f3b3ab40646df8dccfff0c099aea7 (patch)
treea9527a6e5f37d73dabd0cc10133c68a40ff552ce
parent88c7f54db69ded44b3017e6a1ccbc05352103683 (diff)
parent8e4577f7b48aad4c4a36a0d5787139a36ca2be94 (diff)
downloadandroid-system-bt-ff868423456f3b3ab40646df8dccfff0c099aea7.tar.gz
android-system-bt-ff868423456f3b3ab40646df8dccfff0c099aea7.tar.xz
Merge "Fix a Floating point exception for periodic timers" into nyc-dev
-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 d070678..f28843e 100644
--- a/osi/src/alarm.c
+++ b/osi/src/alarm.c
@@ -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);
@@ -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);
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);