libtests/ttest01: Fix CPU counter precision issues

Change the time to convert so that rounding issues do not propergate to
the second next digit.  Properly round the result used for the precision
estimate.
This commit is contained in:
Sebastian Huber
2024-11-14 03:43:47 +01:00
parent f7b04e72f8
commit 83dccef48d

View File

@@ -155,7 +155,7 @@ T_TEST_CASE(ticks)
m = 10;
do {
if (ns / m == 0) {
if ((ns + m / 2) / m == 0) {
break;
}
@@ -165,13 +165,13 @@ T_TEST_CASE(ticks)
n = 10 - n;
t = T_seconds_and_nanoseconds_to_time(1, 123456789);
t = T_seconds_and_nanoseconds_to_time(1, 100000000);
k = T_time_to_ticks(t);
n += 2;
T_eq_nstr(T_ticks_to_string_ns(k, ts), "1.123456789", n);
T_eq_nstr(T_ticks_to_string_us(k, ts), "1.123456", n);
T_eq_nstr(T_ticks_to_string_ms(k, ts), "1.123", n);
T_eq_nstr(T_ticks_to_string_ns(k, ts), "1.100000000", n);
T_eq_nstr(T_ticks_to_string_us(k, ts), "1.100000", n);
T_eq_nstr(T_ticks_to_string_ms(k, ts), "1.100", n);
T_eq_str(T_ticks_to_string_s(k, ts), "1");
}