summaryrefslogtreecommitdiffstats
path: root/tests/udelay.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/udelay.c')
-rw-r--r--tests/udelay.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/tests/udelay.c b/tests/udelay.c
index 277a15dc7..8d24b00dd 100644
--- a/tests/udelay.c
+++ b/tests/udelay.c
@@ -34,6 +34,8 @@ static uint64_t now_us(void) {
#endif
}
+static const int64_t min_sleep = CONFIG_DELAY_MINIMUM_SLEEP_US;
+
/*
* A short delay should delay for at least as long as requested,
* and more than 10x as long would be worrisome.
@@ -43,9 +45,21 @@ static uint64_t now_us(void) {
* test.
*/
void udelay_test_short(void **state) {
+ /*
+ * Delay for 100 microseconds, or short enough that we won't sleep.
+ * It's not useful to test the sleep path because we assume the OS won't
+ * sleep for less time than we ask.
+ */
+ int64_t delay_us = 100;
+ if (delay_us >= min_sleep)
+ delay_us = min_sleep - 1;
+ /* No point in running this test if delay always sleeps. */
+ if (delay_us <= 0)
+ skip();
+
uint64_t start = now_us();
- default_delay(100);
+ default_delay(delay_us);
uint64_t elapsed = now_us() - start;
- assert_in_range(elapsed, 100, 1000);
+ assert_in_range(elapsed, delay_us, 10 * delay_us);
}