Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libc/time Remove bogus errno checks, mktime() (and...



details:   https://anonhg.NetBSD.org/src/rev/4b9a4b8a2da0
branches:  trunk
changeset: 827405:4b9a4b8a2da0
user:      kre <kre%NetBSD.org@localhost>
date:      Fri Oct 27 00:55:27 2017 +0000

description:
Remove bogus errno checks, mktime() (and timegm()) does not guarantee
to leave errno unaltered if there is no error.   And does not.

While here, write -1 the same way everyone else does (not ~0, which
would not even be negative on a 1's complement host, if you can find one).

And while not needed for the test, but so that if checked, the result is
more likely to be what is anticipated, set tm_mday to an in-range value
in the mtime_negyear test (otherwise the correction results in the result
movng backwards to the last day of the previous month, which is the
end of Decemper, 1898, rather than the 1899 one would expect from year -1.)

diffstat:

 tests/lib/libc/time/t_mktime.c |  18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)

diffs (70 lines):

diff -r 90c1cc211114 -r 4b9a4b8a2da0 tests/lib/libc/time/t_mktime.c
--- a/tests/lib/libc/time/t_mktime.c    Thu Oct 26 23:28:14 2017 +0000
+++ b/tests/lib/libc/time/t_mktime.c    Fri Oct 27 00:55:27 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mktime.c,v 1.5 2012/03/18 07:33:58 jruoho Exp $ */
+/* $NetBSD: t_mktime.c,v 1.6 2017/10/27 00:55:27 kre Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -68,11 +68,12 @@
        time_t t;
 
        (void)memset(&tms, 0, sizeof(tms));
-       tms.tm_year = ~0;
+       tms.tm_year = -1;
+       tms.tm_mday = 1;
 
        errno = 0;
        t = mktime(&tms);
-       ATF_REQUIRE_ERRNO(0, t != (time_t)-1);
+       ATF_REQUIRE(t != (time_t)-1);
 }
 
 ATF_TC(timegm_epoch);
@@ -92,7 +93,7 @@
        tms.tm_year = 1970 - 1900;
        tms.tm_mday = 1;
        t = timegm(&tms);
-       ATF_REQUIRE_ERRNO(0, t == (time_t)0);
+       ATF_REQUIRE(t == (time_t)0);
 
        /* one second after midnight on 1 Jan 1970 */
        (void)memset(&tms, 0, sizeof(tms));
@@ -101,7 +102,7 @@
        tms.tm_mday = 1;
        tms.tm_sec = 1;
        t = timegm(&tms);
-       ATF_REQUIRE_ERRNO(0, t == (time_t)1);
+       ATF_REQUIRE(t == (time_t)1);
 
        /*
         * 1969-12-31 23:59:59 = one second before the epoch.
@@ -116,7 +117,8 @@
        tms.tm_min = 59;
        tms.tm_sec = 59;
        t = timegm(&tms);
-       ATF_REQUIRE_ERRNO(0, t == (time_t)-1);
+       ATF_REQUIRE(t == (time_t)-1);
+       /* ATF_REQUIRE(errno == 0); does not work, errno is kept clear */
 
        /*
         * Another way of getting one second before the epoch:
@@ -128,7 +130,7 @@
        tms.tm_mday = 1;
        tms.tm_sec = -1;
        t = timegm(&tms);
-       ATF_REQUIRE_ERRNO(0, t == (time_t)-1);
+       ATF_REQUIRE(t == (time_t)-1);
 
        /*
         * Two seconds before the epoch.
@@ -139,7 +141,7 @@
        tms.tm_mday = 1;
        tms.tm_sec = -2;
        t = timegm(&tms);
-       ATF_REQUIRE_ERRNO(0, t == (time_t)-2);
+       ATF_REQUIRE(t == (time_t)-2);
 
 }
 



Home | Main Index | Thread Index | Old Index