| 485 | } |
| 486 | |
| 487 | void* check_sleep(void* pthread_task) { |
| 488 | EXPECT_TRUE(bthread_self() != 0); |
| 489 | // Create a no-signal task that other worker will not steal. The task will be |
| 490 | // run if current bthread does context switch. |
| 491 | bthread_attr_t attr = BTHREAD_ATTR_NORMAL | BTHREAD_NOSIGNAL; |
| 492 | bthread_t th1; |
| 493 | pthread_t run = 0; |
| 494 | const pthread_t pid = pthread_self(); |
| 495 | EXPECT_EQ(0, bthread_start_urgent(&th1, &attr, mark_run, &run)); |
| 496 | if (pthread_task) { |
| 497 | bthread_usleep(100000L); |
| 498 | // due to NOSIGNAL, mark_run did not run. |
| 499 | // FIXME: actually runs. someone is still stealing. |
| 500 | // EXPECT_EQ((pthread_t)0, run); |
| 501 | // bthread_usleep = usleep for BTHREAD_ATTR_PTHREAD |
| 502 | EXPECT_EQ(pid, pthread_self()); |
| 503 | // schedule mark_run |
| 504 | bthread_flush(); |
| 505 | } else { |
| 506 | // start_urgent should jump to the new thread first, then back to |
| 507 | // current thread. |
| 508 | EXPECT_EQ(pid, run); // should run in the same pthread |
| 509 | } |
| 510 | EXPECT_EQ(0, bthread_join(th1, NULL)); |
| 511 | if (pthread_task) { |
| 512 | EXPECT_EQ(pid, pthread_self()); |
| 513 | EXPECT_NE((pthread_t)0, run); // the mark_run should run. |
| 514 | } |
| 515 | return NULL; |
| 516 | } |
| 517 | |
| 518 | TEST_F(BthreadTest, bthread_usleep) { |
| 519 | // NOTE: May fail because worker threads may still be stealing tasks |
nothing calls this directly
no test coverage detected