]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
test/threadstest.c: Add a test to load providers concurrently
authorRichard Levitte <levitte@openssl.org>
Mon, 1 Mar 2021 15:31:34 +0000 (16:31 +0100)
committerRichard Levitte <levitte@openssl.org>
Thu, 4 Mar 2021 15:09:02 +0000 (16:09 +0100)
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)

test/threadstest.c

index 9c8e2181d0ee980feb36db16c45b2bb2f953c248..26807e294c392d413348ffb74f62a42c3de2cb1f 100644 (file)
@@ -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;
 }