mirror of
git://git.gnupg.org/gnupg.git
synced 2025-02-02 16:43:03 +01:00
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>
This commit is contained in:
parent
cafcd4336a
commit
fbf24cd09a
@ -80,8 +80,11 @@ do_test (int argc, char *argv[])
|
|||||||
ABORT ("1E42B367 has no user id packet");
|
ABORT ("1E42B367 has no user id packet");
|
||||||
uid2 = kb2->pkt->pkt.user_id->name;
|
uid2 = kb2->pkt->pkt.user_id->name;
|
||||||
|
|
||||||
printf ("user id for DBFC6AD9: %s\n", uid1);
|
if (verbose)
|
||||||
printf ("user id for 1E42B367: %s\n", uid2);
|
{
|
||||||
|
printf ("user id for DBFC6AD9: %s\n", uid1);
|
||||||
|
printf ("user id for 1E42B367: %s\n", uid2);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_P ("cache consistency", strcmp (uid1, uid2) != 0);
|
TEST_P ("cache consistency", strcmp (uid1, uid2) != 0);
|
||||||
}
|
}
|
||||||
|
31
g10/test.c
31
g10/test.c
@ -18,6 +18,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "gpg.h"
|
#include "gpg.h"
|
||||||
|
|
||||||
/* A unit test consists of one or more tests. Tests can be broken
|
/* 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. */
|
/* The total number of tests that failed. */
|
||||||
static int tests_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) \
|
#define TEST_GROUP(description) \
|
||||||
do { \
|
do { \
|
||||||
test_group = (description); \
|
test_group = (description); \
|
||||||
@ -92,7 +99,7 @@ static int tests_failed;
|
|||||||
int tests_failed_pre = tests_failed; \
|
int tests_failed_pre = tests_failed; \
|
||||||
CHECK(description, test, expected); \
|
CHECK(description, test, expected); \
|
||||||
if (tests_failed_pre != tests_failed) \
|
if (tests_failed_pre != tests_failed) \
|
||||||
exit (1); \
|
exit_tests (1); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/* Call this if something went wrong. */
|
/* Call this if something went wrong. */
|
||||||
@ -102,19 +109,22 @@ static int tests_failed;
|
|||||||
if (message) \
|
if (message) \
|
||||||
printf (" %s\n", (message)); \
|
printf (" %s\n", (message)); \
|
||||||
\
|
\
|
||||||
exit(1); \
|
exit_tests (1); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/* You need to fill this function in. */
|
/* You need to fill this function in. */
|
||||||
static void do_test (int argc, char *argv[]);
|
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
|
static void
|
||||||
print_results (void)
|
exit_tests (int force)
|
||||||
{
|
{
|
||||||
if (tests_failed == 0)
|
if (tests_failed == 0)
|
||||||
{
|
{
|
||||||
printf ("All %d tests passed.\n", tests);
|
printf ("All %d tests passed.\n", tests);
|
||||||
exit (0);
|
exit (!!force);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -124,7 +134,6 @@ print_results (void)
|
|||||||
printf (" (%d of %d groups)",
|
printf (" (%d of %d groups)",
|
||||||
test_groups_failed, test_groups);
|
test_groups_failed, test_groups);
|
||||||
printf ("\n");
|
printf ("\n");
|
||||||
|
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -132,10 +141,16 @@ print_results (void)
|
|||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
const char *s;
|
||||||
|
|
||||||
(void) test_group;
|
(void) test_group;
|
||||||
|
|
||||||
do_test (argc, argv);
|
s = getenv ("verbose");
|
||||||
atexit (print_results);
|
if (s && *s)
|
||||||
|
verbose = 1;
|
||||||
|
|
||||||
return tests_failed == 0;
|
do_test (argc, argv);
|
||||||
|
exit_tests (0);
|
||||||
|
|
||||||
|
return !!tests_failed;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user