From: Kevin Day Date: Fri, 29 Aug 2025 02:50:10 +0000 (-0500) Subject: Progress: Begin adding f_schedule. X-Git-Tag: 0.7.3~17 X-Git-Url: https://www.git.kevux.org/?a=commitdiff_plain;h=67519dca9dfb6b7a0b3cb06cf88c799d2d5ce25b;p=fll Progress: Begin adding f_schedule. I distantly remembered considering this in the past. I think that I need to do this now. This will be adding several of the scheduling functions. This starts with the easiest one, `nice()`. --- diff --git a/build/scripts/bootstrap-example.sh b/build/scripts/bootstrap-example.sh index 3095764..8e8e926 100644 --- a/build/scripts/bootstrap-example.sh +++ b/build/scripts/bootstrap-example.sh @@ -160,7 +160,7 @@ boostrap_process() { ${shell_command} build/scripts/package.sh ${verbose} ${color} rebuild -i if [[ ${?} -eq 0 ]] ; then - for i in f_type f_status f_memory f_type_array f_string f_utf f_abstruse f_account f_capability f_color f_compare f_console f_control_group f_conversion f_directory f_environment f_execute f_file f_fss f_iki f_limit f_network f_parse f_path f_pipe f_print f_random f_rip f_serialize f_signal f_socket f_status_string f_thread f_time fl_control_group fl_conversion fl_directory fl_environment fl_execute fl_fss fl_iki fl_path fl_print fl_status_string fl_utf_file fll_control_group fll_error fll_execute fll_file fll_fss fll_fss_status_string fll_iki fll_print fll_program ; do + for i in f_type f_status f_memory f_type_array f_string f_utf f_abstruse f_account f_capability f_color f_compare f_console f_control_group f_conversion f_directory f_environment f_execute f_file f_fss f_iki f_limit f_network f_parse f_path f_pipe f_print f_random f_rip f_schedule f_serialize f_signal f_socket f_status_string f_thread f_time fl_control_group fl_conversion fl_directory fl_environment fl_execute fl_fss fl_iki fl_path fl_print fl_status_string fl_utf_file fll_control_group fll_error fll_execute fll_file fll_fss fll_fss_status_string fll_iki fll_print fll_program ; do echo && echo "Processing ${i}." && diff --git a/build/scripts/test.sh b/build/scripts/test.sh index 953ad33..f19bf6a 100644 --- a/build/scripts/test.sh +++ b/build/scripts/test.sh @@ -72,7 +72,7 @@ test_main() { local verbose= local verbose_common= - local projects="f_type f_status f_memory f_type_array f_string f_utf f_abstruse f_account f_capability f_color f_compare f_console f_control_group f_conversion f_directory f_environment f_execute f_file f_fss f_iki f_limit f_network f_parse f_path f_pipe f_print f_random f_rip f_serialize f_signal f_socket f_status_string f_thread f_time fl_control_group fl_conversion fl_directory fl_environment fl_execute fl_fss fl_iki fl_path fl_print fl_status_string fl_utf_file fll_control_group fll_error fll_execute fll_file fll_fss fll_fss_status_string fll_iki fll_print fll_program" + local projects="f_type f_status f_memory f_type_array f_string f_utf f_abstruse f_account f_capability f_color f_compare f_console f_control_group f_conversion f_directory f_environment f_execute f_file f_fss f_iki f_limit f_network f_parse f_path f_pipe f_print f_random f_rip f_schedule f_serialize f_signal f_socket f_status_string f_thread f_time fl_control_group fl_conversion fl_directory fl_environment fl_execute fl_fss fl_iki fl_path fl_print fl_status_string fl_utf_file fll_control_group fll_error fll_execute fll_file fll_fss fll_fss_status_string fll_iki fll_print fll_program" local projects_no_tests="f_type" local programs="fss_read" diff --git a/level_0/f_schedule/c/schedule.c b/level_0/f_schedule/c/schedule.c new file mode 100644 index 0000000..067036c --- /dev/null +++ b/level_0/f_schedule/c/schedule.c @@ -0,0 +1,28 @@ +#include "schedule.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_schedule_nice_ + f_status_t f_schedule_nice(const int niceness) { + + if (niceness < -20) return F_status_set_error(F_too_small); + if (niceness > 19) return F_status_set_error(F_too_large); + + // The nice() might return -1 on error, so set and check errno instead. + errno = 0; + + if (nice(niceness) == -1) { + if (errno == EPERM) return F_status_set_error(F_prohibited); + + return F_status_set_error(F_failure); + } + + return F_okay; + } +#endif // _di_f_schedule_nice_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_schedule/c/schedule.h b/level_0/f_schedule/c/schedule.h new file mode 100644 index 0000000..554b2f2 --- /dev/null +++ b/level_0/f_schedule/c/schedule.h @@ -0,0 +1,80 @@ +/** + * FLL - Level 0 + * + * Project: Schedule + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides schedule functionality. + */ +#ifndef _F_schedule_h +#define _F_schedule_h + +// Libc includes. +#include + +// FLL-0 includes. +#include +#include + +// FLL-0 schedule includes. +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Set the niceness of the current process. + * + * The niceness affects the priority of the process for processor scheduling purposes. + * + * The RLIMIT_NICE limitation restricts how much a process can lower its niceness and therefore raise its priority. + * + * @param niceness + * The nice value to assign. + * A higher value, meaning more nice, makes the process less important in the priority (low priority). + * A lower value, meaning less nice, makes the process more important in the priority (high priority). + * + * A lower value means that the process generally gets more CPU time. + * + * The max value is 19 and the lowest value is -20. + * + * @return + * F_okay on success but no signal found. + * + * F_too_large (with error bit) if the niceness value is too large (greater than 19). + * F_too_small (with error bit) if the niceness value is too small (less than -20). + * F_prohibited (with error bit) if unable to set the requested nice value (such as when limited by RLIMIT_NICE). + * + * F_failure (with error bit) for any other error. + * + * @see nice() + */ +#ifndef _di_f_schedule_nice_ + extern f_status_t f_schedule_nice(const int niceness); +#endif // _di_f_schedule_nice_ + +/* + * @todo: add all of these: + getpriority() + setpriority() + sched_setscheduler() + sched_getscheduler() + sched_setparam() + sched_getparam() + sched_get_priority_max() + sched_get_priority_min() + sched_rr_get_interval() + sched_yield() + sched_setaffinity() + sched_getaffinity() + sched_setattr() + sched_getattr() +*/ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_schedule_h diff --git a/level_0/f_schedule/c/schedule/common.h b/level_0/f_schedule/c/schedule/common.h new file mode 100644 index 0000000..312488a --- /dev/null +++ b/level_0/f_schedule/c/schedule/common.h @@ -0,0 +1,42 @@ +/** + * FLL - Level 0 + * + * Project: Schedule + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Defines common data to be used for/by project signal. + * + * This is auto-included by schedule.h and should not need to be explicitly included. + */ +#ifndef _F_schedule_common_h +#define _F_schedule_common_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Thread scheduler policy defines. + * + * f_schedule_policy_*_d: + * - batch: Use batch style scheduling policy. + * - fifo: Use first in, first out scheduling policy. + * - idle: Use very low priority scheduling policy. + * - robin: Use round-robin style scheduling policy. + * - standard: Use standard scheduling. + */ +#ifndef _di_f_schedule_policy_d_ + #define f_schedule_policy_batch_d SCHED_BATCH + #define f_schedule_policy_fifo_d SCHED_FIFO + #define f_schedule_policy_idle_d SCHED_IDLE + #define f_schedule_policy_robin_d SCHED_RR + #define f_schedule_policy_standard_d SCHED_OTHER +#endif // _di_f_schedule_policy_d_ + + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_schedule_common_h diff --git a/level_0/f_schedule/data/build/defines b/level_0/f_schedule/data/build/defines new file mode 100644 index 0000000..4f13080 --- /dev/null +++ b/level_0/f_schedule/data/build/defines @@ -0,0 +1 @@ +# fss-0000 diff --git a/level_0/f_schedule/data/build/dependencies b/level_0/f_schedule/data/build/dependencies new file mode 100644 index 0000000..d9c4b77 --- /dev/null +++ b/level_0/f_schedule/data/build/dependencies @@ -0,0 +1,4 @@ +# fss-0000 + +f_type +f_status diff --git a/level_0/f_schedule/data/build/dependencies-tests b/level_0/f_schedule/data/build/dependencies-tests new file mode 100644 index 0000000..dea3179 --- /dev/null +++ b/level_0/f_schedule/data/build/dependencies-tests @@ -0,0 +1,3 @@ +# fss-0001 + +cmocka 1.* diff --git a/level_0/f_schedule/data/build/fakefile b/level_0/f_schedule/data/build/fakefile new file mode 100644 index 0000000..82cffd9 --- /dev/null +++ b/level_0/f_schedule/data/build/fakefile @@ -0,0 +1,20 @@ +# fss-0005 iki-0002 + +settings: + fail exit + modes individual individual_thread level monolithic clang coverage fanalyzer gcc gcc_13 test thread threadless + + environment PATH LD_LIBRARY_PATH + environment LANG LC_ALL LC_COLLATE LC_CTYPE LC_FASTMSG LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME LOCPATH NLSPATH + +main: + build + +help: + print + print context:'title'Fakefile Options for FLL Software.context:'reset' + + print + print The following operations are available\: + print " - context:'notable'help:context:'reset' Perform the help operation, printing this message." + print " - context:'notable'main:context:'reset' The default compilation using the build settings mode." diff --git a/level_0/f_schedule/data/build/settings b/level_0/f_schedule/data/build/settings new file mode 100644 index 0000000..d4ab50b --- /dev/null +++ b/level_0/f_schedule/data/build/settings @@ -0,0 +1,86 @@ +# fss-0001 +# +# Modes: +# - android: Compile on an android system (using Termux; may need modification depending on the android system). +# - clang: Use CLang rather than the default, which is generally GCC. +# - coverage: Compile for building coverage. +# - fanalyzer: Compile using GCC's -fanalyzer compile time option. +# - gcc: Use GCC specific settings. +# - gcc_13: Use GCC version 13 or greater specific settings. +# - individual: Compile using per project (individual) libraries, does not handle thread or threadless cases. +# - individual_thread: This is required when compiling in individual mode with "thread" mode. +# - level: Compile using per level libraries. +# - monolithic: Compile using per monolithic libraries. +# - test: Compile for a test, such as unit testing. +# - thread: Compile with thread support. +# - threadless: Compile without thread support. +# + +build_name f_schedule + +version_major 0 +version_minor 7 +version_micro 3 +version_file micro +version_target minor + +modes android clang coverage fanalyzer gcc gcc_13 individual individual_thread level monolithic test thread threadless +modes_default individual individual_thread thread + +build_compiler gcc +build_compiler-clang clang +build_indexer ar +build_indexer_arguments rcs +build_language c + +build_libraries_shared -lc + +build_libraries_static -l:libc.a + +build_sources_library schedule.c + +build_sources_headers schedule.h schedule/common.h + +build_script yes +build_shared yes +build_static no + +path_headers fll/level_0 +path_library_script script +path_library_shared shared +path_library_static static +path_object_script script +path_object_shared shared +path_object_static static +path_program_script script +path_program_shared shared +path_program_static static + +has_path_standard yes +preserve_path_headers yes + +search_exclusive yes +search_shared yes +search_static yes + +environment PATH LD_LIBRARY_PATH +environment LANG LC_ALL LC_COLLATE LC_CTYPE LC_FASTMSG LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME LOCPATH NLSPATH + +defines-android +defines-thread +defines-threadless + +flags -O2 -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-parentheses -Wno-missing-braces +flags -fstack-clash-protection -fno-delete-null-pointer-checks +flags -Wl,-z,nodlopen -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now +flags-android -Wno-implicit-function-declaration -Wl,-z,norelro +flags-clang -Wno-logical-op-parentheses +flags-coverage -O0 --coverage -fprofile-abs-path -fprofile-dir=build/coverage/ +flags-gcc_13 -fstrict-flex-arrays=3 +flags-test -O0 -fstack-protector-strong -Wall -Wno-missing-braces +flags-thread -pthread + +flags_library -fPIC +flags_object -fPIC +flags_program -fPIE +flags_program-android -fPIE -Wl,-z,relro diff --git a/level_0/f_schedule/data/build/settings-mocks b/level_0/f_schedule/data/build/settings-mocks new file mode 100644 index 0000000..bd7744c --- /dev/null +++ b/level_0/f_schedule/data/build/settings-mocks @@ -0,0 +1,67 @@ +# fss-0001 +# +# Build the project with appropriate mocks linked in via the dynamic linker's "--wrap" functionality. +# +# The -Wl,--wrap does not work across shared files. +# Therefore, this file is a work-around to inject the mocks into the library for testing purposes. +# This should exactly match the "settings" file, except for the additional "-Wl,--wrap" parts and the additional mock source file. +# +# The flags -o0 must be passed to prevent the compiler from optimizing away any functions being mocked (which results in the mock not happening and a real function being called). +# Alternatively, figure out which optimization that is disabled by -o0 and have that specific optimization disabled. +# + +build_name f_schedule + +version_major 0 +version_minor 7 +version_micro 3 +version_file micro +version_target minor + +modes individual clang gcc gcc_13 test coverage +modes_default individual test gcc + +build_compiler gcc +build_compiler-clang clang +build_indexer ar +build_indexer_arguments rcs +build_language c + +build_libraries -lc +build_libraries-individual -lf_memory -lf_string + +build_sources_library schedule.c ../../tests/unit/c/mock-schedule.c + +build_sources_headers schedule.h schedule/common.h + +build_script yes +build_shared yes +build_static no + +path_headers fll/level_0 +path_library_script script +path_library_shared shared +path_library_static static + +has_path_standard yes +preserve_path_headers yes + +search_exclusive yes +search_shared yes +search_static yes + +environment PATH LD_LIBRARY_PATH +environment LANG LC_ALL LC_COLLATE LC_CTYPE LC_FASTMSG LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME LOCPATH NLSPATH + +flags -O0 -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-parentheses -Wno-missing-braces +flags -fstack-clash-protection -fno-delete-null-pointer-checks +flags -Wl,-z,nodlopen -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now +flags-clang -Wno-logical-op-parentheses +flags-coverage --coverage -fprofile-abs-path -fprofile-dir=build/coverage/ +flags-gcc_13 -fstrict-flex-arrays=3 +flags-test -fstack-protector-strong -Wall -Wno-missing-braces + +flags_library -fPIC + +# Inject mocks. +flags -Wl,--wrap=nice diff --git a/level_0/f_schedule/data/build/settings-tests b/level_0/f_schedule/data/build/settings-tests new file mode 100644 index 0000000..d6096b3 --- /dev/null +++ b/level_0/f_schedule/data/build/settings-tests @@ -0,0 +1,60 @@ +# fss-0001 +# +# Builds a program that is links to the generated library and is executed to perform tests. +# +# Memory leaks in the test program can be checked for by running valgrind with this executable. +# + +build_name test-f_schedule + +version_major 0 +version_minor 7 +version_micro 3 +version_file major +version_target major + +modes individual clang gcc gcc_13 test coverage +modes_default individual test gcc + +build_compiler gcc +build_compiler-clang clang +build_indexer ar +build_indexer_arguments rcs +build_language c + +build_libraries -lc -lcmocka +build_libraries-individual -lf_memory -lf_string -lf_schedule + +build_sources_program test-schedule-nice.c +build_sources_program test-schedule.c + +build_script no +build_shared yes +build_static no + +path_headers tests/unit/c +path_sources tests/unit/c + +has_path_standard no +preserve_path_headers yes + +search_exclusive yes +search_shared yes +search_static yes + +environment PATH LD_LIBRARY_PATH +environment LANG LC_ALL LC_COLLATE LC_CTYPE LC_FASTMSG LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME LOCPATH NLSPATH + +defines -Ibuild/includes +defines_static -Lbuild/libraries/static +defines_shared -Lbuild/libraries/shared + +flags -O2 -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-parentheses -Wno-missing-braces +flags -fstack-clash-protection -fno-delete-null-pointer-checks +flags -Wl,-z,nodlopen -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now +flags-clang -Wno-logical-op-parentheses +flags-coverage -O0 --coverage -fprofile-abs-path -fprofile-dir=build/coverage/ +flags-gcc_13 -fstrict-flex-arrays=3 +flags-test -fstack-protector-strong -Wall -Wno-missing-braces + +flags_program -fPIE diff --git a/level_0/f_schedule/data/build/testfile b/level_0/f_schedule/data/build/testfile new file mode 100644 index 0000000..6317a0a --- /dev/null +++ b/level_0/f_schedule/data/build/testfile @@ -0,0 +1,73 @@ +# fss-0005 iki-0002 + +settings: + load_build yes + fail exit + + environment PATH LD_LIBRARY_PATH + environment LANG LC_ALL LC_COLLATE LC_CTYPE LC_FASTMSG LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME LOCPATH NLSPATH + environment CMOCKA_XML_FILE CMOCKA_MESSAGE_OUTPUT CMOCKA_TEST_ABORT + + # Cmocka is not fully thread-safe, set this to "1" to have cmocka call abort() on a test failure. + #define CMOCKA_TEST_ABORT 1 + + # One of: STDOUT, SUBUNIT, TAP, or XML. + #define CMOCKA_MESSAGE_OUTPUT STDOUT + + # When in "XML" output mode, output to this file rather than stdout. + #define CMOCKA_XML_FILE ./out.xml + +main: + build settings-mocks individual test + build settings-tests individual test + + operate build_path + operate ld_library_path + + if exist parameter:"build_path"programs/shared/test-f_schedule + shell parameter:"build_path"programs/shared/test-f_schedule + + if exist parameter:"build_path"programs/static/test-f_schedule + shell parameter:"build_path"programs/static/test-f_schedule + + if not exist parameter:"build_path"programs/shared/test-f_schedule + and not exist parameter:"build_path"programs/static/test-f_schedule + operate not_created + +not_created: + print + print 'context:"error"Failed to test due to being unable to find either a shared or static test binary to perform tests. context:"reset"' + + exit failure + +build_path: + parameter build_path build/ + + if parameter build:value + parameter build_path parameter:"build:value" + +ld_library_path: + if define LD_LIBRARY_PATH + and parameter work:value + define LD_LIBRARY_PATH 'parameter:"build_path"libraries/shared:parameter:"work:value"libraries/shared:define:"LD_LIBRARY_PATH"' + + else + if define LD_LIBRARY_PATH + define LD_LIBRARY_PATH 'parameter:"build_path"libraries/shared:define:"LD_LIBRARY_PATH"' + + else + if parameter work:value + define LD_LIBRARY_PATH 'parameter:"build_path"libraries/shared:parameter:"work:value"libraries/shared' + + else + define LD_LIBRARY_PATH 'parameter:"build_path"libraries/shared' + +help: + print + print context:'title'Fakefile Options for FLL Software Testing.context:'reset' + print + + print + print The following operations are available\: + print " - context:'notable'help:context:'reset' Perform the help operation, printing this message." + print " - context:'notable'main:context:'reset' Build and run the tests." diff --git a/level_0/f_schedule/tests/unit/c/mock-schedule.c b/level_0/f_schedule/tests/unit/c/mock-schedule.c new file mode 100644 index 0000000..573833e --- /dev/null +++ b/level_0/f_schedule/tests/unit/c/mock-schedule.c @@ -0,0 +1,22 @@ +#include "mock-schedule.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int __wrap_nice(int inc) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return -1; + } + + return 0; +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_schedule/tests/unit/c/mock-schedule.h b/level_0/f_schedule/tests/unit/c/mock-schedule.h new file mode 100644 index 0000000..23d2888 --- /dev/null +++ b/level_0/f_schedule/tests/unit/c/mock-schedule.h @@ -0,0 +1,37 @@ +/** + * FLL - Level 0 + * + * Project: Schedule + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the schedule project. + */ +#ifndef _MOCK__schedule_h +#define _MOCK__schedule_h + +// Libc includes. +#include +#include +#include +#include + +// cmocka includes. +#include + +// FLL-0 includes. +#include + +#ifdef __cplusplus +extern "C" { +#endif + +const static int mock_errno_generic = 32767; + +extern int __wrap_nice(int inc); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _MOCK__schedule_h diff --git a/level_0/f_schedule/tests/unit/c/test-schedule-nice.c b/level_0/f_schedule/tests/unit/c/test-schedule-nice.c new file mode 100644 index 0000000..0ca6c9b --- /dev/null +++ b/level_0/f_schedule/tests/unit/c/test-schedule-nice.c @@ -0,0 +1,72 @@ +#include "test-schedule.h" +#include "test-schedule-nice.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_schedule_nice__fails(void **state) { + + const int niceness = 1; + + { + int errnos[] = { + EPERM, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_prohibited, + F_failure, + }; + + for (int i = 0; i < 2; ++i) { + + will_return(__wrap_nice, true); + will_return(__wrap_nice, errnos[i]); + + const f_status_t status = f_schedule_nice(niceness); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for + } +} + +void test__f_schedule_nice__returns_too_large(void **state) { + + const int niceness = 100; + + { + const f_status_t status = f_schedule_nice(niceness); + + assert_int_equal(status, F_status_set_error(F_too_large)); + } +} + +void test__f_schedule_nice__returns_too_small(void **state) { + + const int niceness = -100; + + { + const f_status_t status = f_schedule_nice(niceness); + + assert_int_equal(status, F_status_set_error(F_too_small)); + } +} + +void test__f_schedule_nice__works(void **state) { + + const int niceness = 1; + + { + will_return(__wrap_nice, false); + + const f_status_t status = f_schedule_nice(niceness); + + assert_int_equal(status, F_okay); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_schedule/tests/unit/c/test-schedule-nice.h b/level_0/f_schedule/tests/unit/c/test-schedule-nice.h new file mode 100644 index 0000000..3c9a253 --- /dev/null +++ b/level_0/f_schedule/tests/unit/c/test-schedule-nice.h @@ -0,0 +1,41 @@ +/** + * FLL - Level 0 + * + * Project: Schedule + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the schedule project. + */ +#ifndef _TEST__F_schedule_nice_h +#define _TEST__F_schedule_nice_h + +/** + * Test that function fails. + * + * @see f_schedule_nice() + */ +extern void test__f_schedule_nice__fails(void **state); + +/** + * Test that function returns F_too_large. + * + * @see f_schedule_nice() + */ +extern void test__f_schedule_nice__returns_too_large(void **state); + +/** + * Test that function returns F_too_small. + * + * @see f_schedule_nice() + */ +extern void test__f_schedule_nice__returns_too_small(void **state); + +/** + * Test that function works. + * + * @see f_schedule_nice() + */ +extern void test__f_schedule_nice__works(void **state); + +#endif // _TEST__F_schedule_nice_h diff --git a/level_0/f_schedule/tests/unit/c/test-schedule.c b/level_0/f_schedule/tests/unit/c/test-schedule.c new file mode 100644 index 0000000..ca39255 --- /dev/null +++ b/level_0/f_schedule/tests/unit/c/test-schedule.c @@ -0,0 +1,38 @@ +#include "test-schedule.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int setup(void **state) { + + return 0; +} + +int setdown(void **state) { + + errno = 0; + + return 0; +} + +int main(void) { + + const struct CMUnitTest tests[] = { + cmocka_unit_test(test__f_schedule_nice__fails), + cmocka_unit_test(test__f_schedule_nice__works), + + cmocka_unit_test(test__f_schedule_nice__returns_too_large), + cmocka_unit_test(test__f_schedule_nice__returns_too_small), + + #ifndef _di_level_0_parameter_checking_ + // f_schedule_nice() doesn't use parameter checking. + #endif // _di_level_0_parameter_checking_ + }; + + return cmocka_run_group_tests(tests, setup, setdown); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_schedule/tests/unit/c/test-schedule.h b/level_0/f_schedule/tests/unit/c/test-schedule.h new file mode 100644 index 0000000..466b529 --- /dev/null +++ b/level_0/f_schedule/tests/unit/c/test-schedule.h @@ -0,0 +1,72 @@ +/** + * FLL - Level 0 + * + * Project: Schedule + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the schedule project. + */ +#ifndef _TEST__F_schedule_h +#define _TEST__F_schedule_h + +// Libc includes. +#include +#include +#include +#include + +// cmocka includes. +#include + +// FLL-0 includes. +#include + +// Mock includes. +#include "mock-schedule.h" + +// Test includes. +#include "test-schedule-nice.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Perform any setup operations. + * + * @param state + * The test state. + * + * @return + * The status of this function, where 0 means success. + */ +extern int setup(void **state); + +/** + * Peform any setdown operations. + * + * @param state + * The test state. + * + * @return + * The status of this function, where 0 means success. + */ +extern int setdown(void **state); + +/** + * Run all tests. + * + * @return + * The final result of the tests. + * + * @see cmocka_run_group_tests() + * @see cmocka_unit_test() + */ +extern int main(void); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _TEST__F_schedule_h