Skip to content

Commit

Permalink
Merge pull request #5 from spiiroin/time_source
Browse files Browse the repository at this point in the history
Use system time for timing wakeups
  • Loading branch information
spiiroin committed Oct 10, 2013
2 parents 0e6517f + 36cf1a4 commit 8f5c41e
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 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 Expand Up @@ -1075,23 +1085,22 @@ static void ranges_test(int *xc)

auto void start(int lo, int hi)
{
timer[timers++] = hbtimer_create(scale(lo), scale(hi), 1);
timer[timers++] = hbtimer_create(scale(lo)+1, scale(hi), 1);
}

/* start timers, expected wakeup pattern something like */

// 0 1 2 3 4 5 6 7 8 9 0 1
// | |
start(0, 7); // A AAAAAAAAAAAAAAA |
start(1, 5); // B BBBBBBBBB |
start(2, 3); // C CCC |
// | |
start(4, 9); // D | DDDDDDDDDDD
start(6,11); // E | EEEEEEEEEEE
start(8,10); // F | FFFFF
// | |
// | |
start(0, 9); // A AAAAAAAAAAAAAAAAAA
start(1, 7); // B BBBBBBBBBBBB |
start(2, 3); // C CC |
// | |
start(5, 8); // D | DDDDDD
start(6,11); // E | EEEEEEEEEE
start(7,10); // F | FFFFFF
// | |
// 0 1 2 3 4 5 6 7 8 9 0 1
// | |
// | |
// group1 group2

/* fail if tests do not finish in time */
Expand Down

0 comments on commit 8f5c41e

Please sign in to comment.