From: Kevin Day Date: Tue, 28 Jun 2022 03:44:07 +0000 (-0500) Subject: Progress: Add more unit tests for f_thread. X-Git-Tag: 0.5.10~11 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=b9530c7f1ee4e846863476296b28945770f59680;p=fll Progress: Add more unit tests for f_thread. --- diff --git a/level_0/f_thread/data/build/settings-mocks b/level_0/f_thread/data/build/settings-mocks index 41b0ec7..89712ad 100644 --- a/level_0/f_thread/data/build/settings-mocks +++ b/level_0/f_thread/data/build/settings-mocks @@ -68,13 +68,29 @@ flags -Wl,--wrap=pthread_attr_getdetachstate flags -Wl,--wrap=pthread_attr_getguardsize flags -Wl,--wrap=pthread_attr_getinheritsched flags -Wl,--wrap=pthread_attr_getschedparam +flags -Wl,--wrap=pthread_attr_getschedpolicy +flags -Wl,--wrap=pthread_attr_getscope +flags -Wl,--wrap=pthread_attr_getscopesize +flags -Wl,--wrap=pthread_attr_getstack +flags -Wl,--wrap=pthread_attr_getstacksize flags -Wl,--wrap=pthread_attr_init flags -Wl,--wrap=pthread_attr_setaffinity_np flags -Wl,--wrap=pthread_attr_setdetachstate 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_setscope +flags -Wl,--wrap=pthread_attr_setscopesize +flags -Wl,--wrap=pthread_attr_setstack +flags -Wl,--wrap=pthread_attr_setstacksize +flags -Wl,--wrap=pthread_barrierattr_destroy +flags -Wl,--wrap=pthread_barrierattr_init +flags -Wl,--wrap=pthread_barrierattr_getpshared +flags -Wl,--wrap=pthread_barrierattr_setpshared flags -Wl,--wrap=pthread_barrier_destroy +flags -Wl,--wrap=pthread_barrier_init +flags -Wl,--wrap=pthread_barrier_wait flags -Wl,--wrap=pthread_condattr_getclock flags -Wl,--wrap=pthread_condattr_getpshared flags -Wl,--wrap=pthread_condattr_setclock diff --git a/level_0/f_thread/data/build/settings-tests b/level_0/f_thread/data/build/settings-tests index af89c6a..4c05cce 100644 --- a/level_0/f_thread/data/build/settings-tests +++ b/level_0/f_thread/data/build/settings-tests @@ -51,6 +51,14 @@ build_sources_program test-thread-attribute_detach_get.c test-thread-attribute_d build_sources_program test-thread-attribute_guard_get.c test-thread-attribute_guard_set.c build_sources_program test-thread-attribute_scheduler_inherit_get.c test-thread-attribute_scheduler_inherit_set.c build_sources_program test-thread-attribute_scheduler_parameter_get.c test-thread-attribute_scheduler_parameter_set.c +build_sources_program test-thread-attribute_scheduler_policy_get.c test-thread-attribute_scheduler_policy_set.c +build_sources_program test-thread-attribute_scope_get.c test-thread-attribute_scope_set.c +build_sources_program test-thread-attribute_stack_get.c test-thread-attribute_stack_set.c +build_sources_program test-thread-attribute_stack_size_get.c test-thread-attribute_stack_size_set.c +build_sources_program test-thread-barrier_attribute_create.c test-thread-barrier_attribute_delete.c +build_sources_program test-thread-barrier_attribute_shared_get.c test-thread-barrier_attribute_shared_set.c +build_sources_program test-thread-barrier_create.c test-thread-barrier_delete.c +build_sources_program test-thread-barrier_wait.c build_sources_program test-thread.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 a5ac7c5..c163db7 100644 --- a/level_0/f_thread/tests/unit/c/mock-thread.c +++ b/level_0/f_thread/tests/unit/c/mock-thread.c @@ -26,7 +26,7 @@ int __wrap_pthread_attr_destroy(pthread_attr_t *attr) { return 0; } -int __wrap_pthread_attr_getaffinity_np(const pthread_attr_t *__attr, size_t __cpusetsize, cpu_set_t *__cpuset) { +int __wrap_pthread_attr_getaffinity_np(const pthread_attr_t *attr, size_t cpusetsize, cpu_set_t *cpuset) { const bool failure = mock_type(bool); @@ -48,7 +48,7 @@ int __wrap_pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachst return 0; } -int __wrap_pthread_attr_getguardsize(const pthread_attr_t *restrict attr, size_t *restrict guardsize) { +int __wrap_pthread_attr_getguardsize(const pthread_attr_t * restrict attr, size_t * restrict guardsize) { const bool failure = mock_type(bool); @@ -59,7 +59,7 @@ int __wrap_pthread_attr_getguardsize(const pthread_attr_t *restrict attr, size_t return 0; } -int __wrap_pthread_attr_getinheritsched(const pthread_attr_t *restrict attr, int *restrict inheritsched) { +int __wrap_pthread_attr_getinheritsched(const pthread_attr_t * restrict attr, int * restrict inheritsched) { const bool failure = mock_type(bool); @@ -70,7 +70,7 @@ int __wrap_pthread_attr_getinheritsched(const pthread_attr_t *restrict attr, int return 0; } -int __wrap_pthread_attr_getschedparam(const pthread_attr_t *restrict attr, struct sched_param *restrict param) { +int __wrap_pthread_attr_getschedparam(const pthread_attr_t * restrict attr, struct sched_param * restrict param) { const bool failure = mock_type(bool); @@ -81,7 +81,7 @@ int __wrap_pthread_attr_getschedparam(const pthread_attr_t *restrict attr, struc return 0; } -int __wrap_pthread_attr_setaffinity_np(pthread_t __id, size_t __cpusetsize, const cpu_set_t *__cpuset) { +int __wrap_pthread_attr_getschedpolicy(const pthread_attr_t * restrict attr, int * restrict policy) { const bool failure = mock_type(bool); @@ -92,7 +92,7 @@ int __wrap_pthread_attr_setaffinity_np(pthread_t __id, size_t __cpusetsize, cons return 0; } -int __wrap_pthread_barrier_destroy(pthread_barrier_t barrier) { +int __wrap_pthread_attr_getscope(const pthread_attr_t *attr, int *contentionscope) { const bool failure = mock_type(bool); @@ -103,7 +103,7 @@ int __wrap_pthread_barrier_destroy(pthread_barrier_t barrier) { return 0; } -int __wrap_pthread_condattr_getclock(const pthread_condattr_t *__restrict __attr, clockid_t *__restrict __clock_id) { +int __wrap_pthread_attr_getstack(const pthread_attr_t *attr, void **stackaddr, size_t *stacksize) { const bool failure = mock_type(bool); @@ -114,7 +114,7 @@ int __wrap_pthread_condattr_getclock(const pthread_condattr_t *__restrict __attr return 0; } -int __wrap_pthread_condattr_setclock(pthread_condattr_t *__attr, clockid_t __clock_id) { +int __wrap_pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize) { const bool failure = mock_type(bool); @@ -125,7 +125,7 @@ int __wrap_pthread_condattr_setclock(pthread_condattr_t *__attr, clockid_t __clo return 0; } -int __wrap_pthread_condattr_getpshared(const pthread_condattr_t *__attr, int *__pshared) { +int __wrap_pthread_attr_init(pthread_attr_t *attr) { const bool failure = mock_type(bool); @@ -136,7 +136,7 @@ int __wrap_pthread_condattr_getpshared(const pthread_condattr_t *__attr, int *__ return 0; } -int __wrap_pthread_condattr_setpshared(pthread_condattr_t *__attr, int __pshared) { +int __wrap_pthread_attr_setaffinity_np(pthread_t id, size_t cpusetsize, const cpu_set_t *cpuset) { const bool failure = mock_type(bool); @@ -147,7 +147,7 @@ int __wrap_pthread_condattr_setpshared(pthread_condattr_t *__attr, int __pshared return 0; } -int __wrap_pthread_getattr_default_np(pthread_attr_t *attr) { +int __wrap_pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate) { const bool failure = mock_type(bool); @@ -158,7 +158,7 @@ int __wrap_pthread_getattr_default_np(pthread_attr_t *attr) { return 0; } -int __wrap_pthread_setattr_default_np(const pthread_attr_t *attr) { +int __wrap_pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize) { const bool failure = mock_type(bool); @@ -169,7 +169,7 @@ int __wrap_pthread_setattr_default_np(const pthread_attr_t *attr) { return 0; } -int __wrap_pthread_attr_init(pthread_attr_t *__attr) { +int __wrap_pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched) { const bool failure = mock_type(bool); @@ -180,7 +180,7 @@ int __wrap_pthread_attr_init(pthread_attr_t *__attr) { return 0; } -int __wrap_pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate) { +int __wrap_pthread_attr_setschedparam(pthread_attr_t *restrict attr, const struct sched_param *restrict param) { const bool failure = mock_type(bool); @@ -191,7 +191,7 @@ int __wrap_pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate) { return 0; } -int __wrap_pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize) { +int __wrap_pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy) { const bool failure = mock_type(bool); @@ -202,7 +202,7 @@ int __wrap_pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize) { return 0; } -int __wrap_pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched) { +int __wrap_pthread_attr_setscope(pthread_attr_t *attr, int contentionscope) { const bool failure = mock_type(bool); @@ -213,7 +213,150 @@ 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_setstack(pthread_attr_t *attr, void *stackaddr, size_t stacksize) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_attr_setstacksize (pthread_attr_t *attr, size_t stacksize) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_barrierattr_destroy(pthread_barrierattr_t *attr) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_barrierattr_init(pthread_barrierattr_t *attr) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_barrierattr_getpshared(const pthread_barrierattr_t *attr, int *pshared) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_barrierattr_setpshared(pthread_barrierattr_t *attr, int pshared) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_barrier_destroy(pthread_barrier_t *barrier) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned count) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_barrier_wait(pthread_barrier_t *barrier) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_condattr_getclock(const pthread_condattr_t * restrict attr, clockid_t * restrict clock_id) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clock_id) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_condattr_getpshared(const pthread_condattr_t *attr, int *pshared) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + return 0; +} + +int __wrap_pthread_getattr_default_np(pthread_attr_t *attr) { const bool failure = mock_type(bool); @@ -229,6 +372,17 @@ int __wrap_pthread_key_delete(pthread_key_t key) { return mock_type(int); } +int __wrap_pthread_setattr_default_np(const pthread_attr_t *attr) { + + const bool failure = mock_type(bool); + + if (failure) { + return mock_type(int); + } + + 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 20fa3b5..0e97830 100644 --- a/level_0/f_thread/tests/unit/c/mock-thread.h +++ b/level_0/f_thread/tests/unit/c/mock-thread.h @@ -30,40 +30,41 @@ const static int mock_errno_generic = 32767; extern int __wrap_pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void)); 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_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_init(pthread_attr_t *__attr); -extern int __wrap_pthread_attr_setaffinity_np(pthread_t __id, size_t __cpusetsize, const cpu_set_t *__cpuset); +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); +extern int __wrap_pthread_attr_init(pthread_attr_t *attr); +extern int __wrap_pthread_attr_setaffinity_np(pthread_t id, size_t cpusetsize, const cpu_set_t *cpuset); 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_barrier_destroy(pthread_barrier_t barrier); -extern int __wrap_pthread_condattr_getclock(const pthread_condattr_t *__restrict __attr, clockid_t *__restrict __clock_id); -extern int __wrap_pthread_condattr_getpshared(const pthread_condattr_t *__attr, int *__pshared); -extern int __wrap_pthread_condattr_setclock(pthread_condattr_t *__attr, clockid_t __clock_id); -extern int __wrap_pthread_condattr_setpshared(pthread_condattr_t *__attr, int __pshared); +extern int __wrap_pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy); +extern int __wrap_pthread_attr_setscope(pthread_attr_t *attr, int contentionscope); +extern int __wrap_pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr, size_t stacksize); +extern int __wrap_pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize); +extern int __wrap_pthread_barrierattr_destroy(pthread_barrierattr_t *attr); +extern int __wrap_pthread_barrierattr_init(pthread_barrierattr_t *attr); +extern int __wrap_pthread_barrierattr_getpshared(const pthread_barrierattr_t *attr, int *pshared); +extern int __wrap_pthread_barrierattr_setpshared(pthread_barrierattr_t *attr, int pshared); +extern int __wrap_pthread_barrier_destroy(pthread_barrier_t *barrier); +extern int __wrap_pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned count); +extern int __wrap_pthread_barrier_wait(pthread_barrier_t *barrier); +extern int __wrap_pthread_condattr_getclock(const pthread_condattr_t * restrict attr, clockid_t * restrict clock_id); +extern int __wrap_pthread_condattr_getpshared(const pthread_condattr_t *attr, int *pshared); +extern int __wrap_pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clock_id); +extern int __wrap_pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared); extern int __wrap_pthread_getattr_default_np(pthread_attr_t *attr); extern int __wrap_pthread_key_delete(pthread_key_t key); extern int __wrap_pthread_setattr_default_np(const pthread_attr_t *attr); /* -pthread_attr_getschedpolicy -pthread_attr_setschedpolicy -pthread_attr_getscope -pthread_attr_setscope -pthread_attr_getstack -pthread_attr_setstack -pthread_attr_getstacksize -pthread_attr_setstacksize -pthread_barrierattr_init -pthread_barrierattr_getpshared -pthread_barrierattr_setpshared -pthread_barrier_init -pthread_barrier_wait pthread_setcancelstate pthread_testcancel pthread_setcanceltype diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_scheduler_policy_get.c b/level_0/f_thread/tests/unit/c/test-thread-attribute_scheduler_policy_get.c new file mode 100644 index 0000000..ed54922 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-attribute_scheduler_policy_get.c @@ -0,0 +1,61 @@ +#include "test-thread.h" +#include "test-thread-attribute_scheduler_policy_get.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_attribute_scheduler_policy_get__fails(void **state) { + + f_thread_attribute_t attribute = f_thread_attribute_t_initialize; + int policy = 0; + + int errnos[] = { + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 2; ++i) { + + will_return(__wrap_pthread_attr_getschedpolicy, true); + will_return(__wrap_pthread_attr_getschedpolicy, errnos[i]); + + const f_status_t status = f_thread_attribute_scheduler_policy_get(attribute, &policy); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_attribute_scheduler_policy_get__parameter_checking(void **state) { + + f_thread_attribute_t attribute = f_thread_attribute_t_initialize; + + { + const f_status_t status = f_thread_attribute_scheduler_policy_get(attribute, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_attribute_scheduler_policy_get__works(void **state) { + + f_thread_attribute_t attribute = f_thread_attribute_t_initialize; + int policy = 0; + + { + will_return(__wrap_pthread_attr_getschedpolicy, false); + + const f_status_t status = f_thread_attribute_scheduler_policy_get(attribute, &policy); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_scheduler_policy_get.h b/level_0/f_thread/tests/unit/c/test-thread-attribute_scheduler_policy_get.h new file mode 100644 index 0000000..742d4ca --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-attribute_scheduler_policy_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__attribute_scheduler_policy_get_h +#define _TEST__F_thread__attribute_scheduler_policy_get_h + +/** + * Test that function fails. + * + * @see f_thread_attribute_scheduler_policy_get() + */ +extern void test__f_thread_attribute_scheduler_policy_get__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_attribute_scheduler_policy_get() + */ +extern void test__f_thread_attribute_scheduler_policy_get__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_attribute_scheduler_policy_get() + */ +extern void test__f_thread_attribute_scheduler_policy_get__works(void **state); + +#endif // _TEST__F_thread__attribute_scheduler_policy_get_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_scheduler_policy_set.c b/level_0/f_thread/tests/unit/c/test-thread-attribute_scheduler_policy_set.c new file mode 100644 index 0000000..1fb136f --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-attribute_scheduler_policy_set.c @@ -0,0 +1,61 @@ +#include "test-thread.h" +#include "test-thread-attribute_scheduler_policy_set.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_attribute_scheduler_policy_set__fails(void **state) { + + f_thread_attribute_t attribute = f_thread_attribute_t_initialize; + int policy = 0; + + int errnos[] = { + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 2; ++i) { + + will_return(__wrap_pthread_attr_setschedpolicy, true); + will_return(__wrap_pthread_attr_setschedpolicy, errnos[i]); + + const f_status_t status = f_thread_attribute_scheduler_policy_set(policy, &attribute); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_attribute_scheduler_policy_set__parameter_checking(void **state) { + + int policy = 0; + + { + const f_status_t status = f_thread_attribute_scheduler_policy_set(policy, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_attribute_scheduler_policy_set__works(void **state) { + + f_thread_attribute_t attribute = f_thread_attribute_t_initialize; + int policy = 0; + + { + will_return(__wrap_pthread_attr_setschedpolicy, false); + + const f_status_t status = f_thread_attribute_scheduler_policy_set(policy, &attribute); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_scheduler_policy_set.h b/level_0/f_thread/tests/unit/c/test-thread-attribute_scheduler_policy_set.h new file mode 100644 index 0000000..5997750 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-attribute_scheduler_policy_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__attribute_scheduler_policy_set_h +#define _TEST__F_thread__attribute_scheduler_policy_set_h + +/** + * Test that function fails. + * + * @see f_thread_attribute_scheduler_policy_set() + */ +extern void test__f_thread_attribute_scheduler_policy_set__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_attribute_scheduler_policy_set() + */ +extern void test__f_thread_attribute_scheduler_policy_set__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_attribute_scheduler_policy_set() + */ +extern void test__f_thread_attribute_scheduler_policy_set__works(void **state); + +#endif // _TEST__F_thread__attribute_scheduler_policy_set_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_scope_get.c b/level_0/f_thread/tests/unit/c/test-thread-attribute_scope_get.c new file mode 100644 index 0000000..1682442 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-attribute_scope_get.c @@ -0,0 +1,61 @@ +#include "test-thread.h" +#include "test-thread-attribute_scope_get.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_attribute_scope_get__fails(void **state) { + + f_thread_attribute_t attribute = f_thread_attribute_t_initialize; + int scope = 0; + + int errnos[] = { + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 2; ++i) { + + will_return(__wrap_pthread_attr_getscope, true); + will_return(__wrap_pthread_attr_getscope, errnos[i]); + + const f_status_t status = f_thread_attribute_scope_get(attribute, &scope); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_attribute_scope_get__parameter_checking(void **state) { + + f_thread_attribute_t attribute = f_thread_attribute_t_initialize; + + { + const f_status_t status = f_thread_attribute_scope_get(attribute, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_attribute_scope_get__works(void **state) { + + f_thread_attribute_t attribute = f_thread_attribute_t_initialize; + int scope = 0; + + { + will_return(__wrap_pthread_attr_getscope, false); + + const f_status_t status = f_thread_attribute_scope_get(attribute, &scope); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_scope_get.h b/level_0/f_thread/tests/unit/c/test-thread-attribute_scope_get.h new file mode 100644 index 0000000..66ddd87 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-attribute_scope_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__attribute_scope_get_h +#define _TEST__F_thread__attribute_scope_get_h + +/** + * Test that function fails. + * + * @see f_thread_attribute_scope_get() + */ +extern void test__f_thread_attribute_scope_get__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_attribute_scope_get() + */ +extern void test__f_thread_attribute_scope_get__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_attribute_scope_get() + */ +extern void test__f_thread_attribute_scope_get__works(void **state); + +#endif // _TEST__F_thread__attribute_scope_get_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_scope_set.c b/level_0/f_thread/tests/unit/c/test-thread-attribute_scope_set.c new file mode 100644 index 0000000..e8f5a86 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-attribute_scope_set.c @@ -0,0 +1,61 @@ +#include "test-thread.h" +#include "test-thread-attribute_scope_set.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_attribute_scope_set__fails(void **state) { + + f_thread_attribute_t attribute = f_thread_attribute_t_initialize; + int scope = 0; + + int errnos[] = { + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 2; ++i) { + + will_return(__wrap_pthread_attr_setscope, true); + will_return(__wrap_pthread_attr_setscope, errnos[i]); + + const f_status_t status = f_thread_attribute_scope_set(scope, &attribute); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_attribute_scope_set__parameter_checking(void **state) { + + int scope = 0; + + { + const f_status_t status = f_thread_attribute_scope_set(scope, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_attribute_scope_set__works(void **state) { + + f_thread_attribute_t attribute = f_thread_attribute_t_initialize; + int scope = 0; + + { + will_return(__wrap_pthread_attr_setscope, false); + + const f_status_t status = f_thread_attribute_scope_set(scope, &attribute); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_scope_set.h b/level_0/f_thread/tests/unit/c/test-thread-attribute_scope_set.h new file mode 100644 index 0000000..3d55472 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-attribute_scope_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__attribute_scope_set_h +#define _TEST__F_thread__attribute_scope_set_h + +/** + * Test that function fails. + * + * @see f_thread_attribute_scope_set() + */ +extern void test__f_thread_attribute_scope_set__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_attribute_scope_set() + */ +extern void test__f_thread_attribute_scope_set__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_attribute_scope_set() + */ +extern void test__f_thread_attribute_scope_set__works(void **state); + +#endif // _TEST__F_thread__attribute_scope_set_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_stack_get.c b/level_0/f_thread/tests/unit/c/test-thread-attribute_stack_get.c new file mode 100644 index 0000000..8563b6e --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-attribute_stack_get.c @@ -0,0 +1,65 @@ +#include "test-thread.h" +#include "test-thread-attribute_stack_get.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_attribute_stack_get__fails(void **state) { + + f_thread_attribute_t attribute = f_thread_attribute_t_initialize; + size_t stack_size = 2; + int stack[] = { 0, 0 }; + + int errnos[] = { + EACCES, + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_access_denied, + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 3; ++i) { + + will_return(__wrap_pthread_attr_getstack, true); + will_return(__wrap_pthread_attr_getstack, errnos[i]); + + const f_status_t status = f_thread_attribute_stack_get(attribute, &stack_size, (void *) &stack); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_attribute_stack_get__parameter_checking(void **state) { + + f_thread_attribute_t attribute = f_thread_attribute_t_initialize; + + { + const f_status_t status = f_thread_attribute_stack_get(attribute, 0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_attribute_stack_get__works(void **state) { + + f_thread_attribute_t attribute = f_thread_attribute_t_initialize; + size_t stack_size = 2; + int stack[] = { 0, 0 }; + + { + will_return(__wrap_pthread_attr_getstack, false); + + const f_status_t status = f_thread_attribute_stack_get(attribute, &stack_size, (void *) &stack); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_stack_get.h b/level_0/f_thread/tests/unit/c/test-thread-attribute_stack_get.h new file mode 100644 index 0000000..b99cf24 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-attribute_stack_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__attribute_stack_get_h +#define _TEST__F_thread__attribute_stack_get_h + +/** + * Test that function fails. + * + * @see f_thread_attribute_stack_get() + */ +extern void test__f_thread_attribute_stack_get__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_attribute_stack_get() + */ +extern void test__f_thread_attribute_stack_get__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_attribute_stack_get() + */ +extern void test__f_thread_attribute_stack_get__works(void **state); + +#endif // _TEST__F_thread__attribute_stack_get_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_stack_set.c b/level_0/f_thread/tests/unit/c/test-thread-attribute_stack_set.c new file mode 100644 index 0000000..a4cbd56 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-attribute_stack_set.c @@ -0,0 +1,79 @@ +#include "test-thread.h" +#include "test-thread-attribute_stack_set.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_attribute_stack_set__fails(void **state) { + + f_thread_attribute_t attribute = f_thread_attribute_t_initialize; + size_t stack_size = 2; + int stack[] = { 0, 0 }; + + int errnos[] = { + EACCES, + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_access_denied, + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 3; ++i) { + + will_return(__wrap_pthread_attr_setstack, true); + will_return(__wrap_pthread_attr_setstack, errnos[i]); + + const f_status_t status = f_thread_attribute_stack_set(stack_size, (void *) &stack, &attribute); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_attribute_stack_set__parameter_checking(void **state) { + + f_thread_attribute_t attribute = f_thread_attribute_t_initialize; + size_t stack_size = 2; + int stack[] = { 0, 0 }; + + { + const f_status_t status = f_thread_attribute_stack_set(stack_size, 0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_attribute_stack_set(stack_size, (void *) &stack, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_attribute_stack_set(stack_size, 0, &attribute); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_attribute_stack_set__works(void **state) { + + f_thread_attribute_t attribute = f_thread_attribute_t_initialize; + size_t stack_size = 2; + int stack[] = { 0, 0 }; + + { + will_return(__wrap_pthread_attr_setstack, false); + + const f_status_t status = f_thread_attribute_stack_set(stack_size, (void *) &stack, &attribute); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_stack_set.h b/level_0/f_thread/tests/unit/c/test-thread-attribute_stack_set.h new file mode 100644 index 0000000..c4c5cd8 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-attribute_stack_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__attribute_stack_set_h +#define _TEST__F_thread__attribute_stack_set_h + +/** + * Test that function fails. + * + * @see f_thread_attribute_stack_set() + */ +extern void test__f_thread_attribute_stack_set__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_attribute_stack_set() + */ +extern void test__f_thread_attribute_stack_set__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_attribute_stack_set() + */ +extern void test__f_thread_attribute_stack_set__works(void **state); + +#endif // _TEST__F_thread__attribute_stack_set_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_stack_size_get.c b/level_0/f_thread/tests/unit/c/test-thread-attribute_stack_size_get.c new file mode 100644 index 0000000..c677d6e --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-attribute_stack_size_get.c @@ -0,0 +1,61 @@ +#include "test-thread.h" +#include "test-thread-attribute_stack_size_get.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_attribute_stack_size_get__fails(void **state) { + + f_thread_attribute_t attribute = f_thread_attribute_t_initialize; + size_t stack_size = 2; + + 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_attr_getstacksize, true); + will_return(__wrap_pthread_attr_getstacksize, errnos[i]); + + const f_status_t status = f_thread_attribute_stack_size_get(attribute, &stack_size); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_attribute_stack_size_get__parameter_checking(void **state) { + + f_thread_attribute_t attribute = f_thread_attribute_t_initialize; + + { + const f_status_t status = f_thread_attribute_stack_size_get(attribute, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_attribute_stack_size_get__works(void **state) { + + f_thread_attribute_t attribute = f_thread_attribute_t_initialize; + size_t stack_size = 2; + + { + will_return(__wrap_pthread_attr_getstacksize, false); + + const f_status_t status = f_thread_attribute_stack_size_get(attribute, &stack_size); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_stack_size_get.h b/level_0/f_thread/tests/unit/c/test-thread-attribute_stack_size_get.h new file mode 100644 index 0000000..aa0ce7f --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-attribute_stack_size_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__attribute_stack_size_get_h +#define _TEST__F_thread__attribute_stack_size_get_h + +/** + * Test that function fails. + * + * @see f_thread_attribute_stack_size_get() + */ +extern void test__f_thread_attribute_stack_size_get__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_attribute_stack_size_get() + */ +extern void test__f_thread_attribute_stack_size_get__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_attribute_stack_size_get() + */ +extern void test__f_thread_attribute_stack_size_get__works(void **state); + +#endif // _TEST__F_thread__attribute_stack_size_get_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_stack_size_set.c b/level_0/f_thread/tests/unit/c/test-thread-attribute_stack_size_set.c new file mode 100644 index 0000000..c6fdb4e --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-attribute_stack_size_set.c @@ -0,0 +1,61 @@ +#include "test-thread.h" +#include "test-thread-attribute_stack_size_set.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_attribute_stack_size_set__fails(void **state) { + + f_thread_attribute_t attribute = f_thread_attribute_t_initialize; + size_t stack_size = 2; + + 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_attr_setstacksize, true); + will_return(__wrap_pthread_attr_setstacksize, errnos[i]); + + const f_status_t status = f_thread_attribute_stack_size_set(stack_size, &attribute); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_attribute_stack_size_set__parameter_checking(void **state) { + + size_t stack_size = 2; + + { + const f_status_t status = f_thread_attribute_stack_size_set(stack_size, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_attribute_stack_size_set__works(void **state) { + + f_thread_attribute_t attribute = f_thread_attribute_t_initialize; + size_t stack_size = 2; + + { + will_return(__wrap_pthread_attr_setstacksize, false); + + const f_status_t status = f_thread_attribute_stack_size_set(stack_size, &attribute); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-attribute_stack_size_set.h b/level_0/f_thread/tests/unit/c/test-thread-attribute_stack_size_set.h new file mode 100644 index 0000000..b450e88 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-attribute_stack_size_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__attribute_stack_size_set_h +#define _TEST__F_thread__attribute_stack_size_set_h + +/** + * Test that function fails. + * + * @see f_thread_attribute_stack_size_set() + */ +extern void test__f_thread_attribute_stack_size_set__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_attribute_stack_size_set() + */ +extern void test__f_thread_attribute_stack_size_set__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_attribute_stack_size_set() + */ +extern void test__f_thread_attribute_stack_size_set__works(void **state); + +#endif // _TEST__F_thread__attribute_stack_size_set_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-barrier_attribute_create.c b/level_0/f_thread/tests/unit/c/test-thread-barrier_attribute_create.c new file mode 100644 index 0000000..e782615 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-barrier_attribute_create.c @@ -0,0 +1,57 @@ +#include "test-thread.h" +#include "test-thread-barrier_attribute_create.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_barrier_attribute_create__fails(void **state) { + + f_thread_barrier_attribute_t attribute = f_thread_barrier_attribute_t_initialize; + + int errnos[] = { + ENOMEM, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_memory_not, + F_failure, + }; + + for (uint8_t i = 0; i < 2; ++i) { + + will_return(__wrap_pthread_barrierattr_init, true); + will_return(__wrap_pthread_barrierattr_init, errnos[i]); + + const f_status_t status = f_thread_barrier_attribute_create(&attribute); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_barrier_attribute_create__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_barrier_attribute_create(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_barrier_attribute_create__works(void **state) { + + f_thread_barrier_attribute_t attribute = f_thread_barrier_attribute_t_initialize; + + { + will_return(__wrap_pthread_barrierattr_init, false); + + const f_status_t status = f_thread_barrier_attribute_create(&attribute); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-barrier_attribute_create.h b/level_0/f_thread/tests/unit/c/test-thread-barrier_attribute_create.h new file mode 100644 index 0000000..ff2430c --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-barrier_attribute_create.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__barrier_attribute_create_h +#define _TEST__F_thread__barrier_attribute_create_h + +/** + * Test that function fails. + * + * @see f_thread_barrier_attribute_create() + */ +extern void test__f_thread_barrier_attribute_create__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_barrier_attribute_create() + */ +extern void test__f_thread_barrier_attribute_create__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_barrier_attribute_create() + */ +extern void test__f_thread_barrier_attribute_create__works(void **state); + +#endif // _TEST__F_thread__barrier_attribute_create_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-barrier_attribute_delete.c b/level_0/f_thread/tests/unit/c/test-thread-barrier_attribute_delete.c new file mode 100644 index 0000000..d3d5833 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-barrier_attribute_delete.c @@ -0,0 +1,55 @@ +#include "test-thread.h" +#include "test-thread-barrier_attribute_delete.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_barrier_attribute_delete__fails(void **state) { + + f_thread_barrier_attribute_t attribute = f_thread_barrier_attribute_t_initialize; + + int errnos[] = { + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_failure, + }; + + for (uint8_t i = 0; i < 1; ++i) { + + will_return(__wrap_pthread_barrierattr_destroy, true); + will_return(__wrap_pthread_barrierattr_destroy, errnos[i]); + + const f_status_t status = f_thread_barrier_attribute_delete(&attribute); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_barrier_attribute_delete__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_barrier_attribute_delete(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_barrier_attribute_delete__works(void **state) { + + f_thread_barrier_attribute_t attribute = f_thread_barrier_attribute_t_initialize; + + { + will_return(__wrap_pthread_barrierattr_destroy, false); + + const f_status_t status = f_thread_barrier_attribute_delete(&attribute); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-barrier_attribute_delete.h b/level_0/f_thread/tests/unit/c/test-thread-barrier_attribute_delete.h new file mode 100644 index 0000000..0c87c16 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-barrier_attribute_delete.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__barrier_attribute_delete_h +#define _TEST__F_thread__barrier_attribute_delete_h + +/** + * Test that function fails. + * + * @see f_thread_barrier_attribute_delete() + */ +extern void test__f_thread_barrier_attribute_delete__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_barrier_attribute_delete() + */ +extern void test__f_thread_barrier_attribute_delete__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_barrier_attribute_delete() + */ +extern void test__f_thread_barrier_attribute_delete__works(void **state); + +#endif // _TEST__F_thread__barrier_attribute_delete_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-barrier_attribute_shared_get.c b/level_0/f_thread/tests/unit/c/test-thread-barrier_attribute_shared_get.c new file mode 100644 index 0000000..795a461 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-barrier_attribute_shared_get.c @@ -0,0 +1,74 @@ +#include "test-thread.h" +#include "test-thread-barrier_attribute_shared_get.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_barrier_attribute_shared_get__fails(void **state) { + + f_thread_barrier_attribute_t attribute = f_thread_barrier_attribute_t_initialize; + int shared = 0; + + int errnos[] = { + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 2; ++i) { + + will_return(__wrap_pthread_barrierattr_getpshared, true); + will_return(__wrap_pthread_barrierattr_getpshared, errnos[i]); + + const f_status_t status = f_thread_barrier_attribute_shared_get(&attribute, &shared); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_barrier_attribute_shared_get__parameter_checking(void **state) { + + f_thread_barrier_attribute_t attribute = f_thread_barrier_attribute_t_initialize; + int shared = 0; + + { + const f_status_t status = f_thread_barrier_attribute_shared_get(0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_barrier_attribute_shared_get(&attribute, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } + + { + const f_status_t status = f_thread_barrier_attribute_shared_get(0, &shared); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_barrier_attribute_shared_get__works(void **state) { + + f_thread_barrier_attribute_t attribute = f_thread_barrier_attribute_t_initialize; + int shared = 0; + + { + will_return(__wrap_pthread_barrierattr_getpshared, false); + + const f_status_t status = f_thread_barrier_attribute_shared_get(&attribute, &shared); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-barrier_attribute_shared_get.h b/level_0/f_thread/tests/unit/c/test-thread-barrier_attribute_shared_get.h new file mode 100644 index 0000000..c9fbd71 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-barrier_attribute_shared_get.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__barrier_attribute_shared_get_h +#define _TEST__F_thread__barrier_attribute_shared_get_h + +/** + * Test that function fails. + * + * @see f_thread_barrier_attribute_shared_get() + */ +extern void test__f_thread_barrier_attribute_shared_get__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_barrier_attribute_shared_get() + */ +extern void test__f_thread_barrier_attribute_shared_get__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_barrier_attribute_shared_get() + */ +extern void test__f_thread_barrier_attribute_shared_get__works(void **state); + +#endif // _TEST__F_thread__barrier_attribute_shared_get_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-barrier_attribute_shared_set.c b/level_0/f_thread/tests/unit/c/test-thread-barrier_attribute_shared_set.c new file mode 100644 index 0000000..f3989cd --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-barrier_attribute_shared_set.c @@ -0,0 +1,61 @@ +#include "test-thread.h" +#include "test-thread-barrier_attribute_shared_set.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_barrier_attribute_shared_set__fails(void **state) { + + f_thread_barrier_attribute_t attribute = f_thread_barrier_attribute_t_initialize; + int shared = 0; + + int errnos[] = { + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_parameter, + F_failure, + }; + + for (uint8_t i = 0; i < 2; ++i) { + + will_return(__wrap_pthread_barrierattr_setpshared, true); + will_return(__wrap_pthread_barrierattr_setpshared, errnos[i]); + + const f_status_t status = f_thread_barrier_attribute_shared_set(shared, &attribute); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_barrier_attribute_shared_set__parameter_checking(void **state) { + + int shared = 0; + + { + const f_status_t status = f_thread_barrier_attribute_shared_set(shared, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_barrier_attribute_shared_set__works(void **state) { + + f_thread_barrier_attribute_t attribute = f_thread_barrier_attribute_t_initialize; + int shared = 0; + + { + will_return(__wrap_pthread_barrierattr_setpshared, false); + + const f_status_t status = f_thread_barrier_attribute_shared_set(shared, &attribute); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-barrier_attribute_shared_set.h b/level_0/f_thread/tests/unit/c/test-thread-barrier_attribute_shared_set.h new file mode 100644 index 0000000..9d2ef9d --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-barrier_attribute_shared_set.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Thread + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the thread project. + */ +#ifndef _TEST__F_thread__barrier_attribute_shared_set_h +#define _TEST__F_thread__barrier_attribute_shared_set_h + +/** + * Test that function fails. + * + * @see f_thread_barrier_attribute_shared_set() + */ +extern void test__f_thread_barrier_attribute_shared_set__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_barrier_attribute_shared_set() + */ +extern void test__f_thread_barrier_attribute_shared_set__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_barrier_attribute_shared_set() + */ +extern void test__f_thread_barrier_attribute_shared_set__works(void **state); + +#endif // _TEST__F_thread__barrier_attribute_shared_set_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-barrier_attributes_decimate_by.c b/level_0/f_thread/tests/unit/c/test-thread-barrier_attributes_decimate_by.c index 54c162e..0117a97 100644 --- a/level_0/f_thread/tests/unit/c/test-thread-barrier_attributes_decimate_by.c +++ b/level_0/f_thread/tests/unit/c/test-thread-barrier_attributes_decimate_by.c @@ -59,6 +59,10 @@ void test__f_thread_barrier_attributes_decimate_by__works(void **state) { } { + for (uint8_t i = 0; i < length; ++i) { + will_return(__wrap_pthread_barrierattr_destroy, false); + } // for + const f_status_t status = f_thread_barrier_attributes_decimate_by(length, &data); assert_int_equal(status, F_none); diff --git a/level_0/f_thread/tests/unit/c/test-thread-barrier_attributes_decrease_by.c b/level_0/f_thread/tests/unit/c/test-thread-barrier_attributes_decrease_by.c index fe767d6..a87ad3e 100644 --- a/level_0/f_thread/tests/unit/c/test-thread-barrier_attributes_decrease_by.c +++ b/level_0/f_thread/tests/unit/c/test-thread-barrier_attributes_decrease_by.c @@ -59,6 +59,10 @@ void test__f_thread_barrier_attributes_decrease_by__works(void **state) { } { + for (uint8_t i = 0; i < length; ++i) { + will_return(__wrap_pthread_barrierattr_destroy, false); + } // for + const f_status_t status = f_thread_barrier_attributes_decrease_by(length, &data); assert_int_equal(status, F_none); diff --git a/level_0/f_thread/tests/unit/c/test-thread-barrier_create.c b/level_0/f_thread/tests/unit/c/test-thread-barrier_create.c new file mode 100644 index 0000000..0213680 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-barrier_create.c @@ -0,0 +1,70 @@ +#include "test-thread.h" +#include "test-thread-barrier_create.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_barrier_create__fails(void **state) { + + f_thread_barrier_attribute_t attribute = f_thread_barrier_attribute_t_initialize; + f_thread_barrier_t barrier = f_thread_barrier_t_initialize; + int count = 0; + + int errnos[] = { + EAGAIN, + EBUSY, + EINVAL, + ENOMEM, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_resource_not, + F_busy, + F_parameter, + F_memory_not, + F_failure, + }; + + for (uint8_t i = 0; i < 5; ++i) { + + will_return(__wrap_pthread_barrier_init, true); + will_return(__wrap_pthread_barrier_init, errnos[i]); + + const f_status_t status = f_thread_barrier_create(count, &attribute, &barrier); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_barrier_create__parameter_checking(void **state) { + + f_thread_barrier_attribute_t attribute = f_thread_barrier_attribute_t_initialize; + int count = 0; + + { + const f_status_t status = f_thread_barrier_create(count, &attribute, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_barrier_create__works(void **state) { + + f_thread_barrier_attribute_t attribute = f_thread_barrier_attribute_t_initialize; + f_thread_barrier_t barrier = f_thread_barrier_t_initialize; + int count = 0; + + { + will_return(__wrap_pthread_barrier_init, false); + + const f_status_t status = f_thread_barrier_create(count, &attribute, &barrier); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-barrier_create.h b/level_0/f_thread/tests/unit/c/test-thread-barrier_create.h new file mode 100644 index 0000000..1a620ab --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-barrier_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__barrier_create_h +#define _TEST__F_thread__barrier_create_h + +/** + * Test that function fails. + * + * @see f_thread_barrier_create() + */ +extern void test__f_thread_barrier_create__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_barrier_create() + */ +extern void test__f_thread_barrier_create__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_barrier_create() + */ +extern void test__f_thread_barrier_create__works(void **state); + +#endif // _TEST__F_thread__barrier_create_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-barrier_delete.c b/level_0/f_thread/tests/unit/c/test-thread-barrier_delete.c new file mode 100644 index 0000000..689d946 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-barrier_delete.c @@ -0,0 +1,59 @@ +#include "test-thread.h" +#include "test-thread-barrier_delete.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_barrier_delete__fails(void **state) { + + f_thread_barrier_t barrier = f_thread_barrier_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_barrier_destroy, true); + will_return(__wrap_pthread_barrier_destroy, errnos[i]); + + const f_status_t status = f_thread_barrier_delete(&barrier); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for +} + +void test__f_thread_barrier_delete__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_barrier_delete(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_barrier_delete__works(void **state) { + + f_thread_barrier_t barrier = f_thread_barrier_t_initialize; + + { + will_return(__wrap_pthread_barrier_destroy, false); + + const f_status_t status = f_thread_barrier_delete(&barrier); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-barrier_delete.h b/level_0/f_thread/tests/unit/c/test-thread-barrier_delete.h new file mode 100644 index 0000000..6a29815 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-barrier_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__barrier_delete_h +#define _TEST__F_thread__barrier_delete_h + +/** + * Test that function fails. + * + * @see f_thread_barrier_delete() + */ +extern void test__f_thread_barrier_delete__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_barrier_delete() + */ +extern void test__f_thread_barrier_delete__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_barrier_delete() + */ +extern void test__f_thread_barrier_delete__works(void **state); + +#endif // _TEST__F_thread__barrier_delete_h diff --git a/level_0/f_thread/tests/unit/c/test-thread-barrier_wait.c b/level_0/f_thread/tests/unit/c/test-thread-barrier_wait.c new file mode 100644 index 0000000..7b66f16 --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-barrier_wait.c @@ -0,0 +1,33 @@ +#include "test-thread.h" +#include "test-thread-barrier_wait.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_thread_barrier_wait__parameter_checking(void **state) { + + { + const f_status_t status = f_thread_barrier_wait(0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_thread_barrier_wait__works(void **state) { + + f_thread_barrier_t attribute = f_thread_barrier_t_initialize; + int result = 0; + + { + will_return(__wrap_pthread_barrier_wait, false); + + const f_status_t status = f_thread_barrier_wait(&attribute, &result); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_thread/tests/unit/c/test-thread-barrier_wait.h b/level_0/f_thread/tests/unit/c/test-thread-barrier_wait.h new file mode 100644 index 0000000..3b25afb --- /dev/null +++ b/level_0/f_thread/tests/unit/c/test-thread-barrier_wait.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__barrier_wait_h +#define _TEST__F_thread__barrier_wait_h + +/** + * Test that parameter checking works as expected. + * + * @see f_thread_barrier_wait() + */ +extern void test__f_thread_barrier_wait__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_thread_barrier_wait() + */ +extern void test__f_thread_barrier_wait__works(void **state); + +#endif // _TEST__F_thread__barrier_wait_h 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 46b7bb7..94bd973 100644 --- a/level_0/f_thread/tests/unit/c/test-thread.c +++ b/level_0/f_thread/tests/unit/c/test-thread.c @@ -256,6 +256,50 @@ int main(void) { cmocka_unit_test(test__f_thread_attribute_scheduler_parameter_set__fails), cmocka_unit_test(test__f_thread_attribute_scheduler_parameter_set__works), + cmocka_unit_test(test__f_thread_attribute_scheduler_policy_get__fails), + cmocka_unit_test(test__f_thread_attribute_scheduler_policy_get__works), + + cmocka_unit_test(test__f_thread_attribute_scheduler_policy_set__fails), + cmocka_unit_test(test__f_thread_attribute_scheduler_policy_set__works), + + cmocka_unit_test(test__f_thread_attribute_scope_get__fails), + cmocka_unit_test(test__f_thread_attribute_scope_get__works), + + cmocka_unit_test(test__f_thread_attribute_scope_set__fails), + cmocka_unit_test(test__f_thread_attribute_scope_set__works), + + cmocka_unit_test(test__f_thread_attribute_stack_get__fails), + cmocka_unit_test(test__f_thread_attribute_stack_get__works), + + cmocka_unit_test(test__f_thread_attribute_stack_set__fails), + cmocka_unit_test(test__f_thread_attribute_stack_set__works), + + cmocka_unit_test(test__f_thread_attribute_stack_size_get__fails), + cmocka_unit_test(test__f_thread_attribute_stack_size_get__works), + + cmocka_unit_test(test__f_thread_attribute_stack_size_set__fails), + cmocka_unit_test(test__f_thread_attribute_stack_size_set__works), + + cmocka_unit_test(test__f_thread_barrier_attribute_create__fails), + cmocka_unit_test(test__f_thread_barrier_attribute_create__works), + + cmocka_unit_test(test__f_thread_barrier_attribute_delete__fails), + cmocka_unit_test(test__f_thread_barrier_attribute_delete__works), + + cmocka_unit_test(test__f_thread_barrier_attribute_shared_get__fails), + cmocka_unit_test(test__f_thread_barrier_attribute_shared_get__works), + + cmocka_unit_test(test__f_thread_barrier_attribute_shared_set__fails), + cmocka_unit_test(test__f_thread_barrier_attribute_shared_set__works), + + cmocka_unit_test(test__f_thread_barrier_create__fails), + cmocka_unit_test(test__f_thread_barrier_create__works), + + cmocka_unit_test(test__f_thread_barrier_delete__fails), + cmocka_unit_test(test__f_thread_barrier_delete__works), + + cmocka_unit_test(test__f_thread_barrier_wait__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), @@ -392,6 +436,31 @@ int main(void) { cmocka_unit_test(test__f_thread_attribute_scheduler_parameter_get__parameter_checking), cmocka_unit_test(test__f_thread_attribute_scheduler_parameter_set__parameter_checking), + cmocka_unit_test(test__f_thread_attribute_scheduler_policy_get__parameter_checking), + cmocka_unit_test(test__f_thread_attribute_scheduler_policy_set__parameter_checking), + + cmocka_unit_test(test__f_thread_attribute_scope_get__parameter_checking), + cmocka_unit_test(test__f_thread_attribute_scope_set__parameter_checking), + + cmocka_unit_test(test__f_thread_attribute_stack_get__parameter_checking), + cmocka_unit_test(test__f_thread_attribute_stack_set__parameter_checking), + + cmocka_unit_test(test__f_thread_attribute_stack_size_get__parameter_checking), + cmocka_unit_test(test__f_thread_attribute_stack_size_set__parameter_checking), + + cmocka_unit_test(test__f_thread_barrier_attribute_create__parameter_checking), + + cmocka_unit_test(test__f_thread_barrier_attribute_delete__parameter_checking), + + cmocka_unit_test(test__f_thread_barrier_attribute_shared_get__parameter_checking), + + cmocka_unit_test(test__f_thread_barrier_attribute_shared_set__parameter_checking), + + cmocka_unit_test(test__f_thread_barrier_create__parameter_checking), + + cmocka_unit_test(test__f_thread_barrier_delete__parameter_checking), + + cmocka_unit_test(test__f_thread_barrier_wait__parameter_checking), #endif // _di_level_0_parameter_checking_ // f_thread_user_set() doesn't use parameter checking. 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 ebef6b4..cc9259f 100644 --- a/level_0/f_thread/tests/unit/c/test-thread.h +++ b/level_0/f_thread/tests/unit/c/test-thread.h @@ -137,6 +137,21 @@ #include "test-thread-attribute_scheduler_inherit_set.h" #include "test-thread-attribute_scheduler_parameter_get.h" #include "test-thread-attribute_scheduler_parameter_set.h" +#include "test-thread-attribute_scheduler_policy_get.h" +#include "test-thread-attribute_scheduler_policy_set.h" +#include "test-thread-attribute_scope_get.h" +#include "test-thread-attribute_scope_set.h" +#include "test-thread-attribute_stack_get.h" +#include "test-thread-attribute_stack_set.h" +#include "test-thread-attribute_stack_size_get.h" +#include "test-thread-attribute_stack_size_set.h" +#include "test-thread-barrier_attribute_create.h" +#include "test-thread-barrier_attribute_delete.h" +#include "test-thread-barrier_attribute_shared_get.h" +#include "test-thread-barrier_attribute_shared_set.h" +#include "test-thread-barrier_create.h" +#include "test-thread-barrier_delete.h" +#include "test-thread-barrier_wait.h" #ifdef __cplusplus extern "C" {