summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stef@thewalter.net>2013-07-23 14:53:53 +0200
committerStef Walter <stef@thewalter.net>2013-07-24 16:06:06 +0200
commitd6e09b62cc79cdd798e24de59a955bebab615fa3 (patch)
tree83a56d08ffc7e3d1c72bca15c65242ef4573c952
parent9ff8b0d074d7509645bb5e86e38131ba7b93de40 (diff)
downloadp11-kit-d6e09b62cc79cdd798e24de59a955bebab615fa3.tar.gz
Use simple serial automake test harness
* Add a testing sanity check to see if we're catching errors * Fix a few other testing issues
-rw-r--r--build/Makefile.tests2
-rw-r--r--common/tests/Makefile.am1
-rw-r--r--common/tests/test-tests.c103
-rw-r--r--configure.ac2
-rw-r--r--p11-kit/conf.c2
-rw-r--r--p11-kit/tests/test-init.c1
6 files changed, 108 insertions, 3 deletions
diff --git a/build/Makefile.tests b/build/Makefile.tests
index 3faa7f3..235508f 100644
--- a/build/Makefile.tests
+++ b/build/Makefile.tests
@@ -8,7 +8,7 @@ CUTEST_CFLAGS = \
CUTEST_LIBS = $(top_builddir)/build/libcutest.la
-MEMCHECK_ENV = $(TEST_RUNNER) valgrind --error-exitcode=80 --quiet --trace-children=yes
+MEMCHECK_ENV = $(TEST_RUNNER) valgrind --error-exitcode=80 --quiet
LEAKCHECK_ENV = $(TEST_RUNNER) valgrind --error-exitcode=81 --quiet --leak-check=yes
diff --git a/common/tests/Makefile.am b/common/tests/Makefile.am
index 36292cd..06f2261 100644
--- a/common/tests/Makefile.am
+++ b/common/tests/Makefile.am
@@ -14,6 +14,7 @@ LDADD = \
$(NULL)
CHECK_PROGS = \
+ test-tests \
test-compat \
test-hash \
test-dict \
diff --git a/common/tests/test-tests.c b/common/tests/test-tests.c
new file mode 100644
index 0000000..e88c4b1
--- /dev/null
+++ b/common/tests/test-tests.c
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2013 Red Hat Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the
+ * following disclaimer.
+ * * 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.
+ * * The names of contributors to this software may not be
+ * used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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
+ * COPYRIGHT OWNER OR CONTRIBUTORS 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.
+ *
+ * Author: Stef Walter <stefw@redhat.com>
+ */
+
+#include "config.h"
+#include "CuTest.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+
+static void
+test_success (CuTest *tc)
+{
+ /* Yup, nothing */
+}
+
+
+static void
+test_failure (CuTest *tc)
+{
+ if (getenv ("TEST_FAIL"))
+ CuFail (tc, "Unconditional test failure due to TEST_FAIL environment variable");
+}
+
+static void
+test_memory (CuTest *tc)
+{
+ char *mem;
+
+ if (getenv ("TEST_FAIL")) {
+ mem = malloc (1);
+ free (mem);
+ *mem = 1;
+ }
+}
+
+
+static void
+test_leak (CuTest *tc)
+{
+ char *mem;
+
+ if (getenv ("TEST_FAIL")) {
+ mem = malloc (1);
+ *mem = 1;
+ }
+}
+
+int
+main (void)
+{
+ CuString *output = CuStringNew ();
+ CuSuite* suite = CuSuiteNew ();
+ int ret;
+
+ SUITE_ADD_TEST (suite, test_success);
+
+ if (getenv ("TEST_FAIL")) {
+ SUITE_ADD_TEST (suite, test_failure);
+ SUITE_ADD_TEST (suite, test_memory);
+ SUITE_ADD_TEST (suite, test_leak);
+ }
+
+ CuSuiteRun (suite);
+ CuSuiteSummary (suite, output);
+ CuSuiteDetails (suite, output);
+ printf ("%s\n", output->buffer);
+ ret = suite->failCount;
+ CuSuiteDelete (suite);
+ CuStringDelete (output);
+
+ return ret;
+}
diff --git a/configure.ac b/configure.ac
index 33c1e18..51b4f39 100644
--- a/configure.ac
+++ b/configure.ac
@@ -21,7 +21,7 @@ P11KIT_AGE=0
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([build/m4])
-AM_INIT_AUTOMAKE([1.10])
+AM_INIT_AUTOMAKE([1.10 foreign serial-tests])
AM_SANITY_CHECK
AM_MAINTAINER_MODE([enable])
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])],)
diff --git a/p11-kit/conf.c b/p11-kit/conf.c
index 481ce26..2cdf507 100644
--- a/p11-kit/conf.c
+++ b/p11-kit/conf.c
@@ -417,7 +417,7 @@ load_configs_from_directory (const char *directory,
{
if (stat (path, &st) < 0) {
error = errno;
- p11_message ("couldn't stat path: %s", path);
+ p11_message_err (error, "couldn't stat path: %s", path);
free (path);
break;
}
diff --git a/p11-kit/tests/test-init.c b/p11-kit/tests/test-init.c
index 7df4be9..60c250f 100644
--- a/p11-kit/tests/test-init.c
+++ b/p11-kit/tests/test-init.c
@@ -71,6 +71,7 @@ mock_C_Initialize__with_fork (CK_VOID_PTR init_args)
/* Fork during the initialization */
child = fork ();
if (child == 0) {
+ close (1);
nanosleep (&ts, NULL);
exit (66);
}