unit-tests: Add a thread cleanup pop test
authorMartin Willi <martin@revosec.ch>
Mon, 21 Oct 2013 14:12:52 +0000 (16:12 +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 2db9672..3282fb9 100644 (file)
@@ -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;