eng_aesni.c: win32 fix.
[openssl.git] / crypto / engine / enginetest.c
index 351b0c742e99b3684dd4f34e229de9096af0e7c6..f4d70e7e0a600b51f71464dd369592ce304f2a58 100644 (file)
@@ -3,7 +3,7 @@
  * project 2000.
  */
 /* ====================================================================
  * project 2000.
  */
 /* ====================================================================
- * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2001 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  *
  */
 
  *
  */
 
-#include <openssl/e_os2.h>
 #include <stdio.h>
 #include <stdio.h>
+#include <string.h>
+#include <openssl/e_os2.h>
+
+#ifdef OPENSSL_NO_ENGINE
+int main(int argc, char *argv[])
+{
+    printf("No ENGINE support\n");
+    return(0);
+}
+#else
 #include <openssl/buffer.h>
 #include <openssl/crypto.h>
 #include <openssl/engine.h>
 #include <openssl/err.h>
 
 #include <openssl/buffer.h>
 #include <openssl/crypto.h>
 #include <openssl/engine.h>
 #include <openssl/err.h>
 
-static void display_engine_list()
+static void display_engine_list(void)
        {
        ENGINE *h;
        int loop;
        {
        ENGINE *h;
        int loop;
@@ -78,6 +87,9 @@ static void display_engine_list()
                h = ENGINE_get_next(h);
                }
        printf("end of list\n");
                h = ENGINE_get_next(h);
                }
        printf("end of list\n");
+       /* ENGINE_get_first() increases the struct_ref counter, so we 
+           must call ENGINE_free() to decrease it again */
+       ENGINE_free(h);
        }
 
 int main(int argc, char *argv[])
        }
 
 int main(int argc, char *argv[])
@@ -93,6 +105,18 @@ int main(int argc, char *argv[])
        ENGINE *new_h3 = NULL;
        ENGINE *new_h4 = NULL;
 
        ENGINE *new_h3 = NULL;
        ENGINE *new_h4 = NULL;
 
+       /* enable memory leak checking unless explicitly disabled */
+       if (!((getenv("OPENSSL_DEBUG_MEMORY") != NULL) && (0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off"))))
+               {
+               CRYPTO_malloc_debug_init();
+               CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
+               }
+       else
+               {
+               /* OPENSSL_DEBUG_MEMORY=off */
+               CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0);
+               }
+       CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
        ERR_load_crypto_strings();
 
        memset(block, 0, 512 * sizeof(ENGINE *));
        ERR_load_crypto_strings();
 
        memset(block, 0, 512 * sizeof(ENGINE *));
@@ -126,6 +150,8 @@ int main(int argc, char *argv[])
                printf("Remove failed!\n");
                goto end;
                }
                printf("Remove failed!\n");
                goto end;
                }
+       if (ptr)
+               ENGINE_free(ptr);
        display_engine_list();
        if(!ENGINE_add(new_h3) || !ENGINE_add(new_h2))
                {
        display_engine_list();
        if(!ENGINE_add(new_h3) || !ENGINE_add(new_h2))
                {
@@ -160,12 +186,7 @@ int main(int argc, char *argv[])
                }
        else
                printf("Remove that should fail did.\n");
                }
        else
                printf("Remove that should fail did.\n");
-       if(!ENGINE_remove(new_h1))
-               {
-               printf("Remove failed!\n");
-               goto end;
-               }
-       display_engine_list();
+       ERR_clear_error();
        if(!ENGINE_remove(new_h3))
                {
                printf("Remove failed!\n");
        if(!ENGINE_remove(new_h3))
                {
                printf("Remove failed!\n");
@@ -185,6 +206,8 @@ int main(int argc, char *argv[])
                if(!ENGINE_remove(ptr))
                        printf("Remove failed!i - probably no hardware "
                                "support present.\n");
                if(!ENGINE_remove(ptr))
                        printf("Remove failed!i - probably no hardware "
                                "support present.\n");
+       if (ptr)
+               ENGINE_free(ptr);
        display_engine_list();
        if(!ENGINE_add(new_h1) || !ENGINE_remove(new_h1))
                {
        display_engine_list();
        if(!ENGINE_add(new_h1) || !ENGINE_remove(new_h1))
                {
@@ -230,6 +253,7 @@ cleanup_loop:
                        printf("\nRemove failed!\n");
                        goto end;
                        }
                        printf("\nRemove failed!\n");
                        goto end;
                        }
+               ENGINE_free(ptr);
                printf("."); fflush(stdout);
                }
        for(loop = 0; loop < 512; loop++)
                printf("."); fflush(stdout);
                }
        for(loop = 0; loop < 512; loop++)
@@ -249,5 +273,11 @@ end:
        for(loop = 0; loop < 512; loop++)
                if(block[loop])
                        ENGINE_free(block[loop]);
        for(loop = 0; loop < 512; loop++)
                if(block[loop])
                        ENGINE_free(block[loop]);
+       ENGINE_cleanup();
+       CRYPTO_cleanup_all_ex_data();
+       ERR_free_strings();
+       ERR_remove_thread_state(NULL);
+       CRYPTO_mem_leaks_fp(stderr);
        return to_return;
        }
        return to_return;
        }
+#endif