Module Name: src Committed By: pgoyette Date: Wed Jan 12 17:32:27 UTC 2011
Modified Files: src/tests/lib/libc: Makefile src/tests/lib/libc/net: Makefile Added Files: src/tests/lib/libc/net: h_protoent.c h_servent.c t_protoent.sh t_servent.sh Removed Files: src/tests/lib/libc: h_protoent.c h_servent.c t_protoent.sh t_servent.sh Log Message: Move the servent and protoent tests to src/tests/lib/libc/net/ (where they should have gone initially). To generate a diff of this commit: cvs rdiff -u -r1.29 -r1.30 src/tests/lib/libc/Makefile cvs rdiff -u -r1.1 -r0 src/tests/lib/libc/h_protoent.c \ src/tests/lib/libc/h_servent.c src/tests/lib/libc/t_servent.sh cvs rdiff -u -r1.2 -r0 src/tests/lib/libc/t_protoent.sh cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/net/Makefile cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/net/h_protoent.c \ src/tests/lib/libc/net/h_servent.c src/tests/lib/libc/net/t_protoent.sh \ src/tests/lib/libc/net/t_servent.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/lib/libc/Makefile diff -u src/tests/lib/libc/Makefile:1.29 src/tests/lib/libc/Makefile:1.30 --- src/tests/lib/libc/Makefile:1.29 Wed Jan 12 02:58:40 2011 +++ src/tests/lib/libc/Makefile Wed Jan 12 17:32:27 2011 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.29 2011/01/12 02:58:40 pgoyette Exp $ +# $NetBSD: Makefile,v 1.30 2011/01/12 17:32:27 pgoyette Exp $ .include <bsd.own.mk> .include <bsd.sys.mk> @@ -26,16 +26,12 @@ TESTS_SH+= t_atexit TESTS_SH+= t_nsdispatch -TESTS_SH+= t_protoent -TESTS_SH+= t_servent BINDIR= ${TESTSDIR} MKMAN= no PROGS+= h_atexit PROGS+= h_nsd_recurse -PROGS+= h_protoent -PROGS+= h_servent LDADD.h_nsd_recurse+= -lpthread LDADD.t_mktime+= -lpthread Index: src/tests/lib/libc/net/Makefile diff -u src/tests/lib/libc/net/Makefile:1.1 src/tests/lib/libc/net/Makefile:1.2 --- src/tests/lib/libc/net/Makefile:1.1 Wed Jan 12 02:58:40 2011 +++ src/tests/lib/libc/net/Makefile Wed Jan 12 17:32:27 2011 @@ -1,9 +1,19 @@ -# $NetBSD: Makefile,v 1.1 2011/01/12 02:58:40 pgoyette Exp $ +# $NetBSD: Makefile,v 1.2 2011/01/12 17:32:27 pgoyette Exp $ .include <bsd.own.mk> +MKMAN= no + TESTS_SUBDIRS+= getaddrinfo TESTSDIR= ${TESTSBASE}/lib/libc/net +TESTS_SH+= t_protoent +TESTS_SH+= t_servent + +BINDIR= ${TESTSDIR} + +PROGS+= h_protoent +PROGS+= h_servent + .include <bsd.test.mk> Added files: Index: src/tests/lib/libc/net/h_protoent.c diff -u /dev/null src/tests/lib/libc/net/h_protoent.c:1.1 --- /dev/null Wed Jan 12 17:32:27 2011 +++ src/tests/lib/libc/net/h_protoent.c Wed Jan 12 17:32:27 2011 @@ -0,0 +1,100 @@ +/* $NetBSD: h_protoent.c,v 1.1 2011/01/12 17:32:27 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; +} Index: src/tests/lib/libc/net/h_servent.c diff -u /dev/null src/tests/lib/libc/net/h_servent.c:1.1 --- /dev/null Wed Jan 12 17:32:27 2011 +++ src/tests/lib/libc/net/h_servent.c Wed Jan 12 17:32:27 2011 @@ -0,0 +1,103 @@ +/* $NetBSD: h_servent.c,v 1.1 2011/01/12 17:32:27 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; +} Index: src/tests/lib/libc/net/t_protoent.sh diff -u /dev/null src/tests/lib/libc/net/t_protoent.sh:1.1 --- /dev/null Wed Jan 12 17:32:27 2011 +++ src/tests/lib/libc/net/t_protoent.sh Wed Jan 12 17:32:27 2011 @@ -0,0 +1,92 @@ +# $NetBSD: t_protoent.sh,v 1.1 2011/01/12 17:32:27 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. +# + +atf_test_case protoent +protoent_head() +{ + atf_set "descr" "Checks {get,set,end}protoent(3)" +} +protoent_body() +{ + # + # Munge original to: + # (1) match output format of the test program + # (2) fold all names for the same port/proto together + # (3) prune duplicates + # + tr '\t' ' ' </etc/protocols | awk ' + function add(key, name, i, n, ar) { + n = split(names[key], ar); + for (i=1; i<=n; i++) { + if (name == ar[i]) { + return; + } + } + delete ar; + names[key] = names[key] " " name; + } + + { + sub("#.*", "", $0); + gsub(" *", " ", $0); + if (NF==0) { + next; + } + add($2, $1, 0); + for (i=3; i<=NF; i++) { + add($2, $i, 1); + } + } + END { + for (key in names) { + proto = key; + + n = split(names[key], ar); + printf "name=%s, proto=%s, aliases=", ar[1], proto; + for (i=2; i<=n; i++) { + if (i>2) { + printf " "; + } + printf "%s", ar[i]; + } + printf "\n"; + delete ar; + } + } + ' | sort >exp + + # run test program + "$(atf_get_srcdir)/h_protoent" | sed 's/ *$//' | sort >out + + diff -u exp out || \ + atf_fail "Observed output does not match reference output" +} + +atf_init_test_cases() +{ + atf_add_test_case protoent +} Index: src/tests/lib/libc/net/t_servent.sh diff -u /dev/null src/tests/lib/libc/net/t_servent.sh:1.1 --- /dev/null Wed Jan 12 17:32:27 2011 +++ src/tests/lib/libc/net/t_servent.sh Wed Jan 12 17:32:27 2011 @@ -0,0 +1,93 @@ +# $NetBSD: t_servent.sh,v 1.1 2011/01/12 17:32:27 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. +# + +atf_test_case servent +servent_head() +{ + atf_set "descr" "Checks {get,set,end}servent(3)" +} +servent_body() +{ + # + # Munge original to: + # (1) match output format of the test program + # (2) fold all names for the same port/proto together + # (3) prune duplicates + # + tr '\t' ' ' </etc/services | awk ' + function add(key, name, i, n, ar) { + n = split(names[key], ar); + for (i=1; i<=n; i++) { + if (name == ar[i]) { + return; + } + } + delete ar; + names[key] = names[key] " " name; + } + + { + sub("#.*", "", $0); + gsub(" *", " ", $0); + if (NF==0) { + next; + } + add($2, $1, 0); + for (i=3; i<=NF; i++) { + add($2, $i, 1); + } + } + END { + for (key in names) { + portproto = key; + sub("/", ", proto=", portproto); + portproto = "port=" portproto; + + n = split(names[key], ar); + printf "name=%s, %s, aliases=", ar[1], portproto; + for (i=2; i<=n; i++) { + if (i>2) { + printf " "; + } + printf "%s", ar[i]; + } + printf "\n"; + delete ar; + } + } + ' | sort >exp + + # run test program + "$(atf_get_srcdir)/h_servent" | sed 's/ *$//' | sort >out + + diff -u exp out || atf_fail "Observed output does not match reference output" +} + +atf_init_test_cases() +{ + atf_add_test_case servent +}