From: Richard Levitte Date: Mon, 1 Mar 2021 15:31:34 +0000 (+0100) Subject: test/threadstest.c: Add a test to load providers concurrently X-Git-Tag: openssl-3.0.0-alpha13~50 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2f17e978a0ec5becda8a61dcf3e7840740ccdfd3;p=thirdparty%2Fopenssl.git test/threadstest.c: Add a test to load providers concurrently If we don't synchronize properly in the core provider code, and build with a thread sanitizer, this should cause a crash. Reviewed-by: Paul Dale Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/14354) --- diff --git a/test/threadstest.c b/test/threadstest.c index 9c8e2181d0..26807e294c 100644 --- a/test/threadstest.c +++ b/test/threadstest.c @@ -473,6 +473,34 @@ static int test_multi(int idx) return testresult; } +/* + * This test attempts to load several providers at the same time, and if + * run with a thread sanitizer, should crash if the core provider code + * doesn't synchronize well enough. + */ +#define MULTI_LOAD_THREADS 3 +static void test_multi_load_worker(void) +{ + OSSL_PROVIDER *prov; + + TEST_ptr(prov = OSSL_PROVIDER_load(NULL, "default")); + TEST_true(OSSL_PROVIDER_unload(prov)); +} + +static int test_multi_load(void) +{ + thread_t threads[MULTI_LOAD_THREADS]; + int i; + + for (i = 0; i < MULTI_LOAD_THREADS; i++) + TEST_true(run_thread(&threads[i], test_multi_load_worker)); + + for (i = 0; i < MULTI_LOAD_THREADS; i++) + TEST_true(wait_for_thread(threads[i])); + + return 1; +} + typedef enum OPTION_choice { OPT_ERR = -1, OPT_EOF = 0, @@ -518,6 +546,7 @@ int setup_tests(void) ADD_TEST(test_once); ADD_TEST(test_thread_local); ADD_TEST(test_atomic); + ADD_TEST(test_multi_load); ADD_ALL_TESTS(test_multi, 4); return 1; }