TESTS: Add a library to check for the default loopback network
authorJason Edgecombe <jason@rampaginggeek.com>
Sat, 22 Sep 2012 03:14:37 +0000 (23:14 -0400)
committerDerrick Brashear <shadow@your-file-system.com>
Wed, 26 Sep 2012 11:47:01 +0000 (04:47 -0700)
Change-Id: Id7bb92345e97309363fa5ddbff9147edf30ccd96
Reviewed-on: http://gerrit.openafs.org/8145
Reviewed-by: Marc Dionne <marc.c.dionne@gmail.com>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>

tests/common/Makefile.in
tests/common/common.h
tests/common/network.c [new file with mode: 0644]

index 11708e1..2909f61 100644 (file)
@@ -4,9 +4,10 @@ abs_top_builddir=@abs_top_builddir@
 include @TOP_OBJDIR@/src/config/Makefile.config
 include @TOP_OBJDIR@/src/config/Makefile.pthread
 
-MODULE_CFLAGS=-I$(srcdir)/..
+MODULE_CFLAGS=-I$(srcdir)/.. -I$(srcdir)/../..
+CFLAGS_network.o = -Wno-strict-prototypes
 
-all check test tests:  config.o servers.o ubik.o rxkad.o
+all check test tests:  config.o servers.o ubik.o rxkad.o network.o
 
 clean:
        rm -f *.o
index 9782a98..cf19692 100644 (file)
@@ -50,3 +50,7 @@ extern int afstest_GetUbikClient(struct afsconf_dir *dir, char *service,
                                 struct rx_securityClass *secClass,
                                 int secIndex,
                                 struct ubik_client **ubikClient);
+
+/* network.c */
+extern int afstest_IsLoopbackNetworkDefault(void);
+extern int afstest_SkipTestsIfLoopbackNetIsDefault(void);
diff --git a/tests/common/network.c b/tests/common/network.c
new file mode 100644 (file)
index 0000000..e605b28
--- /dev/null
@@ -0,0 +1,44 @@
+#include <afsconfig.h>
+#include <afs/param.h>
+#include <afs/cellconfig.h>
+#include <rx/rx.h>
+
+#include <stdio.h>
+#include <unistd.h>
+#include <netdb.h>
+#include <string.h>
+
+#include <tests/tap/basic.h>
+#include "common.h"
+
+extern int h_errno;
+
+/*! Check if the current machine's hostname resolves to the loopback
+ * network.
+ */
+int
+afstest_IsLoopbackNetworkDefault(void) {
+  char hostname[MAXHOSTCHARS];
+  afs_uint32 addr;
+  struct hostent *host;
+
+  gethostname(hostname, sizeof(hostname));
+  host = gethostbyname(hostname);
+  memcpy(&addr, host->h_addr, sizeof(addr));
+
+  return(rx_IsLoopbackAddr(ntohl(addr)));
+}
+
+/*! Skips all TAP tests if the current machine's hostname resolves to the
+ * loopback network.
+ */
+int
+afstest_SkipTestsIfLoopbackNetIsDefault(void) {
+  int retval=0;
+  retval=afstest_IsLoopbackNetworkDefault();
+  if(retval==1) {
+    skip_all("Default IP address is on the loopback network!\n");
+  }
+
+  return retval;
+}