summaryrefslogtreecommitdiff
path: root/lib/mlibc/tests/posix/pthread_rwlock.c
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-03-07 17:28:52 -0500
committerIan Moffett <ian@osmora.org>2024-03-07 18:24:51 -0500
commitf5e48e94a2f4d4bbd6e5628c7f2afafc6dbcc459 (patch)
tree93b156621dc0303816b37f60ba88051b702d92f6 /lib/mlibc/tests/posix/pthread_rwlock.c
parentbd5969fc876a10b18613302db7087ef3c40f18e1 (diff)
build: Build mlibc + add distclean target
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'lib/mlibc/tests/posix/pthread_rwlock.c')
-rw-r--r--lib/mlibc/tests/posix/pthread_rwlock.c114
1 files changed, 0 insertions, 114 deletions
diff --git a/lib/mlibc/tests/posix/pthread_rwlock.c b/lib/mlibc/tests/posix/pthread_rwlock.c
deleted file mode 100644
index 5316372..0000000
--- a/lib/mlibc/tests/posix/pthread_rwlock.c
+++ /dev/null
@@ -1,114 +0,0 @@
-#include <assert.h>
-#include <errno.h>
-#include <pthread.h>
-
-static void test_write_lock_unlock() {
- int res;
- pthread_rwlock_t rw = PTHREAD_RWLOCK_INITIALIZER;
- res = pthread_rwlock_wrlock(&rw);
- assert(!res);
- res = pthread_rwlock_unlock(&rw);
- assert(!res);
-}
-
-static void test_read_lock_unlock() {
- int res;
- pthread_rwlock_t rw = PTHREAD_RWLOCK_INITIALIZER;
- res = pthread_rwlock_rdlock(&rw);
- assert(!res);
- res = pthread_rwlock_unlock(&rw);
- assert(!res);
-}
-
-static void test_write_trylock_unlock() {
- int res;
- pthread_rwlock_t rw = PTHREAD_RWLOCK_INITIALIZER;
- res = pthread_rwlock_trywrlock(&rw);
- assert(!res);
- res = pthread_rwlock_unlock(&rw);
- assert(!res);
-}
-
-static void test_read_trylock_unlock() {
- int res;
- pthread_rwlock_t rw = PTHREAD_RWLOCK_INITIALIZER;
- res = pthread_rwlock_tryrdlock(&rw);
- assert(!res);
- res = pthread_rwlock_unlock(&rw);
- assert(!res);
-}
-
-static void test_write_prevents_read() {
- int res;
- pthread_rwlock_t rw = PTHREAD_RWLOCK_INITIALIZER;
- res = pthread_rwlock_wrlock(&rw);
- assert(!res);
- res = pthread_rwlock_tryrdlock(&rw);
- assert(res == EBUSY);
- res = pthread_rwlock_unlock(&rw);
- assert(!res);
-}
-
-static void test_write_prevents_write() {
- int res;
- pthread_rwlock_t rw = PTHREAD_RWLOCK_INITIALIZER;
- res = pthread_rwlock_wrlock(&rw);
- assert(!res);
- res = pthread_rwlock_trywrlock(&rw);
- assert(res == EBUSY);
- res = pthread_rwlock_unlock(&rw);
- assert(!res);
-}
-
-static void test_read_prevents_write() {
- int res;
- pthread_rwlock_t rw = PTHREAD_RWLOCK_INITIALIZER;
- res = pthread_rwlock_rdlock(&rw);
- assert(!res);
- res = pthread_rwlock_trywrlock(&rw);
- assert(res == EBUSY);
- res = pthread_rwlock_unlock(&rw);
- assert(!res);
-}
-
-static void test_read_allows_read() {
- int res;
- pthread_rwlock_t rw = PTHREAD_RWLOCK_INITIALIZER;
- res = pthread_rwlock_rdlock(&rw);
- assert(!res);
- res = pthread_rwlock_tryrdlock(&rw);
- assert(!res);
- res = pthread_rwlock_unlock(&rw);
- assert(!res);
-}
-
-static void test_attr() {
- pthread_rwlockattr_t attr;
- pthread_rwlockattr_init(&attr);
-
- int pshared;
- pthread_rwlockattr_getpshared(&attr, &pshared);
- assert(pshared == PTHREAD_PROCESS_PRIVATE);
-
- pthread_rwlockattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
- pthread_rwlockattr_getpshared(&attr, &pshared);
- assert(pshared == PTHREAD_PROCESS_SHARED);
-
- pthread_rwlockattr_setpshared(&attr, PTHREAD_PROCESS_PRIVATE);
- pthread_rwlockattr_getpshared(&attr, &pshared);
- assert(pshared == PTHREAD_PROCESS_PRIVATE);
-
- pthread_rwlockattr_destroy(&attr);
-}
-
-int main() {
- test_write_lock_unlock();
- test_read_lock_unlock();
- test_write_trylock_unlock();
- test_read_trylock_unlock();
- test_write_prevents_read();
- test_write_prevents_write();
- test_read_prevents_write();
- test_read_allows_read();
- test_attr();
-}