[openssl-commits] [openssl] master update

Richard Levitte levitte at openssl.org
Fri Apr 28 14:00:22 UTC 2017


The branch master has been updated
       via  0918b94c9c01307a1cc4cfc347d458827e30ffea (commit)
       via  68e49bf22384c33494886eb95d78f1f69f433781 (commit)
       via  603ddbdb7527710c293a762aa5eed51ad05646b3 (commit)
       via  c5657cb71011eb2471f6d70e558919d3da561f39 (commit)
       via  579d0fabcddb4a0ec4307be420f0bc7c2eea6b7c (commit)
      from  36b2cfb191f4a3f3a49b7c4d865308b7021daa42 (commit)


- Log -----------------------------------------------------------------
commit 0918b94c9c01307a1cc4cfc347d458827e30ffea
Author: Richard Levitte <levitte at openssl.org>
Date:   Fri Apr 28 15:40:55 2017 +0200

    testutil: Remove test_puts_std{out,err}, they are superfluous
    
    Reviewed-by: Andy Polyakov <appro at openssl.org>
    Reviewed-by: Rich Salz <rsalz at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/3345)

commit 68e49bf22384c33494886eb95d78f1f69f433781
Author: Richard Levitte <levitte at openssl.org>
Date:   Fri Apr 28 14:48:13 2017 +0200

    testutil: Add OpenSSL error stack printing wrapper TEST_openssl_errors
    
    Also added a internal error printing callback to be used both with
    ERR_print_errors_cb() and with CRYPTO_mem_leaks_cb
    
    Reviewed-by: Andy Polyakov <appro at openssl.org>
    Reviewed-by: Rich Salz <rsalz at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/3345)

commit 603ddbdb7527710c293a762aa5eed51ad05646b3
Author: Richard Levitte <levitte at openssl.org>
Date:   Fri Apr 28 14:46:18 2017 +0200

    testutil: Add commodity printing functions test_printf_std{out,err}
    
    Reviewed-by: Andy Polyakov <appro at openssl.org>
    Reviewed-by: Rich Salz <rsalz at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/3345)

commit c5657cb71011eb2471f6d70e558919d3da561f39
Author: Richard Levitte <levitte at openssl.org>
Date:   Fri Apr 28 14:42:46 2017 +0200

    testutil: make subtest_level() internal
    
    Reviewed-by: Andy Polyakov <appro at openssl.org>
    Reviewed-by: Rich Salz <rsalz at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/3345)

commit 579d0fabcddb4a0ec4307be420f0bc7c2eea6b7c
Author: Richard Levitte <levitte at openssl.org>
Date:   Fri Apr 28 14:37:19 2017 +0200

    testutil: Move printing function declarations to "internal" header
    
    These functions aren't meant to be used directly by the test programs,
    reflect that by making the declarations a little harder to reach, but
    still available enough if there's a need to override them.
    
    Reviewed-by: Andy Polyakov <appro at openssl.org>
    Reviewed-by: Rich Salz <rsalz at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/3345)

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

Summary of changes:
 test/bioprinttest.c                                | 25 ++---------
 test/build.info                                    |  7 ++--
 test/testutil.h                                    | 23 ++--------
 test/testutil/basic_output.c                       | 11 +----
 crypto/o_init.c => test/testutil/cb.c              | 15 +++----
 test/testutil/driver.c                             | 49 +++++++++-------------
 test/testutil/output.h                             | 32 ++++++++++++++
 test/testutil/output_helpers.c                     | 34 +++++++++++++++
 test/testutil/test_main.c                          |  3 +-
 test/testutil/tests.c                              | 29 ++++++-------
 .../internal/async.h => test/testutil/tu_local.h   |  9 ++--
 11 files changed, 120 insertions(+), 117 deletions(-)
 copy crypto/o_init.c => test/testutil/cb.c (53%)
 create mode 100644 test/testutil/output.h
 create mode 100644 test/testutil/output_helpers.c
 copy crypto/include/internal/async.h => test/testutil/tu_local.h (57%)

diff --git a/test/bioprinttest.c b/test/bioprinttest.c
index 2c2dc8c..3034cda 100644
--- a/test/bioprinttest.c
+++ b/test/bioprinttest.c
@@ -14,6 +14,7 @@
 #include <openssl/bio.h>
 #include "internal/numbers.h"
 #include "testutil.h"
+#include "testutil/output.h"
 
 #define nelem(x) (int)(sizeof(x) / sizeof((x)[0]))
 
@@ -260,18 +261,6 @@ void test_close_streams(void)
 {
 }
 
-int test_puts_stdout(const char *str)
-{
-    return fputs(str, stdout);
-}
-
-int test_puts_stderr(const char *str)
-{
-    return fputs(str, stderr);
-}
-
-static char vprint_buf[10240];
-
 /*
  * This works out as long as caller doesn't use any "fancy" formats.
  * But we are caller's caller, and test_str_eq is the only one called,
@@ -279,20 +268,12 @@ static char vprint_buf[10240];
  */
 int test_vprintf_stdout(const char *fmt, va_list ap)
 {
-    size_t len = vsnprintf(vprint_buf, sizeof(vprint_buf), fmt, ap);
-
-    if (len >= sizeof(vprint_buf))
-        return -1;
-    return test_puts_stdout(vprint_buf);
+    return vfprintf(stdout, fmt, ap);
 }
 
 int test_vprintf_stderr(const char *fmt, va_list ap)
 {
-    size_t len = vsnprintf(vprint_buf, sizeof(vprint_buf), fmt, ap);
-
-    if (len >= sizeof(vprint_buf))
-        return -1;
-    return test_puts_stderr(vprint_buf);
+    return vfprintf(stderr, fmt, ap);
 }
 
 int test_flush_stdout(void)
diff --git a/test/build.info b/test/build.info
index c8d86f7..2b1ced8 100644
--- a/test/build.info
+++ b/test/build.info
@@ -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 testutil/cb.c \
+          {- rebase_files("../apps", $target{apps_aux_src}) -} \
+          testutil/test_main.c testutil/main.c
   INCLUDE[libtestutil.a]=.. ../include
   DEPEND[libtestutil.a]=../libcrypto
 
diff --git a/test/testutil.h b/test/testutil.h
index ecf9934..f1c1bba 100644
--- a/test/testutil.h
+++ b/test/testutil.h
@@ -248,6 +248,7 @@ void test_error_c90(const char *desc, ...) PRINTF_FORMAT(1, 2);
 void test_info(const char *file, int line, const char *desc, ...)
     PRINTF_FORMAT(3, 4);
 void test_info_c90(const char *desc, ...) PRINTF_FORMAT(1, 2);
+void test_openssl_errors(void);
 
 /*
  * The following macros provide wrapper calls to the test functions with
@@ -342,6 +343,7 @@ void test_info_c90(const char *desc, ...) PRINTF_FORMAT(1, 2);
 #  define TEST_error(...)    test_error(__FILE__, __LINE__, __VA_ARGS__)
 #  define TEST_info(...)     test_info(__FILE__, __LINE__, __VA_ARGS__)
 # endif
+# define TEST_openssl_errors test_openssl_errors
 
 /*
  * For "impossible" conditions such as malloc failures or bugs in test code,
@@ -351,29 +353,12 @@ void test_info_c90(const char *desc, ...) PRINTF_FORMAT(1, 2);
 # define TEST_check(condition)                  \
     do {                                        \
         if (!(condition)) {                     \
-            ERR_print_errors_fp(stderr);        \
+            TEST_openssl_errors();              \
             OPENSSL_assert(!#condition);        \
         }                                       \
     } while (0)
-#endif                          /* HEADER_TESTUTIL_H */
-
-
-/*
- * The basic I/O functions used by the test framework.  These can be
- * overriden when needed. Note that if one is, then all must be.
- */
-void test_open_streams(void);
-void test_close_streams(void);
-/* The following ALL return the number of characters written */
-int test_puts_stdout(const char *str);
-int test_puts_stderr(const char *str);
-int test_vprintf_stdout(const char *fmt, va_list ap);
-int test_vprintf_stderr(const char *fmt, va_list ap);
-/* These return failure or success */
-int test_flush_stdout(void);
-int test_flush_stderr(void);
 
 extern BIO *bio_out;
 extern BIO *bio_err;
 
-int subtest_level(void);
+#endif                          /* HEADER_TESTUTIL_H */
diff --git a/test/testutil/basic_output.c b/test/testutil/basic_output.c
index 9080aae..6e1f99a 100644
--- a/test/testutil/basic_output.c
+++ b/test/testutil/basic_output.c
@@ -8,6 +8,7 @@
  */
 
 #include "../testutil.h"
+#include "output.h"
 
 #include <openssl/crypto.h>
 #include <openssl/bio.h>
@@ -30,16 +31,6 @@ void test_close_streams(void)
     BIO_free(bio_err);
 }
 
-int test_puts_stdout(const char *str)
-{
-    return BIO_puts(bio_out, str);
-}
-
-int test_puts_stderr(const char *str)
-{
-    return BIO_puts(bio_err, str);
-}
-
 int test_vprintf_stdout(const char *fmt, va_list ap)
 {
     return BIO_vprintf(bio_out, fmt, ap);
diff --git a/crypto/o_init.c b/test/testutil/cb.c
similarity index 53%
copy from crypto/o_init.c
copy to test/testutil/cb.c
index 5eb7654..a291eaa 100644
--- a/crypto/o_init.c
+++ b/test/testutil/cb.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2011-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * 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
@@ -7,15 +7,10 @@
  * https://www.openssl.org/source/license.html
  */
 
-#include <e_os.h>
-#include <openssl/err.h>
+#include "output.h"
+#include "tu_local.h"
 
-/*
- * Perform any essential OpenSSL initialization operations. Currently does
- * nothing.
- */
-
-void OPENSSL_init(void)
+int openssl_error_cb(const char *str, size_t len, void *u)
 {
-    return;
+    return test_printf_stderr("%*s# %s", subtest_level(), "", str);
 }
diff --git a/test/testutil/driver.c b/test/testutil/driver.c
index 29c97a9..786bc38 100644
--- a/test/testutil/driver.c
+++ b/test/testutil/driver.c
@@ -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,7 @@ static void finalize(int success)
     if (success)
         ERR_clear_error();
     else
-        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);
+        ERR_print_errors_cb(openssl_error_cb, NULL);
 }
 
 int run_tests(const char *test_prog_name)
@@ -139,13 +128,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) {
@@ -160,8 +149,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 {
@@ -169,10 +158,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();
             }
 
@@ -193,7 +182,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();
                 }
             }
@@ -204,8 +193,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();
         }
     }
diff --git a/test/testutil/output.h b/test/testutil/output.h
new file mode 100644
index 0000000..7c03aff
--- /dev/null
+++ b/test/testutil/output.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2014-2016 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
+ */
+
+#ifndef HEADER_TU_OUTPUT_H
+# define HEADER_TU_OUTPUT_H
+
+#include <stdarg.h>
+
+/*
+ * The basic I/O functions used internally by the test framework.  These
+ * can be overriden when needed. Note that if one is, then all must be.
+ */
+void test_open_streams(void);
+void test_close_streams(void);
+/* The following ALL return the number of characters written */
+int test_vprintf_stdout(const char *fmt, va_list ap);
+int test_vprintf_stderr(const char *fmt, va_list ap);
+/* These return failure or success */
+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
index 0000000..9351474
--- /dev/null
+++ b/test/testutil/output_helpers.c
@@ -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;
+}
diff --git a/test/testutil/test_main.c b/test/testutil/test_main.c
index 0152421..3fa08b6 100644
--- a/test/testutil/test_main.c
+++ b/test/testutil/test_main.c
@@ -8,13 +8,14 @@
  */
 
 #include "../testutil.h"
+#include "output.h"
 
 #include <stdio.h>
 
 int test_main(int argc, char *argv[])
 {
     if (argc > 1)
-        test_puts_stderr("Warning: ignoring extra command-line arguments.\n");
+        test_printf_stderr("Warning: ignoring extra command-line arguments.\n");
 
     register_tests();
     return run_tests(argv[0]);
diff --git a/test/testutil/tests.c b/test/testutil/tests.c
index 67b20a5..19a366f 100644
--- a/test/testutil/tests.c
+++ b/test/testutil/tests.c
@@ -8,6 +8,8 @@
  */
 
 #include "../testutil.h"
+#include "output.h"
+#include "tu_local.h"
 
 #include <string.h>
 #include "../../e_os.h"
@@ -43,33 +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);
-int subtest_level(void);
-
-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_puts_stderr(prefix != NULL ? prefix : "ERROR");
-    test_puts_stderr(":");
+    test_printf_stderr("%*s# %s: ", subtest_level(), "",
+                       prefix != NULL ? prefix : "ERROR");
     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_printf_stderr("\n");
     test_flush_stderr();
 }
 
@@ -119,6 +109,11 @@ void test_error(const char *file, int line, const char *desc, ...)
     va_end(ap);
 }
 
+void test_openssl_errors(void)
+{
+    ERR_print_errors_cb(openssl_error_cb, NULL);
+}
+
 /*
  * Define some comparisons between pairs of various types.
  * These functions return 1 if the test is true.
diff --git a/crypto/include/internal/async.h b/test/testutil/tu_local.h
similarity index 57%
copy from crypto/include/internal/async.h
copy to test/testutil/tu_local.h
index db56258..ad50fca 100644
--- a/crypto/include/internal/async.h
+++ b/test/testutil/tu_local.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+ * 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
@@ -7,8 +7,7 @@
  * https://www.openssl.org/source/license.html
  */
 
-#include <openssl/async.h>
-
-int async_init(void);
-void async_deinit(void);
+#include <stdlib.h>              /* size_t */
 
+int subtest_level(void);
+int openssl_error_cb(const char *str, size_t len, void *u);


More information about the openssl-commits mailing list