This is an automated email from the git hooks/post-receive script.
git pushed a commit to reference refs/pull/286/head
in repository efl.
View the commit online.
commit 080f640f0c321497523bfdb09892cf50353074de
Author: Cedric BAIL <[email protected]>
AuthorDate: Sat Nov 28 23:24:52 2026 -0600
eina:tests: do not cancel a thread inside a check assertion
eina_thread_test_cancel could hang until check gave up on it after 120
seconds, which a loaded machine, such as one running the whole of meson
test, would sometimes produce.
The thread became cancellable and then called ck_assert(). Even one that
passes writes the position it reached to the stream check reports
through. Signalled from inside that window, the main thread canceled the
thread in the middle of the write, which left the stream locked, and the
next assertion of the main thread never returned. Making the thread do
nothing but assert once cancellable hung the test 20 times out of 20.
It now asserts nothing after enabling cancellation.
The test could also miss its wakeup: the thread signaled without the
lock, so it could do so before the main thread was waiting. Delaying the
main thread by 200ms after creating the thread hung it every time.
With 32 copies of eina_suite running at once, 2 hung in the first round.
With this, 400 rounds, 12800 runs, all passed.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/tests/eina/eina_test_thread.c | 47 +++++++++++++++++++++++++++++----------
1 file changed, 35 insertions(+), 12 deletions(-)
diff --git a/src/tests/eina/eina_test_thread.c b/src/tests/eina/eina_test_thread.c
index 2b35907db7..c92136466f 100644
--- a/src/tests/eina/eina_test_thread.c
+++ b/src/tests/eina/eina_test_thread.c
@@ -54,13 +54,30 @@ thread_fn_skip(void *arg, Eina_Thread t EINA_UNUSED)
return NULL;
}
+typedef struct
+{
+ Eina_Lock lock;
+ Eina_Condition cond;
+ Eina_Bool waiting_to_be_cancelled;
+ Eina_Bool cancellable_set;
+} Cancel_Sync;
+
static void *
thread_fn_cancel(void *arg, Eina_Thread t EINA_UNUSED)
{
- Eina_Condition *cond = arg;
+ Cancel_Sync *sync = arg;
- ck_assert(eina_thread_cancellable_set(EINA_TRUE, NULL));
- ck_assert(eina_condition_signal(cond));
+ ck_assert(eina_lock_take(&sync->lock) == EINA_LOCK_SUCCEED);
+ sync->waiting_to_be_cancelled = EINA_TRUE;
+ ck_assert(eina_condition_signal(&sync->cond));
+ ck_assert(eina_lock_release(&sync->lock) == EINA_LOCK_SUCCEED);
+
+ /* No check assertion from here on. Even one that passes writes to the
+ * stream check reports through, and a thread cancelled in that write
+ * leaves the stream locked for good: the next assertion never returns.
+ * Threads start with cancellation disabled, and a request made before
+ * this enables it waits for the next cancellation point. */
+ sync->cancellable_set = eina_thread_cancellable_set(EINA_TRUE, NULL);
for (size_t i = 0; i < 100; ++i)
{
@@ -98,20 +115,26 @@ EFL_END_TEST
EFL_START_TEST(eina_thread_test_cancel)
{
Eina_Thread t;
- Eina_Lock mutex;
- Eina_Condition cond;
+ Cancel_Sync sync = { .waiting_to_be_cancelled = EINA_FALSE };
- ck_assert(eina_lock_new(&mutex));
- ck_assert(eina_condition_new(&cond, &mutex));
+ ck_assert(eina_lock_new(&sync.lock));
+ ck_assert(eina_condition_new(&sync.cond, &sync.lock));
+
+ /* held until the wait, so the signal cannot come before it */
+ ck_assert(eina_lock_take(&sync.lock) == EINA_LOCK_SUCCEED);
+ ck_assert(eina_thread_create(&t, EINA_THREAD_NORMAL, -1, thread_fn_cancel, &sync));
+ while (!sync.waiting_to_be_cancelled)
+ {
+ ck_assert(eina_condition_wait(&sync.cond));
+ }
+ ck_assert(eina_lock_release(&sync.lock) == EINA_LOCK_SUCCEED);
- ck_assert(eina_thread_create(&t, EINA_THREAD_NORMAL, -1, thread_fn_cancel, &cond));
- ck_assert(eina_lock_take(&mutex));
- ck_assert(eina_condition_wait(&cond));
ck_assert(eina_thread_cancel(t));
ck_assert_ptr_eq(eina_thread_join(t), EINA_THREAD_JOIN_CANCELED);
+ ck_assert(sync.cancellable_set);
- eina_condition_free(&cond);
- eina_lock_free(&mutex);
+ eina_condition_free(&sync.cond);
+ eina_lock_free(&sync.lock);
}
EFL_END_TEST
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.