diff options
author | Stef Walter <stef@thewalter.net> | 2013-07-23 14:53:53 +0200 |
---|---|---|
committer | Stef Walter <stef@thewalter.net> | 2013-07-23 23:06:27 +0200 |
commit | b7cc29a78c3c705374ff25223fe14749ddb076b9 (patch) | |
tree | 4d9ec4586d19ed2230f4bdbb2a2e1887f7b254a4 | |
parent | 4d04cfdf2ac078cc4a95ff9a145f0045e074470b (diff) |
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.tests | 2 | ||||
-rw-r--r-- | common/test.c | 2 | ||||
-rw-r--r-- | common/tests/Makefile.am | 1 | ||||
-rw-r--r-- | common/tests/test-compat.c | 4 | ||||
-rw-r--r-- | common/tests/test-tests.c | 93 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | p11-kit/conf.c | 2 | ||||
-rw-r--r-- | p11-kit/tests/test-deprecated.c | 1 | ||||
-rw-r--r-- | p11-kit/tests/test-init.c | 1 | ||||
-rw-r--r-- | trust/builder.c | 2 | ||||
-rw-r--r-- | trust/tests/test-builder.c | 12 | ||||
-rw-r--r-- | trust/token.c | 3 |
12 files changed, 113 insertions, 12 deletions
diff --git a/build/Makefile.tests b/build/Makefile.tests index 429f5fe..c26e689 100644 --- a/build/Makefile.tests +++ b/build/Makefile.tests @@ -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 diff --git a/common/test.c b/common/test.c index eb02645..af0ea96 100644 --- a/common/test.c +++ b/common/test.c @@ -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; } diff --git a/common/tests/Makefile.am b/common/tests/Makefile.am index b1a42bd..af4dc15 100644 --- a/common/tests/Makefile.am +++ b/common/tests/Makefile.am @@ -15,6 +15,7 @@ LDADD = \ $(NULL) CHECK_PROGS = \ + test-tests \ test-compat \ test-hash \ test-dict \ diff --git a/common/tests/test-compat.c b/common/tests/test-compat.c index a541235..fe312f8 100644 --- a/common/tests/test-compat.c +++ b/common/tests/test-compat.c @@ -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 index 0000000..cd48a13 --- /dev/null +++ b/common/tests/test-tests.c @@ -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); +} diff --git a/configure.ac b/configure.ac index 4efdb57..0587f6a 100644 --- a/configure.ac +++ b/configure.ac @@ -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])],) diff --git a/p11-kit/conf.c b/p11-kit/conf.c index 2a6dc5c..ef542f2 100644 --- a/p11-kit/conf.c +++ b/p11-kit/conf.c @@ -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; } diff --git a/p11-kit/tests/test-deprecated.c b/p11-kit/tests/test-deprecated.c index 7ea8260..56f1941 100644 --- a/p11-kit/tests/test-deprecated.c +++ b/p11-kit/tests/test-deprecated.c @@ -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); } diff --git a/p11-kit/tests/test-init.c b/p11-kit/tests/test-init.c index ebc0666..c4fcecb 100644 --- a/p11-kit/tests/test-init.c +++ b/p11-kit/tests/test-init.c @@ -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); } diff --git a/trust/builder.c b/trust/builder.c index 038fc88..2daadb3 100644 --- a/trust/builder.c +++ b/trust/builder.c @@ -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); diff --git a/trust/tests/test-builder.c b/trust/tests/test-builder.c index 6f9fdcc..1d37924 100644 --- a/trust/tests/test-builder.c +++ b/trust/tests/test-builder.c @@ -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); diff --git a/trust/token.c b/trust/token.c index d2a12d0..97b1fc0 100644 --- a/trust/token.c +++ b/trust/token.c @@ -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); |