From fd26b7ff1b412378b41f7f1a90d1816b5a45d439 Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Mon, 21 Oct 2013 16:12:52 +0200 Subject: [PATCH] unit-tests: Add a thread cleanup pop test --- .../tests/suites/test_threading.c | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/libstrongswan/tests/suites/test_threading.c b/src/libstrongswan/tests/suites/test_threading.c index 2db967244e..3282fb975b 100644 --- a/src/libstrongswan/tests/suites/test_threading.c +++ b/src/libstrongswan/tests/suites/test_threading.c @@ -513,6 +513,38 @@ START_TEST(test_cleanup_cancel) } END_TEST +static void *cleanup_pop_run(void *data) +{ + thread_cleanup_push(cleanup3, data); + thread_cleanup_push(cleanup2, data); + thread_cleanup_push(cleanup1, data); + + thread_cleanup_push(cleanup2, data); + thread_cleanup_pop(FALSE); + + thread_cleanup_pop(TRUE); + return NULL; +} + +START_TEST(test_cleanup_pop) +{ + thread_t *threads[THREADS]; + uintptr_t values[THREADS]; + int i; + + for (i = 0; i < THREADS; i++) + { + values[i] = 1; + threads[i] = thread_create(cleanup_pop_run, &values[i]); + } + for (i = 0; i < THREADS; i++) + { + threads[i]->join(threads[i]); + ck_assert_int_eq(values[i], 4); + } +} +END_TEST + Suite *threading_suite_create() { Suite *s; @@ -544,6 +576,7 @@ Suite *threading_suite_create() tcase_add_test(tc, test_cleanup); tcase_add_test(tc, test_cleanup_exit); tcase_add_test(tc, test_cleanup_cancel); + tcase_add_test(tc, test_cleanup_pop); suite_add_tcase(s, tc); return s; -- 2.47.2