summaryrefslogtreecommitdiffstats
path: root/g10
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2015-09-10 17:43:13 +0200
committerWerner Koch <wk@gnupg.org>2015-09-10 17:43:37 +0200
commitfbf24cd09abcdc3dec21db4114ab2db99ce21e4c (patch)
treeca8c1a0fdd751ab952a407cd8bf83983dbae6897 /g10
parentpo: Auto-update (diff)
downloadgnupg2-fbf24cd09abcdc3dec21db4114ab2db99ce21e4c.tar.xz
gnupg2-fbf24cd09abcdc3dec21db4114ab2db99ce21e4c.zip
g10: Improve portability of the new test driver.
* g10/test.c: Include stdio.h and stdlib.h. (verbose): New. (print_results): Rename to exit_tests. (main): Remove atexit and call exit_tests. Set verbose. (ASSERT, ABORT): Call exit_tests instead of exit. -- Calling exit from an exit handler is undefined behaviour. It works on Linux but other systems will hit an endless loop. That is indeed unfortunate but we can't do anything about it. Calling _exit() would be possible but that may lead to other problems. Thus we change to call a custom exit function :-(. Using "make check verbose=1" is supported by tests/openpgp and thus we add the same mechanism here. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to '')
-rw-r--r--g10/t-keydb.c7
-rw-r--r--g10/test.c29
2 files changed, 27 insertions, 9 deletions
diff --git a/g10/t-keydb.c b/g10/t-keydb.c
index 0f176431c..634cb05a7 100644
--- a/g10/t-keydb.c
+++ b/g10/t-keydb.c
@@ -80,8 +80,11 @@ do_test (int argc, char *argv[])
ABORT ("1E42B367 has no user id packet");
uid2 = kb2->pkt->pkt.user_id->name;
- printf ("user id for DBFC6AD9: %s\n", uid1);
- printf ("user id for 1E42B367: %s\n", uid2);
+ if (verbose)
+ {
+ printf ("user id for DBFC6AD9: %s\n", uid1);
+ printf ("user id for 1E42B367: %s\n", uid2);
+ }
TEST_P ("cache consistency", strcmp (uid1, uid2) != 0);
}
diff --git a/g10/test.c b/g10/test.c
index 6910f95ad..e9e6b2342 100644
--- a/g10/test.c
+++ b/g10/test.c
@@ -18,6 +18,9 @@
*/
#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+
#include "gpg.h"
/* A unit test consists of one or more tests. Tests can be broken
@@ -38,6 +41,10 @@ static int tests;
/* The total number of tests that failed. */
static int tests_failed;
+/* Flag to request verbose diagnostics. This is set if the envvar
+ "verbose" exists and is not the empty string. */
+static int verbose;
+
#define TEST_GROUP(description) \
do { \
test_group = (description); \
@@ -92,7 +99,7 @@ static int tests_failed;
int tests_failed_pre = tests_failed; \
CHECK(description, test, expected); \
if (tests_failed_pre != tests_failed) \
- exit (1); \
+ exit_tests (1); \
} while (0)
/* Call this if something went wrong. */
@@ -102,19 +109,22 @@ static int tests_failed;
if (message) \
printf (" %s\n", (message)); \
\
- exit(1); \
+ exit_tests (1); \
} while (0)
/* You need to fill this function in. */
static void do_test (int argc, char *argv[]);
+
+/* Print stats and call the real exit. If FORCE is set use
+ EXIT_FAILURE even if no test has failed. */
static void
-print_results (void)
+exit_tests (int force)
{
if (tests_failed == 0)
{
printf ("All %d tests passed.\n", tests);
- exit (0);
+ exit (!!force);
}
else
{
@@ -124,7 +134,6 @@ print_results (void)
printf (" (%d of %d groups)",
test_groups_failed, test_groups);
printf ("\n");
-
exit (1);
}
}
@@ -132,10 +141,16 @@ print_results (void)
int
main (int argc, char *argv[])
{
+ const char *s;
+
(void) test_group;
+ s = getenv ("verbose");
+ if (s && *s)
+ verbose = 1;
+
do_test (argc, argv);
- atexit (print_results);
+ exit_tests (0);
- return tests_failed == 0;
+ return !!tests_failed;
}