bionic tests: migrate test for mutex type from system/extras
Migrate the test about pthread mutex type in file system/extras/tests/bionic/libc/bionic/test_mutex.c to the new place bionic/tests/pthread_test.cpp in the gtest format. Change-Id: I6aab10170ccad5b9a4892d52dba2403876c86659 Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org>
This commit is contained in:
parent
f56a2f5ed2
commit
4199695657
@ -965,15 +965,15 @@ TEST(pthread, pthread_gettid_np) {
|
|||||||
|
|
||||||
static size_t cleanup_counter = 0;
|
static size_t cleanup_counter = 0;
|
||||||
|
|
||||||
void AbortCleanupRoutine(void*) {
|
static void AbortCleanupRoutine(void*) {
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CountCleanupRoutine(void*) {
|
static void CountCleanupRoutine(void*) {
|
||||||
++cleanup_counter;
|
++cleanup_counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PthreadCleanupTester() {
|
static void PthreadCleanupTester() {
|
||||||
pthread_cleanup_push(CountCleanupRoutine, NULL);
|
pthread_cleanup_push(CountCleanupRoutine, NULL);
|
||||||
pthread_cleanup_push(CountCleanupRoutine, NULL);
|
pthread_cleanup_push(CountCleanupRoutine, NULL);
|
||||||
pthread_cleanup_push(AbortCleanupRoutine, NULL);
|
pthread_cleanup_push(AbortCleanupRoutine, NULL);
|
||||||
@ -988,7 +988,7 @@ void PthreadCleanupTester() {
|
|||||||
pthread_cleanup_pop(0);
|
pthread_cleanup_pop(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* PthreadCleanupStartRoutine(void*) {
|
static void* PthreadCleanupStartRoutine(void*) {
|
||||||
PthreadCleanupTester();
|
PthreadCleanupTester();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -999,3 +999,75 @@ TEST(pthread, pthread_cleanup_push__pthread_cleanup_pop) {
|
|||||||
pthread_join(t, NULL);
|
pthread_join(t, NULL);
|
||||||
ASSERT_EQ(2U, cleanup_counter);
|
ASSERT_EQ(2U, cleanup_counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(pthread, PTHREAD_MUTEX_DEFAULT_is_PTHREAD_MUTEX_NORMAL) {
|
||||||
|
ASSERT_EQ(PTHREAD_MUTEX_NORMAL, PTHREAD_MUTEX_DEFAULT);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(pthread, pthread_mutexattr_gettype) {
|
||||||
|
pthread_mutexattr_t attr;
|
||||||
|
ASSERT_EQ(0, pthread_mutexattr_init(&attr));
|
||||||
|
|
||||||
|
int attr_type;
|
||||||
|
|
||||||
|
ASSERT_EQ(0, pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL));
|
||||||
|
ASSERT_EQ(0, pthread_mutexattr_gettype(&attr, &attr_type));
|
||||||
|
ASSERT_EQ(PTHREAD_MUTEX_NORMAL, attr_type);
|
||||||
|
|
||||||
|
ASSERT_EQ(0, pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK));
|
||||||
|
ASSERT_EQ(0, pthread_mutexattr_gettype(&attr, &attr_type));
|
||||||
|
ASSERT_EQ(PTHREAD_MUTEX_ERRORCHECK, attr_type);
|
||||||
|
|
||||||
|
ASSERT_EQ(0, pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE));
|
||||||
|
ASSERT_EQ(0, pthread_mutexattr_gettype(&attr, &attr_type));
|
||||||
|
ASSERT_EQ(PTHREAD_MUTEX_RECURSIVE, attr_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(pthread, pthread_mutex_lock_NORMAL) {
|
||||||
|
pthread_mutexattr_t attr;
|
||||||
|
ASSERT_EQ(0, pthread_mutexattr_init(&attr));
|
||||||
|
ASSERT_EQ(0, pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL));
|
||||||
|
|
||||||
|
pthread_mutex_t lock;
|
||||||
|
ASSERT_EQ(0, pthread_mutex_init(&lock, &attr));
|
||||||
|
|
||||||
|
ASSERT_EQ(0, pthread_mutex_lock(&lock));
|
||||||
|
ASSERT_EQ(0, pthread_mutex_unlock(&lock));
|
||||||
|
ASSERT_EQ(0, pthread_mutex_destroy(&lock));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(pthread, pthread_mutex_lock_ERRORCHECK) {
|
||||||
|
pthread_mutexattr_t attr;
|
||||||
|
ASSERT_EQ(0, pthread_mutexattr_init(&attr));
|
||||||
|
ASSERT_EQ(0, pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK));
|
||||||
|
|
||||||
|
pthread_mutex_t lock;
|
||||||
|
ASSERT_EQ(0, pthread_mutex_init(&lock, &attr));
|
||||||
|
|
||||||
|
ASSERT_EQ(0, pthread_mutex_lock(&lock));
|
||||||
|
ASSERT_EQ(EDEADLK, pthread_mutex_lock(&lock));
|
||||||
|
ASSERT_EQ(0, pthread_mutex_unlock(&lock));
|
||||||
|
ASSERT_EQ(0, pthread_mutex_trylock(&lock));
|
||||||
|
ASSERT_EQ(EBUSY, pthread_mutex_trylock(&lock));
|
||||||
|
ASSERT_EQ(0, pthread_mutex_unlock(&lock));
|
||||||
|
ASSERT_EQ(EPERM, pthread_mutex_unlock(&lock));
|
||||||
|
ASSERT_EQ(0, pthread_mutex_destroy(&lock));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(pthread, pthread_mutex_lock_RECURSIVE) {
|
||||||
|
pthread_mutexattr_t attr;
|
||||||
|
ASSERT_EQ(0, pthread_mutexattr_init(&attr));
|
||||||
|
ASSERT_EQ(0, pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE));
|
||||||
|
|
||||||
|
pthread_mutex_t lock;
|
||||||
|
ASSERT_EQ(0, pthread_mutex_init(&lock, &attr));
|
||||||
|
|
||||||
|
ASSERT_EQ(0, pthread_mutex_lock(&lock));
|
||||||
|
ASSERT_EQ(0, pthread_mutex_lock(&lock));
|
||||||
|
ASSERT_EQ(0, pthread_mutex_unlock(&lock));
|
||||||
|
ASSERT_EQ(0, pthread_mutex_unlock(&lock));
|
||||||
|
ASSERT_EQ(0, pthread_mutex_trylock(&lock));
|
||||||
|
ASSERT_EQ(0, pthread_mutex_unlock(&lock));
|
||||||
|
ASSERT_EQ(EPERM, pthread_mutex_unlock(&lock));
|
||||||
|
ASSERT_EQ(0, pthread_mutex_destroy(&lock));
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user