Stop test/shlibloadtest.c from failing in a regression test
[openssl.git] / test / shlibloadtest.c
index c57ca8f202209c576a800747389296fa5a696f89..0bf24eee074a968830c59b0dc8191ebf4cb8a570 100644 (file)
@@ -52,12 +52,10 @@ static int shlib_sym(SHLIB lib, const char *symname, SHLIB_SYM *sym)
     return *sym != NULL;
 }
 
-# ifdef OPENSSL_USE_NODELETE
 static int shlib_close(SHLIB lib)
 {
     return dlclose(lib) != 0 ? 0 : 1;
 }
-# endif
 #endif
 
 #ifdef DSO_WIN32
@@ -81,12 +79,10 @@ static int shlib_sym(SHLIB lib, const char *symname, SHLIB_SYM *sym)
     return *sym != NULL;
 }
 
-# ifdef OPENSSL_USE_NODELETE
 static int shlib_close(SHLIB lib)
 {
     return FreeLibrary(lib) == 0 ? 0 : 1;
 }
-# endif
 #endif
 
 
@@ -145,11 +141,22 @@ static int test_lib(void)
     myERR_get_error = (ERR_get_error_t)symbols[0].func;
     if (!TEST_int_eq(myERR_get_error(), 0))
         goto end;
+
+    /*
+     * The bits that COMPATIBILITY_MASK lets through MUST be the same in
+     * the library and in the application.
+     * The bits that are masked away MUST be a larger or equal number in
+     * the library compared to the application.
+     */
+# define COMPATIBILITY_MASK 0xfff00000L
     myOpenSSL_version_num = (OpenSSL_version_num_t)symbols[1].func;
-    if (!TEST_int_eq(myOpenSSL_version_num(), OPENSSL_VERSION_NUMBER))
+    if (!TEST_int_eq(myOpenSSL_version_num() & COMPATIBILITY_MASK,
+                     OPENSSL_VERSION_NUMBER & COMPATIBILITY_MASK)
+        goto end;
+    if (!TEST_int_ge(myOpenSSL_version_num() & ~COMPATIBILITY_MASK,
+                     OPENSSL_VERSION_NUMBER & ~COMPATIBILITY_MASK)
         goto end;
 
-#ifdef OPENSSL_USE_NODELETE
     switch (test_type) {
     case JUST_CRYPTO:
         if (!TEST_true(shlib_close(cryptolib)))
@@ -166,7 +173,6 @@ static int test_lib(void)
             goto end;
         break;
     }
-#endif
 
     result = 1;
 end:
@@ -175,28 +181,26 @@ end:
 #endif
 
 
-int test_main(int argc, char **argv)
+int setup_tests(void)
 {
-    if (argc != 4) {
-        TEST_error("Unexpected number of arguments");
-        return EXIT_FAILURE;
-    }
+    const char *p = test_get_argument(0);
 
-    if (strcmp(argv[1], "-crypto_first") == 0) {
+    if (strcmp(p, "-crypto_first") == 0) {
         test_type = CRYPTO_FIRST;
-    } else if (strcmp(argv[1], "-ssl_first") == 0) {
+    } else if (strcmp(p, "-ssl_first") == 0) {
         test_type = SSL_FIRST;
-    } else if (strcmp(argv[1], "-just_crypto") == 0) {
+    } else if (strcmp(p, "-just_crypto") == 0) {
         test_type = JUST_CRYPTO;
     } else {
         TEST_error("Unrecognised argument");
-        return EXIT_FAILURE;
+        return 0;
     }
-    path_crypto = argv[2];
-    path_ssl = argv[3];
+    if (!TEST_ptr(path_crypto = test_get_argument(1))
+            || !TEST_ptr(path_ssl = test_get_argument(2)))
+        return 0;
 
 #if defined(DSO_DLFCN) || defined(DSO_WIN32)
     ADD_TEST(test_lib);
 #endif
-    return run_tests(argv[0]);
+    return 1;
 }