Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Convert a few more tests from regress to atf



details:   https://anonhg.NetBSD.org/src/rev/e25d558cea32
branches:  trunk
changeset: 760261:e25d558cea32
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Sat Jan 01 23:56:48 2011 +0000

description:
Convert a few more tests from regress to atf

diffstat:

 distrib/sets/lists/tests/mi              |    9 +-
 tests/lib/libc/stdlib/Makefile           |   16 +-
 tests/lib/libc/stdlib/h_getopt.c         |  127 ++++++++++++++++
 tests/lib/libc/stdlib/h_getopt_long.c    |  239 +++++++++++++++++++++++++++++++
 tests/lib/libc/stdlib/t_getopt.sh        |  123 +++++++++++++++
 tests/lib/libc/stdlib/t_posix_memalign.c |   88 +++++++++++
 6 files changed, 599 insertions(+), 3 deletions(-)

diffs (truncated from 661 to 300 lines):

diff -r dbc6c69289c0 -r e25d558cea32 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sat Jan 01 23:45:01 2011 +0000
+++ b/distrib/sets/lists/tests/mi       Sat Jan 01 23:56:48 2011 +0000
@@ -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
diff -r dbc6c69289c0 -r e25d558cea32 tests/lib/libc/stdlib/Makefile
--- a/tests/lib/libc/stdlib/Makefile    Sat Jan 01 23:45:01 2011 +0000
+++ b/tests/lib/libc/stdlib/Makefile    Sat Jan 01 23:56:48 2011 +0000
@@ -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>
diff -r dbc6c69289c0 -r e25d558cea32 tests/lib/libc/stdlib/h_getopt.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/stdlib/h_getopt.c  Sat Jan 01 23:56:48 2011 +0000
@@ -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;
+}
diff -r dbc6c69289c0 -r e25d558cea32 tests/lib/libc/stdlib/h_getopt_long.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/stdlib/h_getopt_long.c     Sat Jan 01 23:56:48 2011 +0000
@@ -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",



Home | Main Index | Thread Index | Old Index