Annotate t_add_test() as printf()-like and fix the fallout.

This commit is contained in:
Dag-Erling Smørgrav 2017-03-14 15:07:02 +01:00
parent 52cf1f9d3c
commit 3917a6dfd7
24 changed files with 43 additions and 32 deletions

View file

@ -62,7 +62,8 @@ struct t_test {
extern const char *t_progname; extern const char *t_progname;
extern int t_verbose; extern int t_verbose;
void t_add_test(t_func *, void *, const char *, ...); void t_add_test(t_func *, void *, const char *, ...)
CRYB_PRINTF(3, 4);
void t_add_tests(struct t_test *, int); void t_add_tests(struct t_test *, int);
typedef int (*t_prepare_func)(int, char **); typedef int (*t_prepare_func)(int, char **);

View file

@ -144,7 +144,8 @@ t_prepare(int argc, char *argv[])
n = sizeof t_cases / sizeof t_cases[0]; n = sizeof t_cases / sizeof t_cases[0];
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
if (t_cases[i].sum != 0xffffffffLU) if (t_cases[i].sum != 0xffffffffLU)
t_add_test(t_adler32, &t_cases[i], t_cases[i].desc); t_add_test(t_adler32, &t_cases[i], "%s",
t_cases[i].desc);
return (0); return (0);
} }

View file

@ -149,8 +149,8 @@ t_prepare(int argc, char *argv[])
(void)argv; (void)argv;
n = sizeof t_cases / sizeof t_cases[0]; n = sizeof t_cases / sizeof t_cases[0];
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
t_add_test(t_aes_enc, &t_cases[i], t_cases[i].desc); t_add_test(t_aes_enc, &t_cases[i], "%s", t_cases[i].desc);
t_add_test(t_aes_dec, &t_cases[i], t_cases[i].desc); t_add_test(t_aes_dec, &t_cases[i], "%s", t_cases[i].desc);
} }
return (0); return (0);
} }

View file

@ -298,13 +298,16 @@ t_prepare(int argc, char *argv[])
n = sizeof t_cases / sizeof t_cases[0]; n = sizeof t_cases / sizeof t_cases[0];
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
if (t_cases[i].sum16 != 0xffffU) if (t_cases[i].sum16 != 0xffffU)
t_add_test(t_fletcher16, &t_cases[i], t_cases[i].desc); t_add_test(t_fletcher16, &t_cases[i], "%s",
t_cases[i].desc);
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
if (t_cases[i].sum32 != 0xffffffffLU) if (t_cases[i].sum32 != 0xffffffffLU)
t_add_test(t_fletcher32, &t_cases[i], t_cases[i].desc); t_add_test(t_fletcher32, &t_cases[i], "%s",
t_cases[i].desc);
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
if (t_cases[i].sum64 != 0xffffffffffffffffLLU) if (t_cases[i].sum64 != 0xffffffffffffffffLLU)
t_add_test(t_fletcher64, &t_cases[i], t_cases[i].desc); t_add_test(t_fletcher64, &t_cases[i], "%s",
t_cases[i].desc);
return (0); return (0);
} }

View file

@ -169,7 +169,7 @@ t_prepare(int argc, char *argv[])
n = sizeof t_hmac_sha1_vectors / sizeof t_hmac_sha1_vectors[0]; n = sizeof t_hmac_sha1_vectors / sizeof t_hmac_sha1_vectors[0];
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
t_add_test(t_hmac_sha1_vector, &t_hmac_sha1_vectors[i], t_add_test(t_hmac_sha1_vector, &t_hmac_sha1_vectors[i],
t_hmac_sha1_vectors[i].desc); "%s", t_hmac_sha1_vectors[i].desc);
return (0); return (0);
} }

View file

@ -174,7 +174,7 @@ t_prepare(int argc, char *argv[])
n = sizeof t_hmac_sha224_vectors / sizeof t_hmac_sha224_vectors[0]; n = sizeof t_hmac_sha224_vectors / sizeof t_hmac_sha224_vectors[0];
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
t_add_test(t_hmac_sha224_vector, &t_hmac_sha224_vectors[i], t_add_test(t_hmac_sha224_vector, &t_hmac_sha224_vectors[i],
t_hmac_sha224_vectors[i].desc); "%s", t_hmac_sha224_vectors[i].desc);
return (0); return (0);
} }

View file

@ -174,7 +174,7 @@ t_prepare(int argc, char *argv[])
n = sizeof t_hmac_sha256_vectors / sizeof t_hmac_sha256_vectors[0]; n = sizeof t_hmac_sha256_vectors / sizeof t_hmac_sha256_vectors[0];
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
t_add_test(t_hmac_sha256_vector, &t_hmac_sha256_vectors[i], t_add_test(t_hmac_sha256_vector, &t_hmac_sha256_vectors[i],
t_hmac_sha256_vectors[i].desc); "%s", t_hmac_sha256_vectors[i].desc);
return (0); return (0);
} }

View file

@ -184,7 +184,7 @@ t_prepare(int argc, char *argv[])
n = sizeof t_hmac_sha384_vectors / sizeof t_hmac_sha384_vectors[0]; n = sizeof t_hmac_sha384_vectors / sizeof t_hmac_sha384_vectors[0];
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
t_add_test(t_hmac_sha384_vector, &t_hmac_sha384_vectors[i], t_add_test(t_hmac_sha384_vector, &t_hmac_sha384_vectors[i],
t_hmac_sha384_vectors[i].desc); "%s", t_hmac_sha384_vectors[i].desc);
return (0); return (0);
} }

View file

@ -194,7 +194,7 @@ t_prepare(int argc, char *argv[])
n = sizeof t_hmac_sha512_vectors / sizeof t_hmac_sha512_vectors[0]; n = sizeof t_hmac_sha512_vectors / sizeof t_hmac_sha512_vectors[0];
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
t_add_test(t_hmac_sha512_vector, &t_hmac_sha512_vectors[i], t_add_test(t_hmac_sha512_vector, &t_hmac_sha512_vectors[i],
t_hmac_sha512_vectors[i].desc); "%s", t_hmac_sha512_vectors[i].desc);
return (0); return (0);
} }

View file

@ -140,7 +140,7 @@ t_prepare(int argc, char *argv[])
t_add_test(t_memset_s_null, NULL, "null"); t_add_test(t_memset_s_null, NULL, "null");
n = sizeof t_cases / sizeof t_cases[0]; n = sizeof t_cases / sizeof t_cases[0];
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
t_add_test(t_memset_s, &t_cases[i], t_cases[i].desc); t_add_test(t_memset_s, &t_cases[i], "%s", t_cases[i].desc);
return (0); return (0);
} }

View file

@ -1831,26 +1831,31 @@ t_prepare(int argc, char *argv[])
/* load / store */ /* load / store */
for (i = 0; i < sizeof t_load_cases / sizeof t_load_cases[0]; ++i) for (i = 0; i < sizeof t_load_cases / sizeof t_load_cases[0]; ++i)
t_add_test(t_mpi_load, &t_load_cases[i], t_load_cases[i].desc); t_add_test(t_mpi_load, &t_load_cases[i], "%s",
t_load_cases[i].desc);
t_add_test(t_mpi_exact_load, NULL, "exact load"); t_add_test(t_mpi_exact_load, NULL, "exact load");
t_add_test(t_mpi_large_load, NULL, "large load"); t_add_test(t_mpi_large_load, NULL, "large load");
t_add_test(t_mpi_large_load_fail, NULL, "large load (failure)"); t_add_test(t_mpi_large_load_fail, NULL, "large load (failure)");
/* comparison */ /* comparison */
for (i = 0; i < sizeof t_cmp_cases / sizeof t_cmp_cases[0]; ++i) for (i = 0; i < sizeof t_cmp_cases / sizeof t_cmp_cases[0]; ++i)
t_add_test(t_mpi_cmp, &t_cmp_cases[i], t_cmp_cases[i].desc); t_add_test(t_mpi_cmp, &t_cmp_cases[i], "%s",
t_cmp_cases[i].desc);
/* left / right shift */ /* left / right shift */
for (i = 0; i < sizeof t_lsh_cases / sizeof t_lsh_cases[0]; ++i) for (i = 0; i < sizeof t_lsh_cases / sizeof t_lsh_cases[0]; ++i)
t_add_test(t_mpi_lsh, &t_lsh_cases[i], t_lsh_cases[i].desc); t_add_test(t_mpi_lsh, &t_lsh_cases[i], "%s",
t_lsh_cases[i].desc);
t_add_test(t_mpi_large_lsh, NULL, "large left shift"); t_add_test(t_mpi_large_lsh, NULL, "large left shift");
t_add_test(t_mpi_large_lsh_fail, NULL, "large left shift (failure)"); t_add_test(t_mpi_large_lsh_fail, NULL, "large left shift (failure)");
for (i = 0; i < sizeof t_rsh_cases / sizeof t_rsh_cases[0]; ++i) for (i = 0; i < sizeof t_rsh_cases / sizeof t_rsh_cases[0]; ++i)
t_add_test(t_mpi_rsh, &t_rsh_cases[i], t_rsh_cases[i].desc); t_add_test(t_mpi_rsh, &t_rsh_cases[i], "%s",
t_rsh_cases[i].desc);
/* addition */ /* addition */
for (i = 0; i < sizeof t_add_cases / sizeof t_add_cases[0]; ++i) for (i = 0; i < sizeof t_add_cases / sizeof t_add_cases[0]; ++i)
t_add_test(t_mpi_add_tc, &t_add_cases[i], t_add_cases[i].desc); t_add_test(t_mpi_add_tc, &t_add_cases[i], "%s",
t_add_cases[i].desc);
t_add_test(t_mpi_add, NULL, "x = a + b"); t_add_test(t_mpi_add, NULL, "x = a + b");
t_add_test(t_mpi_add_fail1, NULL, "x = a + b (failure 1)"); t_add_test(t_mpi_add_fail1, NULL, "x = a + b (failure 1)");
t_add_test(t_mpi_add_fail2, NULL, "x = a + b (failure 2)"); t_add_test(t_mpi_add_fail2, NULL, "x = a + b (failure 2)");
@ -1869,7 +1874,8 @@ t_prepare(int argc, char *argv[])
/* subtraction */ /* subtraction */
for (i = 0; i < sizeof t_sub_cases / sizeof t_sub_cases[0]; ++i) for (i = 0; i < sizeof t_sub_cases / sizeof t_sub_cases[0]; ++i)
t_add_test(t_mpi_sub_tc, &t_sub_cases[i], t_sub_cases[i].desc); t_add_test(t_mpi_sub_tc, &t_sub_cases[i], "%s",
t_sub_cases[i].desc);
t_add_test(t_mpi_sub, NULL, "x = a - b"); t_add_test(t_mpi_sub, NULL, "x = a - b");
t_add_test(t_mpi_sub_fail, NULL, "x = a - b (failure)"); t_add_test(t_mpi_sub_fail, NULL, "x = a - b (failure)");
t_add_test(t_mpi_sub_b_from_a, NULL, "a = a - b"); t_add_test(t_mpi_sub_b_from_a, NULL, "a = a - b");

View file

@ -206,7 +206,7 @@ t_prepare(int argc, char *argv[])
(void)argv; (void)argv;
n = sizeof t_cases / sizeof t_cases[0]; n = sizeof t_cases / sizeof t_cases[0];
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
t_add_test(t_murmur3_32, &t_cases[i], t_cases[i].desc); t_add_test(t_murmur3_32, &t_cases[i], "%s", t_cases[i].desc);
return (0); return (0);
} }

View file

@ -103,7 +103,7 @@ t_prepare(int argc, char *argv[])
(void)argv; (void)argv;
n = sizeof t_cases / sizeof t_cases[0]; n = sizeof t_cases / sizeof t_cases[0];
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
t_add_test(t_pearson, &t_cases[i], t_cases[i].desc); t_add_test(t_pearson, &t_cases[i], "%s", t_cases[i].desc);
return (0); return (0);
} }

View file

@ -1998,7 +1998,7 @@ t_prepare(int argc, char *argv[])
(void)argv; (void)argv;
n = sizeof t_cases / sizeof t_cases[0]; n = sizeof t_cases / sizeof t_cases[0];
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
t_add_test(t_rc4, &t_cases[i], t_cases[i].desc); t_add_test(t_rc4, &t_cases[i], "%s", t_cases[i].desc);
return (0); return (0);
} }

View file

@ -339,7 +339,7 @@ t_prepare(int argc, char *argv[])
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
t = &t_cases[i]; t = &t_cases[i];
if (t->desc) { if (t->desc) {
t_add_test(t_rfc3986, t, t->desc); t_add_test(t_rfc3986, t, "%s", t->desc);
} else if (t->ret == 0) { } else if (t->ret == 0) {
t_add_test(t_rfc3986, t, t_add_test(t_rfc3986, t,
"%s \"%s\" -> \"%s\"", "%s \"%s\" -> \"%s\"",

View file

@ -318,7 +318,7 @@ t_prepare(int argc, char *argv[])
(void)argv; (void)argv;
n = sizeof t_cases / sizeof t_cases[0]; n = sizeof t_cases / sizeof t_cases[0];
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
t_add_test(t_rfc4648, &t_cases[i], t_cases[i].desc); t_add_test(t_rfc4648, &t_cases[i], "%s", t_cases[i].desc);
return (0); return (0);
} }

View file

@ -213,7 +213,7 @@ t_prepare(int argc, char *argv[])
n = sizeof t_sha1_vectors / sizeof t_sha1_vectors[0]; n = sizeof t_sha1_vectors / sizeof t_sha1_vectors[0];
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
t_add_test(t_sha1_vector, &t_sha1_vectors[i], t_add_test(t_sha1_vector, &t_sha1_vectors[i],
t_sha1_vectors[i].desc); "%s", t_sha1_vectors[i].desc);
#if !defined(WITH_OPENSSL) && !defined(WITH_RSAREF) #if !defined(WITH_OPENSSL) && !defined(WITH_RSAREF)
/* /*
* Run test vector 5 (md5 test vector 7, which is 80 characters * Run test vector 5 (md5 test vector 7, which is 80 characters

View file

@ -222,7 +222,7 @@ t_prepare(int argc, char *argv[])
n = sizeof t_sha224_vectors / sizeof t_sha224_vectors[0]; n = sizeof t_sha224_vectors / sizeof t_sha224_vectors[0];
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
t_add_test(t_sha224_vector, &t_sha224_vectors[i], t_add_test(t_sha224_vector, &t_sha224_vectors[i],
t_sha224_vectors[i].desc); "%s", t_sha224_vectors[i].desc);
#if !defined(WITH_OPENSSL) && !defined(WITH_RSAREF) #if !defined(WITH_OPENSSL) && !defined(WITH_RSAREF)
/* /*
* Run test vector 5 (md5 test vector 7, which is 80 characters * Run test vector 5 (md5 test vector 7, which is 80 characters

View file

@ -218,7 +218,7 @@ t_prepare(int argc, char *argv[])
n = sizeof t_sha256_vectors / sizeof t_sha256_vectors[0]; n = sizeof t_sha256_vectors / sizeof t_sha256_vectors[0];
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
t_add_test(t_sha256_vector, &t_sha256_vectors[i], t_add_test(t_sha256_vector, &t_sha256_vectors[i],
t_sha256_vectors[i].desc); "%s", t_sha256_vectors[i].desc);
#if !defined(WITH_OPENSSL) && !defined(WITH_RSAREF) #if !defined(WITH_OPENSSL) && !defined(WITH_RSAREF)
/* /*
* Run test vector 5 (md5 test vector 7, which is 80 characters * Run test vector 5 (md5 test vector 7, which is 80 characters

View file

@ -266,7 +266,7 @@ t_prepare(int argc, char *argv[])
n = sizeof t_sha384_vectors / sizeof t_sha384_vectors[0]; n = sizeof t_sha384_vectors / sizeof t_sha384_vectors[0];
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
t_add_test(t_sha384_vector, &t_sha384_vectors[i], t_add_test(t_sha384_vector, &t_sha384_vectors[i],
t_sha384_vectors[i].desc); "%s", t_sha384_vectors[i].desc);
#if !defined(WITH_OPENSSL) && !defined(WITH_RSAREF) #if !defined(WITH_OPENSSL) && !defined(WITH_RSAREF)
/* /*
* Run test vector 5 (md5 test vector 7, which is 80 characters * Run test vector 5 (md5 test vector 7, which is 80 characters

View file

@ -278,7 +278,7 @@ t_prepare(int argc, char *argv[])
n = sizeof t_sha512_vectors / sizeof t_sha512_vectors[0]; n = sizeof t_sha512_vectors / sizeof t_sha512_vectors[0];
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
t_add_test(t_sha512_vector, &t_sha512_vectors[i], t_add_test(t_sha512_vector, &t_sha512_vectors[i],
t_sha512_vectors[i].desc); "%s", t_sha512_vectors[i].desc);
#if !defined(WITH_OPENSSL) && !defined(WITH_RSAREF) #if !defined(WITH_OPENSSL) && !defined(WITH_RSAREF)
/* /*
* Run test vector 5 (md5 test vector 7, which is 80 characters * Run test vector 5 (md5 test vector 7, which is 80 characters

View file

@ -160,7 +160,7 @@ t_prepare(int argc, char *argv[])
(void)argv; (void)argv;
n = sizeof t_cases / sizeof t_cases[0]; n = sizeof t_cases / sizeof t_cases[0];
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
t_add_test(t_strlcat, &t_cases[i], t_cases[i].desc); t_add_test(t_strlcat, &t_cases[i], "%s", t_cases[i].desc);
return (0); return (0);
} }

View file

@ -141,7 +141,7 @@ t_prepare(int argc, char *argv[])
(void)argv; (void)argv;
n = sizeof t_cases / sizeof t_cases[0]; n = sizeof t_cases / sizeof t_cases[0];
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
t_add_test(t_strlcmp, &t_cases[i], t_cases[i].desc); t_add_test(t_strlcmp, &t_cases[i], "%s", t_cases[i].desc);
return (0); return (0);
} }

View file

@ -115,7 +115,7 @@ t_prepare(int argc, char *argv[])
(void)argv; (void)argv;
n = sizeof t_cases / sizeof t_cases[0]; n = sizeof t_cases / sizeof t_cases[0];
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
t_add_test(t_strlcpy, &t_cases[i], t_cases[i].desc); t_add_test(t_strlcpy, &t_cases[i], "%s", t_cases[i].desc);
return (0); return (0);
} }