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