[openssl-commits] [openssl] master update

Rich Salz rsalz at openssl.org
Mon May 15 12:43:38 UTC 2017


The branch master has been updated
       via  e0011aa831d6d6765c3e65a1bec57f5b8be6f1e5 (commit)
       via  bdd07c78a08bba9e006749bf0ee20dc4a553ab83 (commit)
      from  1d0f116e47664abd95b20aaff629e41ae7a85e76 (commit)


- Log -----------------------------------------------------------------
commit e0011aa831d6d6765c3e65a1bec57f5b8be6f1e5
Author: Rich Salz <rsalz at openssl.org>
Date:   Sat May 6 07:59:18 2017 -0400

    Review feedback; use single main, #ifdef ADD_TEST
    
    Suppose OPENSSL_USE_NODELETE (via Nick Reilly)
    
    Reviewed-by: Richard Levitte <levitte at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/3399)

commit bdd07c78a08bba9e006749bf0ee20dc4a553ab83
Author: Rich Salz <rsalz at openssl.org>
Date:   Fri May 5 17:39:13 2017 -0400

    Convert shlibloadtest to new framework
    
    Reviewed-by: Richard Levitte <levitte at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/3399)

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

Summary of changes:
 test/build.info      |   1 +
 test/shlibloadtest.c | 263 +++++++++++++++++++++++----------------------------
 2 files changed, 117 insertions(+), 147 deletions(-)

diff --git a/test/build.info b/test/build.info
index da7620c..42dc1d6 100644
--- a/test/build.info
+++ b/test/build.info
@@ -329,6 +329,7 @@ INCLUDE_MAIN___test_libtestutil_OLB = /INCLUDE=MAIN
     PROGRAMS_NO_INST=shlibloadtest
     SOURCE[shlibloadtest]=shlibloadtest.c
     INCLUDE[shlibloadtest]=../include
+    DEPEND[shlibloadtest]=libtestutil.a
   ENDIF
 
   IF[{- $disabled{shared} -}]
diff --git a/test/shlibloadtest.c b/test/shlibloadtest.c
index 6f220ba..8c27bfc 100644
--- a/test/shlibloadtest.c
+++ b/test/shlibloadtest.c
@@ -11,221 +11,190 @@
 #include <string.h>
 #include <stdlib.h>
 #include <openssl/opensslv.h>
+#include <openssl/ssl.h>
+#include <openssl/ossl_typ.h>
+#include "testutil.h"
 
-/* The test is only currently implemented for DSO_DLFCN and DSO_WIN32 */
-#if defined(DSO_DLFCN) || defined(DSO_WIN32)
-
-#define SSL_CTX_NEW "SSL_CTX_new"
-#define SSL_CTX_FREE "SSL_CTX_free"
-#define TLS_METHOD "TLS_method"
-
-#define ERR_GET_ERROR "ERR_get_error"
-#define OPENSSL_VERSION_NUM_FUNC "OpenSSL_version_num"
-
-typedef struct ssl_ctx_st SSL_CTX;
-typedef struct ssl_method_st SSL_METHOD;
 typedef const SSL_METHOD * (*TLS_method_t)(void);
 typedef SSL_CTX * (*SSL_CTX_new_t)(const SSL_METHOD *meth);
 typedef void (*SSL_CTX_free_t)(SSL_CTX *);
-
 typedef unsigned long (*ERR_get_error_t)(void);
 typedef unsigned long (*OpenSSL_version_num_t)(void);
 
-static TLS_method_t TLS_method;
-static SSL_CTX_new_t SSL_CTX_new;
-static SSL_CTX_free_t SSL_CTX_free;
+typedef enum test_types_en {
+    CRYPTO_FIRST,
+    SSL_FIRST,
+    JUST_CRYPTO
+} TEST_TYPE;
 
-static ERR_get_error_t ERR_get_error;
-static OpenSSL_version_num_t OpenSSL_version_num;
+static TEST_TYPE test_type;
+static const char *path_crypto;
+static const char *path_ssl;
 
 #ifdef DSO_DLFCN
 
 # include <dlfcn.h>
 
-typedef void * SHLIB;
-typedef void * SHLIB_SYM;
 # define SHLIB_INIT NULL
 
+typedef void *SHLIB;
+typedef void *SHLIB_SYM;
+
 static int shlib_load(const char *filename, SHLIB *lib)
 {
     *lib = dlopen(filename, RTLD_GLOBAL | RTLD_LAZY);
-
-    if (*lib == NULL)
-        return 0;
-
-    return 1;
+    return *lib == NULL ? 0 : 1;
 }
 
 static int shlib_sym(SHLIB lib, const char *symname, SHLIB_SYM *sym)
 {
     *sym = dlsym(lib, symname);
-
     return *sym != NULL;
 }
 
+# ifdef OPENSSL_USE_NODELETE
 static int shlib_close(SHLIB lib)
 {
-    if (dlclose(lib) != 0)
-        return 0;
-
-    return 1;
+    return dlclose(lib) != 0 ? 0 : 1;
 }
+# endif
+#endif
 
-#elif defined(DSO_WIN32)
+#ifdef DSO_WIN32
 
 # include <windows.h>
 
-typedef HINSTANCE SHLIB;
-typedef void * SHLIB_SYM;
 # define SHLIB_INIT 0
 
+typedef HINSTANCE SHLIB;
+typedef void *SHLIB_SYM;
+
 static int shlib_load(const char *filename, SHLIB *lib)
 {
     *lib = LoadLibraryA(filename);
-    if (*lib == NULL)
-        return 0;
-
-    return 1;
+    return *lib == NULL ? 0 : 1;
 }
 
 static int shlib_sym(SHLIB lib, const char *symname, SHLIB_SYM *sym)
 {
     *sym = (SHLIB_SYM)GetProcAddress(lib, symname);
-
     return *sym != NULL;
 }
 
+# ifdef OPENSSL_USE_NODELETE
 static int shlib_close(SHLIB lib)
 {
-    if (FreeLibrary(lib) == 0)
-        return 0;
-
-    return 1;
+    return FreeLibrary(lib) == 0 ? 0 : 1;
 }
-
+# endif
 #endif
 
-# define CRYPTO_FIRST_OPT    "-crypto_first"
-# define SSL_FIRST_OPT       "-ssl_first"
-# define JUST_CRYPTO_OPT     "-just_crypto"
 
-enum test_types_en {
-    CRYPTO_FIRST,
-    SSL_FIRST,
-    JUST_CRYPTO
-};
+#if defined(DSO_DLFCN) || defined(DSO_WIN32)
 
-int main(int argc, char **argv)
+static int test_lib(void)
 {
-    SHLIB ssllib = SHLIB_INIT, cryptolib = SHLIB_INIT;
+    SHLIB ssllib = SHLIB_INIT;
+    SHLIB cryptolib = SHLIB_INIT;
     SSL_CTX *ctx;
     union {
-        void (*func) (void);
+        void (*func)(void);
         SHLIB_SYM sym;
-    } tls_method_sym, ssl_ctx_new_sym, ssl_ctx_free_sym, err_get_error_sym,
-    openssl_version_num_sym;
-    enum test_types_en test_type;
-    int i;
-
-    if (argc != 4) {
-        printf("Unexpected number of arguments\n");
-        return 1;
-    }
-
-    if (strcmp(argv[1], CRYPTO_FIRST_OPT) == 0) {
-        test_type = CRYPTO_FIRST;
-    } else if (strcmp(argv[1], SSL_FIRST_OPT) == 0) {
-            test_type = SSL_FIRST;
-    } else if (strcmp(argv[1], JUST_CRYPTO_OPT) == 0) {
-            test_type = JUST_CRYPTO;
-    } else {
-        printf("Unrecognised argument\n");
-        return 1;
-    }
-
-    for (i = 0; i < 2; i++) {
-        if ((i == 0 && (test_type == CRYPTO_FIRST
-                       || test_type == JUST_CRYPTO))
-               || (i == 1 && test_type == SSL_FIRST)) {
-            if (!shlib_load(argv[2], &cryptolib)) {
-                printf("Unable to load libcrypto\n");
-                return 1;
-            }
-        }
-        if ((i == 0 && test_type == SSL_FIRST)
-                || (i == 1 && test_type == CRYPTO_FIRST)) {
-            if (!shlib_load(argv[3], &ssllib)) {
-                printf("Unable to load libssl\n");
-                return 1;
-            }
-        }
+    } symbols[3];
+    TLS_method_t myTLS_method;
+    SSL_CTX_new_t mySSL_CTX_new;
+    SSL_CTX_free_t mySSL_CTX_free;
+    ERR_get_error_t myERR_get_error;
+    OpenSSL_version_num_t myOpenSSL_version_num;
+    int result = 0;
+
+    switch (test_type) {
+    case JUST_CRYPTO:
+        if (!TEST_true(shlib_load(path_crypto, &cryptolib)))
+            goto end;
+        break;
+    case CRYPTO_FIRST:
+        if (!TEST_true(shlib_load(path_crypto, &cryptolib))
+                || !TEST_true(shlib_load(path_ssl, &ssllib)))
+            goto end;
+    case SSL_FIRST:
+        if (!TEST_true(shlib_load(path_ssl, &ssllib))
+                || !TEST_true(shlib_load(path_crypto, &cryptolib)))
+            goto end;
+        break;
     }
 
     if (test_type != JUST_CRYPTO) {
-        if (!shlib_sym(ssllib, TLS_METHOD, &tls_method_sym.sym)
-                || !shlib_sym(ssllib, SSL_CTX_NEW, &ssl_ctx_new_sym.sym)
-                || !shlib_sym(ssllib, SSL_CTX_FREE, &ssl_ctx_free_sym.sym)) {
-            printf("Unable to load ssl symbols\n");
-            return 1;
-        }
-
-        TLS_method = (TLS_method_t)tls_method_sym.func;
-        SSL_CTX_new = (SSL_CTX_new_t)ssl_ctx_new_sym.func;
-        SSL_CTX_free = (SSL_CTX_free_t)ssl_ctx_free_sym.func;
-
-        ctx = SSL_CTX_new(TLS_method());
-        if (ctx == NULL) {
-            printf("Unable to create SSL_CTX\n");
-            return 1;
-        }
-        SSL_CTX_free(ctx);
+        if (!TEST_true(shlib_sym(ssllib, "TLS_method", &symbols[0].sym))
+                || !TEST_true(shlib_sym(ssllib, "SSL_CTX_new", &symbols[1].sym))
+                || !TEST_true(shlib_sym(ssllib, "SSL_CTX_free", &symbols[2].sym)))
+            goto end;
+        myTLS_method = (TLS_method_t)symbols[0].func;
+        mySSL_CTX_new = (SSL_CTX_new_t)symbols[1].func;
+        mySSL_CTX_free = (SSL_CTX_free_t)symbols[2].func;
+        if (!TEST_ptr(ctx = mySSL_CTX_new(myTLS_method())))
+            goto end;
+        mySSL_CTX_free(ctx);
     }
 
-    if (!shlib_sym(cryptolib, ERR_GET_ERROR, &err_get_error_sym.sym)
-            || !shlib_sym(cryptolib, OPENSSL_VERSION_NUM_FUNC,
-                          &openssl_version_num_sym.sym)) {
-        printf("Unable to load crypto symbols\n");
-        return 1;
+    if (!TEST_true(shlib_sym(cryptolib, "ERR_get_error", &symbols[0].sym))
+            || !TEST_true(shlib_sym(cryptolib, "OpenSSL_version_num",
+                                    &symbols[1].sym)))
+        goto end;
+    myERR_get_error = (ERR_get_error_t)symbols[0].func;
+    if (!TEST_int_eq(myERR_get_error(), 0))
+        goto end;
+    myOpenSSL_version_num = (OpenSSL_version_num_t)symbols[1].func;
+    if (!TEST_int_eq(myOpenSSL_version_num(), OPENSSL_VERSION_NUMBER))
+        goto end;
+
+#ifdef OPENSSL_USE_NODELETE
+    switch (test_type) {
+    case JUST_CRYPTO:
+        if (!TEST_true(shlib_close(cryptolib)))
+            goto end;
+        break;
+    case CRYPTO_FIRST:
+        if (!TEST_true(shlib_close(cryptolib))
+                || !TEST_true(shlib_close(ssllib)))
+            goto end;
+    case SSL_FIRST:
+        if (!TEST_true(shlib_close(ssllib))
+                || !TEST_true(shlib_close(cryptolib)))
+            goto end;
+        break;
     }
+#endif
 
-    ERR_get_error = (ERR_get_error_t)err_get_error_sym.func;
-    OpenSSL_version_num = (OpenSSL_version_num_t)openssl_version_num_sym.func;
+    result = 1;
+end:
+    return result;
+}
+#endif
 
-    if (ERR_get_error() != 0) {
-        printf("Unexpected error in error queue\n");
-        return 1;
-    }
 
-    if (OpenSSL_version_num() != OPENSSL_VERSION_NUMBER) {
-        printf("Unexpected library version loaded\n");
-        return 1;
+int test_main(int argc, char **argv)
+{
+    if (argc != 4) {
+        TEST_error("Unexpected number of arguments");
+        return EXIT_FAILURE;
     }
 
-    for (i = 0; i < 2; i++) {
-        if ((i == 0 && test_type == CRYPTO_FIRST)
-                || (i == 1 && test_type == SSL_FIRST)) {
-            if (!shlib_close(ssllib)) {
-                printf("Unable to close libssl\n");
-                return 1;
-            }
-        }
-        if ((i == 0 && (test_type == SSL_FIRST
-                       || test_type == JUST_CRYPTO))
-                || (i == 1 && test_type == CRYPTO_FIRST)) {
-            if (!shlib_close(cryptolib)) {
-                printf("Unable to close libcrypto\n");
-                return 1;
-            }
-        }
+    if (strcmp(argv[1], "-crypto_first") == 0) {
+        test_type = CRYPTO_FIRST;
+    } else if (strcmp(argv[1], "-ssl_first") == 0) {
+        test_type = SSL_FIRST;
+    } else if (strcmp(argv[1], "-just_crypto") == 0) {
+        test_type = JUST_CRYPTO;
+    } else {
+        TEST_error("Unrecognised argument");
+        return EXIT_FAILURE;
     }
+    path_crypto = argv[2];
+    path_ssl = argv[3];
 
-    printf("Success\n");
-    return 0;
-}
-#else
-int main(void)
-{
-    printf("Test not implemented on this platform\n");
-    return 0;
-}
+#if defined(DSO_DLFCN) || defined(DSO_WIN32)
+    ADD_TEST(test_lib);
 #endif
+    return run_tests(argv[0]);
+}


More information about the openssl-commits mailing list