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

2024-07-24 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Jul 24 09:26:06 UTC 2024

Modified Files:
src/tests/lib/libc/stdlib: t_strtoi.c

Log Message:
Add some test cases to tests/lib/libc/stdlib/t_strtoi

PR lib/58461  PR lib/58453

Apologies for the previous commit message - I managed to
forget to include the message filename after commit -F
and so used the file being committed (the only changed file
in the directory) as the log message.   (Fortunately that
meant that the log didn't get appended to the PR).

For the PR, the command to check what actually changed is

cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/stdlib/t_strtoi.c

rather than what will be reported below.

This commit message really belongs to the previous commit,
(1.5) there are no changes at all in this one.

No pullups required.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/stdlib/t_strtoi.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/stdlib/t_strtoi.c
diff -u src/tests/lib/libc/stdlib/t_strtoi.c:1.4 src/tests/lib/libc/stdlib/t_strtoi.c:1.5
--- src/tests/lib/libc/stdlib/t_strtoi.c:1.4	Wed Jul 24 08:59:11 2024
+++ src/tests/lib/libc/stdlib/t_strtoi.c	Wed Jul 24 09:26:06 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_strtoi.c,v 1.4 2024/07/24 08:59:11 kre Exp $	*/
+/*	$NetBSD: t_strtoi.c,v 1.5 2024/07/24 09:26:06 kre Exp $	*/
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_strtoi.c,v 1.4 2024/07/24 08:59:11 kre Exp $");
+__RCSID("$NetBSD: t_strtoi.c,v 1.5 2024/07/24 09:26:06 kre Exp $");
 
 #include 
 #include 



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

2024-07-24 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Jul 24 09:26:06 UTC 2024

Modified Files:
src/tests/lib/libc/stdlib: t_strtoi.c

Log Message:
Add some test cases to tests/lib/libc/stdlib/t_strtoi

PR lib/58461  PR lib/58453

Apologies for the previous commit message - I managed to
forget to include the message filename after commit -F
and so used the file being committed (the only changed file
in the directory) as the log message.   (Fortunately that
meant that the log didn't get appended to the PR).

For the PR, the command to check what actually changed is

cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/stdlib/t_strtoi.c

rather than what will be reported below.

This commit message really belongs to the previous commit,
(1.5) there are no changes at all in this one.

No pullups required.


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

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



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

2024-07-24 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Jul 24 08:59:12 UTC 2024

Modified Files:
src/tests/lib/libc/stdlib: t_strtoi.c

Log Message:
/*  $NetBSD: t_strtoi.c,v 1.3 2024/01/20 16:52:41 christos Exp $*/

/*-
 * Copyright (c) 2015 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Jukka Ruohonen.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *notice, this list of conditions and the following disclaimer in the
 *documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * Created by Kamil Rytarowski, based on ID:
 * NetBSD: t_strtol.c,v 1.5 2011/06/14 02:45:58 jruoho Exp
 */

#include 
__RCSID("$NetBSD: t_strtoi.c,v 1.3 2024/01/20 16:52:41 christos Exp $");

#include 
#include 
#include 
#include 
#include 
#include 

struct test {
const char  *str;
intmax_t res;
int  base;
const char  *end;
intmax_t lo;
intmax_t hi;
int  rstatus;
};

static void check(struct test *, intmax_t, char *, int);

static void
check(struct test *t, intmax_t rv, char *end, int rstatus)
{

if (rv != t->res)
atf_tc_fail_nonfatal("strtoi(\"%s\", &end, %d, %jd, %jd, "
"&rstatus) failed (rv = %jd)", t->str, t->base,
t->lo, t->hi, rv);

if (rstatus != t->rstatus) {
char *emsg;

if (rstatus != 0) {
emsg = strerror(rstatus);
if (emsg != NULL) {
emsg = strdup(emsg);
if (emsg == NULL) {
atf_tc_fail("Out of Memory");
return;
}
}
} else
emsg = NULL;

atf_tc_fail_nonfatal("strtoi(\"%s\", &end, %d, %jd, %jd, 
&rstatus)"
" failed (rstatus: %d %s%s%sexpected %d%s%s%s)",
t->str, t->base, t->lo, t->hi, rstatus, rstatus ? "('" : "",
emsg != NULL ? emsg : "", rstatus ? "') " : "", t->rstatus,
t->rstatus ? " ('" : "", t->rstatus ? strerror(t->rstatus)
: "", t->rstatus ? "')" : "");

free(emsg);
}

if ((t->end != NULL && strcmp(t->end, end) != 0) ||
(t->end == NULL && *end != '\0'))
atf_tc_fail_nonfatal("invalid end pointer ('%s') from "
"strtoi(\"%s\", &end, %d, %jd, %jd, &rstatus), "
"expected '%s'", end, t->str, t->base, t->lo, t->hi,
 t->end != NULL ? t->end : "\\0");
}

static void
check_errno(int e)
{
if (e != 0)
atf_tc_fail("strtoi(3) changed errno to %d ('%s')",
e, strerror(e));
}

ATF_TC(strtoi_base);
ATF_TC_HEAD(strtoi_base, tc)
{
atf_tc_set_md_var(tc, "descr", "Test strtoi(3) with different bases");
}

ATF_TC_BODY(strtoi_base, tc)
{
struct test t[] = {
{ "123456789",  123456789,  0,  NULL,
  INTMAX_MIN,   INTMAX_MAX, 0   },
{ "11101011000110100010101",123456789,  2,  NULL,
  INTMAX_MIN,   INTMAX_MAX, 0   },
{ "22121022020212200",  123456789,  3,  NULL,
  INTMAX_MIN,   INTMAX_MAX, 0   },
{ "13112330310111", 123456789,  4,  NULL,
  INTMAX_MIN,   INTMAX_MAX, 0   },
{ "223101104124",   123456789,  5,  NULL,
  INTMAX_MIN,   INTMAX

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

2024-07-24 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Jul 24 08:59:12 UTC 2024

Modified Files:
src/tests/lib/libc/stdlib: t_strtoi.c

Log Message:
/*  $NetBSD: t_strtoi.c,v 1.3 2024/01/20 16:52:41 christos Exp $*/

/*-
 * Copyright (c) 2015 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Jukka Ruohonen.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *notice, this list of conditions and the following disclaimer in the
 *documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * Created by Kamil Rytarowski, based on ID:
 * NetBSD: t_strtol.c,v 1.5 2011/06/14 02:45:58 jruoho Exp
 */

#include 
__RCSID("$NetBSD: t_strtoi.c,v 1.3 2024/01/20 16:52:41 christos Exp $");

#include 
#include 
#include 
#include 
#include 
#include 

struct test {
const char  *str;
intmax_t res;
int  base;
const char  *end;
intmax_t lo;
intmax_t hi;
int  rstatus;
};

static void check(struct test *, intmax_t, char *, int);

static void
check(struct test *t, intmax_t rv, char *end, int rstatus)
{

if (rv != t->res)
atf_tc_fail_nonfatal("strtoi(\"%s\", &end, %d, %jd, %jd, "
"&rstatus) failed (rv = %jd)", t->str, t->base,
t->lo, t->hi, rv);

if (rstatus != t->rstatus) {
char *emsg;

if (rstatus != 0) {
emsg = strerror(rstatus);
if (emsg != NULL) {
emsg = strdup(emsg);
if (emsg == NULL) {
atf_tc_fail("Out of Memory");
return;
}
}
} else
emsg = NULL;

atf_tc_fail_nonfatal("strtoi(\"%s\", &end, %d, %jd, %jd, 
&rstatus)"
" failed (rstatus: %d %s%s%sexpected %d%s%s%s)",
t->str, t->base, t->lo, t->hi, rstatus, rstatus ? "('" : "",
emsg != NULL ? emsg : "", rstatus ? "') " : "", t->rstatus,
t->rstatus ? " ('" : "", t->rstatus ? strerror(t->rstatus)
: "", t->rstatus ? "')" : "");

free(emsg);
}

if ((t->end != NULL && strcmp(t->end, end) != 0) ||
(t->end == NULL && *end != '\0'))
atf_tc_fail_nonfatal("invalid end pointer ('%s') from "
"strtoi(\"%s\", &end, %d, %jd, %jd, &rstatus), "
"expected '%s'", end, t->str, t->base, t->lo, t->hi,
 t->end != NULL ? t->end : "\\0");
}

static void
check_errno(int e)
{
if (e != 0)
atf_tc_fail("strtoi(3) changed errno to %d ('%s')",
e, strerror(e));
}

ATF_TC(strtoi_base);
ATF_TC_HEAD(strtoi_base, tc)
{
atf_tc_set_md_var(tc, "descr", "Test strtoi(3) with different bases");
}

ATF_TC_BODY(strtoi_base, tc)
{
struct test t[] = {
{ "123456789",  123456789,  0,  NULL,
  INTMAX_MIN,   INTMAX_MAX, 0   },
{ "11101011000110100010101",123456789,  2,  NULL,
  INTMAX_MIN,   INTMAX_MAX, 0   },
{ "22121022020212200",  123456789,  3,  NULL,
  INTMAX_MIN,   INTMAX_MAX, 0   },
{ "13112330310111", 123456789,  4,  NULL,
  INTMAX_MIN,   INTMAX_MAX, 0   },
{ "223101104124",   123456789,  5,  NULL,
  INTMAX_MIN,   INTMAX

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

2024-07-22 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jul 22 16:41:05 UTC 2024

Modified Files:
src/tests/lib/libc/stdlib: t_strtol.c

Log Message:
Add strto{i,u}max tests and invalid base tests


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

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



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

2024-07-22 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jul 22 16:41:05 UTC 2024

Modified Files:
src/tests/lib/libc/stdlib: t_strtol.c

Log Message:
Add strto{i,u}max tests and invalid base tests


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libc/stdlib/t_strtol.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/stdlib/t_strtol.c
diff -u src/tests/lib/libc/stdlib/t_strtol.c:1.7 src/tests/lib/libc/stdlib/t_strtol.c:1.8
--- src/tests/lib/libc/stdlib/t_strtol.c:1.7	Thu Jul  6 17:08:44 2017
+++ src/tests/lib/libc/stdlib/t_strtol.c	Mon Jul 22 12:41:05 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_strtol.c,v 1.7 2017/07/06 21:08:44 joerg Exp $ */
+/*	$NetBSD: t_strtol.c,v 1.8 2024/07/22 16:41:05 christos Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -30,10 +30,11 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_strtol.c,v 1.7 2017/07/06 21:08:44 joerg Exp $");
+__RCSID("$NetBSD: t_strtol.c,v 1.8 2024/07/22 16:41:05 christos Exp $");
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -45,10 +46,8 @@ struct test {
 	const char	*end;
 };
 
-static void	check(struct test *, long int, long long int, char *);
-
 static void
-check(struct test *t, long int li, long long int lli, char *end)
+check(struct test *t, long int li, long long int lli, intmax_t ji, char *end)
 {
 
 	if (li != -1 && li != t->res)
@@ -59,6 +58,10 @@ check(struct test *t, long int li, long 
 		atf_tc_fail_nonfatal("strtoll(%s, NULL, %d) failed "
 		"(rv = %lld)", t->str, t->base, lli);
 
+	if (ji != -1 && ji != t->res)
+		atf_tc_fail_nonfatal("strtoll(%s, NULL, %d) failed "
+		"(rv = %jd)", t->str, t->base, ji);
+
 	if ((t->end != NULL && strcmp(t->end, end) != 0) ||
 	(t->end == NULL && *end != '\0'))
 		atf_tc_fail_nonfatal("invalid end pointer (%p) from "
@@ -102,8 +105,10 @@ ATF_TC_BODY(strtol_base, tc)
 
 	long long int lli;
 	long int li;
+	intmax_t ji;
 	long long int ulli;
 	long int uli;
+	uintmax_t uji;
 	char *end, *end2;
 	size_t i;
 
@@ -111,24 +116,68 @@ ATF_TC_BODY(strtol_base, tc)
 
 		li = strtol(t[i].str, &end, t[i].base);
 		lli = strtoll(t[i].str, NULL, t[i].base);
+		ji = strtoimax(t[i].str, NULL, t[i].base);
 
 		uli = strtoul(t[i].str, &end2, t[i].base);
 		ulli = strtoull(t[i].str, NULL, t[i].base);
+		uji = strtoumax(t[i].str, NULL, t[i].base);
 
-		check(&t[i], li, lli, end);
+		check(&t[i], li, lli, ji, end);
 
 		if (li != uli)
 			atf_tc_fail_nonfatal("strtoul(%s, NULL, %d) failed "
 			"(rv = %lu)", t[i].str, t[i].base, uli);
-		if (end != end2)
-			atf_tc_fail_nonfatal("invalid end pointer ('%p') from "
-			"strtoul(%s, &end, %d)", end2, t[i].str, t[i].base);
 		if (lli != ulli)
 			atf_tc_fail_nonfatal("strtoull(%s, NULL, %d) failed "
 			"(rv = %llu)", t[i].str, t[i].base, ulli);
+		if ((uintmax_t)ji != uji)
+			atf_tc_fail_nonfatal("strtoumax(%s, NULL, %d) failed "
+			"(rv = %ju)", t[i].str, t[i].base, uji);
+		if (end != end2)
+			atf_tc_fail_nonfatal("invalid end pointer ('%p') from "
+			"strtoul(%s, &end, %d)", end2, t[i].str, t[i].base);
 	}
 }
 
+ATF_TC(strtol_invbase);
+ATF_TC_HEAD(strtol_invbase, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Test strtol(3) with an invalid base");
+}
+
+ATF_TC_BODY(strtol_invbase, tc)
+{
+	long long int lli;
+	long int li;
+	intmax_t ji;
+	long long int ulli;
+	long int uli;
+	uintmax_t uji;
+	char *end;
+	char boo[] = "boo";
+	const char str[] = "1";
+
+#define CHECK(r, f, fun) \
+	end = boo; \
+	r = fun(str, &end, -2); \
+	if (strcmp(str, end) != 0) \
+	atf_tc_fail_nonfatal( \
+		"%s(1, boo, -2) failed endptr=%s ", # fun, end); \
+	if (r) \
+	atf_tc_fail_nonfatal( \
+		"%s(1, boo, -2) failed rv=" f, # fun, r); \
+	if (errno != EINVAL) \
+	atf_tc_fail_nonfatal( \
+		"%s(1, boo, -2) failed errno=%d", # fun, errno)
+
+	CHECK(li, "%ld", strtol);
+	CHECK(lli, "%lld", strtoll);
+	CHECK(ji, "%jd", strtoimax);
+	CHECK(uli, "%lu", strtoul);
+	CHECK(ulli, "%llu", strtoull);
+	CHECK(uji, "%ju", strtoumax);
+}
+
 ATF_TC(strtol_case);
 ATF_TC_HEAD(strtol_case, tc)
 {
@@ -151,6 +200,7 @@ ATF_TC_BODY(strtol_case, tc)
 
 	long long int lli;
 	long int li;
+	intmax_t ji;
 	char *end;
 	size_t i;
 
@@ -158,8 +208,9 @@ ATF_TC_BODY(strtol_case, tc)
 
 		li = strtol(t[i].str, &end, t[i].base);
 		lli = strtoll(t[i].str, NULL, t[i].base);
+		ji = strtoimax(t[i].str, NULL, t[i].base);
 
-		check(&t[i], li, lli, end);
+		check(&t[i], li, lli, ji, end);
 	}
 }
 
@@ -199,7 +250,7 @@ ATF_TC_BODY(strtol_range, tc)
 		if (errno != ERANGE)
 			atf_tc_fail("strtol(3) did not catch ERANGE");
 
-		check(&t[i], li, -1, end);
+		check(&t[i], li, -1, -1, end);
 	}
 }
 
@@ -230,6 +281,7 @@ ATF_TC_BODY(strtol_signed, tc)
 
 	long long int lli;
 	long int li;
+	intmax_t ji;
 	char *end;
 	size_t i;
 
@@ -237,14 +289,16 @@ ATF_TC_BODY(strtol_signed, tc)
 
 		li = strtol(t[i].str, &

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

2024-06-15 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jun 15 12:20:22 UTC 2024

Modified Files:
src/tests/lib/libc/stdlib: t_strtod.c

Log Message:
tests/strtold: test a few simple examples


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/tests/lib/libc/stdlib/t_strtod.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/stdlib/t_strtod.c
diff -u src/tests/lib/libc/stdlib/t_strtod.c:1.36 src/tests/lib/libc/stdlib/t_strtod.c:1.37
--- src/tests/lib/libc/stdlib/t_strtod.c:1.36	Mon May  6 18:39:36 2024
+++ src/tests/lib/libc/stdlib/t_strtod.c	Sat Jun 15 12:20:22 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_strtod.c,v 1.36 2024/05/06 18:39:36 riastradh Exp $ */
+/*	$NetBSD: t_strtod.c,v 1.37 2024/06/15 12:20:22 rillig Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -32,9 +32,11 @@
 /* Public domain, Otto Moerbeek , 2006. */
 
 #include 
-__RCSID("$NetBSD: t_strtod.c,v 1.36 2024/05/06 18:39:36 riastradh Exp $");
+__RCSID("$NetBSD: t_strtod.c,v 1.37 2024/06/15 12:20:22 rillig Exp $");
 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -42,8 +44,6 @@ __RCSID("$NetBSD: t_strtod.c,v 1.36 2024
 
 #include 
 
-#include 
-
 static const char * const inf_strings[] =
 { "Inf", "INF", "-Inf", "-INF", "Infinity", "+Infinity",
   "INFINITY", "-INFINITY", "InFiNiTy", "+InFiNiTy" };
@@ -73,6 +73,38 @@ ATF_TC_BODY(strtod_basic, tc)
 	}
 }
 
+ATF_TC(strtold_basic);
+ATF_TC_HEAD(strtold_basic, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Some examples of strtold(3)");
+}
+
+ATF_TC_BODY(strtold_basic, tc)
+{
+	static const struct {
+		const char *str;
+		long double val;
+	} testcases[] = {
+		{ "0x0p0", 0.0L },
+		{ "0x1.234p0", 0x1234 / 4096.0L },
+		{ "0x1.234p0", 0x1234 / 4096.0L },
+#if FLT_RADIX == 2 && LDBL_MAX_EXP == 16384 && LDBL_MANT_DIG == 64
+		{ "2.16", 0x8.a3d70a3d70a3d71p-2L },
+#endif
+	};
+
+	for (size_t i = 0, n = __arraycount(testcases); i < n; i++) {
+		char *end;
+		errno = 0;
+		long double val = strtold(testcases[i].str, &end);
+
+		ATF_CHECK_MSG(
+		errno == 0 && *end == '\0' && val == testcases[i].val,
+		"'%s' want %La have %La errno %d end '%s'",
+		testcases[i].str, testcases[i].val, val, errno, end);
+	}
+}
+
 ATF_TC(strtod_hex);
 ATF_TC_HEAD(strtod_hex, tc)
 {
@@ -306,6 +338,7 @@ ATF_TP_ADD_TCS(tp)
 {
 
 	ATF_TP_ADD_TC(tp, strtod_basic);
+	ATF_TP_ADD_TC(tp, strtold_basic);
 	ATF_TP_ADD_TC(tp, strtod_hex);
 	ATF_TP_ADD_TC(tp, strtod_inf);
 	ATF_TP_ADD_TC(tp, strtof_inf);



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

2024-06-15 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jun 15 12:20:22 UTC 2024

Modified Files:
src/tests/lib/libc/stdlib: t_strtod.c

Log Message:
tests/strtold: test a few simple examples


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/tests/lib/libc/stdlib/t_strtod.c

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



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

2024-05-06 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May  6 18:39:36 UTC 2024

Modified Files:
src/tests/lib/libc/stdlib: t_strtod.c

Log Message:
tests/lib/libc/stdlib/t_strtod: Spruce up and nix needless #ifdefs.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/tests/lib/libc/stdlib/t_strtod.c

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



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

2024-05-06 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May  6 18:39:36 UTC 2024

Modified Files:
src/tests/lib/libc/stdlib: t_strtod.c

Log Message:
tests/lib/libc/stdlib/t_strtod: Spruce up and nix needless #ifdefs.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/tests/lib/libc/stdlib/t_strtod.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/stdlib/t_strtod.c
diff -u src/tests/lib/libc/stdlib/t_strtod.c:1.35 src/tests/lib/libc/stdlib/t_strtod.c:1.36
--- src/tests/lib/libc/stdlib/t_strtod.c:1.35	Sun Jan 14 12:44:09 2024
+++ src/tests/lib/libc/stdlib/t_strtod.c	Mon May  6 18:39:36 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_strtod.c,v 1.35 2024/01/14 12:44:09 andvar Exp $ */
+/*	$NetBSD: t_strtod.c,v 1.36 2024/05/06 18:39:36 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 /* Public domain, Otto Moerbeek , 2006. */
 
 #include 
-__RCSID("$NetBSD: t_strtod.c,v 1.35 2024/01/14 12:44:09 andvar Exp $");
+__RCSID("$NetBSD: t_strtod.c,v 1.36 2024/05/06 18:39:36 riastradh Exp $");
 
 #include 
 #include 
@@ -44,12 +44,10 @@ __RCSID("$NetBSD: t_strtod.c,v 1.35 2024
 
 #include 
 
-#if !defined(__vax__)
 static const char * const inf_strings[] =
 { "Inf", "INF", "-Inf", "-INF", "Infinity", "+Infinity",
   "INFINITY", "-INFINITY", "InFiNiTy", "+InFiNiTy" };
-const char *nan_string = "NaN(x)y";
-#endif
+const char * const nan_string = "NaN(x)y";
 
 ATF_TC(strtod_basic);
 ATF_TC_HEAD(strtod_basic, tc)
@@ -68,8 +66,10 @@ ATF_TC_BODY(strtod_basic, tc)
 		errno = 0;
 		double d = strtod(buf, NULL);
 
-		ATF_REQUIRE(d > 0.0);
-		ATF_REQUIRE(errno == 0);
+		ATF_CHECK_MSG(d > 0, "i=%zu buf=\"%s\" d=%g errno=%d",
+		i, buf, d, errno);
+		ATF_CHECK_EQ_MSG(errno, 0, "i=%zu buf=\"%s\" d=%g errno=%d",
+		i, buf, d, errno);
 	}
 }
 
@@ -79,12 +79,6 @@ ATF_TC_HEAD(strtod_hex, tc)
 	atf_tc_set_md_var(tc, "descr", "A strtod(3) with hexadecimals");
 }
 
-#ifdef __vax__
-#define SMALL_NUM   1.0e-38
-#else
-#define SMALL_NUM   1.0e-40
-#endif
-
 ATF_TC_BODY(strtod_hex, tc)
 {
 	const char *str;
@@ -94,16 +88,18 @@ ATF_TC_BODY(strtod_hex, tc)
 	str = "-0x0";
 	d = strtod(str, &end);	/* -0.0 */
 
-	ATF_REQUIRE(end == str + 4);
-	ATF_REQUIRE(signbit(d) != 0);
-	ATF_REQUIRE(fabs(d) < SMALL_NUM);
+	ATF_CHECK_EQ_MSG(end, str + 4, "str=%p end=%p", str, end);
+	ATF_CHECK_MSG(signbit(d) != 0, "d=%g=%a signbit=%d", d, d, signbit(d));
+	ATF_CHECK_EQ_MSG(fabs(d), 0, "d=%g=%a, fabs(d)=%g=%a",
+	d, d, fabs(d), fabs(d));
 
 	str = "-0x";
 	d = strtod(str, &end);	/* -0.0 */
 
-	ATF_REQUIRE(end == str + 2);
-	ATF_REQUIRE(signbit(d) != 0);
-	ATF_REQUIRE(fabs(d) < SMALL_NUM);
+	ATF_CHECK_EQ_MSG(end, str + 2, "str=%p end=%p", str, end);
+	ATF_CHECK_MSG(signbit(d) != 0, "d=%g=%a signbit=%d", d, d, signbit(d));
+	ATF_CHECK_EQ_MSG(fabs(d), 0, "d=%g=%a fabs(d)=%g=%a",
+	d, d, fabs(d), fabs(d));
 }
 
 ATF_TC(strtod_inf);
@@ -114,14 +110,15 @@ ATF_TC_HEAD(strtod_inf, tc)
 
 ATF_TC_BODY(strtod_inf, tc)
 {
-#ifndef __vax__
+
+	if (!isinf(INFINITY))
+		atf_tc_skip("no infinities on this architecture");
+
 	for (size_t i = 0; i < __arraycount(inf_strings); i++) {
 		volatile double d = strtod(inf_strings[i], NULL);
-		ATF_REQUIRE(isinf(d) != 0);
+		ATF_CHECK_MSG(isinf(d), "inf_strings[%zu]=\"%s\" d=%g=%a",
+		i, inf_strings[i], d, d);
 	}
-#else
-	atf_tc_skip("vax not supported");
-#endif
 }
 
 ATF_TC(strtof_inf);
@@ -132,14 +129,17 @@ ATF_TC_HEAD(strtof_inf, tc)
 
 ATF_TC_BODY(strtof_inf, tc)
 {
-#ifndef __vax__
+
+	if (!isinf(INFINITY))
+		atf_tc_skip("no infinities on this architecture");
+
 	for (size_t i = 0; i < __arraycount(inf_strings); i++) {
 		volatile float f = strtof(inf_strings[i], NULL);
-		ATF_REQUIRE(isinf(f) != 0);
+		ATF_CHECK_MSG(isinf(f), "inf_strings[%zu]=\"%s\" f=%g=%a",
+		i, inf_strings[i], f, f);
+		ATF_CHECK_MSG(isinff(f), "inf_strings[%zu]=\"%s\" f=%g=%a",
+		i, inf_strings[i], f, f);
 	}
-#else
-	atf_tc_skip("vax not supported");
-#endif
 }
 
 ATF_TC(strtold_inf);
@@ -150,19 +150,15 @@ ATF_TC_HEAD(strtold_inf, tc)
 
 ATF_TC_BODY(strtold_inf, tc)
 {
-#ifndef __vax__
-#   ifdef __HAVE_LONG_DOUBLE
+
+	if (!isinf(INFINITY))
+		atf_tc_skip("no infinities on this architecture");
 
 	for (size_t i = 0; i < __arraycount(inf_strings); i++) {
 		volatile long double ld = strtold(inf_strings[i], NULL);
-		ATF_REQUIRE(isinf(ld) != 0);
+		ATF_CHECK_MSG(isinf(ld), "inf_strings[%zu]=\"%s\" ld=%Lg=%La",
+		i, inf_strings[i], ld, ld);
 	}
-#   else
-	atf_tc_skip("Requires long double support");
-#   endif
-#else
-	atf_tc_skip("vax not supported");
-#endif
 }
 
 ATF_TC(strtod_nan);
@@ -173,15 +169,16 @@ ATF_TC_HEAD(strtod_nan, tc)
 
 ATF_TC_BODY(strtod_nan, tc)
 {
-#ifndef __vax__
 	char *end;
 
-	volatile double d = strtod(nan_string, &end);
-	ATF_REQUIRE(isnan(d) != 0);
-	ATF_REQUIRE(strcmp(end, "y") == 0);
-#else
-	atf_tc

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

2024-01-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Jan 20 16:52:41 UTC 2024

Modified Files:
src/tests/lib/libc/stdlib: t_strtoi.c

Log Message:
Add range tests with trailing characters.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/stdlib/t_strtoi.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/stdlib/t_strtoi.c
diff -u src/tests/lib/libc/stdlib/t_strtoi.c:1.2 src/tests/lib/libc/stdlib/t_strtoi.c:1.3
--- src/tests/lib/libc/stdlib/t_strtoi.c:1.2	Fri Apr 28 15:01:01 2017
+++ src/tests/lib/libc/stdlib/t_strtoi.c	Sat Jan 20 11:52:41 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_strtoi.c,v 1.2 2017/04/28 19:01:01 kamil Exp $	*/
+/*	$NetBSD: t_strtoi.c,v 1.3 2024/01/20 16:52:41 christos Exp $	*/
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_strtoi.c,v 1.2 2017/04/28 19:01:01 kamil Exp $");
+__RCSID("$NetBSD: t_strtoi.c,v 1.3 2024/01/20 16:52:41 christos Exp $");
 
 #include 
 #include 
@@ -235,6 +235,38 @@ ATF_TC_BODY(strtoi_range, tc)
 	}
 }
 
+ATF_TC(strtoi_range_trail);
+ATF_TC_HEAD(strtoi_range_trail, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Test ERANGE from strtoi(3) "
+		"with trailing characters");
+}
+
+ATF_TC_BODY(strtoi_range_trail, tc)
+{
+	struct test t[] = {
+		{ "11x", 9, 10, "x", 0,	9, ERANGE },
+		{ " -3y", -2, 10, "y", -2, 1, ERANGE },
+	};
+
+	intmax_t rv;
+	char *end;
+	int e;
+	size_t i;
+
+	for (i = 0; i < __arraycount(t); i++) {
+
+		errno = 0;
+		rv = strtoi(t[i].str, &end, t[i].base, t[i].lo, t[i].hi, &e);
+
+		if (errno != 0)
+			atf_tc_fail("strtoi(3) changed errno to %d ('%s')",
+			e, strerror(e));
+
+		check(&t[i], rv, end, e);
+	}
+}
+
 ATF_TC(strtoi_signed);
 ATF_TC_HEAD(strtoi_signed, tc)
 {
@@ -298,6 +330,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, strtoi_base);
 	ATF_TP_ADD_TC(tp, strtoi_case);
 	ATF_TP_ADD_TC(tp, strtoi_range);
+	ATF_TP_ADD_TC(tp, strtoi_range_trail);
 	ATF_TP_ADD_TC(tp, strtoi_signed);
 
 	return atf_no_error();



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

2024-01-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Jan 20 16:52:41 UTC 2024

Modified Files:
src/tests/lib/libc/stdlib: t_strtoi.c

Log Message:
Add range tests with trailing characters.


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

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



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

2024-01-14 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Sun Jan 14 12:44:09 UTC 2024

Modified Files:
src/tests/lib/libc/stdlib: t_strtod.c

Log Message:
s/rouding/rounding/ in test description.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/tests/lib/libc/stdlib/t_strtod.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/stdlib/t_strtod.c
diff -u src/tests/lib/libc/stdlib/t_strtod.c:1.34 src/tests/lib/libc/stdlib/t_strtod.c:1.35
--- src/tests/lib/libc/stdlib/t_strtod.c:1.34	Tue Dec 22 14:19:25 2015
+++ src/tests/lib/libc/stdlib/t_strtod.c	Sun Jan 14 12:44:09 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_strtod.c,v 1.34 2015/12/22 14:19:25 christos Exp $ */
+/*	$NetBSD: t_strtod.c,v 1.35 2024/01/14 12:44:09 andvar Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 /* Public domain, Otto Moerbeek , 2006. */
 
 #include 
-__RCSID("$NetBSD: t_strtod.c,v 1.34 2015/12/22 14:19:25 christos Exp $");
+__RCSID("$NetBSD: t_strtod.c,v 1.35 2024/01/14 12:44:09 andvar Exp $");
 
 #include 
 #include 
@@ -231,7 +231,7 @@ ATF_TC_BODY(strtold_nan, tc)
 ATF_TC(strtod_round);
 ATF_TC_HEAD(strtod_round, tc)
 {
-	atf_tc_set_md_var(tc, "descr", "Test rouding in strtod(3)");
+	atf_tc_set_md_var(tc, "descr", "Test rounding in strtod(3)");
 }
 
 ATF_TC_BODY(strtod_round, tc)



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

2024-01-14 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Sun Jan 14 12:44:09 UTC 2024

Modified Files:
src/tests/lib/libc/stdlib: t_strtod.c

Log Message:
s/rouding/rounding/ in test description.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/tests/lib/libc/stdlib/t_strtod.c

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



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

2023-07-05 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jul  5 12:09:39 UTC 2023

Modified Files:
src/tests/lib/libc/stdlib: t_posix_memalign.c

Log Message:
t_posix_memalign: Simplify.

No functional change intended.


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

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



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

2023-07-05 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jul  5 12:09:39 UTC 2023

Modified Files:
src/tests/lib/libc/stdlib: t_posix_memalign.c

Log Message:
t_posix_memalign: Simplify.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libc/stdlib/t_posix_memalign.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/stdlib/t_posix_memalign.c
diff -u src/tests/lib/libc/stdlib/t_posix_memalign.c:1.7 src/tests/lib/libc/stdlib/t_posix_memalign.c:1.8
--- src/tests/lib/libc/stdlib/t_posix_memalign.c:1.7	Wed Jul  5 11:43:05 2023
+++ src/tests/lib/libc/stdlib/t_posix_memalign.c	Wed Jul  5 12:09:39 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_posix_memalign.c,v 1.7 2023/07/05 11:43:05 riastradh Exp $ */
+/*	$NetBSD: t_posix_memalign.c,v 1.8 2023/07/05 12:09:39 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_posix_memalign.c,v 1.7 2023/07/05 11:43:05 riastradh Exp $");
+__RCSID("$NetBSD: t_posix_memalign.c,v 1.8 2023/07/05 12:09:39 riastradh Exp $");
 
 #include 
 
@@ -189,19 +189,11 @@ ATF_TC_BODY(aligned_alloc_basic, tc)
 ATF_CHECK_EQ_MSG(p, NULL,
 "aligned_alloc(%zu, %zu): %p, %s",
 align[i], size[j], p, strerror(errno));
-switch (errno) {
-case EINVAL:
-case ENOMEM:
-	break;
-default:
-	atf_tc_fail_nonfatal(
-	"%s:%d:"
-	" aligned_alloc(%zu, %zu): %s",
-	__FILE__, __LINE__,
-	align[i], size[j],
-	strerror(errno));
-	break;
-}
+ATF_CHECK_MSG((errno == EINVAL ||
+	errno == ENOMEM),
+"aligned_alloc(%zu, %zu): %s",
+align[i], size[j],
+strerror(errno));
 continue;
 			}
 
@@ -219,15 +211,10 @@ ATF_TC_BODY(aligned_alloc_basic, tc)
 			"aligned_alloc(%zu, %zu): %p",
 			align[i], size[j], p);
 			if (size[j] != 0) {
-if (p == NULL) {
-	atf_tc_fail_nonfatal(
-	"%s:%d:"
-	" aligned_alloc(&p, %zu, %zu):"
-	" %p, %s",
-	__FILE__, __LINE__,
-	align[i], size[j], p,
-	strerror(errno));
-}
+ATF_CHECK_MSG(p != NULL,
+"aligned_alloc(&p, %zu, %zu): %p, %s",
+align[i], size[j], p,
+strerror(errno));
 			} else {
 /*
  * No guarantees about whether



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

2023-07-05 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jul  5 11:43:05 UTC 2023

Modified Files:
src/tests/lib/libc/stdlib: t_posix_memalign.c

Log Message:
t_posix_memalign: Fix this to reflect restriction lifted in C17.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libc/stdlib/t_posix_memalign.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/stdlib/t_posix_memalign.c
diff -u src/tests/lib/libc/stdlib/t_posix_memalign.c:1.6 src/tests/lib/libc/stdlib/t_posix_memalign.c:1.7
--- src/tests/lib/libc/stdlib/t_posix_memalign.c:1.6	Tue Jul  4 15:06:36 2023
+++ src/tests/lib/libc/stdlib/t_posix_memalign.c	Wed Jul  5 11:43:05 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_posix_memalign.c,v 1.6 2023/07/04 15:06:36 riastradh Exp $ */
+/*	$NetBSD: t_posix_memalign.c,v 1.7 2023/07/05 11:43:05 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_posix_memalign.c,v 1.6 2023/07/04 15:06:36 riastradh Exp $");
+__RCSID("$NetBSD: t_posix_memalign.c,v 1.7 2023/07/05 11:43:05 riastradh Exp $");
 
 #include 
 
@@ -152,20 +152,19 @@ ATF_TC_BODY(aligned_alloc_basic, tc)
 			void *const p = aligned_alloc(align[i], size[j]);
 
 			/*
-			 * C11, 6.2.8 Alignment of objects, paragraph
-			 * 4, p. 48:
+			 * C17, 6.2.8 Alignment of objects, paragraph
+			 * 4, p. 37:
 			 *
 			 *	Every valid alignment value shall be a
 			 *	nonnegative integral power of two.
 			 *
-			 * C11, 7.22.3.1 The aligned_alloc function,
+			 * C17, 7.22.3.1 The aligned_alloc function,
 			 * paragraph 2, p. 348:
 			 *
-			 *	The value of alignment shall be a valid
-			 *	alignment supported by the
-			 *	implementation and the value of size
-			 *	shall be an integral multiple of
-			 *	alignment.
+			 *	If the value of alignment is not a
+			 *	valid alignment supported by the
+			 *	implementation the function shall fail
+			 *	by returning a null pointer.
 			 *
 			 * Setting errno to EINVAL is a NetBSD
 			 * extension.  The last clause appears to rule
@@ -173,8 +172,7 @@ ATF_TC_BODY(aligned_alloc_basic, tc)
 			 * not clear.
 			 */
 			if (align[i] == 0 ||
-			(align[i] & (align[i] - 1)) != 0 ||
-			(size[j] != 0 && size[j] % align[i] != 0)) {
+			(align[i] & (align[i] - 1)) != 0) {
 if (p != NULL) {
 	ATF_CHECK_EQ_MSG(p, NULL,
 	"aligned_alloc(%zu, %zu): %p",



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

2023-07-05 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jul  5 11:43:05 UTC 2023

Modified Files:
src/tests/lib/libc/stdlib: t_posix_memalign.c

Log Message:
t_posix_memalign: Fix this to reflect restriction lifted in C17.


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

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



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

2023-07-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul  4 15:06:36 UTC 2023

Modified Files:
src/tests/lib/libc/stdlib: Makefile t_posix_memalign.c

Log Message:
t_posix_memalign: Expand test cases and properties.

- Test cartesian product of a sampling of sizes and a sampling of
  alignments.

- Verify all the edge cases I could find in posix_memalign and
  aligned_alloc, including failure modes.

- Test an unreasonably large (but aligned) allocation size.

- Use ATF_CHECK_* instead of ATF_REQUIRE_* so all failures will be
  reported, not just the first one.

- While here, build with -fno-builtin-aligned_alloc and with
  -fno-builtin-posix_memalign to make sure the compiler doesn't try
  any shenanigans.

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/tests/lib/libc/stdlib/Makefile
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libc/stdlib/t_posix_memalign.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/stdlib/Makefile
diff -u src/tests/lib/libc/stdlib/Makefile:1.33 src/tests/lib/libc/stdlib/Makefile:1.34
--- src/tests/lib/libc/stdlib/Makefile:1.33	Wed Jul  1 07:16:37 2020
+++ src/tests/lib/libc/stdlib/Makefile	Tue Jul  4 15:06:36 2023
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.33 2020/07/01 07:16:37 jruoho Exp $
+# $NetBSD: Makefile,v 1.34 2023/07/04 15:06:36 riastradh Exp $
 
 .include 
 
@@ -31,6 +31,9 @@ BINDIR=		${TESTSDIR}
 PROGS+=		h_atexit
 PROGS+=		h_getopt h_getopt_long
 
+CFLAGS.t_posix_memalign.c+=	-fno-builtin-posix_memalign
+CFLAGS.t_posix_memalign.c+=	-fno-builtin-aligned_alloc
+
 CPPFLAGS.t_strtod.c+=  -D__TEST_FENV
 LDADD.t_strtod=			-lm
 DPADD.t_strtod+=		${LIBM}

Index: src/tests/lib/libc/stdlib/t_posix_memalign.c
diff -u src/tests/lib/libc/stdlib/t_posix_memalign.c:1.5 src/tests/lib/libc/stdlib/t_posix_memalign.c:1.6
--- src/tests/lib/libc/stdlib/t_posix_memalign.c:1.5	Sun Jul 29 01:45:25 2018
+++ src/tests/lib/libc/stdlib/t_posix_memalign.c	Tue Jul  4 15:06:36 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_posix_memalign.c,v 1.5 2018/07/29 01:45:25 maya Exp $ */
+/*	$NetBSD: t_posix_memalign.c,v 1.6 2023/07/04 15:06:36 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_posix_memalign.c,v 1.5 2018/07/29 01:45:25 maya Exp $");
+__RCSID("$NetBSD: t_posix_memalign.c,v 1.6 2023/07/04 15:06:36 riastradh Exp $");
 
 #include 
 
@@ -43,6 +43,8 @@ __RCSID("$NetBSD: t_posix_memalign.c,v 1
 #include 
 #include 
 
+#define	rounddown(x, n)	(((x) / (n)) * (n))
+
 ATF_TC(posix_memalign_basic);
 ATF_TC_HEAD(posix_memalign_basic, tc)
 {
@@ -50,32 +52,77 @@ ATF_TC_HEAD(posix_memalign_basic, tc)
 }
 ATF_TC_BODY(posix_memalign_basic, tc)
 {
-	static const size_t size[] = {
-		1, 2, 3, 4, 10, 100, 16384, 32768, 65536
-	};
+	enum { maxaligntest = 16384 };
 	static const size_t align[] = {
-		512, 1024, 16, 32, 64, 4, 2048, 16, 2
+		0, 1, 2, 3, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096,
+		8192, maxaligntest,
+	};
+	static const size_t size[] = {
+		0, 1, 2, 3, 4, 10, 100, 1, 16384, 32768, 65536,
+		rounddown(SIZE_MAX, maxaligntest),
 	};
+	size_t i, j;
 
-	size_t i;
-	void *p;
+	for (i = 0; i < __arraycount(align); i++) {
+		for (j = 0; j < __arraycount(size); j++) {
+			void *p = (void *)0x1;
+			const int ret = posix_memalign(&p, align[i], size[j]);
+
+			if (align[i] == 0 ||
+			(align[i] & (align[i] - 1)) != 0 ||
+			align[i] < sizeof(void *)) {
+ATF_CHECK_EQ_MSG(ret, EINVAL,
+"posix_memalign(&p, %zu, %zu): %s",
+align[i], size[j], strerror(ret));
+continue;
+			}
+			if (size[j] == rounddown(SIZE_MAX, maxaligntest) &&
+			ret != EINVAL) {
+/*
+ * If obscenely large alignment isn't
+ * rejected as EINVAL, we can't
+ * allocate that much memory anyway.
+ */
+ATF_CHECK_EQ_MSG(ret, ENOMEM,
+"posix_memalign(&p, %zu, %zu): %s",
+align[i], size[j], strerror(ret));
+continue;
+			}
+
+			/*
+			 * Allocation should fail only if the alignment
+			 * isn't supported, in which case it will fail
+			 * with EINVAL.  No standard criterion for what
+			 * alignments are supported, so just stop here
+			 * on EINVAL.
+			 */
+			if (ret == EINVAL)
+continue;
+
+			ATF_CHECK_EQ_MSG(ret, 0,
+			"posix_memalign(&p, %zu, %zu): %s",
+			align[i], size[j], strerror(ret));
+			ATF_CHECK_EQ_MSG((intptr_t)p & (align[i] - 1), 0,
+			"posix_memalign(&p, %zu, %zu): %p",
+			align[i], size[j], p);
+
+			if (size[j] != 0) {
+if (p == NULL) {
+	atf_tc_fail_nonfatal(
+	"%s:%d:"
+	"posix_memalign(&p, %zu, %zu):"
+	" %p",
+	__FILE__, __LINE__,
+	align[i], size[j], p);
+}
+			} else {
+/*
+ * No guarantees about whether
+ * zero-size allocation yields 

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

2023-07-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul  4 15:06:36 UTC 2023

Modified Files:
src/tests/lib/libc/stdlib: Makefile t_posix_memalign.c

Log Message:
t_posix_memalign: Expand test cases and properties.

- Test cartesian product of a sampling of sizes and a sampling of
  alignments.

- Verify all the edge cases I could find in posix_memalign and
  aligned_alloc, including failure modes.

- Test an unreasonably large (but aligned) allocation size.

- Use ATF_CHECK_* instead of ATF_REQUIRE_* so all failures will be
  reported, not just the first one.

- While here, build with -fno-builtin-aligned_alloc and with
  -fno-builtin-posix_memalign to make sure the compiler doesn't try
  any shenanigans.

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/tests/lib/libc/stdlib/Makefile
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libc/stdlib/t_posix_memalign.c

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



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

2023-05-10 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Wed May 10 23:44:15 UTC 2023

Modified Files:
src/tests/lib/libc/stdlib: t_getopt.sh

Log Message:
t_getopt.sh: fix naming of head() of getopt_optval test case


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/stdlib/t_getopt.sh

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/stdlib/t_getopt.sh
diff -u src/tests/lib/libc/stdlib/t_getopt.sh:1.2 src/tests/lib/libc/stdlib/t_getopt.sh:1.3
--- src/tests/lib/libc/stdlib/t_getopt.sh:1.2	Mon Feb 20 15:47:56 2023
+++ src/tests/lib/libc/stdlib/t_getopt.sh	Wed May 10 23:44:15 2023
@@ -1,4 +1,4 @@
-# $NetBSD: t_getopt.sh,v 1.2 2023/02/20 15:47:56 christos Exp $
+# $NetBSD: t_getopt.sh,v 1.3 2023/05/10 23:44:15 gutteridge Exp $
 #
 # Copyright (c) 2008 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -66,7 +66,7 @@ getopt_body()
 }
 
 atf_test_case getopt_optval
-getopt_optval()
+getopt_optval_head()
 {
 	atf_set "descr" "Checks getopt(3) with optional value"
 }



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

2023-05-10 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Wed May 10 23:44:15 UTC 2023

Modified Files:
src/tests/lib/libc/stdlib: t_getopt.sh

Log Message:
t_getopt.sh: fix naming of head() of getopt_optval test case


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/stdlib/t_getopt.sh

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



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

2023-02-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Feb 20 15:47:56 UTC 2023

Modified Files:
src/tests/lib/libc/stdlib: t_getopt.sh

Log Message:
New optval test from des @ FreeBSD


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/stdlib/t_getopt.sh

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/stdlib/t_getopt.sh
diff -u src/tests/lib/libc/stdlib/t_getopt.sh:1.1 src/tests/lib/libc/stdlib/t_getopt.sh:1.2
--- src/tests/lib/libc/stdlib/t_getopt.sh:1.1	Sat Jan  1 18:56:49 2011
+++ src/tests/lib/libc/stdlib/t_getopt.sh	Mon Feb 20 10:47:56 2023
@@ -1,4 +1,4 @@
-# $NetBSD: t_getopt.sh,v 1.1 2011/01/01 23:56:49 pgoyette Exp $
+# $NetBSD: t_getopt.sh,v 1.2 2023/02/20 15:47:56 christos Exp $
 #
 # Copyright (c) 2008 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -65,6 +65,18 @@ getopt_body()
 	h_getopt "${load}" "foo -d - 1" "d|2"
 }
 
+atf_test_case getopt_optval
+getopt_optval()
+{
+	atf_set "descr" "Checks getopt(3) with optional value"
+}
+getopt_optval_body()
+{
+	h_getopt "o::" "foo -o" "o=(null)|0"
+	h_getopt "o::" "foo -o1 2" "o=1|1"
+	h_getopt "o::" "foo -o 1 2" "o=(null)|2"
+}
+
 atf_test_case getopt_long
 getopt_long_head()
 {
@@ -119,5 +131,6 @@ longopt:	list, no_argument, lopt, 'l'"
 atf_init_test_cases()
 {
 	atf_add_test_case getopt
+	atf_add_test_case getopt_optval
 	atf_add_test_case getopt_long
 }



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

2023-02-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Feb 20 15:47:56 UTC 2023

Modified Files:
src/tests/lib/libc/stdlib: t_getopt.sh

Log Message:
New optval test from des @ FreeBSD


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/stdlib/t_getopt.sh

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



Re: CVS commit: src/tests/lib/libc/stdlib

2020-06-27 Thread Jukka Ruohonen
On Sat, Jun 27, 2020 at 10:39:08AM +, m...@netbsd.org wrote:
> > Add the default TNF copyright (2005), cf. PR misc/55419.
> 
> I don't think we can generally do this. Can you clarify if you discussed
> this with the author in commit messages?

Well, the committer is christos, and I doubt he cares.  But as noted in the
test, this 15 year old code snippet is from another person.  Like with many
test cases, I suppose it was originally taken/modified from a PR or a
mailing list.

As I noted in PR misc/55419, the problem is generic. I doubt whether it is
even possible to contact all people whose code appears in src/tests. But I
guess at least all NetBSD people should add the meta-data if they have code
in src/tests.

- Jukka



Re: CVS commit: src/tests/lib/libc/stdlib

2020-06-27 Thread maya
On Sat, Jun 27, 2020 at 10:19:43AM +, Jukka Ruohonen wrote:
> Module Name:  src
> Committed By: jruoho
> Date: Sat Jun 27 10:19:43 UTC 2020
> 
> Modified Files:
>   src/tests/lib/libc/stdlib: t_mbtowc.c
> 
> Log Message:
> Add the default TNF copyright (2005), cf. PR misc/55419.
> 
> 
> To generate a diff of this commit:
> cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/stdlib/t_mbtowc.c
> 

I don't think we can generally do this. Can you clarify if you discussed
this with the author in commit messages?

Thanks.


Re: CVS commit: src/tests/lib/libc/stdlib

2011-07-15 Thread Christos Zoulas
In article <20110715140041.6d97117...@cvs.netbsd.org>,
Jukka Ruohonen  wrote:
>-=-=-=-=-=-
>
>Module Name:   src
>Committed By:  jruoho
>Date:  Fri Jul 15 14:00:41 UTC 2011
>
>Modified Files:
>   src/tests/lib/libc/stdlib: Makefile
>
>Log Message:
>Fix wrong linker flag that has always been lurking here.

Actually I think it is better to put -pthread in CFLAGS since this is
the portable way to get the threaded compiler environment.

christos



Re: CVS commit: src/tests/lib/libc/stdlib

2011-06-04 Thread Matt Thomas

On Jun 4, 2011, at 4:35 PM, Adam Hamsik wrote:

> 
> On Jun,Sunday 5 2011, at 12:58 AM, Jukka Ruohonen wrote:
> 
>> On Sat, Jun 04, 2011 at 10:49:49PM +, Adam Hamsik wrote:
>>> Module Name:src
>>> Committed By:   haad
>>> Date:   Sat Jun  4 22:49:49 UTC 2011
>>> 
>>> Modified Files:
>>> src/tests/lib/libc/stdlib: t_strtol.c
>>> 
>>> Log Message:
>>> Fix problem with overflowing constant definition
>>> 
>>> t_strtol.c:95: warning: overflow in implicit constant conversion
>> 
>> Can you note the architecture and explain the overflow so that I can
>> learn something?
> 
> Architecture i386 - PAE,

also dies on powerpc.


Re: CVS commit: src/tests/lib/libc/stdlib

2011-06-04 Thread Adam Hamsik

On Jun,Sunday 5 2011, at 12:58 AM, Jukka Ruohonen wrote:

> On Sat, Jun 04, 2011 at 10:49:49PM +, Adam Hamsik wrote:
>> Module Name: src
>> Committed By:haad
>> Date:Sat Jun  4 22:49:49 UTC 2011
>> 
>> Modified Files:
>>  src/tests/lib/libc/stdlib: t_strtol.c
>> 
>> Log Message:
>> Fix problem with overflowing constant definition
>> 
>> t_strtol.c:95: warning: overflow in implicit constant conversion
> 
> Can you note the architecture and explain the overflow so that I can
> learn something?

Architecture i386 - PAE,

#   compile  kern/strtoull.o
/usr/devel/buildslave/obj/i386/tooldir/bin/i486--netbsdelf-gcc -O2 -Wall -Os 
-ffreestanding -std=gnu99 -Werror  -march=i386 -mtune=i386  
--sysroot=/usr/devel/buildslave/obj/i386/destdir.i386 
-I/usr/devel/buildslave/full/build/sys/arch/i386/stand/netboot/3c509/../../../../../lib/libkern/arch/i386
 --sysroot=/usr/devel/buildslave/obj/i386/destdir.i386 -DSLOW -DSUPPORT_BOOTP 
-DSUPPORT_DHCP -DSUPPORT_TFTP -DBOOTROM -DRELOC=0x9 -nostdinc 
-I/usr/devel/buildslave/obj/i386/sys/arch/i386/stand/netboot/3c509 
-I/usr/devel/buildslave/full/build/sys/arch/i386/stand/netboot/3c509/../../../../..
 
-I/usr/devel/buildslave/full/build/sys/arch/i386/stand/netboot/3c509/../../../../../arch/i386/stand/lib
 
-I/usr/devel/buildslave/full/build/sys/arch/i386/stand/netboot/3c509/../../../../../lib/libsa
 -D_STANDALONE 
-I/usr/devel/buildslave/full/build/sys/arch/i386/stand/netboot/3c509/../../../../../lib/libkern/../../../common/lib/libc/quad
 
-I/usr/devel/buildslave/full/build/sys/arch/i386/stand/netboot/3c509/../../../../../lib/libkern/../../../common/lib/libc/string
 
-I/usr/devel/buildslave/full/build/sys/arch/i386/stand/netboot/3c509/../../../../../lib/libkern/../../../common/lib/libc/arch/i386/string
  
-I/usr/devel/buildslave/full/build/sys/arch/i386/stand/netboot/3c509/../../../../../lib/libkern/../../../common/lib/libc/quad
 
-I/usr/devel/buildslave/full/build/sys/arch/i386/stand/netboot/3c509/../../../../../lib/libkern/../../../common/lib/libc/string
 
-I/usr/devel/buildslave/full/build/sys/arch/i386/stand/netboot/3c509/../../../../../lib/libkern/../../../common/lib/libc/arch/i386/string
 
-I/usr/devel/buildslave/full/build/sys/arch/i386/stand/netboot/3c509/../../../../../lib/libkern/../../../common/include
  -c
/usr/devel/buildslave/full/build/sys/arch/i386/stand/netboot/3c509/../../../../../lib/libkern/../../../common/lib/libc/stdlib/strtoull.c
 -o strtoull.o
--- dependall-tests ---
cc1: warnings being treated as errors
/usr/devel/buildslave/full/build/tests/lib/libc/stdlib/t_strtol.c: In function 
'atfu_strtol_base_body':
/usr/devel/buildslave/full/build/tests/lib/libc/stdlib/t_strtol.c:95: warning: 
overflow in implicit constant conversion
/usr/devel/buildslave/full/build/tests/lib/libc/stdlib/t_strtol.c:96: warning: 
overflow in implicit constant conversion
*** [t_strtol.o] Error code 1
nbmake: stopped in /usr/devel/buildslave/full/build/tests/lib/libc/stdlib
1 error
nbmake: stopped in /usr/devel/buildslave/full/build/tests/lib/libc/stdlib

Please revert/fix my commit if I did it wrong. But I can compile -current with 
it.

Regards

Adam.



Re: CVS commit: src/tests/lib/libc/stdlib

2011-06-04 Thread Jukka Ruohonen
On Sat, Jun 04, 2011 at 10:49:49PM +, Adam Hamsik wrote:
> Module Name:  src
> Committed By: haad
> Date: Sat Jun  4 22:49:49 UTC 2011
> 
> Modified Files:
>   src/tests/lib/libc/stdlib: t_strtol.c
> 
> Log Message:
> Fix problem with overflowing constant definition
> 
> t_strtol.c:95: warning: overflow in implicit constant conversion

Can you note the architecture and explain the overflow so that I can
learn something?

- Jukka.


Re: CVS commit: src/tests/lib/libc/stdlib

2011-05-10 Thread Jukka Ruohonen
On Tue, May 10, 2011 at 11:37:16AM -0700, Cliff Neighbors wrote:
> > In file included from 
> > /home/cliff/netbsd/NetBSD-current/usr/src/tests/lib/libc/s
> > tdlib/t_strtod.c:38:
> > /home/cliff/netbsd/NetBSD-current/build/evbmips64-eb-20110510/dest/usr/include/f
> > env.h:29:2: error: #error "fenv.h is currently not supported for this 
> > architectu
> > re"
> > /home/cliff/netbsd/NetBSD-current/build/evbmips64-eb-20110510/dest/usr/include/f
> > env.h:35:26: error: machine/fenv.h: No such file or directory
> > nbmkdep: compile failed.
> > *** [t_strtod.d] Error code 1
> > 
> 
> do we need #ifdef Honor_FLT_ROUNDS around that include?

Hmm, I guess so. Or #ifndef NO_FENV_H? I am not familiar with the
conditional compilation of gdtoa.

- Jukka.


Re: CVS commit: src/tests/lib/libc/stdlib

2011-05-10 Thread Cliff Neighbors
Jukka,

#include fenv.h as part of this seems to have caused build.sh to break on arch 
evbmips64-eb 

> In file included from 
> /home/cliff/netbsd/NetBSD-current/usr/src/tests/lib/libc/s
> tdlib/t_strtod.c:38:
> /home/cliff/netbsd/NetBSD-current/build/evbmips64-eb-20110510/dest/usr/include/f
> env.h:29:2: error: #error "fenv.h is currently not supported for this 
> architectu
> re"
> /home/cliff/netbsd/NetBSD-current/build/evbmips64-eb-20110510/dest/usr/include/f
> env.h:35:26: error: machine/fenv.h: No such file or directory
> nbmkdep: compile failed.
> *** [t_strtod.d] Error code 1
> 

do we need #ifdef Honor_FLT_ROUNDS around that include?

 -cliff-




On May 10, 2011, at 8:20 AM, Jukka Ruohonen wrote:

> Module Name:  src
> Committed By: jruoho
> Date: Tue May 10 15:20:19 UTC 2011
> 
> Modified Files:
>   src/tests/lib/libc/stdlib: t_strtod.c
> 
> Log Message:
> Verify that strtod(3) honors the current rounding mode set by fesetround(3).
> Passes on amd64. Prompted by a bug in the GNU C library.
> 
> 
> To generate a diff of this commit:
> cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libc/stdlib/t_strtod.c
> 
> Please note that diffs are not public domain; they are subject to the
> copyright notices on the relevant files.
>