From: Marc Dionne Date: Sun, 17 Feb 2013 18:29:38 +0000 (-0500) Subject: tests: Improve failure mode for unresolvable hostname X-Git-Tag: upstream/1.8.0_pre1^2~1539 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=0a528a52f5da5e225567f3b9deab9f7d08022f9f;p=packages%2Fo%2Fopenafs.git tests: Improve failure mode for unresolvable hostname In the case of a host where gethostbyname is unable to resolve the hostname, afstest_BuildTestConfig() may return NULL which can cause several tests to crash. Add a common function to look out for this condition and use it where appropriate. When it occurs, the current module is skipped and the user gets an error message that indicates the configuration problem. Change-Id: I7216876eb2424368f415e5759e2b95009ad055b2 Reviewed-on: http://gerrit.openafs.org/9120 Reviewed-by: Derrick Brashear Tested-by: BuildBot Reviewed-by: Jeffrey Altman --- diff --git a/tests/auth/Makefile.in b/tests/auth/Makefile.in index 4cdb63913..ed4ed27ae 100644 --- a/tests/auth/Makefile.in +++ b/tests/auth/Makefile.in @@ -15,22 +15,22 @@ MODULE_LIBS = ../tap/libtap.a \ $(LIB_rfc3961) $(LIB_roken) \ $(XLIBS) -authcon-t: authcon-t.o ../common/config.o - $(LT_LDRULE_static) authcon-t.o ../common/config.o \ +authcon-t: authcon-t.o ../common/config.o ../common/network.o + $(LT_LDRULE_static) authcon-t.o ../common/config.o ../common/network.o \ $(MODULE_LIBS) superuser-t: superuser-t.o ../common/config.o ../common/rxkad.o \ - test.cs.o test.ss.o test.xdr.o + test.cs.o test.ss.o test.xdr.o ../common/network.o $(LT_LDRULE_static) superuser-t.o ../common/config.o \ ../common/rxkad.o ../common/servers.o \ - test.cs.o test.ss.o test.xdr.o \ + test.cs.o test.ss.o test.xdr.o ../common/network.o \ $(MODULE_LIBS) -keys-t: keys-t.o ../common/config.o - $(LT_LDRULE_static) keys-t.o ../common/config.o $(MODULE_LIBS) +keys-t: keys-t.o ../common/config.o ../common/network.o + $(LT_LDRULE_static) keys-t.o ../common/config.o ../common/network.o $(MODULE_LIBS) -realms-t: realms-t.o ../common/config.o - $(LT_LDRULE_static) realms-t.o ../common/config.o $(MODULE_LIBS) +realms-t: realms-t.o ../common/config.o ../common/network.o + $(LT_LDRULE_static) realms-t.o ../common/config.o ../common/network.o $(MODULE_LIBS) writekeyfile: writekeyfile.o $(LT_LDRULE_static) writekeyfile.o $(MODULE_LIBS) diff --git a/tests/auth/authcon-t.c b/tests/auth/authcon-t.c index 46cf3c949..e029774f3 100644 --- a/tests/auth/authcon-t.c +++ b/tests/auth/authcon-t.c @@ -51,6 +51,8 @@ main(int argc, char **argv) struct afsconf_typedKey *key; int code = 0; + afstest_SkipTestsIfBadHostname(); + plan(9); dirname = afstest_BuildTestConfig(); diff --git a/tests/auth/keys-t.c b/tests/auth/keys-t.c index 2f08e08c1..5c483c537 100644 --- a/tests/auth/keys-t.c +++ b/tests/auth/keys-t.c @@ -106,6 +106,8 @@ int main(int argc, char **argv) int code; int i; + afstest_SkipTestsIfBadHostname(); + plan(134); /* Create a temporary afs configuration directory */ diff --git a/tests/auth/realms-t.c b/tests/auth/realms-t.c index cdd15da95..04fac4e21 100644 --- a/tests/auth/realms-t.c +++ b/tests/auth/realms-t.c @@ -359,6 +359,8 @@ test_update_config_files(void) int main(int argc, char **argv) { + afstest_SkipTestsIfBadHostname(); + plan(113); test_edges(); diff --git a/tests/auth/superuser-t.c b/tests/auth/superuser-t.c index 03f67d918..bdba611f5 100644 --- a/tests/auth/superuser-t.c +++ b/tests/auth/superuser-t.c @@ -373,6 +373,8 @@ int main(int argc, char **argv) int code; int ret = 0; + afstest_SkipTestsIfBadHostname(); + /* Start the client and the server if requested */ if (argc == 3 ) { diff --git a/tests/common/common.h b/tests/common/common.h index cf1969250..c9f734970 100644 --- a/tests/common/common.h +++ b/tests/common/common.h @@ -54,3 +54,4 @@ extern int afstest_GetUbikClient(struct afsconf_dir *dir, char *service, /* network.c */ extern int afstest_IsLoopbackNetworkDefault(void); extern int afstest_SkipTestsIfLoopbackNetIsDefault(void); +extern void afstest_SkipTestsIfBadHostname(void); diff --git a/tests/common/config.c b/tests/common/config.c index 4783753dd..faefc0058 100644 --- a/tests/common/config.c +++ b/tests/common/config.c @@ -35,6 +35,7 @@ #include +#include #include "common.h" static FILE * diff --git a/tests/common/network.c b/tests/common/network.c index 5611003c8..474fc6155 100644 --- a/tests/common/network.c +++ b/tests/common/network.c @@ -22,6 +22,9 @@ afstest_IsLoopbackNetworkDefault(void) gethostname(hostname, sizeof(hostname)); host = gethostbyname(hostname); + if (!host) { + skip_all("Can't resolve hostname %s\n", hostname); + } memcpy(&addr, host->h_addr, sizeof(addr)); return(rx_IsLoopbackAddr(ntohl(addr))); @@ -42,3 +45,19 @@ afstest_SkipTestsIfLoopbackNetIsDefault(void) } return retval; } + +/*! + * Skips all TAP tests if the current machine's hostname can't be resolved + * to any IP address. + */ +void +afstest_SkipTestsIfBadHostname(void) +{ + char hostname[MAXHOSTCHARS]; + struct hostent *host; + + gethostname(hostname, sizeof(hostname)); + host = gethostbyname(hostname); + if (!host) + skip_all("Can't resolve hostname %s\n", hostname); +} diff --git a/tests/volser/vos-t.c b/tests/volser/vos-t.c index e3c499cca..3919c0b69 100644 --- a/tests/volser/vos-t.c +++ b/tests/volser/vos-t.c @@ -95,11 +95,13 @@ main(int argc, char **argv) struct ubik_client *ubikClient = NULL; int ret = 0; - 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(); + plan(6); + code = rx_Init(0); dirname = afstest_BuildTestConfig();