Module Name:    src
Committed By:   pgoyette
Date:           Sat Jan  1 23:56:49 UTC 2011

Modified Files:
        src/distrib/sets/lists/tests: mi
        src/tests/lib/libc/stdlib: Makefile
Added Files:
        src/tests/lib/libc/stdlib: h_getopt.c h_getopt_long.c t_getopt.sh
            t_posix_memalign.c

Log Message:
Convert a few more tests from regress to atf


To generate a diff of this commit:
cvs rdiff -u -r1.200 -r1.201 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libc/stdlib/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/stdlib/h_getopt.c \
    src/tests/lib/libc/stdlib/h_getopt_long.c \
    src/tests/lib/libc/stdlib/t_getopt.sh \
    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/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.200 src/distrib/sets/lists/tests/mi:1.201
--- src/distrib/sets/lists/tests/mi:1.200	Fri Dec 31 18:20:32 2010
+++ src/distrib/sets/lists/tests/mi	Sat Jan  1 23:56:48 2011
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.200 2010/12/31 18:20:32 pooka Exp $
+# $NetBSD: mi,v 1.201 2011/01/01 23:56:48 pgoyette Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -356,10 +356,13 @@
 ./usr/libdata/debug/usr/tests/lib/libc/stdio/t_format.debug		tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/stdio/t_popen.debug		tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/stdlib				tests-lib-debug
+./usr/libdata/debug/usr/tests/lib/libc/stdlib/h_getopt.debug		tests-lib-debug		debug,atf
+./usr/libdata/debug/usr/tests/lib/libc/stdlib/h_getoptlong.debug	tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_div.debug		tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_environment.debug	tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_environment_pth.debug	tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_mi_vector_hash.debug	tests-lib-debug		debug,atf
+./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_posix_memalign.debug	tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_strtox.debug		tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/string				tests-lib-debug
 ./usr/libdata/debug/usr/tests/lib/libc/string/t_memcpy.debug		tests-lib-debug		debug,atf
@@ -1596,10 +1599,14 @@
 ./usr/tests/lib/libc/hash/t_sha2		tests-lib-tests		atf
 ./usr/tests/lib/libc/stdlib			tests-lib-tests
 ./usr/tests/lib/libc/stdlib/Atffile		tests-lib-tests		atf
+./usr/tests/lib/libc/stdlib/h_getopt		tests-lib-tests		atf
+./usr/tests/lib/libc/stdlib/h_getoptlong	tests-lib-tests		atf
 ./usr/tests/lib/libc/stdlib/t_div		tests-lib-tests		atf
 ./usr/tests/lib/libc/stdlib/t_environment	tests-lib-tests		atf
 ./usr/tests/lib/libc/stdlib/t_environment_pth	tests-lib-tests		atf
+./usr/tests/lib/libc/stdlib/t_getopt		tests-lib-tests		atf
 ./usr/tests/lib/libc/stdlib/t_mi_vector_hash	tests-lib-tests		atf
+./usr/tests/lib/libc/stdlib/t_posix_memalign	tests-lib-tests		atf
 ./usr/tests/lib/libc/stdlib/t_strtox		tests-lib-tests		atf
 ./usr/tests/lib/libc/setjmp			tests-lib-tests
 ./usr/tests/lib/libc/setjmp/Atffile		tests-lib-tests		atf

Index: src/tests/lib/libc/stdlib/Makefile
diff -u src/tests/lib/libc/stdlib/Makefile:1.6 src/tests/lib/libc/stdlib/Makefile:1.7
--- src/tests/lib/libc/stdlib/Makefile:1.6	Thu Dec 23 15:27:44 2010
+++ src/tests/lib/libc/stdlib/Makefile	Sat Jan  1 23:56:49 2011
@@ -1,12 +1,24 @@
-# $NetBSD: Makefile,v 1.6 2010/12/23 15:27:44 pgoyette Exp $
+# $NetBSD: Makefile,v 1.7 2011/01/01 23:56:49 pgoyette Exp $
 
 .include <bsd.own.mk>
 
 TESTSDIR=	${TESTSBASE}/lib/libc/stdlib
 
-TESTS_C+=	t_div t_mi_vector_hash t_environment t_environment_pth
+TESTS_C+=	t_div
+TESTS_C+=	t_environment
+TESTS_C+=	t_environment_pth
+TESTS_C+=	t_mi_vector_hash
+TESTS_C+=	t_posix_memalign
 TESTS_C+=	t_strtox
 
+TESTS_SH+=	t_getopt        
+
+MKMAN=no
+
+BINDIR=		${TESTSDIR}
+
+PROGS+=		h_getopt h_getopt_long
+
 LDADD.t_environment_pth=	-pthread
 
 .include <bsd.test.mk>

Added files:

Index: src/tests/lib/libc/stdlib/h_getopt.c
diff -u /dev/null src/tests/lib/libc/stdlib/h_getopt.c:1.1
--- /dev/null	Sat Jan  1 23:56:49 2011
+++ src/tests/lib/libc/stdlib/h_getopt.c	Sat Jan  1 23:56:49 2011
@@ -0,0 +1,127 @@
+/*	$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>
+
+#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;
+}
Index: src/tests/lib/libc/stdlib/h_getopt_long.c
diff -u /dev/null src/tests/lib/libc/stdlib/h_getopt_long.c:1.1
--- /dev/null	Sat Jan  1 23:56:49 2011
+++ src/tests/lib/libc/stdlib/h_getopt_long.c	Sat Jan  1 23:56:49 2011
@@ -0,0 +1,239 @@
+/*	$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>
+
+#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;
+}
Index: src/tests/lib/libc/stdlib/t_getopt.sh
diff -u /dev/null src/tests/lib/libc/stdlib/t_getopt.sh:1.1
--- /dev/null	Sat Jan  1 23:56:49 2011
+++ src/tests/lib/libc/stdlib/t_getopt.sh	Sat Jan  1 23:56:49 2011
@@ -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
+}
Index: src/tests/lib/libc/stdlib/t_posix_memalign.c
diff -u /dev/null src/tests/lib/libc/stdlib/t_posix_memalign.c:1.1
--- /dev/null	Sat Jan  1 23:56:49 2011
+++ src/tests/lib/libc/stdlib/t_posix_memalign.c	Sat Jan  1 23:56:49 2011
@@ -0,0 +1,88 @@
+/*	$NetBSD: t_posix_memalign.c,v 1.1 2011/01/01 23:56:49 pgoyette 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.1 2011/01/01 23:56:49 pgoyette Exp $");
+
+#include <atf-c.h>
+
+#include <errno.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+ATF_TC(posix_memalign);
+ATF_TC_HEAD(posix_memalign, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Checks posix_memalign(3)");
+}
+ATF_TC_BODY(posix_memalign, 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);
+
+	return atf_no_error();
+}

Reply via email to