uint32_t threads_supported;
size_t i;
void *t[3];
+ int status = 0;
OSSL_LIB_CTX *cust_ctx = OSSL_LIB_CTX_new();
threads_supported = OSSL_get_thread_support_flags();
if (threads_supported == 0) {
if (!TEST_uint64_t_eq(OSSL_get_max_threads(NULL), 0))
- return 0;
+ goto cleanup;
if (!TEST_uint64_t_eq(OSSL_get_max_threads(cust_ctx), 0))
- return 0;
+ goto cleanup;
if (!TEST_int_eq(OSSL_set_max_threads(NULL, 1), 0))
- return 0;
+ goto cleanup;
if (!TEST_int_eq(OSSL_set_max_threads(cust_ctx, 1), 0))
- return 0;
+ goto cleanup;
if (!TEST_uint64_t_eq(OSSL_get_max_threads(NULL), 0))
- return 0;
+ goto cleanup;
if (!TEST_uint64_t_eq(OSSL_get_max_threads(cust_ctx), 0))
- return 0;
+ goto cleanup;
t[0] = ossl_crypto_thread_start(NULL, test_thread_native_fn, &local[0]);
if (!TEST_ptr_null(t[0]))
- return 0;
+ goto cleanup;
- return 1;
+ status = 1;
+ goto cleanup;
}
/* fail when not allowed to use threads */
if (!TEST_uint64_t_eq(OSSL_get_max_threads(NULL), 0))
- return 0;
+ goto cleanup;
t[0] = ossl_crypto_thread_start(NULL, test_thread_native_fn, &local[0]);
if (!TEST_ptr_null(t[0]))
- return 0;
+ goto cleanup;
/* fail when enabled on a different context */
if (!TEST_uint64_t_eq(OSSL_get_max_threads(cust_ctx), 0))
- return 0;
+ goto cleanup;
if (!TEST_int_eq(OSSL_set_max_threads(cust_ctx, 1), 1))
- return 0;
+ goto cleanup;
if (!TEST_uint64_t_eq(OSSL_get_max_threads(NULL), 0))
- return 0;
+ goto cleanup;
if (!TEST_uint64_t_eq(OSSL_get_max_threads(cust_ctx), 1))
- return 0;
+ goto cleanup;
t[0] = ossl_crypto_thread_start(NULL, test_thread_native_fn, &local[0]);
if (!TEST_ptr_null(t[0]))
- return 0;
+ goto cleanup;
if (!TEST_int_eq(OSSL_set_max_threads(cust_ctx, 0), 1))
- return 0;
+ goto cleanup;
/* sequential startup */
if (!TEST_int_eq(OSSL_set_max_threads(NULL, 1), 1))
- return 0;
+ goto cleanup;
if (!TEST_uint64_t_eq(OSSL_get_max_threads(NULL), 1))
- return 0;
+ goto cleanup;
if (!TEST_uint64_t_eq(OSSL_get_max_threads(cust_ctx), 0))
- return 0;
+ goto cleanup;
for (i = 0; i < OSSL_NELEM(t); ++i) {
local[0] = i + 1;
t[i] = ossl_crypto_thread_start(NULL, test_thread_native_fn, &local[0]);
if (!TEST_ptr(t[i]))
- return 0;
+ goto cleanup;
/*
* pthread_join results in undefined behaviour if called on a joined
* if we do).
*/
if (!TEST_int_eq(ossl_crypto_thread_join(t[i], &retval[0]), 1))
- return 0;
+ goto cleanup;
if (!TEST_int_eq(ossl_crypto_thread_join(t[i], &retval[0]), 1))
- return 0;
+ goto cleanup;
if (!TEST_int_eq(retval[0], i + 1) || !TEST_int_eq(local[0], i + 2))
- return 0;
+ goto cleanup;
if (!TEST_int_eq(ossl_crypto_thread_clean(t[i]), 1))
- return 0;
+ goto cleanup;
t[i] = NULL;
if (!TEST_int_eq(ossl_crypto_thread_clean(t[i]), 0))
- return 0;
+ goto cleanup;
}
/* parallel startup */
if (!TEST_int_eq(OSSL_set_max_threads(NULL, OSSL_NELEM(t)), 1))
- return 0;
+ goto cleanup;
for (i = 0; i < OSSL_NELEM(t); ++i) {
local[i] = i + 1;
t[i] = ossl_crypto_thread_start(NULL, test_thread_native_fn, &local[i]);
if (!TEST_ptr(t[i]))
- return 0;
+ goto cleanup;
}
for (i = 0; i < OSSL_NELEM(t); ++i) {
if (!TEST_int_eq(ossl_crypto_thread_join(t[i], &retval[i]), 1))
- return 0;
+ goto cleanup;
}
for (i = 0; i < OSSL_NELEM(t); ++i) {
if (!TEST_int_eq(retval[i], i + 1) || !TEST_int_eq(local[i], i + 2))
- return 0;
+ goto cleanup;
if (!TEST_int_eq(ossl_crypto_thread_clean(t[i]), 1))
- return 0;
+ goto cleanup;
}
/* parallel startup, bottleneck */
if (!TEST_int_eq(OSSL_set_max_threads(NULL, OSSL_NELEM(t) - 1), 1))
- return 0;
+ goto cleanup;
for (i = 0; i < OSSL_NELEM(t); ++i) {
local[i] = i + 1;
t[i] = ossl_crypto_thread_start(NULL, test_thread_native_fn, &local[i]);
if (!TEST_ptr(t[i]))
- return 0;
+ goto cleanup;
}
for (i = 0; i < OSSL_NELEM(t); ++i) {
if (!TEST_int_eq(ossl_crypto_thread_join(t[i], &retval[i]), 1))
- return 0;
+ goto cleanup;
}
for (i = 0; i < OSSL_NELEM(t); ++i) {
if (!TEST_int_eq(retval[i], i + 1) || !TEST_int_eq(local[i], i + 2))
- return 0;
+ goto cleanup;
if (!TEST_int_eq(ossl_crypto_thread_clean(t[i]), 1))
- return 0;
+ goto cleanup;
}
if (!TEST_int_eq(OSSL_set_max_threads(NULL, 0), 1))
- return 0;
+ goto cleanup;
+ status = 1;
+cleanup:
OSSL_LIB_CTX_free(cust_ctx);
- return 1;
+ return status;
}
# endif