threadstest.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279
  1. /*
  2. * Copyright 2016-2024 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. * The test_multi_downgrade_shared_pkey function tests the thread safety of a
  11. * deprecated function.
  12. */
  13. #ifndef OPENSSL_NO_DEPRECATED_3_0
  14. # define OPENSSL_SUPPRESS_DEPRECATED
  15. #endif
  16. #if defined(_WIN32)
  17. # include <windows.h>
  18. #endif
  19. #include <string.h>
  20. #include <openssl/crypto.h>
  21. #include <openssl/rsa.h>
  22. #include <openssl/aes.h>
  23. #include <openssl/err.h>
  24. #include <openssl/rand.h>
  25. #include <openssl/pem.h>
  26. #include <openssl/evp.h>
  27. #include "internal/tsan_assist.h"
  28. #include "internal/nelem.h"
  29. #include "internal/time.h"
  30. #include "internal/rcu.h"
  31. #include "testutil.h"
  32. #include "threadstest.h"
  33. #ifdef __SANITIZE_THREAD__
  34. #include <sanitizer/tsan_interface.h>
  35. #define TSAN_ACQUIRE(s) __tsan_acquire(s)
  36. #else
  37. #define TSAN_ACQUIRE(s)
  38. #endif
  39. /* Limit the maximum number of threads */
  40. #define MAXIMUM_THREADS 10
  41. /* Limit the maximum number of providers loaded into a library context */
  42. #define MAXIMUM_PROVIDERS 4
  43. static int do_fips = 0;
  44. static char *privkey;
  45. static char *config_file = NULL;
  46. static int multidefault_run = 0;
  47. static const char *default_provider[] = { "default", NULL };
  48. static const char *fips_provider[] = { "fips", NULL };
  49. static const char *fips_and_default_providers[] = { "default", "fips", NULL };
  50. static CRYPTO_RWLOCK *global_lock;
  51. #ifdef TSAN_REQUIRES_LOCKING
  52. static CRYPTO_RWLOCK *tsan_lock;
  53. #endif
  54. /* Grab a globally unique integer value, return 0 on failure */
  55. static int get_new_uid(void)
  56. {
  57. /*
  58. * Start with a nice large number to avoid potential conflicts when
  59. * we generate a new OID.
  60. */
  61. static TSAN_QUALIFIER int current_uid = 1 << (sizeof(int) * 8 - 2);
  62. #ifdef TSAN_REQUIRES_LOCKING
  63. int r;
  64. if (!TEST_true(CRYPTO_THREAD_write_lock(tsan_lock)))
  65. return 0;
  66. r = ++current_uid;
  67. if (!TEST_true(CRYPTO_THREAD_unlock(tsan_lock)))
  68. return 0;
  69. return r;
  70. #else
  71. return tsan_counter(&current_uid);
  72. #endif
  73. }
  74. static int test_lock(void)
  75. {
  76. CRYPTO_RWLOCK *lock = CRYPTO_THREAD_lock_new();
  77. int res;
  78. if (!TEST_ptr(lock))
  79. return 0;
  80. res = TEST_true(CRYPTO_THREAD_read_lock(lock))
  81. && TEST_true(CRYPTO_THREAD_unlock(lock))
  82. && TEST_true(CRYPTO_THREAD_write_lock(lock))
  83. && TEST_true(CRYPTO_THREAD_unlock(lock));
  84. CRYPTO_THREAD_lock_free(lock);
  85. return res;
  86. }
  87. #if defined(OPENSSL_THREADS)
  88. static int contention = 0;
  89. static int rwwriter1_done = 0;
  90. static int rwwriter2_done = 0;
  91. static int rwreader1_iterations = 0;
  92. static int rwreader2_iterations = 0;
  93. static int rwwriter1_iterations = 0;
  94. static int rwwriter2_iterations = 0;
  95. static int *rwwriter_ptr = NULL;
  96. static int rw_torture_result = 1;
  97. static CRYPTO_RWLOCK *rwtorturelock = NULL;
  98. static CRYPTO_RWLOCK *atomiclock = NULL;
  99. static void rwwriter_fn(int id, int *iterations)
  100. {
  101. int count;
  102. int *old, *new;
  103. OSSL_TIME t1, t2;
  104. t1 = ossl_time_now();
  105. for (count = 0; ; count++) {
  106. new = CRYPTO_zalloc(sizeof (int), NULL, 0);
  107. if (contention == 0)
  108. OSSL_sleep(1000);
  109. if (!CRYPTO_THREAD_write_lock(rwtorturelock))
  110. abort();
  111. if (rwwriter_ptr != NULL) {
  112. *new = *rwwriter_ptr + 1;
  113. } else {
  114. *new = 0;
  115. }
  116. old = rwwriter_ptr;
  117. rwwriter_ptr = new;
  118. if (!CRYPTO_THREAD_unlock(rwtorturelock))
  119. abort();
  120. if (old != NULL)
  121. CRYPTO_free(old, __FILE__, __LINE__);
  122. t2 = ossl_time_now();
  123. if ((ossl_time2seconds(t2) - ossl_time2seconds(t1)) >= 4)
  124. break;
  125. }
  126. *iterations = count;
  127. return;
  128. }
  129. static void rwwriter1_fn(void)
  130. {
  131. int local;
  132. TEST_info("Starting writer1");
  133. rwwriter_fn(1, &rwwriter1_iterations);
  134. CRYPTO_atomic_add(&rwwriter1_done, 1, &local, atomiclock);
  135. }
  136. static void rwwriter2_fn(void)
  137. {
  138. int local;
  139. TEST_info("Starting writer 2");
  140. rwwriter_fn(2, &rwwriter2_iterations);
  141. CRYPTO_atomic_add(&rwwriter2_done, 1, &local, atomiclock);
  142. }
  143. static void rwreader_fn(int *iterations)
  144. {
  145. unsigned int count = 0;
  146. int old = 0;
  147. int lw1 = 0;
  148. int lw2 = 0;
  149. if (CRYPTO_THREAD_read_lock(rwtorturelock) == 0)
  150. abort();
  151. while (lw1 != 1 || lw2 != 1) {
  152. CRYPTO_atomic_add(&rwwriter1_done, 0, &lw1, atomiclock);
  153. CRYPTO_atomic_add(&rwwriter2_done, 0, &lw2, atomiclock);
  154. count++;
  155. if (rwwriter_ptr != NULL && old > *rwwriter_ptr) {
  156. TEST_info("rwwriter pointer went backwards\n");
  157. rw_torture_result = 0;
  158. }
  159. if (CRYPTO_THREAD_unlock(rwtorturelock) == 0)
  160. abort();
  161. *iterations = count;
  162. if (rw_torture_result == 0) {
  163. *iterations = count;
  164. return;
  165. }
  166. if (CRYPTO_THREAD_read_lock(rwtorturelock) == 0)
  167. abort();
  168. }
  169. *iterations = count;
  170. if (CRYPTO_THREAD_unlock(rwtorturelock) == 0)
  171. abort();
  172. }
  173. static void rwreader1_fn(void)
  174. {
  175. TEST_info("Starting reader 1");
  176. rwreader_fn(&rwreader1_iterations);
  177. }
  178. static void rwreader2_fn(void)
  179. {
  180. TEST_info("Starting reader 2");
  181. rwreader_fn(&rwreader2_iterations);
  182. }
  183. static thread_t rwwriter1;
  184. static thread_t rwwriter2;
  185. static thread_t rwreader1;
  186. static thread_t rwreader2;
  187. static int _torture_rw(void)
  188. {
  189. double tottime = 0;
  190. int ret = 0;
  191. double avr, avw;
  192. OSSL_TIME t1, t2;
  193. struct timeval dtime;
  194. rwtorturelock = CRYPTO_THREAD_lock_new();
  195. atomiclock = CRYPTO_THREAD_lock_new();
  196. if (!TEST_ptr(rwtorturelock) || !TEST_ptr(atomiclock))
  197. goto out;
  198. rwwriter1_iterations = 0;
  199. rwwriter2_iterations = 0;
  200. rwreader1_iterations = 0;
  201. rwreader2_iterations = 0;
  202. rwwriter1_done = 0;
  203. rwwriter2_done = 0;
  204. rw_torture_result = 1;
  205. memset(&rwwriter1, 0, sizeof(thread_t));
  206. memset(&rwwriter2, 0, sizeof(thread_t));
  207. memset(&rwreader1, 0, sizeof(thread_t));
  208. memset(&rwreader2, 0, sizeof(thread_t));
  209. TEST_info("Staring rw torture");
  210. t1 = ossl_time_now();
  211. if (!TEST_true(run_thread(&rwreader1, rwreader1_fn))
  212. || !TEST_true(run_thread(&rwreader2, rwreader2_fn))
  213. || !TEST_true(run_thread(&rwwriter1, rwwriter1_fn))
  214. || !TEST_true(run_thread(&rwwriter2, rwwriter2_fn))
  215. || !TEST_true(wait_for_thread(rwwriter1))
  216. || !TEST_true(wait_for_thread(rwwriter2))
  217. || !TEST_true(wait_for_thread(rwreader1))
  218. || !TEST_true(wait_for_thread(rwreader2)))
  219. goto out;
  220. t2 = ossl_time_now();
  221. dtime = ossl_time_to_timeval(ossl_time_subtract(t2, t1));
  222. tottime = dtime.tv_sec + (dtime.tv_usec / 1e6);
  223. TEST_info("rw_torture_result is %d\n", rw_torture_result);
  224. TEST_info("performed %d reads and %d writes over 2 read and 2 write threads in %e seconds",
  225. rwreader1_iterations + rwreader2_iterations,
  226. rwwriter1_iterations + rwwriter2_iterations, tottime);
  227. if ((rwreader1_iterations + rwreader2_iterations == 0)
  228. || (rwwriter1_iterations + rwwriter2_iterations == 0)) {
  229. TEST_info("Threads did not iterate\n");
  230. goto out;
  231. }
  232. avr = tottime / (rwreader1_iterations + rwreader2_iterations);
  233. avw = (tottime / (rwwriter1_iterations + rwwriter2_iterations));
  234. TEST_info("Average read time %e/read", avr);
  235. TEST_info("Averate write time %e/write", avw);
  236. if (TEST_int_eq(rw_torture_result, 1))
  237. ret = 1;
  238. out:
  239. CRYPTO_THREAD_lock_free(rwtorturelock);
  240. CRYPTO_THREAD_lock_free(atomiclock);
  241. rwtorturelock = NULL;
  242. return ret;
  243. }
  244. static int torture_rw_low(void)
  245. {
  246. contention = 0;
  247. return _torture_rw();
  248. }
  249. static int torture_rw_high(void)
  250. {
  251. contention = 1;
  252. return _torture_rw();
  253. }
  254. # ifndef OPENSSL_SYS_MACOSX
  255. static CRYPTO_RCU_LOCK *rcu_lock = NULL;
  256. static int writer1_done = 0;
  257. static int writer2_done = 0;
  258. static int reader1_iterations = 0;
  259. static int reader2_iterations = 0;
  260. static int writer1_iterations = 0;
  261. static int writer2_iterations = 0;
  262. static uint64_t *writer_ptr = NULL;
  263. static uint64_t global_ctr = 0;
  264. static int rcu_torture_result = 1;
  265. static void free_old_rcu_data(void *data)
  266. {
  267. CRYPTO_free(data, NULL, 0);
  268. }
  269. static void writer_fn(int id, int *iterations)
  270. {
  271. int count;
  272. OSSL_TIME t1, t2;
  273. uint64_t *old, *new;
  274. t1 = ossl_time_now();
  275. for (count = 0; ; count++) {
  276. new = CRYPTO_zalloc(sizeof(uint64_t), NULL, 0);
  277. if (contention == 0)
  278. OSSL_sleep(1000);
  279. ossl_rcu_write_lock(rcu_lock);
  280. old = ossl_rcu_deref(&writer_ptr);
  281. TSAN_ACQUIRE(&writer_ptr);
  282. *new = global_ctr++;
  283. ossl_rcu_assign_ptr(&writer_ptr, &new);
  284. if (contention == 0)
  285. ossl_rcu_call(rcu_lock, free_old_rcu_data, old);
  286. ossl_rcu_write_unlock(rcu_lock);
  287. if (contention != 0) {
  288. ossl_synchronize_rcu(rcu_lock);
  289. CRYPTO_free(old, NULL, 0);
  290. }
  291. t2 = ossl_time_now();
  292. if ((ossl_time2seconds(t2) - ossl_time2seconds(t1)) >= 4)
  293. break;
  294. }
  295. *iterations = count;
  296. return;
  297. }
  298. static void writer1_fn(void)
  299. {
  300. int local;
  301. TEST_info("Starting writer1");
  302. writer_fn(1, &writer1_iterations);
  303. CRYPTO_atomic_add(&writer1_done, 1, &local, atomiclock);
  304. }
  305. static void writer2_fn(void)
  306. {
  307. int local;
  308. TEST_info("Starting writer2");
  309. writer_fn(2, &writer2_iterations);
  310. CRYPTO_atomic_add(&writer2_done, 1, &local, atomiclock);
  311. }
  312. static void reader_fn(int *iterations)
  313. {
  314. unsigned int count = 0;
  315. uint64_t *valp;
  316. uint64_t val;
  317. uint64_t oldval = 0;
  318. int lw1 = 0;
  319. int lw2 = 0;
  320. while (lw1 != 1 || lw2 != 1) {
  321. CRYPTO_atomic_add(&writer1_done, 0, &lw1, atomiclock);
  322. CRYPTO_atomic_add(&writer2_done, 0, &lw2, atomiclock);
  323. count++;
  324. ossl_rcu_read_lock(rcu_lock);
  325. valp = ossl_rcu_deref(&writer_ptr);
  326. val = (valp == NULL) ? 0 : *valp;
  327. if (oldval > val) {
  328. TEST_info("rcu torture value went backwards! %llu : %llu", (unsigned long long)oldval, (unsigned long long)val);
  329. rcu_torture_result = 0;
  330. }
  331. oldval = val; /* just try to deref the pointer */
  332. ossl_rcu_read_unlock(rcu_lock);
  333. if (rcu_torture_result == 0) {
  334. *iterations = count;
  335. return;
  336. }
  337. }
  338. *iterations = count;
  339. }
  340. static void reader1_fn(void)
  341. {
  342. TEST_info("Starting reader 1");
  343. reader_fn(&reader1_iterations);
  344. }
  345. static void reader2_fn(void)
  346. {
  347. TEST_info("Starting reader 2");
  348. reader_fn(&reader2_iterations);
  349. }
  350. static thread_t writer1;
  351. static thread_t writer2;
  352. static thread_t reader1;
  353. static thread_t reader2;
  354. static int _torture_rcu(void)
  355. {
  356. OSSL_TIME t1, t2;
  357. struct timeval dtime;
  358. double tottime;
  359. double avr, avw;
  360. int rc = 0;
  361. atomiclock = CRYPTO_THREAD_lock_new();
  362. if (!TEST_ptr(atomiclock))
  363. goto out;
  364. memset(&writer1, 0, sizeof(thread_t));
  365. memset(&writer2, 0, sizeof(thread_t));
  366. memset(&reader1, 0, sizeof(thread_t));
  367. memset(&reader2, 0, sizeof(thread_t));
  368. writer1_iterations = 0;
  369. writer2_iterations = 0;
  370. reader1_iterations = 0;
  371. reader2_iterations = 0;
  372. writer1_done = 0;
  373. writer2_done = 0;
  374. rcu_torture_result = 1;
  375. rcu_lock = ossl_rcu_lock_new(1, NULL);
  376. if (!rcu_lock)
  377. goto out;
  378. TEST_info("Staring rcu torture");
  379. t1 = ossl_time_now();
  380. if (!TEST_true(run_thread(&reader1, reader1_fn))
  381. || !TEST_true(run_thread(&reader2, reader2_fn))
  382. || !TEST_true(run_thread(&writer1, writer1_fn))
  383. || !TEST_true(run_thread(&writer2, writer2_fn))
  384. || !TEST_true(wait_for_thread(writer1))
  385. || !TEST_true(wait_for_thread(writer2))
  386. || !TEST_true(wait_for_thread(reader1))
  387. || !TEST_true(wait_for_thread(reader2)))
  388. goto out;
  389. t2 = ossl_time_now();
  390. dtime = ossl_time_to_timeval(ossl_time_subtract(t2, t1));
  391. tottime = dtime.tv_sec + (dtime.tv_usec / 1e6);
  392. TEST_info("rcu_torture_result is %d\n", rcu_torture_result);
  393. TEST_info("performed %d reads and %d writes over 2 read and 2 write threads in %e seconds",
  394. reader1_iterations + reader2_iterations,
  395. writer1_iterations + writer2_iterations, tottime);
  396. if ((reader1_iterations + reader2_iterations == 0)
  397. || (writer1_iterations + writer2_iterations == 0)) {
  398. TEST_info("Threads did not iterate\n");
  399. goto out;
  400. }
  401. avr = tottime / (reader1_iterations + reader2_iterations);
  402. avw = tottime / (writer1_iterations + writer2_iterations);
  403. TEST_info("Average read time %e/read", avr);
  404. TEST_info("Average write time %e/write", avw);
  405. if (!TEST_int_eq(rcu_torture_result, 1))
  406. goto out;
  407. rc = 1;
  408. out:
  409. ossl_rcu_lock_free(rcu_lock);
  410. CRYPTO_THREAD_lock_free(atomiclock);
  411. if (!TEST_int_eq(rcu_torture_result, 1))
  412. return 0;
  413. return rc;
  414. }
  415. static int torture_rcu_low(void)
  416. {
  417. contention = 0;
  418. return _torture_rcu();
  419. }
  420. static int torture_rcu_high(void)
  421. {
  422. contention = 1;
  423. return _torture_rcu();
  424. }
  425. # endif
  426. #endif
  427. static CRYPTO_ONCE once_run = CRYPTO_ONCE_STATIC_INIT;
  428. static unsigned once_run_count = 0;
  429. static void once_do_run(void)
  430. {
  431. once_run_count++;
  432. }
  433. static void once_run_thread_cb(void)
  434. {
  435. CRYPTO_THREAD_run_once(&once_run, once_do_run);
  436. }
  437. static int test_once(void)
  438. {
  439. thread_t thread;
  440. if (!TEST_true(run_thread(&thread, once_run_thread_cb))
  441. || !TEST_true(wait_for_thread(thread))
  442. || !CRYPTO_THREAD_run_once(&once_run, once_do_run)
  443. || !TEST_int_eq(once_run_count, 1))
  444. return 0;
  445. return 1;
  446. }
  447. static CRYPTO_THREAD_LOCAL thread_local_key;
  448. static unsigned destructor_run_count = 0;
  449. static int thread_local_thread_cb_ok = 0;
  450. static void thread_local_destructor(void *arg)
  451. {
  452. unsigned *count;
  453. if (arg == NULL)
  454. return;
  455. count = arg;
  456. (*count)++;
  457. }
  458. static void thread_local_thread_cb(void)
  459. {
  460. void *ptr;
  461. ptr = CRYPTO_THREAD_get_local(&thread_local_key);
  462. if (!TEST_ptr_null(ptr)
  463. || !TEST_true(CRYPTO_THREAD_set_local(&thread_local_key,
  464. &destructor_run_count)))
  465. return;
  466. ptr = CRYPTO_THREAD_get_local(&thread_local_key);
  467. if (!TEST_ptr_eq(ptr, &destructor_run_count))
  468. return;
  469. thread_local_thread_cb_ok = 1;
  470. }
  471. static int test_thread_local(void)
  472. {
  473. thread_t thread;
  474. void *ptr = NULL;
  475. if (!TEST_true(CRYPTO_THREAD_init_local(&thread_local_key,
  476. thread_local_destructor)))
  477. return 0;
  478. ptr = CRYPTO_THREAD_get_local(&thread_local_key);
  479. if (!TEST_ptr_null(ptr)
  480. || !TEST_true(run_thread(&thread, thread_local_thread_cb))
  481. || !TEST_true(wait_for_thread(thread))
  482. || !TEST_int_eq(thread_local_thread_cb_ok, 1))
  483. return 0;
  484. #if defined(OPENSSL_THREADS) && !defined(CRYPTO_TDEBUG)
  485. ptr = CRYPTO_THREAD_get_local(&thread_local_key);
  486. if (!TEST_ptr_null(ptr))
  487. return 0;
  488. # if !defined(OPENSSL_SYS_WINDOWS)
  489. if (!TEST_int_eq(destructor_run_count, 1))
  490. return 0;
  491. # endif
  492. #endif
  493. if (!TEST_true(CRYPTO_THREAD_cleanup_local(&thread_local_key)))
  494. return 0;
  495. return 1;
  496. }
  497. static int test_atomic(void)
  498. {
  499. int val = 0, ret = 0, testresult = 0;
  500. uint64_t val64 = 1, ret64 = 0;
  501. CRYPTO_RWLOCK *lock = CRYPTO_THREAD_lock_new();
  502. if (!TEST_ptr(lock))
  503. return 0;
  504. if (CRYPTO_atomic_add(&val, 1, &ret, NULL)) {
  505. /* This succeeds therefore we're on a platform with lockless atomics */
  506. if (!TEST_int_eq(val, 1) || !TEST_int_eq(val, ret))
  507. goto err;
  508. } else {
  509. /* This failed therefore we're on a platform without lockless atomics */
  510. if (!TEST_int_eq(val, 0) || !TEST_int_eq(val, ret))
  511. goto err;
  512. }
  513. val = 0;
  514. ret = 0;
  515. if (!TEST_true(CRYPTO_atomic_add(&val, 1, &ret, lock)))
  516. goto err;
  517. if (!TEST_int_eq(val, 1) || !TEST_int_eq(val, ret))
  518. goto err;
  519. if (CRYPTO_atomic_or(&val64, 2, &ret64, NULL)) {
  520. /* This succeeds therefore we're on a platform with lockless atomics */
  521. if (!TEST_uint_eq((unsigned int)val64, 3)
  522. || !TEST_uint_eq((unsigned int)val64, (unsigned int)ret64))
  523. goto err;
  524. } else {
  525. /* This failed therefore we're on a platform without lockless atomics */
  526. if (!TEST_uint_eq((unsigned int)val64, 1)
  527. || !TEST_int_eq((unsigned int)ret64, 0))
  528. goto err;
  529. }
  530. val64 = 1;
  531. ret64 = 0;
  532. if (!TEST_true(CRYPTO_atomic_or(&val64, 2, &ret64, lock)))
  533. goto err;
  534. if (!TEST_uint_eq((unsigned int)val64, 3)
  535. || !TEST_uint_eq((unsigned int)val64, (unsigned int)ret64))
  536. goto err;
  537. ret64 = 0;
  538. if (CRYPTO_atomic_load(&val64, &ret64, NULL)) {
  539. /* This succeeds therefore we're on a platform with lockless atomics */
  540. if (!TEST_uint_eq((unsigned int)val64, 3)
  541. || !TEST_uint_eq((unsigned int)val64, (unsigned int)ret64))
  542. goto err;
  543. } else {
  544. /* This failed therefore we're on a platform without lockless atomics */
  545. if (!TEST_uint_eq((unsigned int)val64, 3)
  546. || !TEST_int_eq((unsigned int)ret64, 0))
  547. goto err;
  548. }
  549. ret64 = 0;
  550. if (!TEST_true(CRYPTO_atomic_load(&val64, &ret64, lock)))
  551. goto err;
  552. if (!TEST_uint_eq((unsigned int)val64, 3)
  553. || !TEST_uint_eq((unsigned int)val64, (unsigned int)ret64))
  554. goto err;
  555. testresult = 1;
  556. err:
  557. CRYPTO_THREAD_lock_free(lock);
  558. return testresult;
  559. }
  560. static OSSL_LIB_CTX *multi_libctx = NULL;
  561. static int multi_success;
  562. static OSSL_PROVIDER *multi_provider[MAXIMUM_PROVIDERS + 1];
  563. static size_t multi_num_threads;
  564. static thread_t multi_threads[MAXIMUM_THREADS];
  565. static void multi_intialise(void)
  566. {
  567. multi_success = 1;
  568. multi_libctx = NULL;
  569. multi_num_threads = 0;
  570. memset(multi_threads, 0, sizeof(multi_threads));
  571. memset(multi_provider, 0, sizeof(multi_provider));
  572. }
  573. static void multi_set_success(int ok)
  574. {
  575. if (CRYPTO_THREAD_write_lock(global_lock) == 0) {
  576. /* not synchronized, but better than not reporting failure */
  577. multi_success = ok;
  578. return;
  579. }
  580. multi_success = ok;
  581. CRYPTO_THREAD_unlock(global_lock);
  582. }
  583. static void thead_teardown_libctx(void)
  584. {
  585. OSSL_PROVIDER **p;
  586. for (p = multi_provider; *p != NULL; p++)
  587. OSSL_PROVIDER_unload(*p);
  588. OSSL_LIB_CTX_free(multi_libctx);
  589. multi_intialise();
  590. }
  591. static int thread_setup_libctx(int libctx, const char *providers[])
  592. {
  593. size_t n;
  594. if (libctx && !TEST_true(test_get_libctx(&multi_libctx, NULL, config_file,
  595. NULL, NULL)))
  596. return 0;
  597. if (providers != NULL)
  598. for (n = 0; providers[n] != NULL; n++)
  599. if (!TEST_size_t_lt(n, MAXIMUM_PROVIDERS)
  600. || !TEST_ptr(multi_provider[n] = OSSL_PROVIDER_load(multi_libctx,
  601. providers[n]))) {
  602. thead_teardown_libctx();
  603. return 0;
  604. }
  605. return 1;
  606. }
  607. static int teardown_threads(void)
  608. {
  609. size_t i;
  610. for (i = 0; i < multi_num_threads; i++)
  611. if (!TEST_true(wait_for_thread(multi_threads[i])))
  612. return 0;
  613. return 1;
  614. }
  615. static int start_threads(size_t n, void (*thread_func)(void))
  616. {
  617. size_t i;
  618. if (!TEST_size_t_le(multi_num_threads + n, MAXIMUM_THREADS))
  619. return 0;
  620. for (i = 0 ; i < n; i++)
  621. if (!TEST_true(run_thread(multi_threads + multi_num_threads++, thread_func)))
  622. return 0;
  623. return 1;
  624. }
  625. /* Template multi-threaded test function */
  626. static int thread_run_test(void (*main_func)(void),
  627. size_t num_threads, void (*thread_func)(void),
  628. int libctx, const char *providers[])
  629. {
  630. int testresult = 0;
  631. multi_intialise();
  632. if (!thread_setup_libctx(libctx, providers)
  633. || !start_threads(num_threads, thread_func))
  634. goto err;
  635. if (main_func != NULL)
  636. main_func();
  637. if (!teardown_threads()
  638. || !TEST_true(multi_success))
  639. goto err;
  640. testresult = 1;
  641. err:
  642. thead_teardown_libctx();
  643. return testresult;
  644. }
  645. static void thread_general_worker(void)
  646. {
  647. EVP_MD_CTX *mdctx = EVP_MD_CTX_new();
  648. EVP_MD *md = EVP_MD_fetch(multi_libctx, "SHA2-256", NULL);
  649. EVP_CIPHER_CTX *cipherctx = EVP_CIPHER_CTX_new();
  650. EVP_CIPHER *ciph = EVP_CIPHER_fetch(multi_libctx, "AES-128-CBC", NULL);
  651. const char *message = "Hello World";
  652. size_t messlen = strlen(message);
  653. /* Should be big enough for encryption output too */
  654. unsigned char out[EVP_MAX_MD_SIZE];
  655. const unsigned char key[AES_BLOCK_SIZE] = {
  656. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  657. 0x0c, 0x0d, 0x0e, 0x0f
  658. };
  659. const unsigned char iv[AES_BLOCK_SIZE] = {
  660. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  661. 0x0c, 0x0d, 0x0e, 0x0f
  662. };
  663. unsigned int mdoutl;
  664. int ciphoutl;
  665. EVP_PKEY *pkey = NULL;
  666. int testresult = 0;
  667. int i, isfips;
  668. isfips = OSSL_PROVIDER_available(multi_libctx, "fips");
  669. if (!TEST_ptr(mdctx)
  670. || !TEST_ptr(md)
  671. || !TEST_ptr(cipherctx)
  672. || !TEST_ptr(ciph))
  673. goto err;
  674. /* Do some work */
  675. for (i = 0; i < 5; i++) {
  676. if (!TEST_true(EVP_DigestInit_ex(mdctx, md, NULL))
  677. || !TEST_true(EVP_DigestUpdate(mdctx, message, messlen))
  678. || !TEST_true(EVP_DigestFinal(mdctx, out, &mdoutl)))
  679. goto err;
  680. }
  681. for (i = 0; i < 5; i++) {
  682. if (!TEST_true(EVP_EncryptInit_ex(cipherctx, ciph, NULL, key, iv))
  683. || !TEST_true(EVP_EncryptUpdate(cipherctx, out, &ciphoutl,
  684. (unsigned char *)message,
  685. messlen))
  686. || !TEST_true(EVP_EncryptFinal(cipherctx, out, &ciphoutl)))
  687. goto err;
  688. }
  689. /*
  690. * We want the test to run quickly - not securely.
  691. * Therefore we use an insecure bit length where we can (512).
  692. * In the FIPS module though we must use a longer length.
  693. */
  694. pkey = EVP_PKEY_Q_keygen(multi_libctx, NULL, "RSA", isfips ? 2048 : 512);
  695. if (!TEST_ptr(pkey))
  696. goto err;
  697. testresult = 1;
  698. err:
  699. EVP_MD_CTX_free(mdctx);
  700. EVP_MD_free(md);
  701. EVP_CIPHER_CTX_free(cipherctx);
  702. EVP_CIPHER_free(ciph);
  703. EVP_PKEY_free(pkey);
  704. if (!testresult)
  705. multi_set_success(0);
  706. }
  707. static void thread_multi_simple_fetch(void)
  708. {
  709. EVP_MD *md = EVP_MD_fetch(multi_libctx, "SHA2-256", NULL);
  710. if (md != NULL)
  711. EVP_MD_free(md);
  712. else
  713. multi_set_success(0);
  714. }
  715. static EVP_PKEY *shared_evp_pkey = NULL;
  716. static void thread_shared_evp_pkey(void)
  717. {
  718. char *msg = "Hello World";
  719. unsigned char ctbuf[256];
  720. unsigned char ptbuf[256];
  721. size_t ptlen, ctlen = sizeof(ctbuf);
  722. EVP_PKEY_CTX *ctx = NULL;
  723. int success = 0;
  724. int i;
  725. for (i = 0; i < 1 + do_fips; i++) {
  726. if (i > 0)
  727. EVP_PKEY_CTX_free(ctx);
  728. ctx = EVP_PKEY_CTX_new_from_pkey(multi_libctx, shared_evp_pkey,
  729. i == 0 ? "provider=default"
  730. : "provider=fips");
  731. if (!TEST_ptr(ctx))
  732. goto err;
  733. if (!TEST_int_ge(EVP_PKEY_encrypt_init(ctx), 0)
  734. || !TEST_int_ge(EVP_PKEY_encrypt(ctx, ctbuf, &ctlen,
  735. (unsigned char *)msg, strlen(msg)),
  736. 0))
  737. goto err;
  738. EVP_PKEY_CTX_free(ctx);
  739. ctx = EVP_PKEY_CTX_new_from_pkey(multi_libctx, shared_evp_pkey, NULL);
  740. if (!TEST_ptr(ctx))
  741. goto err;
  742. ptlen = sizeof(ptbuf);
  743. if (!TEST_int_ge(EVP_PKEY_decrypt_init(ctx), 0)
  744. || !TEST_int_gt(EVP_PKEY_decrypt(ctx, ptbuf, &ptlen, ctbuf, ctlen),
  745. 0)
  746. || !TEST_mem_eq(msg, strlen(msg), ptbuf, ptlen))
  747. goto err;
  748. }
  749. success = 1;
  750. err:
  751. EVP_PKEY_CTX_free(ctx);
  752. if (!success)
  753. multi_set_success(0);
  754. }
  755. static void thread_provider_load_unload(void)
  756. {
  757. OSSL_PROVIDER *deflt = OSSL_PROVIDER_load(multi_libctx, "default");
  758. if (!TEST_ptr(deflt)
  759. || !TEST_true(OSSL_PROVIDER_available(multi_libctx, "default")))
  760. multi_set_success(0);
  761. OSSL_PROVIDER_unload(deflt);
  762. }
  763. static int test_multi_general_worker_default_provider(void)
  764. {
  765. return thread_run_test(&thread_general_worker, 2, &thread_general_worker,
  766. 1, default_provider);
  767. }
  768. static int test_multi_general_worker_fips_provider(void)
  769. {
  770. if (!do_fips)
  771. return TEST_skip("FIPS not supported");
  772. return thread_run_test(&thread_general_worker, 2, &thread_general_worker,
  773. 1, fips_provider);
  774. }
  775. static int test_multi_fetch_worker(void)
  776. {
  777. return thread_run_test(&thread_multi_simple_fetch,
  778. 2, &thread_multi_simple_fetch, 1, default_provider);
  779. }
  780. static int test_multi_shared_pkey_common(void (*worker)(void))
  781. {
  782. int testresult = 0;
  783. multi_intialise();
  784. if (!thread_setup_libctx(1, do_fips ? fips_and_default_providers
  785. : default_provider)
  786. || !TEST_ptr(shared_evp_pkey = load_pkey_pem(privkey, multi_libctx))
  787. || !start_threads(1, &thread_shared_evp_pkey)
  788. || !start_threads(1, worker))
  789. goto err;
  790. thread_shared_evp_pkey();
  791. if (!teardown_threads()
  792. || !TEST_true(multi_success))
  793. goto err;
  794. testresult = 1;
  795. err:
  796. EVP_PKEY_free(shared_evp_pkey);
  797. thead_teardown_libctx();
  798. return testresult;
  799. }
  800. #ifndef OPENSSL_NO_DEPRECATED_3_0
  801. static void thread_downgrade_shared_evp_pkey(void)
  802. {
  803. /*
  804. * This test is only relevant for deprecated functions that perform
  805. * downgrading
  806. */
  807. if (EVP_PKEY_get0_RSA(shared_evp_pkey) == NULL)
  808. multi_set_success(0);
  809. }
  810. static int test_multi_downgrade_shared_pkey(void)
  811. {
  812. return test_multi_shared_pkey_common(&thread_downgrade_shared_evp_pkey);
  813. }
  814. #endif
  815. static int test_multi_shared_pkey(void)
  816. {
  817. return test_multi_shared_pkey_common(&thread_shared_evp_pkey);
  818. }
  819. static int test_multi_load_unload_provider(void)
  820. {
  821. EVP_MD *sha256 = NULL;
  822. OSSL_PROVIDER *prov = NULL;
  823. int testresult = 0;
  824. multi_intialise();
  825. if (!thread_setup_libctx(1, NULL)
  826. || !TEST_ptr(prov = OSSL_PROVIDER_load(multi_libctx, "default"))
  827. || !TEST_ptr(sha256 = EVP_MD_fetch(multi_libctx, "SHA2-256", NULL))
  828. || !TEST_true(OSSL_PROVIDER_unload(prov)))
  829. goto err;
  830. prov = NULL;
  831. if (!start_threads(2, &thread_provider_load_unload))
  832. goto err;
  833. thread_provider_load_unload();
  834. if (!teardown_threads()
  835. || !TEST_true(multi_success))
  836. goto err;
  837. testresult = 1;
  838. err:
  839. OSSL_PROVIDER_unload(prov);
  840. EVP_MD_free(sha256);
  841. thead_teardown_libctx();
  842. return testresult;
  843. }
  844. static char *multi_load_provider = "legacy";
  845. /*
  846. * This test attempts to load several providers at the same time, and if
  847. * run with a thread sanitizer, should crash if the core provider code
  848. * doesn't synchronize well enough.
  849. */
  850. static void test_multi_load_worker(void)
  851. {
  852. OSSL_PROVIDER *prov;
  853. if (!TEST_ptr(prov = OSSL_PROVIDER_load(multi_libctx, multi_load_provider))
  854. || !TEST_true(OSSL_PROVIDER_unload(prov)))
  855. multi_set_success(0);
  856. }
  857. static int test_multi_default(void)
  858. {
  859. /* Avoid running this test twice */
  860. if (multidefault_run) {
  861. TEST_skip("multi default test already run");
  862. return 1;
  863. }
  864. multidefault_run = 1;
  865. return thread_run_test(&thread_multi_simple_fetch,
  866. 2, &thread_multi_simple_fetch, 0, default_provider);
  867. }
  868. static int test_multi_load(void)
  869. {
  870. int res = 1;
  871. OSSL_PROVIDER *prov;
  872. /* The multidefault test must run prior to this test */
  873. if (!multidefault_run) {
  874. TEST_info("Running multi default test first");
  875. res = test_multi_default();
  876. }
  877. /*
  878. * We use the legacy provider in test_multi_load_worker because it uses a
  879. * child libctx that might hit more codepaths that might be sensitive to
  880. * threading issues. But in a no-legacy build that won't be loadable so
  881. * we use the default provider instead.
  882. */
  883. prov = OSSL_PROVIDER_load(NULL, "legacy");
  884. if (prov == NULL) {
  885. TEST_info("Cannot load legacy provider - assuming this is a no-legacy build");
  886. multi_load_provider = "default";
  887. }
  888. OSSL_PROVIDER_unload(prov);
  889. return thread_run_test(NULL, MAXIMUM_THREADS, &test_multi_load_worker, 0,
  890. NULL) && res;
  891. }
  892. static void test_obj_create_one(void)
  893. {
  894. char tids[12], oid[40], sn[30], ln[30];
  895. int id = get_new_uid();
  896. BIO_snprintf(tids, sizeof(tids), "%d", id);
  897. BIO_snprintf(oid, sizeof(oid), "1.3.6.1.4.1.16604.%s", tids);
  898. BIO_snprintf(sn, sizeof(sn), "short-name-%s", tids);
  899. BIO_snprintf(ln, sizeof(ln), "long-name-%s", tids);
  900. if (!TEST_int_ne(id, 0)
  901. || !TEST_true(id = OBJ_create(oid, sn, ln))
  902. || !TEST_true(OBJ_add_sigid(id, NID_sha3_256, NID_rsa)))
  903. multi_set_success(0);
  904. }
  905. static int test_obj_add(void)
  906. {
  907. return thread_run_test(&test_obj_create_one,
  908. MAXIMUM_THREADS, &test_obj_create_one,
  909. 1, default_provider);
  910. }
  911. #if !defined(OPENSSL_NO_DGRAM) && !defined(OPENSSL_NO_SOCK)
  912. static BIO *multi_bio1, *multi_bio2;
  913. static void test_bio_dgram_pair_worker(void)
  914. {
  915. ossl_unused int r;
  916. int ok = 0;
  917. uint8_t ch = 0;
  918. uint8_t scratch[64];
  919. BIO_MSG msg = {0};
  920. size_t num_processed = 0;
  921. if (!TEST_int_eq(RAND_bytes_ex(multi_libctx, &ch, 1, 64), 1))
  922. goto err;
  923. msg.data = scratch;
  924. msg.data_len = sizeof(scratch);
  925. /*
  926. * We do not test for failure here as recvmmsg may fail if no sendmmsg
  927. * has been called yet. The purpose of this code is to exercise tsan.
  928. */
  929. if (ch & 2)
  930. r = BIO_sendmmsg(ch & 1 ? multi_bio2 : multi_bio1, &msg,
  931. sizeof(BIO_MSG), 1, 0, &num_processed);
  932. else
  933. r = BIO_recvmmsg(ch & 1 ? multi_bio2 : multi_bio1, &msg,
  934. sizeof(BIO_MSG), 1, 0, &num_processed);
  935. ok = 1;
  936. err:
  937. if (ok == 0)
  938. multi_set_success(0);
  939. }
  940. static int test_bio_dgram_pair(void)
  941. {
  942. int r;
  943. BIO *bio1 = NULL, *bio2 = NULL;
  944. r = BIO_new_bio_dgram_pair(&bio1, 0, &bio2, 0);
  945. if (!TEST_int_eq(r, 1))
  946. goto err;
  947. multi_bio1 = bio1;
  948. multi_bio2 = bio2;
  949. r = thread_run_test(&test_bio_dgram_pair_worker,
  950. MAXIMUM_THREADS, &test_bio_dgram_pair_worker,
  951. 1, default_provider);
  952. err:
  953. BIO_free(bio1);
  954. BIO_free(bio2);
  955. return r;
  956. }
  957. #endif
  958. static const char *pemdataraw[] = {
  959. "-----BEGIN RSA PRIVATE KEY-----\n",
  960. "MIIBOgIBAAJBAMFcGsaxxdgiuuGmCkVImy4h99CqT7jwY3pexPGcnUFtR2Fh36Bp\n",
  961. "oncwtkZ4cAgtvd4Qs8PkxUdp6p/DlUmObdkCAwEAAQJAUR44xX6zB3eaeyvTRzms\n",
  962. "kHADrPCmPWnr8dxsNwiDGHzrMKLN+i/HAam+97HxIKVWNDH2ba9Mf1SA8xu9dcHZ\n",
  963. "AQIhAOHPCLxbtQFVxlnhSyxYeb7O323c3QulPNn3bhOipElpAiEA2zZpBE8ZXVnL\n",
  964. "74QjG4zINlDfH+EOEtjJJ3RtaYDugvECIBtsQDxXytChsRgDQ1TcXdStXPcDppie\n",
  965. "dZhm8yhRTTBZAiAZjE/U9rsIDC0ebxIAZfn3iplWh84yGB3pgUI3J5WkoQIhAInE\n",
  966. "HTUY5WRj5riZtkyGnbm3DvF+1eMtO2lYV+OuLcfE\n",
  967. "-----END RSA PRIVATE KEY-----\n",
  968. NULL
  969. };
  970. static void test_pem_read_one(void)
  971. {
  972. EVP_PKEY *key = NULL;
  973. BIO *pem = NULL;
  974. char *pemdata;
  975. size_t len;
  976. pemdata = glue_strings(pemdataraw, &len);
  977. if (pemdata == NULL) {
  978. multi_set_success(0);
  979. goto err;
  980. }
  981. pem = BIO_new_mem_buf(pemdata, len);
  982. if (pem == NULL) {
  983. multi_set_success(0);
  984. goto err;
  985. }
  986. key = PEM_read_bio_PrivateKey(pem, NULL, NULL, NULL);
  987. if (key == NULL)
  988. multi_set_success(0);
  989. err:
  990. EVP_PKEY_free(key);
  991. BIO_free(pem);
  992. OPENSSL_free(pemdata);
  993. }
  994. /* Test reading PEM files in multiple threads */
  995. static int test_pem_read(void)
  996. {
  997. return thread_run_test(&test_pem_read_one, MAXIMUM_THREADS,
  998. &test_pem_read_one, 1, default_provider);
  999. }
  1000. typedef enum OPTION_choice {
  1001. OPT_ERR = -1,
  1002. OPT_EOF = 0,
  1003. OPT_FIPS, OPT_CONFIG_FILE,
  1004. OPT_TEST_ENUM
  1005. } OPTION_CHOICE;
  1006. const OPTIONS *test_get_options(void)
  1007. {
  1008. static const OPTIONS options[] = {
  1009. OPT_TEST_OPTIONS_DEFAULT_USAGE,
  1010. { "fips", OPT_FIPS, '-', "Test the FIPS provider" },
  1011. { "config", OPT_CONFIG_FILE, '<',
  1012. "The configuration file to use for the libctx" },
  1013. { NULL }
  1014. };
  1015. return options;
  1016. }
  1017. int setup_tests(void)
  1018. {
  1019. OPTION_CHOICE o;
  1020. char *datadir;
  1021. while ((o = opt_next()) != OPT_EOF) {
  1022. switch (o) {
  1023. case OPT_FIPS:
  1024. do_fips = 1;
  1025. break;
  1026. case OPT_CONFIG_FILE:
  1027. config_file = opt_arg();
  1028. break;
  1029. case OPT_TEST_CASES:
  1030. break;
  1031. default:
  1032. return 0;
  1033. }
  1034. }
  1035. if (!TEST_ptr(datadir = test_get_argument(0)))
  1036. return 0;
  1037. privkey = test_mk_file_path(datadir, "rsakey.pem");
  1038. if (!TEST_ptr(privkey))
  1039. return 0;
  1040. if (!TEST_ptr(global_lock = CRYPTO_THREAD_lock_new()))
  1041. return 0;
  1042. #ifdef TSAN_REQUIRES_LOCKING
  1043. if (!TEST_ptr(tsan_lock = CRYPTO_THREAD_lock_new()))
  1044. return 0;
  1045. #endif
  1046. /* Keep first to validate auto creation of default library context */
  1047. ADD_TEST(test_multi_default);
  1048. ADD_TEST(test_lock);
  1049. #if defined(OPENSSL_THREADS)
  1050. ADD_TEST(torture_rw_low);
  1051. ADD_TEST(torture_rw_high);
  1052. # ifndef OPENSSL_SYS_MACOSX
  1053. ADD_TEST(torture_rcu_low);
  1054. ADD_TEST(torture_rcu_high);
  1055. # endif
  1056. #endif
  1057. ADD_TEST(test_once);
  1058. ADD_TEST(test_thread_local);
  1059. ADD_TEST(test_atomic);
  1060. ADD_TEST(test_multi_load);
  1061. ADD_TEST(test_multi_general_worker_default_provider);
  1062. ADD_TEST(test_multi_general_worker_fips_provider);
  1063. ADD_TEST(test_multi_fetch_worker);
  1064. ADD_TEST(test_multi_shared_pkey);
  1065. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1066. ADD_TEST(test_multi_downgrade_shared_pkey);
  1067. #endif
  1068. ADD_TEST(test_multi_load_unload_provider);
  1069. ADD_TEST(test_obj_add);
  1070. #if !defined(OPENSSL_NO_DGRAM) && !defined(OPENSSL_NO_SOCK)
  1071. ADD_TEST(test_bio_dgram_pair);
  1072. #endif
  1073. ADD_TEST(test_pem_read);
  1074. return 1;
  1075. }
  1076. void cleanup_tests(void)
  1077. {
  1078. OPENSSL_free(privkey);
  1079. #ifdef TSAN_REQUIRES_LOCKING
  1080. CRYPTO_THREAD_lock_free(tsan_lock);
  1081. #endif
  1082. CRYPTO_THREAD_lock_free(global_lock);
  1083. }