tests: Abstract out code for a test RPC service
authorSimon Wilkinson <sxw@your-file-system.com>
Tue, 26 Jun 2012 20:04:41 +0000 (21:04 +0100)
committerDerrick Brashear <shadow@dementix.org>
Wed, 27 Jun 2012 14:27:42 +0000 (07:27 -0700)
Lots of our tests want to start a test RPC server, and then run
commands against it. Start to abstract out the code to do this
by pulling the code to start a test RPC server into its own
function in the common test directory.

Change-Id: Ie7fa1fa1984113f3722def17a9fd4b98993bd6ff
Reviewed-on: http://gerrit.openafs.org/7584
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@secure-endpoints.com>
Reviewed-by: Derrick Brashear <shadow@dementix.org>

tests/auth/Makefile.in
tests/auth/superuser-t.c
tests/common/common.h
tests/common/servers.c

index 2e9e3e3..bb00344 100644 (file)
@@ -25,6 +25,7 @@ authcon-t: authcon-t.o ../common/config.o
 superuser-t: superuser-t.o ../common/config.o ../common/rxkad.o \
             test.cs.o test.ss.o test.xdr.o
        $(AFS_LDRULE) superuser-t.o ../common/config.o ../common/rxkad.o \
+               ../common/servers.o \
                test.cs.o test.ss.o test.xdr.o \
                $(MODULE_LIBS)
 
index bb7141e..a3ddbcd 100644 (file)
@@ -364,37 +364,6 @@ STEST_NewWhoAmI(struct rx_call *call, char **result)
    return 0;
 }
 
-void
-startServer(char *configPath)
-{
-    struct rx_securityClass **classes;
-    afs_int32 numClasses;
-    int code;
-    struct rx_service *service;
-
-    globalDir = afsconf_Open(configPath);
-    if (globalDir == NULL) {
-       fprintf(stderr, "Server: Unable to open config directory\n");
-       exit(1);
-    }
-
-    code = rx_Init(htons(TEST_PORT));
-    if (code != 0) {
-       fprintf(stderr, "Server: Unable to initialise RX\n");
-        exit(1);
-    }
-
-    afsconf_BuildServerSecurityObjects(globalDir, &classes, &numClasses);
-    service = rx_NewService(0, TEST_SERVICE_ID, "test", classes, numClasses,
-                           TEST_ExecuteRequest);
-    if (service == NULL) {
-       fprintf(stderr, "Server: Unable to start to test service\n");
-       exit(1);
-    }
-
-    rx_StartServer(1);
-}
-
 int main(int argc, char **argv)
 {
     struct afsconf_dir *dir;
@@ -406,7 +375,9 @@ int main(int argc, char **argv)
 
     if (argc == 3 ) {
         if (strcmp(argv[1], "-server") == 0) {
-            startServer(argv[2]);
+           globalDir = afsconf_Open(argv[2]);
+           afstest_StartTestRPCService(argv[2], TEST_PORT, TEST_SERVICE_ID,
+                                       TEST_ExecuteRequest);
             exit(0);
         } else if (strcmp(argv[1], "-client") == 0) {
             startClient(argv[2]);
index 4345470..9782a98 100644 (file)
@@ -37,8 +37,11 @@ extern struct rx_securityClass
                                afs_uint32 startTime, afs_uint32 endTime);
 /* servers.c */
 
+struct rx_call;
 extern int afstest_StartVLServer(char *dirname, pid_t *serverPid);
 extern int afstest_StopServer(pid_t serverPid);
+extern int afstest_StartTestRPCService(const char *, u_short, u_short,
+                                      afs_int32 (*proc)(struct rx_call *));
 
 /* ubik.c */
 struct ubik_client;
index a322e23..a2a4e69 100644 (file)
@@ -7,6 +7,10 @@
 #include <sys/wait.h>
 #endif
 
+#include <rx/rx.h>
+
+#include <afs/cellconfig.h>
+
 #include "common.h"
 
 /* Start up the VLserver, using the configuration in dirname, and putting our
@@ -63,3 +67,40 @@ afstest_StopServer(pid_t serverPid)
     }
     return 0;
 }
+
+int
+afstest_StartTestRPCService(const char *configPath,
+                           u_short port,
+                           u_short serviceId,
+                           afs_int32 (*proc) (struct rx_call *))
+{
+    struct afsconf_dir *dir;
+    struct rx_securityClass **classes;
+    afs_int32 numClasses;
+    int code;
+    struct rx_service *service;
+
+    dir = afsconf_Open(configPath);
+    if (dir == NULL) {
+        fprintf(stderr, "Server: Unable to open config directory\n");
+        return -1;
+    }
+
+    code = rx_Init(htons(port));
+    if (code != 0) {
+       fprintf(stderr, "Server: Unable to initialise RX\n");
+       return -1;
+    }
+
+    afsconf_BuildServerSecurityObjects(dir, &classes, &numClasses);
+    service = rx_NewService(0, serviceId, "test", classes, numClasses,
+                            proc);
+    if (service == NULL) {
+        fprintf(stderr, "Server: Unable to start to test service\n");
+        return -1;
+    }
+
+    rx_StartServer(1);
+
+    return 0; /* Not reached, we donated ourselves to StartServer */
+}