From 855747eab7f78b7d9dc76a9259e0da4351f21356 Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Mon, 21 Oct 2013 14:32:06 +0200 Subject: [PATCH] unit-tests: Add a simple thread_cancel() test --- .../tests/suites/test_threading.c | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/libstrongswan/tests/suites/test_threading.c b/src/libstrongswan/tests/suites/test_threading.c index 2293af1bc0..b8c155e4db 100644 --- a/src/libstrongswan/tests/suites/test_threading.c +++ b/src/libstrongswan/tests/suites/test_threading.c @@ -17,6 +17,7 @@ #include "test_suite.h" #include +#include #include #include @@ -281,6 +282,36 @@ START_TEST(test_detach_exit) } END_TEST +static void *cancel_run(void *data) +{ + /* default cancellability should be TRUE, so don't change it */ + while (TRUE) + { + sleep(10); + } + return NULL; +} + +START_TEST(test_cancel) +{ + thread_t *threads[THREADS]; + int i; + + for (i = 0; i < THREADS; i++) + { + threads[i] = thread_create(cancel_run, NULL); + } + for (i = 0; i < THREADS; i++) + { + threads[i]->cancel(threads[i]); + } + for (i = 0; i < THREADS; i++) + { + threads[i]->join(threads[i]); + } +} +END_TEST + Suite *threading_suite_create() { Suite *s; @@ -302,5 +333,9 @@ Suite *threading_suite_create() tcase_add_test(tc, test_detach_exit); suite_add_tcase(s, tc); + tc = tcase_create("thread cancellation"); + tcase_add_test(tc, test_cancel); + suite_add_tcase(s, tc); + return s; } -- 2.47.2