1 // RUN: %clangxx -O0 %s -o %t && %run %t
2 
3 // Android does not implement pthread_getaffinity_np.
4 // (Note: libresolv is integrated with libc, but apparently only
5 // sched_getaffinity).
6 // UNSUPPORTED: android
7 
8 #ifndef _GNU_SOURCE
9 #  define _GNU_SOURCE
10 #endif
11 
12 #include <assert.h>
13 #include <pthread.h>
14 #include <stdio.h>
15 #include <sys/sysinfo.h>
16 
17 #include <sanitizer/msan_interface.h>
18 
19 int main() {
20   cpu_set_t set_x;
21   pthread_t tid = pthread_self();
22   int res = pthread_getaffinity_np(tid, sizeof(set_x), &set_x);
23   if (res != 0) {
24     fprintf(stderr, "tid: %lu\n", tid);
25     fprintf(stderr, "sizeof(set_x): %d\n", sizeof(set_x));
26     fprintf(stderr, "res: %d\n", res);
27   }
28   assert(res == 0);
29   assert(CPU_COUNT_S(sizeof(set_x), &set_x) == get_nprocs());
30 
31   return 0;
32 }
33