unit-tests: Add a simple thread join() test
authorMartin Willi <martin@revosec.ch>
Mon, 21 Oct 2013 09:45:10 +0000 (11:45 +0200)
committerMartin Willi <martin@revosec.ch>
Wed, 6 Nov 2013 09:31:02 +0000 (10:31 +0100)
src/libstrongswan/tests/suites/test_threading.c

index c75d6de..23c2b93 100644 (file)
@@ -166,6 +166,29 @@ START_TEST(test_mutex)
 }
 END_TEST
 
+static void *join_run(void *data)
+{
+       /* force some context switches */
+       sched_yield();
+       return (void*)((uintptr_t)data + THREADS);
+}
+
+START_TEST(test_join)
+{
+       thread_t *threads[THREADS];
+       int i;
+
+       for (i = 0; i < THREADS; i++)
+       {
+               threads[i] = thread_create(join_run, (void*)(uintptr_t)i);
+       }
+       for (i = 0; i < THREADS; i++)
+       {
+               ck_assert_int_eq((uintptr_t)threads[i]->join(threads[i]), i + THREADS);
+       }
+}
+END_TEST
+
 Suite *threading_suite_create()
 {
        Suite *s;
@@ -177,5 +200,9 @@ Suite *threading_suite_create()
        tcase_add_test(tc, test_mutex);
        suite_add_tcase(s, tc);
 
+       tc = tcase_create("thread joining");
+       tcase_add_test(tc, test_join);
+       suite_add_tcase(s, tc);
+
        return s;
 }