From 603ddbdb7527710c293a762aa5eed51ad05646b3 Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Fri, 28 Apr 2017 14:46:18 +0200 Subject: [PATCH] testutil: Add commodity printing functions test_printf_std{out,err} Reviewed-by: Andy Polyakov Reviewed-by: Rich Salz (Merged from https://github.com/openssl/openssl/pull/3345) --- test/build.info | 7 ++++--- test/testutil/driver.c | 37 +++++++++++++--------------------- test/testutil/output.h | 4 ++++ test/testutil/output_helpers.c | 34 +++++++++++++++++++++++++++++++ test/testutil/tests.c | 14 +++---------- 5 files changed, 59 insertions(+), 37 deletions(-) create mode 100644 test/testutil/output_helpers.c diff --git a/test/build.info b/test/build.info index c8d86f7d13..d5232ec132 100644 --- a/test/build.info +++ b/test/build.info @@ -9,9 +9,10 @@ -} IF[{- !$disabled{tests} -}] LIBS_NO_INST=libtestutil.a - SOURCE[libtestutil.a]=testutil/basic_output.c testutil/driver.c \ - testutil/tests.c testutil/test_main.c testutil/main.c \ - {- rebase_files("../apps", $target{apps_aux_src}) -} + SOURCE[libtestutil.a]=testutil/basic_output.c testutil/output_helpers.c \ + testutil/driver.c testutil/tests.c \ + {- rebase_files("../apps", $target{apps_aux_src}) -} \ + testutil/test_main.c testutil/main.c INCLUDE[libtestutil.a]=.. ../include DEPEND[libtestutil.a]=../libcrypto diff --git a/test/testutil/driver.c b/test/testutil/driver.c index b0bd3e079a..6689a781cd 100644 --- a/test/testutil/driver.c +++ b/test/testutil/driver.c @@ -125,15 +125,6 @@ static void finalize(int success) ERR_print_errors_cb(err_cb, NULL); } -static void helper_printf_stdout(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - test_vprintf_stdout(fmt, ap); - va_end(ap); -} - int run_tests(const char *test_prog_name) { int num_failed = 0; @@ -141,13 +132,13 @@ int run_tests(const char *test_prog_name) int i, j; if (num_tests < 1) - helper_printf_stdout("%*s1..0 # Skipped: %s\n", level, "", - test_prog_name); + test_printf_stdout("%*s1..0 # Skipped: %s\n", level, "", + test_prog_name); else if (level > 0) - helper_printf_stdout("%*s1..%d # Subtest: %s\n", level, "", num_tests, - test_prog_name); + test_printf_stdout("%*s1..%d # Subtest: %s\n", level, "", num_tests, + test_prog_name); else - helper_printf_stdout("%*s1..%d\n", level, "", num_tests); + test_printf_stdout("%*s1..%d\n", level, "", num_tests); test_flush_stdout(); for (i = 0; i != num_tests; ++i) { @@ -162,8 +153,8 @@ int run_tests(const char *test_prog_name) verdict = "not ok"; ++num_failed; } - helper_printf_stdout("%*s%s %d - %s\n", level, "", verdict, i + 1, - all_tests[i].test_case_name); + test_printf_stdout("%*s%s %d - %s\n", level, "", verdict, i + 1, + all_tests[i].test_case_name); test_flush_stdout(); finalize(ret); } else { @@ -171,10 +162,10 @@ int run_tests(const char *test_prog_name) level += 4; if (all_tests[i].subtest) { - helper_printf_stdout("%*s# Subtest: %s\n", level, "", - all_tests[i].test_case_name); - helper_printf_stdout("%*s%d..%d\n", level, "", 1, - all_tests[i].num); + test_printf_stdout("%*s# Subtest: %s\n", level, "", + all_tests[i].test_case_name); + test_printf_stdout("%*s%d..%d\n", level, "", 1, + all_tests[i].num); test_flush_stdout(); } @@ -195,7 +186,7 @@ int run_tests(const char *test_prog_name) verdict = "not ok"; ++num_failed_inner; } - helper_printf_stdout("%*s%s %d\n", level, "", verdict, j + 1); + test_printf_stdout("%*s%s %d\n", level, "", verdict, j + 1); test_flush_stdout(); } } @@ -206,8 +197,8 @@ int run_tests(const char *test_prog_name) verdict = "not ok"; ++num_failed; } - helper_printf_stdout("%*s%s %d - %s\n", level, "", verdict, i + 1, - all_tests[i].test_case_name); + test_printf_stdout("%*s%s %d - %s\n", level, "", verdict, i + 1, + all_tests[i].test_case_name); test_flush_stdout(); } } diff --git a/test/testutil/output.h b/test/testutil/output.h index 5e7d8c0954..1ca12d289f 100644 --- a/test/testutil/output.h +++ b/test/testutil/output.h @@ -27,4 +27,8 @@ int test_vprintf_stderr(const char *fmt, va_list ap); int test_flush_stdout(void); int test_flush_stderr(void); +/* Commodity functions. There's no need to override these */ +int test_printf_stdout(const char *fmt, ...); +int test_printf_stderr(const char *fmt, ...); + #endif /* HEADER_TU_OUTPUT_H */ diff --git a/test/testutil/output_helpers.c b/test/testutil/output_helpers.c new file mode 100644 index 0000000000..93514743e2 --- /dev/null +++ b/test/testutil/output_helpers.c @@ -0,0 +1,34 @@ +/* + * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include "output.h" + +int test_printf_stdout(const char *fmt, ...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + ret = test_vprintf_stdout(fmt, ap); + va_end(ap); + + return ret; +} + +int test_printf_stderr(const char *fmt, ...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + ret = test_vprintf_stderr(fmt, ap); + va_end(ap); + + return ret; +} diff --git a/test/testutil/tests.c b/test/testutil/tests.c index cb6a3bb688..6dfe2424ef 100644 --- a/test/testutil/tests.c +++ b/test/testutil/tests.c @@ -45,29 +45,21 @@ static void test_fail_message(const char *prefix, const char *file, int line, const char *type, const char *fmt, ...) PRINTF_FORMAT(5, 6); -static void helper_printf_stderr(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - test_vprintf_stderr(fmt, ap); - va_end(ap); -} static void test_fail_message_va(const char *prefix, const char *file, int line, const char *type, const char *fmt, va_list ap) { - helper_printf_stderr("%*s# ", subtest_level(), ""); + test_printf_stderr("%*s# ", subtest_level(), ""); test_puts_stderr(prefix != NULL ? prefix : "ERROR"); test_puts_stderr(":"); if (type) - helper_printf_stderr(" (%s)", type); + test_printf_stderr(" (%s)", type); if (fmt != NULL) { test_puts_stderr(" "); test_vprintf_stderr(fmt, ap); } if (file != NULL) { - helper_printf_stderr(" @ %s:%d", file, line); + test_printf_stderr(" @ %s:%d", file, line); } test_puts_stderr("\n"); test_flush_stderr(); -- 2.25.1