tests: Accommodate c-tap-harness 4.7
[openafs.git] / tests / common / servers.c
index a2a4e69..716b0ca 100644 (file)
@@ -11,6 +11,8 @@
 
 #include <afs/cellconfig.h>
 
+#include <tests/tap/basic.h>
+
 #include "common.h"
 
 /* Start up the VLserver, using the configuration in dirname, and putting our
@@ -21,6 +23,7 @@ int
 afstest_StartVLServer(char *dirname, pid_t *serverPid)
 {
     pid_t pid;
+    int status;
 
     pid = fork();
     if (pid == -1) {
@@ -30,19 +33,36 @@ afstest_StartVLServer(char *dirname, pid_t *serverPid)
        char *binPath, *logPath, *dbPath, *build;
 
        /* Child */
-       build = getenv("BUILD");
+       build = getenv("C_TAP_BUILD");
 
        if (build == NULL)
            build = "..";
 
-       asprintf(&binPath, "%s/../src/tvlserver/vlserver", build);
-       asprintf(&logPath, "%s/VLLog", dirname);
-       asprintf(&dbPath, "%s/vldb", dirname);
+       if (asprintf(&binPath, "%s/../src/tvlserver/vlserver", build) < 0 ||
+           asprintf(&logPath, "%s/VLLog", dirname) < 0 ||
+           asprintf(&dbPath, "%s/vldb", dirname) < 0) {
+           fprintf(stderr, "Out of memory building vlserver arguments\n");
+           exit(1);
+       }
        execl(binPath, "vlserver",
              "-logfile", logPath, "-database", dbPath, "-config", dirname, NULL);
        fprintf(stderr, "Running %s failed\n", binPath);
        exit(1);
     }
+
+    if (waitpid(pid, &status, WNOHANG) != 0) {
+       fprintf(stderr, "Error starting vlserver\n");
+       return -1;
+    }
+
+    diag("Sleeping for a few seconds to let the vlserver startup");
+    sleep(5);
+
+    if (waitpid(pid, &status, WNOHANG) != 0) {
+       fprintf(stderr, "vlserver died during startup\n");
+       return -1;
+    }
+
     *serverPid = pid;
 
     return 0;
@@ -70,6 +90,7 @@ afstest_StopServer(pid_t serverPid)
 
 int
 afstest_StartTestRPCService(const char *configPath,
+                           pid_t signal_pid,
                            u_short port,
                            u_short serviceId,
                            afs_int32 (*proc) (struct rx_call *))
@@ -92,6 +113,10 @@ afstest_StartTestRPCService(const char *configPath,
        return -1;
     }
 
+    if (signal_pid != 0) {
+       kill(signal_pid, SIGUSR1);
+    }
+
     afsconf_BuildServerSecurityObjects(dir, &classes, &numClasses);
     service = rx_NewService(0, serviceId, "test", classes, numClasses,
                             proc);