| 45 | } |
| 46 | |
| 47 | TEST(MutexTest, sanity) { |
| 48 | bthread_mutex_t m; |
| 49 | ASSERT_EQ(0, bthread_mutex_init(&m, NULL)); |
| 50 | ASSERT_EQ(0u, *get_butex(m)); |
| 51 | ASSERT_EQ(0, bthread_mutex_lock(&m)); |
| 52 | ASSERT_EQ(1u, *get_butex(m)); |
| 53 | bthread_t th1; |
| 54 | ASSERT_EQ(0, bthread_start_urgent(&th1, NULL, locker, &m)); |
| 55 | usleep(5000); // wait for locker to run. |
| 56 | ASSERT_EQ(257u, *get_butex(m)); // contention |
| 57 | ASSERT_EQ(0, bthread_mutex_unlock(&m)); |
| 58 | ASSERT_EQ(0, bthread_join(th1, NULL)); |
| 59 | ASSERT_EQ(0u, *get_butex(m)); |
| 60 | ASSERT_EQ(0, bthread_mutex_destroy(&m)); |
| 61 | } |
| 62 | |
| 63 | TEST(MutexTest, used_in_pthread) { |
| 64 | bthread_mutex_t m; |
nothing calls this directly
no test coverage detected