]> git.saurik.com Git - apple/libpthread.git/blobdiff - tests/pthread_cancel.c
libpthread-218.1.3.tar.gz
[apple/libpthread.git] / tests / pthread_cancel.c
diff --git a/tests/pthread_cancel.c b/tests/pthread_cancel.c
new file mode 100644 (file)
index 0000000..20b8f88
--- /dev/null
@@ -0,0 +1,23 @@
+#include <pthread.h>
+
+#include <darwintest.h>
+
+static void *
+run(void * __unused arg)
+{
+       while (true) {
+               pthread_testcancel();
+               sched_yield();
+       }
+}
+
+T_DECL(pthread_cancel, "pthread_cancel",
+               T_META_ALL_VALID_ARCHS(YES))
+{
+       pthread_t thread;
+       void *join_result = NULL;
+       T_ASSERT_POSIX_ZERO(pthread_create(&thread, NULL, run, NULL), NULL);
+       T_ASSERT_POSIX_ZERO(pthread_cancel(thread), NULL);
+       T_ASSERT_POSIX_ZERO(pthread_join(thread, &join_result), NULL);
+       T_ASSERT_EQ(join_result, PTHREAD_CANCELED, NULL);
+}