Source-Changes-HG archive

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

[src/trunk]: src/tests/lib/libc/rpc Add a test for the rpc getaddr bug lib/13...



details:   https://anonhg.NetBSD.org/src/rev/189b8814957f
branches:  trunk
changeset: 785142:189b8814957f
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Feb 26 17:06:55 2013 +0000

description:
Add a test for the rpc getaddr bug lib/13082.
Timeout added, but it needs rpcbind to be running to succeed.

diffstat:

 tests/lib/libc/rpc/Makefile |    4 +-
 tests/lib/libc/rpc/t_rpc.c  |  143 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 146 insertions(+), 1 deletions(-)

diffs (165 lines):

diff -r 517b888049eb -r 189b8814957f tests/lib/libc/rpc/Makefile
--- a/tests/lib/libc/rpc/Makefile       Tue Feb 26 16:33:57 2013 +0000
+++ b/tests/lib/libc/rpc/Makefile       Tue Feb 26 17:06:55 2013 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1 2011/01/08 06:59:37 pgoyette Exp $
+# $NetBSD: Makefile,v 1.2 2013/02/26 17:06:55 christos Exp $
 
 MKMAN= no
 
@@ -9,6 +9,8 @@
 TESTS_C=               t_xdr
 SRCS.t_xdr=            ${RPCSRCS:.x=_xdr.c} t_xdr.c
 
+TESTS_C+=              t_rpc
+
 RPCSRCS=               h_testbits.x
 DPSRCS=                        ${RPCSRCS:.x=.h}
 CLEANFILES+=   ${RPCSRCS:.x=.h} ${RPCSRCS:.x=_xdr.c}
diff -r 517b888049eb -r 189b8814957f tests/lib/libc/rpc/t_rpc.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/rpc/t_rpc.c        Tue Feb 26 17:06:55 2013 +0000
@@ -0,0 +1,143 @@
+/*     $NetBSD: t_rpc.c,v 1.1 2013/02/26 17:06:55 christos Exp $       */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_rpc.c,v 1.1 2013/02/26 17:06:55 christos Exp $");
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <rpc/rpc.h>
+#include <stdlib.h>
+#include <err.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <unistd.h>
+
+
+#ifndef TEST
+#include <atf-c.h>
+
+#define ERRX(ev, msg, ...)     ATF_REQUIRE_MSG(0, msg, __VA_ARGS__)
+#else
+#define ERRX(ev, msg, ...)     errx(ev, msg, __VA_ARGS__)
+#endif
+
+
+#define RPCBPROC_NULL 0
+
+static int
+reply(caddr_t replyp, struct netbuf * raddrp, struct netconfig * nconf)
+{
+       char host[NI_MAXHOST];
+       struct sockaddr *sock = raddrp->buf;
+       int error;
+
+
+       error = getnameinfo(sock, sock->sa_len, host, sizeof(host), NULL, 0, 0);
+       if (error)
+               warnx("Cannot resolve address (%s)", gai_strerror(error));
+       else
+               printf("response from: %s\n", host);
+       return 0;
+}
+
+static void
+onehost(const char *host, const char *transp)
+{
+       CLIENT         *clnt;
+       struct netbuf   addr;
+       struct timeval  tv;
+
+
+       if ((clnt = clnt_create(host, RPCBPROG, RPCBVERS, transp)) == NULL)
+               ERRX(EXIT_FAILURE, "clnt_create (%s)", clnt_spcreateerror(""));
+
+       tv.tv_sec = 1;
+       tv.tv_usec = 0;
+       if (clnt_call(clnt, RPCBPROC_NULL, xdr_void, NULL, xdr_void, NULL, tv)
+           != RPC_SUCCESS)
+               ERRX(EXIT_FAILURE, "clnt_call (%s)", clnt_sperror(clnt, ""));
+       clnt_control(clnt, CLGET_SVC_ADDR, (char *) &addr);
+       reply(NULL, &addr, NULL);
+}
+
+#ifdef TEST
+static void
+allhosts(void)
+{
+       enum clnt_stat  clnt_stat;
+
+       clnt_stat = rpc_broadcast(RPCBPROG, RPCBVERS, RPCBPROC_NULL,
+           (xdrproc_t)xdr_void, NULL, (xdrproc_t)xdr_void,
+           NULL, (resultproc_t)reply, transp);
+       if (clnt_stat != RPC_SUCCESS && clnt_stat != RPC_TIMEDOUT)
+               ERRX(EXIT_FAILURE, "%s", clnt_sperrno(clnt_stat));
+}
+
+int
+main(int argc, char *argv[])
+{
+       int             ch;
+       const char     *transp = "udp";
+
+
+       while ((ch = getopt(argc, argv, "ut")) != -1)
+               switch (ch) {
+               case 't':
+                       transp = "tcp";
+                       break;
+               case 'u':
+                       transp = "udp";
+                       break;
+               default:
+                       fprintf(stderr, "Usage: %s -[t|u] [<hostname>...]\n",
+                           getprogname());
+                       return EXIT_FAILURE;
+               }
+
+       if (argc == optind)
+               allhosts();
+       else
+               for (; optind < argc; optind++)
+                       onehost(argv[optind], transp);
+
+       return EXIT_SUCCESS;
+}
+
+#else
+
+ATF_TC(get_svc_addr_tcp);
+ATF_TC_HEAD(get_svc_addr_tcp, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Checks CLGET_SVC_ADDR for tcp");
+       atf_tc_set_md_var(tc, "timeout", "1");
+
+}
+
+ATF_TC_BODY(get_svc_addr_tcp, tc)
+{
+       onehost("localhost", "tcp");
+
+}
+
+ATF_TC(get_svc_addr_udp);
+ATF_TC_HEAD(get_svc_addr_udp, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Checks CLGET_SVC_ADDR for udp");
+       atf_tc_set_md_var(tc, "timeout", "1");
+}
+
+ATF_TC_BODY(get_svc_addr_udp, tc)
+{
+       onehost("localhost", "udp");
+
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+       ATF_TP_ADD_TC(tp, get_svc_addr_udp);
+       ATF_TP_ADD_TC(tp, get_svc_addr_tcp);
+
+       return atf_no_error();
+}
+
+#endif



Home | Main Index | Thread Index | Old Index