Source-Changes-HG archive

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

[src/trunk]: src/tests/lib/libc Atf-ify servent and protoent tests, and the r...



details:   https://anonhg.NetBSD.org/src/rev/96c3e4283a5d
branches:  trunk
changeset: 760336:96c3e4283a5d
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Sun Jan 02 22:03:25 2011 +0000

description:
Atf-ify servent and protoent tests, and the remaining hash test.

diffstat:

 tests/lib/libc/Makefile                |   11 +-
 tests/lib/libc/h_protoent.c            |  100 +++++++++++++++++++
 tests/lib/libc/h_servent.c             |  103 ++++++++++++++++++++
 tests/lib/libc/hash/Makefile           |   17 +++-
 tests/lib/libc/hash/data/md5test-in    |    7 +
 tests/lib/libc/hash/data/md5test-out   |    7 +
 tests/lib/libc/hash/data/sha1test-in   |    2 +
 tests/lib/libc/hash/data/sha1test-out  |    2 +
 tests/lib/libc/hash/data/sha1test2-out |    1 +
 tests/lib/libc/hash/h_hash.c           |  167 +++++++++++++++++++++++++++++++++
 tests/lib/libc/hash/t_hash.sh          |   67 +++++++++++++
 tests/lib/libc/t_protoent.sh           |   93 ++++++++++++++++++
 tests/lib/libc/t_servent.sh            |   93 ++++++++++++++++++
 13 files changed, 668 insertions(+), 2 deletions(-)

diffs (truncated from 738 to 300 lines):

diff -r f8566b08cbdc -r 96c3e4283a5d tests/lib/libc/Makefile
--- a/tests/lib/libc/Makefile   Sun Jan 02 22:03:24 2011 +0000
+++ b/tests/lib/libc/Makefile   Sun Jan 02 22:03:25 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.16 2011/01/02 03:51:20 pgoyette Exp $
+# $NetBSD: Makefile,v 1.17 2011/01/02 22:03:25 pgoyette Exp $
 
 .include <bsd.own.mk>
 .include <bsd.sys.mk>
@@ -25,4 +25,13 @@
 TESTS_C+=      t_randomid
 TESTS_C+=      t_strptime
 
+TESTS_SH+=     t_protoent
+TESTS_SH+=     t_servent
+
+BINDIR=                ${TESTSDIR}
+MKMAN=         no
+
+PROGS+=                h_protoent
+PROGS+=                h_servent
+
 .include <bsd.test.mk>
diff -r f8566b08cbdc -r 96c3e4283a5d tests/lib/libc/h_protoent.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/h_protoent.c       Sun Jan 02 22:03:25 2011 +0000
@@ -0,0 +1,100 @@
+/* $NetBSD: h_protoent.c,v 1.1 2011/01/02 22:03:25 pgoyette Exp $ */
+
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by 
+ *
+ * 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 <netdb.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <netinet/in.h>
+#include <sys/types.h>
+#include <stdio.h>
+
+static void
+pserv(const struct protoent *prp)
+{
+       char **pp;
+
+       printf("name=%s, proto=%d, aliases=",
+           prp->p_name, prp->p_proto);
+       for (pp = prp->p_aliases; *pp; pp++)
+               printf("%s ", *pp);
+       printf("\n");
+}
+
+static void
+usage(void)
+{
+       (void)fprintf(stderr, "Usage: %s\n"
+           "\t%s -p <proto>\n"
+           "\t%s -n <name>\n", getprogname(), getprogname(),
+           getprogname());
+       exit(1);
+}
+
+int
+main(int argc, char *argv[])
+{
+       struct protoent *prp;
+       const char *proto = NULL, *name = NULL;
+       int c;
+
+       while ((c = getopt(argc, argv, "p:n:")) != -1) {
+               switch (c) {
+               case 'n':
+                       name = optarg;
+                       break;
+               case 'p':
+                       proto = optarg;
+                       break;
+               default:
+                       usage();
+               }
+       }
+
+       if (proto && name)
+               usage();
+       if (proto) {
+               if ((prp = getprotobynumber(atoi(proto))) != NULL)
+                       pserv(prp);
+               return 0;
+       }
+       if (name) {
+               if ((prp = getprotobyname(name)) != NULL)
+                       pserv(prp);
+               return 0;
+       }
+
+       setprotoent(0);
+       while ((prp = getprotoent()) != NULL)
+               pserv(prp);
+       endprotoent();
+       return 0;
+}
diff -r f8566b08cbdc -r 96c3e4283a5d tests/lib/libc/h_servent.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/h_servent.c        Sun Jan 02 22:03:25 2011 +0000
@@ -0,0 +1,103 @@
+/* $NetBSD: h_servent.c,v 1.1 2011/01/02 22:03:25 pgoyette Exp $ */
+
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by 
+ *
+ * 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 <netdb.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <netinet/in.h>
+#include <sys/types.h>
+#include <stdio.h>
+
+static void
+pserv(const struct servent *svp)
+{
+       char **pp;
+
+       printf("name=%s, port=%d, proto=%s, aliases=",
+           svp->s_name, ntohs((uint16_t)svp->s_port), svp->s_proto);
+       for (pp = svp->s_aliases; *pp; pp++)
+               printf("%s ", *pp);
+       printf("\n");
+}
+
+static void
+usage(void)
+{
+       (void)fprintf(stderr, "Usage: %s\n"
+           "\t%s -p <port> [-P <proto>]\n"
+           "\t%s -n <name> [-P <proto>]\n", getprogname(), getprogname(),
+           getprogname());
+       exit(1);
+}
+
+int
+main(int argc, char *argv[])
+{
+       struct servent *svp;
+       const char *port = NULL, *proto = NULL, *name = NULL;
+       int c;
+
+       while ((c = getopt(argc, argv, "p:n:P:")) != -1) {
+               switch (c) {
+               case 'n':
+                       name = optarg;
+                       break;
+               case 'p':
+                       port = optarg;
+                       break;
+               case 'P':
+                       proto = optarg;
+                       break;
+               default:
+                       usage();
+               }
+       }
+
+       if (port && name)
+               usage();
+       if (port) {
+               if ((svp = getservbyport(htons(atoi(port)), proto)) != NULL)
+                       pserv(svp);
+               return 0;
+       }
+       if (name) {
+               if ((svp = getservbyname(name, proto)) != NULL)
+                       pserv(svp);
+               return 0;
+       }
+
+       setservent(0);
+       while ((svp = getservent()) != NULL)
+               pserv(svp);
+       endservent();
+       return 0;
+}
diff -r f8566b08cbdc -r 96c3e4283a5d tests/lib/libc/hash/Makefile
--- a/tests/lib/libc/hash/Makefile      Sun Jan 02 22:03:24 2011 +0000
+++ b/tests/lib/libc/hash/Makefile      Sun Jan 02 22:03:25 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1 2010/01/24 21:12:17 joerg Exp $
+# $NetBSD: Makefile,v 1.2 2011/01/02 22:03:25 pgoyette Exp $
 
 .include <bsd.own.mk>
 
@@ -6,4 +6,19 @@
 
 TESTS_C+=      t_sha2
 
+TESTS_SH+=     t_hash
+
+BINDIR=                ${TESTSDIR}
+MKMAN=         no
+
+PROGS+=                h_hash
+
+FILESDIR=      ${TESTSDIR}/data
+
+FILES+=                data/md5test-in
+FILES+=                data/md5test-out
+FILES+=                data/sha1test-in
+FILES+=                data/sha1test-out
+FILES+=                data/sha1test2-out
+
 .include <bsd.test.mk>
diff -r f8566b08cbdc -r 96c3e4283a5d tests/lib/libc/hash/data/md5test-in
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/hash/data/md5test-in       Sun Jan 02 22:03:25 2011 +0000
@@ -0,0 +1,7 @@
+
+a
+abc
+message digest
+abcdefghijklmnopqrstuvwxyz
+ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
+12345678901234567890123456789012345678901234567890123456789012345678901234567890
diff -r f8566b08cbdc -r 96c3e4283a5d tests/lib/libc/hash/data/md5test-out
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/hash/data/md5test-out      Sun Jan 02 22:03:25 2011 +0000
@@ -0,0 +1,7 @@
+d41d8cd98f00b204e9800998ecf8427e
+0cc175b9c0f1b6a831c399e269772661
+900150983cd24fb0d6963f7d28e17f72
+f96b697d7cb7938d525a2f31aaf161d0
+c3fcd3d76192e4007dfb496cca67e13b
+d174ab98d277d9f5a5611c2c9f419d9f
+57edf4a22be3c955ac49da2e2107b67a
diff -r f8566b08cbdc -r 96c3e4283a5d tests/lib/libc/hash/data/sha1test-in
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/hash/data/sha1test-in      Sun Jan 02 22:03:25 2011 +0000
@@ -0,0 +1,2 @@
+abc
+abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq
diff -r f8566b08cbdc -r 96c3e4283a5d tests/lib/libc/hash/data/sha1test-out
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/hash/data/sha1test-out     Sun Jan 02 22:03:25 2011 +0000
@@ -0,0 +1,2 @@
+a9993e364706816aba3e25717850c26c9cd0d89d
+84983e441c3bd26ebaae4aa1f95129e5e54670f1
diff -r f8566b08cbdc -r 96c3e4283a5d tests/lib/libc/hash/data/sha1test2-out
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/hash/data/sha1test2-out    Sun Jan 02 22:03:25 2011 +0000



Home | Main Index | Thread Index | Old Index