diff options
Diffstat (limited to 'regress/unittests/test_helper')
-rw-r--r-- | regress/unittests/test_helper/test_helper.c | 29 | ||||
-rw-r--r-- | regress/unittests/test_helper/test_helper.h | 4 |
2 files changed, 29 insertions, 4 deletions
diff --git a/regress/unittests/test_helper/test_helper.c b/regress/unittests/test_helper/test_helper.c index e7a47b265..9014ce8e4 100644 --- a/regress/unittests/test_helper/test_helper.c +++ b/regress/unittests/test_helper/test_helper.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: test_helper.c,v 1.11 2018/11/23 02:53:57 dtucker Exp $ */ | 1 | /* $OpenBSD: test_helper.c,v 1.12 2019/08/02 01:41:24 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2011 Damien Miller <djm@mindrot.org> | 3 | * Copyright (c) 2011 Damien Miller <djm@mindrot.org> |
4 | * | 4 | * |
@@ -23,6 +23,7 @@ | |||
23 | #include <sys/param.h> | 23 | #include <sys/param.h> |
24 | #include <sys/uio.h> | 24 | #include <sys/uio.h> |
25 | 25 | ||
26 | #include <stdarg.h> | ||
26 | #include <fcntl.h> | 27 | #include <fcntl.h> |
27 | #include <stdio.h> | 28 | #include <stdio.h> |
28 | #ifdef HAVE_STDINT_H | 29 | #ifdef HAVE_STDINT_H |
@@ -34,8 +35,10 @@ | |||
34 | #include <unistd.h> | 35 | #include <unistd.h> |
35 | #include <signal.h> | 36 | #include <signal.h> |
36 | 37 | ||
38 | #ifdef WITH_OPENSSL | ||
37 | #include <openssl/bn.h> | 39 | #include <openssl/bn.h> |
38 | #include <openssl/err.h> | 40 | #include <openssl/err.h> |
41 | #endif | ||
39 | 42 | ||
40 | #if defined(HAVE_STRNVIS) && defined(HAVE_VIS_H) && !defined(BROKEN_STRNVIS) | 43 | #if defined(HAVE_STRNVIS) && defined(HAVE_VIS_H) && !defined(BROKEN_STRNVIS) |
41 | # include <vis.h> | 44 | # include <vis.h> |
@@ -126,7 +129,9 @@ main(int argc, char **argv) | |||
126 | int ch; | 129 | int ch; |
127 | 130 | ||
128 | seed_rng(); | 131 | seed_rng(); |
132 | #ifdef WITH_OPENSSL | ||
129 | ERR_load_CRYPTO_strings(); | 133 | ERR_load_CRYPTO_strings(); |
134 | #endif | ||
130 | 135 | ||
131 | /* Handle systems without __progname */ | 136 | /* Handle systems without __progname */ |
132 | if (__progname == NULL) { | 137 | if (__progname == NULL) { |
@@ -287,6 +292,7 @@ test_subtest_info(const char *fmt, ...) | |||
287 | void | 292 | void |
288 | ssl_err_check(const char *file, int line) | 293 | ssl_err_check(const char *file, int line) |
289 | { | 294 | { |
295 | #ifdef WITH_OPENSSL | ||
290 | long openssl_error = ERR_get_error(); | 296 | long openssl_error = ERR_get_error(); |
291 | 297 | ||
292 | if (openssl_error == 0) | 298 | if (openssl_error == 0) |
@@ -294,6 +300,10 @@ ssl_err_check(const char *file, int line) | |||
294 | 300 | ||
295 | fprintf(stderr, "\n%s:%d: uncaught OpenSSL error: %s", | 301 | fprintf(stderr, "\n%s:%d: uncaught OpenSSL error: %s", |
296 | file, line, ERR_error_string(openssl_error, NULL)); | 302 | file, line, ERR_error_string(openssl_error, NULL)); |
303 | #else /* WITH_OPENSSL */ | ||
304 | fprintf(stderr, "\n%s:%d: uncaught OpenSSL error ", | ||
305 | file, line); | ||
306 | #endif /* WITH_OPENSSL */ | ||
297 | abort(); | 307 | abort(); |
298 | } | 308 | } |
299 | 309 | ||
@@ -338,6 +348,7 @@ test_header(const char *file, int line, const char *a1, const char *a2, | |||
338 | a2 != NULL ? ", " : "", a2 != NULL ? a2 : ""); | 348 | a2 != NULL ? ", " : "", a2 != NULL ? a2 : ""); |
339 | } | 349 | } |
340 | 350 | ||
351 | #ifdef WITH_OPENSSL | ||
341 | void | 352 | void |
342 | assert_bignum(const char *file, int line, const char *a1, const char *a2, | 353 | assert_bignum(const char *file, int line, const char *a1, const char *a2, |
343 | const BIGNUM *aa1, const BIGNUM *aa2, enum test_predicate pred) | 354 | const BIGNUM *aa1, const BIGNUM *aa2, enum test_predicate pred) |
@@ -350,6 +361,7 @@ assert_bignum(const char *file, int line, const char *a1, const char *a2, | |||
350 | fprintf(stderr, "%12s = 0x%s\n", a2, BN_bn2hex(aa2)); | 361 | fprintf(stderr, "%12s = 0x%s\n", a2, BN_bn2hex(aa2)); |
351 | test_die(); | 362 | test_die(); |
352 | } | 363 | } |
364 | #endif | ||
353 | 365 | ||
354 | void | 366 | void |
355 | assert_string(const char *file, int line, const char *a1, const char *a2, | 367 | assert_string(const char *file, int line, const char *a1, const char *a2, |
@@ -391,6 +403,8 @@ assert_mem(const char *file, int line, const char *a1, const char *a2, | |||
391 | const void *aa1, const void *aa2, size_t l, enum test_predicate pred) | 403 | const void *aa1, const void *aa2, size_t l, enum test_predicate pred) |
392 | { | 404 | { |
393 | int r; | 405 | int r; |
406 | char *aa1_tohex = NULL; | ||
407 | char *aa2_tohex = NULL; | ||
394 | 408 | ||
395 | if (l == 0) | 409 | if (l == 0) |
396 | return; | 410 | return; |
@@ -401,8 +415,12 @@ assert_mem(const char *file, int line, const char *a1, const char *a2, | |||
401 | r = memcmp(aa1, aa2, l); | 415 | r = memcmp(aa1, aa2, l); |
402 | TEST_CHECK_INT(r, pred); | 416 | TEST_CHECK_INT(r, pred); |
403 | test_header(file, line, a1, a2, "STRING", pred); | 417 | test_header(file, line, a1, a2, "STRING", pred); |
404 | fprintf(stderr, "%12s = %s (len %zu)\n", a1, tohex(aa1, MIN(l, 256)), l); | 418 | aa1_tohex = tohex(aa1, MIN(l, 256)); |
405 | fprintf(stderr, "%12s = %s (len %zu)\n", a2, tohex(aa2, MIN(l, 256)), l); | 419 | aa2_tohex = tohex(aa2, MIN(l, 256)); |
420 | fprintf(stderr, "%12s = %s (len %zu)\n", a1, aa1_tohex, l); | ||
421 | fprintf(stderr, "%12s = %s (len %zu)\n", a2, aa2_tohex, l); | ||
422 | free(aa1_tohex); | ||
423 | free(aa2_tohex); | ||
406 | test_die(); | 424 | test_die(); |
407 | } | 425 | } |
408 | 426 | ||
@@ -427,6 +445,7 @@ assert_mem_filled(const char *file, int line, const char *a1, | |||
427 | size_t where = -1; | 445 | size_t where = -1; |
428 | int r; | 446 | int r; |
429 | char tmp[64]; | 447 | char tmp[64]; |
448 | char *aa1_tohex = NULL; | ||
430 | 449 | ||
431 | if (l == 0) | 450 | if (l == 0) |
432 | return; | 451 | return; |
@@ -436,8 +455,10 @@ assert_mem_filled(const char *file, int line, const char *a1, | |||
436 | r = memvalcmp(aa1, v, l, &where); | 455 | r = memvalcmp(aa1, v, l, &where); |
437 | TEST_CHECK_INT(r, pred); | 456 | TEST_CHECK_INT(r, pred); |
438 | test_header(file, line, a1, NULL, "MEM_ZERO", pred); | 457 | test_header(file, line, a1, NULL, "MEM_ZERO", pred); |
458 | aa1_tohex = tohex(aa1, MIN(l, 20)); | ||
439 | fprintf(stderr, "%20s = %s%s (len %zu)\n", a1, | 459 | fprintf(stderr, "%20s = %s%s (len %zu)\n", a1, |
440 | tohex(aa1, MIN(l, 20)), l > 20 ? "..." : "", l); | 460 | aa1_tohex, l > 20 ? "..." : "", l); |
461 | free(aa1_tohex); | ||
441 | snprintf(tmp, sizeof(tmp), "(%s)[%zu]", a1, where); | 462 | snprintf(tmp, sizeof(tmp), "(%s)[%zu]", a1, where); |
442 | fprintf(stderr, "%20s = 0x%02x (expected 0x%02x)\n", tmp, | 463 | fprintf(stderr, "%20s = 0x%02x (expected 0x%02x)\n", tmp, |
443 | ((u_char *)aa1)[where], v); | 464 | ((u_char *)aa1)[where], v); |
diff --git a/regress/unittests/test_helper/test_helper.h b/regress/unittests/test_helper/test_helper.h index 1f893c8dd..66302201c 100644 --- a/regress/unittests/test_helper/test_helper.h +++ b/regress/unittests/test_helper/test_helper.h | |||
@@ -27,8 +27,10 @@ | |||
27 | # include <stdint.h> | 27 | # include <stdint.h> |
28 | #endif | 28 | #endif |
29 | 29 | ||
30 | #ifdef WITH_OPENSSL | ||
30 | #include <openssl/bn.h> | 31 | #include <openssl/bn.h> |
31 | #include <openssl/err.h> | 32 | #include <openssl/err.h> |
33 | #endif | ||
32 | 34 | ||
33 | enum test_predicate { | 35 | enum test_predicate { |
34 | TEST_EQ, TEST_NE, TEST_LT, TEST_LE, TEST_GT, TEST_GE | 36 | TEST_EQ, TEST_NE, TEST_LT, TEST_LE, TEST_GT, TEST_GE |
@@ -50,9 +52,11 @@ int test_is_slow(void); | |||
50 | void test_subtest_info(const char *fmt, ...) | 52 | void test_subtest_info(const char *fmt, ...) |
51 | __attribute__((format(printf, 1, 2))); | 53 | __attribute__((format(printf, 1, 2))); |
52 | void ssl_err_check(const char *file, int line); | 54 | void ssl_err_check(const char *file, int line); |
55 | #ifdef WITH_OPENSSL | ||
53 | void assert_bignum(const char *file, int line, | 56 | void assert_bignum(const char *file, int line, |
54 | const char *a1, const char *a2, | 57 | const char *a1, const char *a2, |
55 | const BIGNUM *aa1, const BIGNUM *aa2, enum test_predicate pred); | 58 | const BIGNUM *aa1, const BIGNUM *aa2, enum test_predicate pred); |
59 | #endif | ||
56 | void assert_string(const char *file, int line, | 60 | void assert_string(const char *file, int line, |
57 | const char *a1, const char *a2, | 61 | const char *a1, const char *a2, |
58 | const char *aa1, const char *aa2, enum test_predicate pred); | 62 | const char *aa1, const char *aa2, enum test_predicate pred); |