summaryrefslogtreecommitdiffstats
path: root/test/threadstest.c
diff options
context:
space:
mode:
authorČestmír Kalina <ckalina@redhat.com>2022-10-21 11:08:24 +0200
committerTomas Mraz <tomas@openssl.org>2022-10-21 12:44:56 +0200
commit6ca4bd2e4c92531e74acba3e1ff08e6fbb664b20 (patch)
treee75a640d2bc33ee8c1bbb578ad5961310f1385b1 /test/threadstest.c
parent4e43bc06f7673597a99f61325543449e72070c8c (diff)
test: threads: replace test_thread_noreturn
While POSIX threads are cancellable and may be asynchronously cancelled, their cancellation is not guaranteed by the POSIX standard. test_thread_noreturn, which simulates a long-running possibly unresponsive thread: THREAD #1 THREAD #2 LOCK L1 SPAWN #2 LOCK L1 On MacOS, cancelling such thread only queues cancellation request, but the following pthread_join hangs. Replace this implementation by an unbounded sequence of sleeps instead. Signed-off-by: Čestmír Kalina <ckalina@redhat.com> Reviewed-by: Hugo Landau <hlandau@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/19433)
Diffstat (limited to 'test/threadstest.c')
-rw-r--r--test/threadstest.c31
1 files changed, 8 insertions, 23 deletions
diff --git a/test/threadstest.c b/test/threadstest.c
index 6ddb4bf96c..cd1277082c 100644
--- a/test/threadstest.c
+++ b/test/threadstest.c
@@ -787,13 +787,13 @@ static uint32_t test_thread_native_fn(void *data)
static uint32_t test_thread_noreturn(void *data)
{
- CRYPTO_MUTEX *lock = (uint32_t*) data;
-
- /* lock is assumed to be locked */
- ossl_crypto_mutex_lock(lock);
+ while (1) {
+ OSSL_sleep(1000);
+ }
/* unreachable */
OPENSSL_die("test_thread_noreturn", __FILE__, __LINE__);
+
return 0;
}
@@ -801,11 +801,9 @@ static uint32_t test_thread_noreturn(void *data)
static int test_thread_native(void)
{
- int testval = 0;
uint32_t retval;
uint32_t local;
CRYPTO_THREAD *t;
- CRYPTO_MUTEX *lock;
/* thread spawn, join and termination */
@@ -845,28 +843,15 @@ static int test_thread_native(void)
/* termination of a long running thread */
- lock = ossl_crypto_mutex_new();
- if (!TEST_ptr(lock))
- return 0;
- ossl_crypto_mutex_lock(lock);
-
- t = ossl_crypto_thread_native_start(test_thread_noreturn, lock, 1);
+ t = ossl_crypto_thread_native_start(test_thread_noreturn, NULL, 1);
if (!TEST_ptr(t))
- goto fail;
+ return 0;
if (!TEST_int_eq(ossl_crypto_thread_native_terminate(t), 1))
- goto fail;
+ return 0;
if (!TEST_int_eq(ossl_crypto_thread_native_clean(t), 1))
- goto fail;
-
- testval = 1;
-
-fail:
- ossl_crypto_mutex_unlock(lock);
- ossl_crypto_mutex_free(&lock);
- if (!TEST_ptr_null(lock))
return 0;
- return testval;
+ return 1;
}
#if !defined(OPENSSL_NO_DEFAULT_THREAD_POOL)