mirror of
https://github.com/openssl/openssl.git
synced 2025-01-30 14:01:55 +08:00
testutil: Add commodity printing functions test_printf_std{out,err}
Reviewed-by: Andy Polyakov <appro@openssl.org> Reviewed-by: Rich Salz <rsalz@openssl.org> (Merged from https://github.com/openssl/openssl/pull/3345)
This commit is contained in:
parent
c5657cb710
commit
603ddbdb75
@ -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
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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 */
|
||||
|
34
test/testutil/output_helpers.c
Normal file
34
test/testutil/output_helpers.c
Normal file
@ -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;
|
||||
}
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user