GNOME Bugzilla – Bug 506251
src/engine/test/test-date fails on systems with a timezone east of UTC
Last modified: 2018-06-29 21:57:41 UTC
I was seeing multiple failures in src/engine/test/test-date when running "make check". I tracked this down to the usage of mktime() in gnc_iso8601_to_timespec_gmt and gnc_timespec_to_iso8601_buff. When the timespec is (or would be) very close to the epoch, mktime() will fail if the timezone is east of UTC. For example, consider gnc_iso8601_to_timespec_gmt where the resulting timespec should be zero. Because mktime actually returns local time, if the timezone is east of UTC, the local time time_t value corresponding to a zero timespec would actually be negative. mktime cannot handle this and errors out with the value of -1, causing the conversion to fail. src/engine/test/test-date.c has multiple tests that specify/require timespecs at or very close to zero. Lines 93-134 explicitly test strings that should result in a zero timespec, which all fail on systems with timezones east of UTC. In addition, the loops in lines 397-402 and 404-418 can also result in timespecs that will fail. Fixing the loops is easy - simply skip any iterations in which the timespec falls in the range [0, max(0, -gnc_timezone()) ). The zero timespec tests cannot be fixed without either reimplementing gnc_iso8601_to_timespec_gmt to not depend on mktime, or changing the test to use a timespec at least twelve hours later than the zero timespec. They could probably also be safely removed since there are plenty of other tests using non-failing timespecs to make sure the conversions happen properly. It is unlikely that the zero timespec tests will catch any errors that the other tests will not.
Is this still an issue. I understand this is a compile-time problem. I still wonder if it has anything to do with bug 137017.
Created attachment 122750 [details] Output from test-date when failing. Yes, it is still an issue. The test compiles fine, it simply fails at run-time when run on a system with a time zone east of UTC (for example, UTC+10:00 for Sydney, Australia). I have attached the output of the test in the failure case.
Created attachment 122751 [details] [review] Simplistic fix to test-date.c to prevent timezone-related failures. Here is a patch that fixes this problem in a very simplistic way: it removes all the calls to check_conversion which test zero seconds (the epoch) and it changes the check_time function to skip any timestamps that are before noon on January 1, 1970, UTC. This may not be the best approach to solving the problem, however.
Committed to trunk, r17721. Thanks!
GnuCash bug tracking has moved to a new Bugzilla host. This bug has been copied to https://bugs.gnucash.org/show_bug.cgi?id=506251. Please update any external references or bookmarks.