From f5e48e94a2f4d4bbd6e5628c7f2afafc6dbcc459 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Thu, 7 Mar 2024 17:28:52 -0500 Subject: build: Build mlibc + add distclean target Signed-off-by: Ian Moffett --- lib/mlibc/tests/posix/pthread_mutex.c | 101 ---------------------------------- 1 file changed, 101 deletions(-) delete mode 100644 lib/mlibc/tests/posix/pthread_mutex.c (limited to 'lib/mlibc/tests/posix/pthread_mutex.c') diff --git a/lib/mlibc/tests/posix/pthread_mutex.c b/lib/mlibc/tests/posix/pthread_mutex.c deleted file mode 100644 index 0a9b82f..0000000 --- a/lib/mlibc/tests/posix/pthread_mutex.c +++ /dev/null @@ -1,101 +0,0 @@ -#include -#include -#include - -#define TEST_ATTR(attr, field, value) ({ \ - int x; \ - assert(!pthread_mutexattr_set ## field (&(attr), (value))); \ - assert(!pthread_mutexattr_get ## field (&(attr), &x)); \ - assert(x == (value)); \ - }) - -int variable; -pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; - -static void *worker(void *arg) { - (void)arg; - pthread_mutex_lock(&mutex); - variable = 1; - pthread_mutex_unlock(&mutex); - return NULL; -} - -static void testAttr() { - pthread_mutexattr_t attr; - pthread_mutexattr_init(&attr); - - TEST_ATTR(attr, type, PTHREAD_MUTEX_DEFAULT); - TEST_ATTR(attr, type, PTHREAD_MUTEX_NORMAL); - TEST_ATTR(attr, type, PTHREAD_MUTEX_ERRORCHECK); - TEST_ATTR(attr, type, PTHREAD_MUTEX_RECURSIVE); - - TEST_ATTR(attr, robust, PTHREAD_MUTEX_STALLED); - TEST_ATTR(attr, robust, PTHREAD_MUTEX_ROBUST); - - TEST_ATTR(attr, protocol, PTHREAD_PRIO_NONE); - TEST_ATTR(attr, protocol, PTHREAD_PRIO_INHERIT); - TEST_ATTR(attr, protocol, PTHREAD_PRIO_PROTECT); - - TEST_ATTR(attr, pshared, PTHREAD_PROCESS_PRIVATE); - TEST_ATTR(attr, pshared, PTHREAD_PROCESS_SHARED); - - // TODO: sched_get_priority* is unimplemented. - // int prio = sched_get_priority_max(SCHED_FIFO); - // TEST_ATTR(attr, prioceiling, prio); - - pthread_mutexattr_destroy(&attr); -} - -static void testNormal() { - pthread_mutexattr_t attr; - pthread_mutexattr_init(&attr); - pthread_mutex_init(&mutex, &attr); - pthread_mutexattr_destroy(&attr); - - pthread_mutex_lock(&mutex); - variable = 0; - - pthread_t thread; - int ret = pthread_create(&thread, NULL, &worker, NULL); - assert(!ret); - - assert(pthread_mutex_trylock(&mutex) == EBUSY); - pthread_mutex_unlock(&mutex); - - ret = pthread_join(thread, NULL); - assert(!ret); - assert(variable == 1); - - pthread_mutex_destroy(&mutex); -} - -static void testRecursive() { - pthread_mutexattr_t attr; - pthread_mutexattr_init(&attr); - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); - pthread_mutex_init(&mutex, &attr); - pthread_mutexattr_destroy(&attr); - - pthread_mutex_lock(&mutex); - variable = 0; - - pthread_t thread; - int ret = pthread_create(&thread, NULL, &worker, NULL); - assert(!ret); - - assert(pthread_mutex_trylock(&mutex) == 0); - pthread_mutex_unlock(&mutex); - pthread_mutex_unlock(&mutex); - - ret = pthread_join(thread, NULL); - assert(!ret); - assert(variable == 1); - - pthread_mutex_destroy(&mutex); -} - -int main() { - testAttr(); - testNormal(); - testRecursive(); -} -- cgit v1.2.3