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 more rpc tests. XXX: Need rpcbind run...



details:   https://anonhg.NetBSD.org/src/rev/732db8acd432
branches:  trunk
changeset: 811639:732db8acd432
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Nov 08 19:38:04 2015 +0000

description:
Add more rpc tests. XXX: Need rpcbind running.

diffstat:

 tests/lib/libc/rpc/t_rpc.c |  138 ++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 129 insertions(+), 9 deletions(-)

diffs (215 lines):

diff -r 3ba75d6e75a9 -r 732db8acd432 tests/lib/libc/rpc/t_rpc.c
--- a/tests/lib/libc/rpc/t_rpc.c        Sun Nov 08 19:30:53 2015 +0000
+++ b/tests/lib/libc/rpc/t_rpc.c        Sun Nov 08 19:38:04 2015 +0000
@@ -1,19 +1,21 @@
-/*     $NetBSD: t_rpc.c,v 1.5 2015/11/06 15:30:47 christos Exp $       */
+/*     $NetBSD: t_rpc.c,v 1.6 2015/11/08 19:38:04 christos Exp $       */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_rpc.c,v 1.5 2015/11/06 15:30:47 christos Exp $");
+__RCSID("$NetBSD: t_rpc.c,v 1.6 2015/11/08 19:38:04 christos Exp $");
 
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <rpc/rpc.h>
-// #include <rpc/raw.h>
 #include <stdlib.h>
+#include <string.h>
 #include <err.h>
 #include <netdb.h>
 #include <stdio.h>
+#include <errno.h>
 #include <unistd.h>
 
-
+#define DEBUG
+#define TEST
 #ifndef TEST
 #include <atf-c.h>
 
@@ -86,8 +88,9 @@
 #define PROGNUM 0x81
 #define VERSNUM 0x01
 #define PLUSONE 1
+#define DESTROY 2
 
-static struct timeval  tout = {0, 0};
+static struct timeval  tout = {1, 0};
 
 static void
 server(struct svc_req *rqstp, SVCXPRT *transp)
@@ -103,6 +106,11 @@
                return;
        case PLUSONE:
                break;
+       case DESTROY:
+               if (!svc_sendreply(transp, (xdrproc_t)xdr_void, NULL))
+                       ERRX(EXIT_FAILURE, "svc_sendreply failed %d", 0);
+               svc_destroy(transp);
+               exit(0);
        default:
                svcerr_noproc(transp);
                return;
@@ -155,6 +163,55 @@
        return EXIT_SUCCESS;
 }
 
+static int
+regtest(const char *hostname, const char *transp, const char *arg, int p)
+{
+       CLIENT         *clnt;
+       int             num, resp;
+       enum clnt_stat  rv;
+       pid_t           pid;
+
+       if (arg)
+               num = atoi(arg);
+       else
+               num = 0;
+
+       svc_fdset_init(p ? SVC_FDSET_POLL : 0);
+       if (!svc_create(server, PROGNUM, VERSNUM, transp))
+               ERRX(EXIT_FAILURE, "Can't not create server %d", num);
+
+       switch ((pid = fork())) {
+       case 0:
+               DPRINTF("Calling svc_run\n");
+               svc_run();
+       case -1:
+               ERRX(EXIT_FAILURE, "Fork failed (%s)", strerror(errno));
+       default:
+               sleep(1);
+               break;
+       }
+
+       DPRINTF("Initializing client\n");
+       clnt = clnt_create(hostname, PROGNUM, VERSNUM, transp);
+       if (clnt == NULL)
+               ERRX(EXIT_FAILURE, "%s",
+                   clnt_spcreateerror("clnt_raw_create"));
+       rv = clnt_call(clnt, PLUSONE, (xdrproc_t)xdr_int, (void *)&num,
+           (xdrproc_t)xdr_int, (void *)&resp, tout);
+       if (rv != RPC_SUCCESS)
+               ERRX(EXIT_FAILURE, "clnt_call: %s", clnt_sperrno(rv));
+       DPRINTF("Got %d\n", resp);
+       if (++num != resp)
+               ERRX(EXIT_FAILURE, "expected %d got %d", num, resp);
+       rv = clnt_call(clnt, DESTROY, (xdrproc_t)xdr_void, NULL,
+           (xdrproc_t)xdr_void, NULL, tout);
+       if (rv != RPC_SUCCESS)
+               ERRX(EXIT_FAILURE, "clnt_call: %s", clnt_sperrno(rv));
+       clnt_destroy(clnt);
+
+       return EXIT_SUCCESS;
+}
+
 
 #ifdef TEST
 static void
@@ -173,11 +230,18 @@
 main(int argc, char *argv[])
 {
        int             ch;
+       int             s, p;
        const char     *transp = "udp";
 
-
-       while ((ch = getopt(argc, argv, "rtu")) != -1)
+       p = s = 0;
+       while ((ch = getopt(argc, argv, "prstu")) != -1)
                switch (ch) {
+               case 'p':
+                       p = 1;
+                       break;
+               case 's':
+                       s = 1;
+                       break;
                case 't':
                        transp = "tcp";
                        break;
@@ -188,7 +252,8 @@
                        transp = NULL;
                        break;
                default:
-                       fprintf(stderr, "Usage: %s -[r|t|u] [<hostname>...]\n",
+                       fprintf(stderr,
+                           "Usage: %s -[r|s|t|u] [<hostname>...]\n",
                            getprogname());
                        return EXIT_FAILURE;
                }
@@ -201,7 +266,9 @@
        } else {
                for (; optind < argc; optind++) {
                        if (transp)
-                               onehost(argv[optind], transp);
+                               s == 0 ?
+                                   onehost(argv[optind], transp) :
+                                   regtest(argv[optind], transp, "1", p);
                        else
                                rawtest(argv[optind]);
                }
@@ -248,11 +315,64 @@
        rawtest(NULL);
 
 }
+
+ATF_TC(tcp);
+ATF_TC_HEAD(tcp, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Checks svc tcp (select)");
+}
+
+ATF_TC_BODY(tcp, tc)
+{
+       regtest("localhost", "tcp", 1, 0);
+
+}
+
+ATF_TC(udp);
+ATF_TC_HEAD(udp, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Checks svc udp (select)");
+}
+
+ATF_TC_BODY(udp, tc)
+{
+       regtest("localhost", "udp", 1, 0);
+
+}
+
+ATF_TC(tcp_poll);
+ATF_TC_HEAD(tcp_poll, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Checks svc tcp (poll)");
+}
+
+ATF_TC_BODY(tcp_poll, tc)
+{
+       regtest("localhost", "tcp", 1, 1);
+
+}
+
+ATF_TC(udp_poll);
+ATF_TC_HEAD(udp_poll, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Checks svc udp (poll)");
+}
+
+ATF_TC_BODY(udp_poll, tc)
+{
+       regtest("localhost", "udp", 1, 1);
+
+}
+
 ATF_TP_ADD_TCS(tp)
 {
        ATF_TP_ADD_TC(tp, get_svc_addr_udp);
        ATF_TP_ADD_TC(tp, get_svc_addr_tcp);
        ATF_TP_ADD_TC(tp, raw);
+       ATF_TP_ADD_TC(tp, tcp);
+       ATF_TP_ADD_TC(tp, udp);
+       ATF_TP_ADD_TC(tp, tcp_poll);
+       ATF_TP_ADD_TC(tp, udp_poll);
 
        return atf_no_error();
 }



Home | Main Index | Thread Index | Old Index