mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-16 01:44:34 +00:00
test: Update time tests to use unit-test asserts
Rather than returning various error codes, use assertions to check that the test passes. Signed-off-by: Simon Glass <sjg@chromium.org> Tested-by: Tom Rini <trini@konsulko.com> # rpi_3, rpi_4, rpi_arm64, am64x_evm_a53, am64-sk
This commit is contained in:
parent
dd0057dacb
commit
88db4fc5fe
1 changed files with 7 additions and 24 deletions
|
@ -22,11 +22,7 @@ static int test_get_timer(struct unit_test_state *uts)
|
|||
next = get_timer(0);
|
||||
} while (start == next);
|
||||
|
||||
if (start + 1 != next) {
|
||||
printf("%s: iter=%d, start=%lu, next=%lu, expected a difference of 1\n",
|
||||
__func__, iter, start, next);
|
||||
return -EINVAL;
|
||||
}
|
||||
ut_asserteq(start + 1, next);
|
||||
start++;
|
||||
}
|
||||
|
||||
|
@ -35,11 +31,7 @@ static int test_get_timer(struct unit_test_state *uts)
|
|||
* an extra millisecond may have passed.
|
||||
*/
|
||||
diff = get_timer(base);
|
||||
if (diff != iter && diff != iter + 1) {
|
||||
printf("%s: expected get_timer(base) to match elapsed time: diff=%lu, expected=%d\n",
|
||||
__func__, diff, iter);
|
||||
return -EINVAL;
|
||||
}
|
||||
ut_assert(diff == iter || diff == iter + 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -57,11 +49,8 @@ static int test_timer_get_us(struct unit_test_state *uts)
|
|||
next = timer_get_us();
|
||||
if (next != prev) {
|
||||
delta = next - prev;
|
||||
if (delta < 0) {
|
||||
printf("%s: timer_get_us() went backwards from %lu to %lu\n",
|
||||
__func__, prev, next);
|
||||
return -EINVAL;
|
||||
} else if (delta != 0) {
|
||||
ut_assert(delta >= 0);
|
||||
if (delta) {
|
||||
if (delta < min)
|
||||
min = delta;
|
||||
prev = next;
|
||||
|
@ -70,11 +59,7 @@ static int test_timer_get_us(struct unit_test_state *uts)
|
|||
}
|
||||
}
|
||||
|
||||
if (min != 1) {
|
||||
printf("%s: Minimum microsecond delta should be 1 but is %lu\n",
|
||||
__func__, min);
|
||||
return -EINVAL;
|
||||
}
|
||||
ut_asserteq(1, min);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -95,8 +80,7 @@ static int test_time_comparison(struct unit_test_state *uts)
|
|||
error = delta_us - 1000000;
|
||||
printf("%s: Microsecond time for 1 second: %lu, error = %ld\n",
|
||||
__func__, delta_us, error);
|
||||
if (abs(error) > 1000)
|
||||
return -EINVAL;
|
||||
ut_assert(abs(error) <= 1000);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -115,8 +99,7 @@ static int test_udelay(struct unit_test_state *uts)
|
|||
error = delta - 1000;
|
||||
printf("%s: Delay time for 1000 udelay(1000): %lu ms, error = %ld\n",
|
||||
__func__, delta, error);
|
||||
if (abs(error) > 100)
|
||||
return -EINVAL;
|
||||
ut_assert(abs(error) <= 100);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue