[gnome-keyring/dbus-api] [pkcs11] Use p11-tests to test pkcs#11 modules.
- From: Stefan Walter <stefw src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-keyring/dbus-api] [pkcs11] Use p11-tests to test pkcs#11 modules.
- Date: Wed, 18 Nov 2009 18:04:57 +0000 (UTC)
commit 626969db4fe2b8a1e16746d9383557d98cb1dfd7
Author: Stef Walter <stef memberwebs com>
Date: Mon Nov 16 01:39:29 2009 +0000
[pkcs11] Use p11-tests to test pkcs#11 modules.
Work them in as 'external' tests, which run after the main
glib based tests.
configure.in | 25 ++++++++++
pkcs11/roots-store/tests/Makefile.am | 21 ++++++--
pkcs11/roots-store/tests/test-module.c | 34 +++++++++++++
pkcs11/ssh-store/tests/Makefile.am | 3 -
pkcs11/ssh-store/tests/p11-tests.conf | 2 +-
pkcs11/ssh-store/tests/test-ssh-module.c | 8 +++
pkcs11/user-store/Makefile.am | 8 ++--
pkcs11/user-store/tests/Makefile.am | 21 ++++++--
pkcs11/user-store/tests/test-module.c | 34 +++++++++++++
tests/gtest-helpers.c | 76 ++++++++++++++++++++++++++++++
tests/gtest-helpers.h | 15 ++++++
tests/gtest.make | 10 ++--
tests/prep-gtest.sh | 12 ++++-
13 files changed, 243 insertions(+), 26 deletions(-)
---
diff --git a/configure.in b/configure.in
index 9061812..9642b39 100644
--- a/configure.in
+++ b/configure.in
@@ -505,6 +505,26 @@ else
fi
# ----------------------------------------------------------------------
+# p11-tests
+
+AC_ARG_ENABLE(p11_tests,
+ AC_HELP_STRING([--disable-p11-tests],
+ [Build in p11-tests for testing PKCS#11 modules]))
+
+p11_tests_status="no"
+
+if test "$enable_p11_tests" != "no"; then
+ PKG_CHECK_MODULES(P11_TESTS, p11-tests >= 0.1,
+ p11_tests_status=yes, p11_tests_status=no)
+fi
+
+AM_CONDITIONAL(WITH_P11_TESTS, test "$p11_tests_status" = "yes")
+
+if test "$p11_tests_status" = "yes"; then
+ AC_DEFINE_UNQUOTED(WITH_P11_TESTS, 1, [Run p11-tests module testing])
+fi
+
+# ----------------------------------------------------------------------
GP11_LT_RELEASE=$GP11_MAJOR:$GP11_REVISION:$GP11_AGE
AC_SUBST(GP11_LT_RELEASE)
@@ -520,6 +540,9 @@ AC_SUBST(DAEMON_LIBS)
AC_SUBST(LIBRARY_CFLAGS)
AC_SUBST(LIBRARY_LIBS)
+AC_SUBST(P11_TESTS_CFLAGS)
+AC_SUBST(P11_TESTS_LIBS)
+
BINDIR="$bindir"
AC_SUBST(BINDIR)
@@ -568,6 +591,7 @@ pkcs11/ssh-agent/Makefile
pkcs11/ssh-store/Makefile
pkcs11/ssh-store/tests/Makefile
pkcs11/user-store/Makefile
+pkcs11/user-store/tests/Makefile
po/Makefile.in
secrets/Makefile
tests/Makefile
@@ -591,6 +615,7 @@ echo
echo "BUILD"
echo " Debug Build: $debug_status"
echo " Valgrind: $valgrind_status"
+echo " Pkcs#11 Tests $p11_tests_status"
echo " Tests, -Werror: $tests_status"
echo
diff --git a/pkcs11/roots-store/tests/Makefile.am b/pkcs11/roots-store/tests/Makefile.am
index d0952b3..8f0c7ef 100644
--- a/pkcs11/roots-store/tests/Makefile.am
+++ b/pkcs11/roots-store/tests/Makefile.am
@@ -1,7 +1,16 @@
-# Nothing to do
-all:
-
-p11-tests:
- p11-tests -f p11-tests.conf ../.libs/gck-roots-module.so
-
\ No newline at end of file
+UNIT_AUTO = \
+ test-module.c
+
+UNIT_PROMPT =
+
+UNIT_LIBS = \
+ $(top_builddir)/pkcs11/roots-store/libgck-roots-store.la \
+ $(top_builddir)/pkcs11/gck/libgck.la \
+ $(top_builddir)/egg/libegg.la
+
+include $(top_srcdir)/tests/gtest.make
+
+EXTRA_DIST = \
+ test-data \
+ p11-tests.conf
diff --git a/pkcs11/roots-store/tests/test-module.c b/pkcs11/roots-store/tests/test-module.c
new file mode 100644
index 0000000..885a968
--- /dev/null
+++ b/pkcs11/roots-store/tests/test-module.c
@@ -0,0 +1,34 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* test-module.c: A test PKCS#11 implementation
+
+ Copyright (C) 2009 Stefan Walter
+
+ The Gnome Keyring Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Keyring Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Stef Walter <stef memberwebs com>
+*/
+
+#include "config.h"
+
+#include "roots-store/gck-roots-store.h"
+
+#include "run-auto-test.h"
+
+DEFINE_EXTERNAL(roots_module)
+{
+ CK_FUNCTION_LIST_PTR funcs = gck_roots_store_get_functions ();
+ test_p11_module (funcs, "p11-tests.conf");
+}
diff --git a/pkcs11/ssh-store/tests/Makefile.am b/pkcs11/ssh-store/tests/Makefile.am
index 2a133bc..3ea22a6 100644
--- a/pkcs11/ssh-store/tests/Makefile.am
+++ b/pkcs11/ssh-store/tests/Makefile.am
@@ -12,8 +12,5 @@ UNIT_LIBS = \
include $(top_srcdir)/tests/gtest.make
-p11-tests:
- p11-tests -f p11-tests.conf ../.libs/gck-ssh-store-standalone.so
-
EXTRA_DIST = \
test-data
diff --git a/pkcs11/ssh-store/tests/p11-tests.conf b/pkcs11/ssh-store/tests/p11-tests.conf
index 1578a78..7179012 100644
--- a/pkcs11/ssh-store/tests/p11-tests.conf
+++ b/pkcs11/ssh-store/tests/p11-tests.conf
@@ -1,3 +1,3 @@
# Configuration for running p11-tests on this module
-init-string = directory='pkcs11/ssh-store/tests/test-data'
+init-string = directory='test-data'
login-context-pin = password
diff --git a/pkcs11/ssh-store/tests/test-ssh-module.c b/pkcs11/ssh-store/tests/test-ssh-module.c
index 29cbb73..44a5dbd 100644
--- a/pkcs11/ssh-store/tests/test-ssh-module.c
+++ b/pkcs11/ssh-store/tests/test-ssh-module.c
@@ -28,6 +28,8 @@
#include "ssh-store/gck-ssh-store.h"
+#include "run-auto-test.h"
+
static GMutex *mutex = NULL;
GckModule* _gck_ssh_store_get_module_for_testing (void);
@@ -103,3 +105,9 @@ test_ssh_module_open_session (gboolean writable)
return session;
}
+
+DEFINE_EXTERNAL(ssh_module)
+{
+ CK_FUNCTION_LIST_PTR funcs = gck_ssh_store_get_functions ();
+ test_p11_module (funcs, "p11-tests.conf");
+}
diff --git a/pkcs11/user-store/Makefile.am b/pkcs11/user-store/Makefile.am
index 3804d6d..636d528 100644
--- a/pkcs11/user-store/Makefile.am
+++ b/pkcs11/user-store/Makefile.am
@@ -48,10 +48,10 @@ gck_user_store_standalone_la_LIBADD = \
# -------------------------------------------------------------------------------
-# if WITH_TESTS
-# TESTS_DIR = tests
-# else
+if WITH_TESTS
+TESTS_DIR = tests
+else
TESTS_DIR =
-# endif
+endif
SUBDIRS = . $(TESTS_DIR)
diff --git a/pkcs11/user-store/tests/Makefile.am b/pkcs11/user-store/tests/Makefile.am
index e5fb1f7..1774443 100644
--- a/pkcs11/user-store/tests/Makefile.am
+++ b/pkcs11/user-store/tests/Makefile.am
@@ -1,7 +1,16 @@
-# Nothing to do
-all:
-
-p11-tests:
- p11-tests -f p11-tests.conf ../.libs/gck-user-store-standalone.so
-
\ No newline at end of file
+UNIT_AUTO = \
+ test-module.c
+
+UNIT_PROMPT =
+
+UNIT_LIBS = \
+ $(top_builddir)/pkcs11/user-store/libgck-user-store.la \
+ $(top_builddir)/pkcs11/gck/libgck.la \
+ $(top_builddir)/egg/libegg.la
+
+include $(top_srcdir)/tests/gtest.make
+
+EXTRA_DIST = \
+ test-data \
+ p11-tests.conf
diff --git a/pkcs11/user-store/tests/test-module.c b/pkcs11/user-store/tests/test-module.c
new file mode 100644
index 0000000..d1dfb4e
--- /dev/null
+++ b/pkcs11/user-store/tests/test-module.c
@@ -0,0 +1,34 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* test-module.c: A test PKCS#11 implementation
+
+ Copyright (C) 2009 Stefan Walter
+
+ The Gnome Keyring Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Keyring Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Stef Walter <stef memberwebs com>
+*/
+
+#include "config.h"
+
+#include "user-store/gck-user-store.h"
+
+#include "run-auto-test.h"
+
+DEFINE_EXTERNAL(user_module)
+{
+ CK_FUNCTION_LIST_PTR funcs = gck_user_store_get_functions ();
+ test_p11_module (funcs, "p11-tests.conf");
+}
diff --git a/tests/gtest-helpers.c b/tests/gtest-helpers.c
index ff584af..ae27114 100644
--- a/tests/gtest-helpers.c
+++ b/tests/gtest-helpers.c
@@ -23,6 +23,8 @@
/* This file is included into the main .c file for each gtest unit-test program */
+#include "config.h"
+
#include <glib.h>
#include <gtk/gtk.h>
#include <stdio.h>
@@ -35,6 +37,11 @@
#include "egg/egg-secure-memory.h"
+#include <p11-tests.h>
+
+/* Forward declaration */
+void test_p11_module (CK_FUNCTION_LIST_PTR module, const gchar *config);
+
static GStaticMutex memory_mutex = G_STATIC_MUTEX_INIT;
static const gchar *test_path = NULL;
@@ -147,6 +154,71 @@ test_data_read (const gchar *basename, gsize *n_result)
return (guchar*)result;
}
+#ifdef WITH_P11_TESTS
+
+static void
+on_p11_tests_log (int level, const char *section, const char *message)
+{
+ if (level == P11_TESTS_NONE) {
+ g_message ("%s", message);
+ } else if (level != P11_TESTS_FAIL) {
+ g_message ("%s: %s", section, message);
+ } else {
+ g_print ("/%s/%s: FAIL: %s\n", test_external_name (), section, message);
+ test_external_fail ();
+ }
+}
+
+void
+test_p11_module (CK_FUNCTION_LIST_PTR module, const gchar *config)
+{
+ p11_tests_set_log_func (on_p11_tests_log);
+ p11_tests_set_unexpected (1);
+ p11_tests_set_verbose (0);
+ p11_tests_set_write_session (1);
+ if (config)
+ p11_tests_load_config (config);
+ p11_tests_perform (module);
+}
+
+#else /* !WITH_P11_TESTS */
+
+gint
+test_p11_module (CK_FUNCTION_LIST_PTR module)
+{
+ g_message ("p11-tests support not built in");
+ return 0;
+}
+
+#endif /* !WITH_P11_TESTS */
+
+static const gchar *external_name = NULL;
+static gint external_fails = 0;
+
+void
+test_external_run (const gchar *name, TestExternalFunc func)
+{
+ external_fails = 0;
+ external_name = name;
+ func ();
+ if (external_fails) {
+ g_printerr ("/%s: FAIL: %d failures", name, external_fails);
+ abort();
+ }
+}
+
+const gchar*
+test_external_name (void)
+{
+ return external_name;
+}
+
+void
+test_external_fail (void)
+{
+ ++external_fails;
+}
+
static void
chdir_base_dir (char* argv0)
{
@@ -197,6 +269,10 @@ main (int argc, char* argv[])
start_tests ();
ret = g_test_run ();
+
+ /* Any auxiliary suites */
+ run_externals ();
+
stop_tests();
return ret;
diff --git a/tests/gtest-helpers.h b/tests/gtest-helpers.h
index 311d215..82ec6e7 100644
--- a/tests/gtest-helpers.h
+++ b/tests/gtest-helpers.h
@@ -45,6 +45,16 @@ guchar* test_data_read (const gchar *basename, gsize *n_data);
gchar* test_scratch_filename (const gchar *basename);
gchar* test_data_filename (const gchar *basename);
+#ifdef CRYPTOKI_VERSION_MAJOR
+void test_p11_module (CK_FUNCTION_LIST_PTR module, const gchar *config);
+#endif
+
+
+typedef void (*TestExternalFunc) (void);
+void test_external_run (const gchar *name, TestExternalFunc func);
+const gchar* test_external_name (void);
+void test_external_fail (void);
+
#define DECLARE_SETUP(x) \
void setup_##x(int *v, gconstpointer d)
#define DEFINE_SETUP(x) \
@@ -70,6 +80,11 @@ gchar* test_data_filename (const gchar *basename);
#define DEFINE_STOP(x) \
void stop_##x(void)
+#define DECLARE_EXTERNAL(x) \
+ void external_##x(void)
+#define DEFINE_EXTERNAL(x) \
+ void external_##x(void)
+
/* #define DEFINE_ABORT(x) void abort_x(void *__unused G_GNUC_UNUSED, gconstpointer __data G_GNUC_UNUSED)' */
#endif /* GTEST_HELPERS_H_ */
diff --git a/tests/gtest.make b/tests/gtest.make
index faffd42..785e3f6 100644
--- a/tests/gtest.make
+++ b/tests/gtest.make
@@ -12,13 +12,15 @@ INCLUDES= \
-I$(srcdir)/.. \
-I$(srcdir)/../.. \
$(GTK_CFLAGS) \
- $(GLIB_CFLAGS)
-
+ $(GLIB_CFLAGS) \
+ $(P11_TESTS_CFLAGS)
+
LIBS = \
$(GTK_LIBS) \
$(GLIB_LIBS) \
- $(GTHREAD_LIBS)
-
+ $(GTHREAD_LIBS) \
+ $(P11_TESTS_LIBS)
+
noinst_PROGRAMS= \
run-auto-test \
run-prompt-test
diff --git a/tests/prep-gtest.sh b/tests/prep-gtest.sh
index de550b0..de19a5d 100755
--- a/tests/prep-gtest.sh
+++ b/tests/prep-gtest.sh
@@ -33,6 +33,7 @@ build_header()
sed -ne 's/.*DEFINE_TEST[ ]*(\([^)]\+\))/DECLARE_TEST(\1);/p' $_file
sed -ne 's/.*DEFINE_START[ ]*(\([^)]\+\))/DECLARE_START(\1);/p' $_file
sed -ne 's/.*DEFINE_STOP[ ]*(\([^)]\+\))/DECLARE_STOP(\1);/p' $_file
+ sed -ne 's/.*DEFINE_EXTERNAL[ ]*(\([^)]\+\))/DECLARE_EXTERNAL(\1);/p' $_file
done
echo
}
@@ -83,10 +84,17 @@ build_source()
sed -ne "s/.*DEFINE_TEST(\([^)]\+\)).*/ g_test_add(\"\/$_name\/\1\", int, NULL, $_setup, test_\1, $_teardown);/p" $_file
done
-
echo "}"
echo
-
+
+ # External function
+ echo "static void run_externals (void) {"
+ for _file in $@; do
+ sed -ne "s/.*DEFINE_EXTERNAL(\([^)]\+\)).*/ test_external_run (\"\1\", external_\1);/p" $_file
+ done
+ echo "}"
+ echo
+
echo "#include \"tests/gtest-helpers.c\""
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]