From: Kevin Day Date: Sat, 23 Apr 2022 04:37:28 +0000 (-0500) Subject: Update: Add f_execute unit tests. X-Git-Tag: 0.5.10~185 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=7b17dc68edbd61059f6b6eafd3f49020b597c6c3;p=fll Update: Add f_execute unit tests. --- diff --git a/level_0/f_execute/data/build/dependencies-tests b/level_0/f_execute/data/build/dependencies-tests new file mode 100644 index 0000000..dea3179 --- /dev/null +++ b/level_0/f_execute/data/build/dependencies-tests @@ -0,0 +1,3 @@ +# fss-0001 + +cmocka 1.* diff --git a/level_0/f_execute/data/build/settings-tests b/level_0/f_execute/data/build/settings-tests new file mode 100644 index 0000000..dc8c67d --- /dev/null +++ b/level_0/f_execute/data/build/settings-tests @@ -0,0 +1,54 @@ +# 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_execute + +version_major 0 +version_minor 5 +version_micro 9 +version_file major +version_target major + +modes individual clang test +modes_default individual + +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_execute + +build_sources_program test-execute-status_from_status.c test-execute-status_to_status.c +build_sources_program test-execute.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 + +#defines -D_di_libcap_ +defines -Ibuild/includes +defines_static -Lbuild/libraries/static +defines_shared -Lbuild/libraries/shared + +flags -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-parentheses +flags-clang -Wno-logical-op-parentheses +flags-test -fstack-protector + +flags_program -fPIE diff --git a/level_0/f_execute/data/build/testfile b/level_0/f_execute/data/build/testfile new file mode 100644 index 0000000..dc84ec4 --- /dev/null +++ b/level_0/f_execute/data/build/testfile @@ -0,0 +1,44 @@ +# fss-0005 iki-0002 + +settings: + load_build yes + fail exit + + environment LD_LIBRARY_PATH + +main: + build settings-tests + + operate ld_library_path + + if exists build/programs/shared/test-f_execute + shell build/programs/shared/test-f_execute + + if exists build/programs/static/test-f_execute + shell build/programs/static/test-f_execute + + if not exists build/programs/shared/test-f_execute + and not exists build/programs/static/test-f_execute + 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 + +ld_library_path: + if defined environment LD_LIBRARY_PATH + and defined parameter work + define LD_LIBRARY_PATH 'build/libraries/shared:parameter:"work:value"libraries/shared:define:"LD_LIBRARY_PATH"' + + else + if defined environment LD_LIBRARY_PATH + define LD_LIBRARY_PATH 'build/libraries/shared:parameter:define:"LD_LIBRARY_PATH"' + + else + if defined parameter work + define LD_LIBRARY_PATH 'build/libraries/shared:parameter:"work:value"libraries/shared' + + else + define LD_LIBRARY_PATH build/libraries/shared diff --git a/level_0/f_execute/tests/unit/c/test-execute-status_from_status.c b/level_0/f_execute/tests/unit/c/test-execute-status_from_status.c new file mode 100644 index 0000000..c9ca6f2 --- /dev/null +++ b/level_0/f_execute/tests/unit/c/test-execute-status_from_status.c @@ -0,0 +1,143 @@ +#include "test-execute.h" +#include "test-execute-status_from_status.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_execute_status_from_status__fails(void **state) { + + for (f_status_t i = 0; i < F_status_code_last; ++i) { + + // Skip past all valid status codes. + if (i == F_none) continue; + if (i == F_access) continue; + if (i == F_execute_not) continue; + if (i == F_buffer) continue; + if (i == F_busy) continue; + if (i == F_capability) continue; + if (i == F_control_group) continue; + if (i == F_child) continue; + if (i == F_directory_not) continue; + if (i == F_failure) continue; + if (i == F_file_found_not) continue; + if (i == F_file_type_directory) continue; + if (i == F_fork_not) continue; + if (i == F_format_not) continue; + if (i == F_group) continue; + if (i == F_input_output) continue; + if (i == F_limit) continue; + if (i == F_loop) continue; + if (i == F_memory_not) continue; + if (i == F_name_not) continue; + if (i == F_nice) continue; + if (i == F_parameter) continue; + if (i == F_pipe) continue; + if (i == F_processor) continue; + if (i == F_prohibited) continue; + if (i == F_resource_not) continue; + if (i == F_schedule) continue; + if (i == F_terminal) continue; + if (i == F_terminal_known_not) continue; + if (i == F_terminal_not) continue; + if (i == F_terminal_prohibited) continue; + if (i == F_terminal_valid_not) continue; + if (i == F_too_large) continue; + if (i == F_user) continue; + if (i == F_valid_not) continue; + + const uint8_t execute_status = f_execute_status_from_status(i); + + assert_int_equal(execute_status, F_execute_code_last); + } // for +} + +void test__f_execute_status_from_status__works(void **state) { + + const uint8_t status_executes[] = { + F_execute_none, + F_execute_access, + F_execute_bad, + F_execute_buffer, + F_execute_busy, + F_execute_capability, + F_execute_control_group, + F_execute_child, + F_execute_directory_not, + F_execute_failure, + F_execute_file_found_not, + F_execute_file_type_directory, + F_execute_fork_not, + F_execute_format_not, + F_execute_group, + F_execute_input_output, + F_execute_limit, + F_execute_loop, + F_execute_memory_not, + F_execute_name_not, + F_execute_nice, + F_execute_parameter, + F_execute_pipe, + F_execute_processor, + F_execute_prohibited, + F_execute_resource_not, + F_execute_schedule, + F_execute_terminal, + F_execute_terminal_known_not, + F_execute_terminal_not, + F_execute_terminal_prohibited, + F_execute_terminal_valid_not, + F_execute_too_large, + F_execute_user, + F_execute_valid_not, + }; + + const f_status_t statuss[] = { + F_none, + F_access, + F_execute_not, + F_buffer, + F_busy, + F_capability, + F_control_group, + F_child, + F_directory_not, + F_failure, + F_file_found_not, + F_file_type_directory, + F_fork_not, + F_format_not, + F_group, + F_input_output, + F_limit, + F_loop, + F_memory_not, + F_name_not, + F_nice, + F_parameter, + F_pipe, + F_processor, + F_prohibited, + F_resource_not, + F_schedule, + F_terminal, + F_terminal_known_not, + F_terminal_not, + F_terminal_prohibited, + F_terminal_valid_not, + F_too_large, + F_user, + F_valid_not, + }; + + for (uint8_t i = 0; i < 35; ++i) { + + const uint8_t execute_status = f_execute_status_from_status(statuss[i]); + + assert_int_equal(execute_status, status_executes[i]); + } // for +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_execute/tests/unit/c/test-execute-status_from_status.h b/level_0/f_execute/tests/unit/c/test-execute-status_from_status.h new file mode 100644 index 0000000..0edb6ad --- /dev/null +++ b/level_0/f_execute/tests/unit/c/test-execute-status_from_status.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Execute + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the execute project. + */ +#ifndef _TEST__F_execute_status_from_status_h +#define _TEST__F_execute_status_from_status_h + +/** + * Test that function fails. + * + * @see f_execute_status_from_status() + */ +extern void test__f_execute_status_from_status__fails(void **state); + +/** + * Test that function works. + * + * @see f_execute_status_from_status() + */ +extern void test__f_execute_status_from_status__works(void **state); + +#endif // _TEST__F_execute_status_from_status_h diff --git a/level_0/f_execute/tests/unit/c/test-execute-status_to_status.c b/level_0/f_execute/tests/unit/c/test-execute-status_to_status.c new file mode 100644 index 0000000..ad14792 --- /dev/null +++ b/level_0/f_execute/tests/unit/c/test-execute-status_to_status.c @@ -0,0 +1,151 @@ +#include "test-execute.h" +#include "test-execute-status_to_status.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_execute_status_to_status__fails(void **state) { + + for (uint8_t i = 0; i < 0xff; ++i) { + + // Skip past all valid execute codes. + if (i == F_execute_none) continue; + if (i == F_execute_access) continue; + if (i == F_execute_bad) continue; + if (i == F_execute_buffer) continue; + if (i == F_execute_busy) continue; + if (i == F_execute_capability) continue; + if (i == F_execute_control_group) continue; + if (i == F_execute_child) continue; + if (i == F_execute_directory_not) continue; + if (i == F_execute_failure) continue; + if (i == F_execute_file_found_not) continue; + if (i == F_execute_file_type_directory) continue; + if (i == F_execute_fork_not) continue; + if (i == F_execute_format_not) continue; + if (i == F_execute_group) continue; + if (i == F_execute_input_output) continue; + if (i == F_execute_limit) continue; + if (i == F_execute_loop) continue; + if (i == F_execute_memory_not) continue; + if (i == F_execute_name_not) continue; + if (i == F_execute_nice) continue; + if (i == F_execute_parameter) continue; + if (i == F_execute_pipe) continue; + if (i == F_execute_processor) continue; + if (i == F_execute_prohibited) continue; + if (i == F_execute_resource_not) continue; + if (i == F_execute_schedule) continue; + if (i == F_execute_terminal) continue; + if (i == F_execute_terminal_known_not) continue; + if (i == F_execute_terminal_not) continue; + if (i == F_execute_terminal_prohibited) continue; + if (i == F_execute_terminal_valid_not) continue; + if (i == F_execute_too_large) continue; + if (i == F_execute_user) continue; + if (i == F_execute_valid_not) continue; + + const f_status_t status = f_execute_status_to_status(i); + + assert_int_equal(status, F_status_set_error(F_known_not)); + } // for +} + +void test__f_execute_status_to_status__works(void **state) { + + const uint8_t status_executes[] = { + F_execute_none, + F_execute_access, + F_execute_bad, + F_execute_buffer, + F_execute_busy, + F_execute_capability, + F_execute_control_group, + F_execute_child, + F_execute_directory_not, + F_execute_failure, + F_execute_file_found_not, + F_execute_file_type_directory, + F_execute_fork_not, + F_execute_format_not, + F_execute_group, + F_execute_input_output, + F_execute_limit, + F_execute_loop, + F_execute_memory_not, + F_execute_name_not, + F_execute_nice, + F_execute_parameter, + F_execute_pipe, + F_execute_processor, + F_execute_prohibited, + F_execute_resource_not, + F_execute_schedule, + F_execute_terminal, + F_execute_terminal_known_not, + F_execute_terminal_not, + F_execute_terminal_prohibited, + F_execute_terminal_valid_not, + F_execute_too_large, + F_execute_user, + F_execute_valid_not, + }; + + const f_status_t statuss[] = { + F_none, + F_access, + F_execute_not, + F_buffer, + F_busy, + F_capability, + F_control_group, + F_child, + F_directory_not, + F_failure, + F_file_found_not, + F_file_type_directory, + F_fork_not, + F_format_not, + F_group, + F_input_output, + F_limit, + F_loop, + F_memory_not, + F_name_not, + F_nice, + F_parameter, + F_pipe, + F_processor, + F_prohibited, + F_resource_not, + F_schedule, + F_terminal, + F_terminal_known_not, + F_terminal_not, + F_terminal_prohibited, + F_terminal_valid_not, + F_too_large, + F_user, + F_valid_not, + }; + + for (uint8_t i = 0; i < 35; ++i) { + + { + const f_status_t status = f_execute_status_to_status(status_executes[i]); + + assert_int_equal(status, statuss[i]); + } + + { + const f_status_t status = f_execute_status_to_status(status_executes[i]); + + assert_int_equal(status, statuss[i]); + } + } // for +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_execute/tests/unit/c/test-execute-status_to_status.h b/level_0/f_execute/tests/unit/c/test-execute-status_to_status.h new file mode 100644 index 0000000..d3925c2 --- /dev/null +++ b/level_0/f_execute/tests/unit/c/test-execute-status_to_status.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Execute + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the execute project. + */ +#ifndef _TEST__F_execute_status_to_status_h +#define _TEST__F_execute_status_to_status_h + +/** + * Test that function fails. + * + * @see f_execute_status_to_status() + */ +extern void test__f_execute_status_to_status__fails(void **state); + +/** + * Test that function works. + * + * @see f_execute_status_to_status() + */ +extern void test__f_execute_status_to_status__works(void **state); + +#endif // _TEST__F_execute_status_to_status_h diff --git a/level_0/f_execute/tests/unit/c/test-execute.c b/level_0/f_execute/tests/unit/c/test-execute.c new file mode 100644 index 0000000..9f5a6c0 --- /dev/null +++ b/level_0/f_execute/tests/unit/c/test-execute.c @@ -0,0 +1,40 @@ +#include "test-execute.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_execute_status_from_status__fails), + cmocka_unit_test(test__f_execute_status_from_status__works), + + cmocka_unit_test(test__f_execute_status_to_status__fails), + cmocka_unit_test(test__f_execute_status_to_status__works), + + #ifndef _di_level_0_parameter_checking_ + // f_execute_status_from_status() doesn't use parameter checking. + // f_execute_status_to_status() 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_execute/tests/unit/c/test-execute.h b/level_0/f_execute/tests/unit/c/test-execute.h new file mode 100644 index 0000000..f16af61 --- /dev/null +++ b/level_0/f_execute/tests/unit/c/test-execute.h @@ -0,0 +1,72 @@ +/** + * FLL - Level 0 + * + * Project: Execute + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the execute project. + */ +#ifndef _TEST__F_execute_h +#define _TEST__F_execute_h + +// Libc includes. +#include +#include +#include +#include + +// cmocka includes. +#include + +// FLL-0 includes. +#include + +// Mock includes. + +// Test includes. +#include "test-execute-status_from_status.h" +#include "test-execute-status_to_status.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_execute_h