[AA] Rename CaptureInfo -> CaptureAnalysis (NFC) (#116842)
[llvm-project.git] / compiler-rt / test / msan / pthread_getname_np.cpp
blob753a90529e451319eb06a6826cee8705a8c94977
1 // RUN: %clangxx_msan -std=c++11 -O0 %s -o %t && %run %t
2 // The main goal is getting the pthread name back and
3 // FreeBSD based do not support this feature
4 // UNSUPPORTED: android, target={{.*freebsd.*}}
6 // Regression test for a deadlock in pthread_getattr_np
8 #include <assert.h>
9 #include <pthread.h>
10 #include <string.h>
11 #include <sanitizer/msan_interface.h>
13 #include <stdio.h>
15 // Stall child thread on this lock to make sure it doesn't finish
16 // before the end of the pthread_getname_np() / pthread_setname_np() tests.
17 static pthread_mutex_t lock;
19 void *ThreadFn(void *) {
20 pthread_mutex_lock (&lock);
21 pthread_mutex_unlock (&lock);
22 return nullptr;
25 int main(void) {
26 pthread_t t;
28 pthread_mutex_init (&lock, NULL);
29 pthread_mutex_lock (&lock);
31 int res = pthread_create(&t, 0, ThreadFn, 0);
32 assert(!res);
34 const char *kMyThreadName = "my-thread-name";
35 #if defined(__NetBSD__)
36 res = pthread_setname_np(t, "%s", (void *)kMyThreadName);
37 #else
38 res = pthread_setname_np(t, kMyThreadName);
39 #endif
40 assert(!res);
42 char buf[100];
43 res = pthread_getname_np(t, buf, sizeof(buf));
44 assert(!res);
45 assert(strcmp(buf, kMyThreadName) == 0);
47 pthread_mutex_unlock (&lock);
49 res = pthread_join(t, 0);
50 assert(!res);
51 return 0;