]> granicus.if.org Git - p11-kit/commitdiff
Use simple serial automake test harness
authorStef Walter <stef@thewalter.net>
Tue, 23 Jul 2013 12:53:53 +0000 (14:53 +0200)
committerStef Walter <stef@thewalter.net>
Tue, 23 Jul 2013 21:06:27 +0000 (23:06 +0200)
* Add a testing sanity check to see if we're catching errors
* Fix a few other testing issues

12 files changed:
build/Makefile.tests
common/test.c
common/tests/Makefile.am
common/tests/test-compat.c
common/tests/test-tests.c [new file with mode: 0644]
configure.ac
p11-kit/conf.c
p11-kit/tests/test-deprecated.c
p11-kit/tests/test-init.c
trust/builder.c
trust/tests/test-builder.c
trust/token.c

index 429f5fe78237e17e8a17609fb2f0d89849eee7ca..c26e689767f8e2373e80cf0b3730f0dbdfab82c1 100644 (file)
@@ -5,7 +5,7 @@ TEST_CFLAGS = \
        -DBUILDDIR=\"$(abs_builddir)\" \
        -DP11_KIT_FUTURE_UNSTABLE_API
 
-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
 
index eb0264553ed3d439938f64b62f2b6dae96780922..af0ea96f2b7749713d54a40f5a7dfceaaa9cc546 100644 (file)
@@ -381,7 +381,7 @@ p11_test_copy_setgid (const char *input)
                }
        }
        if (i == ret) {
-               fprintf (stderr, "# no suitable group, skipping test");
+               fprintf (stderr, "# no suitable group, skipping test\n");
                return NULL;
        }
 
index b1a42bd20001ebd5203cb4f095a89e052afa83e0..af4dc15afc604366373d7e262d4d09fde9f12566 100644 (file)
@@ -15,6 +15,7 @@ LDADD = \
        $(NULL)
 
 CHECK_PROGS = \
+       test-tests \
        test-compat \
        test-hash \
        test-dict \
index a54123531829469992ae5602f1ed7a3db07eafe9..fe312f8ea6979a5888d61215f942c3286db18ce4 100644 (file)
@@ -89,7 +89,7 @@ int
 main (int argc,
       char *argv[])
 {
-       p11_test (test_strndup, "/test/strndup");
-       p11_test (test_getauxval, "/test/getauxval");
+       p11_test (test_strndup, "/compat/strndup");
+       p11_test (test_getauxval, "/compat/getauxval");
        return p11_test_run (argc, argv);
 }
diff --git a/common/tests/test-tests.c b/common/tests/test-tests.c
new file mode 100644 (file)
index 0000000..cd48a13
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * 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 "test.h"
+
+#include <stdlib.h>
+
+static void
+test_success (void)
+{
+       /* Yup, nothing */
+}
+
+
+static void
+test_failure (void)
+{
+       if (getenv ("TEST_FAIL")) {
+               p11_test_fail (__FILE__, __LINE__, __FUNCTION__,
+                              "Unconditional test failure due to TEST_FAIL environment variable");
+       }
+}
+
+static void
+test_memory (void)
+{
+       char *mem;
+
+       if (getenv ("TEST_FAIL")) {
+               mem = malloc (1);
+               free (mem);
+               *mem = 1;
+       }
+}
+
+
+static void
+test_leak (void)
+{
+       char *mem;
+
+       if (getenv ("TEST_FAIL")) {
+               mem = malloc (1);
+               *mem = 1;
+       }
+}
+
+int
+main (int argc,
+      char *argv[])
+{
+       p11_test (test_success, "/test/success");
+
+       if (getenv ("TEST_FAIL")) {
+               p11_test (test_failure, "/test/failure");
+               p11_test (test_memory, "/test/memory");
+               p11_test (test_leak, "/test/leak");
+       }
+
+       return p11_test_run (argc, argv);
+}
index 4efdb5778009a2f397ae80f1ceef92ff55b65c9c..0587f6a5b6d1fd248aa7d26ac1ca90d5f1405d6e 100644 (file)
@@ -24,7 +24,7 @@ P11KIT_AGE=0
 AC_CONFIG_HEADERS([config.h])
 AC_CONFIG_MACRO_DIR([build/m4])
 AC_CONFIG_AUX_DIR([build/aux])
-AM_INIT_AUTOMAKE([1.10 foreign])
+AM_INIT_AUTOMAKE([1.10 foreign serial-tests])
 AM_SANITY_CHECK
 AM_MAINTAINER_MODE([enable])
 m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])],)
index 2a6dc5cef7606b38722766d5c7ab560e560aa8eb..ef542f29d7341f5eb398992c0810882dcd45d2fe 100644 (file)
@@ -416,7 +416,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;
                        }
index 7ea8260d279f8c7ad51f57a76a0c993ef7f4f1d7..56f1941db05e044f3438bb699bcfa1f7f500a099 100644 (file)
@@ -250,6 +250,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);
        }
index ebc0666bb0dc5234efc88f53eb2115a62ef0d1f2..c4fcecb875f5e254cf2f91615919bdb05795c5f5 100644 (file)
@@ -73,6 +73,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);
        }
index 038fc88da01375b7893991942bb88d4c58c8a41a..2daadb3ec2ebc8a124287b0486bdc5c3c00f7c9f 100644 (file)
@@ -240,7 +240,7 @@ type_date (p11_builder *builder,
 
        date = attr->pValue;
        memset (&tm, 0, sizeof (tm));
-       tm.tm_year = atoin ((char *)date->year, 4);
+       tm.tm_year = atoin ((char *)date->year, 4) - 1900;
        tm.tm_mon = atoin ((char *)date->month, 2);
        tm.tm_mday = atoin ((char *)date->day, 2);
 
index 6f9fdcce39b0e9278ccc59e225d3a1b60447e75b..1d37924e71b11c854738b08c04e810ad3d9b99b9 100644 (file)
@@ -760,7 +760,9 @@ test_valid_dates (void)
                { CKA_INVALID },
        };
 
-       memcpy (&date, "20001010", sizeof (date));
+       memcpy (date.year, "2000", sizeof (date.year));
+       memcpy (date.month, "10", sizeof (date.month));
+       memcpy (date.day, "10", sizeof (date.day));
        rv = p11_builder_build (test.builder, test.index, attrs, input, &extra);
        assert_num_eq (CKR_OK, rv);
 
@@ -791,11 +793,15 @@ test_invalid_dates (void)
 
        p11_message_quiet ();
 
-       memcpy (&date, "AAAABBCC", sizeof (date));
+       memcpy (date.year, "AAAA", sizeof (date.year));
+       memcpy (date.month, "BB", sizeof (date.month));
+       memcpy (date.day, "CC", sizeof (date.day));
        rv = p11_builder_build (test.builder, test.index, attrs, input, &extra);
        assert_num_eq (CKR_ATTRIBUTE_VALUE_INVALID, rv);
 
-       memcpy (&date, "20001580", sizeof (date));
+       memcpy (date.year, "2000", sizeof (date.year));
+       memcpy (date.month, "15", sizeof (date.month));
+       memcpy (date.day, "80", sizeof (date.day));
        rv = p11_builder_build (test.builder, test.index, attrs, input, &extra);
        assert_num_eq (CKR_ATTRIBUTE_VALUE_INVALID, rv);
 
index d2a12d0c05b395087834f2b2335031299968aa35..97b1fc04f4f7f33343efb62e21c47352407b78d1 100644 (file)
@@ -225,9 +225,8 @@ loader_load_if_file (p11_token *token,
        struct stat sb;
 
        if (stat (path, &sb) < 0) {
-               if (errno == ENOENT) {
+               if (errno != ENOENT)
                        p11_message_err (errno, "couldn't stat path: %s", path);
-               }
 
        } else if (!S_ISDIR (sb.st_mode)) {
                return loader_load_file (token, path, &sb);