From 741fe487f782d66d8b5a198efbd04e98f4960c45 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Fri, 1 Jul 2022 00:36:16 -0500 Subject: [PATCH] Update: Add the last of the unit tests for f_thread. This implements the last of the intended unit tests for f_thread. --- level_0/f_thread/data/build/settings-mocks | 69 +++-- level_0/f_thread/data/build/settings-tests | 12 + level_0/f_thread/tests/unit/c/mock-thread.c | 279 ++++++++++++++++++++- level_0/f_thread/tests/unit/c/mock-thread.h | 60 +++-- .../c/test-thread-mutex_priority_ceiling_get.c | 76 ++++++ .../c/test-thread-mutex_priority_ceiling_get.h | 34 +++ .../c/test-thread-mutex_priority_ceiling_set.c | 74 ++++++ .../c/test-thread-mutex_priority_ceiling_set.h | 34 +++ level_0/f_thread/tests/unit/c/test-thread-once.c | 71 ++++++ level_0/f_thread/tests/unit/c/test-thread-once.h | 34 +++ .../unit/c/test-thread-scheduler_parameter_get.c | 83 ++++++ .../unit/c/test-thread-scheduler_parameter_get.h | 34 +++ .../unit/c/test-thread-scheduler_parameter_set.c | 70 ++++++ .../unit/c/test-thread-scheduler_parameter_set.h | 34 +++ .../unit/c/test-thread-scheduler_priority_set.c | 54 ++++ .../unit/c/test-thread-scheduler_priority_set.h | 27 ++ .../tests/unit/c/test-thread-semaphore_create.c | 66 +++++ .../tests/unit/c/test-thread-semaphore_create.h | 34 +++ .../tests/unit/c/test-thread-semaphore_delete.c | 57 +++++ .../tests/unit/c/test-thread-semaphore_delete.h | 34 +++ .../unit/c/test-thread-semaphore_file_close.c | 57 +++++ .../unit/c/test-thread-semaphore_file_close.h | 34 +++ .../unit/c/test-thread-semaphore_file_delete.c | 54 ++++ .../unit/c/test-thread-semaphore_file_delete.h | 27 ++ .../tests/unit/c/test-thread-semaphore_file_open.c | 111 ++++++++ .../tests/unit/c/test-thread-semaphore_file_open.h | 34 +++ .../tests/unit/c/test-thread-semaphore_lock.c | 59 +++++ .../tests/unit/c/test-thread-semaphore_lock.h | 34 +++ .../unit/c/test-thread-semaphore_lock_timed.c | 84 +++++++ .../unit/c/test-thread-semaphore_lock_timed.h | 34 +++ .../tests/unit/c/test-thread-semaphore_lock_try.c | 61 +++++ .../tests/unit/c/test-thread-semaphore_lock_try.h | 34 +++ .../tests/unit/c/test-thread-semaphore_unlock.c | 59 +++++ .../tests/unit/c/test-thread-semaphore_unlock.h | 34 +++ .../tests/unit/c/test-thread-semaphore_value_get.c | 74 ++++++ .../tests/unit/c/test-thread-semaphore_value_get.h | 34 +++ .../tests/unit/c/test-thread-signal_mask.c | 92 +++++++ .../tests/unit/c/test-thread-signal_mask.h | 34 +++ .../tests/unit/c/test-thread-signal_queue.c | 76 ++++++ .../tests/unit/c/test-thread-signal_queue.h | 34 +++ .../tests/unit/c/test-thread-signal_write.c | 90 +++++++ .../tests/unit/c/test-thread-signal_write.h | 27 ++ .../tests/unit/c/test-thread-spin_create.c | 63 +++++ .../tests/unit/c/test-thread-spin_create.h | 34 +++ .../tests/unit/c/test-thread-spin_delete.c | 59 +++++ .../tests/unit/c/test-thread-spin_delete.h | 34 +++ .../f_thread/tests/unit/c/test-thread-spin_lock.c | 61 +++++ .../f_thread/tests/unit/c/test-thread-spin_lock.h | 34 +++ .../tests/unit/c/test-thread-spin_lock_try.c | 61 +++++ .../tests/unit/c/test-thread-spin_lock_try.h | 34 +++ .../tests/unit/c/test-thread-spin_unlock.c | 63 +++++ .../tests/unit/c/test-thread-spin_unlock.h | 34 +++ .../tests/unit/c/test-thread-spins_decimate_by.c | 4 + .../tests/unit/c/test-thread-spins_decrease_by.c | 4 + level_0/f_thread/tests/unit/c/test-thread.c | 107 ++++++++ level_0/f_thread/tests/unit/c/test-thread.h | 24 ++ 56 files changed, 2972 insertions(+), 57 deletions(-) create mode 100644 level_0/f_thread/tests/unit/c/test-thread-mutex_priority_ceiling_get.c create mode 100644 level_0/f_thread/tests/unit/c/test-thread-mutex_priority_ceiling_get.h create mode 100644 level_0/f_thread/tests/unit/c/test-thread-mutex_priority_ceiling_set.c create mode 100644 level_0/f_thread/tests/unit/c/test-thread-mutex_priority_ceiling_set.h create mode 100644 level_0/f_thread/tests/unit/c/test-thread-once.c create mode 100644 level_0/f_thread/tests/unit/c/test-thread-once.h create mode 100644 level_0/f_thread/tests/unit/c/test-thread-scheduler_parameter_get.c create mode 100644 level_0/f_thread/tests/unit/c/test-thread-scheduler_parameter_get.h create mode 100644 level_0/f_thread/tests/unit/c/test-thread-scheduler_parameter_set.c create mode 100644 level_0/f_thread/tests/unit/c/test-thread-scheduler_parameter_set.h create mode 100644 level_0/f_thread/tests/unit/c/test-thread-scheduler_priority_set.c create mode 100644 level_0/f_thread/tests/unit/c/test-thread-scheduler_priority_set.h create mode 100644 level_0/f_thread/tests/unit/c/test-thread-semaphore_create.c create mode 100644 level_0/f_thread/tests/unit/c/test-thread-semaphore_create.h create mode 100644 level_0/f_thread/tests/unit/c/test-thread-semaphore_delete.c create mode 100644 level_0/f_thread/tests/unit/c/test-thread-semaphore_delete.h create mode 100644 level_0/f_thread/tests/unit/c/test-thread-semaphore_file_close.c create mode 100644 level_0/f_thread/tests/unit/c/test-thread-semaphore_file_close.h create mode 100644 level_0/f_thread/tests/unit/c/test-thread-semaphore_file_delete.c create mode 100644 level_0/f_thread/tests/unit/c/test-thread-semaphore_file_delete.h create mode 100644 level_0/f_thread/tests/unit/c/test-thread-semaphore_file_open.c create mode 100644 level_0/f_thread/tests/unit/c/test-thread-semaphore_file_open.h create mode 100644 level_0/f_thread/tests/unit/c/test-thread-semaphore_lock.c create mode 100644 level_0/f_thread/tests/unit/c/test-thread-semaphore_lock.h create mode 100644 level_0/f_thread/tests/unit/c/test-thread-semaphore_lock_timed.c create mode 100644 level_0/f_thread/tests/unit/c/test-thread-semaphore_lock_timed.h create mode 100644 level_0/f_thread/tests/unit/c/test-thread-semaphore_lock_try.c create mode 100644 level_0/f_thread/tests/unit/c/test-thread-semaphore_lock_try.h create mode 100644 level_0/f_thread/tests/unit/c/test-thread-semaphore_unlock.c create mode 100644 level_0/f_thread/tests/unit/c/test-thread-semaphore_unlock.h create mode 100644 level_0/f_thread/tests/unit/c/test-thread-semaphore_value_get.c create mode 100644 level_0/f_thread/tests/unit/c/test-thread-semaphore_value_get.h create mode 100644 level_0/f_thread/tests/unit/c/test-thread-signal_mask.c create mode 100644 level_0/f_thread/tests/unit/c/test-thread-signal_mask.h create mode 100644 level_0/f_thread/tests/unit/c/test-thread-signal_queue.c create mode 100644 level_0/f_thread/tests/unit/c/test-thread-signal_queue.h create mode 100644 level_0/f_thread/tests/unit/c/test-thread-signal_write.c create mode 100644 level_0/f_thread/tests/unit/c/test-thread-signal_write.h create mode 100644 level_0/f_thread/tests/unit/c/test-thread-spin_create.c create mode 100644 level_0/f_thread/tests/unit/c/test-thread-spin_create.h create mode 100644 level_0/f_thread/tests/unit/c/test-thread-spin_delete.c create mode 100644 level_0/f_thread/tests/unit/c/test-thread-spin_delete.h create mode 100644 level_0/f_thread/tests/unit/c/test-thread-spin_lock.c create mode 100644 level_0/f_thread/tests/unit/c/test-thread-spin_lock.h create mode 100644 level_0/f_thread/tests/unit/c/test-thread-spin_lock_try.c create mode 100644 level_0/f_thread/tests/unit/c/test-thread-spin_lock_try.h create mode 100644 level_0/f_thread/tests/unit/c/test-thread-spin_unlock.c create mode 100644 level_0/f_thread/tests/unit/c/test-thread-spin_unlock.h diff --git a/level_0/f_thread/data/build/settings-mocks b/level_0/f_thread/data/build/settings-mocks index 03be671..eda3492 100644 --- a/level_0/f_thread/data/build/settings-mocks +++ b/level_0/f_thread/data/build/settings-mocks @@ -80,6 +80,7 @@ flags -Wl,--wrap=pthread_attr_setguardsize flags -Wl,--wrap=pthread_attr_setinheritsched flags -Wl,--wrap=pthread_attr_setschedparam flags -Wl,--wrap=pthread_attr_setschedpolicy +flags -Wl,--wrap=pthread_attr_setschedprio flags -Wl,--wrap=pthread_attr_setscope flags -Wl,--wrap=pthread_attr_setscopesize flags -Wl,--wrap=pthread_attr_setstack @@ -111,36 +112,17 @@ 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_getschedparam 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_kill flags -Wl,--wrap=pthread_mutex_destroy +flags -Wl,--wrap=pthread_mutex_getprioceiling flags -Wl,--wrap=pthread_mutex_init flags -Wl,--wrap=pthread_mutex_lock +flags -Wl,--wrap=pthread_mutex_setprioceiling flags -Wl,--wrap=pthread_mutex_timedlock flags -Wl,--wrap=pthread_mutex_trylock flags -Wl,--wrap=pthread_mutex_unlock @@ -154,4 +136,45 @@ 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=pthread_once +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_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_setschedparam +flags -Wl,--wrap=pthread_setschedprio +flags -Wl,--wrap=pthread_setspecific +flags -Wl,--wrap=pthread_sigmask +flags -Wl,--wrap=pthread_sigqueue +flags -Wl,--wrap=pthread_spin_destroy +flags -Wl,--wrap=pthread_spin_init +flags -Wl,--wrap=pthread_spin_lock +flags -Wl,--wrap=pthread_spin_trylock +flags -Wl,--wrap=pthread_spin_unlock +flags -Wl,--wrap=pthread_testcancel +flags -Wl,--wrap=pthread_timedjoin_np +flags -Wl,--wrap=pthread_tryjoin_np +flags -Wl,--wrap=sem_close flags -Wl,--wrap=sem_destroy +flags -Wl,--wrap=sem_getvalue +flags -Wl,--wrap=sem_init +flags -Wl,--wrap=sem_open +flags -Wl,--wrap=sem_post +flags -Wl,--wrap=sem_timedwait +flags -Wl,--wrap=sem_trywait +flags -Wl,--wrap=sem_unlink +flags -Wl,--wrap=sem_wait diff --git a/level_0/f_thread/data/build/settings-tests b/level_0/f_thread/data/build/settings-tests index a4a09a8..ccf1c38 100644 --- a/level_0/f_thread/data/build/settings-tests +++ b/level_0/f_thread/data/build/settings-tests @@ -89,6 +89,18 @@ build_sources_program test-thread-mutex_attribute_type_get.c test-thread-mutex_a 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-scheduler_parameter_get.c test-thread-scheduler_parameter_set.c +build_sources_program test-thread-scheduler_priority_set.c +build_sources_program test-thread-signal_mask.c test-thread-signal_queue.c test-thread-signal_write.c +build_sources_program test-thread-spin_create.c test-thread-spin_delete.c +build_sources_program test-thread-spin_lock.c test-thread-spin_lock_try.c test-thread-spin_unlock.c +build_sources_program test-thread-mutex_priority_ceiling_get.c test-thread-mutex_priority_ceiling_set.c +build_sources_program test-thread-once.c +build_sources_program test-thread-semaphore_create.c test-thread-semaphore_delete.c +build_sources_program test-thread-semaphore_file_open.c test-thread-semaphore_file_close.c test-thread-semaphore_file_delete.c +build_sources_program test-thread-semaphore_lock.c test-thread-semaphore_lock_timed.c test-thread-semaphore_lock_try.c +build_sources_program test-thread-semaphore_unlock.c +build_sources_program test-thread-semaphore_value_get.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 4e186d7..26f4aaf 100644 --- a/level_0/f_thread/tests/unit/c/mock-thread.c +++ b/level_0/f_thread/tests/unit/c/mock-thread.c @@ -180,7 +180,7 @@ int __wrap_pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched) return 0; } -int __wrap_pthread_attr_setschedparam(pthread_attr_t *restrict attr, const struct sched_param *restrict param) { +int __wrap_pthread_attr_setschedparam(pthread_attr_t * restrict attr, const struct sched_param * restrict param) { const bool failure = mock_type(bool); @@ -502,7 +502,7 @@ int __wrap_pthread_getattr_default_np(pthread_attr_t *attr) { int __wrap_pthread_getconcurrency(void) { - return mock_type(int);; + return mock_type(int); } int __wrap_pthread_getcpuclockid(pthread_t thread, clockid_t *clock_id) { @@ -516,6 +516,17 @@ int __wrap_pthread_getcpuclockid(pthread_t thread, clockid_t *clock_id) { return 0; } +int __wrap_pthread_getschedparam(pthread_t pthread, int *policy, struct sched_param *param) { + + 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 *); @@ -548,6 +559,17 @@ int __wrap_pthread_key_delete(pthread_key_t key) { return mock_type(int); } +int __wrap_pthread_kill(pthread_t thread, int sig) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + pthread_t __wrap_pthread_self(void) { return mock_type(int); @@ -597,6 +619,28 @@ int __wrap_pthread_setconcurrency(int new_level) { return 0; } +int __wrap_pthread_setschedparam(pthread_t pthread, int policy, const struct sched_param *param) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_setschedprio(pthread_t thread, int prio) { + + 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); @@ -608,6 +652,83 @@ int __wrap_pthread_setspecific(pthread_key_t key, const void *value) { return 0; } +int __wrap_pthread_sigmask(int how, const sigset_t *set, sigset_t *oldset) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_sigqueue(pthread_t thread, int sig, const union sigval value) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_spin_destroy(pthread_spinlock_t *spinlock) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_spin_init(pthread_spinlock_t *spinlock, int pshared) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_spin_lock(pthread_spinlock_t *spinlock) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_spin_trylock(pthread_spinlock_t *spinlock) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_spin_unlock(pthread_spinlock_t *spinlock) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + void __wrap_pthread_testcancel(void) { } @@ -787,6 +908,17 @@ int __wrap_pthread_mutex_destroy(pthread_mutex_t *mutex) { return 0; } +int __wrap_pthread_mutex_getprioceiling(const pthread_mutex_t * restrict mutex, int *prioceiling) { + + 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); @@ -809,6 +941,17 @@ int __wrap_pthread_mutex_lock(pthread_mutex_t *mutex) { return 0; } +int __wrap_pthread_mutex_setprioceiling(pthread_mutex_t *mutex, int prioceiling, int *old_ceiling) { + + 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); @@ -952,7 +1095,7 @@ int __wrap_pthread_mutexattr_settype(pthread_mutexattr_t *attr, int kind) { return 0; } -int __wrap_sem_destroy(sem_t *sem) { +int __wrap_pthread_once(pthread_once_t *once_control, void (*init_routine)(void)) { const bool failure = mock_type(bool); @@ -963,6 +1106,136 @@ int __wrap_sem_destroy(sem_t *sem) { return 0; } +int __wrap_sem_close(sem_t *sem) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return -1; + } + + return 0; +} + +int __wrap_sem_destroy(sem_t *sem) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return -1; + } + + return 0; +} + +int __wrap_sem_getvalue(sem_t * restrict sem, int * restrict sval) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return -1; + } + + return 0; +} + +int __wrap_sem_init(sem_t *sem, int pshared, unsigned int value) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return -1; + } + + return 0; +} + +sem_t *__wrap_sem_open(const char *name, int oflag, ...) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return SEM_FAILED; + } + + return ((sem_t *) 1); +} + +int __wrap_sem_post(sem_t *sem) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return -1; + } + + return 0; +} + +int __wrap_sem_timedwait(sem_t * restrict sem, const struct timespec * restrict abs_timeout) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return -1; + } + + return 0; +} + +int __wrap_sem_trywait(sem_t *sem) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return -1; + } + + return 0; +} + +int __wrap_sem_unlink(const char *name) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return -1; + } + + return 0; +} + +int __wrap_sem_wait(sem_t *sem) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return -1; + } + + return 0; +} + void stub(void) { } 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 300943a..ce8b6cb 100644 --- a/level_0/f_thread/tests/unit/c/mock-thread.h +++ b/level_0/f_thread/tests/unit/c/mock-thread.h @@ -11,6 +11,7 @@ #define _MOCK__thread_h // Libc includes. +#include #include #include #include @@ -32,10 +33,10 @@ extern int __wrap_pthread_atfork(void (*prepare)(void), void (*parent)(void), vo extern int __wrap_pthread_attr_destroy(pthread_attr_t *attr); extern int __wrap_pthread_attr_getaffinity_np(const pthread_attr_t *attr, size_t cpusetsize, cpu_set_t *cpuset); extern int __wrap_pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate); -extern int __wrap_pthread_attr_getguardsize(const pthread_attr_t *restrict attr, size_t *restrict guardsize); -extern int __wrap_pthread_attr_getinheritsched(const pthread_attr_t *restrict attr, int *restrict inheritsched); -extern int __wrap_pthread_attr_getschedparam(const pthread_attr_t *restrict attr, struct sched_param *restrict param); -extern int __wrap_pthread_attr_getschedpolicy(const pthread_attr_t *restrict attr, int *restrict policy); +extern int __wrap_pthread_attr_getguardsize(const pthread_attr_t * restrict attr, size_t * restrict guardsize); +extern int __wrap_pthread_attr_getinheritsched(const pthread_attr_t * restrict attr, int * restrict inheritsched); +extern int __wrap_pthread_attr_getschedparam(const pthread_attr_t * restrict attr, struct sched_param * restrict param); +extern int __wrap_pthread_attr_getschedpolicy(const pthread_attr_t * restrict attr, int * restrict policy); extern int __wrap_pthread_attr_getscope(const pthread_attr_t *attr, int *contentionscope); extern int __wrap_pthread_attr_getstack(const pthread_attr_t *attr, void **stackaddr, size_t *stacksize); extern int __wrap_pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize); @@ -44,7 +45,7 @@ extern int __wrap_pthread_attr_setaffinity_np(pthread_t id, size_t cpusetsize, c extern int __wrap_pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate); extern int __wrap_pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize); extern int __wrap_pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched); -extern int __wrap_pthread_attr_setschedparam(pthread_attr_t *restrict attr, const struct sched_param *restrict param); +extern int __wrap_pthread_attr_setschedparam(pthread_attr_t * restrict attr, const struct sched_param * restrict param); 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); @@ -76,16 +77,27 @@ 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 int __wrap_pthread_getschedparam(pthread_t pthread, int *policy, struct sched_param *param); 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 int __wrap_pthread_kill(pthread_t thread, int sig); 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_setschedparam(pthread_t pthread, int policy, const struct sched_param *param); +extern int __wrap_pthread_setschedprio(pthread_t thread, int prio); extern int __wrap_pthread_setspecific(pthread_key_t key, const void *value); +extern int __wrap_pthread_sigmask(int how, const sigset_t *set, sigset_t *oldset); +extern int __wrap_pthread_sigqueue(pthread_t thread, int sig, const union sigval value); +extern int __wrap_pthread_spin_destroy(pthread_spinlock_t *spinlock); +extern int __wrap_pthread_spin_init(pthread_spinlock_t *spinlock, int pshared); +extern int __wrap_pthread_spin_lock(pthread_spinlock_t *spinlock); +extern int __wrap_pthread_spin_trylock(pthread_spinlock_t *spinlock); +extern int __wrap_pthread_spin_unlock(pthread_spinlock_t *spinlock); 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); @@ -103,8 +115,10 @@ 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_getprioceiling(const pthread_mutex_t * restrict mutex, int *prioceiling); 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_setprioceiling(pthread_mutex_t *mutex, int prioceiling, int *old_ceiling); 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); @@ -118,33 +132,17 @@ extern int __wrap_pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr, in 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_pthread_once(pthread_once_t *once_control, void (*init_routine)(void)); +extern int __wrap_sem_close(sem_t *sem); extern int __wrap_sem_destroy(sem_t *sem); - -/* -sem_init -sem_open -sem_close -sem_unlink -sem_wait -sem_timedwait -sem_trywait -sem_post -sem_getvalue -pthread_mutex_getprioceiling -pthread_mutex_setprioceiling -pthread_mutex_unlock -pthread_once -pthread_getschedparam -pthread_setschedparam -pthread_setschedprio -pthread_sigmask -pthread_sigqueue -pthread_spin_init -pthread_spin_lock -pthread_spin_trylock -pthread_spin_unlock -pthread_rwlock_unlock -*/ +extern int __wrap_sem_getvalue(sem_t * restrict sem, int * restrict sval); +extern int __wrap_sem_init(sem_t *sem, int pshared, unsigned int value); +extern sem_t *__wrap_sem_open(const char *name, int oflag, ...); +extern int __wrap_sem_post(sem_t *sem); +extern int __wrap_sem_timedwait(sem_t * restrict sem, const struct timespec * restrict abs_timeout); +extern int __wrap_sem_trywait(sem_t *sem); +extern int __wrap_sem_unlink(const char *name); +extern int __wrap_sem_wait(sem_t *sem); /** * A stub intended to be used for passing to functions like f_thread_at_fork(). diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_priority_ceiling_get.c b/level_0/f_thread/tests/unit/c/test-thread-mutex_priority_ceiling_get.c new file mode 100644 index 0000000..c9dac07 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_priority_ceiling_get.c @@ -0,0 +1,76 @@ +#include "test-thread.h" +#include "test-thread-mutex_priority_ceiling_get.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_mutex_priority_ceiling_get__fails(void **state) { + + f_thread_mutex_t mutex = f_thread_mutex_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_mutex_getprioceiling, true); + will_return(__wrap_pthread_mutex_getprioceiling, errnos[i]); + + const f_status_t status = f_thread_mutex_priority_ceiling_get(&mutex, &ceiling); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_mutex_priority_ceiling_get__parameter_checking(void **state) { + + f_thread_mutex_t mutex = f_thread_mutex_t_initialize; + int ceiling = 0; + + { + const f_status_t status = f_thread_mutex_priority_ceiling_get(0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_mutex_priority_ceiling_get(&mutex, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_mutex_priority_ceiling_get(0, &ceiling); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_mutex_priority_ceiling_get__works(void **state) { + + f_thread_mutex_t mutex = f_thread_mutex_t_initialize; + int ceiling = 0; + + { + will_return(__wrap_pthread_mutex_getprioceiling, false); + + const f_status_t status = f_thread_mutex_priority_ceiling_get(&mutex, &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_priority_ceiling_get.h b/level_0/f_thread/tests/unit/c/test-thread-mutex_priority_ceiling_get.h new file mode 100644 index 0000000..98326b1 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_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_priority_ceiling_get_h +#define _TEST__F_thread__mutex_priority_ceiling_get_h + +/** + * Test that function fails. + * + * @see f_thread_mutex_priority_ceiling_get() + */ +extern void test__f_thread_mutex_priority_ceiling_get__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_mutex_priority_ceiling_get() + */ +extern void test__f_thread_mutex_priority_ceiling_get__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_mutex_priority_ceiling_get() + */ +extern void test__f_thread_mutex_priority_ceiling_get__works(void **state); + +#endif // _TEST__F_thread__mutex_priority_ceiling_get_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_priority_ceiling_set.c b/level_0/f_thread/tests/unit/c/test-thread-mutex_priority_ceiling_set.c new file mode 100644 index 0000000..1ce7231 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_priority_ceiling_set.c @@ -0,0 +1,74 @@ +#include "test-thread.h" +#include "test-thread-mutex_priority_ceiling_set.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_mutex_priority_ceiling_set__fails(void **state) { + + f_thread_mutex_t mutex = f_thread_mutex_t_initialize; + int ceiling = 0; + int previous = 0; + + int errnos[] = { + EAGAIN, + EDEADLK, + EINVAL, + ENOTRECOVERABLE, + EOWNERDEAD, + EPERM, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_resource_not, + F_deadlock, + F_parameter, + F_recover_not, + F_dead, + F_prohibited, + F_failure, + }; + + for (uint8_t i = 0; i < 7; ++i) { + + will_return(__wrap_pthread_mutex_setprioceiling, true); + will_return(__wrap_pthread_mutex_setprioceiling, errnos[i]); + + const f_status_t status = f_thread_mutex_priority_ceiling_set(ceiling, &mutex, &previous); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_mutex_priority_ceiling_set__parameter_checking(void **state) { + + int ceiling = 0; + int previous = 0; + + { + const f_status_t status = f_thread_mutex_priority_ceiling_set(ceiling, 0, &previous); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_mutex_priority_ceiling_set__works(void **state) { + + f_thread_mutex_t mutex = f_thread_mutex_t_initialize; + int ceiling = 0; + int previous = 0; + + { + will_return(__wrap_pthread_mutex_setprioceiling, false); + + const f_status_t status = f_thread_mutex_priority_ceiling_set(ceiling, &mutex, &previous); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-mutex_priority_ceiling_set.h b/level_0/f_thread/tests/unit/c/test-thread-mutex_priority_ceiling_set.h new file mode 100644 index 0000000..3d13d47 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-mutex_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_priority_ceiling_set_h +#define _TEST__F_thread__mutex_priority_ceiling_set_h + +/** + * Test that function fails. + * + * @see f_thread_mutex_priority_ceiling_set() + */ +extern void test__f_thread_mutex_priority_ceiling_set__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_mutex_priority_ceiling_set() + */ +extern void test__f_thread_mutex_priority_ceiling_set__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_mutex_priority_ceiling_set() + */ +extern void test__f_thread_mutex_priority_ceiling_set__works(void **state); + +#endif // _TEST__F_thread__mutex_priority_ceiling_set_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-once.c b/level_0/f_thread/tests/unit/c/test-thread-once.c new file mode 100644 index 0000000..aae098e --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-once.c @@ -0,0 +1,71 @@ +#include "test-thread.h" +#include "test-thread-once.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_once__fails(void **state) { + + f_thread_once_t once = f_thread_once_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_once, true); + will_return(__wrap_pthread_once, errnos[i]); + + const f_status_t status = f_thread_once(stub, &once); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_once__parameter_checking(void **state) { + + f_thread_once_t once = f_thread_once_t_initialize; + + { + const f_status_t status = f_thread_once(0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_once(stub, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_once(0, &once); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_once__works(void **state) { + + f_thread_once_t once = f_thread_once_t_initialize; + + { + will_return(__wrap_pthread_once, false); + + const f_status_t status = f_thread_once(stub, &once); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-once.h b/level_0/f_thread/tests/unit/c/test-thread-once.h new file mode 100644 index 0000000..b437ff8 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-once.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__once_h +#define _TEST__F_thread__once_h + +/** + * Test that function fails. + * + * @see f_thread_once() + */ +extern void test__f_thread_once__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_once() + */ +extern void test__f_thread_once__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_once() + */ +extern void test__f_thread_once__works(void **state); + +#endif // _TEST__F_thread__once_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-scheduler_parameter_get.c b/level_0/f_thread/tests/unit/c/test-thread-scheduler_parameter_get.c new file mode 100644 index 0000000..c8011f8 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-scheduler_parameter_get.c @@ -0,0 +1,83 @@ +#include "test-thread.h" +#include "test-thread-scheduler_parameter_get.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_scheduler_parameter_get__fails(void **state) { + + f_thread_id_t id = f_thread_id_t_initialize; + int policy = 0; + struct sched_param parameter; + + memset(¶meter, 0, sizeof(struct sched_param)); + + int errnos[] = { + ENOTSUP, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_supported_not, + F_failure, + }; + + for (uint8_t i = 0; i < 2; ++i) { + + will_return(__wrap_pthread_getschedparam, true); + will_return(__wrap_pthread_getschedparam, errnos[i]); + + const f_status_t status = f_thread_scheduler_parameter_get(id, &policy, ¶meter); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_scheduler_parameter_get__parameter_checking(void **state) { + + f_thread_id_t id = f_thread_id_t_initialize; + int policy = 0; + struct sched_param parameter; + + memset(¶meter, 0, sizeof(struct sched_param)); + + { + const f_status_t status = f_thread_scheduler_parameter_get(id, 0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_scheduler_parameter_get(id, &policy, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_scheduler_parameter_get(id, 0, ¶meter); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_scheduler_parameter_get__works(void **state) { + + f_thread_id_t id = f_thread_id_t_initialize; + int policy = 0; + struct sched_param parameter; + + memset(¶meter, 0, sizeof(struct sched_param)); + + { + will_return(__wrap_pthread_getschedparam, false); + + const f_status_t status = f_thread_scheduler_parameter_get(id, &policy, ¶meter); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-scheduler_parameter_get.h b/level_0/f_thread/tests/unit/c/test-thread-scheduler_parameter_get.h new file mode 100644 index 0000000..e202cf7 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-scheduler_parameter_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__scheduler_parameter_get_h +#define _TEST__F_thread__scheduler_parameter_get_h + +/** + * Test that function fails. + * + * @see f_thread_scheduler_parameter_get() + */ +extern void test__f_thread_scheduler_parameter_get__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_scheduler_parameter_get() + */ +extern void test__f_thread_scheduler_parameter_get__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_scheduler_parameter_get() + */ +extern void test__f_thread_scheduler_parameter_get__works(void **state); + +#endif // _TEST__F_thread__scheduler_parameter_get_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-scheduler_parameter_set.c b/level_0/f_thread/tests/unit/c/test-thread-scheduler_parameter_set.c new file mode 100644 index 0000000..71c7857 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-scheduler_parameter_set.c @@ -0,0 +1,70 @@ +#include "test-thread.h" +#include "test-thread-scheduler_parameter_set.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_scheduler_parameter_set__fails(void **state) { + + f_thread_id_t id = f_thread_id_t_initialize; + int policy = 0; + struct sched_param parameter; + + memset(¶meter, 0, sizeof(struct sched_param)); + + 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_setschedparam, true); + will_return(__wrap_pthread_setschedparam, errnos[i]); + + const f_status_t status = f_thread_scheduler_parameter_set(id, policy, ¶meter); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_scheduler_parameter_set__parameter_checking(void **state) { + + f_thread_id_t id = f_thread_id_t_initialize; + int policy = 0; + + { + const f_status_t status = f_thread_scheduler_parameter_set(id, policy, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_scheduler_parameter_set__works(void **state) { + + f_thread_id_t id = f_thread_id_t_initialize; + int policy = 0; + struct sched_param parameter; + + memset(¶meter, 0, sizeof(struct sched_param)); + + { + will_return(__wrap_pthread_setschedparam, false); + + const f_status_t status = f_thread_scheduler_parameter_set(id, policy, ¶meter); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-scheduler_parameter_set.h b/level_0/f_thread/tests/unit/c/test-thread-scheduler_parameter_set.h new file mode 100644 index 0000000..48ef585 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-scheduler_parameter_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__scheduler_parameter_set_h +#define _TEST__F_thread__scheduler_parameter_set_h + +/** + * Test that function fails. + * + * @see f_thread_scheduler_parameter_set() + */ +extern void test__f_thread_scheduler_parameter_set__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_scheduler_parameter_set() + */ +extern void test__f_thread_scheduler_parameter_set__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_scheduler_parameter_set() + */ +extern void test__f_thread_scheduler_parameter_set__works(void **state); + +#endif // _TEST__F_thread__scheduler_parameter_set_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-scheduler_priority_set.c b/level_0/f_thread/tests/unit/c/test-thread-scheduler_priority_set.c new file mode 100644 index 0000000..32fe511 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-scheduler_priority_set.c @@ -0,0 +1,54 @@ +#include "test-thread.h" +#include "test-thread-scheduler_priority_set.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_scheduler_priority_set__fails(void **state) { + + f_thread_id_t id = f_thread_id_t_initialize; + int priority = 0; + + int errnos[] = { + EINVAL, + EPERM, + ESRCH, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_parameter, + F_prohibited, + F_found_not, + F_failure, + }; + + for (uint8_t i = 0; i < 4; ++i) { + + will_return(__wrap_pthread_setschedprio, true); + will_return(__wrap_pthread_setschedprio, errnos[i]); + + const f_status_t status = f_thread_scheduler_priority_set(id, priority); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_scheduler_priority_set__works(void **state) { + + f_thread_id_t id = f_thread_id_t_initialize; + int priority = 0; + + { + will_return(__wrap_pthread_setschedprio, false); + + const f_status_t status = f_thread_scheduler_priority_set(id, priority); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-scheduler_priority_set.h b/level_0/f_thread/tests/unit/c/test-thread-scheduler_priority_set.h new file mode 100644 index 0000000..d23d013 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-scheduler_priority_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__scheduler_priority_set_h +#define _TEST__F_thread__scheduler_priority_set_h + +/** + * Test that function fails. + * + * @see f_thread_scheduler_priority_set() + */ +extern void test__f_thread_scheduler_priority_set__fails(void **state); + +/** + * Test that function works. + * + * @see f_thread_scheduler_priority_set() + */ +extern void test__f_thread_scheduler_priority_set__works(void **state); + +#endif // _TEST__F_thread__scheduler_priority_set_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-semaphore_create.c b/level_0/f_thread/tests/unit/c/test-thread-semaphore_create.c new file mode 100644 index 0000000..a3223fb --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-semaphore_create.c @@ -0,0 +1,66 @@ +#include "test-thread.h" +#include "test-thread-semaphore_create.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_semaphore_create__fails(void **state) { + + f_thread_semaphore_t semaphore = f_thread_semaphore_t_initialize; + bool shared = F_false; + unsigned int value = 0; + + int errnos[] = { + EINVAL, + ENOSYS, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_parameter, + F_supported_not, + F_failure, + }; + + for (uint8_t i = 0; i < 3; ++i) { + + will_return(__wrap_sem_init, true); + will_return(__wrap_sem_init, errnos[i]); + + const f_status_t status = f_thread_semaphore_create(shared, value, &semaphore); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_semaphore_create__parameter_checking(void **state) { + + bool shared = F_false; + unsigned int value = 0; + + { + const f_status_t status = f_thread_semaphore_create(shared, value, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_semaphore_create__works(void **state) { + + f_thread_semaphore_t semaphore = f_thread_semaphore_t_initialize; + bool shared = F_false; + unsigned int value = 0; + + { + will_return(__wrap_sem_init, false); + + const f_status_t status = f_thread_semaphore_create(shared, value, &semaphore); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-semaphore_create.h b/level_0/f_thread/tests/unit/c/test-thread-semaphore_create.h new file mode 100644 index 0000000..589cf27 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-semaphore_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__semaphore_create_h +#define _TEST__F_thread__semaphore_create_h + +/** + * Test that function fails. + * + * @see f_thread_semaphore_create() + */ +extern void test__f_thread_semaphore_create__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_semaphore_create() + */ +extern void test__f_thread_semaphore_create__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_semaphore_create() + */ +extern void test__f_thread_semaphore_create__works(void **state); + +#endif // _TEST__F_thread__semaphore_create_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-semaphore_delete.c b/level_0/f_thread/tests/unit/c/test-thread-semaphore_delete.c new file mode 100644 index 0000000..cd18177 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-semaphore_delete.c @@ -0,0 +1,57 @@ +#include "test-thread.h" +#include "test-thread-semaphore_delete.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_semaphore_delete__fails(void **state) { + + f_thread_semaphore_t semaphore = f_thread_semaphore_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_sem_destroy, true); + will_return(__wrap_sem_destroy, errnos[i]); + + const f_status_t status = f_thread_semaphore_delete(&semaphore); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_semaphore_delete__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_semaphore_delete(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_semaphore_delete__works(void **state) { + + f_thread_semaphore_t semaphore = f_thread_semaphore_t_initialize; + + { + will_return(__wrap_sem_destroy, false); + + const f_status_t status = f_thread_semaphore_delete(&semaphore); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-semaphore_delete.h b/level_0/f_thread/tests/unit/c/test-thread-semaphore_delete.h new file mode 100644 index 0000000..a6204ca --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-semaphore_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__semaphore_delete_h +#define _TEST__F_thread__semaphore_delete_h + +/** + * Test that function fails. + * + * @see f_thread_semaphore_delete() + */ +extern void test__f_thread_semaphore_delete__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_semaphore_delete() + */ +extern void test__f_thread_semaphore_delete__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_semaphore_delete() + */ +extern void test__f_thread_semaphore_delete__works(void **state); + +#endif // _TEST__F_thread__semaphore_delete_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-semaphore_file_close.c b/level_0/f_thread/tests/unit/c/test-thread-semaphore_file_close.c new file mode 100644 index 0000000..88042a4 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-semaphore_file_close.c @@ -0,0 +1,57 @@ +#include "test-thread.h" +#include "test-thread-semaphore_file_delete.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_semaphore_file_close__fails(void **state) { + + f_thread_semaphore_t semaphore = f_thread_semaphore_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_sem_close, true); + will_return(__wrap_sem_close, errnos[i]); + + const f_status_t status = f_thread_semaphore_file_close(&semaphore); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_semaphore_file_close__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_semaphore_file_close(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_semaphore_file_close__works(void **state) { + + f_thread_semaphore_t semaphore = f_thread_semaphore_t_initialize; + + { + will_return(__wrap_sem_close, false); + + const f_status_t status = f_thread_semaphore_file_close(&semaphore); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-semaphore_file_close.h b/level_0/f_thread/tests/unit/c/test-thread-semaphore_file_close.h new file mode 100644 index 0000000..6b9bcd9 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-semaphore_file_close.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__semaphore_file_delete_h +#define _TEST__F_thread__semaphore_file_delete_h + +/** + * Test that function fails. + * + * @see f_thread_semaphore_file_close() + */ +extern void test__f_thread_semaphore_file_close__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_semaphore_file_close() + */ +extern void test__f_thread_semaphore_file_close__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_semaphore_file_close() + */ +extern void test__f_thread_semaphore_file_close__works(void **state); + +#endif // _TEST__F_thread__semaphore_file_delete_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-semaphore_file_delete.c b/level_0/f_thread/tests/unit/c/test-thread-semaphore_file_delete.c new file mode 100644 index 0000000..dd6c0bb --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-semaphore_file_delete.c @@ -0,0 +1,54 @@ +#include "test-thread.h" +#include "test-thread-semaphore_file_delete.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_semaphore_file_delete__fails(void **state) { + + f_string_static_t name = macro_f_string_static_t_initialize("test", 0, 4); + + int errnos[] = { + EACCES, + EINVAL, + ENAMETOOLONG, + ENOENT, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_status_set_error(F_access_denied), + F_status_set_error(F_parameter), + F_status_set_error(F_name_not), + F_file_found_not, + F_status_set_error(F_failure), + }; + + for (uint8_t i = 0; i < 5; ++i) { + + will_return(__wrap_sem_unlink, true); + will_return(__wrap_sem_unlink, errnos[i]); + + const f_status_t status = f_thread_semaphore_file_delete(name); + + assert_int_equal(status, statuss[i]); + } // for +} + +void test__f_thread_semaphore_file_delete__works(void **state) { + + f_string_static_t name = macro_f_string_static_t_initialize("test", 0, 4); + + { + will_return(__wrap_sem_unlink, false); + + const f_status_t status = f_thread_semaphore_file_delete(name); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-semaphore_file_delete.h b/level_0/f_thread/tests/unit/c/test-thread-semaphore_file_delete.h new file mode 100644 index 0000000..124ba00 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-semaphore_file_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__semaphore_file_destroy_h +#define _TEST__F_thread__semaphore_file_destroy_h + +/** + * Test that function fails. + * + * @see f_thread_semaphore_file_delete() + */ +extern void test__f_thread_semaphore_file_delete__fails(void **state); + +/** + * Test that function works. + * + * @see f_thread_semaphore_file_delete() + */ +extern void test__f_thread_semaphore_file_delete__works(void **state); + +#endif // _TEST__F_thread__semaphore_file_destroy_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-semaphore_file_open.c b/level_0/f_thread/tests/unit/c/test-thread-semaphore_file_open.c new file mode 100644 index 0000000..3d39eac --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-semaphore_file_open.c @@ -0,0 +1,111 @@ +#include "test-thread.h" +#include "test-thread-semaphore_file_open.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_semaphore_file_open__fails(void **state) { + + f_string_static_t name = macro_f_string_static_t_initialize("test", 0, 4); + f_thread_semaphore_t semaphore = f_thread_semaphore_t_initialize; + f_thread_semaphore_t *semaphore_ptr = &semaphore; + int flag = 0; + mode_t mode = 0; + unsigned value = 0; + + int errnos[] = { + EACCES, + EEXIST, + EINVAL, + EMFILE, + ENAMETOOLONG, + ENFILE, + ENOENT, + ENOMEM, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_access_denied, + F_file_found, + F_parameter, + F_file_descriptor_max, + F_name_not, + F_file_open_max, + F_file_found_not, + F_memory_not, + F_failure, + }; + + for (uint8_t i = 0; i < 9; ++i) { + + semaphore_ptr = &semaphore; + + will_return(__wrap_sem_open, true); + will_return(__wrap_sem_open, errnos[i]); + + const f_status_t status = f_thread_semaphore_file_open(name, flag, mode, value, &semaphore_ptr); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for + + flag = O_CREAT; + + for (uint8_t i = 0; i < 9; ++i) { + + will_return(__wrap_sem_open, true); + will_return(__wrap_sem_open, errnos[i]); + + const f_status_t status = f_thread_semaphore_file_open(name, flag, mode, value, &semaphore_ptr); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_semaphore_file_open__parameter_checking(void **state) { + + f_string_static_t name = macro_f_string_static_t_initialize("test", 0, 4); + int flag = 0; + mode_t mode = 0; + unsigned value = 0; + + { + const f_status_t status = f_thread_semaphore_file_open(name, flag, mode, value, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_semaphore_file_open__works(void **state) { + + f_string_static_t name = macro_f_string_static_t_initialize("test", 0, 4); + f_thread_semaphore_t semaphore = f_thread_semaphore_t_initialize; + f_thread_semaphore_t *semaphore_ptr = &semaphore; + int flag = 0; + mode_t mode = 0; + unsigned value = 0; + + { + will_return(__wrap_sem_open, false); + + const f_status_t status = f_thread_semaphore_file_open(name, flag, mode, value, &semaphore_ptr); + + assert_int_equal(status, F_none); + } + + { + flag = O_CREAT; + semaphore_ptr = &semaphore; + + will_return(__wrap_sem_open, false); + + const f_status_t status = f_thread_semaphore_file_open(name, flag, mode, value, &semaphore_ptr); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-semaphore_file_open.h b/level_0/f_thread/tests/unit/c/test-thread-semaphore_file_open.h new file mode 100644 index 0000000..4de8861 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-semaphore_file_open.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__semaphore_file_open_h +#define _TEST__F_thread__semaphore_file_open_h + +/** + * Test that function fails. + * + * @see f_thread_semaphore_file_open() + */ +extern void test__f_thread_semaphore_file_open__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_semaphore_file_open() + */ +extern void test__f_thread_semaphore_file_open__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_semaphore_file_open() + */ +extern void test__f_thread_semaphore_file_open__works(void **state); + +#endif // _TEST__F_thread__semaphore_file_open_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-semaphore_lock.c b/level_0/f_thread/tests/unit/c/test-thread-semaphore_lock.c new file mode 100644 index 0000000..9a65c47 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-semaphore_lock.c @@ -0,0 +1,59 @@ +#include "test-thread.h" +#include "test-thread-semaphore_lock.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_semaphore_lock__fails(void **state) { + + f_thread_semaphore_t semaphore = f_thread_semaphore_t_initialize; + + int errnos[] = { + EINTR, + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_interrupt, + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 3; ++i) { + + will_return(__wrap_sem_wait, true); + will_return(__wrap_sem_wait, errnos[i]); + + const f_status_t status = f_thread_semaphore_lock(&semaphore); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_semaphore_lock__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_semaphore_lock(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_semaphore_lock__works(void **state) { + + f_thread_semaphore_t semaphore = f_thread_semaphore_t_initialize; + + { + will_return(__wrap_sem_wait, false); + + const f_status_t status = f_thread_semaphore_lock(&semaphore); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-semaphore_lock.h b/level_0/f_thread/tests/unit/c/test-thread-semaphore_lock.h new file mode 100644 index 0000000..2eafd0e --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-semaphore_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__semaphore_lock_h +#define _TEST__F_thread__semaphore_lock_h + +/** + * Test that function fails. + * + * @see f_thread_semaphore_lock() + */ +extern void test__f_thread_semaphore_lock__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_semaphore_lock() + */ +extern void test__f_thread_semaphore_lock__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_semaphore_lock() + */ +extern void test__f_thread_semaphore_lock__works(void **state); + +#endif // _TEST__F_thread__semaphore_lock_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-semaphore_lock_timed.c b/level_0/f_thread/tests/unit/c/test-thread-semaphore_lock_timed.c new file mode 100644 index 0000000..816548e --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-semaphore_lock_timed.c @@ -0,0 +1,84 @@ +#include "test-thread.h" +#include "test-thread-semaphore_lock_timed.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_semaphore_lock_timed__fails(void **state) { + + f_thread_semaphore_t semaphore = f_thread_semaphore_t_initialize; + struct timespec timeout; + + memset(&timeout, 0, sizeof(struct timespec)); + + int errnos[] = { + EINTR, + EINVAL, + ETIMEDOUT, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_status_set_error(F_interrupt), + 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_sem_timedwait, true); + will_return(__wrap_sem_timedwait, errnos[i]); + + const f_status_t status = f_thread_semaphore_lock_timed(&timeout, &semaphore); + + assert_int_equal(status, statuss[i]); + } // for +} + +void test__f_thread_semaphore_lock_timed__parameter_checking(void **state) { + + f_thread_semaphore_t semaphore = f_thread_semaphore_t_initialize; + struct timespec timeout; + + memset(&timeout, 0, sizeof(struct timespec)); + + { + const f_status_t status = f_thread_semaphore_lock_timed(0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_semaphore_lock_timed(&timeout, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_semaphore_lock_timed(0, &semaphore); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_semaphore_lock_timed__works(void **state) { + + f_thread_semaphore_t semaphore = f_thread_semaphore_t_initialize; + struct timespec timeout; + + memset(&timeout, 0, sizeof(struct timespec)); + + { + will_return(__wrap_sem_timedwait, false); + + const f_status_t status = f_thread_semaphore_lock_timed(&timeout, &semaphore); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-semaphore_lock_timed.h b/level_0/f_thread/tests/unit/c/test-thread-semaphore_lock_timed.h new file mode 100644 index 0000000..94b7b7c --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-semaphore_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__semaphore_lock_timed_h +#define _TEST__F_thread__semaphore_lock_timed_h + +/** + * Test that function fails. + * + * @see f_thread_semaphore_lock_timed() + */ +extern void test__f_thread_semaphore_lock_timed__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_semaphore_lock_timed() + */ +extern void test__f_thread_semaphore_lock_timed__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_semaphore_lock_timed() + */ +extern void test__f_thread_semaphore_lock_timed__works(void **state); + +#endif // _TEST__F_thread__semaphore_lock_timed_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-semaphore_lock_try.c b/level_0/f_thread/tests/unit/c/test-thread-semaphore_lock_try.c new file mode 100644 index 0000000..45a2d48 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-semaphore_lock_try.c @@ -0,0 +1,61 @@ +#include "test-thread.h" +#include "test-thread-semaphore_lock_try.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_semaphore_lock_try__fails(void **state) { + + f_thread_semaphore_t semaphore = f_thread_semaphore_t_initialize; + + int errnos[] = { + EAGAIN, + EINTR, + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_resource_not, + F_interrupt, + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 4; ++i) { + + will_return(__wrap_sem_trywait, true); + will_return(__wrap_sem_trywait, errnos[i]); + + const f_status_t status = f_thread_semaphore_lock_try(&semaphore); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_semaphore_lock_try__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_semaphore_lock_try(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_semaphore_lock_try__works(void **state) { + + f_thread_semaphore_t semaphore = f_thread_semaphore_t_initialize; + + { + will_return(__wrap_sem_trywait, false); + + const f_status_t status = f_thread_semaphore_lock_try(&semaphore); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-semaphore_lock_try.h b/level_0/f_thread/tests/unit/c/test-thread-semaphore_lock_try.h new file mode 100644 index 0000000..4fa0a67 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-semaphore_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__semaphore_lock_try_h +#define _TEST__F_thread__semaphore_lock_try_h + +/** + * Test that function fails. + * + * @see f_thread_semaphore_lock_try() + */ +extern void test__f_thread_semaphore_lock_try__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_semaphore_lock_try() + */ +extern void test__f_thread_semaphore_lock_try__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_semaphore_lock_try() + */ +extern void test__f_thread_semaphore_lock_try__works(void **state); + +#endif // _TEST__F_thread__semaphore_lock_try_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-semaphore_unlock.c b/level_0/f_thread/tests/unit/c/test-thread-semaphore_unlock.c new file mode 100644 index 0000000..caf3afd --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-semaphore_unlock.c @@ -0,0 +1,59 @@ +#include "test-thread.h" +#include "test-thread-semaphore_unlock.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_semaphore_unlock__fails(void **state) { + + f_thread_semaphore_t semaphore = f_thread_semaphore_t_initialize; + + int errnos[] = { + EOVERFLOW, + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_number_overflow, + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 3; ++i) { + + will_return(__wrap_sem_post, true); + will_return(__wrap_sem_post, errnos[i]); + + const f_status_t status = f_thread_semaphore_unlock(&semaphore); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_semaphore_unlock__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_semaphore_unlock(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_semaphore_unlock__works(void **state) { + + f_thread_semaphore_t semaphore = f_thread_semaphore_t_initialize; + + { + will_return(__wrap_sem_post, false); + + const f_status_t status = f_thread_semaphore_unlock(&semaphore); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-semaphore_unlock.h b/level_0/f_thread/tests/unit/c/test-thread-semaphore_unlock.h new file mode 100644 index 0000000..1fa2428 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-semaphore_unlock.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__semaphore_unlock_h +#define _TEST__F_thread__semaphore_unlock_h + +/** + * Test that function fails. + * + * @see f_thread_semaphore_unlock() + */ +extern void test__f_thread_semaphore_unlock__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_semaphore_unlock() + */ +extern void test__f_thread_semaphore_unlock__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_semaphore_unlock() + */ +extern void test__f_thread_semaphore_unlock__works(void **state); + +#endif // _TEST__F_thread__semaphore_unlock_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-semaphore_value_get.c b/level_0/f_thread/tests/unit/c/test-thread-semaphore_value_get.c new file mode 100644 index 0000000..2e80ce1 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-semaphore_value_get.c @@ -0,0 +1,74 @@ +#include "test-thread.h" +#include "test-thread-semaphore_value_get.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_semaphore_value_get__fails(void **state) { + + f_thread_semaphore_t semaphore = f_thread_semaphore_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_sem_getvalue, true); + will_return(__wrap_sem_getvalue, errnos[i]); + + const f_status_t status = f_thread_semaphore_value_get(&semaphore, &value); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_semaphore_value_get__parameter_checking(void **state) { + + f_thread_semaphore_t semaphore = f_thread_semaphore_t_initialize; + int value = 0; + + { + const f_status_t status = f_thread_semaphore_value_get(0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_semaphore_value_get(&semaphore, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_semaphore_value_get(0, &value); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_semaphore_value_get__works(void **state) { + + f_thread_semaphore_t semaphore = f_thread_semaphore_t_initialize; + int value = 0; + + { + will_return(__wrap_sem_getvalue, false); + + const f_status_t status = f_thread_semaphore_value_get(&semaphore, &value); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-semaphore_value_get.h b/level_0/f_thread/tests/unit/c/test-thread-semaphore_value_get.h new file mode 100644 index 0000000..b95aed1 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-semaphore_value_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__semaphore_value_get_h +#define _TEST__F_thread__semaphore_value_get_h + +/** + * Test that function fails. + * + * @see f_thread_semaphore_value_get() + */ +extern void test__f_thread_semaphore_value_get__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_semaphore_value_get() + */ +extern void test__f_thread_semaphore_value_get__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_semaphore_value_get() + */ +extern void test__f_thread_semaphore_value_get__works(void **state); + +#endif // _TEST__F_thread__semaphore_value_get_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-signal_mask.c b/level_0/f_thread/tests/unit/c/test-thread-signal_mask.c new file mode 100644 index 0000000..af77830 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-signal_mask.c @@ -0,0 +1,92 @@ +#include "test-thread.h" +#include "test-thread-signal_mask.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_signal_mask__fails(void **state) { + + int how = 0; + sigset_t next; + sigset_t current; + + memset(&next, 0, sizeof(sigset_t)); + memset(¤t, 0, sizeof(sigset_t)); + + int errnos[] = { + EFAULT, + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_buffer, + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 3; ++i) { + + will_return(__wrap_pthread_sigmask, true); + will_return(__wrap_pthread_sigmask, errnos[i]); + + const f_status_t status = f_thread_signal_mask(how, &next, ¤t); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_signal_mask__parameter_checking(void **state) { + + int how = 0; + sigset_t next; + sigset_t current; + + memset(&next, 0, sizeof(sigset_t)); + memset(¤t, 0, sizeof(sigset_t)); + + { + const f_status_t status = f_thread_signal_mask(how, 0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + will_return(__wrap_pthread_sigmask, false); + + const f_status_t status = f_thread_signal_mask(how, &next, 0); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pthread_sigmask, false); + + const f_status_t status = f_thread_signal_mask(how, 0, ¤t); + + assert_int_equal(status, F_none); + } +} + +void test__f_thread_signal_mask__works(void **state) { + + int how = 0; + sigset_t next; + sigset_t current; + + memset(&next, 0, sizeof(sigset_t)); + memset(¤t, 0, sizeof(sigset_t)); + + { + will_return(__wrap_pthread_sigmask, false); + + const f_status_t status = f_thread_signal_mask(how, &next, ¤t); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-signal_mask.h b/level_0/f_thread/tests/unit/c/test-thread-signal_mask.h new file mode 100644 index 0000000..0d440f2 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-signal_mask.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__signal_mask_h +#define _TEST__F_thread__signal_mask_h + +/** + * Test that function fails. + * + * @see f_thread_signal_mask() + */ +extern void test__f_thread_signal_mask__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_signal_mask() + */ +extern void test__f_thread_signal_mask__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_signal_mask() + */ +extern void test__f_thread_signal_mask__works(void **state); + +#endif // _TEST__F_thread__signal_mask_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-signal_queue.c b/level_0/f_thread/tests/unit/c/test-thread-signal_queue.c new file mode 100644 index 0000000..82aa967 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-signal_queue.c @@ -0,0 +1,76 @@ +#include "test-thread.h" +#include "test-thread-signal_queue.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_signal_queue__fails(void **state) { + + f_thread_id_t id = f_thread_id_t_initialize; + int signal = 0; + union sigval value; + + memset(&value, 0, sizeof(union sigval)); + + #ifdef _pthread_sigqueue_unsupported_ + const f_status_t status = f_thread_signal_queue(id, signal, value); + + assert_int_equal(status, F_status_set_error(F_implemented_not)); + #else + { + int errnos[] = { + EAGAIN, + ENOSYS, + EINVAL, + ESRCH, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_resource_not, + F_supported_not, + F_parameter, + F_found_not, + F_failure, + }; + + for (uint8_t i = 0; i < 5; ++i) { + + will_return(__wrap_pthread_sigqueue, true); + will_return(__wrap_pthread_sigqueue, errnos[i]); + + const f_status_t status = f_thread_signal_queue(id, signal, value); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for + } + #endif // _pthread_sigqueue_unsupported_ +} + +void test__f_thread_signal_queue__works(void **state) { + + f_thread_id_t id = f_thread_id_t_initialize; + int signal = 0; + union sigval value; + + memset(&value, 0, sizeof(union sigval)); + + #ifdef _pthread_sigqueue_unsupported_ + const f_status_t status = f_thread_signal_queue(id, signal, value); + + assert_int_equal(status, F_status_set_error(F_implemented_not)); + #else + { + will_return(__wrap_pthread_sigqueue, false); + + const f_status_t status = f_thread_signal_queue(id, signal, value); + + assert_int_equal(status, F_none); + } + #endif // _pthread_sigqueue_unsupported_ +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-signal_queue.h b/level_0/f_thread/tests/unit/c/test-thread-signal_queue.h new file mode 100644 index 0000000..7e9557d --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-signal_queue.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__signal_queue_h +#define _TEST__F_thread__signal_queue_h + +/** + * Test that function fails. + * + * @see f_thread_signal_queue() + */ +extern void test__f_thread_signal_queue__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_signal_queue() + */ +extern void test__f_thread_signal_queue__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_signal_queue() + */ +extern void test__f_thread_signal_queue__works(void **state); + +#endif // _TEST__F_thread__signal_queue_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-signal_write.c b/level_0/f_thread/tests/unit/c/test-thread-signal_write.c new file mode 100644 index 0000000..15a17ea --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-signal_write.c @@ -0,0 +1,90 @@ +#include "test-thread.h" +#include "test-thread-signal_write.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_signal_write__fails(void **state) { + + f_thread_id_t id = f_thread_id_t_initialize; + int signal = 1; + + { + 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_kill, true); + will_return(__wrap_pthread_kill, errnos[i]); + + const f_status_t status = f_thread_signal_write(id, signal); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for + } + + { + signal = 0; + + int errnos[] = { + EINVAL, + ESRCH, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_status_set_error(F_parameter), + F_found_not, + F_status_set_error(F_failure), + }; + + for (uint8_t i = 0; i < 3; ++i) { + + will_return(__wrap_pthread_kill, true); + will_return(__wrap_pthread_kill, errnos[i]); + + const f_status_t status = f_thread_signal_write(id, signal); + + assert_int_equal(status, statuss[i]); + } // for + } +} + +void test__f_thread_signal_write__works(void **state) { + + f_thread_id_t id = f_thread_id_t_initialize; + int signal = 1; + + { + will_return(__wrap_pthread_kill, false); + + const f_status_t status = f_thread_signal_write(id, signal); + + assert_int_equal(status, F_none); + } + + { + signal = 0; + + will_return(__wrap_pthread_kill, false); + + const f_status_t status = f_thread_signal_write(id, signal); + + assert_int_equal(status, F_found); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-signal_write.h b/level_0/f_thread/tests/unit/c/test-thread-signal_write.h new file mode 100644 index 0000000..32d91dc --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-signal_write.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__signal_write_h +#define _TEST__F_thread__signal_write_h + +/** + * Test that function fails. + * + * @see f_thread_signal_write() + */ +extern void test__f_thread_signal_write__fails(void **state); + +/** + * Test that function works. + * + * @see f_thread_signal_write() + */ +extern void test__f_thread_signal_write__works(void **state); + +#endif // _TEST__F_thread__signal_write_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-spin_create.c b/level_0/f_thread/tests/unit/c/test-thread-spin_create.c new file mode 100644 index 0000000..c54bcc3 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-spin_create.c @@ -0,0 +1,63 @@ +#include "test-thread.h" +#include "test-thread-spin_create.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_spin_create__fails(void **state) { + + f_thread_spin_t spin = f_thread_spin_t_initialize; + int shared = 0; + + 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_spin_init, true); + will_return(__wrap_pthread_spin_init, errnos[i]); + + const f_status_t status = f_thread_spin_create(shared, &spin); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_spin_create__parameter_checking(void **state) { + + int shared = 0; + + { + const f_status_t status = f_thread_spin_create(shared, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_spin_create__works(void **state) { + + f_thread_spin_t spin = f_thread_spin_t_initialize; + int shared = 0; + + { + will_return(__wrap_pthread_spin_init, false); + + const f_status_t status = f_thread_spin_create(shared, &spin); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-spin_create.h b/level_0/f_thread/tests/unit/c/test-thread-spin_create.h new file mode 100644 index 0000000..dd8fffc --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-spin_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__spin_create_h +#define _TEST__F_thread__spin_create_h + +/** + * Test that function fails. + * + * @see f_thread_spin_create() + */ +extern void test__f_thread_spin_create__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_spin_create() + */ +extern void test__f_thread_spin_create__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_spin_create() + */ +extern void test__f_thread_spin_create__works(void **state); + +#endif // _TEST__F_thread__spin_create_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-spin_delete.c b/level_0/f_thread/tests/unit/c/test-thread-spin_delete.c new file mode 100644 index 0000000..34d76a1 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-spin_delete.c @@ -0,0 +1,59 @@ +#include "test-thread.h" +#include "test-thread-spin_delete.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_spin_delete__fails(void **state) { + + f_thread_spin_t spin = f_thread_spin_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_spin_destroy, true); + will_return(__wrap_pthread_spin_destroy, errnos[i]); + + const f_status_t status = f_thread_spin_delete(&spin); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_spin_delete__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_spin_delete(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_spin_delete__works(void **state) { + + f_thread_spin_t spin = f_thread_spin_t_initialize; + + { + will_return(__wrap_pthread_spin_destroy, false); + + const f_status_t status = f_thread_spin_delete(&spin); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-spin_delete.h b/level_0/f_thread/tests/unit/c/test-thread-spin_delete.h new file mode 100644 index 0000000..91939a6 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-spin_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__spin_delete_h +#define _TEST__F_thread__spin_delete_h + +/** + * Test that function fails. + * + * @see f_thread_spin_delete() + */ +extern void test__f_thread_spin_delete__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_spin_delete() + */ +extern void test__f_thread_spin_delete__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_spin_delete() + */ +extern void test__f_thread_spin_delete__works(void **state); + +#endif // _TEST__F_thread__spin_delete_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-spin_lock.c b/level_0/f_thread/tests/unit/c/test-thread-spin_lock.c new file mode 100644 index 0000000..9ce302b --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-spin_lock.c @@ -0,0 +1,61 @@ +#include "test-thread.h" +#include "test-thread-spin_lock.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_spin_lock__fails(void **state) { + + f_thread_spin_t spin = f_thread_spin_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_spin_lock, true); + will_return(__wrap_pthread_spin_lock, errnos[i]); + + const f_status_t status = f_thread_spin_lock(&spin); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_spin_lock__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_spin_lock(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_spin_lock__works(void **state) { + + f_thread_spin_t spin = f_thread_spin_t_initialize; + + { + will_return(__wrap_pthread_spin_lock, false); + + const f_status_t status = f_thread_spin_lock(&spin); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-spin_lock.h b/level_0/f_thread/tests/unit/c/test-thread-spin_lock.h new file mode 100644 index 0000000..a9859cb --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-spin_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__spin_lock_h +#define _TEST__F_thread__spin_lock_h + +/** + * Test that function fails. + * + * @see f_thread_spin_lock() + */ +extern void test__f_thread_spin_lock__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_spin_lock() + */ +extern void test__f_thread_spin_lock__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_spin_lock() + */ +extern void test__f_thread_spin_lock__works(void **state); + +#endif // _TEST__F_thread__spin_lock_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-spin_lock_try.c b/level_0/f_thread/tests/unit/c/test-thread-spin_lock_try.c new file mode 100644 index 0000000..89670d6 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-spin_lock_try.c @@ -0,0 +1,61 @@ +#include "test-thread.h" +#include "test-thread-spin_lock_try.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_spin_lock_try__fails(void **state) { + + f_thread_spin_t spin = f_thread_spin_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_spin_trylock, true); + will_return(__wrap_pthread_spin_trylock, errnos[i]); + + const f_status_t status = f_thread_spin_lock_try(&spin); + + assert_int_equal(status, statuss[i]); + } // for +} + +void test__f_thread_spin_lock_try__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_spin_lock_try(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_spin_lock_try__works(void **state) { + + f_thread_spin_t spin = f_thread_spin_t_initialize; + + { + will_return(__wrap_pthread_spin_trylock, false); + + const f_status_t status = f_thread_spin_lock_try(&spin); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-spin_lock_try.h b/level_0/f_thread/tests/unit/c/test-thread-spin_lock_try.h new file mode 100644 index 0000000..a5c22c0 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-spin_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__spin_lock_try_h +#define _TEST__F_thread__spin_lock_try_h + +/** + * Test that function fails. + * + * @see f_thread_spin_lock_try() + */ +extern void test__f_thread_spin_lock_try__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_spin_lock_try() + */ +extern void test__f_thread_spin_lock_try__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_spin_lock_try() + */ +extern void test__f_thread_spin_lock_try__works(void **state); + +#endif // _TEST__F_thread__spin_lock_try_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-spin_unlock.c b/level_0/f_thread/tests/unit/c/test-thread-spin_unlock.c new file mode 100644 index 0000000..20b2d5d --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-spin_unlock.c @@ -0,0 +1,63 @@ +#include "test-thread.h" +#include "test-thread-spin_unlock.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_spin_unlock__fails(void **state) { + + f_thread_spin_t spin = f_thread_spin_t_initialize; + + int errnos[] = { + EAGAIN, + EBUSY, + EINVAL, + EPERM, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_resource_not, + F_busy, + F_parameter, + F_prohibited, + F_failure, + }; + + for (uint8_t i = 0; i < 5; ++i) { + + will_return(__wrap_pthread_spin_unlock, true); + will_return(__wrap_pthread_spin_unlock, errnos[i]); + + const f_status_t status = f_thread_spin_unlock(&spin); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_spin_unlock__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_spin_unlock(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_spin_unlock__works(void **state) { + + f_thread_spin_t spin = f_thread_spin_t_initialize; + + { + will_return(__wrap_pthread_spin_unlock, false); + + const f_status_t status = f_thread_spin_unlock(&spin); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-spin_unlock.h b/level_0/f_thread/tests/unit/c/test-thread-spin_unlock.h new file mode 100644 index 0000000..0be1228 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-spin_unlock.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__spin_unlock_h +#define _TEST__F_thread__spin_unlock_h + +/** + * Test that function fails. + * + * @see f_thread_spin_unlock() + */ +extern void test__f_thread_spin_unlock__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_spin_unlock() + */ +extern void test__f_thread_spin_unlock__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_spin_unlock() + */ +extern void test__f_thread_spin_unlock__works(void **state); + +#endif // _TEST__F_thread__spin_unlock_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-spins_decimate_by.c b/level_0/f_thread/tests/unit/c/test-thread-spins_decimate_by.c index 2c9f451..508474b 100644 --- a/level_0/f_thread/tests/unit/c/test-thread-spins_decimate_by.c +++ b/level_0/f_thread/tests/unit/c/test-thread-spins_decimate_by.c @@ -59,6 +59,10 @@ void test__f_thread_spins_decimate_by__works(void **state) { } { + for (uint8_t i = 0; i < length; ++i) { + will_return(__wrap_pthread_spin_destroy, false); + } // for + const f_status_t status = f_thread_spins_decimate_by(length, &data); assert_int_equal(status, F_none); diff --git a/level_0/f_thread/tests/unit/c/test-thread-spins_decrease_by.c b/level_0/f_thread/tests/unit/c/test-thread-spins_decrease_by.c index 852e749..d7277f4 100644 --- a/level_0/f_thread/tests/unit/c/test-thread-spins_decrease_by.c +++ b/level_0/f_thread/tests/unit/c/test-thread-spins_decrease_by.c @@ -59,6 +59,10 @@ void test__f_thread_spins_decrease_by__works(void **state) { } { + for (uint8_t i = 0; i < length; ++i) { + will_return(__wrap_pthread_spin_destroy, false); + } // for + const f_status_t status = f_thread_spins_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 997d436..944b87d 100644 --- a/level_0/f_thread/tests/unit/c/test-thread.c +++ b/level_0/f_thread/tests/unit/c/test-thread.c @@ -449,6 +449,78 @@ int main(void) { cmocka_unit_test(test__f_thread_mutex_lock_try__fails), cmocka_unit_test(test__f_thread_mutex_lock_try__works), + cmocka_unit_test(test__f_thread_mutex_priority_ceiling_get__fails), + cmocka_unit_test(test__f_thread_mutex_priority_ceiling_get__works), + + cmocka_unit_test(test__f_thread_mutex_priority_ceiling_set__fails), + cmocka_unit_test(test__f_thread_mutex_priority_ceiling_set__works), + + cmocka_unit_test(test__f_thread_once__fails), + cmocka_unit_test(test__f_thread_once__works), + + cmocka_unit_test(test__f_thread_scheduler_parameter_get__fails), + cmocka_unit_test(test__f_thread_scheduler_parameter_get__works), + + cmocka_unit_test(test__f_thread_scheduler_parameter_set__fails), + cmocka_unit_test(test__f_thread_scheduler_parameter_set__works), + + cmocka_unit_test(test__f_thread_scheduler_priority_set__fails), + cmocka_unit_test(test__f_thread_scheduler_priority_set__works), + + cmocka_unit_test(test__f_thread_semaphore_create__fails), + cmocka_unit_test(test__f_thread_semaphore_create__works), + + cmocka_unit_test(test__f_thread_semaphore_delete__fails), + cmocka_unit_test(test__f_thread_semaphore_delete__works), + + cmocka_unit_test(test__f_thread_semaphore_file_close__fails), + cmocka_unit_test(test__f_thread_semaphore_file_close__works), + + cmocka_unit_test(test__f_thread_semaphore_file_delete__fails), + cmocka_unit_test(test__f_thread_semaphore_file_delete__works), + + cmocka_unit_test(test__f_thread_semaphore_file_open__fails), + cmocka_unit_test(test__f_thread_semaphore_file_open__works), + + cmocka_unit_test(test__f_thread_semaphore_lock__fails), + cmocka_unit_test(test__f_thread_semaphore_lock__works), + + cmocka_unit_test(test__f_thread_semaphore_lock_timed__fails), + cmocka_unit_test(test__f_thread_semaphore_lock_timed__works), + + cmocka_unit_test(test__f_thread_semaphore_lock_try__fails), + cmocka_unit_test(test__f_thread_semaphore_lock_try__works), + + cmocka_unit_test(test__f_thread_semaphore_unlock__fails), + cmocka_unit_test(test__f_thread_semaphore_unlock__works), + + cmocka_unit_test(test__f_thread_semaphore_value_get__fails), + cmocka_unit_test(test__f_thread_semaphore_value_get__works), + + cmocka_unit_test(test__f_thread_signal_mask__fails), + cmocka_unit_test(test__f_thread_signal_mask__works), + + cmocka_unit_test(test__f_thread_signal_queue__fails), + cmocka_unit_test(test__f_thread_signal_queue__works), + + cmocka_unit_test(test__f_thread_signal_write__fails), + cmocka_unit_test(test__f_thread_signal_write__works), + + cmocka_unit_test(test__f_thread_spin_create__fails), + cmocka_unit_test(test__f_thread_spin_create__works), + + cmocka_unit_test(test__f_thread_spin_delete__fails), + cmocka_unit_test(test__f_thread_spin_delete__works), + + cmocka_unit_test(test__f_thread_spin_lock__fails), + cmocka_unit_test(test__f_thread_spin_lock__works), + + cmocka_unit_test(test__f_thread_spin_lock_try__fails), + cmocka_unit_test(test__f_thread_spin_lock_try__works), + + cmocka_unit_test(test__f_thread_spin_unlock__fails), + cmocka_unit_test(test__f_thread_spin_unlock__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), @@ -715,6 +787,41 @@ int main(void) { cmocka_unit_test(test__f_thread_mutex_lock_timed__parameter_checking), cmocka_unit_test(test__f_thread_mutex_lock_try__parameter_checking), + + cmocka_unit_test(test__f_thread_mutex_priority_ceiling_get__parameter_checking), + cmocka_unit_test(test__f_thread_mutex_priority_ceiling_set__parameter_checking), + + cmocka_unit_test(test__f_thread_once__parameter_checking), + + cmocka_unit_test(test__f_thread_scheduler_parameter_get__parameter_checking), + cmocka_unit_test(test__f_thread_scheduler_parameter_set__parameter_checking), + // f_thread_scheduler_priority_set() doesn't use parameter checking. + + cmocka_unit_test(test__f_thread_semaphore_create__parameter_checking), + cmocka_unit_test(test__f_thread_semaphore_delete__parameter_checking), + + cmocka_unit_test(test__f_thread_semaphore_file_close__parameter_checking), + // f_thread_semaphore_file_delete() doesn't use parameter checking. + cmocka_unit_test(test__f_thread_semaphore_file_open__parameter_checking), + + cmocka_unit_test(test__f_thread_semaphore_lock__parameter_checking), + cmocka_unit_test(test__f_thread_semaphore_lock_timed__parameter_checking), + cmocka_unit_test(test__f_thread_semaphore_lock_try__parameter_checking), + + cmocka_unit_test(test__f_thread_semaphore_unlock__parameter_checking), + + cmocka_unit_test(test__f_thread_semaphore_value_get__parameter_checking), + + cmocka_unit_test(test__f_thread_signal_mask__parameter_checking), + // f_thread_signal_queue() doesn't use parameter checking. + // f_thread_signal_write() doesn't use parameter checking. + + cmocka_unit_test(test__f_thread_spin_create__parameter_checking), + cmocka_unit_test(test__f_thread_spin_delete__parameter_checking), + + cmocka_unit_test(test__f_thread_spin_lock__parameter_checking), + cmocka_unit_test(test__f_thread_spin_lock_try__parameter_checking), + cmocka_unit_test(test__f_thread_spin_unlock__parameter_checking), #endif // _di_level_0_parameter_checking_ }; 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 44ccc7c..1f4ae52 100644 --- a/level_0/f_thread/tests/unit/c/test-thread.h +++ b/level_0/f_thread/tests/unit/c/test-thread.h @@ -206,6 +206,30 @@ #include "test-thread-mutex_lock.h" #include "test-thread-mutex_lock_timed.h" #include "test-thread-mutex_lock_try.h" +#include "test-thread-mutex_priority_ceiling_get.h" +#include "test-thread-mutex_priority_ceiling_set.h" +#include "test-thread-once.h" +#include "test-thread-scheduler_parameter_get.h" +#include "test-thread-scheduler_parameter_set.h" +#include "test-thread-scheduler_priority_set.h" +#include "test-thread-semaphore_create.h" +#include "test-thread-semaphore_delete.h" +#include "test-thread-semaphore_file_close.h" +#include "test-thread-semaphore_file_delete.h" +#include "test-thread-semaphore_file_open.h" +#include "test-thread-semaphore_lock.h" +#include "test-thread-semaphore_lock_timed.h" +#include "test-thread-semaphore_lock_try.h" +#include "test-thread-semaphore_unlock.h" +#include "test-thread-semaphore_value_get.h" +#include "test-thread-signal_mask.h" +#include "test-thread-signal_queue.h" +#include "test-thread-signal_write.h" +#include "test-thread-spin_create.h" +#include "test-thread-spin_delete.h" +#include "test-thread-spin_lock.h" +#include "test-thread-spin_lock_try.h" +#include "test-thread-spin_unlock.h" #ifdef __cplusplus extern "C" { -- 1.8.3.1