diff options
author | Colin Watson <cjwatson@debian.org> | 2015-08-19 14:23:51 +0100 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2015-08-19 16:48:11 +0100 |
commit | 0f0841b2d28b7463267d4d91577e72e3340a1d3a (patch) | |
tree | ba55fcd2b6e2cc22b30f5afb561dbb3da4c8b6c7 /regress/unittests/test_helper/test_helper.c | |
parent | f2a5f5dae656759efb0b76c3d94890b65c197a02 (diff) | |
parent | 8698446b972003b63dfe5dcbdb86acfe986afb85 (diff) |
New upstream release (6.8p1).
Diffstat (limited to 'regress/unittests/test_helper/test_helper.c')
-rw-r--r-- | regress/unittests/test_helper/test_helper.c | 67 |
1 files changed, 61 insertions, 6 deletions
diff --git a/regress/unittests/test_helper/test_helper.c b/regress/unittests/test_helper/test_helper.c index d0bc67833..26ca26b5e 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.2 2014/05/02 09:41:32 andre Exp $ */ | 1 | /* $OpenBSD: test_helper.c,v 1.6 2015/03/03 20:42:49 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2011 Damien Miller <djm@mindrot.org> | 3 | * Copyright (c) 2011 Damien Miller <djm@mindrot.org> |
4 | * | 4 | * |
@@ -21,6 +21,7 @@ | |||
21 | 21 | ||
22 | #include <sys/types.h> | 22 | #include <sys/types.h> |
23 | #include <sys/param.h> | 23 | #include <sys/param.h> |
24 | #include <sys/uio.h> | ||
24 | 25 | ||
25 | #include <fcntl.h> | 26 | #include <fcntl.h> |
26 | #include <stdio.h> | 27 | #include <stdio.h> |
@@ -31,6 +32,7 @@ | |||
31 | #include <string.h> | 32 | #include <string.h> |
32 | #include <assert.h> | 33 | #include <assert.h> |
33 | #include <unistd.h> | 34 | #include <unistd.h> |
35 | #include <signal.h> | ||
34 | 36 | ||
35 | #include <openssl/bn.h> | 37 | #include <openssl/bn.h> |
36 | 38 | ||
@@ -39,6 +41,7 @@ | |||
39 | #endif | 41 | #endif |
40 | 42 | ||
41 | #include "test_helper.h" | 43 | #include "test_helper.h" |
44 | #include "atomicio.h" | ||
42 | 45 | ||
43 | #define TEST_CHECK_INT(r, pred) do { \ | 46 | #define TEST_CHECK_INT(r, pred) do { \ |
44 | switch (pred) { \ | 47 | switch (pred) { \ |
@@ -111,6 +114,7 @@ static u_int test_number = 0; | |||
111 | static test_onerror_func_t *test_onerror = NULL; | 114 | static test_onerror_func_t *test_onerror = NULL; |
112 | static void *onerror_ctx = NULL; | 115 | static void *onerror_ctx = NULL; |
113 | static const char *data_dir = NULL; | 116 | static const char *data_dir = NULL; |
117 | static char subtest_info[512]; | ||
114 | 118 | ||
115 | int | 119 | int |
116 | main(int argc, char **argv) | 120 | main(int argc, char **argv) |
@@ -180,13 +184,36 @@ test_data_file(const char *name) | |||
180 | } | 184 | } |
181 | 185 | ||
182 | void | 186 | void |
187 | test_info(char *s, size_t len) | ||
188 | { | ||
189 | snprintf(s, len, "In test %u: \"%s\"%s%s\n", test_number, | ||
190 | active_test_name == NULL ? "<none>" : active_test_name, | ||
191 | *subtest_info != '\0' ? " - " : "", subtest_info); | ||
192 | } | ||
193 | |||
194 | #ifdef SIGINFO | ||
195 | static void | ||
196 | siginfo(int unused __attribute__((__unused__))) | ||
197 | { | ||
198 | char buf[256]; | ||
199 | |||
200 | test_info(buf, sizeof(buf)); | ||
201 | atomicio(vwrite, STDERR_FILENO, buf, strlen(buf)); | ||
202 | } | ||
203 | #endif | ||
204 | |||
205 | void | ||
183 | test_start(const char *n) | 206 | test_start(const char *n) |
184 | { | 207 | { |
185 | assert(active_test_name == NULL); | 208 | assert(active_test_name == NULL); |
186 | assert((active_test_name = strdup(n)) != NULL); | 209 | assert((active_test_name = strdup(n)) != NULL); |
210 | *subtest_info = '\0'; | ||
187 | if (verbose_mode) | 211 | if (verbose_mode) |
188 | printf("test %u - \"%s\": ", test_number, active_test_name); | 212 | printf("test %u - \"%s\": ", test_number, active_test_name); |
189 | test_number++; | 213 | test_number++; |
214 | #ifdef SIGINFO | ||
215 | signal(SIGINFO, siginfo); | ||
216 | #endif | ||
190 | } | 217 | } |
191 | 218 | ||
192 | void | 219 | void |
@@ -199,6 +226,7 @@ set_onerror_func(test_onerror_func_t *f, void *ctx) | |||
199 | void | 226 | void |
200 | test_done(void) | 227 | test_done(void) |
201 | { | 228 | { |
229 | *subtest_info = '\0'; | ||
202 | assert(active_test_name != NULL); | 230 | assert(active_test_name != NULL); |
203 | free(active_test_name); | 231 | free(active_test_name); |
204 | active_test_name = NULL; | 232 | active_test_name = NULL; |
@@ -211,6 +239,16 @@ test_done(void) | |||
211 | } | 239 | } |
212 | 240 | ||
213 | void | 241 | void |
242 | test_subtest_info(const char *fmt, ...) | ||
243 | { | ||
244 | va_list ap; | ||
245 | |||
246 | va_start(ap, fmt); | ||
247 | vsnprintf(subtest_info, sizeof(subtest_info), fmt, ap); | ||
248 | va_end(ap); | ||
249 | } | ||
250 | |||
251 | void | ||
214 | ssl_err_check(const char *file, int line) | 252 | ssl_err_check(const char *file, int line) |
215 | { | 253 | { |
216 | long openssl_error = ERR_get_error(); | 254 | long openssl_error = ERR_get_error(); |
@@ -256,8 +294,9 @@ static void | |||
256 | test_header(const char *file, int line, const char *a1, const char *a2, | 294 | test_header(const char *file, int line, const char *a1, const char *a2, |
257 | const char *name, enum test_predicate pred) | 295 | const char *name, enum test_predicate pred) |
258 | { | 296 | { |
259 | fprintf(stderr, "\n%s:%d test #%u \"%s\"\n", | 297 | fprintf(stderr, "\n%s:%d test #%u \"%s\"%s%s\n", |
260 | file, line, test_number, active_test_name); | 298 | file, line, test_number, active_test_name, |
299 | *subtest_info != '\0' ? " - " : "", subtest_info); | ||
261 | fprintf(stderr, "ASSERT_%s_%s(%s%s%s) failed:\n", | 300 | fprintf(stderr, "ASSERT_%s_%s(%s%s%s) failed:\n", |
262 | name, pred_name(pred), a1, | 301 | name, pred_name(pred), a1, |
263 | a2 != NULL ? ", " : "", a2 != NULL ? a2 : ""); | 302 | a2 != NULL ? ", " : "", a2 != NULL ? a2 : ""); |
@@ -280,8 +319,13 @@ void | |||
280 | assert_string(const char *file, int line, const char *a1, const char *a2, | 319 | assert_string(const char *file, int line, const char *a1, const char *a2, |
281 | const char *aa1, const char *aa2, enum test_predicate pred) | 320 | const char *aa1, const char *aa2, enum test_predicate pred) |
282 | { | 321 | { |
283 | int r = strcmp(aa1, aa2); | 322 | int r; |
284 | 323 | ||
324 | /* Verify pointers are not NULL */ | ||
325 | assert_ptr(file, line, a1, "NULL", aa1, NULL, TEST_NE); | ||
326 | assert_ptr(file, line, a2, "NULL", aa2, NULL, TEST_NE); | ||
327 | |||
328 | r = strcmp(aa1, aa2); | ||
285 | TEST_CHECK_INT(r, pred); | 329 | TEST_CHECK_INT(r, pred); |
286 | test_header(file, line, a1, a2, "STRING", pred); | 330 | test_header(file, line, a1, a2, "STRING", pred); |
287 | fprintf(stderr, "%12s = %s (len %zu)\n", a1, aa1, strlen(aa1)); | 331 | fprintf(stderr, "%12s = %s (len %zu)\n", a1, aa1, strlen(aa1)); |
@@ -310,8 +354,15 @@ void | |||
310 | assert_mem(const char *file, int line, const char *a1, const char *a2, | 354 | assert_mem(const char *file, int line, const char *a1, const char *a2, |
311 | const void *aa1, const void *aa2, size_t l, enum test_predicate pred) | 355 | const void *aa1, const void *aa2, size_t l, enum test_predicate pred) |
312 | { | 356 | { |
313 | int r = memcmp(aa1, aa2, l); | 357 | int r; |
314 | 358 | ||
359 | if (l == 0) | ||
360 | return; | ||
361 | /* If length is >0, then verify pointers are not NULL */ | ||
362 | assert_ptr(file, line, a1, "NULL", aa1, NULL, TEST_NE); | ||
363 | assert_ptr(file, line, a2, "NULL", aa2, NULL, TEST_NE); | ||
364 | |||
365 | r = memcmp(aa1, aa2, l); | ||
315 | TEST_CHECK_INT(r, pred); | 366 | TEST_CHECK_INT(r, pred); |
316 | test_header(file, line, a1, a2, "STRING", pred); | 367 | test_header(file, line, a1, a2, "STRING", pred); |
317 | fprintf(stderr, "%12s = %s (len %zu)\n", a1, tohex(aa1, MIN(l, 256)), l); | 368 | fprintf(stderr, "%12s = %s (len %zu)\n", a1, tohex(aa1, MIN(l, 256)), l); |
@@ -338,11 +389,15 @@ assert_mem_filled(const char *file, int line, const char *a1, | |||
338 | const void *aa1, u_char v, size_t l, enum test_predicate pred) | 389 | const void *aa1, u_char v, size_t l, enum test_predicate pred) |
339 | { | 390 | { |
340 | size_t where = -1; | 391 | size_t where = -1; |
341 | int r = memvalcmp(aa1, v, l, &where); | 392 | int r; |
342 | char tmp[64]; | 393 | char tmp[64]; |
343 | 394 | ||
344 | if (l == 0) | 395 | if (l == 0) |
345 | return; | 396 | return; |
397 | /* If length is >0, then verify the pointer is not NULL */ | ||
398 | assert_ptr(file, line, a1, "NULL", aa1, NULL, TEST_NE); | ||
399 | |||
400 | r = memvalcmp(aa1, v, l, &where); | ||
346 | TEST_CHECK_INT(r, pred); | 401 | TEST_CHECK_INT(r, pred); |
347 | test_header(file, line, a1, NULL, "MEM_ZERO", pred); | 402 | test_header(file, line, a1, NULL, "MEM_ZERO", pred); |
348 | fprintf(stderr, "%20s = %s%s (len %zu)\n", a1, | 403 | fprintf(stderr, "%20s = %s%s (len %zu)\n", a1, |