tests: Accommodate c-tap-harness 4.7
[openafs.git] / tests / volser / vos-t.c
index e3c499c..05ec8fd 100644 (file)
@@ -57,7 +57,10 @@ TestListAddrs(struct ubik_client *client, char *dirname)
     is_int(0, code, "Second address registration succeeds");
 
     /* Now we need to run vos ListAddrs and see what happens ... */
-    pipe(outpipe);
+    if (pipe(outpipe) < 0) {
+       perror("pipe");
+       exit(1);
+    }
     pid = fork();
     if (pid == 0) {
        char *build, *binPath;
@@ -66,13 +69,16 @@ TestListAddrs(struct ubik_client *client, char *dirname)
        close(outpipe[0]);
        close(outpipe[1]);
 
-       build = getenv("BUILD");
+       build = getenv("C_TAP_BUILD");
        if (build == NULL)
            build = "..";
 
-       asprintf(&binPath, "%s/../src/volser/vos", build);
+       if (asprintf(&binPath, "%s/../src/volser/vos", build) < 0) {
+           fprintf(stderr, "Out of memory building vos arguments\n");
+           exit(1);
+       }
        execl(binPath, "vos",
-             "listaddrs", "-config", dirname, "-noauth", NULL);
+             "listaddrs", "-config", dirname, "-noauth", "-noresolve", NULL);
        exit(1);
     }
     close(outpipe[1]);
@@ -90,15 +96,20 @@ main(int argc, char **argv)
     char *dirname;
     struct afsconf_dir *dir;
     int code, secIndex;
-    pid_t serverPid;
+    pid_t serverPid = 0;
     struct rx_securityClass *secClass;
     struct ubik_client *ubikClient = NULL;
     int ret = 0;
+    char *argv0 = afstest_GetProgname(argv);
 
-    plan(6);
-
+    /* Skip all tests if the current hostname can't be resolved */
+    afstest_SkipTestsIfBadHostname();
     /* Skip all tests if the current hostname is on the loopback network */
     afstest_SkipTestsIfLoopbackNetIsDefault();
+    /* Skip all tests if a vlserver is already running on this system. */
+    afstest_SkipTestsIfServerRunning("afs3-vlserver");
+
+    plan(6);
 
     code = rx_Init(0);
 
@@ -108,24 +119,22 @@ main(int argc, char **argv)
 
     code = afstest_AddDESKeyFile(dir);
     if (code) {
-       afs_com_err("vos-t", code, "while adding test DES keyfile");
+       afs_com_err(argv0, code, "while adding test DES keyfile");
        ret = 1;
        goto out;
     }
 
     code = afstest_StartVLServer(dirname, &serverPid);
     if (code) {
-       afs_com_err("vos-t", code, "while starting the vlserver");
+       afs_com_err(argv0, code, "while starting the vlserver");
        ret = 1;
        goto out;
     }
 
-    /* Let it figure itself out ... */
-    sleep(5);
     code = afsconf_ClientAuthSecure(dir, &secClass, &secIndex);
     is_int(code, 0, "Successfully got security class");
     if (code) {
-       afs_com_err("authname-t", code, "while getting anonymous secClass");
+       afs_com_err(argv0, code, "while getting anonymous secClass");
        ret = 1;
        goto out;
     }
@@ -134,17 +143,19 @@ main(int argc, char **argv)
                                 secClass, secIndex, &ubikClient);
     is_int(code, 0, "Successfully built ubik client structure");
     if (code) {
-       afs_com_err("vos-t", code, "while building ubik client");
+       afs_com_err(argv0, code, "while building ubik client");
        ret = 1;
        goto out;
     }
 
     TestListAddrs(ubikClient, dirname);
 
-    code = afstest_StopServer(serverPid);
-    is_int(0, code, "Server exited cleanly");
-
 out:
+    if (serverPid != 0) {
+       code = afstest_StopServer(serverPid);
+       is_int(0, code, "Server exited cleanly");
+    }
+
     afstest_UnlinkTestConfig(dirname);
     return ret;
 }