Skip to content

Commit

Permalink
Use system time for timing wakeups
Browse files Browse the repository at this point in the history
Monotonic time might not advance in suspend.
System time could change during test.

Choose lesser of the two evils.

[tests] Use system time for timing wakeups
  • Loading branch information
spiiroin committed Oct 10, 2013
1 parent 7186422 commit 36cf1a4
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/hbtest3.c
Expand Up @@ -26,6 +26,9 @@
/* How strictly we want to interpret the maximum wakup time */
#define ALLOWED_DELAY 999 // ms

/* Should we use monotonic time source or system time for timing */
#define USE_MONOTONIC_TIME 0

typedef struct hbtimer_t hbtimer_t;

/* -- tv -- */
Expand Down Expand Up @@ -114,6 +117,9 @@ static void keepalive_test (int *xc);

static void tv_get_monotime(struct timeval *tv)
{
#if USE_MONOTONIC_TIME
/* CLOCK_MONOTONIC might not advance while device is suspended
* which makes it not ideal for timing waking up from suspend ... */
struct timespec ts;

if( clock_gettime(CLOCK_MONOTONIC, &ts) < 0 )
Expand All @@ -122,6 +128,10 @@ static void tv_get_monotime(struct timeval *tv)
}

TIMESPEC_TO_TIMEVAL(tv, &ts);
#else
/* The system changes will cause tests to fail */
gettimeofday(tv, 0);
#endif
}

static int tv_diff_in_ms(const struct timeval *tv1, const struct timeval *tv2)
Expand Down

0 comments on commit 36cf1a4

Please sign in to comment.