CVS commit: src/tests/lib/libc/time

2018-06-03 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Sun Jun  3 08:48:37 UTC 2018

Modified Files:
src/tests/lib/libc/time: t_strptime.c

Log Message:
use ATF_CHECK instead of ATF_REQUIRE
(continue on failure, to see the rest of the failures)

>From Ngie Cooper in PR bin/51834


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/lib/libc/time/t_strptime.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/time/t_strptime.c
diff -u src/tests/lib/libc/time/t_strptime.c:1.14 src/tests/lib/libc/time/t_strptime.c:1.15
--- src/tests/lib/libc/time/t_strptime.c:1.14	Fri Oct 27 05:14:11 2017
+++ src/tests/lib/libc/time/t_strptime.c	Sun Jun  3 08:48:37 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: t_strptime.c,v 1.14 2017/10/27 05:14:11 kre Exp $ */
+/* $NetBSD: t_strptime.c,v 1.15 2018/06/03 08:48:37 maya Exp $ */
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_strptime.c,v 1.14 2017/10/27 05:14:11 kre Exp $");
+__RCSID("$NetBSD: t_strptime.c,v 1.15 2018/06/03 08:48:37 maya Exp $");
 
 #include 
 #include 
@@ -51,12 +51,12 @@ h_pass(const char *buf, const char *fmt,
 	exp = buf + len;
 	ret = strptime(buf, fmt, );
 
-	ATF_REQUIRE_MSG(ret == exp,
+	ATF_CHECK_MSG(ret == exp,
 	"strptime(\"%s\", \"%s\", tm): incorrect return code: "
 	"expected: %p, got: %p", buf, fmt, exp, ret);
 
 #define H_REQUIRE_FIELD(field)		\
-		ATF_REQUIRE_MSG(tm.field == field,			\
+		ATF_CHECK_MSG(tm.field == field,			\
 		"strptime(\"%s\", \"%s\", tm): incorrect %s: "	\
 		"expected: %d, but got: %d", buf, fmt,		\
 		___STRING(field), field, tm.field)
@@ -78,7 +78,7 @@ h_fail(const char *buf, const char *fmt)
 {
 	struct tm tm = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, NULL };
 
-	ATF_REQUIRE_MSG(strptime(buf, fmt, ) == NULL, "strptime(\"%s\", "
+	ATF_CHECK_MSG(strptime(buf, fmt, ) == NULL, "strptime(\"%s\", "
 	"\"%s\", ) should fail, but it didn't", buf, fmt);
 }
 
@@ -182,7 +182,7 @@ ztest1(const char *name, const char *fmt
 		break;
 	}
 
-	ATF_REQUIRE_MSG(tm.tm_gmtoff == value,
+	ATF_CHECK_MSG(tm.tm_gmtoff == value,
 	"strptime(\"%s\", \"%s\", ): "
 	"expected: tm.tm_gmtoff=%ld, got: tm.tm_gmtoff=%ld",
 	name, fmt, value, tm.tm_gmtoff);



CVS commit: src/tests/lib/libc/time

2017-10-26 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri Oct 27 05:14:11 UTC 2017

Modified Files:
src/tests/lib/libc/time: t_strptime.c

Log Message:
The Zone test was obviously intended to test %Z rather than %z, otherwise
it would be (and has been) identical to the zone test, which would be a
pointless waste of time.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/tests/lib/libc/time/t_strptime.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/time/t_strptime.c
diff -u src/tests/lib/libc/time/t_strptime.c:1.13 src/tests/lib/libc/time/t_strptime.c:1.14
--- src/tests/lib/libc/time/t_strptime.c:1.13	Thu Aug 24 01:01:09 2017
+++ src/tests/lib/libc/time/t_strptime.c	Fri Oct 27 05:14:11 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: t_strptime.c,v 1.13 2017/08/24 01:01:09 ginsbach Exp $ */
+/* $NetBSD: t_strptime.c,v 1.14 2017/10/27 05:14:11 kre Exp $ */
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_strptime.c,v 1.13 2017/08/24 01:01:09 ginsbach Exp $");
+__RCSID("$NetBSD: t_strptime.c,v 1.14 2017/10/27 05:14:11 kre Exp $");
 
 #include 
 #include 
@@ -438,7 +438,7 @@ ATF_TC_HEAD(Zone, tc)
 
 ATF_TC_BODY(Zone, tc)
 {
-	ztest("%z");
+	ztest("%Z");
 }
 
 ATF_TP_ADD_TCS(tp)



CVS commit: src/tests/lib/libc/time

2017-10-26 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri Oct 27 00:55:27 UTC 2017

Modified Files:
src/tests/lib/libc/time: t_mktime.c

Log Message:
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.)


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libc/time/t_mktime.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/time/t_mktime.c
diff -u src/tests/lib/libc/time/t_mktime.c:1.5 src/tests/lib/libc/time/t_mktime.c:1.6
--- src/tests/lib/libc/time/t_mktime.c:1.5	Sun Mar 18 07:33:58 2012
+++ src/tests/lib/libc/time/t_mktime.c	Fri Oct 27 00:55:27 2017
@@ -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 @@ ATF_TC_BODY(mktime_negyear, tc)
 	time_t t;
 
 	(void)memset(, 0, sizeof(tms));
-	tms.tm_year = ~0;
+	tms.tm_year = -1;
+	tms.tm_mday = 1;
 
 	errno = 0;
 	t = mktime();
-	ATF_REQUIRE_ERRNO(0, t != (time_t)-1);
+	ATF_REQUIRE(t != (time_t)-1);
 }
 
 ATF_TC(timegm_epoch);
@@ -92,7 +93,7 @@ ATF_TC_BODY(timegm_epoch, tc)
 	tms.tm_year = 1970 - 1900;
 	tms.tm_mday = 1;
 	t = timegm();
-	ATF_REQUIRE_ERRNO(0, t == (time_t)0);
+	ATF_REQUIRE(t == (time_t)0);
 
 	/* one second after midnight on 1 Jan 1970 */
 	(void)memset(, 0, sizeof(tms));
@@ -101,7 +102,7 @@ ATF_TC_BODY(timegm_epoch, tc)
 	tms.tm_mday = 1;
 	tms.tm_sec = 1;
 	t = timegm();
-	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 @@ ATF_TC_BODY(timegm_epoch, tc)
 	tms.tm_min = 59;
 	tms.tm_sec = 59;
 	t = timegm();
-	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 @@ ATF_TC_BODY(timegm_epoch, tc)
 	tms.tm_mday = 1;
 	tms.tm_sec = -1;
 	t = timegm();
-	ATF_REQUIRE_ERRNO(0, t == (time_t)-1);
+	ATF_REQUIRE(t == (time_t)-1);
 
 	/*
 	 * Two seconds before the epoch.
@@ -139,7 +141,7 @@ ATF_TC_BODY(timegm_epoch, tc)
 	tms.tm_mday = 1;
 	tms.tm_sec = -2;
 	t = timegm();
-	ATF_REQUIRE_ERRNO(0, t == (time_t)-2);
+	ATF_REQUIRE(t == (time_t)-2);
 
 }
 



CVS commit: src/tests/lib/libc/time

2015-10-30 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Oct 31 02:13:41 UTC 2015

Modified Files:
src/tests/lib/libc/time: t_strptime.c

Log Message:
Account for J, fix %Z


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/lib/libc/time/t_strptime.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/time/t_strptime.c
diff -u src/tests/lib/libc/time/t_strptime.c:1.10 src/tests/lib/libc/time/t_strptime.c:1.11
--- src/tests/lib/libc/time/t_strptime.c:1.10	Fri Oct 30 14:25:49 2015
+++ src/tests/lib/libc/time/t_strptime.c	Fri Oct 30 22:13:41 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: t_strptime.c,v 1.10 2015/10/30 18:25:49 christos Exp $ */
+/* $NetBSD: t_strptime.c,v 1.11 2015/10/31 02:13:41 christos Exp $ */
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -32,10 +32,11 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_strptime.c,v 1.10 2015/10/30 18:25:49 christos Exp $");
+__RCSID("$NetBSD: t_strptime.c,v 1.11 2015/10/31 02:13:41 christos Exp $");
 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -148,7 +149,7 @@ static struct {
 	{ "X",39600 },
 	{ "Y",43200 },
 
-	{ "J",-1 },
+	{ "J",-2 },
 
 	{ "America/Los_Angeles",	-28800 },
 	{ "America/New_York",		-18000 },
@@ -161,14 +162,31 @@ static void
 ztest(const char *name, const char *fmt, long value)
 {
 	struct tm tm;
+	char *rv;
 
 	memset(, 0, sizeof(tm));
-	if (strptime(name, fmt, ) == NULL) 
+	if ((rv = strptime(name, fmt, )) == NULL) 
 		tm.tm_gmtoff = -1;
+	else if (rv == name && fmt[1] == 'Z')
+		value = 0;
+
+	switch (value) {
+	case -2:
+		value = -timezone;
+		break;
+	case -1:
+		if (fmt[1] == 'Z')
+			value = 0;
+		break;
+	default:
+		break;
+	}
+
 	ATF_REQUIRE_MSG(tm.tm_gmtoff == value,
 	"strptime(\"%s\", \"%s\", ): "
 	"expected: tm.tm_gmtoff=%ld, got: tm.tm_gmtoff=%ld",
 	name, fmt, value, tm.tm_gmtoff);
+	printf("%s %s %ld\n", name, fmt, tm.tm_gmtoff);
 }
 
 ATF_TC(common);
@@ -418,7 +436,7 @@ ATF_TC_BODY(Zone, tc)
 
 	/* This is all handled by tzalloc for %Z */
 	for (size_t i = 0; i < __arraycount(zt); i++)
-		ztest(zt[i].name, "%z", zt[i].offs);
+		ztest(zt[i].name, "%Z", zt[i].offs);
 }
 
 ATF_TP_ADD_TCS(tp)



CVS commit: src/tests/lib/libc/time

2015-10-30 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Oct 31 02:25:11 UTC 2015

Modified Files:
src/tests/lib/libc/time: t_strptime.c

Log Message:
merge more the tests


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/tests/lib/libc/time/t_strptime.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/time/t_strptime.c
diff -u src/tests/lib/libc/time/t_strptime.c:1.11 src/tests/lib/libc/time/t_strptime.c:1.12
--- src/tests/lib/libc/time/t_strptime.c:1.11	Fri Oct 30 22:13:41 2015
+++ src/tests/lib/libc/time/t_strptime.c	Fri Oct 30 22:25:11 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: t_strptime.c,v 1.11 2015/10/31 02:13:41 christos Exp $ */
+/* $NetBSD: t_strptime.c,v 1.12 2015/10/31 02:25:11 christos Exp $ */
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_strptime.c,v 1.11 2015/10/31 02:13:41 christos Exp $");
+__RCSID("$NetBSD: t_strptime.c,v 1.12 2015/10/31 02:25:11 christos Exp $");
 
 #include 
 #include 
@@ -159,7 +159,7 @@ static struct {
 };
 
 static void
-ztest(const char *name, const char *fmt, long value)
+ztest1(const char *name, const char *fmt, long value)
 {
 	struct tm tm;
 	char *rv;
@@ -189,6 +189,17 @@ ztest(const char *name, const char *fmt,
 	printf("%s %s %ld\n", name, fmt, tm.tm_gmtoff);
 }
 
+static void
+ztest(const char *fmt)
+{
+	setenv("TZ", "US/Eastern", 1);
+	ztest1("GMT", fmt, 0);
+	ztest1("UTC", fmt, 0);
+	ztest1("US/Eastern", fmt, -18000);
+	for (size_t i = 0; i < __arraycount(zt); i++)
+		ztest1(zt[i].name, fmt, zt[i].offs);
+}
+
 ATF_TC(common);
 
 ATF_TC_HEAD(common, tc)
@@ -412,8 +423,7 @@ ATF_TC_HEAD(zone, tc)
 
 ATF_TC_BODY(zone, tc)
 {
-	for (size_t i = 0; i < __arraycount(zt); i++)
-		ztest(zt[i].name, "%z", zt[i].offs);
+	ztest("%z");
 }
 
 ATF_TC(Zone);
@@ -428,15 +438,7 @@ ATF_TC_HEAD(Zone, tc)
 
 ATF_TC_BODY(Zone, tc)
 {
-	/* Test the hard-coded stuff */
-	setenv("TZ", "US/Eastern", 1);
-	ztest("GMT", "%Z", 0);
-	ztest("UTC", "%Z", 0);
-	ztest("US/Eastern", "%Z", -18000);
-
-	/* This is all handled by tzalloc for %Z */
-	for (size_t i = 0; i < __arraycount(zt); i++)
-		ztest(zt[i].name, "%Z", zt[i].offs);
+	ztest("%z");
 }
 
 ATF_TP_ADD_TCS(tp)



CVS commit: src/tests/lib/libc/time

2015-10-30 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Oct 30 18:25:50 UTC 2015

Modified Files:
src/tests/lib/libc/time: t_strptime.c

Log Message:
tests for %Z


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/lib/libc/time/t_strptime.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/time/t_strptime.c
diff -u src/tests/lib/libc/time/t_strptime.c:1.9 src/tests/lib/libc/time/t_strptime.c:1.10
--- src/tests/lib/libc/time/t_strptime.c:1.9	Thu Oct 29 23:18:10 2015
+++ src/tests/lib/libc/time/t_strptime.c	Fri Oct 30 14:25:49 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: t_strptime.c,v 1.9 2015/10/30 03:18:10 ginsbach Exp $ */
+/* $NetBSD: t_strptime.c,v 1.10 2015/10/30 18:25:49 christos Exp $ */
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -32,9 +32,10 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_strptime.c,v 1.9 2015/10/30 03:18:10 ginsbach Exp $");
+__RCSID("$NetBSD: t_strptime.c,v 1.10 2015/10/30 18:25:49 christos Exp $");
 
 #include 
+#include 
 
 #include 
 
@@ -80,6 +81,96 @@ h_fail(const char *buf, const char *fmt)
 	"\"%s\", ) should fail, but it didn't", buf, fmt);
 }
 
+static struct {
+	const char *name;
+	long offs;
+} zt[] = {
+	{ "Z",0 },
+	{ "UT",0 },
+	{ "UTC",			0 },
+	{ "GMT",			0 },
+	{ "EST",			-18000 },
+	{ "EDT",			-14400 },
+	{ "CST",			-21600 },
+	{ "CDT",			-18000 },
+	{ "MST",			-25200 },
+	{ "MDT",			-21600 },
+	{ "PST",			-28800 },
+	{ "PDT",			-25200 },
+
+	{ "VST",			-1 },
+	{ "VDT",			-1 },
+
+	{ "+03",			10800 },
+	{ "-03",			-10800 },
+	{ "+0403",			14580 },
+	{ "-0403",			-14580 },
+	{ "+04:03",			14580 },
+	{ "-04:03",			-14580 },
+	{ "+14:00",			50400 },
+	{ "-14:00",			-50400 },
+	{ "+23:59",			86340 },
+	{ "-23:59",			-86340 },
+
+	{ "1",-1 },
+	{ "03",-1 },
+	{ "0304",			-1 },
+	{ "+1",-1 },
+	{ "-203",			-1 },
+	{ "+12345",			-1 },
+	{ "+12:345",			-1 },
+	{ "+123:45",			-1 },
+	{ "+2400",			-1 },
+	{ "-2400",			-1 },
+	{ "+1060",			-1 },
+	{ "-1060",			-1 },
+
+	{ "A",-3600 },
+	{ "B",-7200 },
+	{ "C",-10800 },
+	{ "D",-14400 },
+	{ "E",-18000 },
+	{ "F",-21600 },
+	{ "G",-25200 },
+	{ "H",-28800 },
+	{ "I",-32400 },
+	{ "L",-39600 },
+	{ "M",-43200 },
+	{ "N",3600 },
+	{ "O",7200 },
+	{ "P",10800 },
+	{ "Q",14400 },
+	{ "R",18000 },
+	{ "T",25200 },
+	{ "U",28800 },
+	{ "V",32400 },
+	{ "W",36000 },
+	{ "X",39600 },
+	{ "Y",43200 },
+
+	{ "J",-1 },
+
+	{ "America/Los_Angeles",	-28800 },
+	{ "America/New_York",		-18000 },
+	{ "EST4EDT",			-14400 },
+
+	{ "Bogus",			-1 },
+};
+
+static void
+ztest(const char *name, const char *fmt, long value)
+{
+	struct tm tm;
+
+	memset(, 0, sizeof(tm));
+	if (strptime(name, fmt, ) == NULL) 
+		tm.tm_gmtoff = -1;
+	ATF_REQUIRE_MSG(tm.tm_gmtoff == value,
+	"strptime(\"%s\", \"%s\", ): "
+	"expected: tm.tm_gmtoff=%ld, got: tm.tm_gmtoff=%ld",
+	name, fmt, value, tm.tm_gmtoff);
+}
+
 ATF_TC(common);
 
 ATF_TC_HEAD(common, tc)
@@ -300,94 +391,34 @@ ATF_TC_HEAD(zone, tc)
 			  "Checks strptime(3) timezone conversion [z]");
 }
 
-static struct {
-	const char *name;
-	long offs;
-} zt[] = {
-	{ "Z",0 },
-	{ "UT",0 },
-	{ "UTC",			0 },
-	{ "GMT",			0 },
-	{ "EST",			-18000 },
-	{ "EDT",			-14400 },
-	{ "CST",			-21600 },
-	{ "CDT",			-18000 },
-	{ "MST",			-25200 },
-	{ "MDT",			-21600 },
-	{ "PST",			-28800 },
-	{ "PDT",			-25200 },
-
-	{ "VST",			-1 },
-	{ "VDT",			-1 },
-
-	{ "+03",			10800 },
-	{ "-03",			-10800 },
-	{ "+0403",			14580 },
-	{ "-0403",			-14580 },
-	{ "+04:03",			14580 },
-	{ "-04:03",			-14580 },
-	{ "+14:00",			50400 },
-	{ "-14:00",			-50400 },
-	{ "+23:59",			86340 },
-	{ "-23:59",			-86340 },
 
-	{ "1",-1 },
-	{ "03",-1 },
-	{ "0304",			-1 },
-	{ "+1",-1 },
-	{ "-203",			-1 },
-	{ "+12345",			-1 },
-	{ "+12:345",			-1 },
-	{ "+123:45",			-1 },
-	{ "+2400",			-1 },
-	{ "-2400",			-1 },
-	{ "+1060",			-1 },
-	{ "-1060",			-1 },
+ATF_TC_BODY(zone, tc)
+{
+	for (size_t i = 0; i < __arraycount(zt); i++)
+		ztest(zt[i].name, "%z", zt[i].offs);
+}
 
-	{ "A",-3600 },
-	{ "B",-7200 },
-	{ "C",-10800 },
-	{ "D",-14400 },
-	{ "E",-18000 },
-	{ "F",-21600 },
-	{ "G",-25200 },
-	{ "H",-28800 },
-	{ "I",-32400 },
-	{ "L",-39600 },
-	{ "M",-43200 },
-	{ "N",3600 },
-	{ "O",7200 },
-	{ "P",10800 },
-	{ "Q",14400 },
-	{ "R",18000 },
-	{ "T",25200 },
-	{ "U",28800 },
-	{ "V",32400 },
-	{ "W",36000 },
-	{ "X",39600 },
-	{ "Y",43200 },
+ATF_TC(Zone);
 
-	{ "J",-1 },
+ATF_TC_HEAD(Zone, tc)
+{
 
-	{ "America/Los_Angeles",	-28800 },
-	{ "America/New_York",		-18000 },
-	{ "EST4EDT",			-14400 },
+	atf_tc_set_md_var(tc, "descr",
+			  "Checks strptime(3) timezone 

CVS commit: src/tests/lib/libc/time

2015-10-29 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Oct 29 17:48:21 UTC 2015

Modified Files:
src/tests/lib/libc/time: t_strptime.c

Log Message:
Add tests for %z


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libc/time/t_strptime.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/time/t_strptime.c
diff -u src/tests/lib/libc/time/t_strptime.c:1.6 src/tests/lib/libc/time/t_strptime.c:1.7
--- src/tests/lib/libc/time/t_strptime.c:1.6	Sat Jul  4 09:36:25 2015
+++ src/tests/lib/libc/time/t_strptime.c	Thu Oct 29 13:48:20 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: t_strptime.c,v 1.6 2015/07/04 13:36:25 christos Exp $ */
+/* $NetBSD: t_strptime.c,v 1.7 2015/10/29 17:48:20 christos Exp $ */
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_strptime.c,v 1.6 2015/07/04 13:36:25 christos Exp $");
+__RCSID("$NetBSD: t_strptime.c,v 1.7 2015/10/29 17:48:20 christos Exp $");
 
 #include 
 
@@ -291,6 +291,97 @@ ATF_TC_BODY(year, tc)
 	h_pass("1980", "%EY", 4, -1, -1, -1, -1, -1, 80, -1, -1);
 }
 
+ATF_TC(zone);
+
+ATF_TC_HEAD(zone, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr",
+			  "Checks strptime(3) timezone conversion [z]");
+}
+
+static struct {
+	const char *name;
+	long offs;
+} zt[] = {
+	{ "Z",0 },
+	{ "UT",0 },
+	{ "UTC",			0 },
+	{ "GMT",			0 },
+	{ "EST",			-18000 },
+	{ "EDT",			-14400 },
+	{ "CST",			-21600 },
+	{ "CDT",			-18000 },
+	{ "MST",			-25200 },
+	{ "MDT",			-21600 },
+	{ "PST",			-28800 },
+	{ "PDT",			-25200 },
+
+	{ "VST",			-1 },
+	{ "VDT",			-1 },
+
+	{ "+03",			10800 },
+	{ "-03",			-10800 },
+	{ "+0403",			14580 },
+	{ "-0403",			-14580 },
+	{ "+04:03",			14580 },
+	{ "-04:03",			-14580 },
+
+	{ "1",-1 },
+	{ "03",-1 },
+	{ "0304",			-1 },
+	{ "+1",-1 },
+	{ "-203",			-1 },
+	{ "+12345",			-1 },
+	{ "+12:345",			-1 },
+	{ "+123:45",			-1 },
+
+	{ "A",-3600 },
+	{ "B",-7200 },
+	{ "C",-10800 },
+	{ "D",-14400 },
+	{ "E",-18000 },
+	{ "F",-21600 },
+	{ "G",-25200 },
+	{ "H",-28800 },
+	{ "I",-32400 },
+	{ "L",-39600 },
+	{ "M",-43200 },
+	{ "N",3600 },
+	{ "O",7200 },
+	{ "P",10800 },
+	{ "Q",14400 },
+	{ "R",18000 },
+	{ "T",25200 },
+	{ "U",28800 },
+	{ "V",32400 },
+	{ "W",36000 },
+	{ "X",39600 },
+	{ "Y",43200 },
+
+	{ "J",-1 },
+
+	{ "America/Los_Angeles",	-28800 },
+	{ "America/New_York",		-18000 },
+	{ "EST4EDT",			-14400 },
+
+	{ "Bogus",			-1 },
+};
+
+ATF_TC_BODY(zone, tc)
+{
+	struct tm tm;
+
+	for (size_t i = 0; i < __arraycount(zt); i++) {
+		if (strptime(zt[i].name, "%z", ) == NULL)
+			tm.tm_gmtoff = -1;
+		ATF_REQUIRE_MSG(tm.tm_gmtoff == zt[i].offs,
+		"strptime(\"%s\", \"%%z\", ): "
+		"expected: tm.tm_gmtoff=%ld, got: tm.tm_gmtoff=%ld",
+		zt[i].name, zt[i].offs, tm.tm_gmtoff);
+	}
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 
@@ -300,6 +391,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, month);
 	ATF_TP_ADD_TC(tp, seconds);
 	ATF_TP_ADD_TC(tp, year);
+	ATF_TP_ADD_TC(tp, zone);
 
 	return atf_no_error();
 }



CVS commit: src/tests/lib/libc/time

2015-10-29 Thread Brian Ginsbach
Module Name:src
Committed By:   ginsbach
Date:   Fri Oct 30 01:51:15 UTC 2015

Modified Files:
src/tests/lib/libc/time: t_strptime.c

Log Message:
Additional tests for timezone offsets.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libc/time/t_strptime.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/time/t_strptime.c
diff -u src/tests/lib/libc/time/t_strptime.c:1.7 src/tests/lib/libc/time/t_strptime.c:1.8
--- src/tests/lib/libc/time/t_strptime.c:1.7	Thu Oct 29 17:48:20 2015
+++ src/tests/lib/libc/time/t_strptime.c	Fri Oct 30 01:51:15 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: t_strptime.c,v 1.7 2015/10/29 17:48:20 christos Exp $ */
+/* $NetBSD: t_strptime.c,v 1.8 2015/10/30 01:51:15 ginsbach Exp $ */
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_strptime.c,v 1.7 2015/10/29 17:48:20 christos Exp $");
+__RCSID("$NetBSD: t_strptime.c,v 1.8 2015/10/30 01:51:15 ginsbach Exp $");
 
 #include 
 
@@ -335,6 +335,10 @@ static struct {
 	{ "+12345",			-1 },
 	{ "+12:345",			-1 },
 	{ "+123:45",			-1 },
+	{ "+1430",			-1 },
+	{ "-1430",			-1 },
+	{ "+1060",			-1 },
+	{ "-1060",			-1 },
 
 	{ "A",-3600 },
 	{ "B",-7200 },



CVS commit: src/tests/lib/libc/time

2015-07-04 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Jul  4 13:36:25 UTC 2015

Modified Files:
src/tests/lib/libc/time: t_strptime.c

Log Message:
strptime now sets tm_yday


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libc/time/t_strptime.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/time/t_strptime.c
diff -u src/tests/lib/libc/time/t_strptime.c:1.5 src/tests/lib/libc/time/t_strptime.c:1.6
--- src/tests/lib/libc/time/t_strptime.c:1.5	Tue Apr 28 12:06:09 2015
+++ src/tests/lib/libc/time/t_strptime.c	Sat Jul  4 09:36:25 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: t_strptime.c,v 1.5 2015/04/28 16:06:09 ginsbach Exp $ */
+/* $NetBSD: t_strptime.c,v 1.6 2015/07/04 13:36:25 christos Exp $ */
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include sys/cdefs.h
 __COPYRIGHT(@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.);
-__RCSID($NetBSD: t_strptime.c,v 1.5 2015/04/28 16:06:09 ginsbach Exp $);
+__RCSID($NetBSD: t_strptime.c,v 1.6 2015/07/04 13:36:25 christos Exp $);
 
 #include time.h
 
@@ -92,17 +92,17 @@ ATF_TC_BODY(common, tc)
 {
 
 	h_pass(Tue Jan 20 23:27:46 1998, %a %b %d %T %Y,
-		24, 46, 27, 23, 20, 0, 98, 2, -1);
+		24, 46, 27, 23, 20, 0, 98, 2, 19);
 	h_pass(Tue Jan 20 23:27:46 1998, %a %b %d %H:%M:%S %Y,
-		24, 46, 27, 23, 20, 0, 98, 2, -1);
+		24, 46, 27, 23, 20, 0, 98, 2, 19);
 	h_pass(Tue Jan 20 23:27:46 1998, %c,
-		24, 46, 27, 23, 20, 0, 98, 2, -1);
+		24, 46, 27, 23, 20, 0, 98, 2, 19);
 	h_pass(Fri Mar  4 20:05:34 2005, %a %b %e %H:%M:%S %Y,
-		24, 34, 5, 20, 4, 2, 105, 5, -1);
+		24, 34, 5, 20, 4, 2, 105, 5, 62);
 	h_pass(5\t3  4 8pm:05:34 2005, %w%n%m%t%d%n%k%p:%M:%S %Y,
-		21, 34, 5, 20, 4, 2, 105, 5, -1);
+		21, 34, 5, 20, 4, 2, 105, 5, 62);
 	h_pass(Fri Mar  4 20:05:34 2005, %c,
-		24, 34, 5, 20, 4, 2, 105, 5, -1);
+		24, 34, 5, 20, 4, 2, 105, 5, 62);
 }
 
 ATF_TC(day);



CVS commit: src/tests/lib/libc/time

2015-04-28 Thread Brian Ginsbach
Module Name:src
Committed By:   ginsbach
Date:   Tue Apr 28 16:06:09 UTC 2015

Modified Files:
src/tests/lib/libc/time: t_strptime.c

Log Message:
Add hour tests as a standalone test case.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/time/t_strptime.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/time/t_strptime.c
diff -u src/tests/lib/libc/time/t_strptime.c:1.4 src/tests/lib/libc/time/t_strptime.c:1.5
--- src/tests/lib/libc/time/t_strptime.c:1.4	Wed Apr 22 13:15:30 2015
+++ src/tests/lib/libc/time/t_strptime.c	Tue Apr 28 16:06:09 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: t_strptime.c,v 1.4 2015/04/22 13:15:30 ginsbach Exp $ */
+/* $NetBSD: t_strptime.c,v 1.5 2015/04/28 16:06:09 ginsbach Exp $ */
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include sys/cdefs.h
 __COPYRIGHT(@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.);
-__RCSID($NetBSD: t_strptime.c,v 1.4 2015/04/22 13:15:30 ginsbach Exp $);
+__RCSID($NetBSD: t_strptime.c,v 1.5 2015/04/28 16:06:09 ginsbach Exp $);
 
 #include time.h
 
@@ -158,6 +158,28 @@ ATF_TC_BODY(day, tc)
 	h_fail(SaturDay, %OA);
 }
 
+ATF_TC(hour);
+
+ATF_TC_HEAD(hour, tc)
+{
+
+	atf_tc_set_md_var(tc, descr,
+			  Checks strptime(3) hour conversions [IH]);
+}
+
+ATF_TC_BODY(hour, tc)
+{
+
+	h_fail(00, %I);
+	h_fail(13, %I);
+
+	h_pass(00, %H, 2, -1, -1, 0, -1, -1, -1, -1, -1);
+	h_pass(12, %H, 2, -1, -1, 12, -1, -1, -1, -1, -1);
+	h_pass(23, %H, 2, -1, -1, 23, -1, -1, -1, -1, -1);
+	h_fail(24, %H);
+}
+
+
 ATF_TC(month);
 
 ATF_TC_HEAD(month, tc)
@@ -274,6 +296,7 @@ ATF_TP_ADD_TCS(tp)
 
 	ATF_TP_ADD_TC(tp, common);
 	ATF_TP_ADD_TC(tp, day);
+	ATF_TP_ADD_TC(tp, hour);
 	ATF_TP_ADD_TC(tp, month);
 	ATF_TP_ADD_TC(tp, seconds);
 	ATF_TP_ADD_TC(tp, year);



CVS commit: src/tests/lib/libc/time

2015-04-22 Thread Brian Ginsbach
Module Name:src
Committed By:   ginsbach
Date:   Wed Apr 22 13:15:30 UTC 2015

Modified Files:
src/tests/lib/libc/time: t_strptime.c

Log Message:
Make century and year conversion tests a standalone test case rather than
part of the common test case.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/time/t_strptime.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/time/t_strptime.c
diff -u src/tests/lib/libc/time/t_strptime.c:1.3 src/tests/lib/libc/time/t_strptime.c:1.4
--- src/tests/lib/libc/time/t_strptime.c:1.3	Tue Apr 21 17:39:50 2015
+++ src/tests/lib/libc/time/t_strptime.c	Wed Apr 22 13:15:30 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: t_strptime.c,v 1.3 2015/04/21 17:39:50 ginsbach Exp $ */
+/* $NetBSD: t_strptime.c,v 1.4 2015/04/22 13:15:30 ginsbach Exp $ */
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include sys/cdefs.h
 __COPYRIGHT(@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.);
-__RCSID($NetBSD: t_strptime.c,v 1.3 2015/04/21 17:39:50 ginsbach Exp $);
+__RCSID($NetBSD: t_strptime.c,v 1.4 2015/04/22 13:15:30 ginsbach Exp $);
 
 #include time.h
 
@@ -103,16 +103,6 @@ ATF_TC_BODY(common, tc)
 		21, 34, 5, 20, 4, 2, 105, 5, -1);
 	h_pass(Fri Mar  4 20:05:34 2005, %c,
 		24, 34, 5, 20, 4, 2, 105, 5, -1);
-
-	h_pass(x20y, x%Cy, 4, -1, -1, -1, -1, -1, 100, -1, -1);
-	h_pass(x84y, x%yy, 4, -1, -1, -1, -1, -1, 84, -1, -1);
-	h_pass(x2084y, x%C%yy, 6, -1, -1, -1, -1, -1, 184, -1, -1);
-	h_pass(x8420y, x%y%Cy, 6, -1, -1, -1, -1, -1, 184, -1, -1);
-	h_pass(%20845, %%%C%y5, 6, -1, -1, -1, -1, -1, 184, -1, -1);
-	h_fail(%, %E%);
-
-	h_pass(1980, %Y, 4, -1, -1, -1, -1, -1, 80, -1, -1);
-	h_pass(1980, %EY, 4, -1, -1, -1, -1, -1, 80, -1, -1);
 }
 
 ATF_TC(day);
@@ -256,6 +246,29 @@ ATF_TC_BODY(seconds, tc)
 	h_fail(62, %S);
 }
 
+ATF_TC(year);
+
+ATF_TC_HEAD(year, tc)
+{
+
+	atf_tc_set_md_var(tc, descr,
+			  Checks strptime(3) century/year conversions [CyY]);
+}
+
+ATF_TC_BODY(year, tc)
+{
+
+	h_pass(x20y, x%Cy, 4, -1, -1, -1, -1, -1, 100, -1, -1);
+	h_pass(x84y, x%yy, 4, -1, -1, -1, -1, -1, 84, -1, -1);
+	h_pass(x2084y, x%C%yy, 6, -1, -1, -1, -1, -1, 184, -1, -1);
+	h_pass(x8420y, x%y%Cy, 6, -1, -1, -1, -1, -1, 184, -1, -1);
+	h_pass(%20845, %%%C%y5, 6, -1, -1, -1, -1, -1, 184, -1, -1);
+	h_fail(%, %E%);
+
+	h_pass(1980, %Y, 4, -1, -1, -1, -1, -1, 80, -1, -1);
+	h_pass(1980, %EY, 4, -1, -1, -1, -1, -1, 80, -1, -1);
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 
@@ -263,6 +276,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, day);
 	ATF_TP_ADD_TC(tp, month);
 	ATF_TP_ADD_TC(tp, seconds);
+	ATF_TP_ADD_TC(tp, year);
 
 	return atf_no_error();
 }



CVS commit: src/tests/lib/libc/time

2015-04-17 Thread Brian Ginsbach
Module Name:src
Committed By:   ginsbach
Date:   Fri Apr 17 15:13:47 UTC 2015

Modified Files:
src/tests/lib/libc/time: t_strptime.c

Log Message:
Add more detail to test descriptions.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/time/t_strptime.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/time/t_strptime.c
diff -u src/tests/lib/libc/time/t_strptime.c:1.1 src/tests/lib/libc/time/t_strptime.c:1.2
--- src/tests/lib/libc/time/t_strptime.c:1.1	Thu Jan 13 00:14:10 2011
+++ src/tests/lib/libc/time/t_strptime.c	Fri Apr 17 15:13:47 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: t_strptime.c,v 1.1 2011/01/13 00:14:10 pgoyette Exp $ */
+/* $NetBSD: t_strptime.c,v 1.2 2015/04/17 15:13:47 ginsbach Exp $ */
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include sys/cdefs.h
 __COPYRIGHT(@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.);
-__RCSID($NetBSD: t_strptime.c,v 1.1 2011/01/13 00:14:10 pgoyette Exp $);
+__RCSID($NetBSD: t_strptime.c,v 1.2 2015/04/17 15:13:47 ginsbach Exp $);
 
 #include time.h
 
@@ -126,7 +126,8 @@ ATF_TC(day);
 ATF_TC_HEAD(day, tc)
 {
 
-	atf_tc_set_md_var(tc, descr, Checks strptime(3): day names);
+	atf_tc_set_md_var(tc, descr,
+			  Checks strptime(3) day name conversions [aA]);
 }
 
 ATF_TC_BODY(day, tc)
@@ -178,7 +179,8 @@ ATF_TC(month);
 ATF_TC_HEAD(month, tc)
 {
 
-	atf_tc_set_md_var(tc, descr, Checks strptime(3): month names);
+	atf_tc_set_md_var(tc, descr,
+			  Checks strptime(3) month name conversions [bB]);
 }
 
 ATF_TC_BODY(month, tc)



CVS commit: src/tests/lib/libc/time

2012-03-18 Thread Jukka Ruohonen
Module Name:src
Committed By:   jruoho
Date:   Sun Mar 18 07:33:58 UTC 2012

Modified Files:
src/tests/lib/libc/time: t_mktime.c

Log Message:
Add a test case for the old NetBSD 2.0 era PR lib/28324.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/time/t_mktime.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/time/t_mktime.c
diff -u src/tests/lib/libc/time/t_mktime.c:1.4 src/tests/lib/libc/time/t_mktime.c:1.5
--- src/tests/lib/libc/time/t_mktime.c:1.4	Sat Jan  7 15:05:22 2012
+++ src/tests/lib/libc/time/t_mktime.c	Sun Mar 18 07:33:58 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mktime.c,v 1.4 2012/01/07 15:05:22 martin Exp $ */
+/* $NetBSD: t_mktime.c,v 1.5 2012/03/18 07:33:58 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -33,11 +33,32 @@
 #include string.h
 #include time.h
 
-ATF_TC(mktime_negyear);
+ATF_TC(localtime_r_gmt);
+ATF_TC_HEAD(localtime_r_gmt, tc)
+{
+	atf_tc_set_md_var(tc, descr, Test that localtime_r(3) 
+	returns localtime, not GMT (PR lib/28324));
+}
 
-ATF_TC_HEAD(mktime_negyear, tc)
+ATF_TC_BODY(localtime_r_gmt, tc)
 {
+	struct tm *t;
+	struct tm tt;
+	time_t x;
+
+	x = time(NULL);
+	localtime_r(x, tt);
+	t = localtime(x);
+
+	if (t-tm_sec != tt.tm_sec || t-tm_min != tt.tm_min ||
+	t-tm_hour != tt.tm_hour || t-tm_mday != tt.tm_mday)
+		atf_tc_fail(inconsistencies between 
+		localtime(3) and localtime_r(3));
+}
 
+ATF_TC(mktime_negyear);
+ATF_TC_HEAD(mktime_negyear, tc)
+{
 	atf_tc_set_md_var(tc, descr, Test mktime(3) with negative year);
 }
 
@@ -55,10 +76,8 @@ ATF_TC_BODY(mktime_negyear, tc)
 }
 
 ATF_TC(timegm_epoch);
-
 ATF_TC_HEAD(timegm_epoch, tc)
 {
-
 	atf_tc_set_md_var(tc, descr, Test timegm(3) close to the epoch);
 }
 
@@ -128,6 +147,7 @@ ATF_TC_BODY(timegm_epoch, tc)
 ATF_TP_ADD_TCS(tp)
 {
 
+	ATF_TP_ADD_TC(tp, localtime_r_gmt);
 	ATF_TP_ADD_TC(tp, mktime_negyear);
 	ATF_TP_ADD_TC(tp, timegm_epoch);
 



CVS commit: src/tests/lib/libc/time

2012-01-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Jan  7 15:05:22 UTC 2012

Modified Files:
src/tests/lib/libc/time: t_mktime.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/time/t_mktime.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/time/t_mktime.c
diff -u src/tests/lib/libc/time/t_mktime.c:1.3 src/tests/lib/libc/time/t_mktime.c:1.4
--- src/tests/lib/libc/time/t_mktime.c:1.3	Sat Dec 17 19:04:07 2011
+++ src/tests/lib/libc/time/t_mktime.c	Sat Jan  7 15:05:22 2012
@@ -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_HEAD(mktime_negyear, tc)
 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_HEAD(timegm_epoch, tc)
 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 @@ ATF_TC_BODY(timegm_epoch, tc)
 	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 @@ ATF_TC_BODY(timegm_epoch, tc)
 	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 @@ ATF_TC_BODY(timegm_epoch, tc)
 	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 @@ ATF_TC_BODY(timegm_epoch, tc)
 	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);
 
 }
 



CVS commit: src/tests/lib/libc/time

2011-12-17 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Sat Dec 17 19:04:07 UTC 2011

Modified Files:
src/tests/lib/libc/time: t_mktime.c

Log Message:
Add some tests for timegm(3) close to the epoch.  In
particular, 1969-12-31 23:59:59 should convert to (time_t)-1
with errno = 0.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/time/t_mktime.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/time/t_mktime.c
diff -u src/tests/lib/libc/time/t_mktime.c:1.2 src/tests/lib/libc/time/t_mktime.c:1.3
--- src/tests/lib/libc/time/t_mktime.c:1.2	Thu Apr  7 18:14:09 2011
+++ src/tests/lib/libc/time/t_mktime.c	Sat Dec 17 19:04:07 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mktime.c,v 1.2 2011/04/07 18:14:09 jruoho Exp $ */
+/* $NetBSD: t_mktime.c,v 1.3 2011/12/17 19:04:07 apb Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -33,15 +33,15 @@
 #include string.h
 #include time.h
 
-ATF_TC(mktime);
+ATF_TC(mktime_negyear);
 
-ATF_TC_HEAD(mktime, tc)
+ATF_TC_HEAD(mktime_negyear, tc)
 {
 
 	atf_tc_set_md_var(tc, descr, Test mktime(3) with negative year);
 }
 
-ATF_TC_BODY(mktime, tc)
+ATF_TC_BODY(mktime_negyear, tc)
 {
 	struct tm tms;
 
@@ -53,10 +53,76 @@ ATF_TC_BODY(mktime, tc)
 	ATF_REQUIRE_ERRNO(errno, mktime(tms) != (time_t)-1);
 }
 
+ATF_TC(timegm_epoch);
+
+ATF_TC_HEAD(timegm_epoch, tc)
+{
+
+	atf_tc_set_md_var(tc, descr, Test timegm(3) close to the epoch);
+}
+
+ATF_TC_BODY(timegm_epoch, tc)
+{
+	struct tm tms;
+
+	/* 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);
+
+	/* one second after midnight on 1 Jan 1970 */
+	(void)memset(tms, 0, sizeof(tms));
+	errno = 0;
+	tms.tm_year = 1970 - 1900;
+	tms.tm_mday = 1;
+	tms.tm_sec = 1;
+	ATF_REQUIRE_ERRNO(errno, timegm(tms) == (time_t)1);
+
+	/*
+	 * 1969-12-31 23:59:59 = one second before the epoch.
+	 * Result should be -1 with errno = 0.
+	 */
+	(void)memset(tms, 0, sizeof(tms));
+	errno = 0;
+	tms.tm_year = 1969 - 1900;
+	tms.tm_mon = 12 - 1;
+	tms.tm_mday = 31;
+	tms.tm_hour = 23;
+	tms.tm_min = 59;
+	tms.tm_sec = 59;
+	ATF_REQUIRE_ERRNO(errno, timegm(tms) == (time_t)-1);
+
+	/*
+	 * Another way of getting one second before the epoch:
+	 * Set date to 1 Jan 1970, and time to -1 second.
+	 */
+	(void)memset(tms, 0, sizeof(tms));
+	errno = 0;
+	tms.tm_year = 1970 - 1900;
+	tms.tm_mday = 1;
+	tms.tm_sec = -1;
+	ATF_REQUIRE_ERRNO(errno, timegm(tms) == (time_t)-1);
+
+	/*
+	 * Two seconds before the epoch.
+	 */
+	(void)memset(tms, 0, sizeof(tms));
+	errno = 0;
+	tms.tm_year = 1970 - 1900;
+	tms.tm_mday = 1;
+	tms.tm_sec = -2;
+	ATF_REQUIRE_ERRNO(errno, timegm(tms) == (time_t)-2);
+
+}
+
+
 ATF_TP_ADD_TCS(tp)
 {
 
-	ATF_TP_ADD_TC(tp, mktime);
+	ATF_TP_ADD_TC(tp, mktime_negyear);
+	ATF_TP_ADD_TC(tp, timegm_epoch);
 
 	return atf_no_error();
 }