summaryrefslogtreecommitdiffstats
path: root/contrib/netbsd-tests/lib/libc/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/netbsd-tests/lib/libc/stdlib')
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/h_atexit.c212
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/h_getopt.c130
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/h_getopt_long.c242
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_abs.c154
-rwxr-xr-xcontrib/netbsd-tests/lib/libc/stdlib/t_atexit.sh54
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_atoi.c121
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_div.c98
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_exit.c186
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_getenv.c211
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_getenv_thread.c250
-rwxr-xr-xcontrib/netbsd-tests/lib/libc/stdlib/t_getopt.sh123
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_hsearch.c411
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_mi_vector_hash.c95
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_posix_memalign.c88
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_random.c82
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_strtod.c342
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_strtol.c234
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_system.c83
18 files changed, 3116 insertions, 0 deletions
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/h_atexit.c b/contrib/netbsd-tests/lib/libc/stdlib/h_atexit.c
new file mode 100644
index 0000000..c0641db
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/h_atexit.c
@@ -0,0 +1,212 @@
+/* $NetBSD: h_atexit.c,v 1.1 2011/01/12 19:44:08 pgoyette Exp $ */
+
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code was contributed to The NetBSD Foundation by Jason R. Thorpe.
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__COPYRIGHT("@(#) Copyright (c) 2011\
+ The NetBSD Foundation, inc. All rights reserved.");
+__RCSID("$NetBSD: h_atexit.c,v 1.1 2011/01/12 19:44:08 pgoyette Exp $");
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <string.h>
+#include <unistd.h>
+
+extern int __cxa_atexit(void (*func)(void *), void *, void *);
+extern void __cxa_finalize(void *);
+
+#ifdef __FreeBSD__
+/*
+ * On shared object unload, in __cxa_finalize, call and clear all installed
+ * atexit and __cxa_atexit handlers that are either installed by unloaded
+ * dso, or points to the functions provided by the dso.
+ *
+ * The reason of the change is to ensure that there is no lingering pointers
+ * to the unloaded code after the dlclose(3). It is known reason for infinite
+ * stream of the crash reports for many programs which use loadable modules
+ * and fail to properly clean on module unload. Examples are apache, php,
+ * perl etc.
+ *
+ * You pass the &dso_handle_1 and &dso_handle_2, which points inside the
+ * main binary, to the registration function. The code from r211706,
+ * correctly detects that they are for the main binary, and on the first
+ * call to __cxa_finalize(), which also pass pointer to main binary, all
+ * registered functions from the main binary are executed.
+ */
+
+static void *dso_handle_1 = (void *)1;
+static void *dso_handle_2 = (void *)2;
+static void *dso_handle_3 = (void *)3;
+#else
+static int dso_handle_1;
+static int dso_handle_2;
+static int dso_handle_3;
+#endif
+
+static int arg_1;
+static int arg_2;
+static int arg_3;
+
+static int exiting_state;
+
+#define ASSERT(expr) \
+do { \
+ if ((expr) == 0) { \
+ write(STDERR_FILENO, __func__, strlen(__func__)); \
+ write(STDERR_FILENO, ": ", 2); \
+ write(STDERR_FILENO, __STRING(expr), \
+ strlen(__STRING(expr))); \
+ write(STDERR_FILENO, "\n", 1); \
+ my_abort(); \
+ } \
+} while (/*CONSTCOND*/0)
+
+#define SUCCESS() \
+do { \
+ write(STDOUT_FILENO, __func__, strlen(__func__)); \
+ write(STDOUT_FILENO, "\n", 1); \
+} while (/*CONSTCOND*/0)
+
+static void
+my_abort(void)
+{
+
+ kill(getpid(), SIGABRT);
+ /* NOTREACHED */
+}
+
+static void
+cxa_handler_5(void *arg)
+{
+ static int cxa_handler_5_called;
+
+ ASSERT(arg == (void *)&arg_1);
+ ASSERT(cxa_handler_5_called == 0);
+ ASSERT(exiting_state == 5);
+
+ exiting_state--;
+ cxa_handler_5_called = 1;
+ SUCCESS();
+}
+
+static void
+cxa_handler_4(void *arg)
+{
+ static int cxa_handler_4_called;
+
+ ASSERT(arg == (void *)&arg_1);
+ ASSERT(cxa_handler_4_called == 0);
+ ASSERT(exiting_state == 4);
+
+ exiting_state--;
+ cxa_handler_4_called = 1;
+ SUCCESS();
+}
+
+static void
+cxa_handler_3(void *arg)
+{
+ static int cxa_handler_3_called;
+
+ ASSERT(arg == (void *)&arg_2);
+ ASSERT(cxa_handler_3_called == 0);
+ ASSERT(exiting_state == 3);
+
+ exiting_state--;
+ cxa_handler_3_called = 1;
+ SUCCESS();
+}
+
+static void
+cxa_handler_2(void *arg)
+{
+ static int cxa_handler_2_called;
+
+ ASSERT(arg == (void *)&arg_3);
+ ASSERT(cxa_handler_2_called == 0);
+ ASSERT(exiting_state == 2);
+
+ exiting_state--;
+ cxa_handler_2_called = 1;
+ SUCCESS();
+}
+
+static void
+normal_handler_1(void)
+{
+ static int normal_handler_1_called;
+
+ ASSERT(normal_handler_1_called == 0);
+ ASSERT(exiting_state == 1);
+
+ exiting_state--;
+ normal_handler_1_called = 1;
+ SUCCESS();
+}
+
+static void
+normal_handler_0(void)
+{
+ static int normal_handler_0_called;
+
+ ASSERT(normal_handler_0_called == 0);
+ ASSERT(exiting_state == 0);
+
+ normal_handler_0_called = 1;
+ SUCCESS();
+}
+
+int
+main(int argc, char *argv[])
+{
+
+ exiting_state = 5;
+
+ ASSERT(0 == atexit(normal_handler_0));
+ ASSERT(0 == atexit(normal_handler_1));
+#ifdef __FreeBSD__
+ ASSERT(0 == __cxa_atexit(cxa_handler_4, &arg_1, dso_handle_1));
+ ASSERT(0 == __cxa_atexit(cxa_handler_5, &arg_1, dso_handle_1));
+ ASSERT(0 == __cxa_atexit(cxa_handler_3, &arg_2, dso_handle_2));
+ ASSERT(0 == __cxa_atexit(cxa_handler_2, &arg_3, dso_handle_3));
+
+ __cxa_finalize(dso_handle_1);
+ __cxa_finalize(dso_handle_2);
+#else
+ ASSERT(0 == __cxa_atexit(cxa_handler_4, &arg_1, &dso_handle_1));
+ ASSERT(0 == __cxa_atexit(cxa_handler_5, &arg_1, &dso_handle_1));
+ ASSERT(0 == __cxa_atexit(cxa_handler_3, &arg_2, &dso_handle_2));
+ ASSERT(0 == __cxa_atexit(cxa_handler_2, &arg_3, &dso_handle_3));
+
+ __cxa_finalize(&dso_handle_1);
+ __cxa_finalize(&dso_handle_2);
+#endif
+ exit(0);
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/h_getopt.c b/contrib/netbsd-tests/lib/libc/stdlib/h_getopt.c
new file mode 100644
index 0000000..ec2b9bb
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/h_getopt.c
@@ -0,0 +1,130 @@
+/* $NetBSD: h_getopt.c,v 1.1 2011/01/01 23:56:49 pgoyette Exp $ */
+
+/*-
+ * Copyright (c) 2002 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <err.h>
+#ifdef __FreeBSD__
+#include <libutil.h>
+#endif
+
+#define WS "\t\n "
+#define debug 0
+
+int
+main(int argc, char *argv[])
+{
+ size_t len, lineno = 0;
+ char *line, *ptr, *optstring = NULL, *result = NULL;
+ char buf[1024];
+ char *args[100];
+ char arg[100];
+ int nargs = -1;
+ int c;
+
+ while ((line = fparseln(stdin, &len, &lineno, NULL, 0)) != NULL) {
+ if (strncmp(line, "load:", 5) == 0) {
+ if (optstring)
+ free(optstring);
+ optstring = strtok(&line[6], WS);
+ if (optstring == NULL)
+ errx(1, "missing optstring at line %ld",
+ (unsigned long)lineno);
+ optstring = strdup(optstring);
+ if (debug)
+ fprintf(stderr, "optstring = %s\n", optstring);
+ } else if (strncmp(line, "args:", 5) == 0) {
+ for (; nargs >= 0; nargs--) {
+ if (args[nargs] != NULL)
+ free(args[nargs]);
+ }
+ args[nargs = 0] = strtok(&line[6], WS);
+ if (args[nargs] == NULL)
+ errx(1, "missing args at line %ld",
+ (unsigned long)lineno);
+
+ args[nargs] = strdup(args[nargs]);
+ while ((args[++nargs] = strtok(NULL, WS)) != NULL)
+ args[nargs] = strdup(args[nargs]);
+ if (debug) {
+ int i = 0;
+ for (i = 0; i < nargs; i++)
+ fprintf(stderr, "argv[%d] = %s\n", i,
+ args[i]);
+ }
+ } else if (strncmp(line, "result:", 7) == 0) {
+ buf[0] = '\0';
+ optind = optreset = 1;
+ if (result)
+ free(result);
+ result = strtok(&line[8], WS);
+ if (result == NULL)
+ errx(1, "missing result at line %ld",
+ (unsigned long)lineno);
+ result = strdup(result);
+ if (nargs == -1)
+ errx(1, "result: without args:");
+ if (debug)
+ fprintf(stderr, "result = %s\n", result);
+ while ((c = getopt(nargs, args, optstring)) != -1) {
+ if (c == ':')
+ err(1, "`:' found as argument char");
+ if ((ptr = strchr(optstring, c)) == NULL) {
+ snprintf(arg, sizeof(arg), "!%c,", c);
+ strcat(buf, arg);
+ continue;
+ }
+ if (ptr[1] != ':')
+ snprintf(arg, sizeof(arg), "%c,", c);
+ else
+ snprintf(arg, sizeof(arg), "%c=%s,",
+ c, optarg);
+ strcat(buf, arg);
+ }
+ len = strlen(buf);
+ if (len > 0) {
+ buf[len - 1] = '|';
+ buf[len] = '\0';
+ } else {
+ buf[0] = '|';
+ buf[1] = '\0';
+ }
+ snprintf(arg, sizeof(arg), "%d", nargs - optind);
+ strcat(buf, arg);
+ if (strcmp(buf, result) != 0)
+ errx(1, "`%s' != `%s'", buf, result);
+ }
+ free(line);
+ }
+ return 0;
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/h_getopt_long.c b/contrib/netbsd-tests/lib/libc/stdlib/h_getopt_long.c
new file mode 100644
index 0000000..2293e2c
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/h_getopt_long.c
@@ -0,0 +1,242 @@
+/* $NetBSD: h_getopt_long.c,v 1.1 2011/01/01 23:56:49 pgoyette Exp $ */
+
+/*-
+ * Copyright (c) 2007 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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.
+ */
+
+#include <ctype.h>
+#include <err.h>
+#include <getopt.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#ifdef __FreeBSD__
+#include <libutil.h>
+#endif
+
+#define SKIPWS(p) while (isspace((int)(*p))) p++
+#define WS "\t\n "
+
+int
+main(int argc, char *argv[])
+{
+ size_t len, lineno = 0;
+ char *line, *eptr, *longopt, *ptr, *optstring = NULL, *result = NULL;
+ char buf[1024];
+ char *args[128];
+ char arg[256];
+ int nargs = -1;
+ int c;
+ int nlongopts = 0;
+ int maxnlongopts = 0;
+ int *longopt_flags = NULL;
+ struct option *longopts = NULL;
+
+ while ((line = fparseln(stdin, &len, &lineno, NULL, 0)) != NULL) {
+ if (strncmp(line, "optstring:", 10) == 0) {
+ if (optstring)
+ free(optstring);
+ optstring = strtok(&line[11], WS);
+ if (optstring == NULL)
+ errx(1, "missing optstring at line %ld",
+ (unsigned long)lineno);
+ optstring = strdup(optstring);
+ } else if (strncmp(line, "longopts:", 9) == 0) {
+ if (longopts) {
+ int i;
+ for (i = 0; i < nlongopts; i++)
+ if (longopts[i].name != NULL)
+ free(__UNCONST(longopts[i].name));
+ free(longopts);
+ }
+ if (longopt_flags)
+ free(longopt_flags);
+ nlongopts = 0;
+ ptr = strtok(&line[10], WS);
+ if (ptr == NULL)
+ errx(1, "missing longopts at line %ld",
+ (unsigned long)lineno);
+ maxnlongopts = strtoul(ptr, &eptr, 10);
+ if (*eptr != '\0')
+ warnx("garbage in longopts at line %ld",
+ (unsigned long)lineno);
+ maxnlongopts++; /* space for trailer */
+ longopts =
+ (struct option *)calloc(sizeof(struct option),
+ maxnlongopts);
+ if (longopts == NULL)
+ err(1, "calloc");
+ longopt_flags = (int *)calloc(sizeof(int), maxnlongopts);
+ if (longopt_flags == NULL)
+ err(1, "calloc");
+ } else if (strncmp(line, "longopt:", 8) == 0) {
+ if (longopts == NULL)
+ errx(1, "longopt: without longopts at line %ld",
+ (unsigned long)lineno);
+ if (nlongopts >= maxnlongopts)
+ errx(1, "longopt: too many options at line %ld",
+ (unsigned long)lineno);
+ /* name */
+ ptr = &line[9];
+ SKIPWS(ptr);
+ longopt = strsep(&ptr, ",");
+ if (longopt == NULL)
+ errx(1, "missing longopt at line %ld",
+ (unsigned long)lineno);
+ longopts[nlongopts].name = strdup(longopt);
+ /* has_arg */
+ SKIPWS(ptr);
+ longopt = strsep(&ptr, ",");
+ if (*longopt != '\0') {
+ if (strncmp(longopt, "0", 1) == 0 ||
+ strncmp(longopt, "no_argument", 2) == 0)
+ longopts[nlongopts].has_arg = no_argument;
+ else if (strncmp(longopt, "1", 1) == 0 ||
+ strncmp(longopt, "required_argument", 8) == 0)
+ longopts[nlongopts].has_arg = required_argument;
+ else if (strncmp(longopt, "2", 1) == 0 ||
+ strncmp(longopt, "optional_argument", 8) == 0)
+ longopts[nlongopts].has_arg = optional_argument;
+ else
+ errx(1, "unknown has_arg %s at line %ld",
+ longopt, (unsigned long)lineno);
+ }
+ /* flag */
+ SKIPWS(ptr);
+ longopt = strsep(&ptr, ",");
+ if (*longopt != '\0' &&
+ strncmp(longopt, "NULL", 4) != 0)
+ longopts[nlongopts].flag = &longopt_flags[nlongopts];
+ /* val */
+ SKIPWS(ptr);
+ longopt = strsep(&ptr, ",");
+ if (*longopt == '\0')
+ errx(1, "missing val at line %ld",
+ (unsigned long)lineno);
+ if (*longopt != '\'') {
+ longopts[nlongopts].val =
+ (int)strtoul(longopt, &eptr, 10);
+ if (*eptr != '\0')
+ errx(1, "invalid val at line %ld",
+ (unsigned long)lineno);
+ } else
+ longopts[nlongopts].val = (int)longopt[1];
+ nlongopts++;
+ } else if (strncmp(line, "args:", 5) == 0) {
+ for (; nargs >= 0; nargs--) {
+ if (args[nargs] != NULL)
+ free(args[nargs]);
+ }
+ args[nargs = 0] = strtok(&line[6], WS);
+ if (args[nargs] == NULL)
+ errx(1, "Missing args");
+
+ args[nargs] = strdup(args[nargs]);
+ while ((args[++nargs] = strtok(NULL, WS)) != NULL)
+ args[nargs] = strdup(args[nargs]);
+ } else if (strncmp(line, "result:", 7) == 0) {
+ int li;
+ buf[0] = '\0';
+ optind = optreset = 1;
+ if (result)
+ free(result);
+ result = strtok(&line[8], WS);
+ if (result == NULL)
+ errx(1, "missing result at line %ld",
+ (unsigned long)lineno);
+ if (optstring == NULL)
+ errx(1, "result: without optstring");
+ if (longopts == NULL || nlongopts == 0)
+ errx(1, "result: without longopts");
+ result = strdup(result);
+ if (nargs == -1)
+ errx(1, "result: without args");
+ li = -2;
+ while ((c = getopt_long(nargs, args, optstring,
+ longopts, &li)) != -1) {
+ if (c == ':')
+ errx(1, "`:' found as argument char");
+ if (li == -2) {
+ ptr = strchr(optstring, c);
+ if (ptr == NULL) {
+ snprintf(arg, sizeof(arg),
+ "!%c,", c);
+ strcat(buf, arg);
+ continue;
+ }
+ if (ptr[1] != ':')
+ snprintf(arg, sizeof(arg),
+ "%c,", c);
+ else
+ snprintf(arg, sizeof(arg),
+ "%c=%s,", c, optarg);
+ } else {
+ switch (longopts[li].has_arg) {
+ case no_argument:
+ snprintf(arg, sizeof(arg), "-%s,",
+ longopts[li].name);
+ break;
+ case required_argument:
+ snprintf(arg, sizeof(arg),
+ "-%s=%s,",
+ longopts[li].name, optarg);
+ break;
+ case optional_argument:
+ snprintf(arg, sizeof(arg),
+ "-%s%s%s,",
+ longopts[li].name,
+ (optarg)? "=" : "",
+ (optarg)? optarg : "");
+ break;
+ default:
+ errx(1, "internal error");
+ }
+ }
+ strcat(buf, arg);
+ li = -2;
+ }
+ len = strlen(buf);
+ if (len > 0) {
+ buf[len - 1] = '|';
+ buf[len] = '\0';
+ } else {
+ buf[0] = '|';
+ buf[1] = '\0';
+ }
+ snprintf(arg, sizeof(arg), "%d", nargs - optind);
+ strcat(buf, arg);
+ if (strcmp(buf, result) != 0)
+ errx(1, "`%s' != `%s'", buf, result);
+ } else
+ errx(1, "unknown directive at line %ld",
+ (unsigned long)lineno);
+ free(line);
+ }
+ return 0;
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_abs.c b/contrib/netbsd-tests/lib/libc/stdlib/t_abs.c
new file mode 100644
index 0000000..282a125
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_abs.c
@@ -0,0 +1,154 @@
+/* $NetBSD: t_abs.c,v 1.3 2014/03/01 22:38:13 joerg Exp $ */
+
+/*-
+ * Copyright (c) 2012 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.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_abs.c,v 1.3 2014/03/01 22:38:13 joerg Exp $");
+
+#include <atf-c.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <stdlib.h>
+
+ATF_TC(abs_basic);
+ATF_TC_HEAD(abs_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test that abs(3) works");
+}
+
+ATF_TC_BODY(abs_basic, tc)
+{
+ static const struct {
+ int val;
+ int res;
+ } table[] = {
+ { 0, 0 },
+ { +0, 0 },
+ { -0, 0 },
+ { -0x1010, 0x1010 },
+ { INT_MAX, INT_MAX },
+ { -INT_MAX, INT_MAX },
+ };
+
+ for (size_t i = 0; i < __arraycount(table); i++)
+ ATF_CHECK(abs(table[i].val) == table[i].res);
+}
+
+ATF_TC(imaxabs_basic);
+ATF_TC_HEAD(imaxabs_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test that imaxabs(3) works");
+}
+
+ATF_TC_BODY(imaxabs_basic, tc)
+{
+ static const struct {
+ intmax_t val;
+ intmax_t res;
+ } table[] = {
+ { 0, 0 },
+ { INT_MAX, INT_MAX },
+ { -INT_MAX, INT_MAX },
+ { LONG_MAX, LONG_MAX },
+ { -LONG_MAX, LONG_MAX },
+ { LLONG_MAX, LLONG_MAX },
+ { -LLONG_MAX, LLONG_MAX },
+ { INT_MAX, INT_MAX },
+ { -INT_MAX, INT_MAX },
+ };
+
+ for (size_t i = 0; i < __arraycount(table); i++)
+ ATF_CHECK(imaxabs(table[i].val) == table[i].res);
+}
+
+ATF_TC(labs_basic);
+ATF_TC_HEAD(labs_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test that labs(3) works");
+}
+
+ATF_TC_BODY(labs_basic, tc)
+{
+ static const struct {
+ long val;
+ long res;
+ } table[] = {
+ { 0, 0 },
+ { +0, 0 },
+ { -0, 0 },
+ { -1, 1 },
+ { LONG_MAX, LONG_MAX },
+ { -LONG_MAX, LONG_MAX },
+ { INT_MAX, INT_MAX },
+ { -INT_MAX, INT_MAX },
+ };
+
+ for (size_t i = 0; i < __arraycount(table); i++)
+ ATF_CHECK(labs(table[i].val) == table[i].res);
+}
+
+ATF_TC(llabs_basic);
+ATF_TC_HEAD(llabs_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test that llabs(3) works");
+}
+
+ATF_TC_BODY(llabs_basic, tc)
+{
+ static const struct {
+ long long val;
+ long long res;
+ } table[] = {
+ { 0, 0 },
+ { +0, 0 },
+ { -0, 0 },
+ { -1, 1 },
+ { INT_MAX, INT_MAX },
+ { -INT_MAX, INT_MAX },
+ { LONG_MAX, LONG_MAX },
+ { -LONG_MAX, LONG_MAX },
+ { LLONG_MAX, LLONG_MAX },
+ { -LLONG_MAX, LLONG_MAX },
+ { -0x100000000LL, 0x100000000LL },
+ };
+
+ for (size_t i = 0; i < __arraycount(table); i++)
+ ATF_CHECK(llabs(table[i].val) == table[i].res);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, abs_basic);
+ ATF_TP_ADD_TC(tp, imaxabs_basic);
+ ATF_TP_ADD_TC(tp, labs_basic);
+ ATF_TP_ADD_TC(tp, llabs_basic);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_atexit.sh b/contrib/netbsd-tests/lib/libc/stdlib/t_atexit.sh
new file mode 100755
index 0000000..d11268b
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_atexit.sh
@@ -0,0 +1,54 @@
+# $NetBSD: t_atexit.sh,v 1.1 2011/01/12 19:44:08 pgoyette Exp $
+#
+# Copyright (c) 2011 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# 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.
+#
+
+atf_test_case atexit
+atexit_head()
+{
+ atf_set "descr" "Checks atexit(3) and __cxa_atexit()/__cxa_finalize()"
+}
+atexit_body()
+{
+ $(atf_get_srcdir)/h_atexit >out \
+ || atf_fail "h_exit failed, see output of the test for details"
+
+ cat >exp <<EOF
+cxa_handler_5
+cxa_handler_4
+cxa_handler_3
+cxa_handler_2
+normal_handler_1
+normal_handler_0
+EOF
+
+ diff -Nru exp out \
+ || atf_fail "h_exit failed, see output of the test for details"
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case atexit
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_atoi.c b/contrib/netbsd-tests/lib/libc/stdlib/t_atoi.c
new file mode 100644
index 0000000..3e0c35f
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_atoi.c
@@ -0,0 +1,121 @@
+/* $NetBSD: t_atoi.c,v 1.2 2012/03/29 05:56:36 jruoho Exp $ */
+
+/*-
+ * Copyright (c) 2012 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.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_atoi.c,v 1.2 2012/03/29 05:56:36 jruoho Exp $");
+
+#include <atf-c.h>
+#include <float.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+ATF_TC(atof_strtod);
+ATF_TC_HEAD(atof_strtod, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that atof(3) matches the corresponding strtod(3) call");
+}
+
+ATF_TC_BODY(atof_strtod, tc)
+{
+ char buf[128];
+
+ (void)snprintf(buf, sizeof(buf), "%f\n", DBL_MAX);
+
+ ATF_REQUIRE(atof("0") == strtod("0", NULL));
+ ATF_REQUIRE(atof("-1") == strtod("-1", NULL));
+ ATF_REQUIRE(atof(buf) == strtod(buf, NULL));
+}
+
+ATF_TC(atoi_strtol);
+ATF_TC_HEAD(atoi_strtol, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that atoi(3) matches the corresponding strtol(3) call");
+}
+
+ATF_TC_BODY(atoi_strtol, tc)
+{
+ char buf[64];
+
+ (void)snprintf(buf, sizeof(buf), "%d\n", INT_MAX);
+
+ ATF_REQUIRE(atoi("0") == strtol("0", NULL, 10));
+ ATF_REQUIRE(atoi("-1") == strtol("-1", NULL, 10));
+ ATF_REQUIRE(atoi(buf) == strtol(buf, NULL, 10));
+}
+
+ATF_TC(atol_strtol);
+ATF_TC_HEAD(atol_strtol, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that atol(3) matches the corresponding strtol(3) call");
+}
+
+ATF_TC_BODY(atol_strtol, tc)
+{
+ char buf[64];
+
+ (void)snprintf(buf, sizeof(buf), "%ld\n", LONG_MAX);
+
+ ATF_REQUIRE(atol("0") == strtol("0", NULL, 10));
+ ATF_REQUIRE(atol("-1") == strtol("-1", NULL, 10));
+ ATF_REQUIRE(atol(buf) == strtol(buf, NULL, 10));
+}
+
+ATF_TC(atoll_strtoll);
+ATF_TC_HEAD(atoll_strtoll, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that atoll(3) matches the corresponding strtoll(3) call");
+}
+
+ATF_TC_BODY(atoll_strtoll, tc)
+{
+ char buf[128];
+
+ (void)snprintf(buf, sizeof(buf), "%lld\n", LLONG_MAX);
+
+ ATF_REQUIRE(atoll("0") == strtoll("0", NULL, 10));
+ ATF_REQUIRE(atoll("-1") == strtoll("-1", NULL, 10));
+ ATF_REQUIRE(atoll(buf) == strtoll(buf, NULL, 10));
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, atof_strtod);
+ ATF_TP_ADD_TC(tp, atoi_strtol);
+ ATF_TP_ADD_TC(tp, atol_strtol);
+ ATF_TP_ADD_TC(tp, atoll_strtoll);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_div.c b/contrib/netbsd-tests/lib/libc/stdlib/t_div.c
new file mode 100644
index 0000000..376f357
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_div.c
@@ -0,0 +1,98 @@
+/* $NetBSD: t_div.c,v 1.2 2011/07/07 11:12:18 jruoho Exp $ */
+
+/*-
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ */
+
+#include <atf-c.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#define NUM 1999236
+#define DENOM 1000000
+#define QUOT 1
+#define REM 999236
+
+ATF_TC(div_basic);
+ATF_TC_HEAD(div_basic, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Test div(3) for correctness");
+}
+
+ATF_TC_BODY(div_basic, tc)
+{
+ div_t d;
+
+ d = div(NUM, DENOM);
+
+ ATF_CHECK(d.quot == QUOT);
+ ATF_CHECK(d.rem == REM);
+}
+
+ATF_TC(ldiv_basic);
+ATF_TC_HEAD(ldiv_basic, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Test ldiv(3) for correctness");
+}
+
+ATF_TC_BODY(ldiv_basic, tc)
+{
+ ldiv_t ld;
+
+ ld = ldiv(NUM, DENOM);
+
+ ATF_CHECK(ld.quot == QUOT);
+ ATF_CHECK(ld.rem == REM);
+}
+
+ATF_TC(lldiv_basic);
+ATF_TC_HEAD(lldiv_basic, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Test lllldiv(3) for correctness");
+}
+
+ATF_TC_BODY(lldiv_basic, tc)
+{
+ lldiv_t lld;
+
+ lld = lldiv(NUM, DENOM);
+
+ ATF_CHECK(lld.quot == QUOT);
+ ATF_CHECK(lld.rem == REM);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, div_basic);
+ ATF_TP_ADD_TC(tp, ldiv_basic);
+ ATF_TP_ADD_TC(tp, lldiv_basic);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_exit.c b/contrib/netbsd-tests/lib/libc/stdlib/t_exit.c
new file mode 100644
index 0000000..067cb51
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_exit.c
@@ -0,0 +1,186 @@
+/* $NetBSD: t_exit.c,v 1.1 2011/05/09 07:31:51 jruoho Exp $ */
+
+/*-
+ * Copyright (c) 2011 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.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_exit.c,v 1.1 2011/05/09 07:31:51 jruoho Exp $");
+
+#include <sys/wait.h>
+
+#include <atf-c.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static bool fail;
+static void func(void);
+
+static void
+func(void)
+{
+ fail = false;
+}
+
+ATF_TC(exit_atexit);
+ATF_TC_HEAD(exit_atexit, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A basic test of atexit(3)");
+}
+
+ATF_TC_BODY(exit_atexit, tc)
+{
+ pid_t pid;
+ int sta;
+
+ pid = fork();
+ ATF_REQUIRE(pid >= 0);
+
+ if (pid == 0) {
+
+ if (atexit(func) != 0)
+ _exit(EXIT_FAILURE);
+
+ fail = true;
+
+ _exit(EXIT_SUCCESS);
+ }
+
+ (void)wait(&sta);
+
+ if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS)
+ atf_tc_fail("atexit(3) failed");
+
+ if (fail != false)
+ atf_tc_fail("atexit(3) was not called");
+}
+
+ATF_TC(exit_basic);
+ATF_TC_HEAD(exit_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A basic test of exit(3)");
+}
+
+ATF_TC_BODY(exit_basic, tc)
+{
+ pid_t pid;
+ int sta;
+
+ pid = fork();
+ ATF_REQUIRE(pid >= 0);
+
+ if (pid == 0) {
+ exit(EXIT_SUCCESS);
+ exit(EXIT_FAILURE);
+ }
+
+ (void)wait(&sta);
+
+ if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS)
+ atf_tc_fail("exit(3) did not exit successfully");
+}
+
+ATF_TC(exit_status);
+ATF_TC_HEAD(exit_status, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test exit(3) status");
+}
+
+ATF_TC_BODY(exit_status, tc)
+{
+ const int n = 10;
+ int i, sta;
+ pid_t pid;
+
+ for (i = 0; i < n; i++) {
+
+ pid = fork();
+
+ if (pid < 0)
+ exit(EXIT_FAILURE);
+
+ if (pid == 0)
+ exit(i);
+
+ (void)wait(&sta);
+
+ if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != i)
+ atf_tc_fail("invalid exit(3) status");
+ }
+}
+
+ATF_TC(exit_tmpfile);
+ATF_TC_HEAD(exit_tmpfile, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Temporary files are unlinked?");
+}
+
+ATF_TC_BODY(exit_tmpfile, tc)
+{
+ int sta, fd = -1;
+ char buf[12];
+ pid_t pid;
+ FILE *f;
+
+ (void)strlcpy(buf, "exit.XXXXXX", sizeof(buf));
+
+ pid = fork();
+ ATF_REQUIRE(pid >= 0);
+
+ if (pid == 0) {
+
+ fd = mkstemp(buf);
+
+ if (fd < 0)
+ exit(EXIT_FAILURE);
+
+ exit(EXIT_SUCCESS);
+ }
+
+ (void)wait(&sta);
+
+ if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS)
+ atf_tc_fail("failed to create temporary file");
+
+ f = fdopen(fd, "r");
+
+ if (f != NULL)
+ atf_tc_fail("exit(3) did not clear temporary file");
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, exit_atexit);
+ ATF_TP_ADD_TC(tp, exit_basic);
+ ATF_TP_ADD_TC(tp, exit_status);
+ ATF_TP_ADD_TC(tp, exit_tmpfile);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_getenv.c b/contrib/netbsd-tests/lib/libc/stdlib/t_getenv.c
new file mode 100644
index 0000000..5a8fa28
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_getenv.c
@@ -0,0 +1,211 @@
+/* $NetBSD: t_getenv.c,v 1.2 2011/07/15 13:54:31 jruoho Exp $ */
+
+/*-
+ * Copyright (c) 2010 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas
+ *
+ * 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 COPYRIGHT HOLDERS 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
+ * COPYRIGHT HOLDERS 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.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_getenv.c,v 1.2 2011/07/15 13:54:31 jruoho Exp $");
+
+#include <atf-c.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef __FreeBSD__
+#include <signal.h>
+#endif
+
+extern char **environ;
+
+ATF_TC(clearenv_basic);
+ATF_TC_HEAD(clearenv_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test user clearing environment directly");
+}
+
+ATF_TC_BODY(clearenv_basic, tc)
+{
+ char name[1024], value[1024];
+
+ for (size_t i = 0; i < 1024; i++) {
+ snprintf(name, sizeof(name), "crap%zu", i);
+ snprintf(value, sizeof(value), "%zu", i);
+ ATF_CHECK(setenv(name, value, 1) != -1);
+ }
+
+ *environ = NULL;
+
+ for (size_t i = 0; i < 1; i++) {
+ snprintf(name, sizeof(name), "crap%zu", i);
+ snprintf(value, sizeof(value), "%zu", i);
+ ATF_CHECK(setenv(name, value, 1) != -1);
+ }
+
+ ATF_CHECK_STREQ(getenv("crap0"), "0");
+ ATF_CHECK(getenv("crap1") == NULL);
+ ATF_CHECK(getenv("crap2") == NULL);
+}
+
+ATF_TC(getenv_basic);
+ATF_TC_HEAD(getenv_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test setenv(3), getenv(3)");
+}
+
+ATF_TC_BODY(getenv_basic, tc)
+{
+ ATF_CHECK(setenv("EVIL", "very=bad", 1) != -1);
+ ATF_CHECK_STREQ(getenv("EVIL"), "very=bad");
+ ATF_CHECK(getenv("EVIL=very") == NULL);
+ ATF_CHECK(unsetenv("EVIL") != -1);
+}
+
+ATF_TC(putenv_basic);
+ATF_TC_HEAD(putenv_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test putenv(3), getenv(3), unsetenv(3)");
+}
+
+
+ATF_TC_BODY(putenv_basic, tc)
+{
+ char string[1024];
+
+ snprintf(string, sizeof(string), "crap=true");
+ ATF_CHECK(putenv(string) != -1);
+ ATF_CHECK_STREQ(getenv("crap"), "true");
+ string[1] = 'l';
+ ATF_CHECK_STREQ(getenv("clap"), "true");
+ ATF_CHECK(getenv("crap") == NULL);
+ string[1] = 'r';
+ ATF_CHECK(unsetenv("crap") != -1);
+ ATF_CHECK(getenv("crap") == NULL);
+
+ ATF_CHECK_ERRNO(EINVAL, putenv(NULL) == -1);
+ ATF_CHECK_ERRNO(EINVAL, putenv(__UNCONST("val")) == -1);
+ ATF_CHECK_ERRNO(EINVAL, putenv(__UNCONST("=val")) == -1);
+}
+
+ATF_TC(setenv_basic);
+ATF_TC_HEAD(setenv_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test setenv(3), getenv(3), unsetenv(3)");
+ atf_tc_set_md_var(tc, "timeout", "300");
+}
+
+ATF_TC_BODY(setenv_basic, tc)
+{
+ const size_t numvars = 8192;
+ size_t i, offset;
+ char name[1024];
+ char value[1024];
+
+ offset = lrand48();
+ for (i = 0; i < numvars; i++) {
+ (void)snprintf(name, sizeof(name), "var%zu",
+ (i * 7 + offset) % numvars);
+ (void)snprintf(value, sizeof(value), "value%ld", lrand48());
+ ATF_CHECK(setenv(name, value, 1) != -1);
+ ATF_CHECK(setenv(name, "foo", 0) != -1);
+ ATF_CHECK_STREQ(getenv(name), value);
+ }
+
+ offset = lrand48();
+ for (i = 0; i < numvars; i++) {
+ (void)snprintf(name, sizeof(name), "var%zu",
+ (i * 11 + offset) % numvars);
+ ATF_CHECK(unsetenv(name) != -1);
+ ATF_CHECK(getenv(name) == NULL);
+ ATF_CHECK(unsetenv(name) != -1);
+ }
+
+ ATF_CHECK_ERRNO(EINVAL, setenv(NULL, "val", 1) == -1);
+ ATF_CHECK_ERRNO(EINVAL, setenv("", "val", 1) == -1);
+ ATF_CHECK_ERRNO(EINVAL, setenv("v=r", "val", 1) == -1);
+#ifdef __FreeBSD__
+ /*
+ Both FreeBSD and OS/X does not validate the second
+ argument to setenv(3)
+ */
+ atf_tc_expect_signal(SIGSEGV, "FreeBSD does not validate the second "
+ "argument to setenv(3); see bin/189805");
+#endif
+
+ ATF_CHECK_ERRNO(EINVAL, setenv("var", NULL, 1) == -1);
+
+ ATF_CHECK(setenv("var", "=val", 1) == 0);
+ ATF_CHECK_STREQ(getenv("var"), "=val");
+}
+
+ATF_TC(setenv_mixed);
+ATF_TC_HEAD(setenv_mixed, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test mixing setenv(3), unsetenv(3) and putenv(3)");
+}
+
+ATF_TC_BODY(setenv_mixed, tc)
+{
+ char string[32];
+
+ (void)strcpy(string, "mixedcrap=putenv");
+
+ ATF_CHECK(setenv("mixedcrap", "setenv", 1) != -1);
+ ATF_CHECK_STREQ(getenv("mixedcrap"), "setenv");
+ ATF_CHECK(putenv(string) != -1);
+ ATF_CHECK_STREQ(getenv("mixedcrap"), "putenv");
+ ATF_CHECK(unsetenv("mixedcrap") != -1);
+ ATF_CHECK(getenv("mixedcrap") == NULL);
+
+ ATF_CHECK(putenv(string) != -1);
+ ATF_CHECK_STREQ(getenv("mixedcrap"), "putenv");
+ ATF_CHECK(setenv("mixedcrap", "setenv", 1) != -1);
+ ATF_CHECK_STREQ(getenv("mixedcrap"), "setenv");
+ ATF_CHECK(unsetenv("mixedcrap") != -1);
+ ATF_CHECK(getenv("mixedcrap") == NULL);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, clearenv_basic);
+ ATF_TP_ADD_TC(tp, getenv_basic);
+ ATF_TP_ADD_TC(tp, putenv_basic);
+ ATF_TP_ADD_TC(tp, setenv_basic);
+ ATF_TP_ADD_TC(tp, setenv_mixed);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_getenv_thread.c b/contrib/netbsd-tests/lib/libc/stdlib/t_getenv_thread.c
new file mode 100644
index 0000000..d935629
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_getenv_thread.c
@@ -0,0 +1,250 @@
+/* $NetBSD: t_getenv_thread.c,v 1.2 2012/03/15 02:02:23 joerg Exp $ */
+
+/*-
+ * Copyright (c) 2010 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Matthias Scheler.
+ *
+ * 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.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_getenv_thread.c,v 1.2 2012/03/15 02:02:23 joerg Exp $");
+
+#include <atf-c.h>
+#include <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#define THREADED_NUM_THREADS 8
+#define THREADED_NUM_VARS 16
+#define THREADED_VAR_NAME "THREADED%zu"
+#define THREADED_RUN_TIME 10
+
+static void *thread_getenv_r(void *);
+static void *thread_putenv(void *);
+static void *thread_setenv(void *);
+static void *thread_unsetenv(void *);
+
+static void *
+thread_getenv_r(void *arg)
+{
+ time_t endtime;
+
+ endtime = *(time_t *)arg;
+ do {
+ size_t i;
+ char name[32], value[128];
+
+ i = lrand48() % THREADED_NUM_VARS;
+ (void)snprintf(name, sizeof(name), THREADED_VAR_NAME, i);
+
+ if (getenv_r(name, value, sizeof(value)) == -1) {
+ ATF_CHECK(errno == ENOENT);
+ }
+ } while (time(NULL) < endtime);
+
+ return NULL;
+}
+
+
+static void *
+thread_putenv(void *arg)
+{
+ time_t endtime;
+ size_t i;
+ static char vars[THREADED_NUM_VARS][128];
+
+ for (i = 0; i < THREADED_NUM_VARS; i++) {
+ (void)snprintf(vars[i], sizeof(vars[i]),
+ THREADED_VAR_NAME "=putenv %ld", i, lrand48());
+ }
+
+ endtime = *(time_t *)arg;
+ do {
+ char name[128];
+
+ i = lrand48() % THREADED_NUM_VARS;
+ (void)strlcpy(name, vars[i], sizeof(name));
+ *strchr(name, '=') = '\0';
+
+ ATF_CHECK(unsetenv(name) != -1);
+ ATF_CHECK(putenv(vars[i]) != -1);
+ } while (time(NULL) < endtime);
+
+ return NULL;
+}
+
+static void *
+thread_setenv(void *arg)
+{
+ time_t endtime;
+
+ endtime = *(time_t *)arg;
+ do {
+ size_t i;
+ char name[32], value[64];
+
+ i = lrand48() % THREADED_NUM_VARS;
+ (void)snprintf(name, sizeof(name), THREADED_VAR_NAME, i);
+ (void)snprintf(value, sizeof(value), "setenv %ld", lrand48());
+
+ ATF_CHECK(setenv(name, value, 1) != -1);
+ } while (time(NULL) < endtime);
+
+ return NULL;
+}
+
+static void *
+thread_unsetenv(void *arg)
+{
+ time_t endtime;
+
+ endtime = *(time_t *)arg;
+ do {
+ size_t i;
+ char name[32];
+
+ i = lrand48() % THREADED_NUM_VARS;
+ (void)snprintf(name, sizeof(name), THREADED_VAR_NAME, i);
+
+ ATF_CHECK(unsetenv(name) != -1);
+ } while (time(NULL) < endtime);
+
+ return NULL;
+}
+
+ATF_TC(getenv_r_thread);
+ATF_TC_HEAD(getenv_r_thread, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Test getenv_r(3) with threads");
+ atf_tc_set_md_var(tc, "timeout", "%d", THREADED_RUN_TIME + 5);
+}
+
+ATF_TC_BODY(getenv_r_thread, tc)
+{
+ pthread_t threads[THREADED_NUM_THREADS];
+ time_t endtime;
+ size_t i, j;
+
+ endtime = time(NULL) + THREADED_RUN_TIME;
+
+ for (i = j = 0; j < 2; j++) {
+
+ ATF_CHECK(pthread_create(&threads[i++], NULL, thread_getenv_r,
+ &endtime) == 0);
+ }
+
+ for (j = 0; j < i; j++)
+ ATF_CHECK(pthread_join(threads[j], NULL) == 0);
+}
+
+ATF_TC(putenv_thread);
+ATF_TC_HEAD(putenv_thread, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test concurrent access by putenv(3)");
+ atf_tc_set_md_var(tc, "timeout", "%d", THREADED_RUN_TIME + 5);
+}
+
+ATF_TC_BODY(putenv_thread, tc)
+{
+ pthread_t threads[THREADED_NUM_THREADS];
+ time_t endtime;
+ size_t i, j;
+
+ endtime = time(NULL) + THREADED_RUN_TIME;
+
+ for (i = j = 0; j < 2; j++) {
+
+ ATF_CHECK(pthread_create(&threads[i++], NULL, thread_putenv,
+ &endtime) == 0);
+ }
+
+ for (j = 0; j < i; j++)
+ ATF_CHECK(pthread_join(threads[j], NULL) == 0);
+}
+
+ATF_TC(setenv_thread);
+ATF_TC_HEAD(setenv_thread, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test concurrent access by setenv(3)");
+ atf_tc_set_md_var(tc, "timeout", "%d", THREADED_RUN_TIME + 5);
+}
+
+ATF_TC_BODY(setenv_thread, tc)
+{
+ pthread_t threads[THREADED_NUM_THREADS];
+ time_t endtime;
+ size_t i, j;
+
+ endtime = time(NULL) + THREADED_RUN_TIME;
+
+ for (i = j = 0; j < 2; j++) {
+
+ ATF_CHECK(pthread_create(&threads[i++], NULL, thread_setenv,
+ &endtime) == 0);
+ }
+
+ for (j = 0; j < i; j++)
+ ATF_CHECK(pthread_join(threads[j], NULL) == 0);
+}
+
+ATF_TC(unsetenv_thread);
+ATF_TC_HEAD(unsetenv_thread, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test unsetenv(3) with threads");
+ atf_tc_set_md_var(tc, "timeout", "%d", THREADED_RUN_TIME + 5);
+}
+
+ATF_TC_BODY(unsetenv_thread, tc)
+{
+ pthread_t threads[THREADED_NUM_THREADS];
+ time_t endtime;
+ size_t i, j;
+
+ endtime = time(NULL) + THREADED_RUN_TIME;
+
+ for (i = j = 0; j < 2; j++) {
+
+ ATF_CHECK(pthread_create(&threads[i++], NULL, thread_unsetenv,
+ &endtime) == 0);
+ }
+
+ for (j = 0; j < i; j++)
+ ATF_CHECK(pthread_join(threads[j], NULL) == 0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, getenv_r_thread);
+ ATF_TP_ADD_TC(tp, putenv_thread);
+ ATF_TP_ADD_TC(tp, setenv_thread);
+ ATF_TP_ADD_TC(tp, unsetenv_thread);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_getopt.sh b/contrib/netbsd-tests/lib/libc/stdlib/t_getopt.sh
new file mode 100755
index 0000000..cc10f65
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_getopt.sh
@@ -0,0 +1,123 @@
+# $NetBSD: t_getopt.sh,v 1.1 2011/01/01 23:56:49 pgoyette Exp $
+#
+# Copyright (c) 2008 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# 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.
+#
+
+h_getopt()
+{
+ atf_check -e save:stderr -x "$(atf_get_srcdir)/h_getopt" <<EOF
+load: $1
+args: $2
+result: $3
+EOF
+ cat stderr
+ rm -f stderr
+}
+
+h_getopt_long()
+{
+ atf_check -e save:stderr -x "$(atf_get_srcdir)/h_getopt_long" <<EOF
+$1
+args: $2
+result: $3
+EOF
+ cat stderr
+ rm -f stderr
+}
+
+atf_test_case getopt
+getopt_head()
+{
+ atf_set "descr" "Checks getopt(3)"
+}
+getopt_body()
+{
+ load="c:d"
+
+ h_getopt "${load}" "foo -c 1 -d foo" "c=1,d|1"
+ h_getopt "${load}" "foo -d foo bar" "d|2"
+ h_getopt "${load}" "foo -c 2 foo bar" "c=2|2"
+ h_getopt "${load}" "foo -e 1 foo bar" "!?|3"
+ h_getopt "${load}" "foo -d -- -c 1" "d|2"
+ h_getopt "${load}" "foo -c- 1" "c=-|1"
+ h_getopt "${load}" "foo -d - 1" "d|2"
+}
+
+atf_test_case getopt_long
+getopt_long_head()
+{
+ atf_set "descr" "Checks getopt_long(3)"
+}
+getopt_long_body()
+{
+ # GNU libc tests with these
+ load="optstring: abc:
+longopts: 5
+longopt: required, required_argument, , 'r'
+longopt: optional, optional_argument, , 'o'
+longopt: none, no_argument, , 'n'
+longopt: color, no_argument, , 'C'
+longopt: colour, no_argument, , 'C'"
+
+ h_getopt_long "${load}" "foo --req foobar" "-required=foobar|0"
+ h_getopt_long "${load}" "foo --opt=bazbug" "-optional=bazbug|0"
+
+ # This is problematic
+ #
+ # GNU libc 2.1.3 this fails with ambiguous result
+ # h_getopt_long "${load}" "foo --col" "!?|0"
+ #
+ # GNU libc 2.2 >= this works
+ h_getopt_long "${load}" "foo --col" "-color|0"
+
+ h_getopt_long "${load}" "foo --colour" "-colour|0"
+
+ # This is the real GNU libc test!
+ args="foo -a -b -cfoobar --required foobar --optional=bazbug --none random --col --color --colour"
+ # GNU libc 2.1.3 this fails with ambiguous
+ #result="a,b,c=foobar,-required=foobar,-optional=bazbug,-none,!?,-color,-colour|1"
+ #
+ # GNU libc 2.2 >= this works
+ result="a,b,c=foobar,-required=foobar,-optional=bazbug,-none,-color,-color,-colour|1"
+ h_getopt_long "${load}" "${args}" "${result}"
+
+ #
+ # The order of long options in the long option array should not matter.
+ # An exact match should never be treated as ambiguous.
+ #
+ load="optstring: fgl
+longopts: 3
+longopt: list-foobar, no_argument, lopt, 'f'
+longopt: list-goobar, no_argument, lopt, 'g'
+longopt: list, no_argument, lopt, 'l'"
+ h_getopt_long "${load}" "foo --list" "-list|0"
+}
+
+
+atf_init_test_cases()
+{
+ atf_add_test_case getopt
+ atf_add_test_case getopt_long
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_hsearch.c b/contrib/netbsd-tests/lib/libc/stdlib/t_hsearch.c
new file mode 100644
index 0000000..a0e77d3
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_hsearch.c
@@ -0,0 +1,411 @@
+/* $NetBSD: t_hsearch.c,v 1.4 2014/07/20 20:17:21 christos Exp $ */
+
+/*-
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ */
+
+/*
+ * Copyright (c) 2001 Christopher G. Demetriou
+ * All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed for the
+ * NetBSD Project. See http://www.NetBSD.org/ for
+ * information about NetBSD.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
+ */
+
+#include <sys/cdefs.h>
+__COPYRIGHT("@(#) Copyright (c) 2008\
+ The NetBSD Foundation, inc. All rights reserved.");
+__RCSID("$NetBSD: t_hsearch.c,v 1.4 2014/07/20 20:17:21 christos Exp $");
+
+#include <errno.h>
+#include <search.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <atf-c.h>
+
+#define REQUIRE_ERRNO(x) ATF_REQUIRE_MSG(x, "%s", strerror(errno))
+
+#ifdef __NetBSD__
+ATF_TC(hsearch_basic);
+ATF_TC_HEAD(hsearch_basic, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Checks basic insertions and searching");
+}
+
+ATF_TC_BODY(hsearch_basic, tc)
+{
+ ENTRY e, *ep;
+ char ch[2];
+ int i;
+
+ REQUIRE_ERRNO(hcreate(16) != 0);
+
+ /* ch[1] should be constant from here on down. */
+ ch[1] = '\0';
+
+ /* Basic insertions. Check enough that there'll be collisions. */
+ for (i = 0; i < 26; i++) {
+ ch[0] = 'a' + i;
+ e.key = strdup(ch); /* ptr to provided key is kept! */
+ ATF_REQUIRE(e.key != NULL);
+ e.data = (void *)(intptr_t)i;
+
+ ep = hsearch(e, ENTER);
+
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, ch);
+ ATF_REQUIRE_EQ((intptr_t)ep->data, i);
+ }
+
+ /* e.key should be constant from here on down. */
+ e.key = ch;
+
+ /* Basic lookups. */
+ for (i = 0; i < 26; i++) {
+ ch[0] = 'a' + i;
+
+ ep = hsearch(e, FIND);
+
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, ch);
+ ATF_REQUIRE_EQ((intptr_t)ep->data, i);
+ }
+
+ hdestroy1(free, NULL);
+}
+#endif
+
+ATF_TC(hsearch_duplicate);
+ATF_TC_HEAD(hsearch_duplicate, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Checks that inserting duplicate "
+ "doesn't overwrite existing data");
+}
+
+ATF_TC_BODY(hsearch_duplicate, tc)
+{
+ ENTRY e, *ep;
+
+ REQUIRE_ERRNO(hcreate(16));
+
+ e.key = __UNCONST("a");
+ e.data = (void *)(intptr_t) 0;
+
+ ep = hsearch(e, ENTER);
+
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, "a");
+ ATF_REQUIRE_EQ((intptr_t)ep->data, 0);
+
+ e.data = (void *)(intptr_t)12345;
+
+ ep = hsearch(e, ENTER);
+ ep = hsearch(e, FIND);
+
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, "a");
+ ATF_REQUIRE_EQ((intptr_t)ep->data, 0);
+
+ hdestroy();
+}
+
+ATF_TC(hsearch_nonexistent);
+ATF_TC_HEAD(hsearch_nonexistent, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr",
+ "Checks searching for non-existent entry");
+}
+
+ATF_TC_BODY(hsearch_nonexistent, tc)
+{
+ ENTRY e, *ep;
+
+ REQUIRE_ERRNO(hcreate(16));
+
+ e.key = __UNCONST("A");
+ ep = hsearch(e, FIND);
+ ATF_REQUIRE_EQ(ep, NULL);
+
+ hdestroy();
+}
+
+ATF_TC(hsearch_two);
+ATF_TC_HEAD(hsearch_two, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr",
+ "Checks that searching doesn't overwrite previous search results");
+}
+
+ATF_TC_BODY(hsearch_two, tc)
+{
+ ENTRY e, *ep, *ep2;
+
+ REQUIRE_ERRNO(hcreate(16));
+
+ e.key = __UNCONST("a");
+ e.data = (void*)(intptr_t)0;
+
+ ep = hsearch(e, ENTER);
+
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, "a");
+ ATF_REQUIRE_EQ((intptr_t)ep->data, 0);
+
+ e.key = __UNCONST("b");
+ e.data = (void*)(intptr_t)1;
+
+ ep = hsearch(e, ENTER);
+
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, "b");
+ ATF_REQUIRE_EQ((intptr_t)ep->data, 1);
+
+ e.key = __UNCONST("a");
+ ep = hsearch(e, FIND);
+
+ e.key = __UNCONST("b");
+ ep2 = hsearch(e, FIND);
+
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, "a");
+ ATF_REQUIRE_EQ((intptr_t)ep->data, 0);
+
+ ATF_REQUIRE(ep2 != NULL);
+ ATF_REQUIRE_STREQ(ep2->key, "b");
+ ATF_REQUIRE_EQ((intptr_t)ep2->data, 1);
+
+ hdestroy();
+}
+
+#if defined(__FreeBSD__) && 1100027 <= __FreeBSD_version
+#ifdef __NetBSD__
+ATF_TC(hsearch_r_basic);
+ATF_TC_HEAD(hsearch_r_basic, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Checks basic insertions and searching");
+}
+
+ATF_TC_BODY(hsearch_r_basic, tc)
+{
+ ENTRY e, *ep;
+ char ch[2];
+ int i;
+ struct hsearch_data t;
+
+ REQUIRE_ERRNO(hcreate_r(16, &t) != 0);
+
+ /* ch[1] should be constant from here on down. */
+ ch[1] = '\0';
+
+ /* Basic insertions. Check enough that there'll be collisions. */
+ for (i = 0; i < 26; i++) {
+ ch[0] = 'a' + i;
+ e.key = strdup(ch); /* ptr to provided key is kept! */
+ ATF_REQUIRE(e.key != NULL);
+ e.data = (void *)(intptr_t)i;
+
+ ATF_REQUIRE(hsearch_r(e, ENTER, &ep, &t) == 1);
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, ch);
+ ATF_REQUIRE_EQ((intptr_t)ep->data, i);
+ }
+
+ /* e.key should be constant from here on down. */
+ e.key = ch;
+
+ /* Basic lookups. */
+ for (i = 0; i < 26; i++) {
+ ch[0] = 'a' + i;
+
+ ATF_REQUIRE(hsearch_r(e, FIND, &ep, &t) == 1);
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, ch);
+ ATF_REQUIRE_EQ((intptr_t)ep->data, i);
+ }
+
+ hdestroy1_r(&t, free, NULL);
+}
+#endif
+
+ATF_TC(hsearch_r_duplicate);
+ATF_TC_HEAD(hsearch_r_duplicate, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Checks that inserting duplicate "
+ "doesn't overwrite existing data");
+}
+
+ATF_TC_BODY(hsearch_r_duplicate, tc)
+{
+ ENTRY e, *ep;
+ struct hsearch_data t;
+
+ REQUIRE_ERRNO(hcreate_r(16, &t));
+
+ e.key = __UNCONST("a");
+ e.data = (void *)(intptr_t) 0;
+
+ ATF_REQUIRE(hsearch_r(e, ENTER, &ep, &t) == 1);
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, "a");
+ ATF_REQUIRE_EQ((intptr_t)ep->data, 0);
+
+ e.data = (void *)(intptr_t)12345;
+
+ ATF_REQUIRE(hsearch_r(e, ENTER, &ep, &t) == 1);
+ ATF_REQUIRE(hsearch_r(e, FIND, &ep, &t) == 1);
+
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, "a");
+ ATF_REQUIRE_EQ((intptr_t)ep->data, 0);
+
+ hdestroy_r(&t);
+}
+
+ATF_TC(hsearch_r_nonexistent);
+ATF_TC_HEAD(hsearch_r_nonexistent, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr",
+ "Checks searching for non-existent entry");
+}
+
+ATF_TC_BODY(hsearch_r_nonexistent, tc)
+{
+ ENTRY e, *ep;
+ struct hsearch_data t;
+
+ REQUIRE_ERRNO(hcreate_r(16, &t));
+
+ e.key = __UNCONST("A");
+ ATF_REQUIRE(hsearch_r(e, FIND, &ep, &t) == 1);
+ ATF_REQUIRE_EQ(ep, NULL);
+
+ hdestroy_r(&t);
+}
+
+ATF_TC(hsearch_r_two);
+ATF_TC_HEAD(hsearch_r_two, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr",
+ "Checks that searching doesn't overwrite previous search results");
+}
+
+ATF_TC_BODY(hsearch_r_two, tc)
+{
+ ENTRY e, *ep, *ep2;
+ struct hsearch_data t;
+
+ REQUIRE_ERRNO(hcreate_r(16, &t));
+
+ e.key = __UNCONST("a");
+ e.data = (void*)(intptr_t)0;
+
+ ATF_REQUIRE(hsearch_r(e, ENTER, &ep, &t) == 1);
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, "a");
+ ATF_REQUIRE_EQ((intptr_t)ep->data, 0);
+
+ e.key = __UNCONST("b");
+ e.data = (void*)(intptr_t)1;
+
+ ATF_REQUIRE(hsearch_r(e, ENTER, &ep, &t) == 1);
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, "b");
+ ATF_REQUIRE_EQ((intptr_t)ep->data, 1);
+
+ e.key = __UNCONST("a");
+ ATF_REQUIRE(hsearch_r(e, FIND, &ep, &t) == 1);
+
+ e.key = __UNCONST("b");
+ ATF_REQUIRE(hsearch_r(e, FIND, &ep2, &t) == 1);
+
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, "a");
+ ATF_REQUIRE_EQ((intptr_t)ep->data, 0);
+
+ ATF_REQUIRE(ep2 != NULL);
+ ATF_REQUIRE_STREQ(ep2->key, "b");
+ ATF_REQUIRE_EQ((intptr_t)ep2->data, 1);
+
+ hdestroy_r(&t);
+}
+#endif
+
+ATF_TP_ADD_TCS(tp)
+{
+
+#ifdef __NetBSD__
+ ATF_TP_ADD_TC(tp, hsearch_basic);
+#endif
+ ATF_TP_ADD_TC(tp, hsearch_duplicate);
+ ATF_TP_ADD_TC(tp, hsearch_nonexistent);
+ ATF_TP_ADD_TC(tp, hsearch_two);
+
+#if defined(__FreeBSD__) && 1100027 <= __FreeBSD_version
+#ifdef __NetBSD__
+ ATF_TP_ADD_TC(tp, hsearch_r_basic);
+#endif
+ ATF_TP_ADD_TC(tp, hsearch_r_duplicate);
+ ATF_TP_ADD_TC(tp, hsearch_r_nonexistent);
+ ATF_TP_ADD_TC(tp, hsearch_r_two);
+#endif
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_mi_vector_hash.c b/contrib/netbsd-tests/lib/libc/stdlib/t_mi_vector_hash.c
new file mode 100644
index 0000000..77d6443
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_mi_vector_hash.c
@@ -0,0 +1,95 @@
+/* $NetBSD: t_mi_vector_hash.c,v 1.3 2011/07/07 11:12:18 jruoho Exp $ */
+/*-
+ * Copyright (c) 2009 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Joerg Sonnenberger.
+ *
+ * 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 COPYRIGHT HOLDERS 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
+ * COPYRIGHT HOLDERS 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.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_mi_vector_hash.c,v 1.3 2011/07/07 11:12:18 jruoho Exp $");
+
+#include <atf-c.h>
+#include <stdlib.h>
+#include <string.h>
+
+ATF_TC(mi_vector_hash_basic);
+ATF_TC_HEAD(mi_vector_hash_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test mi_vector_hash_vector_hash for consistent results");
+}
+
+static const struct testvector {
+ const char *vector;
+ uint32_t hashes[3];
+} testv[] = {
+ { "hello, world", { 0xd38f7f21, 0xbf6be9ab, 0x37a0e989 } },
+ { "", { 0x9b2ec03d, 0xdb2b69ae, 0xbd49d10d } },
+ { "a", { 0x9454baa3, 0xb711c708, 0x29eec818 } },
+ { "ab", { 0x9a5dca90, 0xdd212644, 0x9879ac41 } },
+ { "abc", { 0x0b91c470, 0x4770cdf5, 0x251e4793 } },
+ { "abcd", { 0x5f128df3, 0xf5a667a6, 0x5ae61fa5 } },
+ { "abcde", { 0x4cbae281, 0x799c0ed5, 0x03a96866 } },
+ { "abcdef", { 0x507a54c8, 0xb6bd06f4, 0xde922732 } },
+ { "abcdefg", { 0xae2bca5d, 0x61e960ef, 0xb9e6762c } },
+ { "abcdefgh", { 0xd1021264, 0x87f6988f, 0x053f775e } },
+ { "abcdefghi", { 0xe380defc, 0xfc35a811, 0x3a7b0a5f } },
+ { "abcdefghij", { 0x9a504408, 0x70d2e89d, 0xc9cac242 } },
+ { "abcdefghijk", { 0x376117d0, 0x89f434d4, 0xe52b8e4c } },
+ { "abcdefghijkl", { 0x92253599, 0x7b6ff99e, 0x0b1b3ea5 } },
+ { "abcdefghijklm", { 0x92ee6a52, 0x55587d47, 0x3122b031 } },
+ { "abcdefghijklmn", { 0x827baf08, 0x1d0ada73, 0xfec330e0 } },
+ { "abcdefghijklmno", { 0x06ab787d, 0xc1ad17c2, 0x11dccf31 } },
+ { "abcdefghijklmnop", { 0x2cf18103, 0x638c9268, 0xfa1ecf51 } },
+};
+
+ATF_TC_BODY(mi_vector_hash_basic, tc)
+{
+ size_t i, j, len;
+ uint32_t hashes[3];
+ char buf[256];
+
+ for (j = 0; j < 8; ++j) {
+ for (i = 0; i < sizeof(testv) / sizeof(testv[0]); ++i) {
+ len = strlen(testv[i].vector);
+ strcpy(buf + j, testv[i].vector);
+ mi_vector_hash(buf + j, len, 0, hashes);
+ ATF_CHECK_EQ(hashes[0], testv[i].hashes[0]);
+ ATF_CHECK_EQ(hashes[1], testv[i].hashes[1]);
+ ATF_CHECK_EQ(hashes[2], testv[i].hashes[2]);
+ }
+ }
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, mi_vector_hash_basic);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_posix_memalign.c b/contrib/netbsd-tests/lib/libc/stdlib/t_posix_memalign.c
new file mode 100644
index 0000000..47afb84
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_posix_memalign.c
@@ -0,0 +1,88 @@
+/* $NetBSD: t_posix_memalign.c,v 1.2 2011/07/07 11:12:18 jruoho Exp $ */
+
+/*-
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__COPYRIGHT("@(#) Copyright (c) 2008\
+ The NetBSD Foundation, inc. All rights reserved.");
+__RCSID("$NetBSD: t_posix_memalign.c,v 1.2 2011/07/07 11:12:18 jruoho Exp $");
+
+#include <atf-c.h>
+
+#include <errno.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+ATF_TC(posix_memalign_basic);
+ATF_TC_HEAD(posix_memalign_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks posix_memalign(3)");
+}
+ATF_TC_BODY(posix_memalign_basic, tc)
+{
+ size_t size[] = {
+ 1, 2, 3, 4, 10, 100, 16384, 32768, 65536
+ };
+ size_t align[] = {
+ 512, 1024, 16, 32, 64, 4, 2048, 16, 2
+ };
+
+ size_t i;
+ void *p;
+
+ for (i = 0; i < __arraycount(size); i++) {
+ int ret;
+ p = (void*)0x1;
+
+ (void)printf("Checking posix_memalign(&p, %zd, %zd)...\n",
+ align[i], size[i]);
+ ret = posix_memalign(&p, align[i], size[i]);
+
+ if ( align[i] < sizeof(void *))
+ ATF_REQUIRE_EQ_MSG(ret, EINVAL,
+ "posix_memalign: %s", strerror(ret));
+ else {
+ ATF_REQUIRE_EQ_MSG(ret, 0,
+ "posix_memalign: %s", strerror(ret));
+ ATF_REQUIRE_EQ_MSG(((intptr_t)p) & (align[i] - 1), 0,
+ "p = %p", p);
+ free(p);
+ }
+ }
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, posix_memalign_basic);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_random.c b/contrib/netbsd-tests/lib/libc/stdlib/t_random.c
new file mode 100644
index 0000000..9a6d21e
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_random.c
@@ -0,0 +1,82 @@
+/* $NetBSD: t_random.c,v 1.3 2012/03/29 08:56:06 jruoho Exp $ */
+
+/*-
+ * Copyright (c) 2012 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.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_random.c,v 1.3 2012/03/29 08:56:06 jruoho Exp $");
+
+#include <atf-c.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+/*
+ * TODO: Add some general RNG tests (cf. the famous "diehard" tests?).
+ */
+
+ATF_TC(random_same);
+ATF_TC_HEAD(random_same, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that random(3) does not always return the same "
+ "value when the seed is initialized to zero");
+}
+
+#define MAX_ITER 10
+
+ATF_TC_BODY(random_same, tc)
+{
+ long buf[MAX_ITER];
+ size_t i, j;
+
+ /*
+ * See CVE-2012-1577.
+ */
+ srandom(0);
+
+ for (i = 0; i < __arraycount(buf); i++) {
+
+ buf[i] = random();
+
+ for (j = 0; j < i; j++) {
+
+ (void)fprintf(stderr, "i = %zu, j = %zu: "
+ "%ld vs. %ld\n", i, j, buf[i], buf[j]);
+
+ ATF_CHECK(buf[i] != buf[j]);
+ }
+ }
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, random_same);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_strtod.c b/contrib/netbsd-tests/lib/libc/stdlib/t_strtod.c
new file mode 100644
index 0000000..8f0f899
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_strtod.c
@@ -0,0 +1,342 @@
+/* $NetBSD: t_strtod.c,v 1.32 2014/11/04 00:20:19 justin Exp $ */
+
+/*-
+ * Copyright (c) 2011 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.
+ */
+
+/* Public domain, Otto Moerbeek <otto@drijf.net>, 2006. */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_strtod.c,v 1.32 2014/11/04 00:20:19 justin Exp $");
+
+#include <errno.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <atf-c.h>
+
+#if defined(__i386__) || defined(__amd64__) || defined(__sparc__)
+#include <fenv.h>
+#endif
+
+#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
+
+#ifdef __FreeBSD__
+#define __HAVE_LONG_DOUBLE
+#endif
+
+ATF_TC(strtod_basic);
+ATF_TC_HEAD(strtod_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A basic test of strtod(3)");
+}
+
+ATF_TC_BODY(strtod_basic, tc)
+{
+ static const size_t n = 1024 * 1000;
+
+ for (size_t i = 1; i < n; i = i + 1024) {
+ char buf[512];
+ (void)snprintf(buf, sizeof(buf), "%zu.%zu", i, i + 1);
+
+ errno = 0;
+ double d = strtod(buf, NULL);
+
+ ATF_REQUIRE(d > 0.0);
+ ATF_REQUIRE(errno == 0);
+ }
+}
+
+ATF_TC(strtod_hex);
+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;
+ char *end;
+ volatile double d;
+
+ str = "-0x0";
+ d = strtod(str, &end); /* -0.0 */
+
+ ATF_REQUIRE(end == str + 4);
+ ATF_REQUIRE(signbit(d) != 0);
+ ATF_REQUIRE(fabs(d) < SMALL_NUM);
+
+ 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_TC(strtod_inf);
+ATF_TC_HEAD(strtod_inf, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A strtod(3) with INF (PR lib/33262)");
+}
+
+ATF_TC_BODY(strtod_inf, tc)
+{
+#ifndef __vax__
+ for (size_t i = 0; i < __arraycount(inf_strings); i++) {
+ volatile double d = strtod(inf_strings[i], NULL);
+ ATF_REQUIRE(isinf(d) != 0);
+ }
+#else
+ atf_tc_skip("vax not supported");
+#endif
+}
+
+ATF_TC(strtof_inf);
+ATF_TC_HEAD(strtof_inf, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A strtof(3) with INF (PR lib/33262)");
+}
+
+ATF_TC_BODY(strtof_inf, tc)
+{
+#ifndef __vax__
+ for (size_t i = 0; i < __arraycount(inf_strings); i++) {
+ volatile float f = strtof(inf_strings[i], NULL);
+ ATF_REQUIRE(isinf(f) != 0);
+ }
+#else
+ atf_tc_skip("vax not supported");
+#endif
+}
+
+ATF_TC(strtold_inf);
+ATF_TC_HEAD(strtold_inf, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A strtold(3) with INF (PR lib/33262)");
+}
+
+ATF_TC_BODY(strtold_inf, tc)
+{
+#ifndef __vax__
+# ifdef __HAVE_LONG_DOUBLE
+
+ for (size_t i = 0; i < __arraycount(inf_strings); i++) {
+ volatile long double ld = strtold(inf_strings[i], NULL);
+ ATF_REQUIRE(isinf(ld) != 0);
+ }
+# else
+ atf_tc_skip("Requires long double support");
+# endif
+#else
+ atf_tc_skip("vax not supported");
+#endif
+}
+
+ATF_TC(strtod_nan);
+ATF_TC_HEAD(strtod_nan, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A strtod(3) with NaN");
+}
+
+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_skip("vax not supported");
+#endif
+}
+
+ATF_TC(strtof_nan);
+ATF_TC_HEAD(strtof_nan, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A strtof(3) with NaN");
+}
+
+ATF_TC_BODY(strtof_nan, tc)
+{
+#ifndef __vax__
+ char *end;
+
+ volatile float f = strtof(nan_string, &end);
+ ATF_REQUIRE(isnanf(f) != 0);
+ ATF_REQUIRE(strcmp(end, "y") == 0);
+#else
+ atf_tc_skip("vax not supported");
+#endif
+}
+
+ATF_TC(strtold_nan);
+ATF_TC_HEAD(strtold_nan, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A strtold(3) with NaN (PR lib/45020)");
+}
+
+ATF_TC_BODY(strtold_nan, tc)
+{
+#ifndef __vax__
+# ifdef __HAVE_LONG_DOUBLE
+
+ char *end;
+
+ volatile long double ld = strtold(nan_string, &end);
+ ATF_REQUIRE(isnan(ld) != 0);
+#ifdef __FreeBSD__
+ ATF_REQUIRE(strcmp(end, "y") == 0);
+#else
+ ATF_REQUIRE(__isnanl(ld) != 0);
+#endif
+ ATF_REQUIRE(strcmp(end, "y") == 0);
+# else
+ atf_tc_skip("Requires long double support");
+# endif
+#else
+ atf_tc_skip("vax not supported");
+#endif
+}
+
+ATF_TC(strtod_round);
+ATF_TC_HEAD(strtod_round, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test rouding in strtod(3)");
+}
+
+ATF_TC_BODY(strtod_round, tc)
+{
+#if defined(__i386__) || defined(__amd64__) || defined(__sparc__)
+
+ /*
+ * Test that strtod(3) honors the current rounding mode.
+ * The used value is somewhere near 1 + DBL_EPSILON + FLT_EPSILON.
+ */
+ const char *val =
+ "1.00000011920928977282585492503130808472633361816406";
+
+ (void)fesetround(FE_UPWARD);
+
+ volatile double d1 = strtod(val, NULL);
+
+ (void)fesetround(FE_DOWNWARD);
+
+ volatile double d2 = strtod(val, NULL);
+
+ if (fabs(d1 - d2) > 0.0)
+ return;
+ else {
+ atf_tc_expect_fail("PR misc/44767");
+ atf_tc_fail("strtod(3) did not honor fesetround(3)");
+ }
+#else
+ atf_tc_skip("Requires one of i386, amd64 or sparc");
+#endif
+}
+
+ATF_TC(strtod_underflow);
+ATF_TC_HEAD(strtod_underflow, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test underflow in strtod(3)");
+}
+
+ATF_TC_BODY(strtod_underflow, tc)
+{
+
+ const char *tmp =
+ "0.0000000000000000000000000000000000000000000000000000"
+ "000000000000000000000000000000000000000000000000000000"
+ "000000000000000000000000000000000000000000000000000000"
+ "000000000000000000000000000000000000000000000000000000"
+ "000000000000000000000000000000000000000000000000000000"
+ "000000000000000000000000000000000000000000000000000000"
+ "000000000000000000000000000000000000000000000000000000"
+ "000000000000000002";
+
+ errno = 0;
+ volatile double d = strtod(tmp, NULL);
+
+ if (d != 0 || errno != ERANGE)
+ atf_tc_fail("strtod(3) did not detect underflow");
+}
+
+/*
+ * Bug found by Geza Herman.
+ * See
+ * http://www.exploringbinary.com/a-bug-in-the-bigcomp-function-of-david-gays-strtod/
+ */
+ATF_TC(strtod_gherman_bug);
+ATF_TC_HEAD(strtod_gherman_bug, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test a bug found by Geza Herman");
+}
+
+ATF_TC_BODY(strtod_gherman_bug, tc)
+{
+
+ const char *str =
+ "1.8254370818746402660437411213933955878019332885742187";
+
+ errno = 0;
+ volatile double d = strtod(str, NULL);
+
+ ATF_CHECK(d == 0x1.d34fd8378ea83p+0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, strtod_basic);
+ ATF_TP_ADD_TC(tp, strtod_hex);
+ ATF_TP_ADD_TC(tp, strtod_inf);
+ ATF_TP_ADD_TC(tp, strtof_inf);
+ ATF_TP_ADD_TC(tp, strtold_inf);
+ ATF_TP_ADD_TC(tp, strtod_nan);
+ ATF_TP_ADD_TC(tp, strtof_nan);
+ ATF_TP_ADD_TC(tp, strtold_nan);
+ ATF_TP_ADD_TC(tp, strtod_round);
+ ATF_TP_ADD_TC(tp, strtod_underflow);
+ ATF_TP_ADD_TC(tp, strtod_gherman_bug);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_strtol.c b/contrib/netbsd-tests/lib/libc/stdlib/t_strtol.c
new file mode 100644
index 0000000..5a0c6d0
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_strtol.c
@@ -0,0 +1,234 @@
+/* $NetBSD: t_strtol.c,v 1.5 2011/06/14 02:45:58 jruoho Exp $ */
+
+/*-
+ * Copyright (c) 2011 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.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_strtol.c,v 1.5 2011/06/14 02:45:58 jruoho Exp $");
+
+#include <atf-c.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+
+struct test {
+ const char *str;
+ int64_t res;
+ int base;
+ 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)
+{
+
+ if (li != -1 && li != t->res)
+ atf_tc_fail_nonfatal("strtol(%s, &end, %d) failed "
+ "(rv = %ld)", t->str, t->base, li);
+
+ if (lli != -1 && lli != t->res)
+ atf_tc_fail_nonfatal("strtoll(%s, NULL, %d) failed "
+ "(rv = %lld)", t->str, t->base, lli);
+
+ if (t->end != NULL && strcmp(t->end, end) != 0)
+ atf_tc_fail_nonfatal("invalid end pointer ('%s') from "
+ "strtol(%s, &end, %d)", end, t->str, t->base);
+}
+
+ATF_TC(strtol_base);
+ATF_TC_HEAD(strtol_base, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test strtol(3) with different bases");
+}
+
+ATF_TC_BODY(strtol_base, tc)
+{
+ struct test t[] = {
+ { "123456789", 123456789, 0, NULL },
+ { "111010110111100110100010101", 123456789, 2, NULL },
+ { "22121022020212200", 123456789, 3, NULL },
+ { "13112330310111", 123456789, 4, NULL },
+ { "223101104124", 123456789, 5, NULL },
+ { "20130035113", 123456789, 6, NULL },
+ { "3026236221", 123456789, 7, NULL },
+ { "726746425", 123456789, 8, NULL },
+ { "277266780", 123456789, 9, NULL },
+ { "123456789", 123456789, 10, NULL },
+ { "63762A05", 123456789, 11, NULL },
+ { "35418A99", 123456789, 12, NULL },
+ { "1C767471", 123456789, 13, NULL },
+ { "12579781", 123456789, 14, NULL },
+ { "AC89BC9", 123456789, 15, NULL },
+ { "75BCD15", 123456789, 16, NULL },
+ { "123456789", 342391, 8, NULL },
+ { "0123456789", 342391, 0, NULL },
+ { "0123456789", 123456789, 10, NULL },
+ { "0x75bcd15", 123456789, 0, NULL },
+ };
+
+ long long int lli;
+ long int li;
+ char *end;
+ size_t i;
+
+ for (i = 0; i < __arraycount(t); i++) {
+
+ li = strtol(t[i].str, &end, t[i].base);
+ lli = strtoll(t[i].str, NULL, t[i].base);
+
+ check(&t[i], li, lli, end);
+ }
+}
+
+ATF_TC(strtol_case);
+ATF_TC_HEAD(strtol_case, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Case insensitivity with strtol(3)");
+}
+
+ATF_TC_BODY(strtol_case, tc)
+{
+ struct test t[] = {
+ { "abcd", 0xabcd, 16, NULL },
+ { " dcba", 0xdcba, 16, NULL },
+ { "abcd dcba", 0xabcd, 16, " dcba" },
+ { "abc0x123", 0xabc0, 16, NULL },
+ { "abcd\0x123", 0xabcd, 16, "\0x123" },
+ { "ABCD", 0xabcd, 16, NULL },
+ { "aBcD", 0xabcd, 16, NULL },
+ { "0xABCD", 0xabcd, 16, NULL },
+ { "0xABCDX", 0xabcd, 16, "X" },
+ };
+
+ long long int lli;
+ long int li;
+ char *end;
+ size_t i;
+
+ for (i = 0; i < __arraycount(t); i++) {
+
+ li = strtol(t[i].str, &end, t[i].base);
+ lli = strtoll(t[i].str, NULL, t[i].base);
+
+ check(&t[i], li, lli, end);
+ }
+}
+
+ATF_TC(strtol_range);
+ATF_TC_HEAD(strtol_range, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test ERANGE from strtol(3)");
+}
+
+ATF_TC_BODY(strtol_range, tc)
+{
+
+#if LONG_MAX == 0x7fffffff /* XXX: Is this portable? */
+
+ struct test t[] = {
+ { "20000000000", 2147483647, 8, NULL },
+ { "2147483648", 2147483647, 10, NULL },
+ { "80000000", 2147483647, 16, NULL },
+ };
+#else
+ struct test t[] = {
+ { "1000000000000000000000", 9223372036854775807, 8, NULL },
+ { "9223372036854775808", 9223372036854775807, 10, NULL },
+ { "8000000000000000", 9223372036854775807, 16, NULL },
+ };
+#endif
+
+ long int li;
+ char *end;
+ size_t i;
+
+ for (i = 0; i < __arraycount(t); i++) {
+
+ errno = 0;
+ li = strtol(t[i].str, &end, t[i].base);
+
+ if (errno != ERANGE)
+ atf_tc_fail("strtol(3) did not catch ERANGE");
+
+ check(&t[i], li, -1, end);
+ }
+}
+
+ATF_TC(strtol_signed);
+ATF_TC_HEAD(strtol_signed, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A basic test of strtol(3)");
+}
+
+ATF_TC_BODY(strtol_signed, tc)
+{
+ struct test t[] = {
+ { "1", 1, 0, NULL },
+ { " 2", 2, 0, NULL },
+ { " 3", 3, 0, NULL },
+ { " -3", -3, 0, NULL },
+ { "--1", 0, 0, "--1" },
+ { "+-2", 0, 0, "+-2" },
+ { "++3", 0, 0, "++3" },
+ { "+9", 9, 0, NULL },
+ { "+123", 123, 0, NULL },
+ { "-1 3", -1, 0, " 3" },
+ { "-1.3", -1, 0, ".3" },
+ { "- 3", 0, 0, "- 3" },
+ { "+33.", 33, 0, "." },
+ { "30x0", 30, 0, "x0" },
+ };
+
+ long long int lli;
+ long int li;
+ char *end;
+ size_t i;
+
+ for (i = 0; i < __arraycount(t); i++) {
+
+ li = strtol(t[i].str, &end, t[i].base);
+ lli = strtoll(t[i].str, NULL, t[i].base);
+
+ check(&t[i], li, lli, end);
+ }
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, strtol_base);
+ ATF_TP_ADD_TC(tp, strtol_case);
+ ATF_TP_ADD_TC(tp, strtol_range);
+ ATF_TP_ADD_TC(tp, strtol_signed);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_system.c b/contrib/netbsd-tests/lib/libc/stdlib/t_system.c
new file mode 100644
index 0000000..235005b
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_system.c
@@ -0,0 +1,83 @@
+/* $NetBSD: t_system.c,v 1.1 2011/09/11 10:32:23 jruoho Exp $ */
+
+/*-
+ * Copyright (c) 2011 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.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_system.c,v 1.1 2011/09/11 10:32:23 jruoho Exp $");
+
+#include <atf-c.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static const char *path = "system";
+
+ATF_TC_WITH_CLEANUP(system_basic);
+ATF_TC_HEAD(system_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A basic test of system(3)");
+}
+
+ATF_TC_BODY(system_basic, tc)
+{
+ char buf[23];
+ int fd, i = 2;
+
+ ATF_REQUIRE(system("/bin/echo -n > system") == 0);
+
+ while (i >= 0) {
+ ATF_REQUIRE(system("/bin/echo -n garbage >> system") == 0);
+ i--;
+ }
+
+ fd = open(path, O_RDONLY);
+ ATF_REQUIRE(fd >= 0);
+
+ (void)memset(buf, '\0', sizeof(buf));
+
+ ATF_REQUIRE(read(fd, buf, 21) == 21);
+ ATF_REQUIRE(strcmp(buf, "garbagegarbagegarbage") == 0);
+
+ ATF_REQUIRE(close(fd) == 0);
+ ATF_REQUIRE(unlink(path) == 0);
+}
+
+ATF_TC_CLEANUP(system_basic, tc)
+{
+ (void)unlink(path);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, system_basic);
+
+ return atf_no_error();
+}
OpenPOWER on IntegriCloud