testutil: Fix non-standard subtest output
[openssl.git] / test / testutil / driver.c
index 6689a78..7be6d2f 100644 (file)
@@ -84,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");
@@ -108,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
 
@@ -122,7 +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 const char *test_title = NULL;
+
+void set_test_title(const char *title)
+{
+    test_title = title;
 }
 
 int run_tests(const char *test_prog_name)
@@ -131,19 +134,22 @@ int run_tests(const char *test_prog_name)
     char *verdict = NULL;
     int i, j;
 
-    if (num_tests < 1)
+    if (num_tests < 1) {
         test_printf_stdout("%*s1..0 # Skipped: %s\n", level, "",
                            test_prog_name);
-    else if (level > 0)
-        test_printf_stdout("%*s1..%d # Subtest: %s\n", level, "", num_tests,
-                           test_prog_name);
-    else
+    } 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();
@@ -154,7 +160,7 @@ int run_tests(const char *test_prog_name)
                 ++num_failed;
             }
             test_printf_stdout("%*s%s %d - %s\n", level, "", verdict, i + 1,
-                               all_tests[i].test_case_name);
+                               test_title);
             test_flush_stdout();
             finalize(ret);
         } else {
@@ -170,7 +176,10 @@ int run_tests(const char *test_prog_name)
             }
 
             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();
@@ -186,7 +195,12 @@ int run_tests(const char *test_prog_name)
                         verdict = "not ok";
                         ++num_failed_inner;
                     }
-                    test_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();
                 }
             }