2 * Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
13 #include <openssl/opensslv.h>
14 #include <openssl/ssl.h>
15 #include <openssl/ossl_typ.h>
18 typedef const SSL_METHOD
* (*TLS_method_t
)(void);
19 typedef SSL_CTX
* (*SSL_CTX_new_t
)(const SSL_METHOD
*meth
);
20 typedef void (*SSL_CTX_free_t
)(SSL_CTX
*);
21 typedef unsigned long (*ERR_get_error_t
)(void);
22 typedef unsigned long (*OpenSSL_version_num_t
)(void);
24 typedef enum test_types_en
{
30 static TEST_TYPE test_type
;
31 static const char *path_crypto
;
32 static const char *path_ssl
;
38 # define SHLIB_INIT NULL
41 typedef void *SHLIB_SYM
;
43 static int shlib_load(const char *filename
, SHLIB
*lib
)
45 *lib
= dlopen(filename
, RTLD_GLOBAL
| RTLD_LAZY
);
46 return *lib
== NULL
? 0 : 1;
49 static int shlib_sym(SHLIB lib
, const char *symname
, SHLIB_SYM
*sym
)
51 *sym
= dlsym(lib
, symname
);
55 static int shlib_close(SHLIB lib
)
57 return dlclose(lib
) != 0 ? 0 : 1;
67 typedef HINSTANCE SHLIB
;
68 typedef void *SHLIB_SYM
;
70 static int shlib_load(const char *filename
, SHLIB
*lib
)
72 *lib
= LoadLibraryA(filename
);
73 return *lib
== NULL
? 0 : 1;
76 static int shlib_sym(SHLIB lib
, const char *symname
, SHLIB_SYM
*sym
)
78 *sym
= (SHLIB_SYM
)GetProcAddress(lib
, symname
);
82 static int shlib_close(SHLIB lib
)
84 return FreeLibrary(lib
) == 0 ? 0 : 1;
89 #if defined(DSO_DLFCN) || defined(DSO_WIN32)
91 static int test_lib(void)
93 SHLIB ssllib
= SHLIB_INIT
;
94 SHLIB cryptolib
= SHLIB_INIT
;
100 TLS_method_t myTLS_method
;
101 SSL_CTX_new_t mySSL_CTX_new
;
102 SSL_CTX_free_t mySSL_CTX_free
;
103 ERR_get_error_t myERR_get_error
;
104 OpenSSL_version_num_t myOpenSSL_version_num
;
109 if (!TEST_true(shlib_load(path_crypto
, &cryptolib
)))
113 if (!TEST_true(shlib_load(path_crypto
, &cryptolib
))
114 || !TEST_true(shlib_load(path_ssl
, &ssllib
)))
118 if (!TEST_true(shlib_load(path_ssl
, &ssllib
))
119 || !TEST_true(shlib_load(path_crypto
, &cryptolib
)))
124 if (test_type
!= JUST_CRYPTO
) {
125 if (!TEST_true(shlib_sym(ssllib
, "TLS_method", &symbols
[0].sym
))
126 || !TEST_true(shlib_sym(ssllib
, "SSL_CTX_new", &symbols
[1].sym
))
127 || !TEST_true(shlib_sym(ssllib
, "SSL_CTX_free", &symbols
[2].sym
)))
129 myTLS_method
= (TLS_method_t
)symbols
[0].func
;
130 mySSL_CTX_new
= (SSL_CTX_new_t
)symbols
[1].func
;
131 mySSL_CTX_free
= (SSL_CTX_free_t
)symbols
[2].func
;
132 if (!TEST_ptr(ctx
= mySSL_CTX_new(myTLS_method())))
137 if (!TEST_true(shlib_sym(cryptolib
, "ERR_get_error", &symbols
[0].sym
))
138 || !TEST_true(shlib_sym(cryptolib
, "OpenSSL_version_num",
141 myERR_get_error
= (ERR_get_error_t
)symbols
[0].func
;
142 if (!TEST_int_eq(myERR_get_error(), 0))
144 myOpenSSL_version_num
= (OpenSSL_version_num_t
)symbols
[1].func
;
145 if (!TEST_int_eq(myOpenSSL_version_num(), OPENSSL_VERSION_NUMBER
))
150 if (!TEST_true(shlib_close(cryptolib
)))
154 if (!TEST_true(shlib_close(cryptolib
))
155 || !TEST_true(shlib_close(ssllib
)))
159 if (!TEST_true(shlib_close(ssllib
))
160 || !TEST_true(shlib_close(cryptolib
)))
172 int setup_tests(void)
174 const char *p
= test_get_argument(0);
176 if (strcmp(p
, "-crypto_first") == 0) {
177 test_type
= CRYPTO_FIRST
;
178 } else if (strcmp(p
, "-ssl_first") == 0) {
179 test_type
= SSL_FIRST
;
180 } else if (strcmp(p
, "-just_crypto") == 0) {
181 test_type
= JUST_CRYPTO
;
183 TEST_error("Unrecognised argument");
186 if (!TEST_ptr(path_crypto
= test_get_argument(1))
187 || !TEST_ptr(path_ssl
= test_get_argument(2)))
190 #if defined(DSO_DLFCN) || defined(DSO_WIN32)