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 ATF_REQUIRE_ERRNO() needs to be used wit...



details:   https://anonhg.NetBSD.org/src/rev/a47b1ed2be67
branches:  trunk
changeset: 772527:a47b1ed2be67
user:      martin <martin%NetBSD.org@localhost>
date:      Sat Jan 07 15:05:22 2012 +0000

description:
ATF_REQUIRE_ERRNO() needs to be used with care:
 - pass the expected errno to it, not "errno"
 - make sure to have errno set already before invoking the macro, i.e.
   do not use it to test errno changes as side effect of the asserted
   expression

Spotted by mlelstv, makes the epoch tests correctly fail on amd64 as
well.

diffstat:

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

diffs (83 lines):

diff -r 55d216befd62 -r a47b1ed2be67 tests/lib/libc/time/t_mktime.c
--- a/tests/lib/libc/time/t_mktime.c    Sat Jan 07 15:03:11 2012 +0000
+++ b/tests/lib/libc/time/t_mktime.c    Sat Jan 07 15:05:22 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mktime.c,v 1.3 2011/12/17 19:04:07 apb Exp $ */
+/* $NetBSD: t_mktime.c,v 1.4 2012/01/07 15:05:22 martin Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -44,13 +44,14 @@
 ATF_TC_BODY(mktime_negyear, tc)
 {
        struct tm tms;
+       time_t t;
 
        (void)memset(&tms, 0, sizeof(tms));
        tms.tm_year = ~0;
 
        errno = 0;
-
-       ATF_REQUIRE_ERRNO(errno, mktime(&tms) != (time_t)-1);
+       t = mktime(&tms);
+       ATF_REQUIRE_ERRNO(0, t != (time_t)-1);
 }
 
 ATF_TC(timegm_epoch);
@@ -64,13 +65,15 @@
 ATF_TC_BODY(timegm_epoch, tc)
 {
        struct tm tms;
+       time_t t;
 
        /* midnight on 1 Jan 1970 */
        (void)memset(&tms, 0, sizeof(tms));
        errno = 0;
        tms.tm_year = 1970 - 1900;
        tms.tm_mday = 1;
-       ATF_REQUIRE_ERRNO(errno, timegm(&tms) == (time_t)0);
+       t = timegm(&tms);
+       ATF_REQUIRE_ERRNO(0, t == (time_t)0);
 
        /* one second after midnight on 1 Jan 1970 */
        (void)memset(&tms, 0, sizeof(tms));
@@ -78,7 +81,8 @@
        tms.tm_year = 1970 - 1900;
        tms.tm_mday = 1;
        tms.tm_sec = 1;
-       ATF_REQUIRE_ERRNO(errno, timegm(&tms) == (time_t)1);
+       t = timegm(&tms);
+       ATF_REQUIRE_ERRNO(0, t == (time_t)1);
 
        /*
         * 1969-12-31 23:59:59 = one second before the epoch.
@@ -92,7 +96,8 @@
        tms.tm_hour = 23;
        tms.tm_min = 59;
        tms.tm_sec = 59;
-       ATF_REQUIRE_ERRNO(errno, timegm(&tms) == (time_t)-1);
+       t = timegm(&tms);
+       ATF_REQUIRE_ERRNO(0, t == (time_t)-1);
 
        /*
         * Another way of getting one second before the epoch:
@@ -103,7 +108,8 @@
        tms.tm_year = 1970 - 1900;
        tms.tm_mday = 1;
        tms.tm_sec = -1;
-       ATF_REQUIRE_ERRNO(errno, timegm(&tms) == (time_t)-1);
+       t = timegm(&tms);
+       ATF_REQUIRE_ERRNO(0, t == (time_t)-1);
 
        /*
         * Two seconds before the epoch.
@@ -113,7 +119,8 @@
        tms.tm_year = 1970 - 1900;
        tms.tm_mday = 1;
        tms.tm_sec = -2;
-       ATF_REQUIRE_ERRNO(errno, timegm(&tms) == (time_t)-2);
+       t = timegm(&tms);
+       ATF_REQUIRE_ERRNO(0, t == (time_t)-2);
 
 }
 



Home | Main Index | Thread Index | Old Index