Zach Johnson | 2bbb33c | 2014-08-15 16:49:15 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 2014 Google, Inc. |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | ******************************************************************************/ |
| 18 | |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 19 | #include <gtest/gtest.h> |
Zach Johnson | 2bbb33c | 2014-08-15 16:49:15 -0700 | [diff] [blame] | 20 | |
| 21 | #include "AlarmTestHarness.h" |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 22 | |
| 23 | extern "C" { |
Pavlin Radoslavov | c196f21 | 2015-09-23 20:39:53 -0700 | [diff] [blame] | 24 | #include "osi/include/alarm.h" |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 25 | #include "osi/include/fixed_queue.h" |
Pavlin Radoslavov | c196f21 | 2015-09-23 20:39:53 -0700 | [diff] [blame] | 26 | #include "osi/include/osi.h" |
| 27 | #include "osi/include/semaphore.h" |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 28 | #include "osi/include/thread.h" |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 29 | } |
| 30 | |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 31 | static semaphore_t *semaphore; |
| 32 | static int cb_counter; |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 33 | static int cb_misordered_counter; |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 34 | |
| 35 | static const uint64_t EPSILON_MS = 5; |
| 36 | |
| 37 | static void msleep(uint64_t ms) { |
| 38 | usleep(ms * 1000); |
| 39 | } |
| 40 | |
Zach Johnson | 2bbb33c | 2014-08-15 16:49:15 -0700 | [diff] [blame] | 41 | class AlarmTest : public AlarmTestHarness { |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 42 | protected: |
| 43 | virtual void SetUp() { |
Zach Johnson | 2bbb33c | 2014-08-15 16:49:15 -0700 | [diff] [blame] | 44 | AlarmTestHarness::SetUp(); |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 45 | cb_counter = 0; |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 46 | cb_misordered_counter = 0; |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 47 | |
| 48 | semaphore = semaphore_new(0); |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | virtual void TearDown() { |
Zach Johnson | ee2aa45 | 2014-08-26 20:16:03 -0700 | [diff] [blame] | 52 | semaphore_free(semaphore); |
Zach Johnson | 2bbb33c | 2014-08-15 16:49:15 -0700 | [diff] [blame] | 53 | AlarmTestHarness::TearDown(); |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 54 | } |
| 55 | }; |
| 56 | |
Sharvil Nanavati | e0cdd339 | 2014-07-17 15:45:40 -0700 | [diff] [blame] | 57 | static void cb(UNUSED_ATTR void *data) { |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 58 | ++cb_counter; |
| 59 | semaphore_post(semaphore); |
| 60 | } |
| 61 | |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 62 | static void ordered_cb(void *data) { |
| 63 | int i = PTR_TO_INT(data); |
| 64 | if (i != cb_counter) |
| 65 | cb_misordered_counter++; |
| 66 | ++cb_counter; |
| 67 | semaphore_post(semaphore); |
| 68 | } |
| 69 | |
Zach Johnson | ee2aa45 | 2014-08-26 20:16:03 -0700 | [diff] [blame] | 70 | TEST_F(AlarmTest, test_new_free_simple) { |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 71 | alarm_t *alarm = alarm_new("alarm_test.test_new_free_simple"); |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 72 | ASSERT_TRUE(alarm != NULL); |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 73 | alarm_free(alarm); |
| 74 | } |
| 75 | |
| 76 | TEST_F(AlarmTest, test_free_null) { |
| 77 | alarm_free(NULL); |
| 78 | } |
| 79 | |
| 80 | TEST_F(AlarmTest, test_simple_cancel) { |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 81 | alarm_t *alarm = alarm_new("alarm_test.test_simple_cancel"); |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 82 | alarm_cancel(alarm); |
| 83 | alarm_free(alarm); |
| 84 | } |
| 85 | |
| 86 | TEST_F(AlarmTest, test_cancel) { |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 87 | alarm_t *alarm = alarm_new("alarm_test.test_cancel"); |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 88 | alarm_set(alarm, 10, cb, NULL); |
| 89 | alarm_cancel(alarm); |
| 90 | |
| 91 | msleep(10 + EPSILON_MS); |
| 92 | |
| 93 | EXPECT_EQ(cb_counter, 0); |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 94 | EXPECT_FALSE(WakeLockHeld()); |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 95 | alarm_free(alarm); |
| 96 | } |
| 97 | |
| 98 | TEST_F(AlarmTest, test_cancel_idempotent) { |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 99 | alarm_t *alarm = alarm_new("alarm_test.test_cancel_idempotent"); |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 100 | alarm_set(alarm, 10, cb, NULL); |
| 101 | alarm_cancel(alarm); |
| 102 | alarm_cancel(alarm); |
| 103 | alarm_cancel(alarm); |
| 104 | alarm_free(alarm); |
| 105 | } |
| 106 | |
| 107 | TEST_F(AlarmTest, test_set_short) { |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 108 | alarm_t *alarm = alarm_new("alarm_test.test_set_short"); |
| 109 | |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 110 | alarm_set(alarm, 10, cb, NULL); |
| 111 | |
| 112 | EXPECT_EQ(cb_counter, 0); |
Marie Janssen | 1b2bd2c | 2015-11-16 10:35:17 -0800 | [diff] [blame] | 113 | EXPECT_TRUE(WakeLockHeld()); |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 114 | |
| 115 | semaphore_wait(semaphore); |
| 116 | |
| 117 | EXPECT_EQ(cb_counter, 1); |
Marie Janssen | 1b2bd2c | 2015-11-16 10:35:17 -0800 | [diff] [blame] | 118 | EXPECT_FALSE(WakeLockHeld()); |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 119 | |
| 120 | alarm_free(alarm); |
| 121 | } |
| 122 | |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 123 | TEST_F(AlarmTest, test_set_short_periodic) { |
| 124 | alarm_t *alarm = alarm_new_periodic("alarm_test.test_set_short_periodic"); |
| 125 | |
| 126 | alarm_set(alarm, 10, cb, NULL); |
| 127 | |
| 128 | EXPECT_EQ(cb_counter, 0); |
| 129 | EXPECT_TRUE(WakeLockHeld()); |
| 130 | |
| 131 | for (int i = 1; i <= 10; i++) { |
| 132 | semaphore_wait(semaphore); |
| 133 | |
| 134 | EXPECT_GE(cb_counter, i); |
| 135 | EXPECT_TRUE(WakeLockHeld()); |
| 136 | } |
| 137 | alarm_cancel(alarm); |
| 138 | EXPECT_FALSE(WakeLockHeld()); |
| 139 | |
| 140 | alarm_free(alarm); |
| 141 | } |
| 142 | |
Pavlin Radoslavov | 399f217 | 2016-04-19 17:30:19 -0700 | [diff] [blame] | 143 | TEST_F(AlarmTest, test_set_zero_periodic) { |
| 144 | alarm_t *alarm = alarm_new_periodic("alarm_test.test_set_zero_periodic"); |
| 145 | |
| 146 | alarm_set(alarm, 0, cb, NULL); |
| 147 | |
Pavlin Radoslavov | 399f217 | 2016-04-19 17:30:19 -0700 | [diff] [blame] | 148 | EXPECT_TRUE(WakeLockHeld()); |
| 149 | |
| 150 | for (int i = 1; i <= 10; i++) { |
| 151 | semaphore_wait(semaphore); |
| 152 | |
| 153 | EXPECT_GE(cb_counter, i); |
| 154 | EXPECT_TRUE(WakeLockHeld()); |
| 155 | } |
| 156 | alarm_cancel(alarm); |
| 157 | EXPECT_FALSE(WakeLockHeld()); |
| 158 | |
| 159 | alarm_free(alarm); |
| 160 | } |
| 161 | |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 162 | TEST_F(AlarmTest, test_set_long) { |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 163 | alarm_t *alarm = alarm_new("alarm_test.test_set_long"); |
Marie Janssen | ac786e3 | 2015-12-29 15:34:55 -0800 | [diff] [blame] | 164 | alarm_set(alarm, TIMER_INTERVAL_FOR_WAKELOCK_IN_MS + EPSILON_MS, cb, NULL); |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 165 | |
| 166 | EXPECT_EQ(cb_counter, 0); |
Marie Janssen | 1b2bd2c | 2015-11-16 10:35:17 -0800 | [diff] [blame] | 167 | EXPECT_FALSE(WakeLockHeld()); |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 168 | |
| 169 | semaphore_wait(semaphore); |
| 170 | |
| 171 | EXPECT_EQ(cb_counter, 1); |
Marie Janssen | 1b2bd2c | 2015-11-16 10:35:17 -0800 | [diff] [blame] | 172 | EXPECT_FALSE(WakeLockHeld()); |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 173 | |
| 174 | alarm_free(alarm); |
| 175 | } |
| 176 | |
| 177 | TEST_F(AlarmTest, test_set_short_short) { |
| 178 | alarm_t *alarm[2] = { |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 179 | alarm_new("alarm_test.test_set_short_short_0"), |
| 180 | alarm_new("alarm_test.test_set_short_short_1") |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 181 | }; |
| 182 | |
| 183 | alarm_set(alarm[0], 10, cb, NULL); |
| 184 | alarm_set(alarm[1], 20, cb, NULL); |
| 185 | |
| 186 | EXPECT_EQ(cb_counter, 0); |
Marie Janssen | 1b2bd2c | 2015-11-16 10:35:17 -0800 | [diff] [blame] | 187 | EXPECT_TRUE(WakeLockHeld()); |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 188 | |
| 189 | semaphore_wait(semaphore); |
| 190 | |
| 191 | EXPECT_EQ(cb_counter, 1); |
Marie Janssen | 1b2bd2c | 2015-11-16 10:35:17 -0800 | [diff] [blame] | 192 | EXPECT_TRUE(WakeLockHeld()); |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 193 | |
| 194 | semaphore_wait(semaphore); |
| 195 | |
| 196 | EXPECT_EQ(cb_counter, 2); |
Marie Janssen | 1b2bd2c | 2015-11-16 10:35:17 -0800 | [diff] [blame] | 197 | EXPECT_FALSE(WakeLockHeld()); |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 198 | |
| 199 | alarm_free(alarm[0]); |
| 200 | alarm_free(alarm[1]); |
| 201 | } |
| 202 | |
| 203 | TEST_F(AlarmTest, test_set_short_long) { |
| 204 | alarm_t *alarm[2] = { |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 205 | alarm_new("alarm_test.test_set_short_long_0"), |
| 206 | alarm_new("alarm_test.test_set_short_long_1") |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 207 | }; |
| 208 | |
| 209 | alarm_set(alarm[0], 10, cb, NULL); |
| 210 | alarm_set(alarm[1], 10 + TIMER_INTERVAL_FOR_WAKELOCK_IN_MS + EPSILON_MS, cb, NULL); |
| 211 | |
| 212 | EXPECT_EQ(cb_counter, 0); |
Marie Janssen | 1b2bd2c | 2015-11-16 10:35:17 -0800 | [diff] [blame] | 213 | EXPECT_TRUE(WakeLockHeld()); |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 214 | |
| 215 | semaphore_wait(semaphore); |
| 216 | |
| 217 | EXPECT_EQ(cb_counter, 1); |
Marie Janssen | 1b2bd2c | 2015-11-16 10:35:17 -0800 | [diff] [blame] | 218 | EXPECT_FALSE(WakeLockHeld()); |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 219 | |
| 220 | semaphore_wait(semaphore); |
| 221 | |
| 222 | EXPECT_EQ(cb_counter, 2); |
Marie Janssen | 1b2bd2c | 2015-11-16 10:35:17 -0800 | [diff] [blame] | 223 | EXPECT_FALSE(WakeLockHeld()); |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 224 | |
| 225 | alarm_free(alarm[0]); |
| 226 | alarm_free(alarm[1]); |
| 227 | } |
| 228 | |
| 229 | TEST_F(AlarmTest, test_set_long_long) { |
| 230 | alarm_t *alarm[2] = { |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 231 | alarm_new("alarm_test.test_set_long_long_0"), |
| 232 | alarm_new("alarm_test.test_set_long_long_1") |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 233 | }; |
| 234 | |
Marie Janssen | ac786e3 | 2015-12-29 15:34:55 -0800 | [diff] [blame] | 235 | alarm_set(alarm[0], TIMER_INTERVAL_FOR_WAKELOCK_IN_MS + EPSILON_MS, cb, NULL); |
| 236 | alarm_set(alarm[1], 2 * (TIMER_INTERVAL_FOR_WAKELOCK_IN_MS + EPSILON_MS), cb, NULL); |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 237 | |
| 238 | EXPECT_EQ(cb_counter, 0); |
Marie Janssen | 1b2bd2c | 2015-11-16 10:35:17 -0800 | [diff] [blame] | 239 | EXPECT_FALSE(WakeLockHeld()); |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 240 | |
| 241 | semaphore_wait(semaphore); |
| 242 | |
| 243 | EXPECT_EQ(cb_counter, 1); |
Marie Janssen | 1b2bd2c | 2015-11-16 10:35:17 -0800 | [diff] [blame] | 244 | EXPECT_FALSE(WakeLockHeld()); |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 245 | |
| 246 | semaphore_wait(semaphore); |
| 247 | |
| 248 | EXPECT_EQ(cb_counter, 2); |
Marie Janssen | 1b2bd2c | 2015-11-16 10:35:17 -0800 | [diff] [blame] | 249 | EXPECT_FALSE(WakeLockHeld()); |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 250 | |
| 251 | alarm_free(alarm[0]); |
| 252 | alarm_free(alarm[1]); |
| 253 | } |
| 254 | |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 255 | TEST_F(AlarmTest, test_is_scheduled) { |
| 256 | alarm_t *alarm = alarm_new("alarm_test.test_is_scheduled"); |
| 257 | |
| 258 | EXPECT_FALSE(alarm_is_scheduled((alarm_t *)NULL)); |
| 259 | EXPECT_FALSE(alarm_is_scheduled(alarm)); |
| 260 | alarm_set(alarm, TIMER_INTERVAL_FOR_WAKELOCK_IN_MS + EPSILON_MS, cb, NULL); |
| 261 | EXPECT_TRUE(alarm_is_scheduled(alarm)); |
| 262 | |
| 263 | EXPECT_EQ(cb_counter, 0); |
| 264 | EXPECT_FALSE(WakeLockHeld()); |
| 265 | |
| 266 | semaphore_wait(semaphore); |
| 267 | |
| 268 | EXPECT_FALSE(alarm_is_scheduled(alarm)); |
| 269 | EXPECT_EQ(cb_counter, 1); |
| 270 | EXPECT_FALSE(WakeLockHeld()); |
| 271 | |
| 272 | alarm_free(alarm); |
| 273 | } |
| 274 | |
| 275 | // Test whether the callbacks are invoked in the expected order |
| 276 | TEST_F(AlarmTest, test_callback_ordering) { |
| 277 | alarm_t *alarms[100]; |
| 278 | |
| 279 | for (int i = 0; i < 100; i++) { |
| 280 | const std::string alarm_name = "alarm_test.test_callback_ordering[" + |
| 281 | std::to_string(i) + "]"; |
| 282 | alarms[i] = alarm_new(alarm_name.c_str()); |
| 283 | } |
| 284 | |
| 285 | for (int i = 0; i < 100; i++) { |
| 286 | alarm_set(alarms[i], 100, ordered_cb, INT_TO_PTR(i)); |
| 287 | } |
| 288 | |
| 289 | for (int i = 1; i <= 100; i++) { |
| 290 | semaphore_wait(semaphore); |
| 291 | EXPECT_GE(cb_counter, i); |
| 292 | } |
| 293 | EXPECT_EQ(cb_counter, 100); |
| 294 | EXPECT_EQ(cb_misordered_counter, 0); |
| 295 | |
| 296 | for (int i = 0; i < 100; i++) |
| 297 | alarm_free(alarms[i]); |
| 298 | |
| 299 | EXPECT_FALSE(WakeLockHeld()); |
| 300 | } |
| 301 | |
| 302 | // Test whether the callbacks are involed in the expected order on a |
| 303 | // separate queue. |
| 304 | TEST_F(AlarmTest, test_callback_ordering_on_queue) { |
| 305 | alarm_t *alarms[100]; |
| 306 | fixed_queue_t *queue = fixed_queue_new(SIZE_MAX); |
| 307 | thread_t *thread = thread_new("timers.test_callback_ordering_on_queue.thread"); |
| 308 | |
| 309 | alarm_register_processing_queue(queue, thread); |
| 310 | |
| 311 | for (int i = 0; i < 100; i++) { |
| 312 | const std::string alarm_name = |
| 313 | "alarm_test.test_callback_ordering_on_queue[" + |
| 314 | std::to_string(i) + "]"; |
| 315 | alarms[i] = alarm_new(alarm_name.c_str()); |
| 316 | } |
| 317 | |
| 318 | for (int i = 0; i < 100; i++) { |
| 319 | alarm_set_on_queue(alarms[i], 100, ordered_cb, INT_TO_PTR(i), queue); |
| 320 | } |
| 321 | |
| 322 | for (int i = 1; i <= 100; i++) { |
| 323 | semaphore_wait(semaphore); |
| 324 | EXPECT_GE(cb_counter, i); |
| 325 | } |
| 326 | EXPECT_EQ(cb_counter, 100); |
| 327 | EXPECT_EQ(cb_misordered_counter, 0); |
| 328 | |
| 329 | for (int i = 0; i < 100; i++) |
| 330 | alarm_free(alarms[i]); |
| 331 | |
| 332 | EXPECT_FALSE(WakeLockHeld()); |
| 333 | |
| 334 | alarm_unregister_processing_queue(queue); |
| 335 | fixed_queue_free(queue, NULL); |
| 336 | thread_free(thread); |
| 337 | } |
| 338 | |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 339 | // Try to catch any race conditions between the timer callback and |alarm_free|. |
| 340 | TEST_F(AlarmTest, test_callback_free_race) { |
| 341 | for (int i = 0; i < 1000; ++i) { |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 342 | const std::string alarm_name = "alarm_test.test_callback_free_race[" + |
| 343 | std::to_string(i) + "]"; |
| 344 | alarm_t *alarm = alarm_new(alarm_name.c_str()); |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 345 | alarm_set(alarm, 0, cb, NULL); |
| 346 | alarm_free(alarm); |
| 347 | } |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 348 | alarm_cleanup(); |
Sharvil Nanavati | f0e7c8b | 2014-07-01 18:42:56 -0700 | [diff] [blame] | 349 | } |