unit-tests: Add a test for thread_cancellation_point()
authorMartin Willi <martin@revosec.ch>
Mon, 21 Oct 2013 13:08:14 +0000 (15:08 +0200)
committerMartin Willi <martin@revosec.ch>
Wed, 6 Nov 2013 09:31:03 +0000 (10:31 +0100)
src/libstrongswan/tests/suites/test_threading.c

index bf43d88..fffad0c 100644 (file)
@@ -361,6 +361,38 @@ START_TEST(test_cancel_onoff)
 }
 END_TEST
 
+static void *cancel_point_run(void *data)
+{
+       thread_cancelability(FALSE);
+       while (TRUE)
+       {
+               /* implicitly enables cancellability */
+               thread_cancellation_point();
+       }
+       return NULL;
+}
+
+START_TEST(test_cancel_point)
+{
+       thread_t *threads[THREADS];
+       int i;
+
+       for (i = 0; i < THREADS; i++)
+       {
+               threads[i] = thread_create(cancel_point_run, NULL);
+       }
+       sched_yield();
+       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;
@@ -385,6 +417,7 @@ Suite *threading_suite_create()
        tc = tcase_create("thread cancellation");
        tcase_add_test(tc, test_cancel);
        tcase_add_test(tc, test_cancel_onoff);
+       tcase_add_test(tc, test_cancel_point);
        suite_add_tcase(s, tc);
 
        return s;