From cc72b58b392bde2d015c894f97a3c8cb9c102e1e Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Tue, 20 Jun 2023 21:58:22 -0500 Subject: [PATCH] Feature: Add f_network level 0 project, starting with host to/from network byte order functions. As with most such level 0 projects these are just wrappers to the standard htonl() and similar functions. This also updates the build settings and other related files. The f_type_array also has some problems in the level and monolithic build settings fixed. --- build/disable/about.txt | 4 +- build/level_0/settings | 9 +- build/monolithic/settings | 5 +- build/scripts/bootstrap-example.sh | 2 +- build/scripts/test.sh | 2 +- level_0/f_network/c/network.c | 57 +++++++++++ level_0/f_network/c/network.h | 106 +++++++++++++++++++++ level_0/f_network/data/build/defines | 1 + level_0/f_network/data/build/dependencies | 4 + level_0/f_network/data/build/dependencies-tests | 3 + level_0/f_network/data/build/fakefile | 12 +++ level_0/f_network/data/build/settings | 71 ++++++++++++++ level_0/f_network/data/build/settings-mocks | 54 +++++++++++ level_0/f_network/data/build/settings-tests | 54 +++++++++++ level_0/f_network/data/build/testfile | 63 ++++++++++++ level_0/f_network/tests/unit/c/mock-network.c | 29 ++++++ level_0/f_network/tests/unit/c/mock-network.h | 40 ++++++++ .../tests/unit/c/test-network-from_host_long.c | 34 +++++++ .../tests/unit/c/test-network-from_host_long.h | 27 ++++++ .../tests/unit/c/test-network-from_host_short.c | 34 +++++++ .../tests/unit/c/test-network-from_host_short.h | 27 ++++++ .../tests/unit/c/test-network-to_host_long.c | 34 +++++++ .../tests/unit/c/test-network-to_host_long.h | 27 ++++++ .../tests/unit/c/test-network-to_host_short.c | 34 +++++++ .../tests/unit/c/test-network-to_host_short.h | 27 ++++++ level_0/f_network/tests/unit/c/test-network.c | 40 ++++++++ level_0/f_network/tests/unit/c/test-network.h | 76 +++++++++++++++ 27 files changed, 866 insertions(+), 10 deletions(-) create mode 100644 level_0/f_network/c/network.c create mode 100644 level_0/f_network/c/network.h create mode 100644 level_0/f_network/data/build/defines create mode 100644 level_0/f_network/data/build/dependencies create mode 100644 level_0/f_network/data/build/dependencies-tests create mode 100644 level_0/f_network/data/build/fakefile create mode 100644 level_0/f_network/data/build/settings create mode 100644 level_0/f_network/data/build/settings-mocks create mode 100644 level_0/f_network/data/build/settings-tests create mode 100644 level_0/f_network/data/build/testfile create mode 100644 level_0/f_network/tests/unit/c/mock-network.c create mode 100644 level_0/f_network/tests/unit/c/mock-network.h create mode 100644 level_0/f_network/tests/unit/c/test-network-from_host_long.c create mode 100644 level_0/f_network/tests/unit/c/test-network-from_host_long.h create mode 100644 level_0/f_network/tests/unit/c/test-network-from_host_short.c create mode 100644 level_0/f_network/tests/unit/c/test-network-from_host_short.h create mode 100644 level_0/f_network/tests/unit/c/test-network-to_host_long.c create mode 100644 level_0/f_network/tests/unit/c/test-network-to_host_long.h create mode 100644 level_0/f_network/tests/unit/c/test-network-to_host_short.c create mode 100644 level_0/f_network/tests/unit/c/test-network-to_host_short.h create mode 100644 level_0/f_network/tests/unit/c/test-network.c create mode 100644 level_0/f_network/tests/unit/c/test-network.h diff --git a/build/disable/about.txt b/build/disable/about.txt index f36558e..4600eb9 100644 --- a/build/disable/about.txt +++ b/build/disable/about.txt @@ -33,11 +33,11 @@ Consider the following example using the fake dependencies for the stand alone b # echo $(cat level_3/fake/data/build/dependencies) Which prints: - # fss-0000 f_type f_status f_memory f_type_array f_string f_utf f_account f_capability f_color f_console f_control_group f_conversion f_directory f_environment f_execute f_file f_fss f_iki f_limit f_path f_pipe f_print f_signal fl_control_group fl_conversion fl_directory fl_environment fl_execute fl_fss fl_iki fl_print fl_string fll_error fll_execute fll_file fll_fss fll_path fll_print fll_program + # fss-0000 f_type f_status f_memory f_type_array f_string f_utf f_account f_capability f_color f_console f_control_group f_conversion f_directory f_environment f_execute f_file f_fss f_iki f_limit f_network f_path f_pipe f_print f_signal fl_control_group fl_conversion fl_directory fl_environment fl_execute fl_fss fl_iki fl_print fl_string fll_error fll_execute fll_file fll_fss fll_path fll_print fll_program From this list, build the level_0: -# for i in f_type f_status f_memory f_type_array f_string f_utf f_account f_capability f_color f_console f_control_group f_conversion f_directory f_environment f_execute f_file f_fss f_iki f_limit f_path f_pipe f_print f_signal ; do if [[ -f build/disable/level_0/$i.h ]] ; then echo >> build/stand_alone/fake.config.h && cat build/disable/level_0/$i.h >> build/stand_alone/fake.config.h ; fi ; done +# for i in f_type f_status f_memory f_type_array f_string f_utf f_account f_capability f_color f_console f_control_group f_conversion f_directory f_environment f_execute f_file f_fss f_iki f_limit f_network f_path f_pipe f_print f_signal ; do if [[ -f build/disable/level_0/$i.h ]] ; then echo >> build/stand_alone/fake.config.h && cat build/disable/level_0/$i.h >> build/stand_alone/fake.config.h ; fi ; done From the list, build the level_1: diff --git a/build/level_0/settings b/build/level_0/settings index f01bb55..8a29bfa 100644 --- a/build/level_0/settings +++ b/build/level_0/settings @@ -48,6 +48,7 @@ build_sources_library fss.c private-fss.c fss/common.c fss/named.c fss/nest.c fs build_sources_library iki.c iki/common.c iki/data.c private-iki.c iki/private-data.c build_sources_library limit.c limit/set.c limit/value.c limit/private-set.c limit/private-value.c build_sources_library memory.c private-memory.c memory/structure.c +build_sources_library network.c build_sources_library parse.c parse/utf.c build_sources_library path.c private-path.c path/common.c build_sources_library pipe.c @@ -73,7 +74,7 @@ build_sources_library string/range.c string/ranges.c string/rangess.c build_sources_library string/static.c string/statics.c string/staticss.c build_sources_library string/triple.c string/triples.c string/tripless.c build_sources_library type_array/cell.c type_array/fll_id.c type_array/int8.c type_array/int16.c type_array/int32.c type_array/int64.c type_array/int128.c type_array/number_unsigned.c type_array/state.c type_array/status.c type_array/uint8.c type_array/uint16.c type_array/uint32.c type_array/uint64.c type_array/uint128.c -build_sources_library type_array/private-cell.c type_array/private-fll_id.c type_array/private-int8.c type_array/private-int16.c type_array/private-int32.c type_array/private-int64.c type_array/private-int128.c type_array/private-number_unsinged.c type_array/private-state.c type_array/private-status.c type_array/private-uint8.c type_array/private-uint16.c type_array/private-uint32.c type_array/private-uint64.c type_array/private-uint128.c +build_sources_library type_array/private-cell.c type_array/private-fll_id.c type_array/private-int8.c type_array/private-int16.c type_array/private-int32.c type_array/private-int64.c type_array/private-int128.c type_array/private-number_unsigned.c type_array/private-state.c type_array/private-status.c type_array/private-uint8.c type_array/private-uint16.c type_array/private-uint32.c type_array/private-uint64.c type_array/private-uint128.c build_sources_library utf.c private-utf.c private-utf_alphabetic.c private-utf_combining.c private-utf_control.c private-utf_digit.c private-utf_emoji.c private-utf_numeric.c private-utf_phonetic.c private-utf_private.c private-utf_punctuation.c private-utf_subscript.c private-utf_superscript.c private-utf_symbol.c private-utf_unassigned.c private-utf_valid.c private-utf_whitespace.c private-utf_wide.c private-utf_word.c private-utf_zero_width.c build_sources_library utf/common.c utf/convert.c build_sources_library utf/dynamic.c utf/dynamics.c utf/dynamicss.c @@ -82,7 +83,7 @@ build_sources_library utf/map.c utf/maps.c utf/mapss.c build_sources_library utf/map_multi.c utf/map_multis.c utf/map_multiss.c build_sources_library utf/static.c utf/statics.c utf/staticss.c build_sources_library utf/string.c utf/triple.c utf/triples.c utf/tripless.c -build_sources_library utf/private-dynamic.c utf/private-dynamics.c utf/private-dynamicss.c +build_sources_library utf/private-dynamic.c utf/private-dynamics.c utf/private-dynamicss.c build_sources_library utf/private-maps.c utf/private-mapss.c build_sources_library utf/private-map_multis.c utf/private-map_multiss.c build_sources_library utf/private-string.c @@ -105,6 +106,7 @@ build_sources_headers fss.h fss/comment.h fss/common.h fss/delimit.h fss/named.h build_sources_headers iki.h iki/common.h iki/data.h build_sources_headers limit.h limit/set.h limit/value.h build_sources_headers memory.h memory/structure.h memory/common.h +build_sources_headers network.h build_sources_headers parse.h parse/utf.h build_sources_headers path.h path/common.h build_sources_headers pipe.h @@ -124,8 +126,7 @@ build_sources_headers string/range.h string/ranges.h string/rangess.h build_sources_headers string/static.h string/statics.h string/staticss.h build_sources_headers string/triple.h string/triples.h string/tripless.h build_sources_headers type.h type_file.h -build_sources_headers type_array.h type_array/common.h -build_sources_headers type_array/cell.h type_array/fll_id.h type_array/int8.h type_array/int16.h type_array/int32.h type_array/int64.h type_array/int128.h type_array/number_unsigned.h type_array/state.h type_array/status.h type_array/uint8.h type_array/uint16.h type_array/uint32.h type_array/uint64.h type_array/uint128.h +build_sources_headers type_array.h type_array/common.h type_array/cell.h type_array/fll_id.h type_array/int8.h type_array/int16.h type_array/int32.h type_array/int64.h type_array/int128.h type_array/number_unsigned.h type_array/state.h type_array/status.h type_array/uint8.h type_array/uint16.h type_array/uint32.h type_array/uint64.h type_array/uint128.h build_sources_headers utf.h utf/common.h utf/convert.h utf/dynamic.h utf/dynamics.h utf/dynamicss.h utf/is.h utf/is_character.h utf/map.h utf/maps.h utf/mapss.h utf/map_multi.h utf/map_multis.h utf/map_multiss.h utf/static.h utf/statics.h utf/staticss.h utf/string.h utf/triple.h utf/triples.h utf/tripless.h build_sources_headers-thread thread.h thread/attribute.h thread/barrier.h thread/barrier_attribute.h thread/condition.h thread/condition_attribute.h thread/id.h thread/key.h thread/lock.h thread/lock_attribute.h thread/mutex.h thread/mutex_attribute.h thread/once.h thread/semaphore.h thread/set.h thread/spin.h diff --git a/build/monolithic/settings b/build/monolithic/settings index e00dc31..8a15e3d 100644 --- a/build/monolithic/settings +++ b/build/monolithic/settings @@ -48,6 +48,7 @@ build_sources_library level_0/fss.c level_0/private-fss.c level_0/fss/common.c l build_sources_library level_0/iki.c level_0/iki/common.c level_0/iki/data.c level_0/private-iki.c level_0/iki/private-data.c build_sources_library level_0/limit.c level_0/limit/set.c level_0/limit/value.c level_0/limit/private-set.c level_0/limit/private-value.c build_sources_library level_0/memory.c level_0/private-memory.c level_0/memory/structure.c +build_sources_library level_0/network.c build_sources_library level_0/parse.c level_0/parse/utf.c build_sources_library level_0/path.c level_0/private-path.c level_0/path/common.c build_sources_library level_0/pipe.c @@ -127,6 +128,7 @@ build_sources_headers level_0/fss.h level_0/fss/comment.h level_0/fss/common.h l build_sources_headers level_0/iki.h level_0/iki/common.h level_0/iki/data.h build_sources_headers level_0/limit.h level_0/limit/set.h level_0/limit/value.h build_sources_headers level_0/memory.h level_0/memory/structure.h level_0/memory/common.h +build_sources_headers level_0/network.h build_sources_headers level_0/parse.h level_0/parse/utf.h build_sources_headers level_0/path.h level_0/path/common.h build_sources_headers level_0/pipe.h @@ -146,8 +148,7 @@ build_sources_headers level_0/string/range.h level_0/string/ranges.h level_0/str build_sources_headers level_0/string/static.h level_0/string/statics.h level_0/string/staticss.h build_sources_headers level_0/string/triple.h level_0/string/triples.h level_0/string/tripless.h build_sources_headers level_0/type.h level_0/type_file.h -build_sources_headers level_0/type_array.h level_0/type_array/common.h -build_sources_headers level_0/type_array/cell.h level_0/type_array/fll_id.h level_0/type_array/int8.h level_0/type_array/int16.h level_0/type_array/int32.h level_0/type_array/int64.h level_0/type_array/int128.h level_0/type_array/number_unsigned.h level_0/type_array/state.h level_0/type_array/status.h level_0/type_array/uint8.h level_0/type_array/uint16.h level_0/type_array/uint32.h level_0/type_array/uint64.h level_0/type_array/uint128.h +build_sources_headers level_0/type_array.h level_0/type_array/common.h level_0/type_array/cell.h level_0/type_array/fll_id.h level_0/type_array/int8.h level_0/type_array/int16.h level_0/type_array/int32.h level_0/type_array/int64.h level_0/type_array/int128.h level_0/type_array/number_unsigned.h level_0/type_array/state.h level_0/type_array/status.h level_0/type_array/uint8.h level_0/type_array/uint16.h level_0/type_array/uint32.h level_0/type_array/uint64.h level_0/type_array/uint128.h build_sources_headers level_0/utf.h level_0/utf/common.h level_0/utf/convert.h level_0/utf/dynamic.h level_0/utf/dynamics.h level_0/utf/dynamicss.h level_0/utf/is.h level_0/utf/is_character.h level_0/utf/map.h level_0/utf/maps.h level_0/utf/mapss.h level_0/utf/map_multi.h level_0/utf/map_multis.h level_0/utf/map_multiss.h level_0/utf/static.h level_0/utf/statics.h level_0/utf/staticss.h level_0/utf/string.h level_0/utf/triple.h level_0/utf/triples.h level_0/utf/tripless.h build_sources_headers level_1/control_group.h diff --git a/build/scripts/bootstrap-example.sh b/build/scripts/bootstrap-example.sh index 095c49d..7398f55 100644 --- a/build/scripts/bootstrap-example.sh +++ b/build/scripts/bootstrap-example.sh @@ -130,7 +130,7 @@ if [[ ${1} == "individual" ]] ; then ${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_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_parse f_path f_pipe f_print f_rip f_status_string f_serialize f_signal f_socket f_thread fl_control_group fl_conversion fl_directory fl_environment fl_execute fl_fss fl_iki fl_path fl_print fl_signal 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_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_rip f_status_string f_serialize f_signal f_socket f_thread fl_control_group fl_conversion fl_directory fl_environment fl_execute fl_fss fl_iki fl_path fl_print fl_signal 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}." && cd package/individual/${i}-${version}/ && diff --git a/build/scripts/test.sh b/build/scripts/test.sh index 2c7df59..2d20b75 100644 --- a/build/scripts/test.sh +++ b/build/scripts/test.sh @@ -71,7 +71,7 @@ test_main() { local verbose= local verbose_common= - local projects="f_type f_status f_memory f_type_array f_string f_utf 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_parse f_path f_pipe f_print f_rip f_serialize f_signal f_socket f_status_string f_thread fl_control_group fl_conversion fl_directory fl_environment fl_execute fl_fss fl_iki fl_path fl_print fl_signal 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_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_rip f_serialize f_signal f_socket f_status_string f_thread fl_control_group fl_conversion fl_directory fl_environment fl_execute fl_fss fl_iki fl_path fl_print fl_signal 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_network/c/network.c b/level_0/f_network/c/network.c new file mode 100644 index 0000000..5d0389e --- /dev/null +++ b/level_0/f_network/c/network.c @@ -0,0 +1,57 @@ +#include "network.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_network_from_host_long_ + f_status_t f_network_from_host_long(const uint32_t from, uint32_t *to) { + #ifndef _di_level_0_parameter_checking_ + if (!to) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + *to = htonl(from); + + return F_none; + } +#endif // _di_f_network_from_host_long_ + +#ifndef _di_f_network_from_host_short_ + f_status_t f_network_from_host_short(const uint16_t from, uint16_t *to) { + #ifndef _di_level_0_parameter_checking_ + if (!to) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + *to = htons(from); + + return F_none; + } +#endif // _di_f_network_from_host_short_ + +#ifndef _di_f_network_to_host_long_ + f_status_t f_network_to_host_long(const uint32_t from, uint32_t *to) { + #ifndef _di_level_0_parameter_checking_ + if (!to) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + *to = ntohl(from); + + return F_none; + } +#endif // _di_f_network_to_host_long_ + +#ifndef _di_f_network_to_host_short_ + f_status_t f_network_to_host_short(const uint16_t from, uint16_t *to) { + #ifndef _di_level_0_parameter_checking_ + if (!to) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + *to = ntohs(from); + + return F_none; + } +#endif // _di_f_network_to_host_short_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_network/c/network.h b/level_0/f_network/c/network.h new file mode 100644 index 0000000..d782371 --- /dev/null +++ b/level_0/f_network/c/network.h @@ -0,0 +1,106 @@ +/** + * FLL - Level 0 + * + * Project: Network + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides network related functionality. + */ +#ifndef _F_network_h +#define _F_network_h + +// Libc includes. +#include + +// FLL-0 includes. +#include +#include + +// FLL-0 network includes. + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Convert from host byte order to network byte order for an unsigned long integer. + * + * @param from + * The long integer in host byte order. + * @param to + * The converted long integer in network byte order. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * @see htonl() + */ +#ifndef _di_f_network_from_host_long_ + extern f_status_t f_network_from_host_long(const uint32_t from, uint32_t *to); +#endif // _di_f_network_from_host_long_ + +/** + * Convert from host byte order to network byte order for an unsigned short integer. + * + * @param from + * The short integer in host byte order. + * @param to + * The converted short integer in network byte order. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * @see htons() + */ +#ifndef _di_f_network_from_host_short_ + extern f_status_t f_network_from_host_short(const uint16_t from, uint16_t *to); +#endif // _di_f_network_from_host_short_ + +/** + * Convert from network byte order to host byte order for an unsigned long integer. + * + * @param from + * The long integer in network byte order. + * @param to + * The converted long integer in host byte order. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * @see ntohl() + */ +#ifndef _di_f_network_to_host_long_ + extern f_status_t f_network_to_host_long(const uint32_t from, uint32_t *to); +#endif // _di_f_network_to_host_long_ + +/** + * Convert from network byte order to host byte order for an unsigned short integer. + * + * @param from + * The short integer in network byte order. + * @param to + * The converted short integer in host byte order. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * @see ntohs() + */ +#ifndef _di_f_network_to_host_short_ + extern f_status_t f_network_to_host_short(const uint16_t from, uint16_t *to); +#endif // _di_f_network_to_host_short_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_network_h diff --git a/level_0/f_network/data/build/defines b/level_0/f_network/data/build/defines new file mode 100644 index 0000000..4f13080 --- /dev/null +++ b/level_0/f_network/data/build/defines @@ -0,0 +1 @@ +# fss-0000 diff --git a/level_0/f_network/data/build/dependencies b/level_0/f_network/data/build/dependencies new file mode 100644 index 0000000..d9c4b77 --- /dev/null +++ b/level_0/f_network/data/build/dependencies @@ -0,0 +1,4 @@ +# fss-0000 + +f_type +f_status diff --git a/level_0/f_network/data/build/dependencies-tests b/level_0/f_network/data/build/dependencies-tests new file mode 100644 index 0000000..dea3179 --- /dev/null +++ b/level_0/f_network/data/build/dependencies-tests @@ -0,0 +1,3 @@ +# fss-0001 + +cmocka 1.* diff --git a/level_0/f_network/data/build/fakefile b/level_0/f_network/data/build/fakefile new file mode 100644 index 0000000..90a7134 --- /dev/null +++ b/level_0/f_network/data/build/fakefile @@ -0,0 +1,12 @@ +# fss-0005 iki-0002 + +settings: + fail exit + modes individual individual_thread level monolithic clang test fanalyzer 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 diff --git a/level_0/f_network/data/build/settings b/level_0/f_network/data/build/settings new file mode 100644 index 0000000..eb683e4 --- /dev/null +++ b/level_0/f_network/data/build/settings @@ -0,0 +1,71 @@ +# fss-0001 +# +# Modes: +# - 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. +# - clang: Use clang rather than the default, which is generally gcc. +# - test: Compile for a test, such as unit testing. +# - fanalyzer: Compile using GCC's -fanalyzer compile time option. +# - thread: Compile with thread support. +# - threadless: Compile without thread support. +# + +build_name f_network + +version_major 0 +version_minor 7 +version_micro 0 +version_file micro +version_target minor + +modes individual individual_thread level monolithic clang test fanalyzer 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 -lc +build_libraries-individual + +build_sources_library network.c + +build_sources_headers network.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 + +flags -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-parentheses +flags-clang -Wno-logical-op-parentheses +flags-test -O0 -fstack-protector -Wall +flags-coverage -O0 --coverage -fprofile-abs-path -fprofile-dir=build/coverage/ + +flags_library -fPIC +flags_object -fPIC +flags_program -fPIE diff --git a/level_0/f_network/data/build/settings-mocks b/level_0/f_network/data/build/settings-mocks new file mode 100644 index 0000000..6a70870 --- /dev/null +++ b/level_0/f_network/data/build/settings-mocks @@ -0,0 +1,54 @@ +# fss-0001 + +build_name f_network + +version_major 0 +version_minor 7 +version_micro 0 +version_file micro +version_target minor + +modes individual clang test coverage +modes_default individual test + +build_compiler gcc +build_compiler-clang clang +build_indexer ar +build_indexer_arguments rcs +build_language c + +build_libraries -lc +build_libraries-individual + +build_sources_library network.c ../../tests/unit/c/mock-network.c + +build_sources_headers network.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 + +flags -O0 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-parentheses +flags-clang -Wno-logical-op-parentheses +flags-test -fstack-protector -Wall +flags-coverage --coverage -fprofile-abs-path -fprofile-dir=build/coverage/ + +flags_library -fPIC + +# Inject mocks. +flags -Wl,--wrap=htonl +flags -Wl,--wrap=htons +flags -Wl,--wrap=ntohl +flags -Wl,--wrap=ntohs diff --git a/level_0/f_network/data/build/settings-tests b/level_0/f_network/data/build/settings-tests new file mode 100644 index 0000000..ce8bc65 --- /dev/null +++ b/level_0/f_network/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_network + +version_major 0 +version_minor 7 +version_micro 0 +version_file major +version_target major + +modes individual clang test coverage +modes_default individual test + +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_network + +build_sources_program test-network-from_host_long.c test-network-from_host_short.c test-network-to_host_long.c test-network-to_host_short.c +build_sources_program test-network.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 -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 -Wall +flags-coverage -O0 --coverage -fprofile-abs-path -fprofile-dir=build/coverage/ + +flags_program -fPIE diff --git a/level_0/f_network/data/build/testfile b/level_0/f_network/data/build/testfile new file mode 100644 index 0000000..a21828e --- /dev/null +++ b/level_0/f_network/data/build/testfile @@ -0,0 +1,63 @@ +# 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. + #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_network + shell parameter:"build_path"programs/shared/test-f_network + + if exist parameter:"build_path"programs/static/test-f_network + shell parameter:"build_path"programs/static/test-f_network + + if not exist parameter:"build_path"programs/shared/test-f_network + and not exist parameter:"build_path"programs/static/test-f_network + 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' diff --git a/level_0/f_network/tests/unit/c/mock-network.c b/level_0/f_network/tests/unit/c/mock-network.c new file mode 100644 index 0000000..e3c3986 --- /dev/null +++ b/level_0/f_network/tests/unit/c/mock-network.c @@ -0,0 +1,29 @@ +#include "mock-network.h" + +#ifdef __cplusplus +extern "C" { +#endif + +uint32_t __wrap_htonl(uint32_t hostlong) { + + return mock_type(uint32_t); +} + +uint16_t __wrap_htons(uint16_t hostshort) { + + return mock_type(uint16_t); +} + +uint32_t __wrap_ntohl(uint32_t netlong) { + + return mock_type(uint32_t); +} + +uint16_t __wrap_ntohs(uint16_t netshort) { + + return mock_type(uint16_t); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_network/tests/unit/c/mock-network.h b/level_0/f_network/tests/unit/c/mock-network.h new file mode 100644 index 0000000..c450df3 --- /dev/null +++ b/level_0/f_network/tests/unit/c/mock-network.h @@ -0,0 +1,40 @@ +/** + * FLL - Level 0 + * + * Project: Network + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the network project. + */ +#ifndef _MOCK__network_h +#define _MOCK__network_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 uint32_t __wrap_htonl(uint32_t hostlong); +extern uint16_t __wrap_htons(uint16_t hostshort); +extern uint32_t __wrap_ntohl(uint32_t netlong); +extern uint16_t __wrap_ntohs(uint16_t netshort); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _MOCK__network_h diff --git a/level_0/f_network/tests/unit/c/test-network-from_host_long.c b/level_0/f_network/tests/unit/c/test-network-from_host_long.c new file mode 100644 index 0000000..9c337a2 --- /dev/null +++ b/level_0/f_network/tests/unit/c/test-network-from_host_long.c @@ -0,0 +1,34 @@ +#include "test-network.h" +#include "test-network-from_host_long.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_network_from_host_long__parameter_checking(void **state) { + + { + const f_status_t status = f_network_from_host_long(0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_network_from_host_long__works(void **state) { + + const uint32_t expect = 100; + uint32_t to = 0; + + { + will_return(__wrap_htonl, expect); + + const f_status_t status = f_network_from_host_long(0, &to); + + assert_int_equal(status, F_none); + assert_int_equal(to, expect); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_network/tests/unit/c/test-network-from_host_long.h b/level_0/f_network/tests/unit/c/test-network-from_host_long.h new file mode 100644 index 0000000..5c0fbf8 --- /dev/null +++ b/level_0/f_network/tests/unit/c/test-network-from_host_long.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Limit + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the network project. + */ +#ifndef _TEST__F_network_from_host_long_h +#define _TEST__F_network_from_host_long_h + +/** + * Test that parameter checking works as expected. + * + * @see f_network_from_host_long() + */ +extern void test__f_network_from_host_long__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_network_from_host_long() + */ +extern void test__f_network_from_host_long__works(void **state); + +#endif // _TEST__F_network_from_host_long_h diff --git a/level_0/f_network/tests/unit/c/test-network-from_host_short.c b/level_0/f_network/tests/unit/c/test-network-from_host_short.c new file mode 100644 index 0000000..1bece4e --- /dev/null +++ b/level_0/f_network/tests/unit/c/test-network-from_host_short.c @@ -0,0 +1,34 @@ +#include "test-network.h" +#include "test-network-from_host_short.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_network_from_host_short__parameter_checking(void **state) { + + { + const f_status_t status = f_network_from_host_short(0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_network_from_host_short__works(void **state) { + + const uint16_t expect = 100; + uint16_t to = 0; + + { + will_return(__wrap_htons, expect); + + const f_status_t status = f_network_from_host_short(0, &to); + + assert_int_equal(status, F_none); + assert_int_equal(to, expect); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_network/tests/unit/c/test-network-from_host_short.h b/level_0/f_network/tests/unit/c/test-network-from_host_short.h new file mode 100644 index 0000000..3be793a --- /dev/null +++ b/level_0/f_network/tests/unit/c/test-network-from_host_short.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Network + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the network project. + */ +#ifndef _TEST__F_network_from_host_short_h +#define _TEST__F_network_from_host_short_h + +/** + * Test that parameter checking works as expected. + * + * @see f_network_from_host_short() + */ +extern void test__f_network_from_host_short__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_network_from_host_short() + */ +extern void test__f_network_from_host_short__works(void **state); + +#endif // _TEST__F_network_from_host_short_h diff --git a/level_0/f_network/tests/unit/c/test-network-to_host_long.c b/level_0/f_network/tests/unit/c/test-network-to_host_long.c new file mode 100644 index 0000000..9767090 --- /dev/null +++ b/level_0/f_network/tests/unit/c/test-network-to_host_long.c @@ -0,0 +1,34 @@ +#include "test-network.h" +#include "test-network-to_host_long.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_network_to_host_long__parameter_checking(void **state) { + + { + const f_status_t status = f_network_to_host_long(0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_network_to_host_long__works(void **state) { + + const uint32_t expect = 100; + uint32_t to = 0; + + { + will_return(__wrap_ntohl, expect); + + const f_status_t status = f_network_to_host_long(0, &to); + + assert_int_equal(status, F_none); + assert_int_equal(to, expect); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_network/tests/unit/c/test-network-to_host_long.h b/level_0/f_network/tests/unit/c/test-network-to_host_long.h new file mode 100644 index 0000000..f892588 --- /dev/null +++ b/level_0/f_network/tests/unit/c/test-network-to_host_long.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Network + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the network project. + */ +#ifndef _TEST__F_network_to_host_long_h +#define _TEST__F_network_to_host_long_h + +/** + * Test that parameter checking works as expected. + * + * @see f_network_to_host_long() + */ +extern void test__f_network_to_host_long__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_network_to_host_long() + */ +extern void test__f_network_to_host_long__works(void **state); + +#endif // _TEST__F_network_to_host_long_h diff --git a/level_0/f_network/tests/unit/c/test-network-to_host_short.c b/level_0/f_network/tests/unit/c/test-network-to_host_short.c new file mode 100644 index 0000000..30a278f --- /dev/null +++ b/level_0/f_network/tests/unit/c/test-network-to_host_short.c @@ -0,0 +1,34 @@ +#include "test-network.h" +#include "test-network-to_host_short.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_network_to_host_short__parameter_checking(void **state) { + + { + const f_status_t status = f_network_to_host_short(0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_network_to_host_short__works(void **state) { + + const uint16_t expect = 100; + uint16_t to = 0; + + { + will_return(__wrap_ntohs, expect); + + const f_status_t status = f_network_to_host_short(0, &to); + + assert_int_equal(status, F_none); + assert_int_equal(to, expect); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_network/tests/unit/c/test-network-to_host_short.h b/level_0/f_network/tests/unit/c/test-network-to_host_short.h new file mode 100644 index 0000000..18fb70f --- /dev/null +++ b/level_0/f_network/tests/unit/c/test-network-to_host_short.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Network + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the network project. + */ +#ifndef _TEST__F_network_to_host_short_h +#define _TEST__F_network_to_host_short_h + +/** + * Test that parameter checking works as expected. + * + * @see f_network_to_host_short() + */ +extern void test__f_network_to_host_short__parameter_checking(void **state); + +/** + * Test that function works. + * + * @see f_network_to_host_short() + */ +extern void test__f_network_to_host_short__works(void **state); + +#endif // _TEST__F_network_to_host_short_h diff --git a/level_0/f_network/tests/unit/c/test-network.c b/level_0/f_network/tests/unit/c/test-network.c new file mode 100644 index 0000000..f24759f --- /dev/null +++ b/level_0/f_network/tests/unit/c/test-network.c @@ -0,0 +1,40 @@ +#include "test-network.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_network_from_host_long__works), + cmocka_unit_test(test__f_network_from_host_short__works), + cmocka_unit_test(test__f_network_to_host_long__works), + cmocka_unit_test(test__f_network_to_host_short__works), + + #ifndef _di_level_0_parameter_checking_ + cmocka_unit_test(test__f_network_from_host_long__parameter_checking), + cmocka_unit_test(test__f_network_from_host_short__parameter_checking), + cmocka_unit_test(test__f_network_to_host_long__parameter_checking), + cmocka_unit_test(test__f_network_to_host_short__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_network/tests/unit/c/test-network.h b/level_0/f_network/tests/unit/c/test-network.h new file mode 100644 index 0000000..74dcd06 --- /dev/null +++ b/level_0/f_network/tests/unit/c/test-network.h @@ -0,0 +1,76 @@ +/** + * FLL - Level 0 + * + * Project: Network + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the network project. + */ +#ifndef _TEST__F_network_h +#define _TEST__F_network_h + +// Libc includes. +#include +#include +#include +#include +#include + +// cmocka includes. +#include + +// FLL-0 includes. +#include + +// Mock includes. +#include "mock-network.h" + +// Test includes. +#include "test-network-from_host_long.h" +#include "test-network-from_host_short.h" +#include "test-network-to_host_long.h" +#include "test-network-to_host_short.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_network_h -- 1.8.3.1