From 0c3670914a05c7aa33f0b1239ba9cc25f430ed04 Mon Sep 17 00:00:00 2001 From: Marc Dionne Date: Wed, 19 Sep 2012 19:14:31 -0400 Subject: [PATCH] tests: cleanup temporary files Call the configuration directory cleanup function before exiting so there are no files left behind, even in case of error. Add KeyFileExt to the list of files that are removed. Change-Id: Ie795bef0d44609b36950970244c02a6c6da1a843 Reviewed-on: http://gerrit.openafs.org/8142 Tested-by: BuildBot Reviewed-by: Simon Wilkinson Reviewed-by: Derrick Brashear --- tests/Makefile.in | 2 +- tests/auth/authcon-t.c | 8 ++++++-- tests/auth/superuser-t.c | 19 ++++++++++++------- tests/common/config.c | 17 ++++++++++------- tests/volser/vos-t.c | 17 ++++++++++++----- 5 files changed, 41 insertions(+), 22 deletions(-) diff --git a/tests/Makefile.in b/tests/Makefile.in index d6d221d5a..d07085148 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -23,7 +23,7 @@ runtests.o: $(srcdir)/runtests.c check test tests: runtests @for A in $(SUBDIRS); do cd $$A && $(MAKE) $@ && cd .. || exit 1; done ./libwrap @TOP_OBJDIR@/lib \ - ./runtests $(abs_top_srcdir)/tests/TESTS + MAKECHECK=1 ./runtests $(abs_top_srcdir)/tests/TESTS install: diff --git a/tests/auth/authcon-t.c b/tests/auth/authcon-t.c index 359b3a3f0..46cf3c949 100644 --- a/tests/auth/authcon-t.c +++ b/tests/auth/authcon-t.c @@ -49,6 +49,7 @@ main(int argc, char **argv) int secIndex; int numClasses; struct afsconf_typedKey *key; + int code = 0; plan(9); dirname = afstest_BuildTestConfig(); @@ -56,7 +57,8 @@ main(int argc, char **argv) dir = afsconf_Open(dirname); if (dir == NULL) { fprintf(stderr, "Unable to configure directory.\n"); - exit(1); + code = 1; + goto out; } rx_Init(0); @@ -87,5 +89,7 @@ main(int argc, char **argv) afsconf_GetLatestKeyByTypes(dir, afsconf_rxkad, 0, &key); ok(afsconf_UpToDate(dir), "afsconf_GetLatestKeyByTypes resest UpToDate"); - return 0; +out: + afstest_UnlinkTestConfig(dirname); + return code; } diff --git a/tests/auth/superuser-t.c b/tests/auth/superuser-t.c index 095abf194..03f67d918 100644 --- a/tests/auth/superuser-t.c +++ b/tests/auth/superuser-t.c @@ -371,6 +371,7 @@ int main(int argc, char **argv) char *dirname; int serverPid, clientPid, waited, stat; int code; + int ret = 0; /* Start the client and the server if requested */ @@ -397,13 +398,15 @@ int main(int argc, char **argv) dir = afsconf_Open(dirname); if (dir == NULL) { fprintf(stderr, "Unable to configure directory.\n"); - exit(1); + ret = 1; + goto out; } code = afstest_AddDESKeyFile(dir); if (code) { afs_com_err("superuser-t", code, "while adding new key\n"); - exit(1); + ret = 1; + goto out; } printf("Config directory is %s\n", dirname); @@ -412,13 +415,15 @@ int main(int argc, char **argv) /* Bang */ } else if (serverPid == 0) { execl(argv[0], argv[0], "-server", dirname, NULL); - exit(1); + ret = 1; + goto out; } clientPid = fork(); if (clientPid == -1) { kill(serverPid, SIGTERM); waitpid(serverPid, &stat, 0); - exit(1); + ret = 1; + goto out; } else if (clientPid == 0) { execl(argv[0], argv[0], "-client", dirname, NULL); } @@ -434,9 +439,9 @@ int main(int argc, char **argv) } waitpid(0, &stat, 0); +out: /* Client and server are both done, so cleanup after everything */ + afstest_UnlinkTestConfig(dirname); - /* unlinkTestConfig(dirname); */ - - return 0; + return ret; } diff --git a/tests/common/config.c b/tests/common/config.c index aced66b43..4783753dd 100644 --- a/tests/common/config.c +++ b/tests/common/config.c @@ -120,13 +120,16 @@ fail: void afstest_UnlinkTestConfig(char *dir) { - unlinkConfigFile(dir, "KeyFile"); - unlinkConfigFile(dir, "CellServDB"); - unlinkConfigFile(dir, "ThisCell"); - unlinkConfigFile(dir, "UserList"); - unlinkConfigFile(dir, "krb.conf"); - unlinkConfigFile(dir, "krb.excl"); - rmdir(dir); + if (getenv("MAKECHECK") != NULL) { + unlinkConfigFile(dir, "KeyFile"); + unlinkConfigFile(dir, "KeyFileExt"); + unlinkConfigFile(dir, "CellServDB"); + unlinkConfigFile(dir, "ThisCell"); + unlinkConfigFile(dir, "UserList"); + unlinkConfigFile(dir, "krb.conf"); + unlinkConfigFile(dir, "krb.excl"); + rmdir(dir); + } } int diff --git a/tests/volser/vos-t.c b/tests/volser/vos-t.c index daecfbfa9..e3c499cca 100644 --- a/tests/volser/vos-t.c +++ b/tests/volser/vos-t.c @@ -93,6 +93,7 @@ main(int argc, char **argv) pid_t serverPid; struct rx_securityClass *secClass; struct ubik_client *ubikClient = NULL; + int ret = 0; plan(6); @@ -108,13 +109,15 @@ main(int argc, char **argv) code = afstest_AddDESKeyFile(dir); if (code) { afs_com_err("vos-t", code, "while adding test DES keyfile"); - exit(1); + ret = 1; + goto out; } code = afstest_StartVLServer(dirname, &serverPid); if (code) { afs_com_err("vos-t", code, "while starting the vlserver"); - exit(1); + ret = 1; + goto out; } /* Let it figure itself out ... */ @@ -123,7 +126,8 @@ main(int argc, char **argv) is_int(code, 0, "Successfully got security class"); if (code) { afs_com_err("authname-t", code, "while getting anonymous secClass"); - exit(1); + ret = 1; + goto out; } code = afstest_GetUbikClient(dir, AFSCONF_VLDBSERVICE, USER_SERVICE_ID, @@ -131,7 +135,8 @@ main(int argc, char **argv) is_int(code, 0, "Successfully built ubik client structure"); if (code) { afs_com_err("vos-t", code, "while building ubik client"); - exit(1); + ret = 1; + goto out; } TestListAddrs(ubikClient, dirname); @@ -139,5 +144,7 @@ main(int argc, char **argv) code = afstest_StopServer(serverPid); is_int(0, code, "Server exited cleanly"); - return 0; +out: + afstest_UnlinkTestConfig(dirname); + return ret; } -- 2.39.5