Move main() from libcryb-test to the test program.

Instead of having libcryb-test provide main() and assume that the test program defines t_prepare() and t_cleanup(), have libcryb-test provide a t_main() function which the test program calls with pointers to its prepare and cleanup functions.
This commit is contained in:
Dag-Erling Smørgrav 2016-03-15 14:29:44 +01:00
parent c68fd1098d
commit 401465d8ea
31 changed files with 168 additions and 102 deletions

View file

@ -53,8 +53,10 @@ extern const char *t_progname;
void t_add_test(t_func *, void *, const char *, ...); void t_add_test(t_func *, void *, const char *, ...);
void t_add_tests(struct t_test *, int); void t_add_tests(struct t_test *, int);
int t_prepare(int, char **); typedef int (*t_prepare_func)(int, char **);
void t_cleanup(void); typedef void (*t_cleanup_func)(void);
void t_main(t_prepare_func, t_cleanup_func, int, char **)
CRYB_NORETURN;
void t_verbose_hex(const uint8_t *, size_t); void t_verbose_hex(const uint8_t *, size_t);
void t_verbose(const char *, ...) void t_verbose(const char *, ...)

View file

@ -221,8 +221,9 @@ usage(void)
exit(1); exit(1);
} }
int void
main(int argc, char *argv[]) t_main(t_prepare_func t_prepare, t_cleanup_func t_cleanup,
int argc, char *argv[])
{ {
unsigned int n, pass, fail; unsigned int n, pass, fail;
size_t nt; size_t nt;
@ -270,6 +271,7 @@ main(int argc, char *argv[])
argv += optind; argv += optind;
/* prepare the test plan */ /* prepare the test plan */
if (t_prepare != NULL)
t_prepare(argc, argv); t_prepare(argc, argv);
if (t_plan_len == 0) if (t_plan_len == 0)
errx(1, "no plan\n"); errx(1, "no plan\n");
@ -281,6 +283,7 @@ main(int argc, char *argv[])
t_run_test(t_plan[n], n + 1) ? ++pass : ++fail; t_run_test(t_plan[n], n + 1) ? ++pass : ++fail;
/* clean up as much as possible before we exit */ /* clean up as much as possible before we exit */
if (t_cleanup != NULL)
t_cleanup(); t_cleanup();
t_fcloseall(); t_fcloseall();
for (n = 0; n < t_plan_len; ++n) { for (n = 0; n < t_plan_len; ++n) {

View file

@ -271,7 +271,7 @@ t_string_trunc(char **desc CRYB_UNUSED, void *arg CRYB_UNUSED)
* Boilerplate * Boilerplate
*/ */
int static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
unsigned int i; unsigned int i;
@ -299,7 +299,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
void int
t_cleanup(void) main(int argc, char *argv[])
{ {
t_main(t_prepare, NULL, argc, argv);
} }

View file

@ -132,7 +132,7 @@ t_adler32(char **desc CRYB_UNUSED, void *arg)
* Boilerplate * Boilerplate
*/ */
int static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
unsigned int i, n; unsigned int i, n;
@ -147,7 +147,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
void int
t_cleanup(void) main(int argc, char *argv[])
{ {
t_main(t_prepare, NULL, argc, argv);
} }

View file

@ -139,7 +139,7 @@ t_aes_dec(char **desc CRYB_UNUSED, void *arg)
* Boilerplate * Boilerplate
*/ */
int static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
unsigned int i, n; unsigned int i, n;
@ -154,7 +154,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
void int
t_cleanup(void) main(int argc, char *argv[])
{ {
t_main(t_prepare, NULL, argc, argv);
} }

View file

@ -95,7 +95,7 @@ T_OC(pfcs)
* Boilerplate * Boilerplate
*/ */
int static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
@ -113,7 +113,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
void int
t_cleanup(void) main(int argc, char *argv[])
{ {
t_main(t_prepare, NULL, argc, argv);
} }

View file

@ -91,7 +91,7 @@ T_ENC(le, 64)
#define T_ENC_ADD(e, w) \ #define T_ENC_ADD(e, w) \
t_add_test(t_##e##w##enc, 0, #e #w "enc"); t_add_test(t_##e##w##enc, 0, #e #w "enc");
int static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
@ -112,7 +112,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
void int
t_cleanup(void) main(int argc, char *argv[])
{ {
t_main(t_prepare, NULL, argc, argv);
} }

View file

@ -279,7 +279,7 @@ t_fletcher64(char **desc, void *arg)
* Boilerplate * Boilerplate
*/ */
int static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
unsigned int i, n; unsigned int i, n;
@ -307,7 +307,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
void int
t_cleanup(void) main(int argc, char *argv[])
{ {
t_main(t_prepare, NULL, argc, argv);
} }

View file

@ -157,7 +157,7 @@ t_hmac_sha1_vector(char **desc CRYB_UNUSED, void *arg)
* Boilerplate * Boilerplate
*/ */
int static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
int i, n; int i, n;
@ -171,7 +171,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
void int
t_cleanup(void) main(int argc, char *argv[])
{ {
t_main(t_prepare, NULL, argc, argv);
} }

View file

@ -162,7 +162,7 @@ t_hmac_sha224_vector(char **desc CRYB_UNUSED, void *arg)
* Boilerplate * Boilerplate
*/ */
int static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
int i, n; int i, n;
@ -176,7 +176,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
void int
t_cleanup(void) main(int argc, char *argv[])
{ {
t_main(t_prepare, NULL, argc, argv);
} }

View file

@ -162,7 +162,7 @@ t_hmac_sha256_vector(char **desc CRYB_UNUSED, void *arg)
* Boilerplate * Boilerplate
*/ */
int static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
int i, n; int i, n;
@ -176,7 +176,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
void int
t_cleanup(void) main(int argc, char *argv[])
{ {
t_main(t_prepare, NULL, argc, argv);
} }

View file

@ -172,7 +172,7 @@ t_hmac_sha384_vector(char **desc CRYB_UNUSED, void *arg)
* Boilerplate * Boilerplate
*/ */
int static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
int i, n; int i, n;
@ -186,7 +186,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
void int
t_cleanup(void) main(int argc, char *argv[])
{ {
t_main(t_prepare, NULL, argc, argv);
} }

View file

@ -182,7 +182,7 @@ t_hmac_sha512_vector(char **desc CRYB_UNUSED, void *arg)
* Boilerplate * Boilerplate
*/ */
int static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
int i, n; int i, n;
@ -196,7 +196,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
void int
t_cleanup(void) main(int argc, char *argv[])
{ {
t_main(t_prepare, NULL, argc, argv);
} }

View file

@ -192,7 +192,7 @@ t_md2_perf(char **desc, void *arg)
* Boilerplate * Boilerplate
*/ */
int static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
int i, n; int i, n;
@ -229,7 +229,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
void int
t_cleanup(void) main(int argc, char *argv[])
{ {
t_main(t_prepare, NULL, argc, argv);
} }

View file

@ -208,7 +208,7 @@ t_md4_perf(char **desc, void *arg)
* Boilerplate * Boilerplate
*/ */
int static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
int i, n; int i, n;
@ -245,7 +245,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
void int
t_cleanup(void) main(int argc, char *argv[])
{ {
t_main(t_prepare, NULL, argc, argv);
} }

View file

@ -208,7 +208,7 @@ t_md5_perf(char **desc, void *arg)
* Boilerplate * Boilerplate
*/ */
int static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
int i, n; int i, n;
@ -245,7 +245,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
void int
t_cleanup(void) main(int argc, char *argv[])
{ {
t_main(t_prepare, NULL, argc, argv);
} }

View file

@ -128,7 +128,7 @@ t_memset_s_null(char **desc CRYB_UNUSED, void *arg)
* Boilerplate * Boilerplate
*/ */
int static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
int i, n; int i, n;
@ -142,7 +142,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
void int
t_cleanup(void) main(int argc, char *argv[])
{ {
t_main(t_prepare, NULL, argc, argv);
} }

View file

@ -1554,7 +1554,7 @@ t_mpi_sub_b_from_zero(char **desc CRYB_UNUSED, void *arg CRYB_UNUSED)
* Boilerplate * Boilerplate
*/ */
int static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
unsigned int i; unsigned int i;
@ -1651,9 +1651,16 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
void static void
t_cleanup(void) t_cleanup(void)
{ {
assert(memcmp(&z, t_zero, sizeof z) == 0); assert(memcmp(&z, t_zero, sizeof z) == 0);
} }
int
main(int argc, char *argv[])
{
t_main(t_prepare, t_cleanup, argc, argv);
}

View file

@ -195,7 +195,7 @@ t_murmur3_32(char **desc CRYB_UNUSED, void *arg)
* Boilerplate * Boilerplate
*/ */
int static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
int i, n; int i, n;
@ -208,7 +208,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
void int
t_cleanup(void) main(int argc, char *argv[])
{ {
t_main(t_prepare, NULL, argc, argv);
} }

View file

@ -92,7 +92,7 @@ t_pearson(char **desc CRYB_UNUSED, void *arg)
* Boilerplate * Boilerplate
*/ */
int static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
int i, n; int i, n;
@ -105,7 +105,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
void int
t_cleanup(void) main(int argc, char *argv[])
{ {
t_main(t_prepare, NULL, argc, argv);
} }

View file

@ -1987,7 +1987,7 @@ t_rc4(char **desc CRYB_UNUSED, void *arg)
* Boilerplate * Boilerplate
*/ */
int static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
unsigned int i, n; unsigned int i, n;
@ -2000,7 +2000,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
void int
t_cleanup(void) main(int argc, char *argv[])
{ {
t_main(t_prepare, NULL, argc, argv);
} }

View file

@ -323,10 +323,12 @@ t_rfc3986(char **desc CRYB_UNUSED, void *arg)
return (ret); return (ret);
} }
/*
* Generate the test plan /***************************************************************************
* Boilerplate
*/ */
int
static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
struct t_case *t; struct t_case *t;
@ -354,10 +356,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
/* int
* Cleanup main(int argc, char *argv[])
*/
void
t_cleanup(void)
{ {
t_main(t_prepare, NULL, argc, argv);
} }

View file

@ -299,10 +299,12 @@ t_rfc4648(char **desc CRYB_UNUSED, void *arg)
return (1); return (1);
} }
/*
* Generate the test plan /***************************************************************************
* Boilerplate
*/ */
int
static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
int i, n; int i, n;
@ -315,10 +317,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
/* int
* Cleanup main(int argc, char *argv[])
*/
void
t_cleanup(void)
{ {
t_main(t_prepare, NULL, argc, argv);
} }

View file

@ -201,7 +201,7 @@ t_sha1_perf(char **desc, void *arg)
* Boilerplate * Boilerplate
*/ */
int static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
int i, n; int i, n;
@ -238,7 +238,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
void int
t_cleanup(void) main(int argc, char *argv[])
{ {
t_main(t_prepare, NULL, argc, argv);
} }

View file

@ -210,7 +210,7 @@ t_sha224_perf(char **desc, void *arg)
* Boilerplate * Boilerplate
*/ */
int static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
int i, n; int i, n;
@ -247,7 +247,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
void int
t_cleanup(void) main(int argc, char *argv[])
{ {
t_main(t_prepare, NULL, argc, argv);
} }

View file

@ -206,7 +206,7 @@ t_sha256_perf(char **desc, void *arg)
* Boilerplate * Boilerplate
*/ */
int static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
int i, n; int i, n;
@ -243,7 +243,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
void int
t_cleanup(void) main(int argc, char *argv[])
{ {
t_main(t_prepare, NULL, argc, argv);
} }

View file

@ -254,7 +254,7 @@ t_sha384_carry(char **desc CRYB_UNUSED, void *arg CRYB_UNUSED)
* Boilerplate * Boilerplate
*/ */
int static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
int i, n; int i, n;
@ -292,7 +292,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
void int
t_cleanup(void) main(int argc, char *argv[])
{ {
t_main(t_prepare, NULL, argc, argv);
} }

View file

@ -266,7 +266,7 @@ t_sha512_carry(char **desc CRYB_UNUSED, void *arg CRYB_UNUSED)
* Boilerplate * Boilerplate
*/ */
int static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
int i, n; int i, n;
@ -304,7 +304,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
void int
t_cleanup(void) main(int argc, char *argv[])
{ {
t_main(t_prepare, NULL, argc, argv);
} }

View file

@ -149,7 +149,7 @@ t_strlcat(char **desc CRYB_UNUSED, void *arg)
* Boilerplate * Boilerplate
*/ */
int static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
int i, n; int i, n;
@ -162,7 +162,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
void int
t_cleanup(void) main(int argc, char *argv[])
{ {
t_main(t_prepare, NULL, argc, argv);
} }

View file

@ -131,7 +131,7 @@ t_strlcmp(char **desc CRYB_UNUSED, void *arg)
* Boilerplate * Boilerplate
*/ */
int static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
int i, n; int i, n;
@ -144,7 +144,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
void int
t_cleanup(void) main(int argc, char *argv[])
{ {
t_main(t_prepare, NULL, argc, argv);
} }

View file

@ -104,7 +104,7 @@ t_strlcpy(char **desc CRYB_UNUSED, void *arg)
* Boilerplate * Boilerplate
*/ */
int static int
t_prepare(int argc, char *argv[]) t_prepare(int argc, char *argv[])
{ {
int i, n; int i, n;
@ -117,7 +117,9 @@ t_prepare(int argc, char *argv[])
return (0); return (0);
} }
void int
t_cleanup(void) main(int argc, char *argv[])
{ {
t_main(t_prepare, NULL, argc, argv);
} }