Changeset 12756
- Timestamp:
- Mar 10, 2014, 6:09:22 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/SystemQueue-tests.cc
r12755 r12756 3 3 4 4 #include <unistd.h> // usleep 5 #include <boost/date_time.hpp> // local_time() 5 6 6 7 #include <ostream> … … 9 10 using namespace ariba::utility; 10 11 using namespace std; 12 13 using boost::posix_time::microsec_clock; 14 11 15 12 16 /** … … 264 268 /** 265 269 * This subclass has some special member functions suitable for timing tests 270 * 271 * NOTE: Timing tests are not always reproducable.. sorry. :-/ 266 272 */ 267 273 class SystemQueueTimingTest : … … 277 283 */ 278 284 #define DELAY_TIME 20 // ms 279 #define DELAY_MARGIN 2000 // microseconds (1/1000 ms) 285 #define DELAY_MARGIN 2000 // microseconds (1/1000 ms) // TODO maybe this is too much.. 280 286 281 287 … … 299 305 sysq.cancel(); 300 306 } 307 308 309 /** 310 * @param placed_in_queue The time (as ptime) when this event is put into the delay queue 311 * @param intended_sleep_time The time (in microseconds) the event is supposed to sleep in the queue 312 * @param margin The acceptable margin (in microseconds) 313 */ 314 void TimeCheckingCall(ptime placed_in_queue, uint64_t intended_sleep_time, uint64_t margin) 315 { 316 ptime called_at = microsec_clock::local_time(); 317 318 // calculate actual sleep time and difference to intended sleep time 319 boost::posix_time::time_duration actual_sleep_time = called_at - placed_in_queue; 320 uint64_t diff = actual_sleep_time.total_microseconds() - intended_sleep_time; 321 322 // info 323 cout << "/// Timing difference: " << diff << " microseconds" << endl; 324 325 EXPECT_LT( abs(diff), margin ); 326 327 checkmark = true; 328 } 301 329 302 330 SystemQueue& sysq; … … 315 343 316 344 // noting to do until the delay is up.. 317 usleep(DELAY_TIME + DELAY_MARGIN*10); // XXX margin too high (TODO lower when SysQ is reimplemented)345 usleep(DELAY_TIME*1000 + DELAY_MARGIN*10); // XXX margin too high (TODO lower when SysQ is reimplemented) 318 346 319 347 // wait for the event to happen … … 379 407 // XXX the usual bug.. 380 408 sysq.scheduleCall( 381 boost::bind(&SystemQueueT est::Check, this),409 boost::bind(&SystemQueueTimingTest::Check, this), 382 410 DELAY_TIME*4 383 411 ); 384 412 385 413 // noting to do until the delay is up.. 386 usleep(DELAY_TIME *4+ DELAY_MARGIN*100); // XXX margin too high414 usleep(DELAY_TIME * 4000 + DELAY_MARGIN*100); // XXX margin too high 387 415 388 416 // wait for the event to happen … … 392 420 EXPECT_EQ( 4, last_ordered_call); 393 421 } 422 423 424 /** 425 * Schedules a delayed call and test whether the sleep time is acurate 426 */ 427 TEST_F(SystemQueueTimingTest, TimingSingleCall) 428 { 429 ptime now = microsec_clock::local_time(); 430 431 sysq.scheduleCall( 432 boost::bind(&SystemQueueTimingTest::TimeCheckingCall, this, 433 now, DELAY_TIME*1000, DELAY_MARGIN), 434 DELAY_TIME 435 ); 436 437 // main thread is going to sleep.. 438 usleep(DELAY_TIME * 1000 + DELAY_MARGIN * 2); 439 wait_for_checkmark(MAX_WAIT); 440 441 // make sure the measurement function was called at all 442 EXPECT_TRUE(checkmark) << "Measurement function was NOT RUN AT ALL!"; 443 } 444
Note:
See TracChangeset
for help on using the changeset viewer.