Page MenuHomeFreeBSD

fattime: make the test code check beyond 32-bit time_t limits
ClosedPublic

Authored by jeffpc_josefsipek.net on Apr 12 2024, 2:58 AM.
Tags
None
Referenced Files
F102681436: D44754.diff
Fri, Nov 15, 7:16 PM
Unknown Object (File)
Thu, Nov 7, 1:43 PM
Unknown Object (File)
Fri, Oct 18, 2:10 AM
Unknown Object (File)
Fri, Oct 18, 2:09 AM
Unknown Object (File)
Fri, Oct 18, 2:08 AM
Unknown Object (File)
Thu, Oct 17, 11:31 PM
Unknown Object (File)
Thu, Oct 17, 5:37 PM
Unknown Object (File)
Oct 16 2024, 2:39 AM
Subscribers

Details

Summary

On systems that have a 64-bit time_t, the test code now exercises the whole
range of fattime. To do this, this commit...

  1. replaces the call to random() with two calls to arc4random() to generate a 33-bit number of seconds in order to cover the entire range of fattime [1970,2107]. (32-bits stops just short - in January 2106.) On systems with 32-bit time_t, the extra bits are discarded and only the time_t expressible range is tested.
  2. casts time_t values passed to printf as longs and changes the format string to match.

Now, the test code builds, runs, and exercises what it can (i.e., the whole
fattime range or the 32-bit time_t subset of it) on both 32-bit and 64-bit
time_t systems.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

sys/kern/subr_fattime.c
309

I'd be tempted to use (intmax_t) here instead of long. and a corresponding '%jd' format.

sys/kern/subr_fattime.c
284

why just one bit? Why not, say 16, which gets you dates in the next 8 million years... Hmmm, that seems like overkill... but 2 would get you dates through 2234 or so and would provide better coverage. 3 would get us through 2488. 4 through the year 3000 (which may be a nice round number to stop at).

sys/kern/subr_fattime.c
284

The only reason not to use more bits is that the loop is less likely to terminate quickly. With one extra bit it's ~128/272 chance. With 2 extra bits, it is ~128/544. And so on. (128 = number of years expressible by fattime, 272, 544, ... number of years from 1970 until the max time_t value randomly generated)

This is test code, so it shouldn't matter either way as long as it isn't a large number of extra bits. I'm fine with certainly anything <= 4 extra bits, but can be convinced of more.

309

Sure, I'll change it.

generate 36-bit time_t values & use intmax_t for cast

This revision is now accepted and ready to land.Apr 28 2024, 11:14 PM