Move types.h #undefs for wincrypt.h compatibility
[openssl.git] / test / threadstest.c
1 /*
2  * Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 /*
11  * The test_multi_downgrade_shared_pkey function tests the thread safety of a
12  * deprecated function.
13  */
14 #ifndef OPENSSL_NO_DEPRECATED_3_0
15 # define OPENSSL_SUPPRESS_DEPRECATED
16 #endif
17
18 #if defined(_WIN32)
19 # include <windows.h>
20 #endif
21
22 #include <string.h>
23 #include <openssl/crypto.h>
24 #include <openssl/rsa.h>
25 #include <openssl/aes.h>
26 #include <openssl/err.h>
27 #include "internal/tsan_assist.h"
28 #include "internal/nelem.h"
29 #include "testutil.h"
30 #include "threadstest.h"
31
32 /* Limit the maximum number of threads */
33 #define MAXIMUM_THREADS     10
34
35 /* Limit the maximum number of providers loaded into a library context */
36 #define MAXIMUM_PROVIDERS   4
37
38 static int do_fips = 0;
39 static char *privkey;
40 static char *config_file = NULL;
41 static int multidefault_run = 0;
42
43 static const char *default_provider[] = { "default", NULL };
44 static const char *fips_provider[] = { "fips", NULL };
45 static const char *fips_and_default_providers[] = { "default", "fips", NULL };
46
47 #ifdef TSAN_REQUIRES_LOCKING
48 static CRYPTO_RWLOCK *tsan_lock;
49 #endif
50
51 /* Grab a globally unique integer value, return 0 on failure */
52 static int get_new_uid(void)
53 {
54     /*
55      * Start with a nice large number to avoid potential conflicts when
56      * we generate a new OID.
57      */
58     static TSAN_QUALIFIER int current_uid = 1 << (sizeof(int) * 8 - 2);
59 #ifdef TSAN_REQUIRES_LOCKING
60     int r;
61
62     if (!TEST_true(CRYPTO_THREAD_write_lock(tsan_lock)))
63         return 0;
64     r = ++current_uid;
65     if (!TEST_true(CRYPTO_THREAD_unlock(tsan_lock)))
66         return 0;
67     return r;
68
69 #else
70     return tsan_counter(&current_uid);
71 #endif
72 }
73
74 static int test_lock(void)
75 {
76     CRYPTO_RWLOCK *lock = CRYPTO_THREAD_lock_new();
77     int res;
78
79     res = TEST_true(CRYPTO_THREAD_read_lock(lock))
80           && TEST_true(CRYPTO_THREAD_unlock(lock))
81           && TEST_true(CRYPTO_THREAD_write_lock(lock))
82           && TEST_true(CRYPTO_THREAD_unlock(lock));
83
84     CRYPTO_THREAD_lock_free(lock);
85
86     return res;
87 }
88
89 static CRYPTO_ONCE once_run = CRYPTO_ONCE_STATIC_INIT;
90 static unsigned once_run_count = 0;
91
92 static void once_do_run(void)
93 {
94     once_run_count++;
95 }
96
97 static void once_run_thread_cb(void)
98 {
99     CRYPTO_THREAD_run_once(&once_run, once_do_run);
100 }
101
102 static int test_once(void)
103 {
104     thread_t thread;
105
106     if (!TEST_true(run_thread(&thread, once_run_thread_cb))
107         || !TEST_true(wait_for_thread(thread))
108         || !CRYPTO_THREAD_run_once(&once_run, once_do_run)
109         || !TEST_int_eq(once_run_count, 1))
110         return 0;
111     return 1;
112 }
113
114 static CRYPTO_THREAD_LOCAL thread_local_key;
115 static unsigned destructor_run_count = 0;
116 static int thread_local_thread_cb_ok = 0;
117
118 static void thread_local_destructor(void *arg)
119 {
120     unsigned *count;
121
122     if (arg == NULL)
123         return;
124
125     count = arg;
126
127     (*count)++;
128 }
129
130 static void thread_local_thread_cb(void)
131 {
132     void *ptr;
133
134     ptr = CRYPTO_THREAD_get_local(&thread_local_key);
135     if (!TEST_ptr_null(ptr)
136         || !TEST_true(CRYPTO_THREAD_set_local(&thread_local_key,
137                                               &destructor_run_count)))
138         return;
139
140     ptr = CRYPTO_THREAD_get_local(&thread_local_key);
141     if (!TEST_ptr_eq(ptr, &destructor_run_count))
142         return;
143
144     thread_local_thread_cb_ok = 1;
145 }
146
147 static int test_thread_local(void)
148 {
149     thread_t thread;
150     void *ptr = NULL;
151
152     if (!TEST_true(CRYPTO_THREAD_init_local(&thread_local_key,
153                                             thread_local_destructor)))
154         return 0;
155
156     ptr = CRYPTO_THREAD_get_local(&thread_local_key);
157     if (!TEST_ptr_null(ptr)
158         || !TEST_true(run_thread(&thread, thread_local_thread_cb))
159         || !TEST_true(wait_for_thread(thread))
160         || !TEST_int_eq(thread_local_thread_cb_ok, 1))
161         return 0;
162
163 #if defined(OPENSSL_THREADS) && !defined(CRYPTO_TDEBUG)
164
165     ptr = CRYPTO_THREAD_get_local(&thread_local_key);
166     if (!TEST_ptr_null(ptr))
167         return 0;
168
169 # if !defined(OPENSSL_SYS_WINDOWS)
170     if (!TEST_int_eq(destructor_run_count, 1))
171         return 0;
172 # endif
173 #endif
174
175     if (!TEST_true(CRYPTO_THREAD_cleanup_local(&thread_local_key)))
176         return 0;
177     return 1;
178 }
179
180 static int test_atomic(void)
181 {
182     int val = 0, ret = 0, testresult = 0;
183     uint64_t val64 = 1, ret64 = 0;
184     CRYPTO_RWLOCK *lock = CRYPTO_THREAD_lock_new();
185
186     if (!TEST_ptr(lock))
187         return 0;
188
189     if (CRYPTO_atomic_add(&val, 1, &ret, NULL)) {
190         /* This succeeds therefore we're on a platform with lockless atomics */
191         if (!TEST_int_eq(val, 1) || !TEST_int_eq(val, ret))
192             goto err;
193     } else {
194         /* This failed therefore we're on a platform without lockless atomics */
195         if (!TEST_int_eq(val, 0) || !TEST_int_eq(val, ret))
196             goto err;
197     }
198     val = 0;
199     ret = 0;
200
201     if (!TEST_true(CRYPTO_atomic_add(&val, 1, &ret, lock)))
202         goto err;
203     if (!TEST_int_eq(val, 1) || !TEST_int_eq(val, ret))
204         goto err;
205
206     if (CRYPTO_atomic_or(&val64, 2, &ret64, NULL)) {
207         /* This succeeds therefore we're on a platform with lockless atomics */
208         if (!TEST_uint_eq((unsigned int)val64, 3)
209                 || !TEST_uint_eq((unsigned int)val64, (unsigned int)ret64))
210             goto err;
211     } else {
212         /* This failed therefore we're on a platform without lockless atomics */
213         if (!TEST_uint_eq((unsigned int)val64, 1)
214                 || !TEST_int_eq((unsigned int)ret64, 0))
215             goto err;
216     }
217     val64 = 1;
218     ret64 = 0;
219
220     if (!TEST_true(CRYPTO_atomic_or(&val64, 2, &ret64, lock)))
221         goto err;
222
223     if (!TEST_uint_eq((unsigned int)val64, 3)
224             || !TEST_uint_eq((unsigned int)val64, (unsigned int)ret64))
225         goto err;
226
227     ret64 = 0;
228     if (CRYPTO_atomic_load(&val64, &ret64, NULL)) {
229         /* This succeeds therefore we're on a platform with lockless atomics */
230         if (!TEST_uint_eq((unsigned int)val64, 3)
231                 || !TEST_uint_eq((unsigned int)val64, (unsigned int)ret64))
232             goto err;
233     } else {
234         /* This failed therefore we're on a platform without lockless atomics */
235         if (!TEST_uint_eq((unsigned int)val64, 3)
236                 || !TEST_int_eq((unsigned int)ret64, 0))
237             goto err;
238     }
239
240     ret64 = 0;
241     if (!TEST_true(CRYPTO_atomic_load(&val64, &ret64, lock)))
242         goto err;
243
244     if (!TEST_uint_eq((unsigned int)val64, 3)
245             || !TEST_uint_eq((unsigned int)val64, (unsigned int)ret64))
246         goto err;
247
248     testresult = 1;
249  err:
250     CRYPTO_THREAD_lock_free(lock);
251     return testresult;
252 }
253
254 static OSSL_LIB_CTX *multi_libctx = NULL;
255 static int multi_success;
256 static OSSL_PROVIDER *multi_provider[MAXIMUM_PROVIDERS + 1];
257 static size_t multi_num_threads;
258 static thread_t multi_threads[MAXIMUM_THREADS];
259
260 static void multi_intialise(void)
261 {
262     multi_success = 1;
263     multi_libctx = NULL;
264     multi_num_threads = 0;
265     memset(multi_threads, 0, sizeof(multi_threads));
266     memset(multi_provider, 0, sizeof(multi_provider));
267 }
268
269 static void thead_teardown_libctx(void)
270 {
271     OSSL_PROVIDER **p;
272
273     for (p = multi_provider; *p != NULL; p++)
274         OSSL_PROVIDER_unload(*p);
275     OSSL_LIB_CTX_free(multi_libctx);
276     multi_intialise();
277 }
278
279 static int thread_setup_libctx(int libctx, const char *providers[])
280 {
281     size_t n;
282
283     if (libctx && !TEST_true(test_get_libctx(&multi_libctx, NULL, config_file,
284                                              NULL, NULL)))
285         return 0;
286
287     if (providers != NULL)
288         for (n = 0; providers[n] != NULL; n++)
289             if (!TEST_size_t_lt(n, MAXIMUM_PROVIDERS)
290                 || !TEST_ptr(multi_provider[n] = OSSL_PROVIDER_load(multi_libctx,
291                                                                     providers[n]))) {
292                 thead_teardown_libctx();
293                 return 0;
294             }
295     return 1;
296 }
297
298 static int teardown_threads(void)
299 {
300     size_t i;
301
302     for (i = 0; i < multi_num_threads; i++)
303         if (!TEST_true(wait_for_thread(multi_threads[i])))
304             return 0;
305     return 1;
306 }
307
308 static int start_threads(size_t n, void (*thread_func)(void))
309 {
310     size_t i;
311
312     if (!TEST_size_t_le(multi_num_threads + n, MAXIMUM_THREADS))
313         return 0;
314
315     for (i = 0 ; i < n; i++)
316         if (!TEST_true(run_thread(multi_threads + multi_num_threads++, thread_func)))
317             return 0;
318     return 1;
319 }
320
321 /* Template multi-threaded test function */
322 static int thread_run_test(void (*main_func)(void),
323                            size_t num_threads, void (*thread_func)(void),
324                            int libctx, const char *providers[])
325 {
326     int testresult = 0;
327
328     multi_intialise();
329     if (!thread_setup_libctx(libctx, providers)
330             || !start_threads(num_threads, thread_func))
331         goto err;
332
333     if (main_func != NULL)
334         main_func();
335
336     if (!teardown_threads()
337             || !TEST_true(multi_success))
338         goto err;
339     testresult = 1;
340  err:
341     thead_teardown_libctx();
342     return testresult;
343 }
344
345 static void thread_general_worker(void)
346 {
347     EVP_MD_CTX *mdctx = EVP_MD_CTX_new();
348     EVP_MD *md = EVP_MD_fetch(multi_libctx, "SHA2-256", NULL);
349     EVP_CIPHER_CTX *cipherctx = EVP_CIPHER_CTX_new();
350     EVP_CIPHER *ciph = EVP_CIPHER_fetch(multi_libctx, "AES-128-CBC", NULL);
351     const char *message = "Hello World";
352     size_t messlen = strlen(message);
353     /* Should be big enough for encryption output too */
354     unsigned char out[EVP_MAX_MD_SIZE];
355     const unsigned char key[AES_BLOCK_SIZE] = {
356         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
357         0x0c, 0x0d, 0x0e, 0x0f
358     };
359     const unsigned char iv[AES_BLOCK_SIZE] = {
360         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
361         0x0c, 0x0d, 0x0e, 0x0f
362     };
363     unsigned int mdoutl;
364     int ciphoutl;
365     EVP_PKEY *pkey = NULL;
366     int testresult = 0;
367     int i, isfips;
368
369     isfips = OSSL_PROVIDER_available(multi_libctx, "fips");
370
371     if (!TEST_ptr(mdctx)
372             || !TEST_ptr(md)
373             || !TEST_ptr(cipherctx)
374             || !TEST_ptr(ciph))
375         goto err;
376
377     /* Do some work */
378     for (i = 0; i < 5; i++) {
379         if (!TEST_true(EVP_DigestInit_ex(mdctx, md, NULL))
380                 || !TEST_true(EVP_DigestUpdate(mdctx, message, messlen))
381                 || !TEST_true(EVP_DigestFinal(mdctx, out, &mdoutl)))
382             goto err;
383     }
384     for (i = 0; i < 5; i++) {
385         if (!TEST_true(EVP_EncryptInit_ex(cipherctx, ciph, NULL, key, iv))
386                 || !TEST_true(EVP_EncryptUpdate(cipherctx, out, &ciphoutl,
387                                                 (unsigned char *)message,
388                                                 messlen))
389                 || !TEST_true(EVP_EncryptFinal(cipherctx, out, &ciphoutl)))
390             goto err;
391     }
392
393     /*
394      * We want the test to run quickly - not securely.
395      * Therefore we use an insecure bit length where we can (512).
396      * In the FIPS module though we must use a longer length.
397      */
398     pkey = EVP_PKEY_Q_keygen(multi_libctx, NULL, "RSA", isfips ? 2048 : 512);
399     if (!TEST_ptr(pkey))
400         goto err;
401
402     testresult = 1;
403  err:
404     EVP_MD_CTX_free(mdctx);
405     EVP_MD_free(md);
406     EVP_CIPHER_CTX_free(cipherctx);
407     EVP_CIPHER_free(ciph);
408     EVP_PKEY_free(pkey);
409     if (!testresult)
410         multi_success = 0;
411 }
412
413 static void thread_multi_simple_fetch(void)
414 {
415     EVP_MD *md = EVP_MD_fetch(multi_libctx, "SHA2-256", NULL);
416
417     if (md != NULL)
418         EVP_MD_free(md);
419     else
420         multi_success = 0;
421 }
422
423 static EVP_PKEY *shared_evp_pkey = NULL;
424
425 static void thread_shared_evp_pkey(void)
426 {
427     char *msg = "Hello World";
428     unsigned char ctbuf[256];
429     unsigned char ptbuf[256];
430     size_t ptlen, ctlen = sizeof(ctbuf);
431     EVP_PKEY_CTX *ctx = NULL;
432     int success = 0;
433     int i;
434
435     for (i = 0; i < 1 + do_fips; i++) {
436         if (i > 0)
437             EVP_PKEY_CTX_free(ctx);
438         ctx = EVP_PKEY_CTX_new_from_pkey(multi_libctx, shared_evp_pkey,
439                                          i == 0 ? "provider=default"
440                                                 : "provider=fips");
441         if (!TEST_ptr(ctx))
442             goto err;
443
444         if (!TEST_int_ge(EVP_PKEY_encrypt_init(ctx), 0)
445                 || !TEST_int_ge(EVP_PKEY_encrypt(ctx, ctbuf, &ctlen,
446                                                 (unsigned char *)msg, strlen(msg)),
447                                                 0))
448             goto err;
449
450         EVP_PKEY_CTX_free(ctx);
451         ctx = EVP_PKEY_CTX_new_from_pkey(multi_libctx, shared_evp_pkey, NULL);
452
453         if (!TEST_ptr(ctx))
454             goto err;
455
456         ptlen = sizeof(ptbuf);
457         if (!TEST_int_ge(EVP_PKEY_decrypt_init(ctx), 0)
458                 || !TEST_int_gt(EVP_PKEY_decrypt(ctx, ptbuf, &ptlen, ctbuf, ctlen),
459                                                 0)
460                 || !TEST_mem_eq(msg, strlen(msg), ptbuf, ptlen))
461             goto err;
462     }
463
464     success = 1;
465
466  err:
467     EVP_PKEY_CTX_free(ctx);
468     if (!success)
469         multi_success = 0;
470 }
471
472 static void thread_provider_load_unload(void)
473 {
474     OSSL_PROVIDER *deflt = OSSL_PROVIDER_load(multi_libctx, "default");
475
476     if (!TEST_ptr(deflt)
477             || !TEST_true(OSSL_PROVIDER_available(multi_libctx, "default")))
478         multi_success = 0;
479
480     OSSL_PROVIDER_unload(deflt);
481 }
482
483 static int test_multi_general_worker_default_provider(void)
484 {
485     return thread_run_test(&thread_general_worker, 2, &thread_general_worker,
486                            1, default_provider);
487 }
488
489 static int test_multi_general_worker_fips_provider(void)
490 {
491     if (!do_fips)
492         return TEST_skip("FIPS not supported");
493     return thread_run_test(&thread_general_worker, 2, &thread_general_worker,
494                            1, fips_provider);
495 }
496
497 static int test_multi_fetch_worker(void)
498 {
499     return thread_run_test(&thread_multi_simple_fetch,
500                            2, &thread_multi_simple_fetch, 1, default_provider);
501 }
502
503 static int test_multi_shared_pkey_common(void (*worker)(void))
504 {
505     int testresult = 0;
506
507     multi_intialise();
508     if (!thread_setup_libctx(1, do_fips ? fips_and_default_providers
509                                         : default_provider)
510             || !TEST_ptr(shared_evp_pkey = load_pkey_pem(privkey, multi_libctx))
511             || !start_threads(1, &thread_shared_evp_pkey)
512             || !start_threads(1, worker))
513         goto err;
514
515     thread_shared_evp_pkey();
516
517     if (!teardown_threads()
518             || !TEST_true(multi_success))
519         goto err;
520     testresult = 1;
521  err:
522     EVP_PKEY_free(shared_evp_pkey);
523     thead_teardown_libctx();
524     return testresult;
525 }
526
527 #ifndef OPENSSL_NO_DEPRECATED_3_0
528 static void thread_downgrade_shared_evp_pkey(void)
529 {
530     /*
531      * This test is only relevant for deprecated functions that perform
532      * downgrading
533      */
534     if (EVP_PKEY_get0_RSA(shared_evp_pkey) == NULL)
535         multi_success = 0;
536 }
537
538 static int test_multi_downgrade_shared_pkey(void)
539 {
540     return test_multi_shared_pkey_common(&thread_downgrade_shared_evp_pkey);
541 }
542 #endif
543
544 static int test_multi_shared_pkey(void)
545 {
546     return test_multi_shared_pkey_common(&thread_shared_evp_pkey);
547 }
548
549 static int test_multi_load_unload_provider(void)
550 {
551     EVP_MD *sha256 = NULL;
552     OSSL_PROVIDER *prov = NULL;
553     int testresult = 0;
554
555     multi_intialise();
556     if (!thread_setup_libctx(1, NULL)
557             || !TEST_ptr(prov = OSSL_PROVIDER_load(multi_libctx, "default"))
558             || !TEST_ptr(sha256 = EVP_MD_fetch(multi_libctx, "SHA2-256", NULL))
559             || !TEST_true(OSSL_PROVIDER_unload(prov)))
560         goto err;
561     prov = NULL;
562
563     if (!start_threads(2, &thread_provider_load_unload))
564         goto err;
565
566     thread_provider_load_unload();
567
568     if (!teardown_threads()
569             || !TEST_true(multi_success))
570         goto err;
571     testresult = 1;
572  err:
573     OSSL_PROVIDER_unload(prov);
574     EVP_MD_free(sha256);
575     thead_teardown_libctx();
576     return testresult;
577 }
578
579 static char *multi_load_provider = "legacy";
580 /*
581  * This test attempts to load several providers at the same time, and if
582  * run with a thread sanitizer, should crash if the core provider code
583  * doesn't synchronize well enough.
584  */
585 static void test_multi_load_worker(void)
586 {
587     OSSL_PROVIDER *prov;
588
589     if (!TEST_ptr(prov = OSSL_PROVIDER_load(multi_libctx, multi_load_provider))
590             || !TEST_true(OSSL_PROVIDER_unload(prov)))
591         multi_success = 0;
592 }
593
594 static int test_multi_default(void)
595 {
596     /* Avoid running this test twice */
597     if (multidefault_run) {
598         TEST_skip("multi default test already run");
599         return 1;
600     }
601     multidefault_run = 1;
602
603     return thread_run_test(&thread_multi_simple_fetch,
604                            2, &thread_multi_simple_fetch, 0, default_provider);
605 }
606
607 static int test_multi_load(void)
608 {
609     int res = 1;
610     OSSL_PROVIDER *prov;
611
612     /* The multidefault test must run prior to this test */
613     if (!multidefault_run) {
614         TEST_info("Running multi default test first");
615         res = test_multi_default();
616     }
617
618     /*
619      * We use the legacy provider in test_multi_load_worker because it uses a
620      * child libctx that might hit more codepaths that might be sensitive to
621      * threading issues. But in a no-legacy build that won't be loadable so
622      * we use the default provider instead.
623      */
624     prov = OSSL_PROVIDER_load(NULL, "legacy");
625     if (prov == NULL) {
626         TEST_info("Cannot load legacy provider - assuming this is a no-legacy build");
627         multi_load_provider = "default";
628     }
629     OSSL_PROVIDER_unload(prov);
630
631     return thread_run_test(NULL, MAXIMUM_THREADS, &test_multi_load_worker, 0,
632                           NULL) && res;
633 }
634
635 static void test_obj_create_one(void)
636 {
637     char tids[12], oid[40], sn[30], ln[30];
638     int id = get_new_uid();
639
640     BIO_snprintf(tids, sizeof(tids), "%d", id);
641     BIO_snprintf(oid, sizeof(oid), "1.3.6.1.4.1.16604.%s", tids);
642     BIO_snprintf(sn, sizeof(sn), "short-name-%s", tids);
643     BIO_snprintf(ln, sizeof(ln), "long-name-%s", tids);
644     if (!TEST_int_ne(id, 0)
645             || !TEST_true(id = OBJ_create(oid, sn, ln))
646             || !TEST_true(OBJ_add_sigid(id, NID_sha3_256, NID_rsa)))
647         multi_success = 0;
648 }
649
650 static int test_obj_add(void)
651 {
652     return thread_run_test(&test_obj_create_one,
653                            MAXIMUM_THREADS, &test_obj_create_one,
654                            1, default_provider);
655 }
656
657 typedef enum OPTION_choice {
658     OPT_ERR = -1,
659     OPT_EOF = 0,
660     OPT_FIPS, OPT_CONFIG_FILE,
661     OPT_TEST_ENUM
662 } OPTION_CHOICE;
663
664 const OPTIONS *test_get_options(void)
665 {
666     static const OPTIONS options[] = {
667         OPT_TEST_OPTIONS_DEFAULT_USAGE,
668         { "fips", OPT_FIPS, '-', "Test the FIPS provider" },
669         { "config", OPT_CONFIG_FILE, '<',
670           "The configuration file to use for the libctx" },
671         { NULL }
672     };
673     return options;
674 }
675
676 int setup_tests(void)
677 {
678     OPTION_CHOICE o;
679     char *datadir;
680
681     while ((o = opt_next()) != OPT_EOF) {
682         switch (o) {
683         case OPT_FIPS:
684             do_fips = 1;
685             break;
686         case OPT_CONFIG_FILE:
687             config_file = opt_arg();
688             break;
689         case OPT_TEST_CASES:
690             break;
691         default:
692             return 0;
693         }
694     }
695
696     if (!TEST_ptr(datadir = test_get_argument(0)))
697         return 0;
698
699     privkey = test_mk_file_path(datadir, "rsakey.pem");
700     if (!TEST_ptr(privkey))
701         return 0;
702
703 #ifdef TSAN_REQUIRES_LOCKING
704     if (!TEST_ptr(tsan_lock = CRYPTO_THREAD_lock_new()))
705         return 0;
706 #endif
707
708     /* Keep first to validate auto creation of default library context */
709     ADD_TEST(test_multi_default);
710
711     ADD_TEST(test_lock);
712     ADD_TEST(test_once);
713     ADD_TEST(test_thread_local);
714     ADD_TEST(test_atomic);
715     ADD_TEST(test_multi_load);
716     ADD_TEST(test_multi_general_worker_default_provider);
717     ADD_TEST(test_multi_general_worker_fips_provider);
718     ADD_TEST(test_multi_fetch_worker);
719     ADD_TEST(test_multi_shared_pkey);
720 #ifndef OPENSSL_NO_DEPRECATED_3_0
721     ADD_TEST(test_multi_downgrade_shared_pkey);
722 #endif
723     ADD_TEST(test_multi_load_unload_provider);
724     ADD_TEST(test_obj_add);
725     return 1;
726 }
727
728 void cleanup_tests(void)
729 {
730     OPENSSL_free(privkey);
731 #ifdef TSAN_REQUIRES_LOCKING
732     CRYPTO_THREAD_lock_free(tsan_lock);
733 #endif
734 }