testutil: Fix non-standard subtest output
[openssl.git] / test / testutil / driver.c
index 29c97a9..7be6d2f 100644 (file)
@@ -8,6 +8,8 @@
  */
 
 #include "../testutil.h"
+#include "output.h"
+#include "tu_local.h"
 
 #include <string.h>
 #include <assert.h>
@@ -82,11 +84,6 @@ static int should_report_leaks()
 }
 #endif
 
-static int err_cb(const char *str, size_t len, void *u)
-{
-    return test_puts_stderr(str);
-}
-
 void setup_test()
 {
     char *TAP_levels = getenv("HARNESS_OSSL_LEVEL");
@@ -106,7 +103,8 @@ void setup_test()
 int finish_test(int ret)
 {
 #ifndef OPENSSL_NO_CRYPTO_MDEBUG
-    if (should_report_leaks() && CRYPTO_mem_leaks_cb(err_cb, NULL) <= 0)
+    if (should_report_leaks()
+        && CRYPTO_mem_leaks_cb(openssl_error_cb, NULL) <= 0)
         return EXIT_FAILURE;
 #endif
 
@@ -120,16 +118,14 @@ static void finalize(int success)
     if (success)
         ERR_clear_error();
     else
-        ERR_print_errors_cb(err_cb, NULL);
+        ERR_print_errors_cb(openssl_error_cb, NULL);
 }
 
-static void helper_printf_stdout(const char *fmt, ...)
-{
-    va_list ap;
+static const char *test_title = NULL;
 
-    va_start(ap, fmt);
-    test_vprintf_stdout(fmt, ap);
-    va_end(ap);
+void set_test_title(const char *title)
+{
+    test_title = title;
 }
 
 int run_tests(const char *test_prog_name)
@@ -138,19 +134,22 @@ int run_tests(const char *test_prog_name)
     char *verdict = NULL;
     int i, j;
 
-    if (num_tests < 1)
-        helper_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);
-    else
-        helper_printf_stdout("%*s1..%d\n", level, "", num_tests);
+    if (num_tests < 1) {
+        test_printf_stdout("%*s1..0 # Skipped: %s\n", level, "",
+                           test_prog_name);
+    } else {
+        if (level > 0)
+            test_printf_stdout("%*s# Subtest: %s\n", level, "", test_prog_name);
+        test_printf_stdout("%*s1..%d\n", level, "", num_tests);
+    }
     test_flush_stdout();
 
     for (i = 0; i != num_tests; ++i) {
         if (all_tests[i].num == -1) {
-            int ret = all_tests[i].test_fn();
+            int ret = 0;
+
+            set_test_title(all_tests[i].test_case_name);
+            ret = all_tests[i].test_fn();
 
             test_flush_stdout();
             test_flush_stderr();
@@ -160,8 +159,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,
+                               test_title);
             test_flush_stdout();
             finalize(ret);
         } else {
@@ -169,15 +168,18 @@ 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();
             }
 
             for (j = 0; j < all_tests[i].num; j++) {
-                int ret = all_tests[i].param_test_fn(j);
+                int ret = 0;
+
+                set_test_title(NULL);
+                ret = all_tests[i].param_test_fn(j);
 
                 test_flush_stdout();
                 test_flush_stderr();
@@ -193,7 +195,12 @@ 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);
+                    if (test_title != NULL)
+                        test_printf_stdout("%*s%s %d - %s\n", level, "", verdict,
+                                           j + 1, test_title);
+                    else
+                        test_printf_stdout("%*s%s %d\n", level, "", verdict,
+                                           j + 1);
                     test_flush_stdout();
                 }
             }
@@ -204,8 +211,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();
         }
     }