From: Martin Willi Date: Mon, 21 Oct 2013 12:10:38 +0000 (+0200) Subject: unit-tests: Add a simple thread detach test X-Git-Tag: 5.1.2dr1~33^2~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=274e6beb0028041cd70c008261b05b0a5b773dc3;p=thirdparty%2Fstrongswan.git unit-tests: Add a simple thread detach test --- diff --git a/src/libstrongswan/tests/suites/test_threading.c b/src/libstrongswan/tests/suites/test_threading.c index 23c2b93119..e04ec565dd 100644 --- a/src/libstrongswan/tests/suites/test_threading.c +++ b/src/libstrongswan/tests/suites/test_threading.c @@ -189,6 +189,38 @@ START_TEST(test_join) } END_TEST +static void *detach_run(void *data) +{ + refcount_t *running = (refcount_t*)data; + + ignore_result(ref_put(running)); + return NULL; +} + +START_TEST(test_detach) +{ + thread_t *threads[THREADS]; + int i; + refcount_t running = 0; + + for (i = 0; i < THREADS; i++) + { + ref_get(&running); + threads[i] = thread_create(detach_run, &running); + } + for (i = 0; i < THREADS; i++) + { + threads[i]->detach(threads[i]); + } + while (running > 0) + { + sched_yield(); + } + /* no checks done here, but we check that thread state gets cleaned + * up with leak detective. */ +} +END_TEST + Suite *threading_suite_create() { Suite *s; @@ -204,5 +236,9 @@ Suite *threading_suite_create() tcase_add_test(tc, test_join); suite_add_tcase(s, tc); + tc = tcase_create("thread detaching"); + tcase_add_test(tc, test_detach); + suite_add_tcase(s, tc); + return s; }