Skip to content

Commit d41483b

Browse files
Yifan ZhuSchrodingerZhu
authored andcommitted
add many tests
1 parent 7caf23b commit d41483b

11 files changed

+413
-6
lines changed

libc/src/pthread/pthread_rwlock_destroy.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
namespace LIBC_NAMESPACE {
1818

1919
LLVM_LIBC_FUNCTION(int, pthread_rwlock_destroy, (pthread_rwlock_t * rwlock)) {
20+
if (!rwlock)
21+
return EINVAL;
2022
auto *rw = reinterpret_cast<RwLock *>(rwlock);
2123
RwLock::LockResult res = rw->check_for_destroy();
2224

libc/src/pthread/pthread_rwlock_init.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "src/pthread/pthread_rwlock_init.h"
1010

1111
#include "src/__support/common.h"
12+
#include "src/__support/libc_assert.h"
1213
#include "src/__support/threads/linux/rwlock.h"
1314

1415
#include <errno.h>
@@ -33,6 +34,8 @@ LLVM_LIBC_FUNCTION(int, pthread_rwlock_init,
3334
/*pshared=*/PTHREAD_PROCESS_PRIVATE,
3435
/*pref*/ PTHREAD_RWLOCK_PREFER_READER_NP,
3536
};
37+
// POSIX does not specify this check, so we add an assertion to catch it.
38+
LIBC_ASSERT(rwlock && "rwlock is null");
3639
if (attr)
3740
rwlockattr = *attr;
3841

libc/src/pthread/pthread_rwlock_rdlock.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ static_assert(
2323
"as the internal rwlock type.");
2424

2525
LLVM_LIBC_FUNCTION(int, pthread_rwlock_rdlock, (pthread_rwlock_t * rwlock)) {
26+
if (!rwlock)
27+
return EINVAL;
2628
RwLock *rw = reinterpret_cast<RwLock *>(rwlock);
2729
return static_cast<int>(rw->read_lock());
2830
}

libc/src/pthread/pthread_rwlock_timedrdlock.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ static_assert(
2828
LLVM_LIBC_FUNCTION(int, pthread_rwlock_timedrdlock,
2929
(pthread_rwlock_t * rwlock,
3030
const struct timespec *abstime)) {
31+
if (!rwlock)
32+
return EINVAL;
3133
RwLock *rw = reinterpret_cast<RwLock *>(rwlock);
3234
LIBC_ASSERT(abstime && "timedrdlock called with a null timeout");
3335
auto timeout =

libc/src/pthread/pthread_rwlock_timedwrlock.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ namespace LIBC_NAMESPACE {
2222
LLVM_LIBC_FUNCTION(int, pthread_rwlock_timedwrlock,
2323
(pthread_rwlock_t *__restrict rwlock,
2424
const struct timespec *__restrict abstime)) {
25+
if (!rwlock)
26+
return EINVAL;
2527
RwLock *rw = reinterpret_cast<RwLock *>(rwlock);
2628
LIBC_ASSERT(abstime && "timedwrlock called with a null timeout");
2729
auto timeout =

libc/src/pthread/pthread_rwlock_tryrdlock.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ static_assert(
2323
"as the internal rwlock type.");
2424

2525
LLVM_LIBC_FUNCTION(int, pthread_rwlock_tryrdlock, (pthread_rwlock_t * rwlock)) {
26+
if (!rwlock)
27+
return EINVAL;
2628
RwLock *rw = reinterpret_cast<RwLock *>(rwlock);
2729
return static_cast<int>(rw->try_read_lock());
2830
}

libc/src/pthread/pthread_rwlock_trywrlock.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ static_assert(
2323
"as the internal rwlock type.");
2424

2525
LLVM_LIBC_FUNCTION(int, pthread_rwlock_trywrlock, (pthread_rwlock_t * rwlock)) {
26+
if (!rwlock)
27+
return EINVAL;
2628
RwLock *rw = reinterpret_cast<RwLock *>(rwlock);
2729
return static_cast<int>(rw->try_write_lock());
2830
}

libc/src/pthread/pthread_rwlock_unlock.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
namespace LIBC_NAMESPACE {
1818

1919
LLVM_LIBC_FUNCTION(int, pthread_rwlock_unlock, (pthread_rwlock_t * rwlock)) {
20+
if (!rwlock)
21+
return EINVAL;
2022
auto *rw = reinterpret_cast<RwLock *>(rwlock);
2123
return static_cast<int>(rw->unlock());
2224
}

libc/src/pthread/pthread_rwlock_wrlock.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ static_assert(
2323
"as the internal rwlock type.");
2424

2525
LLVM_LIBC_FUNCTION(int, pthread_rwlock_wrlock, (pthread_rwlock_t * rwlock)) {
26+
if (!rwlock)
27+
return EINVAL;
2628
RwLock *rw = reinterpret_cast<RwLock *>(rwlock);
2729
return static_cast<int>(rw->write_lock());
2830
}

libc/test/integration/src/pthread/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,19 @@ add_integration_test(
3838
libc.src.pthread.pthread_rwlock_unlock
3939
libc.src.pthread.pthread_create
4040
libc.src.pthread.pthread_join
41+
libc.src.pthread.pthread_rwlockattr_init
42+
libc.src.pthread.pthread_rwlockattr_destroy
43+
libc.src.pthread.pthread_rwlockattr_setpshared
44+
libc.src.pthread.pthread_rwlockattr_setkind_np
45+
libc.src.sys.mman.mmap
46+
libc.src.sys.mman.munmap
4147
libc.src.time.clock_gettime
48+
libc.src.sys.random.getrandom
4249
libc.src.unistd.fork
50+
libc.src.sys.wait.waitpid
51+
libc.src.stdlib.exit
52+
libc.src.__support.CPP.atomic
53+
libc.src.__support.threads.sleep
4354
)
4455

4556
add_integration_test(

0 commit comments

Comments
 (0)