]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
tests: Move common code to its own directory
authorSimon Wilkinson <sxw@your-file-system.com>
Mon, 30 May 2011 16:47:35 +0000 (17:47 +0100)
committerDerrick Brashear <shadow@dementia.org>
Tue, 7 Jun 2011 14:50:20 +0000 (07:50 -0700)
Move code for faking up an OpenAFS configuration directory into its
own "common" directory, as it's going to be of use to more tests than
just those in auth.

Change-Id: I9c80dd66763e222deca98bc7744ff317111c6ed8
Reviewed-on: http://gerrit.openafs.org/4806
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
12 files changed:
Makefile.in
configure.ac
tests/Makefile.in
tests/auth/Makefile.in
tests/auth/authcon-t.c
tests/auth/common.c [deleted file]
tests/auth/common.h [deleted file]
tests/auth/keys-t.c
tests/auth/superuser-t.c
tests/common/Makefile.in [new file with mode: 0644]
tests/common/common.h [new file with mode: 0644]
tests/common/config.c [new file with mode: 0644]

index 1fd82ecda76f34a5a0bc1439f4b6111aad991c07..799f9aa217b4b5692eec3865837e59130204c013 100644 (file)
@@ -947,6 +947,7 @@ distclean: clean
        tests/tap/Makefile \
        tests/auth/Makefile \
        tests/cmd/Makefile \
+       tests/common/Makefile \
        tests/util/Makefile \
        src/helper-splint.sh
        if test -d doc/man-pages ; then \
index 0df22bc84ed2e37f2a5ab180c6f8017092b37a83..0aa3dba5fc737cec96939393e6a3ee5614ec24ee 100644 (file)
@@ -245,6 +245,7 @@ src/helper-splint.sh \
 tests/Makefile \
 tests/auth/Makefile \
 tests/cmd/Makefile \
+tests/common/Makefile \
 tests/rpctestlib/Makefile \
 tests/tap/Makefile \
 tests/util/Makefile,
index 3e17b5194632a1a598eeb11fa5850eab949c0ac2..550312cae447024037169d8281466840758d7ce5 100644 (file)
@@ -9,7 +9,7 @@ include @TOP_OBJDIR@/src/config/Makefile.pthread
 MODULE_CFLAGS = -DSOURCE='"$(abs_top_srcdir)/tests"' \
        -DBUILD='"$(abs_top_builddir)/tests"'
 
-SUBDIRS = tap auth util cmd
+SUBDIRS = tap common auth util cmd
 
 all: runtests
        @for A in $(SUBDIRS); do cd $$A && $(MAKE) $@ && cd .. || exit 1; done
index e378b3c048457f063583f35b2737b3c240d7d6c6..b6c84be39eba05c8e88378c7f5b7d625483f9ae9 100644 (file)
@@ -6,7 +6,7 @@ include @TOP_OBJDIR@/src/config/Makefile.pthread
 
 TESTS = authcon-t superuser-t keys-t
 
-MODULE_CFLAGS=-I$(srcdir)/..
+MODULE_CFLAGS=-I$(srcdir)/.. -I$(srcdir)/../common/
 
 all check test tests: $(TESTS)
 
@@ -17,17 +17,17 @@ MODULE_LIBS =       ../tap/libtap.a \
                $(LIB_rfc3961) $(LIB_roken) -lafsutil\
                $(XLIBS)
 
-authcon-t: authcon-t.o common.o
-       $(AFS_LDRULE) authcon-t.o common.o \
+authcon-t: authcon-t.o ../common/config.o
+       $(AFS_LDRULE) authcon-t.o ../common/config.o \
                $(MODULE_LIBS)
 
-superuser-t: superuser-t.o common.o test.cs.o test.ss.o test.xdr.o
-       $(AFS_LDRULE) superuser-t.o common.o \
+superuser-t: superuser-t.o ../common/config.o test.cs.o test.ss.o test.xdr.o
+       $(AFS_LDRULE) superuser-t.o ../common/config.o \
                test.cs.o test.ss.o test.xdr.o \
                $(MODULE_LIBS)
 
-keys-t: keys-t.o common.o
-       $(AFS_LDRULE) keys-t.o common.o $(MODULE_LIBS)
+keys-t: keys-t.o ../common/config.o
+       $(AFS_LDRULE) keys-t.o ../common/config.o $(MODULE_LIBS)
 
 writekeyfile: writekeyfile.o
        $(AFS_LDRULE) writekeyfile.o $(MODULE_LIBS)
@@ -44,7 +44,7 @@ test.xdr.c: test.xg
 test.h: test.xg
        $(RXGEN) -A -x -h -o $@ $(srcdir)/test.xg
 
-superuser-t.o: test.h common.h
+superuser-t.o: test.h
 
 clean:
        rm -f *.o *.cs.c *.ss.c *.xdr.c test.h \
index 1552f263761302c478bd63cc48c9738df66b0ad4..c9e968ee87e6b6f2c953f18af4a8fd2146ced70d 100644 (file)
@@ -51,7 +51,7 @@ main(int argc, char **argv)
     struct afsconf_typedKey *key;
 
     plan(9);
-    dirname = buildTestConfig();
+    dirname = afstest_BuildTestConfig();
 
     dir = afsconf_Open(dirname);
     if (dir == NULL) {
diff --git a/tests/auth/common.c b/tests/auth/common.c
deleted file mode 100644 (file)
index fb95955..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright (c) 2010 Your File System Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*!
- * Common functions for building a configuration directory
- */
-
-#include <afsconfig.h>
-#include <afs/param.h>
-#include <roken.h>
-
-#include <afs/afsutil.h>
-
-#include "common.h"
-
-static FILE *
-openConfigFile(char *dirname, char *filename) {
-    char *path = NULL;
-    FILE *file;
-
-    if (asprintf(&path, "%s/%s", dirname, filename) == -1)
-       return NULL;
-
-    file = fopen(path, "w");
-    free(path);
-    return file;
-}
-
-static void
-unlinkConfigFile(char *dirname, char *filename) {
-    char *path;
-
-    if (asprintf(&path, "%s/%s", dirname, filename) != -1) {
-       unlink(path);
-        free(path);
-    }
-}
-
-/*!
- * Build a test configuration directory, containing a CellServDB and ThisCell
- * file for the "example.org" cell
- *
- * @return
- * The path to the configuration directory. This should be freed by the caller
- * using free()
- *
- */
-
-char *
-buildTestConfig(void) {
-    char *dir = NULL;
-    FILE *file;
-
-    if (asprintf(&dir, "%s/afs_XXXXXX", gettmpdir()) == -1)
-       goto fail;
-
-    if (mkdtemp(dir) == NULL)
-       goto fail;
-
-    /* Create a CellServDB */
-    file = openConfigFile(dir, "CellServDB");
-    fprintf(file, ">example.org # An example cell\n");
-    fprintf(file, "127.0.0.1 #test.example.org\n");
-    fclose(file);
-
-    /* Create a ThisCell file */
-    file = openConfigFile(dir, "ThisCell");
-    fprintf(file, "example.org");
-    fclose(file);
-
-    return dir;
-
-fail:
-    if (dir)
-       free(dir);
-    return NULL;
-}
-
-/*!
- * Delete at test configuration directory
- */
-
-void
-unlinkTestConfig(char *dir)
-{
-    unlinkConfigFile(dir, "KeyFile");
-    unlinkConfigFile(dir, "CellServDB");
-    unlinkConfigFile(dir, "ThisCell");
-    unlinkConfigFile(dir, "UserList");
-    rmdir(dir);
-}
diff --git a/tests/auth/common.h b/tests/auth/common.h
deleted file mode 100644 (file)
index afe0b67..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2010 Your File System Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-extern char *buildTestConfig(void);
-extern void unlinkTestConfig(char *);
index ba7391e0a745f173558a51ee997dd6575c251472..19ab98ab8c76c61a2f0a049cab328c184fed39fb 100644 (file)
@@ -110,7 +110,7 @@ int main(int argc, char **argv)
 
     /* Create a temporary afs configuration directory */
 
-    dirname = buildTestConfig();
+    dirname = afstest_BuildTestConfig();
 
     if (asprintf(&keyfile, "%s/KeyFile", dirname) == -1)
        goto out;
@@ -557,12 +557,12 @@ int main(int argc, char **argv)
 
     afsconf_Close(dir);
 
-    unlinkTestConfig(dirname);
+    afstest_UnlinkTestConfig(dirname);
     free(dirname);
     free(keyfile);
 
     /* Start a new test configuration */
-    dirname = buildTestConfig();
+    dirname = afstest_BuildTestConfig();
     dir = afsconf_Open(dirname);
     ok(dir != NULL, "Sucessfully opened brand new config directory");
     if (dir == NULL)
@@ -583,7 +583,7 @@ int main(int argc, char **argv)
        " ... with the right key");
 
 out:
-    unlinkTestConfig(dirname);
+    afstest_UnlinkTestConfig(dirname);
 
     return 0;
 }
index c2ebbc6f10fb5edbf5e13fdb22692026b29bfa6c..dae89c1dc578d51739fcba42e04e8e871693fcb1 100644 (file)
@@ -457,7 +457,7 @@ int main(int argc, char **argv)
     /* Otherwise, do the basic configuration, then start the client and
      * server */
 
-    dirname = buildTestConfig();
+    dirname = afstest_BuildTestConfig();
 
     dir = afsconf_Open(dirname);
     if (dir == NULL) {
diff --git a/tests/common/Makefile.in b/tests/common/Makefile.in
new file mode 100644 (file)
index 0000000..225d06a
--- /dev/null
@@ -0,0 +1,12 @@
+
+srcdir=@srcdir@
+abs_top_builddir=@abs_top_builddir@
+include @TOP_OBJDIR@/src/config/Makefile.config
+include @TOP_OBJDIR@/src/config/Makefile.pthread
+
+MODULE_CFLAGS=-I$(srcdir)/..
+
+all check test tests:  config.o
+
+clean:
+       rm -f *.o
diff --git a/tests/common/common.h b/tests/common/common.h
new file mode 100644 (file)
index 0000000..9f8fe2b
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2010 Your File System Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+extern char *afstest_BuildTestConfig(void);
+extern void afstest_UnlinkTestConfig(char *);
diff --git a/tests/common/config.c b/tests/common/config.c
new file mode 100644 (file)
index 0000000..1170240
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2010 Your File System Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*!
+ * Common functions for building a configuration directory
+ */
+
+#include <afsconfig.h>
+#include <afs/param.h>
+#include <roken.h>
+
+#include <afs/afsutil.h>
+
+#include "common.h"
+
+static FILE *
+openConfigFile(char *dirname, char *filename) {
+    char *path = NULL;
+    FILE *file;
+
+    if (asprintf(&path, "%s/%s", dirname, filename) == -1)
+       return NULL;
+
+    file = fopen(path, "w");
+    free(path);
+    return file;
+}
+
+static void
+unlinkConfigFile(char *dirname, char *filename) {
+    char *path;
+
+    if (asprintf(&path, "%s/%s", dirname, filename) != -1) {
+       unlink(path);
+        free(path);
+    }
+}
+
+/*!
+ * Build a test configuration directory, containing a CellServDB and ThisCell
+ * file for the "example.org" cell
+ *
+ * @return
+ * The path to the configuration directory. This should be freed by the caller
+ * using free()
+ *
+ */
+
+char *
+afstest_BuildTestConfig(void) {
+    char *dir = NULL;
+    FILE *file;
+
+    if (asprintf(&dir, "%s/afs_XXXXXX", gettmpdir()) == -1)
+       goto fail;
+
+    if (mkdtemp(dir) == NULL)
+       goto fail;
+
+    /* Create a CellServDB */
+    file = openConfigFile(dir, "CellServDB");
+    fprintf(file, ">example.org # An example cell\n");
+    fprintf(file, "127.0.0.1 #test.example.org\n");
+    fclose(file);
+
+    /* Create a ThisCell file */
+    file = openConfigFile(dir, "ThisCell");
+    fprintf(file, "example.org");
+    fclose(file);
+
+    return dir;
+
+fail:
+    if (dir)
+       free(dir);
+    return NULL;
+}
+
+/*!
+ * Delete at test configuration directory
+ */
+
+void
+afstest_UnlinkTestConfig(char *dir)
+{
+    unlinkConfigFile(dir, "KeyFile");
+    unlinkConfigFile(dir, "CellServDB");
+    unlinkConfigFile(dir, "ThisCell");
+    unlinkConfigFile(dir, "UserList");
+    rmdir(dir);
+}