Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: timers: set-timer-lat: Fix hang when testing unsupported alarms

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 <shuahkh@osg.samsung.com>

+6 -3
+6 -3
tools/testing/selftests/timers/set-timer-lat.c
··· 143 143 printf("%-22s %s missing CAP_WAKE_ALARM? : [UNSUPPORTED]\n", 144 144 clockstring(clock_id), 145 145 flags ? "ABSTIME":"RELTIME"); 146 - return 0; 146 + /* Indicate timer isn't set, so caller doesn't wait */ 147 + return 1; 147 148 } 148 149 printf("%s - timer_create() failed\n", clockstring(clock_id)); 149 150 return -1; ··· 214 213 int err; 215 214 216 215 err = setup_timer(clock_id, flags, interval, &tm1); 216 + /* Unsupported case - return 0 to not fail the test */ 217 217 if (err) 218 - return err; 218 + return err == 1 ? 0 : err; 219 219 220 220 while (alarmcount < 5) 221 221 sleep(1); ··· 233 231 int err; 234 232 235 233 err = setup_timer(clock_id, flags, interval, &tm1); 234 + /* Unsupported case - return 0 to not fail the test */ 236 235 if (err) 237 - return err; 236 + return err == 1 ? 0 : err; 238 237 239 238 memset(&timeout, 0, sizeof(timeout)); 240 239 timeout.tv_sec = 5;