]>
git.saurik.com Git - apple/libpthread.git/blob - tests/pthread_threadid_np.c
46eb527136fb58bd305982be4d5ed5cff71a610c
2 #include <pthread/private.h>
3 #include <dispatch/dispatch.h>
7 #include "darwintest_defaults.h"
9 extern __uint64_t
__thread_selfid( void );
11 static void *do_test(void * __unused arg
)
13 uint64_t threadid
= __thread_selfid();
14 T_ASSERT_NE(threadid
, (uint64_t)0, "__thread_selfid()");
16 uint64_t pth_threadid
= 0;
17 T_ASSERT_POSIX_ZERO(pthread_threadid_np(NULL
, &pth_threadid
), NULL
);
18 T_ASSERT_POSIX_ZERO(pthread_threadid_np(pthread_self(), &pth_threadid
), NULL
);
19 T_EXPECT_EQ(threadid
, pth_threadid
, "pthread_threadid_np()");
21 pth_threadid
= _pthread_threadid_self_np_direct();
22 T_EXPECT_EQ(threadid
, pth_threadid
, "pthread_threadid_np_direct()");
27 T_DECL(pthread_threadid_np
, "pthread_threadid_np",
28 T_META_ALL_VALID_ARCHS(YES
))
35 T_ASSERT_POSIX_ZERO(pthread_create(&pth
, NULL
, do_test
, NULL
), NULL
);
36 T_ASSERT_POSIX_ZERO(pthread_join(pth
, NULL
), NULL
);
38 T_LOG("Workqueue Thread");
39 dispatch_queue_t dq
= dispatch_queue_create("myqueue", NULL
);
40 dispatch_async(dq
, ^{ do_test(NULL
); });
41 dispatch_sync(dq
, ^{});
43 T_LOG("Workqueue Thread Reuse");
44 dispatch_async(dq
, ^{ do_test(NULL
); });
45 dispatch_sync(dq
, ^{});
48 T_DECL(pthread_threadid_fork
, "pthread_threadid_np post-fork test")
50 uint64_t tid
= __thread_selfid();
51 T_ASSERT_NE(tid
, (uint64_t)0, "__thread_selfid()");
54 T_ASSERT_POSIX_ZERO(pthread_threadid_np(NULL
, &ptid
), NULL
);
55 T_ASSERT_EQ(ptid
, tid
, NULL
);
60 uint64_t ntid
= __thread_selfid();
62 T_LOG("FAIL: forked child tid is equal to parent tid");
67 if (pthread_threadid_np(NULL
, &nptid
) != 0) {
68 T_LOG("FAIL: pthread_threadid_np: %d", errno
);
73 T_LOG("FAIL: pthread_threadid_np == tid (expected: %lld == %lld)",
80 T_ASSERT_EQ(waitpid(pid
, &status
, 0), pid
, NULL
);
81 int exitstatus
= WEXITSTATUS(status
);
82 T_ASSERT_EQ(exitstatus
, 0, NULL
);