testutil: Add commodity printing functions test_printf_std{out,err}
authorRichard Levitte <levitte@openssl.org>
Fri, 28 Apr 2017 12:46:18 +0000 (14:46 +0200)
committerRichard Levitte <levitte@openssl.org>
Fri, 28 Apr 2017 13:59:46 +0000 (15:59 +0200)
Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3345)

test/build.info
test/testutil/driver.c
test/testutil/output.h
test/testutil/output_helpers.c [new file with mode: 0644]
test/testutil/tests.c

index c8d86f7..d5232ec 100644 (file)
@@ -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
 
index b0bd3e0..6689a78 100644 (file)
@@ -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();
         }
     }
index 5e7d8c0..1ca12d2 100644 (file)
@@ -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 (file)
index 0000000..9351474
--- /dev/null
@@ -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;
+}
index cb6a3bb..6dfe242 100644 (file)
 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();