From: Martin Willi Date: Wed, 23 Oct 2013 13:44:22 +0000 (+0200) Subject: unit-tests: Add a semaphore wait cancel test X-Git-Tag: 5.1.2dr1~33^2~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a4cbda35cec0a3fb836dbff6656152fa3f656f35;p=thirdparty%2Fstrongswan.git unit-tests: Add a semaphore wait cancel test --- diff --git a/src/libstrongswan/tests/suites/test_threading.c b/src/libstrongswan/tests/suites/test_threading.c index 5938bd9598..844959e46d 100644 --- a/src/libstrongswan/tests/suites/test_threading.c +++ b/src/libstrongswan/tests/suites/test_threading.c @@ -862,6 +862,49 @@ START_TEST(test_semaphore_timed_abs) } END_TEST +static void *semaphore_cancel_run(void *data) +{ + refcount_t *ready = (refcount_t*)data; + + thread_cancelability(FALSE); + ref_get(ready); + + thread_cancelability(TRUE); + semaphore->wait(semaphore); + + ck_assert(FALSE); + return NULL; +} + +START_TEST(test_semaphore_cancel) +{ + thread_t *threads[THREADS]; + refcount_t ready = 0; + int i; + + semaphore = semaphore_create(0); + + for (i = 0; i < THREADS; i++) + { + threads[i] = thread_create(semaphore_cancel_run, &ready); + } + while (ready < THREADS) + { + sched_yield(); + } + for (i = 0; i < THREADS; i++) + { + threads[i]->cancel(threads[i]); + } + for (i = 0; i < THREADS; i++) + { + threads[i]->join(threads[i]); + } + + semaphore->destroy(semaphore); +} +END_TEST + static void *join_run(void *data) { /* force some context switches */ @@ -1388,6 +1431,7 @@ Suite *threading_suite_create() tcase_add_test(tc, test_semaphore); tcase_add_test(tc, test_semaphore_timed); tcase_add_test(tc, test_semaphore_timed_abs); + tcase_add_test(tc, test_semaphore_cancel); suite_add_tcase(s, tc); tc = tcase_create("thread joining");