From a135dea4e024ea6750be25859c1d613789a4d575 Mon Sep 17 00:00:00 2001 From: Pauli Date: Tue, 30 Mar 2021 12:27:44 +1000 Subject: test: fix problem with threads test using default library context. Also add a new test that deliberately tests the default library context. Fixes #14720 Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/14773) --- test/threadstest.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/test/threadstest.c b/test/threadstest.c index 17b348b80c..83a3f978f9 100644 --- a/test/threadstest.c +++ b/test/threadstest.c @@ -348,7 +348,7 @@ static void thread_general_worker(void) static void thread_multi_simple_fetch(void) { - EVP_MD *md = EVP_MD_fetch(NULL, "SHA2-256", NULL); + EVP_MD *md = EVP_MD_fetch(multi_libctx, "SHA2-256", NULL); if (md != NULL) EVP_MD_free(md); @@ -501,6 +501,7 @@ static int test_multi(int idx) OSSL_LIB_CTX_free(multi_libctx); EVP_PKEY_free(shared_evp_pkey); shared_evp_pkey = NULL; + multi_libctx = NULL; return testresult; } @@ -532,6 +533,36 @@ static int test_multi_load(void) return 1; } +static int test_multi_default(void) +{ + thread_t thread1, thread2; + int testresult = 0; + OSSL_PROVIDER *prov = NULL; + + multi_success = 1; + multi_libctx = NULL; + prov = OSSL_PROVIDER_load(multi_libctx, "default"); + if (!TEST_ptr(prov)) + goto err; + + if (!TEST_true(run_thread(&thread1, thread_multi_simple_fetch)) + || !TEST_true(run_thread(&thread2, thread_multi_simple_fetch))) + goto err; + + thread_multi_simple_fetch(); + + if (!TEST_true(wait_for_thread(thread1)) + || !TEST_true(wait_for_thread(thread2)) + || !TEST_true(multi_success)) + goto err; + + testresult = 1; + + err: + OSSL_PROVIDER_unload(prov); + return testresult; +} + typedef enum OPTION_choice { OPT_ERR = -1, OPT_EOF = 0, @@ -573,6 +604,9 @@ int setup_tests(void) if (!TEST_ptr(privkey)) return 0; + /* Keep first to validate auto creation of default library context */ + ADD_TEST(test_multi_default); + ADD_TEST(test_lock); ADD_TEST(test_once); ADD_TEST(test_thread_local); -- cgit v1.2.3