LibPthread: Add first test cases for RWlock
This commit is contained in:
parent
69b64a6b04
commit
a8fae3d2c8
Notes:
sideshowbarker
2024-07-18 03:22:20 +09:00
Author: https://github.com/rtobar Commit: https://github.com/SerenityOS/serenity/commit/a8fae3d2c8c Pull-request: https://github.com/SerenityOS/serenity/pull/10244
2 changed files with 91 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
set(TEST_SOURCES
|
||||
TestLibPthreadSpinLocks.cpp
|
||||
TestLibPthreadRWLocks.cpp
|
||||
)
|
||||
|
||||
foreach(source IN LISTS TEST_SOURCES)
|
||||
|
|
90
Tests/LibPthread/TestLibPthreadRWLocks.cpp
Normal file
90
Tests/LibPthread/TestLibPthreadRWLocks.cpp
Normal file
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Rodrigo Tobar <rtobarc@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibPthread/pthread.h>
|
||||
#include <LibTest/TestCase.h>
|
||||
|
||||
TEST_CASE(rwlock_init)
|
||||
{
|
||||
pthread_rwlock_t lock;
|
||||
auto result = pthread_rwlock_init(&lock, nullptr);
|
||||
EXPECT_EQ(0, result);
|
||||
}
|
||||
|
||||
TEST_CASE(rwlock_rdlock)
|
||||
{
|
||||
pthread_rwlock_t lock;
|
||||
auto result = pthread_rwlock_init(&lock, nullptr);
|
||||
EXPECT_EQ(0, result);
|
||||
|
||||
result = pthread_rwlock_rdlock(&lock);
|
||||
EXPECT_EQ(0, result);
|
||||
result = pthread_rwlock_unlock(&lock);
|
||||
EXPECT_EQ(0, result);
|
||||
|
||||
result = pthread_rwlock_rdlock(&lock);
|
||||
EXPECT_EQ(0, result);
|
||||
result = pthread_rwlock_rdlock(&lock);
|
||||
EXPECT_EQ(0, result);
|
||||
result = pthread_rwlock_unlock(&lock);
|
||||
EXPECT_EQ(0, result);
|
||||
result = pthread_rwlock_unlock(&lock);
|
||||
EXPECT_EQ(0, result);
|
||||
}
|
||||
|
||||
TEST_CASE(rwlock_wrlock)
|
||||
{
|
||||
pthread_rwlock_t lock;
|
||||
auto result = pthread_rwlock_init(&lock, nullptr);
|
||||
EXPECT_EQ(0, result);
|
||||
|
||||
result = pthread_rwlock_wrlock(&lock);
|
||||
EXPECT_EQ(0, result);
|
||||
result = pthread_rwlock_unlock(&lock);
|
||||
EXPECT_EQ(0, result);
|
||||
}
|
||||
|
||||
TEST_CASE(rwlock_rwr_sequence)
|
||||
{
|
||||
pthread_rwlock_t lock;
|
||||
auto result = pthread_rwlock_init(&lock, nullptr);
|
||||
EXPECT_EQ(0, result);
|
||||
|
||||
result = pthread_rwlock_rdlock(&lock);
|
||||
EXPECT_EQ(0, result);
|
||||
result = pthread_rwlock_unlock(&lock);
|
||||
EXPECT_EQ(0, result);
|
||||
|
||||
result = pthread_rwlock_wrlock(&lock);
|
||||
EXPECT_EQ(0, result);
|
||||
result = pthread_rwlock_unlock(&lock);
|
||||
EXPECT_EQ(0, result);
|
||||
|
||||
result = pthread_rwlock_rdlock(&lock);
|
||||
EXPECT_EQ(0, result);
|
||||
result = pthread_rwlock_unlock(&lock);
|
||||
EXPECT_EQ(0, result);
|
||||
}
|
||||
|
||||
TEST_CASE(rwlock_wrlock_init_in_once)
|
||||
{
|
||||
static pthread_rwlock_t lock;
|
||||
static pthread_once_t once1 = PTHREAD_ONCE_INIT;
|
||||
static pthread_once_t once2 = PTHREAD_ONCE_INIT;
|
||||
static pthread_once_t once3 = PTHREAD_ONCE_INIT;
|
||||
pthread_once(&once1, []() {
|
||||
pthread_once(&once2, []() {
|
||||
pthread_once(&once3, []() {
|
||||
auto result = pthread_rwlock_init(&lock, nullptr);
|
||||
EXPECT_EQ(0, result);
|
||||
});
|
||||
});
|
||||
});
|
||||
auto result = pthread_rwlock_wrlock(&lock);
|
||||
EXPECT_EQ(0, result);
|
||||
result = pthread_rwlock_unlock(&lock);
|
||||
EXPECT_EQ(0, result);
|
||||
}
|
Loading…
Add table
Reference in a new issue