mirror of
https://github.com/openssl/openssl.git
synced 2025-03-31 20:10:45 +08:00
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 <pauli@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/14354)
This commit is contained in:
parent
8c631cfaa1
commit
2f17e978a0
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user