From: Kevin Day Date: Thu, 30 Jun 2022 05:40:06 +0000 (-0500) Subject: Progress: Add more unit tests for f_thread. X-Git-Tag: 0.5.10~8 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=a2ce6ea2f63e396142eb124b7cfb76a94b473fa0;p=fll Progress: Add more unit tests for f_thread. --- diff --git a/level_0/f_thread/data/build/settings-mocks b/level_0/f_thread/data/build/settings-mocks index 89712ad..03be671 100644 --- a/level_0/f_thread/data/build/settings-mocks +++ b/level_0/f_thread/data/build/settings-mocks @@ -91,10 +91,67 @@ flags -Wl,--wrap=pthread_barrierattr_setpshared flags -Wl,--wrap=pthread_barrier_destroy flags -Wl,--wrap=pthread_barrier_init flags -Wl,--wrap=pthread_barrier_wait +flags -Wl,--wrap=pthread_create +flags -Wl,--wrap=pthread_cancel +flags -Wl,--wrap=pthread_cond_broadcast +flags -Wl,--wrap=pthread_cond_destroy +flags -Wl,--wrap=pthread_cond_init +flags -Wl,--wrap=pthread_cond_signal +flags -Wl,--wrap=pthread_cond_timedwait +flags -Wl,--wrap=pthread_cond_wait +flags -Wl,--wrap=pthread_condattr_destroy flags -Wl,--wrap=pthread_condattr_getclock flags -Wl,--wrap=pthread_condattr_getpshared +flags -Wl,--wrap=pthread_condattr_init flags -Wl,--wrap=pthread_condattr_setclock flags -Wl,--wrap=pthread_condattr_setpshared +flags -Wl,--wrap=pthread_detach +flags -Wl,--wrap=pthread_equal +flags -Wl,--wrap=pthread_exit flags -Wl,--wrap=pthread_getattr_default_np +flags -Wl,--wrap=pthread_getcpuclockid +flags -Wl,--wrap=pthread_getconcurrency +flags -Wl,--wrap=pthread_getspecific +flags -Wl,--wrap=pthread_join +flags -Wl,--wrap=pthread_key_create flags -Wl,--wrap=pthread_key_delete +flags -Wl,--wrap=pthread_self flags -Wl,--wrap=pthread_setattr_default_np +flags -Wl,--wrap=pthread_setcancelstate +flags -Wl,--wrap=pthread_setcanceltype +flags -Wl,--wrap=pthread_setconcurrency +flags -Wl,--wrap=pthread_setspecific +flags -Wl,--wrap=pthread_testcancel +flags -Wl,--wrap=pthread_timedjoin_np +flags -Wl,--wrap=pthread_tryjoin_np + +flags -Wl,--wrap=pthread_rwlock_destroy +flags -Wl,--wrap=pthread_rwlock_init +flags -Wl,--wrap=pthread_rwlock_rdlock +flags -Wl,--wrap=pthread_rwlock_timedrdlock +flags -Wl,--wrap=pthread_rwlock_timedwrlock +flags -Wl,--wrap=pthread_rwlock_tryrdlock +flags -Wl,--wrap=pthread_rwlock_trywrlock +flags -Wl,--wrap=pthread_rwlock_unlock +flags -Wl,--wrap=pthread_rwlock_wrlock +flags -Wl,--wrap=pthread_rwlockattr_destroy +flags -Wl,--wrap=pthread_rwlockattr_init +flags -Wl,--wrap=pthread_rwlockattr_getpshared +flags -Wl,--wrap=pthread_rwlockattr_setpshared +flags -Wl,--wrap=pthread_mutex_destroy +flags -Wl,--wrap=pthread_mutex_init +flags -Wl,--wrap=pthread_mutex_lock +flags -Wl,--wrap=pthread_mutex_timedlock +flags -Wl,--wrap=pthread_mutex_trylock +flags -Wl,--wrap=pthread_mutex_unlock +flags -Wl,--wrap=pthread_mutexattr_destroy +flags -Wl,--wrap=pthread_mutexattr_init +flags -Wl,--wrap=pthread_mutexattr_getprioceiling +flags -Wl,--wrap=pthread_mutexattr_getprotocol +flags -Wl,--wrap=pthread_mutexattr_getpshared +flags -Wl,--wrap=pthread_mutexattr_gettype +flags -Wl,--wrap=pthread_mutexattr_setprioceiling +flags -Wl,--wrap=pthread_mutexattr_setprotocol +flags -Wl,--wrap=pthread_mutexattr_setpshared +flags -Wl,--wrap=pthread_mutexattr_settype +flags -Wl,--wrap=sem_destroy diff --git a/level_0/f_thread/data/build/settings-tests b/level_0/f_thread/data/build/settings-tests index 4c05cce..a4a09a8 100644 --- a/level_0/f_thread/data/build/settings-tests +++ b/level_0/f_thread/data/build/settings-tests @@ -43,8 +43,7 @@ build_sources_program test-thread-spins_adjust.c test-thread-spins_decimate_by.c build_sources_program test-thread-at_fork.c build_sources_program test-thread-attribute_affinity_get.c test-thread-attribute_affinity_set.c -build_sources_program test-thread-attribute_condition_clock_get.c test-thread-attribute_condition_clock_set.c -build_sources_program test-thread-attribute_condition_shared_get.c test-thread-attribute_condition_shared_set.c +build_sources_program test-thread-attribute_concurrency_get.c test-thread-attribute_concurrency_set.c build_sources_program test-thread-attribute_create.c test-thread-attribute_delete.c build_sources_program test-thread-attribute_default_get.c test-thread-attribute_default_set.c build_sources_program test-thread-attribute_detach_get.c test-thread-attribute_detach_set.c @@ -59,6 +58,37 @@ build_sources_program test-thread-barrier_attribute_create.c test-thread-barrier build_sources_program test-thread-barrier_attribute_shared_get.c test-thread-barrier_attribute_shared_set.c build_sources_program test-thread-barrier_create.c test-thread-barrier_delete.c build_sources_program test-thread-barrier_wait.c +build_sources_program test-thread-caller.c +build_sources_program test-thread-cancel.c +build_sources_program test-thread-cancel_state_set.c +build_sources_program test-thread-cancel_test.c +build_sources_program test-thread-cancel_type_set.c +build_sources_program test-thread-clock_get_id.c +build_sources_program test-thread-compare.c +build_sources_program test-thread-condition_attribute_clock_get.c test-thread-condition_attribute_clock_set.c +build_sources_program test-thread-condition_attribute_create.c test-thread-condition_attribute_delete.c +build_sources_program test-thread-condition_attribute_shared_get.c test-thread-condition_attribute_shared_set.c +build_sources_program test-thread-condition_create.c test-thread-condition_delete.c +build_sources_program test-thread-condition_signal.c test-thread-condition_signal_all.c +build_sources_program test-thread-condition_wait.c test-thread-condition_wait_timed.c +build_sources_program test-thread-create.c +build_sources_program test-thread-detach.c +build_sources_program test-thread-exit.c +build_sources_program test-thread-join.c test-thread-join_try.c test-thread-join_timed.c +build_sources_program test-thread-key_create.c test-thread-key_delete.c +build_sources_program test-thread-key_get.c test-thread-key_set.c +build_sources_program test-thread-lock_attribute_create.c test-thread-lock_attribute_delete.c +build_sources_program test-thread-lock_attribute_shared_get.c test-thread-lock_attribute_shared_set.c +build_sources_program test-thread-lock_create.c test-thread-lock_delete.c +build_sources_program test-thread-lock_read.c test-thread-lock_read_timed.c test-thread-lock_read_try.c +build_sources_program test-thread-lock_write.c test-thread-lock_write_timed.c test-thread-lock_write_try.c +build_sources_program test-thread-mutex_attribute_create.c test-thread-mutex_attribute_delete.c +build_sources_program test-thread-mutex_attribute_priority_ceiling_get.c test-thread-mutex_attribute_priority_ceiling_set.c +build_sources_program test-thread-mutex_attribute_shared_get.c test-thread-mutex_attribute_shared_set.c +build_sources_program test-thread-mutex_attribute_type_get.c test-thread-mutex_attribute_type_set.c +build_sources_program test-thread-mutex_attribute_protocol_get.c test-thread-mutex_attribute_protocol_set.c +build_sources_program test-thread-mutex_create.c test-thread-mutex_delete.c +build_sources_program test-thread-mutex_lock.c test-thread-mutex_lock_timed.c test-thread-mutex_lock_try.c build_sources_program test-thread.c diff --git a/level_0/f_thread/tests/unit/c/mock-thread.c b/level_0/f_thread/tests/unit/c/mock-thread.c index c163db7..4e186d7 100644 --- a/level_0/f_thread/tests/unit/c/mock-thread.c +++ b/level_0/f_thread/tests/unit/c/mock-thread.c @@ -224,7 +224,40 @@ int __wrap_pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr, size_t s return 0; } -int __wrap_pthread_attr_setstacksize (pthread_attr_t *attr, size_t stacksize) { +int __wrap_pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_barrier_destroy(pthread_barrier_t *barrier) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned count) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_barrier_wait(pthread_barrier_t *barrier) { const bool failure = mock_type(bool); @@ -279,7 +312,7 @@ int __wrap_pthread_barrierattr_setpshared(pthread_barrierattr_t *attr, int pshar return 0; } -int __wrap_pthread_barrier_destroy(pthread_barrier_t *barrier) { +int __wrap_pthread_cancel(pthread_t pthread) { const bool failure = mock_type(bool); @@ -290,7 +323,7 @@ int __wrap_pthread_barrier_destroy(pthread_barrier_t *barrier) { return 0; } -int __wrap_pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned count) { +int __wrap_pthread_cond_broadcast(pthread_cond_t *__cond) { const bool failure = mock_type(bool); @@ -300,8 +333,17 @@ int __wrap_pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrie return 0; } +int __wrap_pthread_cond_destroy(pthread_cond_t *__mutex) { -int __wrap_pthread_barrier_wait(pthread_barrier_t *barrier) { + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} +int __wrap_pthread_cond_init(pthread_cond_t *__cond, const pthread_condattr_t *__attr) { const bool failure = mock_type(bool); @@ -312,7 +354,7 @@ int __wrap_pthread_barrier_wait(pthread_barrier_t *barrier) { return 0; } -int __wrap_pthread_condattr_getclock(const pthread_condattr_t * restrict attr, clockid_t * restrict clock_id) { +int __wrap_pthread_cond_signal(pthread_cond_t *__cond) { const bool failure = mock_type(bool); @@ -323,7 +365,40 @@ int __wrap_pthread_condattr_getclock(const pthread_condattr_t * restrict attr, c return 0; } -int __wrap_pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clock_id) { +int __wrap_pthread_cond_timedwait(pthread_cond_t *__cond, pthread_mutex_t *__mutex, const struct timespec *__abstime) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_cond_wait(pthread_cond_t *__cond, pthread_mutex_t *__mutex) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_condattr_destroy(pthread_condattr_t *__attr) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_condattr_getclock(const pthread_condattr_t * restrict attr, clockid_t * restrict clock_id) { const bool failure = mock_type(bool); @@ -345,6 +420,28 @@ int __wrap_pthread_condattr_getpshared(const pthread_condattr_t *attr, int *psha return 0; } +int __wrap_pthread_condattr_init(pthread_condattr_t *__attr) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clock_id) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + int __wrap_pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared) { const bool failure = mock_type(bool); @@ -356,6 +453,42 @@ int __wrap_pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared) { return 0; } +int __wrap_pthread_create(pthread_t *pthread, const pthread_attr_t *attr, void *(*routine)(void *), void *arg) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_detach(pthread_t pthread) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_equal(pthread_t __t1, pthread_t __t2) { + + return mock_type(int); +} + +void __wrap_pthread_exit(void *value) { + + if (value) { + int *v = (int *) value; + + *v = mock_type(int); + } +} + int __wrap_pthread_getattr_default_np(pthread_attr_t *attr) { const bool failure = mock_type(bool); @@ -367,11 +500,59 @@ int __wrap_pthread_getattr_default_np(pthread_attr_t *attr) { return 0; } +int __wrap_pthread_getconcurrency(void) { + + return mock_type(int);; +} + +int __wrap_pthread_getcpuclockid(pthread_t thread, clockid_t *clock_id) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +void *__wrap_pthread_getspecific(pthread_key_t key) { + + return mock_type(void *); +} + +int __wrap_pthread_join(pthread_t pthread, void **value_ptr) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_key_create(pthread_key_t *key, void (*destructor)(void *)) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + int __wrap_pthread_key_delete(pthread_key_t key) { return mock_type(int); } +pthread_t __wrap_pthread_self(void) { + + return mock_type(int); +} + int __wrap_pthread_setattr_default_np(const pthread_attr_t *attr) { const bool failure = mock_type(bool); @@ -383,7 +564,414 @@ int __wrap_pthread_setattr_default_np(const pthread_attr_t *attr) { return 0; } -void stub(void) { +int __wrap_pthread_setcancelstate(int state, int *oldstate) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_setcanceltype(int type, int *oldtype) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_setconcurrency(int new_level) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_setspecific(pthread_key_t key, const void *value) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +void __wrap_pthread_testcancel(void) { +} + +int __wrap_pthread_timedjoin_np(pthread_t thread, void **retval) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_tryjoin_np(pthread_t thread, void **retval, const struct timespec *abstime) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_rwlock_destroy(pthread_rwlock_t *rwlock) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_rwlock_rdlock(pthread_rwlock_t *rwlock) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock, const struct timespec *abstime) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock, const struct timespec *abstime) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_rwlock_unlock(pthread_rwlock_t *rwlock) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_rwlock_wrlock(pthread_rwlock_t *rwlock) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_rwlockattr_init(pthread_rwlockattr_t *attr) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *attr, int *pshared) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr, int pshared) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_mutex_destroy(pthread_mutex_t *mutex) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_mutex_lock(pthread_mutex_t *mutex) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *timeout) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_mutex_trylock(pthread_mutex_t *mutex) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_mutex_unlock(pthread_mutex_t *mutex) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_mutexattr_destroy(pthread_mutexattr_t *attr) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_mutexattr_init(pthread_mutexattr_t *attr) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *attr, int *prioceiling) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr, int *protocol) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr, int *pshared) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *kind) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr, int prioceiling) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, int protocol) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_mutexattr_settype(pthread_mutexattr_t *attr, int kind) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_sem_destroy(sem_t *sem) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +void stub(void) { +} + +void stub_other(void *arguments) { +} + +void * stub_callback(void * const arguments) { + + return 0; } #ifdef __cplusplus diff --git a/level_0/f_thread/tests/unit/c/mock-thread.h b/level_0/f_thread/tests/unit/c/mock-thread.h index 0e97830..300943a 100644 --- a/level_0/f_thread/tests/unit/c/mock-thread.h +++ b/level_0/f_thread/tests/unit/c/mock-thread.h @@ -49,67 +49,78 @@ extern int __wrap_pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy); extern int __wrap_pthread_attr_setscope(pthread_attr_t *attr, int contentionscope); extern int __wrap_pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr, size_t stacksize); extern int __wrap_pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize); +extern int __wrap_pthread_barrier_destroy(pthread_barrier_t *barrier); +extern int __wrap_pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned count); +extern int __wrap_pthread_barrier_wait(pthread_barrier_t *barrier); extern int __wrap_pthread_barrierattr_destroy(pthread_barrierattr_t *attr); extern int __wrap_pthread_barrierattr_init(pthread_barrierattr_t *attr); extern int __wrap_pthread_barrierattr_getpshared(const pthread_barrierattr_t *attr, int *pshared); extern int __wrap_pthread_barrierattr_setpshared(pthread_barrierattr_t *attr, int pshared); -extern int __wrap_pthread_barrier_destroy(pthread_barrier_t *barrier); -extern int __wrap_pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned count); -extern int __wrap_pthread_barrier_wait(pthread_barrier_t *barrier); +extern int __wrap_pthread_cancel(pthread_t pthread); +extern int __wrap_pthread_cond_broadcast(pthread_cond_t *__cond); +extern int __wrap_pthread_cond_destroy(pthread_cond_t *__mutex); +extern int __wrap_pthread_cond_init(pthread_cond_t *__cond, const pthread_condattr_t *__attr); +extern int __wrap_pthread_cond_signal(pthread_cond_t *__cond); +extern int __wrap_pthread_cond_timedwait(pthread_cond_t *__cond, pthread_mutex_t *__mutex, const struct timespec *__abstime); +extern int __wrap_pthread_cond_wait(pthread_cond_t *__cond, pthread_mutex_t *__mutex); +extern int __wrap_pthread_condattr_destroy(pthread_condattr_t *__attr); extern int __wrap_pthread_condattr_getclock(const pthread_condattr_t * restrict attr, clockid_t * restrict clock_id); extern int __wrap_pthread_condattr_getpshared(const pthread_condattr_t *attr, int *pshared); +extern int __wrap_pthread_condattr_init(pthread_condattr_t *__attr); extern int __wrap_pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clock_id); extern int __wrap_pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared); +extern int __wrap_pthread_create(pthread_t *pthread, const pthread_attr_t *attr, void *(*routine)(void *), void *arg); +extern int __wrap_pthread_detach(pthread_t pthread); +extern int __wrap_pthread_equal(pthread_t __t1, pthread_t __t2); +extern void __wrap_pthread_exit(void *value); extern int __wrap_pthread_getattr_default_np(pthread_attr_t *attr); +extern int __wrap_pthread_getconcurrency(void); +extern int __wrap_pthread_getcpuclockid(pthread_t thread, clockid_t *clock_id); +extern void *__wrap_pthread_getspecific(pthread_key_t key); +extern int __wrap_pthread_join(pthread_t pthread, void **value_ptr); +extern int __wrap_pthread_key_create(pthread_key_t *key, void (*destructor)(void*)); extern int __wrap_pthread_key_delete(pthread_key_t key); +extern pthread_t __wrap_pthread_self(void); extern int __wrap_pthread_setattr_default_np(const pthread_attr_t *attr); +extern int __wrap_pthread_setcancelstate(int state, int *oldstate); +extern int __wrap_pthread_setcanceltype(int type, int *oldtype); +extern int __wrap_pthread_setconcurrency(int new_level); +extern int __wrap_pthread_setspecific(pthread_key_t key, const void *value); +extern void __wrap_pthread_testcancel(void); +extern int __wrap_pthread_timedjoin_np(pthread_t thread, void **retval); +extern int __wrap_pthread_tryjoin_np(pthread_t thread, void **retval, const struct timespec *abstime); +extern int __wrap_pthread_rwlock_destroy(pthread_rwlock_t *rwlock); +extern int __wrap_pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr); +extern int __wrap_pthread_rwlock_rdlock(pthread_rwlock_t *rwlock); +extern int __wrap_pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock, const struct timespec *abstime); +extern int __wrap_pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock, const struct timespec *abstime); +extern int __wrap_pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock); +extern int __wrap_pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock); +extern int __wrap_pthread_rwlock_unlock(pthread_rwlock_t *rwlock); +extern int __wrap_pthread_rwlock_wrlock(pthread_rwlock_t *rwlock); +extern int __wrap_pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr); +extern int __wrap_pthread_rwlockattr_init(pthread_rwlockattr_t *attr); +extern int __wrap_pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *attr, int *pshared); +extern int __wrap_pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr, int pshared); +extern int __wrap_pthread_mutex_destroy(pthread_mutex_t *mutex); +extern int __wrap_pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr); +extern int __wrap_pthread_mutex_lock(pthread_mutex_t *mutex); +extern int __wrap_pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *timeout); +extern int __wrap_pthread_mutex_trylock(pthread_mutex_t *mutex); +extern int __wrap_pthread_mutex_unlock(pthread_mutex_t *mutex); +extern int __wrap_pthread_mutexattr_destroy(pthread_mutexattr_t *attr); +extern int __wrap_pthread_mutexattr_init(pthread_mutexattr_t *attr); +extern int __wrap_pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *attr, int *prioceiling); +extern int __wrap_pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr, int *protocol); +extern int __wrap_pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr, int *pshared); +extern int __wrap_pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *kind); +extern int __wrap_pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr, int prioceiling); +extern int __wrap_pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, int protocol); +extern int __wrap_pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared); +extern int __wrap_pthread_mutexattr_settype(pthread_mutexattr_t *attr, int kind); +extern int __wrap_sem_destroy(sem_t *sem); /* -pthread_setcancelstate -pthread_testcancel -pthread_setcanceltype -pthread_getcpuclockid -pthread_equal -pthread_getconcurrency -pthread_setconcurrency -pthread_condattr_init -pthread_cond_init -pthread_cond_broadcast -pthread_cond_signal -pthread_cond_wait -pthread_cond_timedwait -pthread_create -pthread_detach -pthread_exit -pthread_join -pthread_tryjoin_np -pthread_timedjoin_np -pthread_key_create -pthread_getspecific -pthread_setspecific -pthread_rwlockattr_init -pthread_rwlockattr_getpshared -pthread_rwlockattr_setpshared -pthread_rwlock_init -pthread_rwlock_rdlock -pthread_rwlock_timedrdlock -pthread_rwlock_tryrdlock -pthread_rwlock_wrlock -pthread_rwlock_timedwrlock -pthread_rwlock_trywrlock -pthread_mutexattr_init -pthread_mutexattr_getprioceiling -pthread_mutexattr_setprioceiling -pthread_mutexattr_getpshared -pthread_mutexattr_setpshared -pthread_mutexattr_gettype -pthread_mutexattr_settype -pthread_mutexattr_getprotocol -pthread_mutexattr_setprotocol -pthread_mutex_init -pthread_mutex_lock -pthread_mutex_timedlock -pthread_mutex_trylock sem_init sem_open sem_close @@ -140,6 +151,16 @@ pthread_rwlock_unlock */ extern void stub(void); +/** + * A stub intended to be used for passing to functions like f_thread_key_create(). + */ +extern void stub_other(void *arguments); + +/** + * A stub intended to be used for passing to functions like f_thread_create(). + */ +extern void *stub_callback(void * const arguments); + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_concurrency_get.c b/level_0/f_thread/tests/unit/c/test-thread-attribute_concurrency_get.c new file mode 100644 index 0000000..150b2ce --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-attribute_concurrency_get.c @@ -0,0 +1,33 @@ +#include "test-thread.h" +#include "test-thread-attribute_concurrency_get.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_attribute_concurrency_get__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_attribute_concurrency_get(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_attribute_concurrency_get__works(void **state) { + + int level = 0; + + { + will_return(__wrap_pthread_getconcurrency, 1); + + const f_status_t status = f_thread_attribute_concurrency_get(&level); + + assert_int_equal(status, F_none); + assert_int_equal(level, 1); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_concurrency_get.h b/level_0/f_thread/tests/unit/c/test-thread-attribute_concurrency_get.h new file mode 100644 index 0000000..4913c21 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-attribute_concurrency_get.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__attribute_concurrency_get_h +#define _TEST__F_thread__attribute_concurrency_get_h + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_attribute_concurrency_get() + */ +extern void test__f_thread_attribute_concurrency_get__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_attribute_concurrency_get() + */ +extern void test__f_thread_attribute_concurrency_get__works(void **state); + +#endif // _TEST__F_thread__attribute_concurrency_get_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_concurrency_set.c b/level_0/f_thread/tests/unit/c/test-thread-attribute_concurrency_set.c new file mode 100644 index 0000000..38111d7 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-attribute_concurrency_set.c @@ -0,0 +1,50 @@ +#include "test-thread.h" +#include "test-thread-attribute_concurrency_set.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_attribute_concurrency_set__fails(void **state) { + + int level = 0; + + int errnos[] = { + EAGAIN, + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_resource_not, + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 3; ++i) { + + will_return(__wrap_pthread_setconcurrency, true); + will_return(__wrap_pthread_setconcurrency, errnos[i]); + + const f_status_t status = f_thread_attribute_concurrency_set(level); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_attribute_concurrency_set__works(void **state) { + + int level = 0; + + { + will_return(__wrap_pthread_setconcurrency, false); + + const f_status_t status = f_thread_attribute_concurrency_set(level); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_concurrency_set.h b/level_0/f_thread/tests/unit/c/test-thread-attribute_concurrency_set.h new file mode 100644 index 0000000..43a42e6 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-attribute_concurrency_set.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__attribute_concurrency_set_h +#define _TEST__F_thread__attribute_concurrency_set_h + +/** + * Test that function fails. + * + * @see f_thread_attribute_concurrency_set() + */ +extern void test__f_thread_attribute_concurrency_set__fails(void **state); + +/** + * Test that function works. + * + * @see f_thread_attribute_concurrency_set() + */ +extern void test__f_thread_attribute_concurrency_set__works(void **state); + +#endif // _TEST__F_thread__attribute_concurrency_set_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_condition_clock_get.h b/level_0/f_thread/tests/unit/c/test-thread-attribute_condition_clock_get.h deleted file mode 100644 index c0bc8b4..0000000 --- a/level_0/f_thread/tests/unit/c/test-thread-attribute_condition_clock_get.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Thread - * API Version: 0.5 - * Licenses: lgpl-2.1-or-later - * - * Test the thread project. - */ -#ifndef _TEST__F_thread__attribute_condition_clock_get_h -#define _TEST__F_thread__attribute_condition_clock_get_h - -/** - * Test that function fails. - * - * @see f_thread_attribute_condition_clock_get() - */ -extern void test__f_thread_attribute_condition_clock_get__fails(void **state); - -/** - * Test that parameter checking works as expected. - * - * @see f_thread_attribute_condition_clock_get() - */ -extern void test__f_thread_attribute_condition_clock_get__parameter_checking(void **state); - -/** - * Test that function works. - * - * @see f_thread_attribute_condition_clock_get() - */ -extern void test__f_thread_attribute_condition_clock_get__works(void **state); - -#endif // _TEST__F_thread__attribute_condition_clock_get_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_condition_clock_set.h b/level_0/f_thread/tests/unit/c/test-thread-attribute_condition_clock_set.h deleted file mode 100644 index b54f26f..0000000 --- a/level_0/f_thread/tests/unit/c/test-thread-attribute_condition_clock_set.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Thread - * API Version: 0.5 - * Licenses: lgpl-2.1-or-later - * - * Test the thread project. - */ -#ifndef _TEST__F_thread__attribute_condition_clock_set_h -#define _TEST__F_thread__attribute_condition_clock_set_h - -/** - * Test that function fails. - * - * @see f_thread_attribute_condition_clock_set() - */ -extern void test__f_thread_attribute_condition_clock_set__fails(void **state); - -/** - * Test that parameter checking works as expected. - * - * @see f_thread_attribute_condition_clock_set() - */ -extern void test__f_thread_attribute_condition_clock_set__parameter_checking(void **state); - -/** - * Test that function works. - * - * @see f_thread_attribute_condition_clock_set() - */ -extern void test__f_thread_attribute_condition_clock_set__works(void **state); - -#endif // _TEST__F_thread__attribute_condition_clock_set_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_condition_shared_get.h b/level_0/f_thread/tests/unit/c/test-thread-attribute_condition_shared_get.h deleted file mode 100644 index 4f0330e..0000000 --- a/level_0/f_thread/tests/unit/c/test-thread-attribute_condition_shared_get.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Thread - * API Version: 0.5 - * Licenses: lgpl-2.1-or-later - * - * Test the thread project. - */ -#ifndef _TEST__F_thread__attribute_condition_shared_get_h -#define _TEST__F_thread__attribute_condition_shared_get_h - -/** - * Test that function fails. - * - * @see f_thread_attribute_condition_shared_get() - */ -extern void test__f_thread_attribute_condition_shared_get__fails(void **state); - -/** - * Test that parameter checking works as expected. - * - * @see f_thread_attribute_condition_shared_get() - */ -extern void test__f_thread_attribute_condition_shared_get__parameter_checking(void **state); - -/** - * Test that function works. - * - * @see f_thread_attribute_condition_shared_get() - */ -extern void test__f_thread_attribute_condition_shared_get__works(void **state); - -#endif // _TEST__F_thread__attribute_condition_shared_get_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_condition_shared_set.h b/level_0/f_thread/tests/unit/c/test-thread-attribute_condition_shared_set.h deleted file mode 100644 index a3431f4..0000000 --- a/level_0/f_thread/tests/unit/c/test-thread-attribute_condition_shared_set.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Thread - * API Version: 0.5 - * Licenses: lgpl-2.1-or-later - * - * Test the thread project. - */ -#ifndef _TEST__F_thread__attribute_condition_shared_set_h -#define _TEST__F_thread__attribute_condition_shared_set_h - -/** - * Test that function fails. - * - * @see f_thread_attribute_condition_shared_set() - */ -extern void test__f_thread_attribute_condition_shared_set__fails(void **state); - -/** - * Test that parameter checking works as expected. - * - * @see f_thread_attribute_condition_shared_set() - */ -extern void test__f_thread_attribute_condition_shared_set__parameter_checking(void **state); - -/** - * Test that function works. - * - * @see f_thread_attribute_condition_shared_set() - */ -extern void test__f_thread_attribute_condition_shared_set__works(void **state); - -#endif // _TEST__F_thread__attribute_condition_shared_set_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-caller.c b/level_0/f_thread/tests/unit/c/test-thread-caller.c new file mode 100644 index 0000000..058530b --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-caller.c @@ -0,0 +1,21 @@ +#include "test-thread.h" +#include "test-thread-caller.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_caller__works(void **state) { + + { + will_return(__wrap_pthread_self, 1); + + const f_thread_id_t id = f_thread_caller(); + + assert_int_equal(id, 1); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-caller.h b/level_0/f_thread/tests/unit/c/test-thread-caller.h new file mode 100644 index 0000000..092365c --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-caller.h @@ -0,0 +1,20 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__caller_h +#define _TEST__F_thread__caller_h + +/** + * Test that function works. + * + * @see f_thread_caller() + */ +extern void test__f_thread_caller__works(void **state); + +#endif // _TEST__F_thread__caller_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-cancel.c b/level_0/f_thread/tests/unit/c/test-thread-cancel.c new file mode 100644 index 0000000..4e722b7 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-cancel.c @@ -0,0 +1,48 @@ +#include "test-thread.h" +#include "test-thread-cancel.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_cancel__fails(void **state) { + + f_thread_id_t id = f_thread_id_t_initialize; + + int errnos[] = { + ESRCH, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_found_not, + F_failure, + }; + + for (uint8_t i = 0; i < 2; ++i) { + + will_return(__wrap_pthread_cancel, true); + will_return(__wrap_pthread_cancel, errnos[i]); + + const f_status_t status = f_thread_cancel(id); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_cancel__works(void **state) { + + f_thread_id_t id = f_thread_id_t_initialize; + + { + will_return(__wrap_pthread_cancel, false); + + const f_status_t status = f_thread_cancel(id); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-cancel.h b/level_0/f_thread/tests/unit/c/test-thread-cancel.h new file mode 100644 index 0000000..81860ee --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-cancel.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__cancel_h +#define _TEST__F_thread__cancel_h + +/** + * Test that function fails. + * + * @see f_thread_cancel() + */ +extern void test__f_thread_cancel__fails(void **state); + +/** + * Test that function works. + * + * @see f_thread_cancel() + */ +extern void test__f_thread_cancel__works(void **state); + +#endif // _TEST__F_thread__cancel_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-cancel_state_set.c b/level_0/f_thread/tests/unit/c/test-thread-cancel_state_set.c new file mode 100644 index 0000000..7cabcae --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-cancel_state_set.c @@ -0,0 +1,50 @@ +#include "test-thread.h" +#include "test-thread-cancel_state_set.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_cancel_state_set__fails(void **state) { + + int state_data = 0; + int previous = 0; + + int errnos[] = { + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 2; ++i) { + + will_return(__wrap_pthread_setcancelstate, true); + will_return(__wrap_pthread_setcancelstate, errnos[i]); + + const f_status_t status = f_thread_cancel_state_set(state_data, &previous); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_cancel_state_set__works(void **state) { + + int state_data = 0; + int previous = 0; + + { + will_return(__wrap_pthread_setcancelstate, false); + + const f_status_t status = f_thread_cancel_state_set(state_data, &previous); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-cancel_state_set.h b/level_0/f_thread/tests/unit/c/test-thread-cancel_state_set.h new file mode 100644 index 0000000..f4b40c8 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-cancel_state_set.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__cancel_state_set_h +#define _TEST__F_thread__cancel_state_set_h + +/** + * Test that function fails. + * + * @see f_thread_cancel_state_set() + */ +extern void test__f_thread_cancel_state_set__fails(void **state); + +/** + * Test that function works. + * + * @see f_thread_cancel_state_set() + */ +extern void test__f_thread_cancel_state_set__works(void **state); + +#endif // _TEST__F_thread__cancel_state_set_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-cancel_test.c b/level_0/f_thread/tests/unit/c/test-thread-cancel_test.c new file mode 100644 index 0000000..6e93b94 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-cancel_test.c @@ -0,0 +1,19 @@ +#include "test-thread.h" +#include "test-thread-cancel_test.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_cancel_test__works(void **state) { + + { + const f_status_t status = f_thread_cancel_test(); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-cancel_test.h b/level_0/f_thread/tests/unit/c/test-thread-cancel_test.h new file mode 100644 index 0000000..5cc42b2 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-cancel_test.h @@ -0,0 +1,20 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__cancel_test_h +#define _TEST__F_thread__cancel_test_h + +/** + * Test that function works. + * + * @see f_thread_cancel_test() + */ +extern void test__f_thread_cancel_test__works(void **state); + +#endif // _TEST__F_thread__cancel_test_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-cancel_type_set.c b/level_0/f_thread/tests/unit/c/test-thread-cancel_type_set.c new file mode 100644 index 0000000..3653ff1 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-cancel_type_set.c @@ -0,0 +1,50 @@ +#include "test-thread.h" +#include "test-thread-cancel_type_set.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_cancel_type_set__fails(void **state) { + + int type = 0; + int previous = 0; + + int errnos[] = { + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 2; ++i) { + + will_return(__wrap_pthread_setcanceltype, true); + will_return(__wrap_pthread_setcanceltype, errnos[i]); + + const f_status_t status = f_thread_cancel_type_set(type, &previous); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_cancel_type_set__works(void **state) { + + int result = 0; + int previous = 0; + + { + will_return(__wrap_pthread_setcanceltype, false); + + const f_status_t status = f_thread_cancel_type_set(result, &previous); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-cancel_type_set.h b/level_0/f_thread/tests/unit/c/test-thread-cancel_type_set.h new file mode 100644 index 0000000..a749a20 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-cancel_type_set.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__cancel_type_set_h +#define _TEST__F_thread__cancel_type_set_h + +/** + * Test that function fails. + * + * @see f_thread_cancel_type_set() + */ +extern void test__f_thread_cancel_type_set__fails(void **state); + +/** + * Test that function works. + * + * @see f_thread_cancel_type_set() + */ +extern void test__f_thread_cancel_type_set__works(void **state); + +#endif // _TEST__F_thread__cancel_type_set_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-clock_get_id.c b/level_0/f_thread/tests/unit/c/test-thread-clock_get_id.c new file mode 100644 index 0000000..8005476 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-clock_get_id.c @@ -0,0 +1,67 @@ +#include "test-thread.h" +#include "test-thread-clock_get_id.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_clock_get_id__fails(void **state) { + + f_thread_id_t id_thread = f_thread_id_t_initialize; + clockid_t id_clock; + + memset(&id_clock, 0, sizeof(clockid_t)); + + int errnos[] = { + ENOENT, + ESRCH, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_supported_not, + F_found_not, + F_failure, + }; + + for (uint8_t i = 0; i < 3; ++i) { + + will_return(__wrap_pthread_getcpuclockid, true); + will_return(__wrap_pthread_getcpuclockid, errnos[i]); + + const f_status_t status = f_thread_clock_get_id(id_thread, &id_clock); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_clock_get_id__parameter_checking(void **state) { + + f_thread_id_t id_thread = f_thread_id_t_initialize; + + { + const f_status_t status = f_thread_clock_get_id(id_thread, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_clock_get_id__works(void **state) { + + f_thread_id_t id_thread = f_thread_id_t_initialize; + clockid_t id_clock; + + memset(&id_clock, 0, sizeof(clockid_t)); + + { + will_return(__wrap_pthread_getcpuclockid, false); + + const f_status_t status = f_thread_clock_get_id(id_thread, &id_clock); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-clock_get_id.h b/level_0/f_thread/tests/unit/c/test-thread-clock_get_id.h new file mode 100644 index 0000000..42c221b --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-clock_get_id.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__clock_get_id_h +#define _TEST__F_thread__clock_get_id_h + +/** + * Test that function fails. + * + * @see f_thread_clock_get_id() + */ +extern void test__f_thread_clock_get_id__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_clock_get_id() + */ +extern void test__f_thread_clock_get_id__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_clock_get_id() + */ +extern void test__f_thread_clock_get_id__works(void **state); + +#endif // _TEST__F_thread__clock_get_id_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-compare.c b/level_0/f_thread/tests/unit/c/test-thread-compare.c new file mode 100644 index 0000000..f76af41 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-compare.c @@ -0,0 +1,32 @@ +#include "test-thread.h" +#include "test-thread-compare.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_compare__works(void **state) { + + f_thread_id_t id1 = 0; + f_thread_id_t id2 = 0; + + { + will_return(__wrap_pthread_equal, false); + + const f_status_t status = f_thread_compare(id1, id2); + + assert_int_equal(status, F_equal_to_not); + } + + { + will_return(__wrap_pthread_equal, true); + + const f_status_t status = f_thread_compare(id1, id2); + + assert_int_equal(status, F_equal_to); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-compare.h b/level_0/f_thread/tests/unit/c/test-thread-compare.h new file mode 100644 index 0000000..25d1b5b --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-compare.h @@ -0,0 +1,20 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__compare_h +#define _TEST__F_thread__compare_h + +/** + * Test that function works. + * + * @see f_thread_compare() + */ +extern void test__f_thread_compare__works(void **state); + +#endif // _TEST__F_thread__compare_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_condition_clock_get.c b/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_clock_get.c similarity index 72% rename from level_0/f_thread/tests/unit/c/test-thread-attribute_condition_clock_get.c rename to level_0/f_thread/tests/unit/c/test-thread-condition_attribute_clock_get.c index aa0b1f8..3249757 100644 --- a/level_0/f_thread/tests/unit/c/test-thread-attribute_condition_clock_get.c +++ b/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_clock_get.c @@ -1,11 +1,11 @@ #include "test-thread.h" -#include "test-thread-attribute_condition_clock_get.h" +#include "test-thread-condition_attribute_clock_get.h" #ifdef __cplusplus extern "C" { #endif -void test__f_thread_attribute_condition_clock_get__fails(void **state) { +void test__f_thread_condition_attribute_clock_get__fails(void **state) { f_thread_condition_attribute_t attribute = f_thread_condition_attribute_t_initialize; clockid_t id; @@ -27,24 +27,24 @@ void test__f_thread_attribute_condition_clock_get__fails(void **state) { will_return(__wrap_pthread_condattr_getclock, true); will_return(__wrap_pthread_condattr_getclock, errnos[i]); - const f_status_t status = f_thread_attribute_condition_clock_get(&attribute, &id); + const f_status_t status = f_thread_condition_attribute_clock_get(&attribute, &id); assert_int_equal(status, F_status_set_error(statuss[i])); } // for } -void test__f_thread_attribute_condition_clock_get__parameter_checking(void **state) { +void test__f_thread_condition_attribute_clock_get__parameter_checking(void **state) { f_thread_condition_attribute_t attribute = f_thread_condition_attribute_t_initialize; { - const f_status_t status = f_thread_attribute_condition_clock_get(&attribute, 0); + const f_status_t status = f_thread_condition_attribute_clock_get(&attribute, 0); assert_int_equal(status, F_status_set_error(F_parameter)); } } -void test__f_thread_attribute_condition_clock_get__works(void **state) { +void test__f_thread_condition_attribute_clock_get__works(void **state) { f_thread_condition_attribute_t attribute = f_thread_condition_attribute_t_initialize; clockid_t id; @@ -54,7 +54,7 @@ void test__f_thread_attribute_condition_clock_get__works(void **state) { { will_return(__wrap_pthread_condattr_getclock, false); - const f_status_t status = f_thread_attribute_condition_clock_get(&attribute, &id); + const f_status_t status = f_thread_condition_attribute_clock_get(&attribute, &id); assert_int_equal(status, F_none); } diff --git a/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_clock_get.h b/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_clock_get.h new file mode 100644 index 0000000..e60285d --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_clock_get.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__condition_attribute_clock_get_h +#define _TEST__F_thread__condition_attribute_clock_get_h + +/** + * Test that function fails. + * + * @see f_thread_condition_attribute_clock_get() + */ +extern void test__f_thread_condition_attribute_clock_get__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_condition_attribute_clock_get() + */ +extern void test__f_thread_condition_attribute_clock_get__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_condition_attribute_clock_get() + */ +extern void test__f_thread_condition_attribute_clock_get__works(void **state); + +#endif // _TEST__F_thread__condition_attribute_clock_get_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_condition_clock_set.c b/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_clock_set.c similarity index 67% rename from level_0/f_thread/tests/unit/c/test-thread-attribute_condition_clock_set.c rename to level_0/f_thread/tests/unit/c/test-thread-condition_attribute_clock_set.c index 2283aaa..bf82f99 100644 --- a/level_0/f_thread/tests/unit/c/test-thread-attribute_condition_clock_set.c +++ b/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_clock_set.c @@ -1,11 +1,11 @@ #include "test-thread.h" -#include "test-thread-attribute_condition_clock_set.h" +#include "test-thread-condition_attribute_clock_set.h" #ifdef __cplusplus extern "C" { #endif -void test__f_thread_attribute_condition_clock_set__fails(void **state) { +void test__f_thread_condition_attribute_clock_set__fails(void **state) { f_thread_condition_attribute_t attribute = f_thread_condition_attribute_t_initialize; @@ -24,29 +24,29 @@ void test__f_thread_attribute_condition_clock_set__fails(void **state) { will_return(__wrap_pthread_condattr_setclock, true); will_return(__wrap_pthread_condattr_setclock, errnos[i]); - const f_status_t status = f_thread_attribute_condition_clock_set(0, &attribute); + const f_status_t status = f_thread_condition_attribute_clock_set(0, &attribute); assert_int_equal(status, F_status_set_error(statuss[i])); } // for } -void test__f_thread_attribute_condition_clock_set__parameter_checking(void **state) { +void test__f_thread_condition_attribute_clock_set__parameter_checking(void **state) { { - const f_status_t status = f_thread_attribute_condition_clock_set(0, 0); + const f_status_t status = f_thread_condition_attribute_clock_set(0, 0); assert_int_equal(status, F_status_set_error(F_parameter)); } } -void test__f_thread_attribute_condition_clock_set__works(void **state) { +void test__f_thread_condition_attribute_clock_set__works(void **state) { f_thread_condition_attribute_t attribute = f_thread_condition_attribute_t_initialize; { will_return(__wrap_pthread_condattr_setclock, false); - const f_status_t status = f_thread_attribute_condition_clock_set(0, &attribute); + const f_status_t status = f_thread_condition_attribute_clock_set(0, &attribute); assert_int_equal(status, F_none); } diff --git a/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_clock_set.h b/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_clock_set.h new file mode 100644 index 0000000..f2c575d --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_clock_set.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__condition_attribute_clock_set_h +#define _TEST__F_thread__condition_attribute_clock_set_h + +/** + * Test that function fails. + * + * @see f_thread_condition_attribute_clock_set() + */ +extern void test__f_thread_condition_attribute_clock_set__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_condition_attribute_clock_set() + */ +extern void test__f_thread_condition_attribute_clock_set__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_condition_attribute_clock_set() + */ +extern void test__f_thread_condition_attribute_clock_set__works(void **state); + +#endif // _TEST__F_thread__condition_attribute_clock_set_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_create.c b/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_create.c new file mode 100644 index 0000000..ca24110 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_create.c @@ -0,0 +1,59 @@ +#include "test-thread.h" +#include "test-thread-condition_attribute_create.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_condition_attribute_create__fails(void **state) { + + f_thread_condition_attribute_t attribute = f_thread_condition_attribute_t_initialize; + + int errnos[] = { + EINVAL, + ENOMEM, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_parameter, + F_memory_not, + F_failure, + }; + + for (uint8_t i = 0; i < 3; ++i) { + + will_return(__wrap_pthread_condattr_init, true); + will_return(__wrap_pthread_condattr_init, errnos[i]); + + const f_status_t status = f_thread_condition_attribute_create(&attribute); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_condition_attribute_create__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_condition_attribute_create(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_condition_attribute_create__works(void **state) { + + f_thread_condition_attribute_t attribute = f_thread_condition_attribute_t_initialize; + + { + will_return(__wrap_pthread_condattr_init, false); + + const f_status_t status = f_thread_condition_attribute_create(&attribute); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_create.h b/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_create.h new file mode 100644 index 0000000..ab855f4 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_create.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__condition_attribute_create_h +#define _TEST__F_thread__condition_attribute_create_h + +/** + * Test that function fails. + * + * @see f_thread_condition_attribute_create() + */ +extern void test__f_thread_condition_attribute_create__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_condition_attribute_create() + */ +extern void test__f_thread_condition_attribute_create__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_condition_attribute_create() + */ +extern void test__f_thread_condition_attribute_create__works(void **state); + +#endif // _TEST__F_thread__condition_attribute_create_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_delete.c b/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_delete.c new file mode 100644 index 0000000..4d25d0b --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_delete.c @@ -0,0 +1,59 @@ +#include "test-thread.h" +#include "test-thread-condition_attribute_delete.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_condition_attribute_delete__fails(void **state) { + + f_thread_condition_attribute_t attribute = f_thread_condition_attribute_t_initialize; + + int errnos[] = { + EBUSY, + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_busy, + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 3; ++i) { + + will_return(__wrap_pthread_condattr_destroy, true); + will_return(__wrap_pthread_condattr_destroy, errnos[i]); + + const f_status_t status = f_thread_condition_attribute_delete(&attribute); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_condition_attribute_delete__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_condition_attribute_delete(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_condition_attribute_delete__works(void **state) { + + f_thread_condition_attribute_t attribute = f_thread_condition_attribute_t_initialize; + + { + will_return(__wrap_pthread_condattr_destroy, false); + + const f_status_t status = f_thread_condition_attribute_delete(&attribute); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_delete.h b/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_delete.h new file mode 100644 index 0000000..2a669ea --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_delete.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__condition_attribute_delete_h +#define _TEST__F_thread__condition_attribute_delete_h + +/** + * Test that function fails. + * + * @see f_thread_condition_attribute_delete() + */ +extern void test__f_thread_condition_attribute_delete__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_condition_attribute_delete() + */ +extern void test__f_thread_condition_attribute_delete__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_condition_attribute_delete() + */ +extern void test__f_thread_condition_attribute_delete__works(void **state); + +#endif // _TEST__F_thread__condition_attribute_delete_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_condition_shared_get.c b/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_shared_get.c similarity index 69% rename from level_0/f_thread/tests/unit/c/test-thread-attribute_condition_shared_get.c rename to level_0/f_thread/tests/unit/c/test-thread-condition_attribute_shared_get.c index c343475..84e624e 100644 --- a/level_0/f_thread/tests/unit/c/test-thread-attribute_condition_shared_get.c +++ b/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_shared_get.c @@ -1,11 +1,11 @@ #include "test-thread.h" -#include "test-thread-attribute_condition_shared_get.h" +#include "test-thread-condition_attribute_shared_get.h" #ifdef __cplusplus extern "C" { #endif -void test__f_thread_attribute_condition_shared_get__fails(void **state) { +void test__f_thread_condition_attribute_shared_get__fails(void **state) { f_thread_condition_attribute_t attribute = f_thread_condition_attribute_t_initialize; int shared = 0; @@ -25,37 +25,37 @@ void test__f_thread_attribute_condition_shared_get__fails(void **state) { will_return(__wrap_pthread_condattr_getpshared, true); will_return(__wrap_pthread_condattr_getpshared, errnos[i]); - const f_status_t status = f_thread_attribute_condition_shared_get(&attribute, &shared); + const f_status_t status = f_thread_condition_attribute_shared_get(&attribute, &shared); assert_int_equal(status, F_status_set_error(statuss[i])); } // for } -void test__f_thread_attribute_condition_shared_get__parameter_checking(void **state) { +void test__f_thread_condition_attribute_shared_get__parameter_checking(void **state) { f_thread_condition_attribute_t attribute = f_thread_condition_attribute_t_initialize; int shared = 0; { - const f_status_t status = f_thread_attribute_condition_shared_get(0, 0); + const f_status_t status = f_thread_condition_attribute_shared_get(0, 0); assert_int_equal(status, F_status_set_error(F_parameter)); } { - const f_status_t status = f_thread_attribute_condition_shared_get(&attribute, 0); + const f_status_t status = f_thread_condition_attribute_shared_get(&attribute, 0); assert_int_equal(status, F_status_set_error(F_parameter)); } { - const f_status_t status = f_thread_attribute_condition_shared_get(0, &shared); + const f_status_t status = f_thread_condition_attribute_shared_get(0, &shared); assert_int_equal(status, F_status_set_error(F_parameter)); } } -void test__f_thread_attribute_condition_shared_get__works(void **state) { +void test__f_thread_condition_attribute_shared_get__works(void **state) { f_thread_condition_attribute_t attribute = f_thread_condition_attribute_t_initialize; int shared = 0; @@ -63,7 +63,7 @@ void test__f_thread_attribute_condition_shared_get__works(void **state) { { will_return(__wrap_pthread_condattr_getpshared, false); - const f_status_t status = f_thread_attribute_condition_shared_get(&attribute, &shared); + const f_status_t status = f_thread_condition_attribute_shared_get(&attribute, &shared); assert_int_equal(status, F_none); } diff --git a/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_shared_get.h b/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_shared_get.h new file mode 100644 index 0000000..fc646d2 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_shared_get.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__condition_attribute_shared_get_h +#define _TEST__F_thread__condition_attribute_shared_get_h + +/** + * Test that function fails. + * + * @see f_thread_condition_attribute_shared_get() + */ +extern void test__f_thread_condition_attribute_shared_get__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_condition_attribute_shared_get() + */ +extern void test__f_thread_condition_attribute_shared_get__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_condition_attribute_shared_get() + */ +extern void test__f_thread_condition_attribute_shared_get__works(void **state); + +#endif // _TEST__F_thread__condition_attribute_shared_get_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_condition_shared_set.c b/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_shared_set.c similarity index 68% rename from level_0/f_thread/tests/unit/c/test-thread-attribute_condition_shared_set.c rename to level_0/f_thread/tests/unit/c/test-thread-condition_attribute_shared_set.c index 0b57e29..979a9ad 100644 --- a/level_0/f_thread/tests/unit/c/test-thread-attribute_condition_shared_set.c +++ b/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_shared_set.c @@ -1,11 +1,11 @@ #include "test-thread.h" -#include "test-thread-attribute_condition_shared_set.h" +#include "test-thread-condition_attribute_shared_set.h" #ifdef __cplusplus extern "C" { #endif -void test__f_thread_attribute_condition_shared_set__fails(void **state) { +void test__f_thread_condition_attribute_shared_set__fails(void **state) { f_thread_condition_attribute_t attribute = f_thread_condition_attribute_t_initialize; @@ -24,29 +24,29 @@ void test__f_thread_attribute_condition_shared_set__fails(void **state) { will_return(__wrap_pthread_condattr_setpshared, true); will_return(__wrap_pthread_condattr_setpshared, errnos[i]); - const f_status_t status = f_thread_attribute_condition_shared_set(0, &attribute); + const f_status_t status = f_thread_condition_attribute_shared_set(0, &attribute); assert_int_equal(status, F_status_set_error(statuss[i])); } // for } -void test__f_thread_attribute_condition_shared_set__parameter_checking(void **state) { +void test__f_thread_condition_attribute_shared_set__parameter_checking(void **state) { { - const f_status_t status = f_thread_attribute_condition_shared_set(0, 0); + const f_status_t status = f_thread_condition_attribute_shared_set(0, 0); assert_int_equal(status, F_status_set_error(F_parameter)); } } -void test__f_thread_attribute_condition_shared_set__works(void **state) { +void test__f_thread_condition_attribute_shared_set__works(void **state) { f_thread_condition_attribute_t attribute = f_thread_condition_attribute_t_initialize; { will_return(__wrap_pthread_condattr_setpshared, false); - const f_status_t status = f_thread_attribute_condition_shared_set(0, &attribute); + const f_status_t status = f_thread_condition_attribute_shared_set(0, &attribute); assert_int_equal(status, F_none); } diff --git a/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_shared_set.h b/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_shared_set.h new file mode 100644 index 0000000..332e7f9 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-condition_attribute_shared_set.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__condition_attribute_shared_set_h +#define _TEST__F_thread__condition_attribute_shared_set_h + +/** + * Test that function fails. + * + * @see f_thread_condition_attribute_shared_set() + */ +extern void test__f_thread_condition_attribute_shared_set__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_condition_attribute_shared_set() + */ +extern void test__f_thread_condition_attribute_shared_set__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_condition_attribute_shared_set() + */ +extern void test__f_thread_condition_attribute_shared_set__works(void **state); + +#endif // _TEST__F_thread__condition_attribute_shared_set_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-condition_attributes_decimate_by.c b/level_0/f_thread/tests/unit/c/test-thread-condition_attributes_decimate_by.c index caba115..114c55e 100644 --- a/level_0/f_thread/tests/unit/c/test-thread-condition_attributes_decimate_by.c +++ b/level_0/f_thread/tests/unit/c/test-thread-condition_attributes_decimate_by.c @@ -59,6 +59,10 @@ void test__f_thread_condition_attributes_decimate_by__works(void **state) { } { + for (uint8_t i = 0; i < length; ++i) { + will_return(__wrap_pthread_condattr_destroy, false); + } // for + const f_status_t status = f_thread_condition_attributes_decimate_by(length, &data); assert_int_equal(status, F_none); diff --git a/level_0/f_thread/tests/unit/c/test-thread-condition_attributes_decrease_by.c b/level_0/f_thread/tests/unit/c/test-thread-condition_attributes_decrease_by.c index 76fc5e5..d6efaf1 100644 --- a/level_0/f_thread/tests/unit/c/test-thread-condition_attributes_decrease_by.c +++ b/level_0/f_thread/tests/unit/c/test-thread-condition_attributes_decrease_by.c @@ -59,6 +59,10 @@ void test__f_thread_condition_attributes_decrease_by__works(void **state) { } { + for (uint8_t i = 0; i < length; ++i) { + will_return(__wrap_pthread_condattr_destroy, false); + } // for + const f_status_t status = f_thread_condition_attributes_decrease_by(length, &data); assert_int_equal(status, F_none); diff --git a/level_0/f_thread/tests/unit/c/test-thread-condition_create.c b/level_0/f_thread/tests/unit/c/test-thread-condition_create.c new file mode 100644 index 0000000..6a8c703 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-condition_create.c @@ -0,0 +1,67 @@ +#include "test-thread.h" +#include "test-thread-condition_create.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_condition_create__fails(void **state) { + + f_thread_condition_attribute_t attribute = f_thread_condition_attribute_t_initialize; + f_thread_condition_t condition = f_thread_condition_t_initialize; + + int errnos[] = { + EAGAIN, + EBUSY, + EINVAL, + ENOMEM, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_resource_not, + F_busy, + F_parameter, + F_memory_not, + F_failure, + }; + + for (uint8_t i = 0; i < 5; ++i) { + + will_return(__wrap_pthread_cond_init, true); + will_return(__wrap_pthread_cond_init, errnos[i]); + + const f_status_t status = f_thread_condition_create(&attribute, &condition); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_condition_create__parameter_checking(void **state) { + + f_thread_condition_attribute_t attribute = f_thread_condition_attribute_t_initialize; + + { + const f_status_t status = f_thread_condition_create(&attribute, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_condition_create__works(void **state) { + + f_thread_condition_attribute_t attribute = f_thread_condition_attribute_t_initialize; + f_thread_condition_t condition = f_thread_condition_t_initialize; + + { + will_return(__wrap_pthread_cond_init, false); + + const f_status_t status = f_thread_condition_create(&attribute, &condition); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-condition_create.h b/level_0/f_thread/tests/unit/c/test-thread-condition_create.h new file mode 100644 index 0000000..843e771 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-condition_create.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__condition_create_h +#define _TEST__F_thread__condition_create_h + +/** + * Test that function fails. + * + * @see f_thread_condition_create() + */ +extern void test__f_thread_condition_create__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_condition_create() + */ +extern void test__f_thread_condition_create__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_condition_create() + */ +extern void test__f_thread_condition_create__works(void **state); + +#endif // _TEST__F_thread__condition_create_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-condition_delete.c b/level_0/f_thread/tests/unit/c/test-thread-condition_delete.c new file mode 100644 index 0000000..32f94d6 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-condition_delete.c @@ -0,0 +1,57 @@ +#include "test-thread.h" +#include "test-thread-condition_delete.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_condition_delete__fails(void **state) { + + f_thread_condition_t condition = f_thread_condition_t_initialize; + + int errnos[] = { + EBUSY, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_busy, + F_failure, + }; + + for (uint8_t i = 0; i < 2; ++i) { + + will_return(__wrap_pthread_cond_destroy, true); + will_return(__wrap_pthread_cond_destroy, errnos[i]); + + const f_status_t status = f_thread_condition_delete(&condition); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_condition_delete__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_condition_delete(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_condition_delete__works(void **state) { + + f_thread_condition_t condition = f_thread_condition_t_initialize; + + { + will_return(__wrap_pthread_cond_destroy, false); + + const f_status_t status = f_thread_condition_delete(&condition); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-condition_delete.h b/level_0/f_thread/tests/unit/c/test-thread-condition_delete.h new file mode 100644 index 0000000..707a0f6 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-condition_delete.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__condition_delete_h +#define _TEST__F_thread__condition_delete_h + +/** + * Test that function fails. + * + * @see f_thread_condition_delete() + */ +extern void test__f_thread_condition_delete__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_condition_delete() + */ +extern void test__f_thread_condition_delete__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_condition_delete() + */ +extern void test__f_thread_condition_delete__works(void **state); + +#endif // _TEST__F_thread__condition_delete_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-condition_signal.c b/level_0/f_thread/tests/unit/c/test-thread-condition_signal.c new file mode 100644 index 0000000..dfe4d70 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-condition_signal.c @@ -0,0 +1,57 @@ +#include "test-thread.h" +#include "test-thread-condition_signal.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_condition_signal__fails(void **state) { + + f_thread_condition_t condition = f_thread_condition_t_initialize; + + int errnos[] = { + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 2; ++i) { + + will_return(__wrap_pthread_cond_signal, true); + will_return(__wrap_pthread_cond_signal, errnos[i]); + + const f_status_t status = f_thread_condition_signal(&condition); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_condition_signal__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_condition_signal(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_condition_signal__works(void **state) { + + f_thread_condition_t condition = f_thread_condition_t_initialize; + + { + will_return(__wrap_pthread_cond_signal, false); + + const f_status_t status = f_thread_condition_signal(&condition); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-condition_signal.h b/level_0/f_thread/tests/unit/c/test-thread-condition_signal.h new file mode 100644 index 0000000..68b9d49 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-condition_signal.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__condition_signal_h +#define _TEST__F_thread__condition_signal_h + +/** + * Test that function fails. + * + * @see f_thread_condition_signal() + */ +extern void test__f_thread_condition_signal__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_condition_signal() + */ +extern void test__f_thread_condition_signal__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_condition_signal() + */ +extern void test__f_thread_condition_signal__works(void **state); + +#endif // _TEST__F_thread__condition_signal_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-condition_signal_all.c b/level_0/f_thread/tests/unit/c/test-thread-condition_signal_all.c new file mode 100644 index 0000000..ea01ec7 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-condition_signal_all.c @@ -0,0 +1,57 @@ +#include "test-thread.h" +#include "test-thread-condition_signal_all.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_condition_signal_all__fails(void **state) { + + f_thread_condition_t condition = f_thread_condition_t_initialize; + + int errnos[] = { + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 2; ++i) { + + will_return(__wrap_pthread_cond_broadcast, true); + will_return(__wrap_pthread_cond_broadcast, errnos[i]); + + const f_status_t status = f_thread_condition_signal_all(&condition); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_condition_signal_all__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_condition_signal_all(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_condition_signal_all__works(void **state) { + + f_thread_condition_t condition = f_thread_condition_t_initialize; + + { + will_return(__wrap_pthread_cond_broadcast, false); + + const f_status_t status = f_thread_condition_signal_all(&condition); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-condition_signal_all.h b/level_0/f_thread/tests/unit/c/test-thread-condition_signal_all.h new file mode 100644 index 0000000..aabe285 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-condition_signal_all.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__condition_signal_all_h +#define _TEST__F_thread__condition_signal_all_h + +/** + * Test that function fails. + * + * @see f_thread_condition_signal_all() + */ +extern void test__f_thread_condition_signal_all__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_condition_signal_all() + */ +extern void test__f_thread_condition_signal_all__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_condition_signal_all() + */ +extern void test__f_thread_condition_signal_all__works(void **state); + +#endif // _TEST__F_thread__condition_signal_all_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-condition_wait.c b/level_0/f_thread/tests/unit/c/test-thread-condition_wait.c new file mode 100644 index 0000000..4954c17 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-condition_wait.c @@ -0,0 +1,80 @@ +#include "test-thread.h" +#include "test-thread-condition_wait.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_condition_wait__fails(void **state) { + + f_thread_condition_t condition = f_thread_condition_t_initialize; + f_thread_mutex_t mutex = f_thread_mutex_t_initialize; + + int errnos[] = { + EINVAL, + ENOTRECOVERABLE, + EOWNERDEAD, + EPERM, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_parameter, + F_recover_not, + F_dead, + F_prohibited, + F_failure, + }; + + for (uint8_t i = 0; i < 5; ++i) { + + will_return(__wrap_pthread_cond_wait, true); + will_return(__wrap_pthread_cond_wait, errnos[i]); + + const f_status_t status = f_thread_condition_wait(&condition, &mutex); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_condition_wait__parameter_checking(void **state) { + + f_thread_condition_t condition = f_thread_condition_t_initialize; + f_thread_mutex_t mutex = f_thread_mutex_t_initialize; + + { + const f_status_t status = f_thread_condition_wait(0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_condition_wait(0, &mutex); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_condition_wait(&condition, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_condition_wait__works(void **state) { + + f_thread_condition_t condition = f_thread_condition_t_initialize; + f_thread_mutex_t mutex = f_thread_mutex_t_initialize; + + { + will_return(__wrap_pthread_cond_wait, false); + + const f_status_t status = f_thread_condition_wait(&condition, &mutex); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-condition_wait.h b/level_0/f_thread/tests/unit/c/test-thread-condition_wait.h new file mode 100644 index 0000000..2135499 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-condition_wait.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__condition_wait_h +#define _TEST__F_thread__condition_wait_h + +/** + * Test that function fails. + * + * @see f_thread_condition_wait() + */ +extern void test__f_thread_condition_wait__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_condition_wait() + */ +extern void test__f_thread_condition_wait__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_condition_wait() + */ +extern void test__f_thread_condition_wait__works(void **state); + +#endif // _TEST__F_thread__condition_wait_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-condition_wait_timed.c b/level_0/f_thread/tests/unit/c/test-thread-condition_wait_timed.c new file mode 100644 index 0000000..731093d --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-condition_wait_timed.c @@ -0,0 +1,91 @@ +#include "test-thread.h" +#include "test-thread-condition_wait_timed.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_condition_wait_timed__fails(void **state) { + + struct timespec wait; + f_thread_condition_t condition = f_thread_condition_t_initialize; + f_thread_mutex_t mutex = f_thread_mutex_t_initialize; + + memset(&wait, 0, sizeof(struct timespec)); + + int errnos[] = { + EINVAL, + ENOTRECOVERABLE, + EOWNERDEAD, + EPERM, + ETIMEDOUT, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_status_set_error(F_parameter), + F_status_set_error(F_recover_not), + F_status_set_error(F_dead), + F_status_set_error(F_prohibited), + F_time, + F_status_set_error(F_failure), + }; + + for (uint8_t i = 0; i < 6; ++i) { + + will_return(__wrap_pthread_cond_timedwait, true); + will_return(__wrap_pthread_cond_timedwait, errnos[i]); + + const f_status_t status = f_thread_condition_wait_timed(&wait, &condition, &mutex); + + assert_int_equal(status, statuss[i]); + } // for +} + +void test__f_thread_condition_wait_timed__parameter_checking(void **state) { + + struct timespec wait; + f_thread_condition_t condition = f_thread_condition_t_initialize; + f_thread_mutex_t mutex = f_thread_mutex_t_initialize; + + memset(&wait, 0, sizeof(struct timespec)); + + { + const f_status_t status = f_thread_condition_wait_timed(&wait, 0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_condition_wait_timed(&wait, &condition, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_condition_wait_timed(&wait, 0, &mutex); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_condition_wait_timed__works(void **state) { + + struct timespec wait; + f_thread_condition_t condition = f_thread_condition_t_initialize; + f_thread_mutex_t mutex = f_thread_mutex_t_initialize; + + memset(&wait, 0, sizeof(struct timespec)); + + { + will_return(__wrap_pthread_cond_timedwait, false); + + const f_status_t status = f_thread_condition_wait_timed(&wait, &condition, &mutex); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-condition_wait_timed.h b/level_0/f_thread/tests/unit/c/test-thread-condition_wait_timed.h new file mode 100644 index 0000000..5e545ad --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-condition_wait_timed.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__condition_wait_timed_h +#define _TEST__F_thread__condition_wait_timed_h + +/** + * Test that function fails. + * + * @see f_thread_condition_wait_timed() + */ +extern void test__f_thread_condition_wait_timed__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_condition_wait_timed() + */ +extern void test__f_thread_condition_wait_timed__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_condition_wait_timed() + */ +extern void test__f_thread_condition_wait_timed__works(void **state); + +#endif // _TEST__F_thread__condition_wait_timed_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-conditions_decimate_by.c b/level_0/f_thread/tests/unit/c/test-thread-conditions_decimate_by.c index 2a19c3b..3b16379 100644 --- a/level_0/f_thread/tests/unit/c/test-thread-conditions_decimate_by.c +++ b/level_0/f_thread/tests/unit/c/test-thread-conditions_decimate_by.c @@ -59,6 +59,10 @@ void test__f_thread_conditions_decimate_by__works(void **state) { } { + for (uint8_t i = 0; i < length; ++i) { + will_return(__wrap_pthread_cond_destroy, false); + } // for + const f_status_t status = f_thread_conditions_decimate_by(length, &data); assert_int_equal(status, F_none); diff --git a/level_0/f_thread/tests/unit/c/test-thread-conditions_decrease_by.c b/level_0/f_thread/tests/unit/c/test-thread-conditions_decrease_by.c index 5351022..dca2d1d 100644 --- a/level_0/f_thread/tests/unit/c/test-thread-conditions_decrease_by.c +++ b/level_0/f_thread/tests/unit/c/test-thread-conditions_decrease_by.c @@ -59,6 +59,10 @@ void test__f_thread_conditions_decrease_by__works(void **state) { } { + for (uint8_t i = 0; i < length; ++i) { + will_return(__wrap_pthread_cond_destroy, false); + } // for + const f_status_t status = f_thread_conditions_decrease_by(length, &data); assert_int_equal(status, F_none); diff --git a/level_0/f_thread/tests/unit/c/test-thread-create.c b/level_0/f_thread/tests/unit/c/test-thread-create.c new file mode 100644 index 0000000..f772a24 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-create.c @@ -0,0 +1,80 @@ +#include "test-thread.h" +#include "test-thread-create.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_create__fails(void **state) { + + f_thread_attribute_t attribute = f_thread_attribute_t_initialize; + f_thread_id_t id = f_thread_id_t_initialize; + int argument = 0; + + int errnos[] = { + EAGAIN, + EINVAL, + EPERM, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_resource_not, + F_parameter, + F_prohibited, + F_failure, + }; + + for (uint8_t i = 0; i < 4; ++i) { + + will_return(__wrap_pthread_create, true); + will_return(__wrap_pthread_create, errnos[i]); + + const f_status_t status = f_thread_create(&attribute, &id, stub_callback, &argument); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_create__parameter_checking(void **state) { + + f_thread_attribute_t attribute = f_thread_attribute_t_initialize; + f_thread_id_t id = f_thread_id_t_initialize; + + { + const f_status_t status = f_thread_create(&attribute, 0, 0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_create(&attribute, &id, 0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_create(&attribute, 0, stub_callback, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_create__works(void **state) { + + f_thread_attribute_t attribute = f_thread_attribute_t_initialize; + f_thread_id_t id = f_thread_id_t_initialize; + int argument = 0; + + { + will_return(__wrap_pthread_create, false); + + const f_status_t status = f_thread_create(&attribute, &id, stub_callback, &argument); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-create.h b/level_0/f_thread/tests/unit/c/test-thread-create.h new file mode 100644 index 0000000..19b4ed2 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-create.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__create_h +#define _TEST__F_thread__create_h + +/** + * Test that function fails. + * + * @see f_thread_create() + */ +extern void test__f_thread_create__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_create() + */ +extern void test__f_thread_create__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_create() + */ +extern void test__f_thread_create__works(void **state); + +#endif // _TEST__F_thread__create_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-detach.c b/level_0/f_thread/tests/unit/c/test-thread-detach.c new file mode 100644 index 0000000..fc67345 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-detach.c @@ -0,0 +1,50 @@ +#include "test-thread.h" +#include "test-thread-detach.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_detach__fails(void **state) { + + f_thread_id_t id = 0; + + int errnos[] = { + EINVAL, + ESRCH, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_parameter, + F_found_not, + F_failure, + }; + + for (uint8_t i = 0; i < 3; ++i) { + + will_return(__wrap_pthread_detach, true); + will_return(__wrap_pthread_detach, errnos[i]); + + const f_status_t status = f_thread_detach(id); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_detach__works(void **state) { + + f_thread_id_t id = 0; + + { + will_return(__wrap_pthread_detach, false); + + const f_status_t status = f_thread_detach(id); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-detach.h b/level_0/f_thread/tests/unit/c/test-thread-detach.h new file mode 100644 index 0000000..e556072 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-detach.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__detach_h +#define _TEST__F_thread__detach_h + +/** + * Test that function fails. + * + * @see f_thread_detach() + */ +extern void test__f_thread_detach__fails(void **state); + +/** + * Test that function works. + * + * @see f_thread_detach() + */ +extern void test__f_thread_detach__works(void **state); + +#endif // _TEST__F_thread__detach_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-exit.c b/level_0/f_thread/tests/unit/c/test-thread-exit.c new file mode 100644 index 0000000..816add8 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-exit.c @@ -0,0 +1,33 @@ +#include "test-thread.h" +#include "test-thread-exit.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_exit__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_exit(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_exit__works(void **state) { + + int result = 0; + + { + will_return(__wrap_pthread_exit, 1); + + const f_status_t status = f_thread_exit(&result); + + assert_int_equal(status, F_none); + assert_int_equal(result, 1); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-exit.h b/level_0/f_thread/tests/unit/c/test-thread-exit.h new file mode 100644 index 0000000..b9004e8 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-exit.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__exit_h +#define _TEST__F_thread__exit_h + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_exit() + */ +extern void test__f_thread_exit__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_exit() + */ +extern void test__f_thread_exit__works(void **state); + +#endif // _TEST__F_thread__exit_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-join.c b/level_0/f_thread/tests/unit/c/test-thread-join.c new file mode 100644 index 0000000..da95ae5 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-join.c @@ -0,0 +1,54 @@ +#include "test-thread.h" +#include "test-thread-join.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_join__fails(void **state) { + + f_thread_id_t id = f_thread_id_t_initialize; + + int errnos[] = { + EDEADLK, + EINVAL, + EPERM, + ESRCH, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_deadlock, + F_parameter, + F_supported_not, + F_found_not, + F_failure, + }; + + for (uint8_t i = 0; i < 5; ++i) { + + will_return(__wrap_pthread_join, true); + will_return(__wrap_pthread_join, errnos[i]); + + const f_status_t status = f_thread_join(id, 0); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_join__works(void **state) { + + f_thread_id_t id = f_thread_id_t_initialize; + + { + will_return(__wrap_pthread_join, false); + + const f_status_t status = f_thread_join(id, 0); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-join.h b/level_0/f_thread/tests/unit/c/test-thread-join.h new file mode 100644 index 0000000..308d737 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-join.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__join_h +#define _TEST__F_thread__join_h + +/** + * Test that function fails. + * + * @see f_thread_join() + */ +extern void test__f_thread_join__fails(void **state); + +/** + * Test that function works. + * + * @see f_thread_join() + */ +extern void test__f_thread_join__works(void **state); + +#endif // _TEST__F_thread__join_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-join_timed.c b/level_0/f_thread/tests/unit/c/test-thread-join_timed.c new file mode 100644 index 0000000..91c23a9 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-join_timed.c @@ -0,0 +1,64 @@ +#include "test-thread.h" +#include "test-thread-join_timed.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_join_timed__fails(void **state) { + + f_thread_id_t id = f_thread_id_t_initialize; + struct timespec wait; + + memset(&wait, 0, sizeof(struct timespec)); + + int errnos[] = { + EBUSY, + EDEADLK, + EINVAL, + EPERM, + ESRCH, + ETIMEDOUT, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_busy, + F_status_set_error(F_deadlock), + F_status_set_error(F_parameter), + F_status_set_error(F_supported_not), + F_status_set_error(F_found_not), + F_time, + F_status_set_error(F_failure), + }; + + for (uint8_t i = 0; i < 7; ++i) { + + will_return(__wrap_pthread_timedjoin_np, true); + will_return(__wrap_pthread_timedjoin_np, errnos[i]); + + const f_status_t status = f_thread_join_timed(id, wait, 0); + + assert_int_equal(status, statuss[i]); + } // for +} + +void test__f_thread_join_timed__works(void **state) { + + f_thread_id_t id = f_thread_id_t_initialize; + struct timespec wait; + + memset(&wait, 0, sizeof(struct timespec)); + + { + will_return(__wrap_pthread_timedjoin_np, false); + + const f_status_t status = f_thread_join_timed(id, wait, 0); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-join_timed.h b/level_0/f_thread/tests/unit/c/test-thread-join_timed.h new file mode 100644 index 0000000..60d0833 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-join_timed.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__join_timed_h +#define _TEST__F_thread__join_timed_h + +/** + * Test that function fails. + * + * @see f_thread_join_timed() + */ +extern void test__f_thread_join_timed__fails(void **state); + +/** + * Test that function works. + * + * @see f_thread_join_timed() + */ +extern void test__f_thread_join_timed__works(void **state); + +#endif // _TEST__F_thread__join_timed_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-join_try.c b/level_0/f_thread/tests/unit/c/test-thread-join_try.c new file mode 100644 index 0000000..9c3a381 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-join_try.c @@ -0,0 +1,56 @@ +#include "test-thread.h" +#include "test-thread-join_try.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_join_try__fails(void **state) { + + f_thread_id_t id = f_thread_id_t_initialize; + + int errnos[] = { + EBUSY, + EDEADLK, + EINVAL, + EPERM, + ESRCH, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_busy, + F_status_set_error(F_deadlock), + F_status_set_error(F_parameter), + F_status_set_error(F_supported_not), + F_status_set_error(F_found_not), + F_status_set_error(F_failure), + }; + + for (uint8_t i = 0; i < 6; ++i) { + + will_return(__wrap_pthread_tryjoin_np, true); + will_return(__wrap_pthread_tryjoin_np, errnos[i]); + + const f_status_t status = f_thread_join_try(id, 0); + + assert_int_equal(status, statuss[i]); + } // for +} + +void test__f_thread_join_try__works(void **state) { + + f_thread_id_t id = f_thread_id_t_initialize; + + { + will_return(__wrap_pthread_tryjoin_np, false); + + const f_status_t status = f_thread_join_try(id, 0); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-join_try.h b/level_0/f_thread/tests/unit/c/test-thread-join_try.h new file mode 100644 index 0000000..90ec9bf --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-join_try.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__join_try_h +#define _TEST__F_thread__join_try_h + +/** + * Test that function fails. + * + * @see f_thread_join_try() + */ +extern void test__f_thread_join_try__fails(void **state); + +/** + * Test that function works. + * + * @see f_thread_join_try() + */ +extern void test__f_thread_join_try__works(void **state); + +#endif // _TEST__F_thread__join_try_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-key_create.c b/level_0/f_thread/tests/unit/c/test-thread-key_create.c new file mode 100644 index 0000000..3fd6afa --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-key_create.c @@ -0,0 +1,73 @@ +#include "test-thread.h" +#include "test-thread-key_create.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_key_create__fails(void **state) { + + f_thread_key_t key = f_thread_key_t_initialize; + + int errnos[] = { + EAGAIN, + ENOMEM, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_resource_not, + F_memory_not, + F_failure, + }; + + for (uint8_t i = 0; i < 3; ++i) { + + will_return(__wrap_pthread_key_create, true); + will_return(__wrap_pthread_key_create, errnos[i]); + + const f_status_t status = f_thread_key_create(stub_other, &key); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_key_create__parameter_checking(void **state) { + + f_thread_key_t key = f_thread_key_t_initialize; + + { + const f_status_t status = f_thread_key_create(0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_key_create(stub_other, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_key_create(0, &key); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_key_create__works(void **state) { + + f_thread_key_t key = f_thread_key_t_initialize; + + { + will_return(__wrap_pthread_key_create, false); + + const f_status_t status = f_thread_key_create(stub_other, &key); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-key_create.h b/level_0/f_thread/tests/unit/c/test-thread-key_create.h new file mode 100644 index 0000000..6de0c36 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-key_create.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__key_create_h +#define _TEST__F_thread__key_create_h + +/** + * Test that function fails. + * + * @see f_thread_key_create() + */ +extern void test__f_thread_key_create__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_key_create() + */ +extern void test__f_thread_key_create__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_key_create() + */ +extern void test__f_thread_key_create__works(void **state); + +#endif // _TEST__F_thread__key_create_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-key_delete.c b/level_0/f_thread/tests/unit/c/test-thread-key_delete.c new file mode 100644 index 0000000..beea9d7 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-key_delete.c @@ -0,0 +1,32 @@ +#include "test-thread.h" +#include "test-thread-key_delete.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_key_delete__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_key_delete(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_key_delete__works(void **state) { + + f_thread_key_t key = f_thread_key_t_initialize; + + { + will_return(__wrap_pthread_key_delete, false); + + const f_status_t status = f_thread_key_delete(&key); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-key_delete.h b/level_0/f_thread/tests/unit/c/test-thread-key_delete.h new file mode 100644 index 0000000..df0a219 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-key_delete.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__key_delete_h +#define _TEST__F_thread__key_delete_h + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_key_delete() + */ +extern void test__f_thread_key_delete__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_key_delete() + */ +extern void test__f_thread_key_delete__works(void **state); + +#endif // _TEST__F_thread__key_delete_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-key_get.c b/level_0/f_thread/tests/unit/c/test-thread-key_get.c new file mode 100644 index 0000000..a0a3eae --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-key_get.c @@ -0,0 +1,38 @@ +#include "test-thread.h" +#include "test-thread-key_get.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_key_get__parameter_checking(void **state) { + + f_thread_key_t key = f_thread_key_t_initialize; + + { + const f_status_t status = f_thread_key_get(key, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_key_get__works(void **state) { + + f_thread_key_t key = f_thread_key_t_initialize; + int value = 0; + int *value_ptr = &value; + int expect = 1; + + { + will_return(__wrap_pthread_getspecific, (void *) &expect); + + const f_status_t status = f_thread_key_get(key, (void *) &value_ptr); + + assert_int_equal(status, F_none); + assert_int_equal(value_ptr, &expect); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-key_get.h b/level_0/f_thread/tests/unit/c/test-thread-key_get.h new file mode 100644 index 0000000..3991c27 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-key_get.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__key_get_h +#define _TEST__F_thread__key_get_h + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_key_get() + */ +extern void test__f_thread_key_get__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_key_get() + */ +extern void test__f_thread_key_get__works(void **state); + +#endif // _TEST__F_thread__key_get_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-key_set.c b/level_0/f_thread/tests/unit/c/test-thread-key_set.c new file mode 100644 index 0000000..b296711 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-key_set.c @@ -0,0 +1,61 @@ +#include "test-thread.h" +#include "test-thread-key_set.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_key_set__fails(void **state) { + + f_thread_key_t key = f_thread_key_t_initialize; + int value = 0; + + int errnos[] = { + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 2; ++i) { + + will_return(__wrap_pthread_setspecific, true); + will_return(__wrap_pthread_setspecific, errnos[i]); + + const f_status_t status = f_thread_key_set(key, &value); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_key_set__parameter_checking(void **state) { + + f_thread_key_t key = f_thread_key_t_initialize; + + { + const f_status_t status = f_thread_key_set(key, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_key_set__works(void **state) { + + f_thread_key_t key = f_thread_key_t_initialize; + int value = 0; + + { + will_return(__wrap_pthread_setspecific, false); + + const f_status_t status = f_thread_key_set(key, &value); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-key_set.h b/level_0/f_thread/tests/unit/c/test-thread-key_set.h new file mode 100644 index 0000000..1b07a3c --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-key_set.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__key_set_h +#define _TEST__F_thread__key_set_h + +/** + * Test that function fails. + * + * @see f_thread_key_set() + */ +extern void test__f_thread_key_set__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_key_set() + */ +extern void test__f_thread_key_set__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_key_set() + */ +extern void test__f_thread_key_set__works(void **state); + +#endif // _TEST__F_thread__key_set_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-lock_attribute_create.c b/level_0/f_thread/tests/unit/c/test-thread-lock_attribute_create.c new file mode 100644 index 0000000..f13b149 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-lock_attribute_create.c @@ -0,0 +1,65 @@ +#include "test-thread.h" +#include "test-thread-lock_attribute_create.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_lock_attribute_create__fails(void **state) { + + f_thread_lock_attribute_t attribute = f_thread_lock_attribute_t_initialize; + + int errnos[] = { + EAGAIN, + EBUSY, + EINVAL, + ENOMEM, + EPERM, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_resource_not, + F_busy, + F_parameter, + F_memory_not, + F_prohibited, + F_failure, + }; + + for (uint8_t i = 0; i < 6; ++i) { + + will_return(__wrap_pthread_rwlockattr_init, true); + will_return(__wrap_pthread_rwlockattr_init, errnos[i]); + + const f_status_t status = f_thread_lock_attribute_create(&attribute); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_lock_attribute_create__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_lock_attribute_create(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_lock_attribute_create__works(void **state) { + + f_thread_lock_attribute_t attribute = f_thread_lock_attribute_t_initialize; + + { + will_return(__wrap_pthread_rwlockattr_init, false); + + const f_status_t status = f_thread_lock_attribute_create(&attribute); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-lock_attribute_create.h b/level_0/f_thread/tests/unit/c/test-thread-lock_attribute_create.h new file mode 100644 index 0000000..6640415 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-lock_attribute_create.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__lock_attribute_create_h +#define _TEST__F_thread__lock_attribute_create_h + +/** + * Test that function fails. + * + * @see f_thread_lock_attribute_create() + */ +extern void test__f_thread_lock_attribute_create__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_lock_attribute_create() + */ +extern void test__f_thread_lock_attribute_create__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_lock_attribute_create() + */ +extern void test__f_thread_lock_attribute_create__works(void **state); + +#endif // _TEST__F_thread__lock_attribute_create_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-lock_attribute_delete.c b/level_0/f_thread/tests/unit/c/test-thread-lock_attribute_delete.c new file mode 100644 index 0000000..907a5d1 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-lock_attribute_delete.c @@ -0,0 +1,59 @@ +#include "test-thread.h" +#include "test-thread-lock_attribute_delete.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_lock_attribute_delete__fails(void **state) { + + f_thread_lock_attribute_t attribute = f_thread_lock_attribute_t_initialize; + + int errnos[] = { + EBUSY, + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_busy, + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 3; ++i) { + + will_return(__wrap_pthread_rwlockattr_destroy, true); + will_return(__wrap_pthread_rwlockattr_destroy, errnos[i]); + + const f_status_t status = f_thread_lock_attribute_delete(&attribute); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_lock_attribute_delete__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_lock_attribute_delete(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_lock_attribute_delete__works(void **state) { + + f_thread_lock_attribute_t attribute = f_thread_lock_attribute_t_initialize; + + { + will_return(__wrap_pthread_rwlockattr_destroy, false); + + const f_status_t status = f_thread_lock_attribute_delete(&attribute); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-lock_attribute_delete.h b/level_0/f_thread/tests/unit/c/test-thread-lock_attribute_delete.h new file mode 100644 index 0000000..c7c47de --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-lock_attribute_delete.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__lock_attribute_delete_h +#define _TEST__F_thread__lock_attribute_delete_h + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_lock_attribute_delete() + */ +extern void test__f_thread_lock_attribute_delete__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_lock_attribute_delete() + */ +extern void test__f_thread_lock_attribute_delete__works(void **state); + +#endif // _TEST__F_thread__lock_attribute_delete_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-lock_attribute_shared_get.c b/level_0/f_thread/tests/unit/c/test-thread-lock_attribute_shared_get.c new file mode 100644 index 0000000..60c69db --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-lock_attribute_shared_get.c @@ -0,0 +1,72 @@ +#include "test-thread.h" +#include "test-thread-lock_attribute_shared_get.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_lock_attribute_shared_get__fails(void **state) { + + f_thread_lock_attribute_t attribute = f_thread_lock_attribute_t_initialize; + int shared = 0; + + int errnos[] = { + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_failure, + }; + + for (uint8_t i = 0; i < 1; ++i) { + + will_return(__wrap_pthread_rwlockattr_getpshared, true); + will_return(__wrap_pthread_rwlockattr_getpshared, errnos[i]); + + const f_status_t status = f_thread_lock_attribute_shared_get(&attribute, &shared); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_lock_attribute_shared_get__parameter_checking(void **state) { + + f_thread_lock_attribute_t attribute = f_thread_lock_attribute_t_initialize; + int shared = 0; + + { + const f_status_t status = f_thread_lock_attribute_shared_get(0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_lock_attribute_shared_get(&attribute, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_lock_attribute_shared_get(0, &shared); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_lock_attribute_shared_get__works(void **state) { + + f_thread_lock_attribute_t attribute = f_thread_lock_attribute_t_initialize; + int shared = 0; + + { + will_return(__wrap_pthread_rwlockattr_getpshared, false); + + const f_status_t status = f_thread_lock_attribute_shared_get(&attribute, &shared); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-lock_attribute_shared_get.h b/level_0/f_thread/tests/unit/c/test-thread-lock_attribute_shared_get.h new file mode 100644 index 0000000..c477eef --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-lock_attribute_shared_get.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__lock_attribute_shared_get_h +#define _TEST__F_thread__lock_attribute_shared_get_h + +/** + * Test that function fails. + * + * @see f_thread_lock_attribute_shared_get() + */ +extern void test__f_thread_lock_attribute_shared_get__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_lock_attribute_shared_get() + */ +extern void test__f_thread_lock_attribute_shared_get__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_lock_attribute_shared_get() + */ +extern void test__f_thread_lock_attribute_shared_get__works(void **state); + +#endif // _TEST__F_thread__lock_attribute_shared_get_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-lock_attribute_shared_set.c b/level_0/f_thread/tests/unit/c/test-thread-lock_attribute_shared_set.c new file mode 100644 index 0000000..eca0eaa --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-lock_attribute_shared_set.c @@ -0,0 +1,61 @@ +#include "test-thread.h" +#include "test-thread-lock_attribute_shared_set.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_lock_attribute_shared_set__fails(void **state) { + + f_thread_lock_attribute_t attribute = f_thread_lock_attribute_t_initialize; + int shared = 0; + + int errnos[] = { + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 2; ++i) { + + will_return(__wrap_pthread_rwlockattr_setpshared, true); + will_return(__wrap_pthread_rwlockattr_setpshared, errnos[i]); + + const f_status_t status = f_thread_lock_attribute_shared_set(shared, &attribute); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_lock_attribute_shared_set__parameter_checking(void **state) { + + int shared = 0; + + { + const f_status_t status = f_thread_lock_attribute_shared_set(shared, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_lock_attribute_shared_set__works(void **state) { + + f_thread_lock_attribute_t attribute = f_thread_lock_attribute_t_initialize; + int shared = 0; + + { + will_return(__wrap_pthread_rwlockattr_setpshared, false); + + const f_status_t status = f_thread_lock_attribute_shared_set(shared, &attribute); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-lock_attribute_shared_set.h b/level_0/f_thread/tests/unit/c/test-thread-lock_attribute_shared_set.h new file mode 100644 index 0000000..03f4ac0 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-lock_attribute_shared_set.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__lock_attribute_shared_set_h +#define _TEST__F_thread__lock_attribute_shared_set_h + +/** + * Test that function fails. + * + * @see f_thread_lock_attribute_shared_set() + */ +extern void test__f_thread_lock_attribute_shared_set__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_lock_attribute_shared_set() + */ +extern void test__f_thread_lock_attribute_shared_set__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_lock_attribute_shared_set() + */ +extern void test__f_thread_lock_attribute_shared_set__works(void **state); + +#endif // _TEST__F_thread__lock_attribute_shared_set_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-lock_attributes_decimate_by.c b/level_0/f_thread/tests/unit/c/test-thread-lock_attributes_decimate_by.c index 2f55aef..1c5330f 100644 --- a/level_0/f_thread/tests/unit/c/test-thread-lock_attributes_decimate_by.c +++ b/level_0/f_thread/tests/unit/c/test-thread-lock_attributes_decimate_by.c @@ -59,6 +59,10 @@ void test__f_thread_lock_attributes_decimate_by__works(void **state) { } { + for (uint8_t i = 0; i < length; ++i) { + will_return(__wrap_pthread_rwlockattr_destroy, false); + } // for + const f_status_t status = f_thread_lock_attributes_decimate_by(length, &data); assert_int_equal(status, F_none); diff --git a/level_0/f_thread/tests/unit/c/test-thread-lock_attributes_decrease_by.c b/level_0/f_thread/tests/unit/c/test-thread-lock_attributes_decrease_by.c index 0f67eb0..0ab8f5a 100644 --- a/level_0/f_thread/tests/unit/c/test-thread-lock_attributes_decrease_by.c +++ b/level_0/f_thread/tests/unit/c/test-thread-lock_attributes_decrease_by.c @@ -59,6 +59,10 @@ void test__f_thread_lock_attributes_decrease_by__works(void **state) { } { + for (uint8_t i = 0; i < length; ++i) { + will_return(__wrap_pthread_rwlockattr_destroy, false); + } // for + const f_status_t status = f_thread_lock_attributes_decrease_by(length, &data); assert_int_equal(status, F_none); diff --git a/level_0/f_thread/tests/unit/c/test-thread-lock_create.c b/level_0/f_thread/tests/unit/c/test-thread-lock_create.c new file mode 100644 index 0000000..bc1eb59 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-lock_create.c @@ -0,0 +1,63 @@ +#include "test-thread.h" +#include "test-thread-lock_create.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_lock_create__fails(void **state) { + + f_thread_lock_attribute_t attribute = f_thread_lock_attribute_t_initialize; + f_thread_lock_t lock = f_thread_lock_t_initialize; + + int errnos[] = { + EAGAIN, + ENOMEM, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_resource_not, + F_memory_not, + F_failure, + }; + + for (uint8_t i = 0; i < 3; ++i) { + + will_return(__wrap_pthread_rwlock_init, true); + will_return(__wrap_pthread_rwlock_init, errnos[i]); + + const f_status_t status = f_thread_lock_create(&attribute, &lock); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_lock_create__parameter_checking(void **state) { + + f_thread_lock_attribute_t attribute = f_thread_lock_attribute_t_initialize; + + { + const f_status_t status = f_thread_lock_create(&attribute, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_lock_create__works(void **state) { + + f_thread_lock_attribute_t attribute = f_thread_lock_attribute_t_initialize; + f_thread_lock_t lock = f_thread_lock_t_initialize; + + { + will_return(__wrap_pthread_rwlock_init, false); + + const f_status_t status = f_thread_lock_create(&attribute, &lock); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-lock_create.h b/level_0/f_thread/tests/unit/c/test-thread-lock_create.h new file mode 100644 index 0000000..8e32648 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-lock_create.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__lock_create_h +#define _TEST__F_thread__lock_create_h + +/** + * Test that function fails. + * + * @see f_thread_lock_create() + */ +extern void test__f_thread_lock_create__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_lock_create() + */ +extern void test__f_thread_lock_create__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_lock_create() + */ +extern void test__f_thread_lock_create__works(void **state); + +#endif // _TEST__F_thread__lock_create_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-lock_delete.c b/level_0/f_thread/tests/unit/c/test-thread-lock_delete.c new file mode 100644 index 0000000..55c4ba3 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-lock_delete.c @@ -0,0 +1,59 @@ +#include "test-thread.h" +#include "test-thread-lock_delete.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_lock_delete__fails(void **state) { + + f_thread_lock_t lock = f_thread_lock_t_initialize; + + int errnos[] = { + EBUSY, + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_busy, + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 3; ++i) { + + will_return(__wrap_pthread_rwlock_destroy, true); + will_return(__wrap_pthread_rwlock_destroy, errnos[i]); + + const f_status_t status = f_thread_lock_delete(&lock); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_lock_delete__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_lock_delete(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_lock_delete__works(void **state) { + + f_thread_lock_t lock = f_thread_lock_t_initialize; + + { + will_return(__wrap_pthread_rwlock_destroy, false); + + const f_status_t status = f_thread_lock_delete(&lock); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-lock_delete.h b/level_0/f_thread/tests/unit/c/test-thread-lock_delete.h new file mode 100644 index 0000000..e8e16a9 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-lock_delete.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__lock_delete_h +#define _TEST__F_thread__lock_delete_h + +/** + * Test that function fails. + * + * @see f_thread_lock_delete() + */ +extern void test__f_thread_lock_delete__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_lock_delete() + */ +extern void test__f_thread_lock_delete__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_lock_delete() + */ +extern void test__f_thread_lock_delete__works(void **state); + +#endif // _TEST__F_thread__lock_delete_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-lock_read.c b/level_0/f_thread/tests/unit/c/test-thread-lock_read.c new file mode 100644 index 0000000..211de69 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-lock_read.c @@ -0,0 +1,61 @@ +#include "test-thread.h" +#include "test-thread-lock_read.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_lock_read__fails(void **state) { + + f_thread_lock_t lock = f_thread_lock_t_initialize; + + int errnos[] = { + EAGAIN, + EDEADLK, + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_resource_not, + F_deadlock, + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 4; ++i) { + + will_return(__wrap_pthread_rwlock_rdlock, true); + will_return(__wrap_pthread_rwlock_rdlock, errnos[i]); + + const f_status_t status = f_thread_lock_read(&lock); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_lock_read__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_lock_read(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_lock_read__works(void **state) { + + f_thread_lock_t lock = f_thread_lock_t_initialize; + + { + will_return(__wrap_pthread_rwlock_rdlock, false); + + const f_status_t status = f_thread_lock_read(&lock); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-lock_read.h b/level_0/f_thread/tests/unit/c/test-thread-lock_read.h new file mode 100644 index 0000000..0392681 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-lock_read.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__lock_read_h +#define _TEST__F_thread__lock_read_h + +/** + * Test that function fails. + * + * @see f_thread_lock_read() + */ +extern void test__f_thread_lock_read__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_lock_read() + */ +extern void test__f_thread_lock_read__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_lock_read() + */ +extern void test__f_thread_lock_read__works(void **state); + +#endif // _TEST__F_thread__lock_read_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-lock_read_timed.c b/level_0/f_thread/tests/unit/c/test-thread-lock_read_timed.c new file mode 100644 index 0000000..0f9c046 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-lock_read_timed.c @@ -0,0 +1,86 @@ +#include "test-thread.h" +#include "test-thread-lock_read_timed.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_lock_read_timed__fails(void **state) { + + f_thread_lock_t lock = f_thread_lock_t_initialize; + struct timespec timeout; + + memset(&timeout, 0, sizeof(struct timespec)); + + int errnos[] = { + EAGAIN, + EDEADLK, + EINVAL, + ETIMEDOUT, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_status_set_error(F_resource_not), + F_status_set_error(F_deadlock), + F_status_set_error(F_parameter), + F_time, + F_status_set_error(F_failure), + }; + + for (uint8_t i = 0; i < 5; ++i) { + + will_return(__wrap_pthread_rwlock_timedrdlock, true); + will_return(__wrap_pthread_rwlock_timedrdlock, errnos[i]); + + const f_status_t status = f_thread_lock_read_timed(&timeout, &lock); + + assert_int_equal(status, statuss[i]); + } // for +} + +void test__f_thread_lock_read_timed__parameter_checking(void **state) { + + f_thread_lock_t lock = f_thread_lock_t_initialize; + struct timespec timeout; + + memset(&timeout, 0, sizeof(struct timespec)); + + { + const f_status_t status = f_thread_lock_read_timed(0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_lock_read_timed(&timeout, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_lock_read_timed(0, &lock); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_lock_read_timed__works(void **state) { + + f_thread_lock_t lock = f_thread_lock_t_initialize; + struct timespec timeout; + + memset(&timeout, 0, sizeof(struct timespec)); + + { + will_return(__wrap_pthread_rwlock_timedrdlock, false); + + const f_status_t status = f_thread_lock_read_timed(&timeout, &lock); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-lock_read_timed.h b/level_0/f_thread/tests/unit/c/test-thread-lock_read_timed.h new file mode 100644 index 0000000..9916bdf --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-lock_read_timed.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__lock_read_timed_h +#define _TEST__F_thread__lock_read_timed_h + +/** + * Test that function fails. + * + * @see f_thread_lock_read_timed() + */ +extern void test__f_thread_lock_read_timed__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_lock_read_timed() + */ +extern void test__f_thread_lock_read_timed__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_lock_read_timed() + */ +extern void test__f_thread_lock_read_timed__works(void **state); + +#endif // _TEST__F_thread__lock_read_timed_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-lock_read_try.c b/level_0/f_thread/tests/unit/c/test-thread-lock_read_try.c new file mode 100644 index 0000000..4829fa4 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-lock_read_try.c @@ -0,0 +1,61 @@ +#include "test-thread.h" +#include "test-thread-lock_read_try.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_lock_read_try__fails(void **state) { + + f_thread_lock_t lock = f_thread_lock_t_initialize; + + int errnos[] = { + EAGAIN, + EBUSY, + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_status_set_error(F_resource_not), + F_busy, + F_status_set_error(F_parameter), + F_status_set_error(F_failure), + }; + + for (uint8_t i = 0; i < 4; ++i) { + + will_return(__wrap_pthread_rwlock_tryrdlock, true); + will_return(__wrap_pthread_rwlock_tryrdlock, errnos[i]); + + const f_status_t status = f_thread_lock_read_try(&lock); + + assert_int_equal(status, statuss[i]); + } // for +} + +void test__f_thread_lock_read_try__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_lock_read_try(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_lock_read_try__works(void **state) { + + f_thread_lock_t lock = f_thread_lock_t_initialize; + + { + will_return(__wrap_pthread_rwlock_tryrdlock, false); + + const f_status_t status = f_thread_lock_read_try(&lock); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-lock_read_try.h b/level_0/f_thread/tests/unit/c/test-thread-lock_read_try.h new file mode 100644 index 0000000..9e4ebd8 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-lock_read_try.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__lock_read_try_h +#define _TEST__F_thread__lock_read_try_h + +/** + * Test that function fails. + * + * @see f_thread_lock_read_try() + */ +extern void test__f_thread_lock_read_try__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_lock_read_try() + */ +extern void test__f_thread_lock_read_try__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_lock_read_try() + */ +extern void test__f_thread_lock_read_try__works(void **state); + +#endif // _TEST__F_thread__lock_read_try_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-lock_write.c b/level_0/f_thread/tests/unit/c/test-thread-lock_write.c new file mode 100644 index 0000000..4668fa8 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-lock_write.c @@ -0,0 +1,61 @@ +#include "test-thread.h" +#include "test-thread-lock_write.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_lock_write__fails(void **state) { + + f_thread_lock_t lock = f_thread_lock_t_initialize; + + int errnos[] = { + EAGAIN, + EDEADLK, + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_resource_not, + F_deadlock, + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 4; ++i) { + + will_return(__wrap_pthread_rwlock_wrlock, true); + will_return(__wrap_pthread_rwlock_wrlock, errnos[i]); + + const f_status_t status = f_thread_lock_write(&lock); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_lock_write__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_lock_write(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_lock_write__works(void **state) { + + f_thread_lock_t lock = f_thread_lock_t_initialize; + + { + will_return(__wrap_pthread_rwlock_wrlock, false); + + const f_status_t status = f_thread_lock_write(&lock); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-lock_write.h b/level_0/f_thread/tests/unit/c/test-thread-lock_write.h new file mode 100644 index 0000000..2cecbea --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-lock_write.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__lock_write_h +#define _TEST__F_thread__lock_write_h + +/** + * Test that function fails. + * + * @see f_thread_lock_write() + */ +extern void test__f_thread_lock_write__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_lock_write() + */ +extern void test__f_thread_lock_write__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_lock_write() + */ +extern void test__f_thread_lock_write__works(void **state); + +#endif // _TEST__F_thread__lock_write_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-lock_write_timed.c b/level_0/f_thread/tests/unit/c/test-thread-lock_write_timed.c new file mode 100644 index 0000000..11cf5db --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-lock_write_timed.c @@ -0,0 +1,84 @@ +#include "test-thread.h" +#include "test-thread-lock_write_timed.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_lock_write_timed__fails(void **state) { + + f_thread_lock_t lock = f_thread_lock_t_initialize; + struct timespec timeout; + + memset(&timeout, 0, sizeof(struct timespec)); + + int errnos[] = { + EDEADLK, + EINVAL, + ETIMEDOUT, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_status_set_error(F_deadlock), + F_status_set_error(F_parameter), + F_time, + F_status_set_error(F_failure), + }; + + for (uint8_t i = 0; i < 4; ++i) { + + will_return(__wrap_pthread_rwlock_timedwrlock, true); + will_return(__wrap_pthread_rwlock_timedwrlock, errnos[i]); + + const f_status_t status = f_thread_lock_write_timed(&timeout, &lock); + + assert_int_equal(status, statuss[i]); + } // for +} + +void test__f_thread_lock_write_timed__parameter_checking(void **state) { + + f_thread_lock_t lock = f_thread_lock_t_initialize; + struct timespec timeout; + + memset(&timeout, 0, sizeof(struct timespec)); + + { + const f_status_t status = f_thread_lock_write_timed(0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_lock_write_timed(&timeout, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_lock_write_timed(0, &lock); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_lock_write_timed__works(void **state) { + + f_thread_lock_t lock = f_thread_lock_t_initialize; + struct timespec timeout; + + memset(&timeout, 0, sizeof(struct timespec)); + + { + will_return(__wrap_pthread_rwlock_timedwrlock, false); + + const f_status_t status = f_thread_lock_write_timed(&timeout, &lock); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-lock_write_timed.h b/level_0/f_thread/tests/unit/c/test-thread-lock_write_timed.h new file mode 100644 index 0000000..b4a1da0 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-lock_write_timed.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__lock_write_timed_h +#define _TEST__F_thread__lock_write_timed_h + +/** + * Test that function fails. + * + * @see f_thread_lock_write_timed() + */ +extern void test__f_thread_lock_write_timed__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_lock_write_timed() + */ +extern void test__f_thread_lock_write_timed__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_lock_write_timed() + */ +extern void test__f_thread_lock_write_timed__works(void **state); + +#endif // _TEST__F_thread__lock_write_timed_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-lock_write_try.c b/level_0/f_thread/tests/unit/c/test-thread-lock_write_try.c new file mode 100644 index 0000000..8b43f1f --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-lock_write_try.c @@ -0,0 +1,61 @@ +#include "test-thread.h" +#include "test-thread-lock_write_try.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_lock_write_try__fails(void **state) { + + f_thread_lock_t lock = f_thread_lock_t_initialize; + + int errnos[] = { + EAGAIN, + EBUSY, + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_status_set_error(F_resource_not), + F_busy, + F_status_set_error(F_parameter), + F_status_set_error(F_failure), + }; + + for (uint8_t i = 0; i < 4; ++i) { + + will_return(__wrap_pthread_rwlock_trywrlock, true); + will_return(__wrap_pthread_rwlock_trywrlock, errnos[i]); + + const f_status_t status = f_thread_lock_write_try(&lock); + + assert_int_equal(status, statuss[i]); + } // for +} + +void test__f_thread_lock_write_try__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_lock_write_try(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_lock_write_try__works(void **state) { + + f_thread_lock_t lock = f_thread_lock_t_initialize; + + { + will_return(__wrap_pthread_rwlock_trywrlock, false); + + const f_status_t status = f_thread_lock_write_try(&lock); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-lock_write_try.h b/level_0/f_thread/tests/unit/c/test-thread-lock_write_try.h new file mode 100644 index 0000000..6f22790 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-lock_write_try.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__lock_write_try_h +#define _TEST__F_thread__lock_write_try_h + +/** + * Test that function fails. + * + * @see f_thread_lock_write_try() + */ +extern void test__f_thread_lock_write_try__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_lock_write_try() + */ +extern void test__f_thread_lock_write_try__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_lock_write_try() + */ +extern void test__f_thread_lock_write_try__works(void **state); + +#endif // _TEST__F_thread__lock_write_try_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-locks_decimate_by.c b/level_0/f_thread/tests/unit/c/test-thread-locks_decimate_by.c index 77df7c1..56423a4 100644 --- a/level_0/f_thread/tests/unit/c/test-thread-locks_decimate_by.c +++ b/level_0/f_thread/tests/unit/c/test-thread-locks_decimate_by.c @@ -59,6 +59,10 @@ void test__f_thread_locks_decimate_by__works(void **state) { } { + for (uint8_t i = 0; i < length; ++i) { + will_return(__wrap_pthread_rwlock_destroy, false); + } // for + const f_status_t status = f_thread_locks_decimate_by(length, &data); assert_int_equal(status, F_none); diff --git a/level_0/f_thread/tests/unit/c/test-thread-locks_decrease_by.c b/level_0/f_thread/tests/unit/c/test-thread-locks_decrease_by.c index de5f11a..c64948d 100644 --- a/level_0/f_thread/tests/unit/c/test-thread-locks_decrease_by.c +++ b/level_0/f_thread/tests/unit/c/test-thread-locks_decrease_by.c @@ -59,6 +59,10 @@ void test__f_thread_locks_decrease_by__works(void **state) { } { + for (uint8_t i = 0; i < length; ++i) { + will_return(__wrap_pthread_rwlock_destroy, false); + } // for + const f_status_t status = f_thread_locks_decrease_by(length, &data); assert_int_equal(status, F_none); diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_create.c b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_create.c new file mode 100644 index 0000000..d832377 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_create.c @@ -0,0 +1,65 @@ +#include "test-thread.h" +#include "test-thread-mutex_attribute_create.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_mutex_attribute_create__fails(void **state) { + + f_thread_mutex_attribute_t attribute = f_thread_mutex_attribute_t_initialize; + + int errnos[] = { + EAGAIN, + EBUSY, + EINVAL, + ENOMEM, + EPERM, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_resource_not, + F_busy, + F_parameter, + F_memory_not, + F_prohibited, + F_failure, + }; + + for (uint8_t i = 0; i < 6; ++i) { + + will_return(__wrap_pthread_mutexattr_init, true); + will_return(__wrap_pthread_mutexattr_init, errnos[i]); + + const f_status_t status = f_thread_mutex_attribute_create(&attribute); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_mutex_attribute_create__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_mutex_attribute_create(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_mutex_attribute_create__works(void **state) { + + f_thread_mutex_attribute_t attribute = f_thread_mutex_attribute_t_initialize; + + { + will_return(__wrap_pthread_mutexattr_init, false); + + const f_status_t status = f_thread_mutex_attribute_create(&attribute); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_create.h b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_create.h new file mode 100644 index 0000000..a6a0ed4 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_create.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__mutex_attribute_create_h +#define _TEST__F_thread__mutex_attribute_create_h + +/** + * Test that function fails. + * + * @see f_thread_mutex_attribute_create() + */ +extern void test__f_thread_mutex_attribute_create__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_mutex_attribute_create() + */ +extern void test__f_thread_mutex_attribute_create__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_mutex_attribute_create() + */ +extern void test__f_thread_mutex_attribute_create__works(void **state); + +#endif // _TEST__F_thread__mutex_attribute_create_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_delete.c b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_delete.c new file mode 100644 index 0000000..4ed537c --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_delete.c @@ -0,0 +1,59 @@ +#include "test-thread.h" +#include "test-thread-mutex_attribute_delete.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_mutex_attribute_delete__fails(void **state) { + + f_thread_mutex_attribute_t attribute = f_thread_mutex_attribute_t_initialize; + + int errnos[] = { + EBUSY, + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_busy, + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 3; ++i) { + + will_return(__wrap_pthread_mutexattr_destroy, true); + will_return(__wrap_pthread_mutexattr_destroy, errnos[i]); + + const f_status_t status = f_thread_mutex_attribute_delete(&attribute); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_mutex_attribute_delete__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_mutex_attribute_delete(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_mutex_attribute_delete__works(void **state) { + + f_thread_mutex_attribute_t attribute = f_thread_mutex_attribute_t_initialize; + + { + will_return(__wrap_pthread_mutexattr_destroy, false); + + const f_status_t status = f_thread_mutex_attribute_delete(&attribute); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_delete.h b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_delete.h new file mode 100644 index 0000000..4b72ff5 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_delete.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__mutex_attribute_delete_h +#define _TEST__F_thread__mutex_attribute_delete_h + +/** + * Test that function fails. + * + * @see f_thread_mutex_attribute_delete() + */ +extern void test__f_thread_mutex_attribute_delete__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_mutex_attribute_delete() + */ +extern void test__f_thread_mutex_attribute_delete__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_mutex_attribute_delete() + */ +extern void test__f_thread_mutex_attribute_delete__works(void **state); + +#endif // _TEST__F_thread__mutex_attribute_delete_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_priority_ceiling_get.c b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_priority_ceiling_get.c new file mode 100644 index 0000000..602eace --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_priority_ceiling_get.c @@ -0,0 +1,76 @@ +#include "test-thread.h" +#include "test-thread-mutex_attribute_priority_ceiling_get.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_mutex_attribute_priority_ceiling_get__fails(void **state) { + + f_thread_mutex_attribute_t attribute = f_thread_mutex_attribute_t_initialize; + int ceiling = 0; + + int errnos[] = { + EINVAL, + EPERM, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_parameter, + F_prohibited, + F_failure, + }; + + for (uint8_t i = 0; i < 3; ++i) { + + will_return(__wrap_pthread_mutexattr_getprioceiling, true); + will_return(__wrap_pthread_mutexattr_getprioceiling, errnos[i]); + + const f_status_t status = f_thread_mutex_attribute_priority_ceiling_get(&attribute, &ceiling); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_mutex_attribute_priority_ceiling_get__parameter_checking(void **state) { + + f_thread_mutex_attribute_t attribute = f_thread_mutex_attribute_t_initialize; + int ceiling = 0; + + { + const f_status_t status = f_thread_mutex_attribute_priority_ceiling_get(0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_mutex_attribute_priority_ceiling_get(&attribute, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_mutex_attribute_priority_ceiling_get(0, &ceiling); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_mutex_attribute_priority_ceiling_get__works(void **state) { + + f_thread_mutex_attribute_t attribute = f_thread_mutex_attribute_t_initialize; + int ceiling = 0; + + { + will_return(__wrap_pthread_mutexattr_getprioceiling, false); + + const f_status_t status = f_thread_mutex_attribute_priority_ceiling_get(&attribute, &ceiling); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_priority_ceiling_get.h b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_priority_ceiling_get.h new file mode 100644 index 0000000..d7832d1 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_priority_ceiling_get.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__mutex_attribute_priority_ceiling_get_h +#define _TEST__F_thread__mutex_attribute_priority_ceiling_get_h + +/** + * Test that function fails. + * + * @see f_thread_mutex_attribute_priority_ceiling_get() + */ +extern void test__f_thread_mutex_attribute_priority_ceiling_get__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_mutex_attribute_priority_ceiling_get() + */ +extern void test__f_thread_mutex_attribute_priority_ceiling_get__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_mutex_attribute_priority_ceiling_get() + */ +extern void test__f_thread_mutex_attribute_priority_ceiling_get__works(void **state); + +#endif // _TEST__F_thread__mutex_attribute_priority_ceiling_get_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_priority_ceiling_set.c b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_priority_ceiling_set.c new file mode 100644 index 0000000..fa0d73a --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_priority_ceiling_set.c @@ -0,0 +1,63 @@ +#include "test-thread.h" +#include "test-thread-mutex_attribute_priority_ceiling_set.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_mutex_attribute_priority_ceiling_set__fails(void **state) { + + f_thread_mutex_attribute_t attribute = f_thread_mutex_attribute_t_initialize; + int ceiling = 0; + + int errnos[] = { + EINVAL, + EPERM, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_parameter, + F_prohibited, + F_failure, + }; + + for (uint8_t i = 0; i < 3; ++i) { + + will_return(__wrap_pthread_mutexattr_setprioceiling, true); + will_return(__wrap_pthread_mutexattr_setprioceiling, errnos[i]); + + const f_status_t status = f_thread_mutex_attribute_priority_ceiling_set(ceiling, &attribute); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_mutex_attribute_priority_ceiling_set__parameter_checking(void **state) { + + int ceiling = 0; + + { + const f_status_t status = f_thread_mutex_attribute_priority_ceiling_set(ceiling, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_mutex_attribute_priority_ceiling_set__works(void **state) { + + f_thread_mutex_attribute_t attribute = f_thread_mutex_attribute_t_initialize; + int ceiling = 0; + + { + will_return(__wrap_pthread_mutexattr_setprioceiling, false); + + const f_status_t status = f_thread_mutex_attribute_priority_ceiling_set(ceiling, &attribute); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_priority_ceiling_set.h b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_priority_ceiling_set.h new file mode 100644 index 0000000..49f85e3 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_priority_ceiling_set.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__mutex_attribute_priority_ceiling_set_h +#define _TEST__F_thread__mutex_attribute_priority_ceiling_set_h + +/** + * Test that function fails. + * + * @see f_thread_mutex_attribute_priority_ceiling_set() + */ +extern void test__f_thread_mutex_attribute_priority_ceiling_set__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_mutex_attribute_priority_ceiling_set() + */ +extern void test__f_thread_mutex_attribute_priority_ceiling_set__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_mutex_attribute_priority_ceiling_set() + */ +extern void test__f_thread_mutex_attribute_priority_ceiling_set__works(void **state); + +#endif // _TEST__F_thread__mutex_attribute_priority_ceiling_set_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_protocol_get.c b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_protocol_get.c new file mode 100644 index 0000000..1c45705 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_protocol_get.c @@ -0,0 +1,76 @@ +#include "test-thread.h" +#include "test-thread-mutex_attribute_protocol_get.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_mutex_attribute_protocol_get__fails(void **state) { + + f_thread_mutex_attribute_t attribute = f_thread_mutex_attribute_t_initialize; + int protocol = 0; + + int errnos[] = { + EINVAL, + EPERM, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_parameter, + F_prohibited, + F_failure, + }; + + for (uint8_t i = 0; i < 3; ++i) { + + will_return(__wrap_pthread_mutexattr_getprotocol, true); + will_return(__wrap_pthread_mutexattr_getprotocol, errnos[i]); + + const f_status_t status = f_thread_mutex_attribute_protocol_get(&attribute, &protocol); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_mutex_attribute_protocol_get__parameter_checking(void **state) { + + f_thread_mutex_attribute_t attribute = f_thread_mutex_attribute_t_initialize; + int protocol = 0; + + { + const f_status_t status = f_thread_mutex_attribute_protocol_get(0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_mutex_attribute_protocol_get(&attribute, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_mutex_attribute_protocol_get(0, &protocol); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_mutex_attribute_protocol_get__works(void **state) { + + f_thread_mutex_attribute_t attribute = f_thread_mutex_attribute_t_initialize; + int protocol = 0; + + { + will_return(__wrap_pthread_mutexattr_getprotocol, false); + + const f_status_t status = f_thread_mutex_attribute_protocol_get(&attribute, &protocol); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_protocol_get.h b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_protocol_get.h new file mode 100644 index 0000000..570f9ce --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_protocol_get.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__mutex_attribute_protocol_get_h +#define _TEST__F_thread__mutex_attribute_protocol_get_h + +/** + * Test that function fails. + * + * @see f_thread_mutex_attribute_protocol_get() + */ +extern void test__f_thread_mutex_attribute_protocol_get__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_mutex_attribute_protocol_get() + */ +extern void test__f_thread_mutex_attribute_protocol_get__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_mutex_attribute_protocol_get() + */ +extern void test__f_thread_mutex_attribute_protocol_get__works(void **state); + +#endif // _TEST__F_thread__mutex_attribute_protocol_get_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_protocol_set.c b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_protocol_set.c new file mode 100644 index 0000000..1b3f620 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_protocol_set.c @@ -0,0 +1,63 @@ +#include "test-thread.h" +#include "test-thread-mutex_attribute_protocol_set.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_mutex_attribute_protocol_set__fails(void **state) { + + f_thread_mutex_attribute_t attribute = f_thread_mutex_attribute_t_initialize; + int protocol = 0; + + int errnos[] = { + EINVAL, + EPERM, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_parameter, + F_prohibited, + F_failure, + }; + + for (uint8_t i = 0; i < 3; ++i) { + + will_return(__wrap_pthread_mutexattr_setprotocol, true); + will_return(__wrap_pthread_mutexattr_setprotocol, errnos[i]); + + const f_status_t status = f_thread_mutex_attribute_protocol_set(protocol, &attribute); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_mutex_attribute_protocol_set__parameter_checking(void **state) { + + int protocol = 0; + + { + const f_status_t status = f_thread_mutex_attribute_protocol_set(protocol, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_mutex_attribute_protocol_set__works(void **state) { + + f_thread_mutex_attribute_t attribute = f_thread_mutex_attribute_t_initialize; + int protocol = 0; + + { + will_return(__wrap_pthread_mutexattr_setprotocol, false); + + const f_status_t status = f_thread_mutex_attribute_protocol_set(protocol, &attribute); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_protocol_set.h b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_protocol_set.h new file mode 100644 index 0000000..536aed6 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_protocol_set.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__mutex_attribute_protocol_set_h +#define _TEST__F_thread__mutex_attribute_protocol_set_h + +/** + * Test that function fails. + * + * @see f_thread_mutex_attribute_protocol_set() + */ +extern void test__f_thread_mutex_attribute_protocol_set__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_mutex_attribute_protocol_set() + */ +extern void test__f_thread_mutex_attribute_protocol_set__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_mutex_attribute_protocol_set() + */ +extern void test__f_thread_mutex_attribute_protocol_set__works(void **state); + +#endif // _TEST__F_thread__mutex_attribute_protocol_set_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_shared_get.c b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_shared_get.c new file mode 100644 index 0000000..70230a7 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_shared_get.c @@ -0,0 +1,72 @@ +#include "test-thread.h" +#include "test-thread-mutex_attribute_shared_get.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_mutex_attribute_shared_get__fails(void **state) { + + f_thread_mutex_attribute_t attribute = f_thread_mutex_attribute_t_initialize; + int shared = 0; + + int errnos[] = { + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_failure, + }; + + for (uint8_t i = 0; i < 1; ++i) { + + will_return(__wrap_pthread_mutexattr_getpshared, true); + will_return(__wrap_pthread_mutexattr_getpshared, errnos[i]); + + const f_status_t status = f_thread_mutex_attribute_shared_get(&attribute, &shared); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_mutex_attribute_shared_get__parameter_checking(void **state) { + + f_thread_mutex_attribute_t attribute = f_thread_mutex_attribute_t_initialize; + int shared = 0; + + { + const f_status_t status = f_thread_mutex_attribute_shared_get(0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_mutex_attribute_shared_get(&attribute, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_mutex_attribute_shared_get(0, &shared); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_mutex_attribute_shared_get__works(void **state) { + + f_thread_mutex_attribute_t attribute = f_thread_mutex_attribute_t_initialize; + int shared = 0; + + { + will_return(__wrap_pthread_mutexattr_getpshared, false); + + const f_status_t status = f_thread_mutex_attribute_shared_get(&attribute, &shared); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_shared_get.h b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_shared_get.h new file mode 100644 index 0000000..455bd7d --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_shared_get.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__mutex_attribute_shared_get_h +#define _TEST__F_thread__mutex_attribute_shared_get_h + +/** + * Test that function fails. + * + * @see f_thread_mutex_attribute_shared_get() + */ +extern void test__f_thread_mutex_attribute_shared_get__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_mutex_attribute_shared_get() + */ +extern void test__f_thread_mutex_attribute_shared_get__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_mutex_attribute_shared_get() + */ +extern void test__f_thread_mutex_attribute_shared_get__works(void **state); + +#endif // _TEST__F_thread__mutex_attribute_shared_get_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_shared_set.c b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_shared_set.c new file mode 100644 index 0000000..04e6f0b --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_shared_set.c @@ -0,0 +1,61 @@ +#include "test-thread.h" +#include "test-thread-mutex_attribute_shared_set.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_mutex_attribute_shared_set__fails(void **state) { + + f_thread_mutex_attribute_t attribute = f_thread_mutex_attribute_t_initialize; + int shared = 0; + + int errnos[] = { + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 2; ++i) { + + will_return(__wrap_pthread_mutexattr_setpshared, true); + will_return(__wrap_pthread_mutexattr_setpshared, errnos[i]); + + const f_status_t status = f_thread_mutex_attribute_shared_set(shared, &attribute); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_mutex_attribute_shared_set__parameter_checking(void **state) { + + int shared = 0; + + { + const f_status_t status = f_thread_mutex_attribute_shared_set(shared, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_mutex_attribute_shared_set__works(void **state) { + + f_thread_mutex_attribute_t attribute = f_thread_mutex_attribute_t_initialize; + int shared = 0; + + { + will_return(__wrap_pthread_mutexattr_setpshared, false); + + const f_status_t status = f_thread_mutex_attribute_shared_set(shared, &attribute); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_shared_set.h b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_shared_set.h new file mode 100644 index 0000000..59c937a --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_shared_set.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__mutex_attribute_shared_set_h +#define _TEST__F_thread__mutex_attribute_shared_set_h + +/** + * Test that function fails. + * + * @see f_thread_mutex_attribute_shared_set() + */ +extern void test__f_thread_mutex_attribute_shared_set__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_mutex_attribute_shared_set() + */ +extern void test__f_thread_mutex_attribute_shared_set__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_mutex_attribute_shared_set() + */ +extern void test__f_thread_mutex_attribute_shared_set__works(void **state); + +#endif // _TEST__F_thread__mutex_attribute_shared_set_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_type_get.c b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_type_get.c new file mode 100644 index 0000000..ab6c91c --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_type_get.c @@ -0,0 +1,57 @@ +#include "test-thread.h" +#include "test-thread-mutex_attribute_type_get.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_mutex_attribute_type_get__fails(void **state) { + + f_thread_mutex_attribute_t attribute = f_thread_mutex_attribute_t_initialize; + int type = 0; + + int errnos[] = { + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_failure, + }; + + for (uint8_t i = 0; i < 1; ++i) { + + will_return(__wrap_pthread_mutexattr_gettype, true); + will_return(__wrap_pthread_mutexattr_gettype, errnos[i]); + + const f_status_t status = f_thread_mutex_attribute_type_get(&attribute, &type); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_mutex_attribute_type_get__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_mutex_attribute_type_get(0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_mutex_attribute_type_get__works(void **state) { + + f_thread_mutex_attribute_t attribute = f_thread_mutex_attribute_t_initialize; + int type = 0; + + { + will_return(__wrap_pthread_mutexattr_gettype, false); + + const f_status_t status = f_thread_mutex_attribute_type_get(&attribute, &type); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_type_get.h b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_type_get.h new file mode 100644 index 0000000..29b8a0d --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_type_get.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__mutex_attribute_type_get_h +#define _TEST__F_thread__mutex_attribute_type_get_h + +/** + * Test that function fails. + * + * @see f_thread_mutex_attribute_type_get() + */ +extern void test__f_thread_mutex_attribute_type_get__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_mutex_attribute_type_get() + */ +extern void test__f_thread_mutex_attribute_type_get__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_mutex_attribute_type_get() + */ +extern void test__f_thread_mutex_attribute_type_get__works(void **state); + +#endif // _TEST__F_thread__mutex_attribute_type_get_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_type_set.c b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_type_set.c new file mode 100644 index 0000000..324c0d9 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_type_set.c @@ -0,0 +1,61 @@ +#include "test-thread.h" +#include "test-thread-mutex_attribute_type_set.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_mutex_attribute_type_set__fails(void **state) { + + f_thread_mutex_attribute_t attribute = f_thread_mutex_attribute_t_initialize; + int type = 0; + + int errnos[] = { + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 2; ++i) { + + will_return(__wrap_pthread_mutexattr_settype, true); + will_return(__wrap_pthread_mutexattr_settype, errnos[i]); + + const f_status_t status = f_thread_mutex_attribute_type_set(type, &attribute); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_mutex_attribute_type_set__parameter_checking(void **state) { + + int type = 0; + + { + const f_status_t status = f_thread_mutex_attribute_type_set(type, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_mutex_attribute_type_set__works(void **state) { + + f_thread_mutex_attribute_t attribute = f_thread_mutex_attribute_t_initialize; + int type = 0; + + { + will_return(__wrap_pthread_mutexattr_settype, false); + + const f_status_t status = f_thread_mutex_attribute_type_set(type, &attribute); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_type_set.h b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_type_set.h new file mode 100644 index 0000000..d6cf399 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_attribute_type_set.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__mutex_attribute_type_set_h +#define _TEST__F_thread__mutex_attribute_type_set_h + +/** + * Test that function fails. + * + * @see f_thread_mutex_attribute_type_set() + */ +extern void test__f_thread_mutex_attribute_type_set__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_mutex_attribute_type_set() + */ +extern void test__f_thread_mutex_attribute_type_set__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_mutex_attribute_type_set() + */ +extern void test__f_thread_mutex_attribute_type_set__works(void **state); + +#endif // _TEST__F_thread__mutex_attribute_type_set_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_attributes_decimate_by.c b/level_0/f_thread/tests/unit/c/test-thread-mutex_attributes_decimate_by.c index 2db5786..5e5fe16 100644 --- a/level_0/f_thread/tests/unit/c/test-thread-mutex_attributes_decimate_by.c +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_attributes_decimate_by.c @@ -59,6 +59,10 @@ void test__f_thread_mutex_attributes_decimate_by__works(void **state) { } { + for (uint8_t i = 0; i < length; ++i) { + will_return(__wrap_pthread_mutexattr_destroy, false); + } // for + const f_status_t status = f_thread_mutex_attributes_decimate_by(length, &data); assert_int_equal(status, F_none); diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_attributes_decrease_by.c b/level_0/f_thread/tests/unit/c/test-thread-mutex_attributes_decrease_by.c index 9bd8ced..7289522 100644 --- a/level_0/f_thread/tests/unit/c/test-thread-mutex_attributes_decrease_by.c +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_attributes_decrease_by.c @@ -59,6 +59,10 @@ void test__f_thread_mutex_attributes_decrease_by__works(void **state) { } { + for (uint8_t i = 0; i < length; ++i) { + will_return(__wrap_pthread_mutexattr_destroy, false); + } // for + const f_status_t status = f_thread_mutex_attributes_decrease_by(length, &data); assert_int_equal(status, F_none); diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_create.c b/level_0/f_thread/tests/unit/c/test-thread-mutex_create.c new file mode 100644 index 0000000..f0f59eb --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_create.c @@ -0,0 +1,69 @@ +#include "test-thread.h" +#include "test-thread-mutex_create.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_mutex_create__fails(void **state) { + + f_thread_mutex_attribute_t attribute = f_thread_mutex_attribute_t_initialize; + f_thread_mutex_t mutex = f_thread_mutex_t_initialize; + + int errnos[] = { + EAGAIN, + EBUSY, + EINVAL, + ENOMEM, + EPERM, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_resource_not, + F_busy, + F_parameter, + F_memory_not, + F_prohibited, + F_failure, + }; + + for (uint8_t i = 0; i < 6; ++i) { + + will_return(__wrap_pthread_mutex_init, true); + will_return(__wrap_pthread_mutex_init, errnos[i]); + + const f_status_t status = f_thread_mutex_create(&attribute, &mutex); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_mutex_create__parameter_checking(void **state) { + + f_thread_mutex_attribute_t attribute = f_thread_mutex_attribute_t_initialize; + + { + const f_status_t status = f_thread_mutex_create(&attribute, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_mutex_create__works(void **state) { + + f_thread_mutex_attribute_t attribute = f_thread_mutex_attribute_t_initialize; + f_thread_mutex_t mutex = f_thread_mutex_t_initialize; + + { + will_return(__wrap_pthread_mutex_init, false); + + const f_status_t status = f_thread_mutex_create(&attribute, &mutex); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_create.h b/level_0/f_thread/tests/unit/c/test-thread-mutex_create.h new file mode 100644 index 0000000..73636db --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_create.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__mutex_create_h +#define _TEST__F_thread__mutex_create_h + +/** + * Test that function fails. + * + * @see f_thread_mutex_create() + */ +extern void test__f_thread_mutex_create__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_mutex_create() + */ +extern void test__f_thread_mutex_create__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_mutex_create() + */ +extern void test__f_thread_mutex_create__works(void **state); + +#endif // _TEST__F_thread__mutex_create_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_delete.c b/level_0/f_thread/tests/unit/c/test-thread-mutex_delete.c new file mode 100644 index 0000000..4580f7f --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_delete.c @@ -0,0 +1,59 @@ +#include "test-thread.h" +#include "test-thread-mutex_delete.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_mutex_delete__fails(void **state) { + + f_thread_mutex_t mutex = f_thread_mutex_t_initialize; + + int errnos[] = { + EBUSY, + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_busy, + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 3; ++i) { + + will_return(__wrap_pthread_mutex_destroy, true); + will_return(__wrap_pthread_mutex_destroy, errnos[i]); + + const f_status_t status = f_thread_mutex_delete(&mutex); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_mutex_delete__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_mutex_delete(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_mutex_delete__works(void **state) { + + f_thread_mutex_t mutex = f_thread_mutex_t_initialize; + + { + will_return(__wrap_pthread_mutex_destroy, false); + + const f_status_t status = f_thread_mutex_delete(&mutex); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_delete.h b/level_0/f_thread/tests/unit/c/test-thread-mutex_delete.h new file mode 100644 index 0000000..4ef1d23 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_delete.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__mutex_delete_h +#define _TEST__F_thread__mutex_delete_h + +/** + * Test that function fails. + * + * @see f_thread_mutex_delete() + */ +extern void test__f_thread_mutex_delete__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_mutex_delete() + */ +extern void test__f_thread_mutex_delete__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_mutex_delete() + */ +extern void test__f_thread_mutex_delete__works(void **state); + +#endif // _TEST__F_thread__mutex_delete_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_lock.c b/level_0/f_thread/tests/unit/c/test-thread-mutex_lock.c new file mode 100644 index 0000000..f9a3691 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_lock.c @@ -0,0 +1,61 @@ +#include "test-thread.h" +#include "test-thread-mutex_lock.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_mutex_lock__fails(void **state) { + + f_thread_mutex_t mutex = f_thread_mutex_t_initialize; + + int errnos[] = { + EAGAIN, + EDEADLK, + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_resource_not, + F_deadlock, + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 4; ++i) { + + will_return(__wrap_pthread_mutex_lock, true); + will_return(__wrap_pthread_mutex_lock, errnos[i]); + + const f_status_t status = f_thread_mutex_lock(&mutex); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_mutex_lock__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_mutex_lock(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_mutex_lock__works(void **state) { + + f_thread_mutex_t mutex = f_thread_mutex_t_initialize; + + { + will_return(__wrap_pthread_mutex_lock, false); + + const f_status_t status = f_thread_mutex_lock(&mutex); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_lock.h b/level_0/f_thread/tests/unit/c/test-thread-mutex_lock.h new file mode 100644 index 0000000..87483b3 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_lock.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__mutex_lock_h +#define _TEST__F_thread__mutex_lock_h + +/** + * Test that function fails. + * + * @see f_thread_mutex_lock() + */ +extern void test__f_thread_mutex_lock__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_mutex_lock() + */ +extern void test__f_thread_mutex_lock__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_mutex_lock() + */ +extern void test__f_thread_mutex_lock__works(void **state); + +#endif // _TEST__F_thread__mutex_lock_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_lock_timed.c b/level_0/f_thread/tests/unit/c/test-thread-mutex_lock_timed.c new file mode 100644 index 0000000..168e41f --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_lock_timed.c @@ -0,0 +1,90 @@ +#include "test-thread.h" +#include "test-thread-mutex_lock_timed.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_mutex_lock_timed__fails(void **state) { + + f_thread_mutex_t mutex = f_thread_mutex_t_initialize; + struct timespec timeout; + + memset(&timeout, 0, sizeof(struct timespec)); + + int errnos[] = { + EAGAIN, + EDEADLK, + EINVAL, + ENOTRECOVERABLE, + EOWNERDEAD, + ETIMEDOUT, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_status_set_error(F_resource_not), + F_status_set_error(F_deadlock), + F_status_set_error(F_parameter), + F_status_set_error(F_recover_not), + F_status_set_error(F_dead), + F_time, + F_status_set_error(F_failure), + }; + + for (uint8_t i = 0; i < 7; ++i) { + + will_return(__wrap_pthread_mutex_timedlock, true); + will_return(__wrap_pthread_mutex_timedlock, errnos[i]); + + const f_status_t status = f_thread_mutex_lock_timed(&timeout, &mutex); + + assert_int_equal(status, statuss[i]); + } // for +} + +void test__f_thread_mutex_lock_timed__parameter_checking(void **state) { + + f_thread_mutex_t mutex = f_thread_mutex_t_initialize; + struct timespec timeout; + + memset(&timeout, 0, sizeof(struct timespec)); + + { + const f_status_t status = f_thread_mutex_lock_timed(0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_mutex_lock_timed(&timeout, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_mutex_lock_timed(0, &mutex); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_mutex_lock_timed__works(void **state) { + + f_thread_mutex_t mutex = f_thread_mutex_t_initialize; + struct timespec timeout; + + memset(&timeout, 0, sizeof(struct timespec)); + + { + will_return(__wrap_pthread_mutex_timedlock, false); + + const f_status_t status = f_thread_mutex_lock_timed(&timeout, &mutex); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_lock_timed.h b/level_0/f_thread/tests/unit/c/test-thread-mutex_lock_timed.h new file mode 100644 index 0000000..148bba5 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_lock_timed.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__mutex_lock_timed_h +#define _TEST__F_thread__mutex_lock_timed_h + +/** + * Test that function fails. + * + * @see f_thread_mutex_lock_timed() + */ +extern void test__f_thread_mutex_lock_timed__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_mutex_lock_timed() + */ +extern void test__f_thread_mutex_lock_timed__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_mutex_lock_timed() + */ +extern void test__f_thread_mutex_lock_timed__works(void **state); + +#endif // _TEST__F_thread__mutex_lock_timed_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_lock_try.c b/level_0/f_thread/tests/unit/c/test-thread-mutex_lock_try.c new file mode 100644 index 0000000..757f3af --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_lock_try.c @@ -0,0 +1,67 @@ +#include "test-thread.h" +#include "test-thread-mutex_lock_try.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_mutex_lock_try__fails(void **state) { + + f_thread_mutex_t mutex = f_thread_mutex_t_initialize; + struct timespec timeout; + + memset(&timeout, 0, sizeof(struct timespec)); + + int errnos[] = { + EAGAIN, + EBUSY, + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_status_set_error(F_resource_not), + F_busy, + F_status_set_error(F_parameter), + F_status_set_error(F_failure), + }; + + for (uint8_t i = 0; i < 4; ++i) { + + will_return(__wrap_pthread_mutex_trylock, true); + will_return(__wrap_pthread_mutex_trylock, errnos[i]); + + const f_status_t status = f_thread_mutex_lock_try(&mutex); + + assert_int_equal(status, statuss[i]); + } // for +} + +void test__f_thread_mutex_lock_try__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_mutex_lock_try(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_mutex_lock_try__works(void **state) { + + f_thread_mutex_t mutex = f_thread_mutex_t_initialize; + struct timespec timeout; + + memset(&timeout, 0, sizeof(struct timespec)); + + { + will_return(__wrap_pthread_mutex_trylock, false); + + const f_status_t status = f_thread_mutex_lock_try(&mutex); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_lock_try.h b/level_0/f_thread/tests/unit/c/test-thread-mutex_lock_try.h new file mode 100644 index 0000000..9605cc9 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_lock_try.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__mutex_lock_try_h +#define _TEST__F_thread__mutex_lock_try_h + +/** + * Test that function fails. + * + * @see f_thread_mutex_lock_try() + */ +extern void test__f_thread_mutex_lock_try__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_mutex_lock_try() + */ +extern void test__f_thread_mutex_lock_try__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_mutex_lock_try() + */ +extern void test__f_thread_mutex_lock_try__works(void **state); + +#endif // _TEST__F_thread__mutex_lock_try_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutexs_decimate_by.c b/level_0/f_thread/tests/unit/c/test-thread-mutexs_decimate_by.c index b4d0965..8026da5 100644 --- a/level_0/f_thread/tests/unit/c/test-thread-mutexs_decimate_by.c +++ b/level_0/f_thread/tests/unit/c/test-thread-mutexs_decimate_by.c @@ -59,6 +59,10 @@ void test__f_thread_mutexs_decimate_by__works(void **state) { } { + for (uint8_t i = 0; i < length; ++i) { + will_return(__wrap_pthread_mutex_destroy, false); + } // for + const f_status_t status = f_thread_mutexs_decimate_by(length, &data); assert_int_equal(status, F_none); diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutexs_decrease_by.c b/level_0/f_thread/tests/unit/c/test-thread-mutexs_decrease_by.c index 8ae2ebb..3a73069 100644 --- a/level_0/f_thread/tests/unit/c/test-thread-mutexs_decrease_by.c +++ b/level_0/f_thread/tests/unit/c/test-thread-mutexs_decrease_by.c @@ -59,6 +59,10 @@ void test__f_thread_mutexs_decrease_by__works(void **state) { } { + for (uint8_t i = 0; i < length; ++i) { + will_return(__wrap_pthread_mutex_destroy, false); + } // for + const f_status_t status = f_thread_mutexs_decrease_by(length, &data); assert_int_equal(status, F_none); diff --git a/level_0/f_thread/tests/unit/c/test-thread-semaphores_decimate_by.c b/level_0/f_thread/tests/unit/c/test-thread-semaphores_decimate_by.c index 9e210b9..1c1cba4 100644 --- a/level_0/f_thread/tests/unit/c/test-thread-semaphores_decimate_by.c +++ b/level_0/f_thread/tests/unit/c/test-thread-semaphores_decimate_by.c @@ -59,6 +59,10 @@ void test__f_thread_semaphores_decimate_by__works(void **state) { } { + for (uint8_t i = 0; i < length; ++i) { + will_return(__wrap_sem_destroy, false); + } // for + const f_status_t status = f_thread_semaphores_decimate_by(length, &data); assert_int_equal(status, F_none); diff --git a/level_0/f_thread/tests/unit/c/test-thread-semaphores_decrease_by.c b/level_0/f_thread/tests/unit/c/test-thread-semaphores_decrease_by.c index 78f614e..3d4133b 100644 --- a/level_0/f_thread/tests/unit/c/test-thread-semaphores_decrease_by.c +++ b/level_0/f_thread/tests/unit/c/test-thread-semaphores_decrease_by.c @@ -59,6 +59,10 @@ void test__f_thread_semaphores_decrease_by__works(void **state) { } { + for (uint8_t i = 0; i < length; ++i) { + will_return(__wrap_sem_destroy, false); + } // for + const f_status_t status = f_thread_semaphores_decrease_by(length, &data); assert_int_equal(status, F_none); diff --git a/level_0/f_thread/tests/unit/c/test-thread.c b/level_0/f_thread/tests/unit/c/test-thread.c index 94bd973..997d436 100644 --- a/level_0/f_thread/tests/unit/c/test-thread.c +++ b/level_0/f_thread/tests/unit/c/test-thread.c @@ -208,17 +208,10 @@ int main(void) { cmocka_unit_test(test__f_thread_attribute_affinity_set__fails), cmocka_unit_test(test__f_thread_attribute_affinity_set__works), - cmocka_unit_test(test__f_thread_attribute_condition_clock_get__fails), - cmocka_unit_test(test__f_thread_attribute_condition_clock_get__works), + cmocka_unit_test(test__f_thread_attribute_concurrency_get__works), - cmocka_unit_test(test__f_thread_attribute_condition_clock_set__fails), - cmocka_unit_test(test__f_thread_attribute_condition_clock_set__works), - - cmocka_unit_test(test__f_thread_attribute_condition_shared_get__fails), - cmocka_unit_test(test__f_thread_attribute_condition_shared_get__works), - - cmocka_unit_test(test__f_thread_attribute_condition_shared_set__fails), - cmocka_unit_test(test__f_thread_attribute_condition_shared_set__works), + cmocka_unit_test(test__f_thread_attribute_concurrency_set__fails), + cmocka_unit_test(test__f_thread_attribute_concurrency_set__works), cmocka_unit_test(test__f_thread_attribute_create__fails), cmocka_unit_test(test__f_thread_attribute_create__works), @@ -300,6 +293,162 @@ int main(void) { cmocka_unit_test(test__f_thread_barrier_wait__works), + cmocka_unit_test(test__f_thread_caller__works), + + cmocka_unit_test(test__f_thread_cancel__fails), + cmocka_unit_test(test__f_thread_cancel__works), + + cmocka_unit_test(test__f_thread_cancel_state_set__fails), + cmocka_unit_test(test__f_thread_cancel_state_set__works), + + cmocka_unit_test(test__f_thread_cancel_test__works), + + cmocka_unit_test(test__f_thread_cancel_type_set__fails), + cmocka_unit_test(test__f_thread_cancel_type_set__works), + + cmocka_unit_test(test__f_thread_clock_get_id__fails), + cmocka_unit_test(test__f_thread_clock_get_id__works), + + cmocka_unit_test(test__f_thread_compare__works), + + cmocka_unit_test(test__f_thread_condition_attribute_clock_get__fails), + cmocka_unit_test(test__f_thread_condition_attribute_clock_get__works), + + cmocka_unit_test(test__f_thread_condition_attribute_clock_set__fails), + cmocka_unit_test(test__f_thread_condition_attribute_clock_set__works), + + cmocka_unit_test(test__f_thread_condition_attribute_create__fails), + cmocka_unit_test(test__f_thread_condition_attribute_create__works), + + cmocka_unit_test(test__f_thread_condition_attribute_delete__fails), + cmocka_unit_test(test__f_thread_condition_attribute_delete__works), + + cmocka_unit_test(test__f_thread_condition_attribute_shared_get__fails), + cmocka_unit_test(test__f_thread_condition_attribute_shared_get__works), + + cmocka_unit_test(test__f_thread_condition_attribute_shared_set__fails), + cmocka_unit_test(test__f_thread_condition_attribute_shared_set__works), + + cmocka_unit_test(test__f_thread_condition_create__fails), + cmocka_unit_test(test__f_thread_condition_create__works), + + cmocka_unit_test(test__f_thread_condition_delete__fails), + cmocka_unit_test(test__f_thread_condition_delete__works), + + cmocka_unit_test(test__f_thread_condition_wait__fails), + cmocka_unit_test(test__f_thread_condition_wait__works), + + cmocka_unit_test(test__f_thread_condition_wait_timed__fails), + cmocka_unit_test(test__f_thread_condition_wait_timed__works), + + cmocka_unit_test(test__f_thread_create__fails), + cmocka_unit_test(test__f_thread_create__works), + + cmocka_unit_test(test__f_thread_detach__fails), + cmocka_unit_test(test__f_thread_detach__works), + + // Mocking pthread_exit() appears to still result in an exit() call and cannot be tested until this is resolved. + //cmocka_unit_test(test__f_thread_exit__works), + + cmocka_unit_test(test__f_thread_join__fails), + cmocka_unit_test(test__f_thread_join__works), + + cmocka_unit_test(test__f_thread_join_timed__fails), + cmocka_unit_test(test__f_thread_join_timed__works), + + cmocka_unit_test(test__f_thread_join_try__fails), + cmocka_unit_test(test__f_thread_join_try__works), + + cmocka_unit_test(test__f_thread_key_create__fails), + cmocka_unit_test(test__f_thread_key_create__works), + + cmocka_unit_test(test__f_thread_key_delete__works), + + cmocka_unit_test(test__f_thread_key_get__works), + + cmocka_unit_test(test__f_thread_key_set__fails), + cmocka_unit_test(test__f_thread_key_set__works), + + cmocka_unit_test(test__f_thread_lock_attribute_create__fails), + cmocka_unit_test(test__f_thread_lock_attribute_create__works), + + cmocka_unit_test(test__f_thread_lock_attribute_delete__works), + + cmocka_unit_test(test__f_thread_lock_attribute_shared_get__fails), + cmocka_unit_test(test__f_thread_lock_attribute_shared_get__works), + + cmocka_unit_test(test__f_thread_lock_attribute_shared_set__fails), + cmocka_unit_test(test__f_thread_lock_attribute_shared_set__works), + + cmocka_unit_test(test__f_thread_lock_create__fails), + cmocka_unit_test(test__f_thread_lock_create__works), + + cmocka_unit_test(test__f_thread_lock_delete__fails), + cmocka_unit_test(test__f_thread_lock_delete__works), + + cmocka_unit_test(test__f_thread_lock_read__fails), + cmocka_unit_test(test__f_thread_lock_read__works), + + cmocka_unit_test(test__f_thread_lock_read_timed__fails), + cmocka_unit_test(test__f_thread_lock_read_timed__works), + + cmocka_unit_test(test__f_thread_lock_read_try__fails), + cmocka_unit_test(test__f_thread_lock_read_try__works), + + cmocka_unit_test(test__f_thread_lock_write__fails), + cmocka_unit_test(test__f_thread_lock_write__works), + + cmocka_unit_test(test__f_thread_lock_write_timed__fails), + cmocka_unit_test(test__f_thread_lock_write_timed__works), + + cmocka_unit_test(test__f_thread_lock_write_try__fails), + cmocka_unit_test(test__f_thread_lock_write_try__works), + + cmocka_unit_test(test__f_thread_mutex_attribute_create__fails), + cmocka_unit_test(test__f_thread_mutex_attribute_create__works), + + cmocka_unit_test(test__f_thread_mutex_attribute_delete__fails), + cmocka_unit_test(test__f_thread_mutex_attribute_delete__works), + + cmocka_unit_test(test__f_thread_mutex_attribute_priority_ceiling_get__fails), + cmocka_unit_test(test__f_thread_mutex_attribute_priority_ceiling_get__works), + + cmocka_unit_test(test__f_thread_mutex_attribute_priority_ceiling_set__fails), + cmocka_unit_test(test__f_thread_mutex_attribute_priority_ceiling_set__works), + + cmocka_unit_test(test__f_thread_mutex_attribute_shared_get__fails), + cmocka_unit_test(test__f_thread_mutex_attribute_shared_get__works), + + cmocka_unit_test(test__f_thread_mutex_attribute_shared_set__fails), + cmocka_unit_test(test__f_thread_mutex_attribute_shared_set__works), + + cmocka_unit_test(test__f_thread_mutex_attribute_type_get__fails), + cmocka_unit_test(test__f_thread_mutex_attribute_type_get__works), + + cmocka_unit_test(test__f_thread_mutex_attribute_type_set__fails), + cmocka_unit_test(test__f_thread_mutex_attribute_type_set__works), + + cmocka_unit_test(test__f_thread_mutex_attribute_protocol_get__fails), + cmocka_unit_test(test__f_thread_mutex_attribute_protocol_get__works), + + cmocka_unit_test(test__f_thread_mutex_attribute_protocol_set__fails), + cmocka_unit_test(test__f_thread_mutex_attribute_protocol_set__works), + + cmocka_unit_test(test__f_thread_mutex_create__fails), + cmocka_unit_test(test__f_thread_mutex_create__works), + + cmocka_unit_test(test__f_thread_mutex_delete__fails), + cmocka_unit_test(test__f_thread_mutex_delete__works), + + cmocka_unit_test(test__f_thread_mutex_lock__fails), + cmocka_unit_test(test__f_thread_mutex_lock__works), + + cmocka_unit_test(test__f_thread_mutex_lock_timed__fails), + cmocka_unit_test(test__f_thread_mutex_lock_timed__works), + + cmocka_unit_test(test__f_thread_mutex_lock_try__fails), + cmocka_unit_test(test__f_thread_mutex_lock_try__works), + #ifndef _di_level_0_parameter_checking_ cmocka_unit_test(test__f_thread_attributes_adjust__parameter_checking), cmocka_unit_test(test__f_thread_attributes_decimate_by__parameter_checking), @@ -411,11 +560,8 @@ int main(void) { cmocka_unit_test(test__f_thread_attribute_affinity_get__parameter_checking), cmocka_unit_test(test__f_thread_attribute_affinity_set__parameter_checking), - cmocka_unit_test(test__f_thread_attribute_condition_clock_get__parameter_checking), - cmocka_unit_test(test__f_thread_attribute_condition_clock_set__parameter_checking), - - cmocka_unit_test(test__f_thread_attribute_condition_shared_get__parameter_checking), - cmocka_unit_test(test__f_thread_attribute_condition_shared_set__parameter_checking), + cmocka_unit_test(test__f_thread_attribute_concurrency_get__parameter_checking), + // f_thread_attribute_concurrency_set() doesn't use parameter checking. cmocka_unit_test(test__f_thread_attribute_create__parameter_checking), @@ -461,9 +607,115 @@ int main(void) { cmocka_unit_test(test__f_thread_barrier_delete__parameter_checking), cmocka_unit_test(test__f_thread_barrier_wait__parameter_checking), - #endif // _di_level_0_parameter_checking_ - // f_thread_user_set() doesn't use parameter checking. + // f_thread_caller() doesn't use parameter checking. + + // f_thread_cancel() doesn't use parameter checking. + + // f_thread_cancel_state_set() doesn't use parameter checking. + + // f_thread_cancel_test() doesn't use parameter checking. + + // f_thread_cancel_type_set() doesn't use parameter checking. + + cmocka_unit_test(test__f_thread_clock_get_id__parameter_checking), + + // f_thread_compare() doesn't use parameter checking. + + cmocka_unit_test(test__f_thread_condition_attribute_clock_get__parameter_checking), + cmocka_unit_test(test__f_thread_condition_attribute_clock_set__parameter_checking), + + cmocka_unit_test(test__f_thread_condition_attribute_create__parameter_checking), + + cmocka_unit_test(test__f_thread_condition_attribute_delete__parameter_checking), + + cmocka_unit_test(test__f_thread_condition_attribute_shared_get__parameter_checking), + cmocka_unit_test(test__f_thread_condition_attribute_shared_set__parameter_checking), + + cmocka_unit_test(test__f_thread_condition_create__parameter_checking), + + cmocka_unit_test(test__f_thread_condition_signal__parameter_checking), + + cmocka_unit_test(test__f_thread_condition_signal_all__parameter_checking), + + cmocka_unit_test(test__f_thread_condition_wait__parameter_checking), + + cmocka_unit_test(test__f_thread_condition_wait_timed__parameter_checking), + + cmocka_unit_test(test__f_thread_create__parameter_checking), + + // f_thread_detach() doesn't use parameter checking. + + cmocka_unit_test(test__f_thread_exit__parameter_checking), + + // f_thread_join() doesn't use parameter checking. + + // f_thread_join_timed() doesn't use parameter checking. + + // f_thread_join_try() doesn't use parameter checking. + + cmocka_unit_test(test__f_thread_key_create__parameter_checking), + + cmocka_unit_test(test__f_thread_key_delete__parameter_checking), + + cmocka_unit_test(test__f_thread_key_get__parameter_checking), + + cmocka_unit_test(test__f_thread_key_set__parameter_checking), + + cmocka_unit_test(test__f_thread_lock_attribute_create__parameter_checking), + + cmocka_unit_test(test__f_thread_lock_attribute_delete__parameter_checking), + + cmocka_unit_test(test__f_thread_lock_attribute_shared_get__parameter_checking), + + cmocka_unit_test(test__f_thread_lock_attribute_shared_set__parameter_checking), + + cmocka_unit_test(test__f_thread_lock_create__parameter_checking), + + cmocka_unit_test(test__f_thread_lock_delete__parameter_checking), + + cmocka_unit_test(test__f_thread_lock_read__parameter_checking), + + cmocka_unit_test(test__f_thread_lock_read_timed__parameter_checking), + + cmocka_unit_test(test__f_thread_lock_read_try__parameter_checking), + + cmocka_unit_test(test__f_thread_lock_write__parameter_checking), + + cmocka_unit_test(test__f_thread_lock_write_timed__parameter_checking), + + cmocka_unit_test(test__f_thread_lock_write_try__parameter_checking), + + cmocka_unit_test(test__f_thread_mutex_attribute_create__parameter_checking), + + cmocka_unit_test(test__f_thread_mutex_attribute_delete__parameter_checking), + + cmocka_unit_test(test__f_thread_mutex_attribute_priority_ceiling_get__parameter_checking), + + cmocka_unit_test(test__f_thread_mutex_attribute_priority_ceiling_set__parameter_checking), + + cmocka_unit_test(test__f_thread_mutex_attribute_shared_get__parameter_checking), + + cmocka_unit_test(test__f_thread_mutex_attribute_shared_set__parameter_checking), + + cmocka_unit_test(test__f_thread_mutex_attribute_type_get__parameter_checking), + + cmocka_unit_test(test__f_thread_mutex_attribute_type_set__parameter_checking), + + cmocka_unit_test(test__f_thread_mutex_attribute_protocol_get__parameter_checking), + + cmocka_unit_test(test__f_thread_mutex_attribute_protocol_set__parameter_checking), + + cmocka_unit_test(test__f_thread_mutex_create__parameter_checking), + + cmocka_unit_test(test__f_thread_mutex_delete__parameter_checking), + + cmocka_unit_test(test__f_thread_mutex_lock__parameter_checking), + + cmocka_unit_test(test__f_thread_mutex_lock_timed__parameter_checking), + + cmocka_unit_test(test__f_thread_mutex_lock_try__parameter_checking), + #endif // _di_level_0_parameter_checking_ }; return cmocka_run_group_tests(tests, setup, setdown); diff --git a/level_0/f_thread/tests/unit/c/test-thread.h b/level_0/f_thread/tests/unit/c/test-thread.h index cc9259f..44ccc7c 100644 --- a/level_0/f_thread/tests/unit/c/test-thread.h +++ b/level_0/f_thread/tests/unit/c/test-thread.h @@ -121,10 +121,8 @@ #include "test-thread-at_fork.h" #include "test-thread-attribute_affinity_get.h" #include "test-thread-attribute_affinity_set.h" -#include "test-thread-attribute_condition_clock_get.h" -#include "test-thread-attribute_condition_clock_set.h" -#include "test-thread-attribute_condition_shared_get.h" -#include "test-thread-attribute_condition_shared_set.h" +#include "test-thread-attribute_concurrency_get.h" +#include "test-thread-attribute_concurrency_set.h" #include "test-thread-attribute_create.h" #include "test-thread-attribute_default_get.h" #include "test-thread-attribute_default_set.h" @@ -152,6 +150,62 @@ #include "test-thread-barrier_create.h" #include "test-thread-barrier_delete.h" #include "test-thread-barrier_wait.h" +#include "test-thread-caller.h" +#include "test-thread-cancel.h" +#include "test-thread-cancel_state_set.h" +#include "test-thread-cancel_test.h" +#include "test-thread-cancel_type_set.h" +#include "test-thread-clock_get_id.h" +#include "test-thread-compare.h" +#include "test-thread-condition_attribute_clock_get.h" +#include "test-thread-condition_attribute_clock_set.h" +#include "test-thread-condition_attribute_create.h" +#include "test-thread-condition_attribute_delete.h" +#include "test-thread-condition_attribute_shared_get.h" +#include "test-thread-condition_attribute_shared_set.h" +#include "test-thread-condition_create.h" +#include "test-thread-condition_delete.h" +#include "test-thread-condition_signal.h" +#include "test-thread-condition_signal_all.h" +#include "test-thread-condition_wait.h" +#include "test-thread-condition_wait_timed.h" +#include "test-thread-create.h" +#include "test-thread-detach.h" +#include "test-thread-exit.h" +#include "test-thread-join.h" +#include "test-thread-join_try.h" +#include "test-thread-join_timed.h" +#include "test-thread-key_create.h" +#include "test-thread-key_delete.h" +#include "test-thread-key_get.h" +#include "test-thread-key_set.h" +#include "test-thread-lock_attribute_create.h" +#include "test-thread-lock_attribute_delete.h" +#include "test-thread-lock_attribute_shared_get.h" +#include "test-thread-lock_attribute_shared_set.h" +#include "test-thread-lock_create.h" +#include "test-thread-lock_delete.h" +#include "test-thread-lock_read.h" +#include "test-thread-lock_read_timed.h" +#include "test-thread-lock_read_try.h" +#include "test-thread-lock_write.h" +#include "test-thread-lock_write_timed.h" +#include "test-thread-lock_write_try.h" +#include "test-thread-mutex_attribute_create.h" +#include "test-thread-mutex_attribute_delete.h" +#include "test-thread-mutex_attribute_priority_ceiling_get.h" +#include "test-thread-mutex_attribute_priority_ceiling_set.h" +#include "test-thread-mutex_attribute_shared_get.h" +#include "test-thread-mutex_attribute_shared_set.h" +#include "test-thread-mutex_attribute_type_get.h" +#include "test-thread-mutex_attribute_type_set.h" +#include "test-thread-mutex_attribute_protocol_get.h" +#include "test-thread-mutex_attribute_protocol_set.h" +#include "test-thread-mutex_create.h" +#include "test-thread-mutex_delete.h" +#include "test-thread-mutex_lock.h" +#include "test-thread-mutex_lock_timed.h" +#include "test-thread-mutex_lock_try.h" #ifdef __cplusplus extern "C" {