[tz] tzcode test suite
scs at eskimo.com
Thu Jan 14 01:37:20 UTC 2016
I've been doing some surgery on localtime.c (perhaps more on
that later), and to check my work I felt the need for a decent
gmtime/localtime/mktime test suite. I'm sure such a thing has
been written numbers of times before, and there may be some
reason not to have one in the tzcode distribution, but if not,
I'd like to donate this one for inclusion.
It runs in two modes, one driven by a script containing (in
effect) a list of known-good (time_t, struct tm) pairs, and
another which exhaustively runs a potentially very large set
of synthesized tests over a specified range.
The script contains lines such as
gmtime 1234567890 2009-02-13 23:31:30
localtime 483811200 1985-05-01 12:00:00 z=EDT o=-14400 dst=1
which are used to drive reciprocal pairs of tests on
gmtime/timegm or localtime/mktime, in a reasonably obvious way.
A line like the first one tests both that gmtime(1234567890)
gives 2009-02-13, and also that timegm on 2009-02-13 23:31:30
There are keywords for setting the expected output values for
zone, offset, and DST flag (as shown). There are also additional
keywords to set the expected values of tm_wday and tm_yday.
(See the attached test script for more examples.)
I'm also enclosing a patch to the tzcode Makefile to add a
"make tests" target, building and appropriately invoking this
At the moment this tool tests only localtime, gmtime, mktime,
and timegm. It would make sense to have coverage of ctime and
strftime, too, which would be straightforward enough to add.
Note that the zone names in the attached 'testcases' script match
those built by the stock tzdata distribution, but not necessarily
those installed on the machine where you may be trying to run this.
See the long comment at the top of testsuite.c for additional
scs at eskimo.com
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 44237 bytes
Desc: not available
More information about the tz