[PATCH v2] tst: Provide test for difftime
Paul Eggert
eggert@cs.ucla.edu
Wed Jan 27 18:42:37 GMT 2021
On 1/27/21 4:42 AM, Lukasz Majewski wrote:
> This change adds new test to assess difftime's functionality by
> adding some arbitrary offsets to current time_t value (read via
> time).
That would make tests irreproducible. Why is that helpful for difftime?
I suggest using only reproducible tests; this should make the code
simpler anyway.
> +static void
> +test_difftime_helper (time_t start, time_t t1, time_t t0, double exp_val)
The signature should be simpler:
static void
test_difftime_helper (long long t1, long long t0, double exp_val)
And test_difftime_helper can test whether its arguments fit into time_t
with code like this:
time_t u1;
if (__builtin_add_overflow (t1, 0, &u1))
return;
That way, you can omit the 'sizeof (time_t) > 4' test, which is a bit
dubious anyway as it wouldn't work on hypothetical hosts where char is
wider than 8 bits. You can do this sort of thing in all the time_t
tests, to omit all uses of sizeof (time_t).
More information about the Libc-alpha
mailing list