pthread_test.cpp revision 718a5b5495ae7726aabd2f8a748da9f391d12b98
1/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <gtest/gtest.h>
18
19#include <errno.h>
20#include <inttypes.h>
21#include <limits.h>
22#include <pthread.h>
23#include <sys/mman.h>
24#include <unistd.h>
25
26TEST(pthread, pthread_key_create) {
27  pthread_key_t key;
28  ASSERT_EQ(0, pthread_key_create(&key, NULL));
29  ASSERT_EQ(0, pthread_key_delete(key));
30  // Can't delete a key that's already been deleted.
31  ASSERT_EQ(EINVAL, pthread_key_delete(key));
32}
33
34#if !defined(__GLIBC__) // glibc uses keys internally that its sysconf value doesn't account for.
35TEST(pthread, pthread_key_create_lots) {
36  // POSIX says PTHREAD_KEYS_MAX should be at least 128.
37  ASSERT_GE(PTHREAD_KEYS_MAX, 128);
38
39  int sysconf_max = sysconf(_SC_THREAD_KEYS_MAX);
40
41  // sysconf shouldn't return a smaller value.
42  ASSERT_GE(sysconf_max, PTHREAD_KEYS_MAX);
43
44  // We can allocate _SC_THREAD_KEYS_MAX keys.
45  sysconf_max -= 2; // (Except that gtest takes two for itself.)
46  std::vector<pthread_key_t> keys;
47  for (int i = 0; i < sysconf_max; ++i) {
48    pthread_key_t key;
49    // If this fails, it's likely that GLOBAL_INIT_THREAD_LOCAL_BUFFER_COUNT is wrong.
50    ASSERT_EQ(0, pthread_key_create(&key, NULL)) << i << " of " << sysconf_max;
51    keys.push_back(key);
52  }
53
54  // ...and that really is the maximum.
55  pthread_key_t key;
56  ASSERT_EQ(EAGAIN, pthread_key_create(&key, NULL));
57
58  // (Don't leak all those keys!)
59  for (size_t i = 0; i < keys.size(); ++i) {
60    ASSERT_EQ(0, pthread_key_delete(keys[i]));
61  }
62}
63#endif
64
65static void* IdFn(void* arg) {
66  return arg;
67}
68
69static void* SleepFn(void* arg) {
70  sleep(reinterpret_cast<uintptr_t>(arg));
71  return NULL;
72}
73
74static void* SpinFn(void* arg) {
75  volatile bool* b = reinterpret_cast<volatile bool*>(arg);
76  while (!*b) {
77  }
78  return NULL;
79}
80
81static void* JoinFn(void* arg) {
82  return reinterpret_cast<void*>(pthread_join(reinterpret_cast<pthread_t>(arg), NULL));
83}
84
85static void AssertDetached(pthread_t t, bool is_detached) {
86  pthread_attr_t attr;
87  ASSERT_EQ(0, pthread_getattr_np(t, &attr));
88  int detach_state;
89  ASSERT_EQ(0, pthread_attr_getdetachstate(&attr, &detach_state));
90  pthread_attr_destroy(&attr);
91  ASSERT_EQ(is_detached, (detach_state == PTHREAD_CREATE_DETACHED));
92}
93
94static void MakeDeadThread(pthread_t& t) {
95  ASSERT_EQ(0, pthread_create(&t, NULL, IdFn, NULL));
96  void* result;
97  ASSERT_EQ(0, pthread_join(t, &result));
98}
99
100TEST(pthread, pthread_create) {
101  void* expected_result = reinterpret_cast<void*>(123);
102  // Can we create a thread?
103  pthread_t t;
104  ASSERT_EQ(0, pthread_create(&t, NULL, IdFn, expected_result));
105  // If we join, do we get the expected value back?
106  void* result;
107  ASSERT_EQ(0, pthread_join(t, &result));
108  ASSERT_EQ(expected_result, result);
109}
110
111TEST(pthread, pthread_create_EAGAIN) {
112  pthread_attr_t attributes;
113  ASSERT_EQ(0, pthread_attr_init(&attributes));
114  ASSERT_EQ(0, pthread_attr_setstacksize(&attributes, static_cast<size_t>(-1) & ~(getpagesize() - 1)));
115
116  pthread_t t;
117  ASSERT_EQ(EAGAIN, pthread_create(&t, &attributes, IdFn, NULL));
118}
119
120TEST(pthread, pthread_no_join_after_detach) {
121  pthread_t t1;
122  ASSERT_EQ(0, pthread_create(&t1, NULL, SleepFn, reinterpret_cast<void*>(5)));
123
124  // After a pthread_detach...
125  ASSERT_EQ(0, pthread_detach(t1));
126  AssertDetached(t1, true);
127
128  // ...pthread_join should fail.
129  void* result;
130  ASSERT_EQ(EINVAL, pthread_join(t1, &result));
131}
132
133TEST(pthread, pthread_no_op_detach_after_join) {
134  bool done = false;
135
136  pthread_t t1;
137  ASSERT_EQ(0, pthread_create(&t1, NULL, SpinFn, &done));
138
139  // If thread 2 is already waiting to join thread 1...
140  pthread_t t2;
141  ASSERT_EQ(0, pthread_create(&t2, NULL, JoinFn, reinterpret_cast<void*>(t1)));
142
143  sleep(1); // (Give t2 a chance to call pthread_join.)
144
145  // ...a call to pthread_detach on thread 1 will "succeed" (silently fail)...
146  ASSERT_EQ(0, pthread_detach(t1));
147  AssertDetached(t1, false);
148
149  done = true;
150
151  // ...but t2's join on t1 still goes ahead (which we can tell because our join on t2 finishes).
152  void* join_result;
153  ASSERT_EQ(0, pthread_join(t2, &join_result));
154  ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(join_result));
155}
156
157TEST(pthread, pthread_join_self) {
158  void* result;
159  ASSERT_EQ(EDEADLK, pthread_join(pthread_self(), &result));
160}
161
162struct TestBug37410 {
163  pthread_t main_thread;
164  pthread_mutex_t mutex;
165
166  static void main() {
167    TestBug37410 data;
168    data.main_thread = pthread_self();
169    ASSERT_EQ(0, pthread_mutex_init(&data.mutex, NULL));
170    ASSERT_EQ(0, pthread_mutex_lock(&data.mutex));
171
172    pthread_t t;
173    ASSERT_EQ(0, pthread_create(&t, NULL, TestBug37410::thread_fn, reinterpret_cast<void*>(&data)));
174
175    // Wait for the thread to be running...
176    ASSERT_EQ(0, pthread_mutex_lock(&data.mutex));
177    ASSERT_EQ(0, pthread_mutex_unlock(&data.mutex));
178
179    // ...and exit.
180    pthread_exit(NULL);
181  }
182
183 private:
184  static void* thread_fn(void* arg) {
185    TestBug37410* data = reinterpret_cast<TestBug37410*>(arg);
186
187    // Let the main thread know we're running.
188    pthread_mutex_unlock(&data->mutex);
189
190    // And wait for the main thread to exit.
191    pthread_join(data->main_thread, NULL);
192
193    return NULL;
194  }
195};
196
197// Even though this isn't really a death test, we have to say "DeathTest" here so gtest knows to
198// run this test (which exits normally) in its own process.
199TEST(pthread_DeathTest, pthread_bug_37410) {
200  // http://code.google.com/p/android/issues/detail?id=37410
201  ::testing::FLAGS_gtest_death_test_style = "threadsafe";
202  ASSERT_EXIT(TestBug37410::main(), ::testing::ExitedWithCode(0), "");
203}
204
205static void* SignalHandlerFn(void* arg) {
206  sigset_t wait_set;
207  sigfillset(&wait_set);
208  return reinterpret_cast<void*>(sigwait(&wait_set, reinterpret_cast<int*>(arg)));
209}
210
211TEST(pthread, pthread_sigmask) {
212  // Check that SIGUSR1 isn't blocked.
213  sigset_t original_set;
214  sigemptyset(&original_set);
215  ASSERT_EQ(0, pthread_sigmask(SIG_BLOCK, NULL, &original_set));
216  ASSERT_FALSE(sigismember(&original_set, SIGUSR1));
217
218  // Block SIGUSR1.
219  sigset_t set;
220  sigemptyset(&set);
221  sigaddset(&set, SIGUSR1);
222  ASSERT_EQ(0, pthread_sigmask(SIG_BLOCK, &set, NULL));
223
224  // Check that SIGUSR1 is blocked.
225  sigset_t final_set;
226  sigemptyset(&final_set);
227  ASSERT_EQ(0, pthread_sigmask(SIG_BLOCK, NULL, &final_set));
228  ASSERT_TRUE(sigismember(&final_set, SIGUSR1));
229  // ...and that sigprocmask agrees with pthread_sigmask.
230  sigemptyset(&final_set);
231  ASSERT_EQ(0, sigprocmask(SIG_BLOCK, NULL, &final_set));
232  ASSERT_TRUE(sigismember(&final_set, SIGUSR1));
233
234  // Spawn a thread that calls sigwait and tells us what it received.
235  pthread_t signal_thread;
236  int received_signal = -1;
237  ASSERT_EQ(0, pthread_create(&signal_thread, NULL, SignalHandlerFn, &received_signal));
238
239  // Send that thread SIGUSR1.
240  pthread_kill(signal_thread, SIGUSR1);
241
242  // See what it got.
243  void* join_result;
244  ASSERT_EQ(0, pthread_join(signal_thread, &join_result));
245  ASSERT_EQ(SIGUSR1, received_signal);
246  ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(join_result));
247
248  // Restore the original signal mask.
249  ASSERT_EQ(0, pthread_sigmask(SIG_SETMASK, &original_set, NULL));
250}
251
252#if __BIONIC__
253extern "C" pid_t __bionic_clone(int flags, void* child_stack, pid_t* parent_tid, void* tls, pid_t* child_tid, int (*fn)(void*), void* arg);
254TEST(pthread, __bionic_clone) {
255  // Check that our hand-written clone assembler sets errno correctly on failure.
256  uintptr_t fake_child_stack[16];
257  errno = 0;
258  ASSERT_EQ(-1, __bionic_clone(CLONE_THREAD, &fake_child_stack[16], NULL, NULL, NULL, NULL, NULL));
259  ASSERT_EQ(EINVAL, errno);
260}
261#endif
262
263#if __BIONIC__ // Not all build servers have a new enough glibc? TODO: remove when they're on gprecise.
264TEST(pthread, pthread_setname_np__too_long) {
265  ASSERT_EQ(ERANGE, pthread_setname_np(pthread_self(), "this name is far too long for linux"));
266}
267#endif
268
269#if __BIONIC__ // Not all build servers have a new enough glibc? TODO: remove when they're on gprecise.
270TEST(pthread, pthread_setname_np__self) {
271  ASSERT_EQ(0, pthread_setname_np(pthread_self(), "short 1"));
272}
273#endif
274
275#if __BIONIC__ // Not all build servers have a new enough glibc? TODO: remove when they're on gprecise.
276TEST(pthread, pthread_setname_np__other) {
277  // Emulator kernels don't currently support setting the name of other threads.
278  char* filename = NULL;
279  asprintf(&filename, "/proc/self/task/%d/comm", gettid());
280  struct stat sb;
281  bool has_comm = (stat(filename, &sb) != -1);
282  free(filename);
283
284  if (has_comm) {
285    pthread_t t1;
286    ASSERT_EQ(0, pthread_create(&t1, NULL, SleepFn, reinterpret_cast<void*>(5)));
287    ASSERT_EQ(0, pthread_setname_np(t1, "short 2"));
288  } else {
289    fprintf(stderr, "skipping test: this kernel doesn't have /proc/self/task/tid/comm files!\n");
290  }
291}
292#endif
293
294#if __BIONIC__ // Not all build servers have a new enough glibc? TODO: remove when they're on gprecise.
295TEST(pthread, pthread_setname_np__no_such_thread) {
296  pthread_t dead_thread;
297  MakeDeadThread(dead_thread);
298
299  // Call pthread_setname_np after thread has already exited.
300  ASSERT_EQ(ESRCH, pthread_setname_np(dead_thread, "short 3"));
301}
302#endif
303
304TEST(pthread, pthread_kill__0) {
305  // Signal 0 just tests that the thread exists, so it's safe to call on ourselves.
306  ASSERT_EQ(0, pthread_kill(pthread_self(), 0));
307}
308
309TEST(pthread, pthread_kill__invalid_signal) {
310  ASSERT_EQ(EINVAL, pthread_kill(pthread_self(), -1));
311}
312
313static void pthread_kill__in_signal_handler_helper(int signal_number) {
314  static int count = 0;
315  ASSERT_EQ(SIGALRM, signal_number);
316  if (++count == 1) {
317    // Can we call pthread_kill from a signal handler?
318    ASSERT_EQ(0, pthread_kill(pthread_self(), SIGALRM));
319  }
320}
321
322TEST(pthread, pthread_kill__in_signal_handler) {
323  struct sigaction action;
324  struct sigaction original_action;
325  sigemptyset(&action.sa_mask);
326  action.sa_flags = 0;
327  action.sa_handler = pthread_kill__in_signal_handler_helper;
328  ASSERT_EQ(0, sigaction(SIGALRM, &action, &original_action));
329  ASSERT_EQ(0, pthread_kill(pthread_self(), SIGALRM));
330  ASSERT_EQ(0, sigaction(SIGALRM, &original_action, NULL));
331}
332
333TEST(pthread, pthread_detach__no_such_thread) {
334  pthread_t dead_thread;
335  MakeDeadThread(dead_thread);
336
337  ASSERT_EQ(ESRCH, pthread_detach(dead_thread));
338}
339
340TEST(pthread, pthread_getcpuclockid__clock_gettime) {
341  pthread_t t;
342  ASSERT_EQ(0, pthread_create(&t, NULL, SleepFn, reinterpret_cast<void*>(5)));
343
344  clockid_t c;
345  ASSERT_EQ(0, pthread_getcpuclockid(t, &c));
346  timespec ts;
347  ASSERT_EQ(0, clock_gettime(c, &ts));
348}
349
350TEST(pthread, pthread_getcpuclockid__no_such_thread) {
351  pthread_t dead_thread;
352  MakeDeadThread(dead_thread);
353
354  clockid_t c;
355  ASSERT_EQ(ESRCH, pthread_getcpuclockid(dead_thread, &c));
356}
357
358TEST(pthread, pthread_getschedparam__no_such_thread) {
359  pthread_t dead_thread;
360  MakeDeadThread(dead_thread);
361
362  int policy;
363  sched_param param;
364  ASSERT_EQ(ESRCH, pthread_getschedparam(dead_thread, &policy, &param));
365}
366
367TEST(pthread, pthread_setschedparam__no_such_thread) {
368  pthread_t dead_thread;
369  MakeDeadThread(dead_thread);
370
371  int policy = 0;
372  sched_param param;
373  ASSERT_EQ(ESRCH, pthread_setschedparam(dead_thread, policy, &param));
374}
375
376TEST(pthread, pthread_join__no_such_thread) {
377  pthread_t dead_thread;
378  MakeDeadThread(dead_thread);
379
380  void* result;
381  ASSERT_EQ(ESRCH, pthread_join(dead_thread, &result));
382}
383
384TEST(pthread, pthread_kill__no_such_thread) {
385  pthread_t dead_thread;
386  MakeDeadThread(dead_thread);
387
388  ASSERT_EQ(ESRCH, pthread_kill(dead_thread, 0));
389}
390
391TEST(pthread, pthread_join__multijoin) {
392  bool done = false;
393
394  pthread_t t1;
395  ASSERT_EQ(0, pthread_create(&t1, NULL, SpinFn, &done));
396
397  pthread_t t2;
398  ASSERT_EQ(0, pthread_create(&t2, NULL, JoinFn, reinterpret_cast<void*>(t1)));
399
400  sleep(1); // (Give t2 a chance to call pthread_join.)
401
402  // Multiple joins to the same thread should fail.
403  ASSERT_EQ(EINVAL, pthread_join(t1, NULL));
404
405  done = true;
406
407  // ...but t2's join on t1 still goes ahead (which we can tell because our join on t2 finishes).
408  void* join_result;
409  ASSERT_EQ(0, pthread_join(t2, &join_result));
410  ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(join_result));
411}
412
413TEST(pthread, pthread_join__race) {
414  // http://b/11693195 --- pthread_join could return before the thread had actually exited.
415  // If the joiner unmapped the thread's stack, that could lead to SIGSEGV in the thread.
416  for (size_t i = 0; i < 1024; ++i) {
417    size_t stack_size = 64*1024;
418    void* stack = mmap(NULL, stack_size, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0);
419
420    pthread_attr_t a;
421    pthread_attr_init(&a);
422    pthread_attr_setstack(&a, stack, stack_size);
423
424    pthread_t t;
425    ASSERT_EQ(0, pthread_create(&t, &a, IdFn, NULL));
426    ASSERT_EQ(0, pthread_join(t, NULL));
427    ASSERT_EQ(0, munmap(stack, stack_size));
428  }
429}
430
431static void* GetActualGuardSizeFn(void* arg) {
432  pthread_attr_t attributes;
433  pthread_getattr_np(pthread_self(), &attributes);
434  pthread_attr_getguardsize(&attributes, reinterpret_cast<size_t*>(arg));
435  return NULL;
436}
437
438static size_t GetActualGuardSize(const pthread_attr_t& attributes) {
439  size_t result;
440  pthread_t t;
441  pthread_create(&t, &attributes, GetActualGuardSizeFn, &result);
442  void* join_result;
443  pthread_join(t, &join_result);
444  return result;
445}
446
447static void* GetActualStackSizeFn(void* arg) {
448  pthread_attr_t attributes;
449  pthread_getattr_np(pthread_self(), &attributes);
450  pthread_attr_getstacksize(&attributes, reinterpret_cast<size_t*>(arg));
451  return NULL;
452}
453
454static size_t GetActualStackSize(const pthread_attr_t& attributes) {
455  size_t result;
456  pthread_t t;
457  pthread_create(&t, &attributes, GetActualStackSizeFn, &result);
458  void* join_result;
459  pthread_join(t, &join_result);
460  return result;
461}
462
463TEST(pthread, pthread_attr_setguardsize) {
464  pthread_attr_t attributes;
465  ASSERT_EQ(0, pthread_attr_init(&attributes));
466
467  // Get the default guard size.
468  size_t default_guard_size;
469  ASSERT_EQ(0, pthread_attr_getguardsize(&attributes, &default_guard_size));
470
471  // No such thing as too small: will be rounded up to one page by pthread_create.
472  ASSERT_EQ(0, pthread_attr_setguardsize(&attributes, 128));
473  size_t guard_size;
474  ASSERT_EQ(0, pthread_attr_getguardsize(&attributes, &guard_size));
475  ASSERT_EQ(128U, guard_size);
476  ASSERT_EQ(4096U, GetActualGuardSize(attributes));
477
478  // Large enough and a multiple of the page size.
479  ASSERT_EQ(0, pthread_attr_setguardsize(&attributes, 32*1024));
480  ASSERT_EQ(0, pthread_attr_getguardsize(&attributes, &guard_size));
481  ASSERT_EQ(32*1024U, guard_size);
482
483  // Large enough but not a multiple of the page size; will be rounded up by pthread_create.
484  ASSERT_EQ(0, pthread_attr_setguardsize(&attributes, 32*1024 + 1));
485  ASSERT_EQ(0, pthread_attr_getguardsize(&attributes, &guard_size));
486  ASSERT_EQ(32*1024U + 1, guard_size);
487}
488
489TEST(pthread, pthread_attr_setstacksize) {
490  pthread_attr_t attributes;
491  ASSERT_EQ(0, pthread_attr_init(&attributes));
492
493  // Get the default stack size.
494  size_t default_stack_size;
495  ASSERT_EQ(0, pthread_attr_getstacksize(&attributes, &default_stack_size));
496
497  // Too small.
498  ASSERT_EQ(EINVAL, pthread_attr_setstacksize(&attributes, 128));
499  size_t stack_size;
500  ASSERT_EQ(0, pthread_attr_getstacksize(&attributes, &stack_size));
501  ASSERT_EQ(default_stack_size, stack_size);
502  ASSERT_GE(GetActualStackSize(attributes), default_stack_size);
503
504  // Large enough and a multiple of the page size.
505  ASSERT_EQ(0, pthread_attr_setstacksize(&attributes, 32*1024));
506  ASSERT_EQ(0, pthread_attr_getstacksize(&attributes, &stack_size));
507  ASSERT_EQ(32*1024U, stack_size);
508  ASSERT_EQ(GetActualStackSize(attributes), 32*1024U);
509
510  // Large enough but not a multiple of the page size; will be rounded up by pthread_create.
511  ASSERT_EQ(0, pthread_attr_setstacksize(&attributes, 32*1024 + 1));
512  ASSERT_EQ(0, pthread_attr_getstacksize(&attributes, &stack_size));
513  ASSERT_EQ(32*1024U + 1, stack_size);
514#if __BIONIC__
515  // Bionic rounds up, which is what POSIX allows.
516  ASSERT_EQ(GetActualStackSize(attributes), (32 + 4)*1024U);
517#else
518  // glibc rounds down, in violation of POSIX. They document this in their BUGS section.
519  ASSERT_EQ(GetActualStackSize(attributes), 32*1024U);
520#endif
521}
522
523TEST(pthread, pthread_rwlock_smoke) {
524  pthread_rwlock_t l;
525  ASSERT_EQ(0, pthread_rwlock_init(&l, NULL));
526
527  ASSERT_EQ(0, pthread_rwlock_rdlock(&l));
528  ASSERT_EQ(0, pthread_rwlock_unlock(&l));
529
530  ASSERT_EQ(0, pthread_rwlock_wrlock(&l));
531  ASSERT_EQ(0, pthread_rwlock_unlock(&l));
532
533  ASSERT_EQ(0, pthread_rwlock_destroy(&l));
534}
535
536static int gOnceFnCallCount = 0;
537static void OnceFn() {
538  ++gOnceFnCallCount;
539}
540
541TEST(pthread, pthread_once_smoke) {
542  pthread_once_t once_control = PTHREAD_ONCE_INIT;
543  ASSERT_EQ(0, pthread_once(&once_control, OnceFn));
544  ASSERT_EQ(0, pthread_once(&once_control, OnceFn));
545  ASSERT_EQ(1, gOnceFnCallCount);
546}
547
548static int gAtForkPrepareCalls = 0;
549static void AtForkPrepare1() { gAtForkPrepareCalls = (gAtForkPrepareCalls << 4) | 1; }
550static void AtForkPrepare2() { gAtForkPrepareCalls = (gAtForkPrepareCalls << 4) | 2; }
551static int gAtForkParentCalls = 0;
552static void AtForkParent1() { gAtForkParentCalls = (gAtForkParentCalls << 4) | 1; }
553static void AtForkParent2() { gAtForkParentCalls = (gAtForkParentCalls << 4) | 2; }
554static int gAtForkChildCalls = 0;
555static void AtForkChild1() { gAtForkChildCalls = (gAtForkChildCalls << 4) | 1; }
556static void AtForkChild2() { gAtForkChildCalls = (gAtForkChildCalls << 4) | 2; }
557
558TEST(pthread, pthread_atfork) {
559  ASSERT_EQ(0, pthread_atfork(AtForkPrepare1, AtForkParent1, AtForkChild1));
560  ASSERT_EQ(0, pthread_atfork(AtForkPrepare2, AtForkParent2, AtForkChild2));
561
562  int pid = fork();
563  ASSERT_NE(-1, pid) << strerror(errno);
564
565  // Child and parent calls are made in the order they were registered.
566  if (pid == 0) {
567    ASSERT_EQ(0x12, gAtForkChildCalls);
568    _exit(0);
569  }
570  ASSERT_EQ(0x12, gAtForkParentCalls);
571
572  // Prepare calls are made in the reverse order.
573  ASSERT_EQ(0x21, gAtForkPrepareCalls);
574}
575
576TEST(pthread, pthread_attr_getscope) {
577  pthread_attr_t attr;
578  ASSERT_EQ(0, pthread_attr_init(&attr));
579
580  int scope;
581  ASSERT_EQ(0, pthread_attr_getscope(&attr, &scope));
582  ASSERT_EQ(PTHREAD_SCOPE_SYSTEM, scope);
583}
584