summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2021-04-23 14:10:07 +0100
committerMatt Caswell <matt@openssl.org>2021-04-28 15:51:10 +0100
commit98369ef25f87ee1dfc5d17da5489bbacb4150972 (patch)
treef0afe0876b688c7d450548f2380c1ac22122f211 /test
parent4189dc3782c5989dbaa7d247e41a96a25b27c940 (diff)
Add a threading test for loading/unloading providers
Check that we don't see any threading issues when loading/unloading a provider from multiple threads. Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15010)
Diffstat (limited to 'test')
-rw-r--r--test/threadstest.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/test/threadstest.c b/test/threadstest.c
index 83a3f978f9..b82e16f8c6 100644
--- a/test/threadstest.c
+++ b/test/threadstest.c
@@ -419,6 +419,16 @@ static void thread_downgrade_shared_evp_pkey(void)
#endif
}
+static void thread_provider_load_unload(void)
+{
+ OSSL_PROVIDER *deflt = OSSL_PROVIDER_load(multi_libctx, "default");
+
+ if (!TEST_ptr(deflt)
+ || !TEST_true(OSSL_PROVIDER_available(multi_libctx, "default")))
+ multi_success = 0;
+
+ OSSL_PROVIDER_unload(deflt);
+}
/*
* Do work in multiple worker threads at the same time.
@@ -427,6 +437,7 @@ static void thread_downgrade_shared_evp_pkey(void)
* Test 2: Simple fetch worker
* Test 3: Worker downgrading a shared EVP_PKEY
* Test 4: Worker using a shared EVP_PKEY
+ * Test 5: Workder loading and unloading a provider
*/
static int test_multi(int idx)
{
@@ -435,6 +446,7 @@ static int test_multi(int idx)
OSSL_PROVIDER *prov = NULL, *prov2 = NULL;
void (*worker)(void) = NULL;
void (*worker2)(void) = NULL;
+ EVP_MD *sha256 = NULL;
if (idx == 1 && !do_fips)
return TEST_skip("FIPS not supported");
@@ -475,6 +487,17 @@ static int test_multi(int idx)
goto err;
worker = thread_shared_evp_pkey;
break;
+ case 5:
+ /*
+ * We ensure we get an md from the default provider, and then unload the
+ * provider. This ensures the provider remains around but in a
+ * deactivated state.
+ */
+ sha256 = EVP_MD_fetch(multi_libctx, "SHA2-256", NULL);
+ OSSL_PROVIDER_unload(prov);
+ prov = NULL;
+ worker = thread_provider_load_unload;
+ break;
default:
TEST_error("Invalid test index");
goto err;
@@ -496,6 +519,7 @@ static int test_multi(int idx)
testresult = 1;
err:
+ EVP_MD_free(sha256);
OSSL_PROVIDER_unload(prov);
OSSL_PROVIDER_unload(prov2);
OSSL_LIB_CTX_free(multi_libctx);
@@ -612,7 +636,7 @@ int setup_tests(void)
ADD_TEST(test_thread_local);
ADD_TEST(test_atomic);
ADD_TEST(test_multi_load);
- ADD_ALL_TESTS(test_multi, 5);
+ ADD_ALL_TESTS(test_multi, 6);
return 1;
}