[openssl] master update

Richard Levitte levitte at openssl.org
Sat Jun 6 17:19:31 UTC 2020


The branch master has been updated
       via  c4683009ad6e8d64e80112fd689921f6c169bd20 (commit)
       via  66d8bd4b37c759e2db51324f5614438bf3db1dbd (commit)
       via  8dce4aa2d974fa357bb3f7d8a77e581d487de732 (commit)
      from  591315297ec45ada0d31f057c4f6cff7f572bf3e (commit)


- Log -----------------------------------------------------------------
commit c4683009ad6e8d64e80112fd689921f6c169bd20
Author: Richard Levitte <levitte at openssl.org>
Date:   Fri Jun 5 17:05:07 2020 +0200

    TEST: Adjust test/bioprinttest.c to behave like the testutil routines
    
    Reviewed-by: Matt Caswell <matt at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/12057)

commit 66d8bd4b37c759e2db51324f5614438bf3db1dbd
Author: Richard Levitte <levitte at openssl.org>
Date:   Fri Jun 5 17:04:33 2020 +0200

    TESTUTIL: Adjust the rest of testutil
    
    Fixes #12054
    
    Reviewed-by: Matt Caswell <matt at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/12057)

commit 8dce4aa2d974fa357bb3f7d8a77e581d487de732
Author: Richard Levitte <levitte at openssl.org>
Date:   Fri Jun 5 16:55:42 2020 +0200

    TESTUTIL: Separate TAP output and other output by BIO filter
    
    Output that's supposed to be understood by a TAP parser gets its own
    BIOs (|tap_out| and |tap_err|), and is only used internally within
    testutils.  |bio_out| and |bio_err| is now only used for output that
    shouldn't be parsed by the TAP parser, and all output written to those
    BIOs are therefore always made to look like comments (it gets prefixed
    with "# ").
    
    Indentation and prefixing with "# " is reworked to use BIO_f_prefix(),
    which allows us to throw away the internal BIO_f_tap().
    
    The indentation level is now adjusted via a special function.
    
    Fixes #12054
    
    Reviewed-by: Matt Caswell <matt at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/12057)

-----------------------------------------------------------------------

Summary of changes:
 test/bioprinttest.c            |  34 ++++++++-
 test/build.info                |   2 +-
 test/testutil/basic_output.c   |  58 +++++++++++++--
 test/testutil/driver.c         |  35 +++++-----
 test/testutil/format_output.c  |   3 +-
 test/testutil/output.h         |  11 +++
 test/testutil/output_helpers.c |  24 +++++++
 test/testutil/tap_bio.c        | 155 -----------------------------------------
 8 files changed, 137 insertions(+), 185 deletions(-)
 delete mode 100644 test/testutil/tap_bio.c

diff --git a/test/bioprinttest.c b/test/bioprinttest.c
index 18c00e09b6..04d1613c6c 100644
--- a/test/bioprinttest.c
+++ b/test/bioprinttest.c
@@ -297,10 +297,20 @@ int setup_tests(void)
  * Replace testutil output routines.  We do this to eliminate possible sources
  * of BIO error
  */
+BIO *bio_out = NULL;
+BIO *bio_err = NULL;
+
+static int tap_level = 0;
+
 void test_open_streams(void)
 {
 }
 
+void test_adjust_streams_tap_level(int level)
+{
+    tap_level = level;
+}
+
 void test_close_streams(void)
 {
 }
@@ -312,12 +322,12 @@ void test_close_streams(void)
  */
 int test_vprintf_stdout(const char *fmt, va_list ap)
 {
-    return vfprintf(stdout, fmt, ap);
+    return fprintf(stdout, "%*s# ", tap_level, "") + vfprintf(stdout, fmt, ap);
 }
 
 int test_vprintf_stderr(const char *fmt, va_list ap)
 {
-    return vfprintf(stderr, fmt, ap);
+    return fprintf(stderr, "%*s# ", tap_level, "") + vfprintf(stderr, fmt, ap);
 }
 
 int test_flush_stdout(void)
@@ -330,3 +340,23 @@ int test_flush_stderr(void)
     return fflush(stderr);
 }
 
+int test_vprintf_tapout(const char *fmt, va_list ap)
+{
+    return fprintf(stdout, "%*s", tap_level, "") + vfprintf(stdout, fmt, ap);
+}
+
+int test_vprintf_taperr(const char *fmt, va_list ap)
+{
+    return fprintf(stderr, "%*s", tap_level, "") + vfprintf(stderr, fmt, ap);
+}
+
+int test_flush_tapout(void)
+{
+    return fflush(stdout);
+}
+
+int test_flush_taperr(void)
+{
+    return fflush(stderr);
+}
+
diff --git a/test/build.info b/test/build.info
index 868b8ebefa..6256a34c91 100644
--- a/test/build.info
+++ b/test/build.info
@@ -20,7 +20,7 @@ IF[{- !$disabled{tests} -}]
   LIBS{noinst,has_main}=libtestutil.a
   SOURCE[libtestutil.a]=testutil/basic_output.c testutil/output_helpers.c \
           testutil/driver.c testutil/tests.c testutil/cb.c testutil/stanza.c \
-          testutil/format_output.c testutil/tap_bio.c \
+          testutil/format_output.c \
           testutil/test_cleanup.c testutil/main.c testutil/testutil_init.c \
           testutil/options.c testutil/test_options.c \
           testutil/apps_mem.c testutil/random.c $LIBAPPSSRC
diff --git a/test/testutil/basic_output.c b/test/testutil/basic_output.c
index 93afcd0fd1..bbed57c55a 100644
--- a/test/testutil/basic_output.c
+++ b/test/testutil/basic_output.c
@@ -14,27 +14,51 @@
 #include <openssl/crypto.h>
 #include <openssl/bio.h>
 
+/* These are available for any test program */
 BIO *bio_out = NULL;
 BIO *bio_err = NULL;
 
+/* These are available for TAP output only (internally) */
+static BIO *tap_out = NULL;
+static BIO *tap_err = NULL;
+
 void test_open_streams(void)
 {
-    bio_out = BIO_new_fp(stdout, BIO_NOCLOSE | BIO_FP_TEXT);
-    bio_err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
+    tap_out = BIO_new_fp(stdout, BIO_NOCLOSE | BIO_FP_TEXT);
+    tap_err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
 #ifdef __VMS
-    bio_out = BIO_push(BIO_new(BIO_f_linebuffer()), bio_out);
-    bio_err = BIO_push(BIO_new(BIO_f_linebuffer()), bio_err);
+    tap_out = BIO_push(BIO_new(BIO_f_linebuffer()), tap_out);
+    tap_err = BIO_push(BIO_new(BIO_f_linebuffer()), tap_err);
 #endif
-    bio_err = BIO_push(BIO_new(BIO_f_tap()), bio_err);
+    tap_out = BIO_push(BIO_new(BIO_f_prefix()), tap_out);
+    tap_err = BIO_push(BIO_new(BIO_f_prefix()), tap_err);
+
+    bio_out = BIO_push(BIO_new(BIO_f_prefix()), tap_out);
+    bio_err = BIO_push(BIO_new(BIO_f_prefix()), tap_err);
+    BIO_set_prefix(bio_out, "# ");
+    BIO_set_prefix(bio_err, "# ");
 
     OPENSSL_assert(bio_out != NULL);
     OPENSSL_assert(bio_err != NULL);
 }
 
+void test_adjust_streams_tap_level(int level)
+{
+    BIO_set_indent(tap_out, level);
+    BIO_set_indent(tap_err, level);
+}
+
 void test_close_streams(void)
 {
-    BIO_free_all(bio_out);
-    BIO_free_all(bio_err);
+    /*
+     * The rest of the chain is freed by the BIO_free_all() calls below, so
+     * we only need to free the last one in the bio_out and bio_err chains.
+     */
+    BIO_free(bio_out);
+    BIO_free(bio_err);
+
+    BIO_free_all(tap_out);
+    BIO_free_all(tap_err);
 }
 
 int test_vprintf_stdout(const char *fmt, va_list ap)
@@ -56,3 +80,23 @@ int test_flush_stderr(void)
 {
     return BIO_flush(bio_err);
 }
+
+int test_vprintf_tapout(const char *fmt, va_list ap)
+{
+    return BIO_vprintf(tap_out, fmt, ap);
+}
+
+int test_vprintf_taperr(const char *fmt, va_list ap)
+{
+    return BIO_vprintf(tap_err, fmt, ap);
+}
+
+int test_flush_tapout(void)
+{
+    return BIO_flush(tap_out);
+}
+
+int test_flush_taperr(void)
+{
+    return BIO_flush(tap_err);
+}
diff --git a/test/testutil/driver.c b/test/testutil/driver.c
index 030fb1544c..775e3daf55 100644
--- a/test/testutil/driver.c
+++ b/test/testutil/driver.c
@@ -76,11 +76,6 @@ void add_all_tests(const char *test_case_name, int(*test_fn)(int idx),
     num_test_cases += num;
 }
 
-int subtest_level(void)
-{
-    return level;
-}
-
 static int gcd(int a, int b)
 {
     while (b != 0) {
@@ -96,7 +91,7 @@ static void set_seed(int s)
     seed = s;
     if (seed <= 0)
         seed = (int)time(NULL);
-    test_printf_stdout("%*s# RAND SEED %d\n", subtest_level(), "", seed);
+    test_printf_stdout("RAND SEED %d\n", seed);
     test_flush_stdout();
     test_random_seed(seed);
 }
@@ -109,6 +104,7 @@ int setup_test_framework(int argc, char *argv[])
 
     if (TAP_levels != NULL)
         level = 4 * atoi(TAP_levels);
+    test_adjust_streams_tap_level(level);
     if (test_seed != NULL)
         set_seed(atoi(test_seed));
 
@@ -214,6 +210,7 @@ static int process_shared_options(void)
             if (!opt_int(opt_arg(), &value))
                 goto end;
             level = 4 * value;
+            test_adjust_streams_tap_level(level);
             break;
         case OPT_TEST_SEED:
             if (!opt_int(opt_arg(), &value))
@@ -260,13 +257,13 @@ PRINTF_FORMAT(2, 3) static void test_verdict(int verdict,
     test_flush_stdout();
     test_flush_stderr();
 
-    test_printf_stdout("%*s%s ", level, "", verdict != 0 ? "ok" : "not ok");
+    test_printf_tapout("%s ", verdict != 0 ? "ok" : "not ok");
     va_start(ap, description);
-    test_vprintf_stdout(description, ap);
+    test_vprintf_tapout(description, ap);
     va_end(ap);
     if (verdict == TEST_SKIP_CODE)
-        test_printf_stdout(" # skipped");
-    test_printf_stdout("\n");
+        test_printf_tapout(" # skipped");
+    test_printf_tapout("\n");
     test_flush_stdout();
 }
 
@@ -284,12 +281,11 @@ int run_tests(const char *test_prog_name)
         return EXIT_FAILURE;
 
     if (num_tests < 1) {
-        test_printf_stdout("%*s1..0 # Skipped: %s\n", level, "",
-                           test_prog_name);
+        test_printf_tapout("1..0 # Skipped: %s\n", test_prog_name);
     } else if (show_list == 0 && single_test == -1) {
         if (level > 0)
-            test_printf_stdout("%*s# Subtest: %s\n", level, "", test_prog_name);
-        test_printf_stdout("%*s1..%d\n", level, "", num_tests);
+            test_printf_stdout("Subtest: %s\n", test_prog_name);
+        test_printf_tapout("1..%d\n", num_tests);
     }
 
     test_flush_stdout();
@@ -312,11 +308,11 @@ int run_tests(const char *test_prog_name)
         }
         else if (show_list) {
             if (all_tests[i].num != -1) {
-                test_printf_stdout("%d - %s (%d..%d)\n", ii + 1,
+                test_printf_tapout("%d - %s (%d..%d)\n", ii + 1,
                                    all_tests[i].test_case_name, 1,
                                    all_tests[i].num);
             } else {
-                test_printf_stdout("%d - %s\n", ii + 1,
+                test_printf_tapout("%d - %s\n", ii + 1,
                                    all_tests[i].test_case_name);
             }
             test_flush_stdout();
@@ -332,11 +328,11 @@ int run_tests(const char *test_prog_name)
 
             verdict = TEST_SKIP_CODE;
             level += 4;
+            test_adjust_streams_tap_level(level);
             if (all_tests[i].subtest && single_iter == -1) {
-                test_printf_stdout("%*s# Subtest: %s\n", level, "",
+                test_printf_stdout("Subtest: %s\n",
                                    all_tests[i].test_case_name);
-                test_printf_stdout("%*s%d..%d\n", level, "", 1,
-                                   all_tests[i].num);
+                test_printf_tapout("%d..%d\n", 1, all_tests[i].num);
                 test_flush_stdout();
             }
 
@@ -375,6 +371,7 @@ int run_tests(const char *test_prog_name)
             }
 
             level -= 4;
+            test_adjust_streams_tap_level(level);
             if (verdict == 0)
                 ++num_failed;
             test_verdict(verdict, "%d - %s", ii + 1,
diff --git a/test/testutil/format_output.c b/test/testutil/format_output.c
index 7f5147516e..a2f8a9e0aa 100644
--- a/test/testutil/format_output.c
+++ b/test/testutil/format_output.c
@@ -42,7 +42,8 @@ static void test_fail_string_common(const char *prefix, const char *file,
                                     const char *op, const char *m1, size_t l1,
                                     const char *m2, size_t l2)
 {
-    const size_t width = (MAX_STRING_WIDTH - subtest_level() - 12) / 16 * 16;
+    const size_t width =
+        (MAX_STRING_WIDTH - BIO_get_indent(bio_err) - 12) / 16 * 16;
     char b1[MAX_STRING_WIDTH + 1], b2[MAX_STRING_WIDTH + 1];
     char bdiff[MAX_STRING_WIDTH + 1];
     size_t n1, n2, i;
diff --git a/test/testutil/output.h b/test/testutil/output.h
index def76af151..8da73e2ac7 100644
--- a/test/testutil/output.h
+++ b/test/testutil/output.h
@@ -35,20 +35,31 @@
  */
 void test_open_streams(void);
 void test_close_streams(void);
+void test_adjust_streams_tap_level(int level);
 /* The following ALL return the number of characters written */
 int test_vprintf_stdout(const char *fmt, va_list ap)
     ossl_test__attr__((__format__(ossl_test__printf__, 1, 0)));
+int test_vprintf_tapout(const char *fmt, va_list ap)
+    ossl_test__attr__((__format__(ossl_test__printf__, 1, 0)));
 int test_vprintf_stderr(const char *fmt, va_list ap)
     ossl_test__attr__((__format__(ossl_test__printf__, 1, 0)));
+int test_vprintf_taperr(const char *fmt, va_list ap)
+    ossl_test__attr__((__format__(ossl_test__printf__, 1, 0)));
 /* These return failure or success */
 int test_flush_stdout(void);
+int test_flush_tapout(void);
 int test_flush_stderr(void);
+int test_flush_taperr(void);
 
 /* Commodity functions.  There's no need to override these */
 int test_printf_stdout(const char *fmt, ...)
     ossl_test__attr__((__format__(ossl_test__printf__, 1, 2)));
+int test_printf_tapout(const char *fmt, ...)
+    ossl_test__attr__((__format__(ossl_test__printf__, 1, 2)));
 int test_printf_stderr(const char *fmt, ...)
     ossl_test__attr__((__format__(ossl_test__printf__, 1, 2)));
+int test_printf_taperr(const char *fmt, ...)
+    ossl_test__attr__((__format__(ossl_test__printf__, 1, 2)));
 
 # undef ossl_test__printf__
 # undef ossl_test__attr__
diff --git a/test/testutil/output_helpers.c b/test/testutil/output_helpers.c
index eb614f1281..64e99dac62 100644
--- a/test/testutil/output_helpers.c
+++ b/test/testutil/output_helpers.c
@@ -32,3 +32,27 @@ int test_printf_stderr(const char *fmt, ...)
 
     return ret;
 }
+
+int test_printf_tapout(const char *fmt, ...)
+{
+    va_list ap;
+    int ret;
+
+    va_start(ap, fmt);
+    ret = test_vprintf_tapout(fmt, ap);
+    va_end(ap);
+
+    return ret;
+}
+
+int test_printf_taperr(const char *fmt, ...)
+{
+    va_list ap;
+    int ret;
+
+    va_start(ap, fmt);
+    ret = test_vprintf_taperr(fmt, ap);
+    va_end(ap);
+
+    return ret;
+}
diff --git a/test/testutil/tap_bio.c b/test/testutil/tap_bio.c
deleted file mode 100644
index f3ee2787d2..0000000000
--- a/test/testutil/tap_bio.c
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
- * Copyright (c) 2017, Oracle and/or its affiliates.  All rights reserved.
- *
- * Licensed under the Apache License 2.0 (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 <string.h>
-#include "tu_local.h"
-
-static int tap_write_ex(BIO *b, const char *buf, size_t size, size_t *in_size);
-static int tap_read_ex(BIO *b, char *buf, size_t size, size_t *out_size);
-static int tap_puts(BIO *b, const char *str);
-static int tap_gets(BIO *b, char *str, int size);
-static long tap_ctrl(BIO *b, int cmd, long arg1, void *arg2);
-static int tap_new(BIO *b);
-static int tap_free(BIO *b);
-static long tap_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp);
-
-const BIO_METHOD *BIO_f_tap(void)
-{
-    static BIO_METHOD *tap = NULL;
-
-    if (tap == NULL) {
-        tap = BIO_meth_new(BIO_TYPE_START | BIO_TYPE_FILTER, "tap");
-        if (tap != NULL) {
-            BIO_meth_set_write_ex(tap, tap_write_ex);
-            BIO_meth_set_read_ex(tap, tap_read_ex);
-            BIO_meth_set_puts(tap, tap_puts);
-            BIO_meth_set_gets(tap, tap_gets);
-            BIO_meth_set_ctrl(tap, tap_ctrl);
-            BIO_meth_set_create(tap, tap_new);
-            BIO_meth_set_destroy(tap, tap_free);
-            BIO_meth_set_callback_ctrl(tap, tap_callback_ctrl);
-        }
-    }
-    return tap;
-}
-
-static int tap_new(BIO *b)
-{
-    BIO_set_data(b, NULL);
-    BIO_set_init(b, 1);
-    return 1;
-}
-
-static int tap_free(BIO *b)
-{
-    if (b == NULL)
-        return 0;
-    BIO_set_data(b, NULL);
-    BIO_set_init(b, 0);
-    return 1;
-}
-
-static int tap_read_ex(BIO *b, char *buf, size_t size, size_t *out_size)
-{
-    BIO *next = BIO_next(b);
-    int ret = 0;
-
-    ret = BIO_read_ex(next, buf, size, out_size);
-    BIO_clear_retry_flags(b);
-    BIO_copy_next_retry(b);
-    return ret;
-}
-
-/*
- * Output a string to the specified bio and return 1 if successful.
- */
-static int write_string(BIO *b, const char *buf, size_t n)
-{
-    size_t m;
-
-    return BIO_write_ex(b, buf, n, &m) != 0 && m == n;
-}
-
-/*
- * Write some data.
- *
- * This function implements a simple state machine that detects new lines.
- * It indents the output and prefixes it with a '#' character.
- *
- * It returns the number of input characters that were output in in_size.
- * More characters than this will likely have been output however any calling
- * code will be unable to correctly assess the actual number of characters
- * emitted and would be prone to failure if the actual number were returned.
- *
- * The BIO_data field is used as our state.  If it is NULL, we've just
- * seen a new line.  If it is not NULL, we're processing characters in a line.
- */
-static int tap_write_ex(BIO *b, const char *buf, size_t size, size_t *in_size)
-{
-    static char empty[] = "";
-    BIO *next = BIO_next(b);
-    size_t i;
-    int j;
-
-    for (i = 0; i < size; i++) {
-        if (BIO_get_data(b) == NULL) {
-            BIO_set_data(b, empty);
-            for (j = 0; j < subtest_level(); j++)
-                if (!write_string(next, " ", 1))
-                    goto err;
-            if (!write_string(next, "# ", 2))
-                goto err;
-        }
-        if (!write_string(next, buf + i, 1))
-            goto err;
-        if (buf[i] == '\n')
-            BIO_set_data(b, NULL);
-    }
-    *in_size = i;
-    return 1;
-
-err:
-    *in_size = i;
-    return 0;
-}
-
-static long tap_ctrl(BIO *b, int cmd, long num, void *ptr)
-{
-    BIO *next = BIO_next(b);
-
-    switch (cmd) {
-    case BIO_CTRL_RESET:
-        BIO_set_data(b, NULL);
-        break;
-
-    default:
-        break;
-    }
-    return BIO_ctrl(next, cmd, num, ptr);
-}
-
-static long tap_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
-{
-    return BIO_callback_ctrl(BIO_next(b), cmd, fp);
-}
-
-static int tap_gets(BIO *b, char *buf, int size)
-{
-    return BIO_gets(BIO_next(b), buf, size);
-}
-
-static int tap_puts(BIO *b, const char *str)
-{
-    size_t m;
-
-    if (!tap_write_ex(b, str, strlen(str), &m))
-        return 0;
-    return m;
-}


More information about the openssl-commits mailing list