Skip to content

Commit

Permalink
selftests: timers: set-timer-lat: Fix hang when testing unsupported a…
Browse files Browse the repository at this point in the history
…larms

When timer_create() fails on a bootime or realtime clock, setup_timer()
returns 0 as if timer has been set. Callers wait forever for the timer
to expire.

This hang is seen on a system that doesn't have support for:

CLOCK_REALTIME_ALARM   ABSTIME missing CAP_WAKE_ALARM? : [UNSUPPORTED]

Test hangs waiting for a timer that hasn't been set to expire. Fix
setup_timer() to return 1, add handling in callers to detect the
unsupported case and return 0 without waiting to not fail the test.

Signed-off-by: Shuah Khan <[email protected]>
  • Loading branch information
Shuah Khan committed Sep 25, 2017
1 parent 01db7fb commit eefd95e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tools/testing/selftests/timers/set-timer-lat.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ int setup_timer(int clock_id, int flags, int interval, timer_t *tm1)
printf("%-22s %s missing CAP_WAKE_ALARM? : [UNSUPPORTED]\n",
clockstring(clock_id),
flags ? "ABSTIME":"RELTIME");
return 0;
/* Indicate timer isn't set, so caller doesn't wait */
return 1;
}
printf("%s - timer_create() failed\n", clockstring(clock_id));
return -1;
Expand Down Expand Up @@ -213,8 +214,9 @@ int do_timer(int clock_id, int flags)
int err;

err = setup_timer(clock_id, flags, interval, &tm1);
/* Unsupported case - return 0 to not fail the test */
if (err)
return err;
return err == 1 ? 0 : err;

while (alarmcount < 5)
sleep(1);
Expand All @@ -231,8 +233,9 @@ int do_timer_oneshot(int clock_id, int flags)
int err;

err = setup_timer(clock_id, flags, interval, &tm1);
/* Unsupported case - return 0 to not fail the test */
if (err)
return err;
return err == 1 ? 0 : err;

memset(&timeout, 0, sizeof(timeout));
timeout.tv_sec = 5;
Expand Down

0 comments on commit eefd95e

Please sign in to comment.