Commit 603ddbdb authored by Richard Levitte's avatar Richard Levitte
Browse files

testutil: Add commodity printing functions test_printf_std{out,err}

parent c5657cb7
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -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

+14 −23
Original line number Diff line number Diff line
@@ -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_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_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,7 +153,7 @@ 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,
            test_printf_stdout("%*s%s %d - %s\n", level, "", verdict, i + 1,
                               all_tests[i].test_case_name);
            test_flush_stdout();
            finalize(ret);
@@ -171,9 +162,9 @@ int run_tests(const char *test_prog_name)

            level += 4;
            if (all_tests[i].subtest) {
                helper_printf_stdout("%*s# Subtest: %s\n", level, "",
                test_printf_stdout("%*s# Subtest: %s\n", level, "",
                                   all_tests[i].test_case_name);
                helper_printf_stdout("%*s%d..%d\n", level, "", 1,
                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,7 +197,7 @@ 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,
            test_printf_stdout("%*s%s %d - %s\n", level, "", verdict, i + 1,
                               all_tests[i].test_case_name);
            test_flush_stdout();
        }
+4 −0
Original line number Diff line number Diff line
@@ -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 −0
Original line number Diff line number Diff line
/*
 * 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;
}
+3 −11
Original line number Diff line number Diff line
@@ -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();