summaryrefslogtreecommitdiffstats
path: root/test/threadstest.c
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2021-03-01 16:31:34 +0100
committerRichard Levitte <levitte@openssl.org>2021-03-04 16:09:02 +0100
commit2f17e978a0ec5becda8a61dcf3e7840740ccdfd3 (patch)
treee146eedee4271f79e6c948cdafc5acac26ea7749 /test/threadstest.c
parentecx_set_priv_key: Try to obtain libctx from the pkey's keymgmt (diff)
downloadopenssl-2f17e978a0ec5becda8a61dcf3e7840740ccdfd3.tar.xz
openssl-2f17e978a0ec5becda8a61dcf3e7840740ccdfd3.zip
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)
Diffstat (limited to 'test/threadstest.c')
-rw-r--r--test/threadstest.c29
1 files changed, 29 insertions, 0 deletions
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;
}