diff options
author | Artjoms Rimdjonoks <artjoms.rimdjonoks@zabbix.com> | 2022-02-07 17:55:37 +0300 |
---|---|---|
committer | Artjoms Rimdjonoks <artjoms.rimdjonoks@zabbix.com> | 2022-02-07 17:59:57 +0300 |
commit | 111d978555281b2f51e361540f2a6fd43ce15e94 (patch) | |
tree | 94422c61f43b6d89316b065e099e23dafc5d087c /tests | |
parent | 1474363b438c2a387d65a3d15f766eee7befa54c (diff) | |
parent | f5396ba6eb6a7c30dcae680a0e26dca9081f0360 (diff) |
.......... [DEV-2064] updated to the latest master
Diffstat (limited to 'tests')
-rw-r--r-- | tests/libs/zbxcommon/Makefile.am | 2 | ||||
-rw-r--r-- | tests/libs/zbxcommon/zbx_common_trim_utf8.c | 67 | ||||
-rw-r--r-- | tests/libs/zbxcommon/zbx_common_trim_utf8.h | 27 | ||||
-rw-r--r-- | tests/libs/zbxcommon/zbx_ltrim_utf8.c | 42 | ||||
-rw-r--r-- | tests/libs/zbxcommon/zbx_rtrim_utf8.c | 41 | ||||
-rw-r--r-- | tests/libs/zbxsysinfo/linux/KERNEL_COMMON.c | 105 | ||||
-rw-r--r-- | tests/libs/zbxsysinfo/linux/KERNEL_COMMON.h | 27 | ||||
-rw-r--r-- | tests/libs/zbxsysinfo/linux/KERNEL_MAXFILES.c | 73 | ||||
-rw-r--r-- | tests/libs/zbxsysinfo/linux/KERNEL_MAXPROC.c | 73 | ||||
-rw-r--r-- | tests/libs/zbxsysinfo/linux/Makefile.am | 5 | ||||
-rw-r--r-- | tests/libs/zbxsysinfo/linux/NET_IF_COMMON.c | 126 | ||||
-rw-r--r-- | tests/libs/zbxsysinfo/linux/NET_IF_COMMON.h | 28 | ||||
-rw-r--r-- | tests/libs/zbxsysinfo/linux/NET_IF_IN.c | 93 | ||||
-rw-r--r-- | tests/libs/zbxsysinfo/linux/NET_IF_OUT.c | 93 | ||||
-rw-r--r-- | tests/libs/zbxsysinfo/linux/NET_IF_TOTAL.c | 93 | ||||
-rw-r--r-- | tests/zbxmockassert.h | 2 |
16 files changed, 401 insertions, 496 deletions
diff --git a/tests/libs/zbxcommon/Makefile.am b/tests/libs/zbxcommon/Makefile.am index 298c752307f..3a89906dbd2 100644 --- a/tests/libs/zbxcommon/Makefile.am +++ b/tests/libs/zbxcommon/Makefile.am @@ -491,6 +491,7 @@ zbx_get_report_nextcheck_CFLAGS = $(COMMON_COMPILER_FLAGS) # zbx_ltrim_utf8 zbx_ltrim_utf8_SOURCES = \ + zbx_common_trim_utf8.c \ zbx_ltrim_utf8.c \ $(COMMON_SRC_FILES) @@ -506,6 +507,7 @@ zbx_ltrim_utf8_CFLAGS = $(COMMON_COMPILER_FLAGS) # zbx_ltrim_utf8 zbx_rtrim_utf8_SOURCES = \ + zbx_common_trim_utf8.c \ zbx_rtrim_utf8.c \ $(COMMON_SRC_FILES) diff --git a/tests/libs/zbxcommon/zbx_common_trim_utf8.c b/tests/libs/zbxcommon/zbx_common_trim_utf8.c new file mode 100644 index 00000000000..4e74420ff8a --- /dev/null +++ b/tests/libs/zbxcommon/zbx_common_trim_utf8.c @@ -0,0 +1,67 @@ +/* +** Zabbix +** Copyright (C) 2001-2022 Zabbix SIA +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +**/ + +#include "zbx_common_trim_utf8.h" +#include "zbxmocktest.h" +#include "zbxmockdata.h" +#include "zbxmockutil.h" +#include "zbxmockassert.h" + +#include "common.h" + +static const char *read_utf8(const char *path_str, const char *path_hex) +{ + const char *data; + size_t len; + zbx_mock_handle_t hdata; + + if (ZBX_MOCK_SUCCESS == zbx_mock_parameter(path_str, &hdata)) + { + if (ZBX_MOCK_SUCCESS != zbx_mock_string(hdata, &data)) + fail_msg("invalid string format"); + } + else if (ZBX_MOCK_SUCCESS == zbx_mock_parameter(path_hex, &hdata)) + { + zbx_mock_binary(hdata, &data, &len); + } + else + fail_msg("cannot read %s/%s parameter", path_str, path_hex); + + return data; +} + +void zbx_mock_test_entry_common_trim_utf8(void **state, int trim_utf8_func) +{ + ZBX_UNUSED(state); + + char *in = zbx_strdup(NULL, read_utf8("in.text.str", "in.text.hex")); + const char *charlist = read_utf8("in.charlist.str", "in.charlist.hex"); + + if (ZABBIX_MOCK_LTRIM_UTF8 == trim_utf8_func) + zbx_ltrim_utf8(in, charlist); + else if (ZABBIX_MOCK_RTRIM_UTF8 == trim_utf8_func) + zbx_rtrim_utf8(in, charlist); + else + fail_msg("Invalid trim_utf8_func"); + + const char *expected = read_utf8("out.str", "out.hex"); + + zbx_mock_assert_str_eq("trimmed value", expected, in); + zbx_free(in); +} diff --git a/tests/libs/zbxcommon/zbx_common_trim_utf8.h b/tests/libs/zbxcommon/zbx_common_trim_utf8.h new file mode 100644 index 00000000000..401264e2507 --- /dev/null +++ b/tests/libs/zbxcommon/zbx_common_trim_utf8.h @@ -0,0 +1,27 @@ +/* +** Zabbix +** Copyright (C) 2001-2022 Zabbix SIA +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +**/ + +#ifndef ZABBIX_COMMON_TRIM_UTF8_H +#define ZABBIX_COMMON_TRIM_UTF8_H + +#define ZABBIX_MOCK_LTRIM_UTF8 0 +#define ZABBIX_MOCK_RTRIM_UTF8 1 + +void zbx_mock_test_entry_common_trim_utf8(void **state, int trim_utf8_func); +#endif diff --git a/tests/libs/zbxcommon/zbx_ltrim_utf8.c b/tests/libs/zbxcommon/zbx_ltrim_utf8.c index 96e09683f99..ad2708c4f86 100644 --- a/tests/libs/zbxcommon/zbx_ltrim_utf8.c +++ b/tests/libs/zbxcommon/zbx_ltrim_utf8.c @@ -17,49 +17,11 @@ ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. **/ +#include "zbx_common_trim_utf8.h" #include "zbxmocktest.h" -#include "zbxmockdata.h" -#include "zbxmockutil.h" -#include "zbxmockassert.h" - #include "common.h" -static const char *read_utf8(const char *path_str, const char *path_hex) -{ - const char *data; - size_t len; - zbx_mock_handle_t hdata; - - if (ZBX_MOCK_SUCCESS == zbx_mock_parameter(path_str, &hdata)) - { - if (ZBX_MOCK_SUCCESS != zbx_mock_string(hdata, &data)) - fail_msg("invalid string format"); - } - else if (ZBX_MOCK_SUCCESS == zbx_mock_parameter(path_hex, &hdata)) - { - zbx_mock_binary(hdata, &data, &len); - } - else - fail_msg("cannot read %s/%s parameter", path_str, path_hex); - - return data; -} - void zbx_mock_test_entry(void **state) { - const char *expected, *charlist; - char *in; - - ZBX_UNUSED(state); - - in = zbx_strdup(NULL, read_utf8("in.text.str", "in.text.hex")); - charlist = read_utf8("in.charlist.str", "in.charlist.hex"); - - zbx_ltrim_utf8(in, charlist); - - expected = read_utf8("out.str", "out.hex"); - - zbx_mock_assert_str_eq("trimmed value", expected, in); - zbx_free(in); - + zbx_mock_test_entry_common_trim_utf8(state, ZABBIX_MOCK_LTRIM_UTF8); } diff --git a/tests/libs/zbxcommon/zbx_rtrim_utf8.c b/tests/libs/zbxcommon/zbx_rtrim_utf8.c index 8d12212b81d..b7562376781 100644 --- a/tests/libs/zbxcommon/zbx_rtrim_utf8.c +++ b/tests/libs/zbxcommon/zbx_rtrim_utf8.c @@ -17,48 +17,11 @@ ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. **/ +#include "zbx_common_trim_utf8.h" #include "zbxmocktest.h" -#include "zbxmockdata.h" -#include "zbxmockutil.h" -#include "zbxmockassert.h" - #include "common.h" -static const char *read_utf8(const char *path_str, const char *path_hex) -{ - const char *data; - size_t len; - zbx_mock_handle_t hdata; - - if (ZBX_MOCK_SUCCESS == zbx_mock_parameter(path_str, &hdata)) - { - if (ZBX_MOCK_SUCCESS != zbx_mock_string(hdata, &data)) - fail_msg("invalid string format"); - } - else if (ZBX_MOCK_SUCCESS == zbx_mock_parameter(path_hex, &hdata)) - { - zbx_mock_binary(hdata, &data, &len); - } - else - fail_msg("cannot read %s/%s parameter", path_str, path_hex); - - return data; -} - void zbx_mock_test_entry(void **state) { - const char *expected, *charlist; - char *in; - - ZBX_UNUSED(state); - - in = zbx_strdup(NULL, read_utf8("in.text.str", "in.text.hex")); - charlist = read_utf8("in.charlist.str", "in.charlist.hex"); - - zbx_rtrim_utf8(in, charlist); - - expected = read_utf8("out.str", "out.hex"); - - zbx_mock_assert_str_eq("trimmed value", expected, in); - zbx_free(in); + zbx_mock_test_entry_common_trim_utf8(state, ZABBIX_MOCK_RTRIM_UTF8); } diff --git a/tests/libs/zbxsysinfo/linux/KERNEL_COMMON.c b/tests/libs/zbxsysinfo/linux/KERNEL_COMMON.c new file mode 100644 index 00000000000..7cef598b53d --- /dev/null +++ b/tests/libs/zbxsysinfo/linux/KERNEL_COMMON.c @@ -0,0 +1,105 @@ +/* +** Zabbix +** Copyright (C) 2001-2022 Zabbix SIA +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +**/ + +#include "KERNEL_COMMON.h" +#include "zbxmocktest.h" +#include "zbxmockdata.h" + +#include "common.h" +#include "sysinfo.h" + +void zbx_mock_test_entry_KERNEL_COMMON(void **state, int kernel_func) +{ + AGENT_REQUEST request; + AGENT_RESULT param_result; + zbx_mock_error_t error; + zbx_mock_handle_t param_handle; + const char *expected_param_value_string, *expected_return_string; + zbx_uint64_t expected_param_value = 0; + int expected_result = SYSINFO_RET_FAIL, actual_result; + + ZBX_UNUSED(state); + + if (ZBX_MOCK_SUCCESS != (error = zbx_mock_out_parameter("return", ¶m_handle)) || + ZBX_MOCK_SUCCESS != (error = zbx_mock_string(param_handle, &expected_return_string))) + { + fail_msg("Cannot get expected 'return' parameter from test case data: %s", + zbx_mock_error_string(error)); + } + + if (0 == strcmp("SYSINFO_RET_OK", expected_return_string)) + expected_result = SYSINFO_RET_OK; + else if (0 == strcmp("SYSINFO_RET_FAIL", expected_return_string)) + expected_result = SYSINFO_RET_FAIL; + else + fail_msg("Get unexpected 'return' parameter from test case data: %s", expected_return_string); + + if (ZBX_MOCK_SUCCESS != (error = zbx_mock_out_parameter("result", ¶m_handle)) || + ZBX_MOCK_SUCCESS != (error = zbx_mock_string(param_handle, &expected_param_value_string))) + { + fail_msg("Cannot get expected 'result' parameter from test case data: %s", + zbx_mock_error_string(error)); + } + + if (FAIL == is_uint64(expected_param_value_string, &expected_param_value) && SYSINFO_RET_OK == expected_result) + fail_msg("Cannot get expected numeric parameter from test case data: %s", expected_param_value_string); + + init_request(&request); + init_result(¶m_result); + + if (ZABBIX_MOCK_KERNEL_MAXPROC == kernel_func) + actual_result = KERNEL_MAXPROC(&request, ¶m_result); + else if (ZABBIX_MOCK_KERNEL_MAXFILES == kernel_func) + actual_result = KERNEL_MAXFILES(&request, ¶m_result); + else + fail_msg("Invalid kernel_func"); + + if (expected_result != actual_result) + { + fail_msg("Got %s instead of %s as a result.", zbx_sysinfo_ret_string(actual_result), + zbx_sysinfo_ret_string(expected_result)); + } + + if (SYSINFO_RET_OK == expected_result) + { + if (NULL == GET_UI64_RESULT(¶m_result)) + fail_msg("Got 'NULL' instead of '%s' as a value.", expected_param_value_string); + + if (expected_param_value != *GET_UI64_RESULT(¶m_result)) + { + fail_msg("Got '" ZBX_FS_UI64 "' instead of '%s' as a value.", *GET_UI64_RESULT(¶m_result), + expected_param_value_string); + } + } + + if (SYSINFO_RET_FAIL == expected_result) + { + if (NULL == GET_MSG_RESULT(¶m_result) || 0 != strcmp(expected_param_value_string, + *GET_MSG_RESULT(¶m_result))) + { + fail_msg("Got '%s' instead of '%s' as a value.", + (NULL != GET_MSG_RESULT(¶m_result) ? + *GET_MSG_RESULT(¶m_result) : "NULL"), + expected_param_value_string); + } + } + + free_request(&request); + free_result(¶m_result); +} diff --git a/tests/libs/zbxsysinfo/linux/KERNEL_COMMON.h b/tests/libs/zbxsysinfo/linux/KERNEL_COMMON.h new file mode 100644 index 00000000000..f84a843f13c --- /dev/null +++ b/tests/libs/zbxsysinfo/linux/KERNEL_COMMON.h @@ -0,0 +1,27 @@ +/* +** Zabbix +** Copyright (C) 2001-2022 Zabbix SIA +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +**/ + +#ifndef KERNEL_COMMON_H +#define KERNEL_COMMON_H + +#define ZABBIX_MOCK_KERNEL_MAXPROC 0 +#define ZABBIX_MOCK_KERNEL_MAXFILES 1 + +void zbx_mock_test_entry_KERNEL_COMMON(void **state, int kernel_func); +#endif diff --git a/tests/libs/zbxsysinfo/linux/KERNEL_MAXFILES.c b/tests/libs/zbxsysinfo/linux/KERNEL_MAXFILES.c index 3472cdc141e..16649268eab 100644 --- a/tests/libs/zbxsysinfo/linux/KERNEL_MAXFILES.c +++ b/tests/libs/zbxsysinfo/linux/KERNEL_MAXFILES.c @@ -17,79 +17,10 @@ ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. **/ +#include "KERNEL_COMMON.h" #include "zbxmocktest.h" -#include "zbxmockdata.h" - -#include "common.h" -#include "sysinfo.h" void zbx_mock_test_entry(void **state) { - AGENT_REQUEST request; - AGENT_RESULT param_result; - zbx_mock_error_t error; - zbx_mock_handle_t param_handle; - const char *expected_param_value_string, *expected_return_string; - zbx_uint64_t expected_param_value = 0; - int expected_result = SYSINFO_RET_FAIL, actual_result; - - ZBX_UNUSED(state); - - if (ZBX_MOCK_SUCCESS != (error = zbx_mock_out_parameter("return", ¶m_handle)) || - ZBX_MOCK_SUCCESS != (error = zbx_mock_string(param_handle, &expected_return_string))) - { - fail_msg("Cannot get expected 'return' parameter from test case data: %s", zbx_mock_error_string(error)); - } - - if (0 == strcmp("SYSINFO_RET_OK", expected_return_string)) - expected_result = SYSINFO_RET_OK; - else if (0 == strcmp("SYSINFO_RET_FAIL", expected_return_string)) - expected_result = SYSINFO_RET_FAIL; - else - fail_msg("Get unexpected 'return' parameter from test case data: %s", expected_return_string); - - if (ZBX_MOCK_SUCCESS != (error = zbx_mock_out_parameter("result", ¶m_handle)) || - ZBX_MOCK_SUCCESS != (error = zbx_mock_string(param_handle, &expected_param_value_string))) - { - fail_msg("Cannot get expected 'result' parameter from test case data: %s", zbx_mock_error_string(error)); - } - - if (FAIL == is_uint64(expected_param_value_string, &expected_param_value) && SYSINFO_RET_OK == expected_result) - fail_msg("Cannot get expected numeric parameter from test case data: %s", expected_param_value_string); - - init_request(&request); - init_result(¶m_result); - - if (expected_result != (actual_result = KERNEL_MAXFILES(&request, ¶m_result))) - { - fail_msg("Got %s instead of %s as a result.", zbx_sysinfo_ret_string(actual_result), - zbx_sysinfo_ret_string(expected_result)); - } - - if (SYSINFO_RET_OK == expected_result) - { - if (NULL == GET_UI64_RESULT(¶m_result)) - fail_msg("Got 'NULL' instead of '%s' as a value.", expected_param_value_string); - - if (expected_param_value != *GET_UI64_RESULT(¶m_result)) - { - fail_msg("Got '" ZBX_FS_UI64 "' instead of '%s' as a value.", *GET_UI64_RESULT(¶m_result), - expected_param_value_string); - } - } - - if (SYSINFO_RET_FAIL == expected_result) - { - if (NULL == GET_MSG_RESULT(¶m_result) || - 0 != strcmp(expected_param_value_string, *GET_MSG_RESULT(¶m_result))) - { - fail_msg("Got '%s' instead of '%s' as a value.", - (NULL != GET_MSG_RESULT(¶m_result) ? - *GET_MSG_RESULT(¶m_result) : "NULL"), - expected_param_value_string); - } - } - - free_request(&request); - free_result(¶m_result); + zbx_mock_test_entry_KERNEL_COMMON(state, ZABBIX_MOCK_KERNEL_MAXFILES); } diff --git a/tests/libs/zbxsysinfo/linux/KERNEL_MAXPROC.c b/tests/libs/zbxsysinfo/linux/KERNEL_MAXPROC.c index 692a4345f5d..eb99ce00492 100644 --- a/tests/libs/zbxsysinfo/linux/KERNEL_MAXPROC.c +++ b/tests/libs/zbxsysinfo/linux/KERNEL_MAXPROC.c @@ -17,79 +17,10 @@ ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. **/ +#include "KERNEL_COMMON.h" #include "zbxmocktest.h" -#include "zbxmockdata.h" - -#include "common.h" -#include "sysinfo.h" void zbx_mock_test_entry(void **state) { - AGENT_REQUEST request; - AGENT_RESULT param_result; - zbx_mock_error_t error; - zbx_mock_handle_t param_handle; - const char *expected_param_value_string, *expected_return_string; - zbx_uint64_t expected_param_value = 0; - int expected_result = SYSINFO_RET_FAIL, actual_result; - - ZBX_UNUSED(state); - - if (ZBX_MOCK_SUCCESS != (error = zbx_mock_out_parameter("return", ¶m_handle)) || - ZBX_MOCK_SUCCESS != (error = zbx_mock_string(param_handle, &expected_return_string))) - { - fail_msg("Cannot get expected 'return' parameter from test case data: %s", zbx_mock_error_string(error)); - } - - if (0 == strcmp("SYSINFO_RET_OK", expected_return_string)) - expected_result = SYSINFO_RET_OK; - else if (0 == strcmp("SYSINFO_RET_FAIL", expected_return_string)) - expected_result = SYSINFO_RET_FAIL; - else - fail_msg("Get unexpected 'return' parameter from test case data: %s", expected_return_string); - - if (ZBX_MOCK_SUCCESS != (error = zbx_mock_out_parameter("result", ¶m_handle)) || - ZBX_MOCK_SUCCESS != (error = zbx_mock_string(param_handle, &expected_param_value_string))) - { - fail_msg("Cannot get expected 'result' parameter from test case data: %s", zbx_mock_error_string(error)); - } - - if (FAIL == is_uint64(expected_param_value_string, &expected_param_value) && SYSINFO_RET_OK == expected_result) - fail_msg("Cannot get expected numeric parameter from test case data: %s", expected_param_value_string); - - init_request(&request); - init_result(¶m_result); - - if (expected_result != (actual_result = KERNEL_MAXPROC(&request, ¶m_result))) - { - fail_msg("Got %s instead of %s as a result.", zbx_sysinfo_ret_string(actual_result), - zbx_sysinfo_ret_string(expected_result)); - } - - if (SYSINFO_RET_OK == expected_result) - { - if (NULL == GET_UI64_RESULT(¶m_result)) - fail_msg("Got 'NULL' instead of '%s' as a value.", expected_param_value_string); - - if (expected_param_value != *GET_UI64_RESULT(¶m_result)) - { - fail_msg("Got '" ZBX_FS_UI64 "' instead of '%s' as a value.", *GET_UI64_RESULT(¶m_result), - expected_param_value_string); - } - } - - if (SYSINFO_RET_FAIL == expected_result) - { - if (NULL == GET_MSG_RESULT(¶m_result) || 0 != strcmp(expected_param_value_string, - *GET_MSG_RESULT(¶m_result))) - { - fail_msg("Got '%s' instead of '%s' as a value.", - (NULL != GET_MSG_RESULT(¶m_result) ? - *GET_MSG_RESULT(¶m_result) : "NULL"), - expected_param_value_string); - } - } - - free_request(&request); - free_result(¶m_result); + zbx_mock_test_entry_KERNEL_COMMON(state, ZABBIX_MOCK_KERNEL_MAXPROC); } diff --git a/tests/libs/zbxsysinfo/linux/Makefile.am b/tests/libs/zbxsysinfo/linux/Makefile.am index 38112ac4c52..498ef42b76b 100644 --- a/tests/libs/zbxsysinfo/linux/Makefile.am +++ b/tests/libs/zbxsysinfo/linux/Makefile.am @@ -77,6 +77,7 @@ VFS_FS_DISCOVERY_LDFLAGS = @AGENT_LDFLAGS@ VFS_FS_DISCOVERY_CFLAGS = $(COMMON_COMPILER_FLAGS) KERNEL_MAXPROC_SOURCES = \ + KERNEL_COMMON.c \ KERNEL_MAXPROC.c \ $(COMMON_SRC_FILES) @@ -103,6 +104,7 @@ SYSTEM_CPU_SWITCHES_LDFLAGS = @AGENT_LDFLAGS@ SYSTEM_CPU_SWITCHES_CFLAGS = $(COMMON_COMPILER_FLAGS) KERNEL_MAXFILES_SOURCES = \ + KERNEL_COMMON.c \ KERNEL_MAXFILES.c \ $(COMMON_SRC_FILES) @@ -143,6 +145,7 @@ SYSTEM_BOOTTIME_CFLAGS = $(COMMON_COMPILER_FLAGS) #NET_IF_TOTAL NET_IF_TOTAL_SOURCES = \ + NET_IF_COMMON.c \ NET_IF_TOTAL.c \ $(COMMON_SRC_FILES) @@ -152,6 +155,7 @@ NET_IF_TOTAL_CFLAGS = $(COMMON_COMPILER_FLAGS) #NET_IF_IN NET_IF_IN_SOURCES = \ + NET_IF_COMMON.c \ NET_IF_IN.c \ $(COMMON_SRC_FILES) @@ -161,6 +165,7 @@ NET_IF_IN_CFLAGS = $(COMMON_COMPILER_FLAGS) #NET_IF_OUT NET_IF_OUT_SOURCES = \ + NET_IF_COMMON.c \ NET_IF_OUT.c \ $(COMMON_SRC_FILES) diff --git a/tests/libs/zbxsysinfo/linux/NET_IF_COMMON.c b/tests/libs/zbxsysinfo/linux/NET_IF_COMMON.c new file mode 100644 index 00000000000..240dd97878b --- /dev/null +++ b/tests/libs/zbxsysinfo/linux/NET_IF_COMMON.c @@ -0,0 +1,126 @@ +/* +** Zabbix +** Copyright (C) 2001-2022 Zabbix SIA +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +**/ + +#include "NET_IF_COMMON.h" +#include "zbxmocktest.h" +#include "zbxmockdata.h" + +#include "common.h" +#include "sysinfo.h" + +void zbx_mock_test_entry_NET_IF_COMMON(void **state, int net_if_func) +{ + AGENT_REQUEST request; + AGENT_RESULT param_result; + zbx_mock_error_t error; + const char *init_param; + zbx_mock_handle_t param_handle; + const char *expected_param_value_string, *expected_return_string; + zbx_uint64_t expected_param_value = 0; + int expected_result = FAIL, actual_result = FAIL; + + ZBX_UNUSED(state); + + if (ZBX_MOCK_SUCCESS != (error = zbx_mock_out_parameter("return", ¶m_handle)) || + ZBX_MOCK_SUCCESS != (error = zbx_mock_string(param_handle,&expected_return_string))) + { + fail_msg("Cannot get expected 'return' parameter from test case data: %s", + zbx_mock_error_string(error)); + } + else + { + if (0 == strcmp("SYSINFO_RET_OK", expected_return_string)) + expected_result = SYSINFO_RET_OK; + else if (0 == strcmp("SYSINFO_RET_FAIL", expected_return_string)) + expected_result = SYSINFO_RET_FAIL; + else + fail_msg("Get unexpected 'return' parameter from test case data: %s", expected_return_string); + } + + if (ZBX_MOCK_SUCCESS != (error = zbx_mock_in_parameter("param", ¶m_handle)) || + ZBX_MOCK_SUCCESS != (error = zbx_mock_string(param_handle, &init_param))) + { + fail_msg("Cannot get input 'param' from test case data: %s", zbx_mock_error_string(error)); + } + + if (ZBX_MOCK_SUCCESS != (error = zbx_mock_out_parameter("result", ¶m_handle)) || + ZBX_MOCK_SUCCESS != (error = zbx_mock_string(param_handle, &expected_param_value_string))) + { + fail_msg("Cannot get expected 'result' parameters from test case data: %s", + zbx_mock_error_string(error)); + } + else + { + if (FAIL == is_uint64(expected_param_value_string, &expected_param_value) && + SYSINFO_RET_OK == expected_result) + { + fail_msg("Cannot get expected numeric parameter from test case data: %s", + expected_param_value_string); + } + } + + init_request(&request); + init_result(¶m_result); + + if (SUCCEED != parse_item_key(init_param, &request)) + fail_msg("Cannot parse item key: %s", init_param); + + if (ZABBIX_MOCK_NET_IF_IN == net_if_func) + actual_result = NET_IF_IN(&request, ¶m_result); + else if (ZABBIX_MOCK_NET_IF_OUT == net_if_func) + actual_result = NET_IF_OUT(&request, ¶m_result); + else if (ZABBIX_MOCK_NET_IF_TOTAL == net_if_func) + actual_result = NET_IF_TOTAL(&request, ¶m_result); + else + fail_msg("invalid net_if_func"); + + if (expected_result != actual_result) + { + fail_msg("Got %s instead of %s as a result.", zbx_sysinfo_ret_string(actual_result), + zbx_sysinfo_ret_string(expected_result)); + } + + if (SYSINFO_RET_OK == expected_result) + { + if (NULL == GET_UI64_RESULT(¶m_result) || expected_param_value != *GET_UI64_RESULT(¶m_result)) + { + if (NULL != GET_UI64_RESULT(¶m_result)) + { + fail_msg("Got '" ZBX_FS_UI64 "' instead of '%s' as a value.", + *GET_UI64_RESULT(¶m_result), expected_param_value_string); + } + else + fail_msg("Got 'NULL' instead of '%s' as a value.", expected_param_value_string); + } + } + else /* SYSINFO_RET_FAIL == expected_result */ + { + if (NULL == GET_MSG_RESULT(¶m_result) || + 0 != strcmp(expected_param_value_string, *GET_MSG_RESULT(¶m_result))) + { + fail_msg("Got '%s' instead of '%s' as a value.", + (NULL != GET_MSG_RESULT(¶m_result) ? + *GET_MSG_RESULT(¶m_result) : "NULL"), + expected_param_value_string); + } + } + + free_request(&request); + free_result(¶m_result); +} diff --git a/tests/libs/zbxsysinfo/linux/NET_IF_COMMON.h b/tests/libs/zbxsysinfo/linux/NET_IF_COMMON.h new file mode 100644 index 00000000000..ba3856fb52c --- /dev/null +++ b/tests/libs/zbxsysinfo/linux/NET_IF_COMMON.h @@ -0,0 +1,28 @@ +/* +** Zabbix +** Copyright (C) 2001-2022 Zabbix SIA +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +**/ + +#ifndef NET_IF_COMMON_H +#define NET_IF_COMMON_H + +#define ZABBIX_MOCK_NET_IF_IN 0 +#define ZABBIX_MOCK_NET_IF_OUT 1 +#define ZABBIX_MOCK_NET_IF_TOTAL 2 + +void zbx_mock_test_entry_NET_IF_COMMON(void **state, int net_if_func); +#endif diff --git a/tests/libs/zbxsysinfo/linux/NET_IF_IN.c b/tests/libs/zbxsysinfo/linux/NET_IF_IN.c index d1d673e9d89..d16c2714599 100644 --- a/tests/libs/zbxsysinfo/linux/NET_IF_IN.c +++ b/tests/libs/zbxsysinfo/linux/NET_IF_IN.c @@ -17,99 +17,10 @@ ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. **/ +#include "NET_IF_COMMON.h" #include "zbxmocktest.h" -#include "zbxmockdata.h" - -#include "common.h" -#include "sysinfo.h" void zbx_mock_test_entry(void **state) { - AGENT_REQUEST request; - AGENT_RESULT param_result; - zbx_mock_error_t error; - const char *init_param; - zbx_mock_handle_t param_handle; - const char *expected_param_value_string, *expected_return_string; - zbx_uint64_t expected_param_value = 0; - int expected_result = FAIL, actual_result = FAIL; - - ZBX_UNUSED(state); - - if (ZBX_MOCK_SUCCESS != (error = zbx_mock_out_parameter("return", ¶m_handle)) || - ZBX_MOCK_SUCCESS != (error = zbx_mock_string(param_handle,&expected_return_string))) - { - fail_msg("Cannot get expected 'return' parameter from test case data: %s", - zbx_mock_error_string(error)); - } - else - { - if (0 == strcmp("SYSINFO_RET_OK", expected_return_string)) - expected_result = SYSINFO_RET_OK; - else if (0 == strcmp("SYSINFO_RET_FAIL", expected_return_string)) - expected_result = SYSINFO_RET_FAIL; - else - fail_msg("Get unexpected 'return' parameter from test case data: %s", expected_return_string); - } - - if (ZBX_MOCK_SUCCESS != (error = zbx_mock_in_parameter("param", ¶m_handle)) || - ZBX_MOCK_SUCCESS != (error = zbx_mock_string(param_handle, &init_param))) - { - fail_msg("Cannot get input 'param' from test case data: %s", zbx_mock_error_string(error)); - } - - if (ZBX_MOCK_SUCCESS != (error = zbx_mock_out_parameter("result", ¶m_handle)) || - ZBX_MOCK_SUCCESS != (error = zbx_mock_string(param_handle, &expected_param_value_string))) - { - fail_msg("Cannot get expected 'result' parameters from test case data: %s", - zbx_mock_error_string(error)); - } - else - { - if (FAIL == is_uint64(expected_param_value_string, &expected_param_value) && - SYSINFO_RET_OK == expected_result) - { - fail_msg("Cannot get expected numeric parameter from test case data: %s", - expected_param_value_string); - } - } - - init_request(&request); - init_result(¶m_result); - if (SUCCEED != parse_item_key(init_param, &request)) - fail_msg("Cannot parse item key: %s", init_param); - - if (expected_result != (actual_result = NET_IF_IN(&request,¶m_result))) - { - fail_msg("Got %s instead of %s as a result.", zbx_sysinfo_ret_string(actual_result), - zbx_sysinfo_ret_string(expected_result)); - } - - if (SYSINFO_RET_OK == expected_result) - { - if (NULL == GET_UI64_RESULT(¶m_result) || expected_param_value != *GET_UI64_RESULT(¶m_result)) - { - if (NULL != GET_UI64_RESULT(¶m_result)) - { - fail_msg("Got '" ZBX_FS_UI64 "' instead of '%s' as a value.", - *GET_UI64_RESULT(¶m_result), expected_param_value_string); - } - else - fail_msg("Got 'NULL' instead of '%s' as a value.", expected_param_value_string); - } - } - else /* SYSINFO_RET_FAIL == expected_result */ - { - if (NULL == GET_MSG_RESULT(¶m_result) || - 0 != strcmp(expected_param_value_string, *GET_MSG_RESULT(¶m_result))) - { - fail_msg("Got '%s' instead of '%s' as a value.", - (NULL != GET_MSG_RESULT(¶m_result) ? - *GET_MSG_RESULT(¶m_result) : "NULL"), - expected_param_value_string); - } - } - - free_request(&request); - free_result(¶m_result); + zbx_mock_test_entry_NET_IF_COMMON(state, ZABBIX_MOCK_NET_IF_IN); } diff --git a/tests/libs/zbxsysinfo/linux/NET_IF_OUT.c b/tests/libs/zbxsysinfo/linux/NET_IF_OUT.c index d4f74061e7b..99e3f99c71d 100644 --- a/tests/libs/zbxsysinfo/linux/NET_IF_OUT.c +++ b/tests/libs/zbxsysinfo/linux/NET_IF_OUT.c @@ -17,99 +17,10 @@ ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. **/ +#include "NET_IF_COMMON.h" #include "zbxmocktest.h" -#include "zbxmockdata.h" - -#include "common.h" -#include "sysinfo.h" void zbx_mock_test_entry(void **state) { - AGENT_REQUEST request; - AGENT_RESULT param_result; - zbx_mock_error_t error; - const char *init_param; - zbx_mock_handle_t param_handle; - const char *expected_param_value_string, *expected_return_string; - zbx_uint64_t expected_param_value = 0; - int expected_result = FAIL, actual_result = FAIL; - - ZBX_UNUSED(state); - - if (ZBX_MOCK_SUCCESS != (error = zbx_mock_out_parameter("return", ¶m_handle)) || - ZBX_MOCK_SUCCESS != (error = zbx_mock_string(param_handle,&expected_return_string))) - { - fail_msg("Cannot get expected 'return' parameter from test case data: %s", - zbx_mock_error_string(error)); - } - else - { - if (0 == strcmp("SYSINFO_RET_OK", expected_return_string)) - expected_result = SYSINFO_RET_OK; - else if (0 == strcmp("SYSINFO_RET_FAIL", expected_return_string)) - expected_result = SYSINFO_RET_FAIL; - else - fail_msg("Get unexpected 'return' parameter from test case data: %s", expected_return_string); - } - - if (ZBX_MOCK_SUCCESS != (error = zbx_mock_in_parameter("param", ¶m_handle)) || - ZBX_MOCK_SUCCESS != (error = zbx_mock_string(param_handle, &init_param))) - { - fail_msg("Cannot get input 'param' from test case data: %s", zbx_mock_error_string(error)); - } - - if (ZBX_MOCK_SUCCESS != (error = zbx_mock_out_parameter("result", ¶m_handle)) || - ZBX_MOCK_SUCCESS != (error = zbx_mock_string(param_handle, &expected_param_value_string))) - { - fail_msg("Cannot get expected 'result' parameters from test case data: %s", - zbx_mock_error_string(error)); - } - else - { - if (FAIL == is_uint64(expected_param_value_string, &expected_param_value) && - SYSINFO_RET_OK == expected_result) - { - fail_msg("Cannot get expected numeric parameter from test case data: %s", - expected_param_value_string); - } - } - - init_request(&request); - init_result(¶m_result); - if (SUCCEED != parse_item_key(init_param, &request)) - fail_msg("Cannot parse item key: %s", init_param); - - if (expected_result != (actual_result = NET_IF_OUT(&request,¶m_result))) - { - fail_msg("Got %s instead of %s as a result.", zbx_sysinfo_ret_string(actual_result), - zbx_sysinfo_ret_string(expected_result)); - } - - if (SYSINFO_RET_OK == expected_result) - { - if (NULL == GET_UI64_RESULT(¶m_result) || expected_param_value != *GET_UI64_RESULT(¶m_result)) - { - if (NULL != GET_UI64_RESULT(¶m_result)) - { - fail_msg("Got '" ZBX_FS_UI64 "' instead of '%s' as a value.", - *GET_UI64_RESULT(¶m_result), expected_param_value_string); - } - else - fail_msg("Got 'NULL' instead of '%s' as a value.", expected_param_value_string); - } - } - else /* SYSINFO_RET_FAIL == expected_result */ - { - if (NULL == GET_MSG_RESULT(¶m_result) || - 0 != strcmp(expected_param_value_string, *GET_MSG_RESULT(¶m_result))) - { - fail_msg("Got '%s' instead of '%s' as a value.", - (NULL != GET_MSG_RESULT(¶m_result) ? - *GET_MSG_RESULT(¶m_result) : "NULL"), - expected_param_value_string); - } - } - - free_request(&request); - free_result(¶m_result); + zbx_mock_test_entry_NET_IF_COMMON(state, ZABBIX_MOCK_NET_IF_OUT); } diff --git a/tests/libs/zbxsysinfo/linux/NET_IF_TOTAL.c b/tests/libs/zbxsysinfo/linux/NET_IF_TOTAL.c index 8d014cf7bf5..fe153997d6b 100644 --- a/tests/libs/zbxsysinfo/linux/NET_IF_TOTAL.c +++ b/tests/libs/zbxsysinfo/linux/NET_IF_TOTAL.c @@ -17,99 +17,10 @@ ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. **/ +#include "NET_IF_COMMON.h" #include "zbxmocktest.h" -#include "zbxmockdata.h" - -#include "common.h" -#include "sysinfo.h" void zbx_mock_test_entry(void **state) { - AGENT_REQUEST request; - AGENT_RESULT param_result; - zbx_mock_error_t error; - const char *init_param; - zbx_mock_handle_t param_handle; - const char *expected_param_value_string, *expected_return_string; - zbx_uint64_t expected_param_value = 0; - int expected_result = FAIL, actual_result = FAIL; - - ZBX_UNUSED(state); - - if (ZBX_MOCK_SUCCESS != (error = zbx_mock_out_parameter("return", ¶m_handle)) || - ZBX_MOCK_SUCCESS != (error = zbx_mock_string(param_handle,&expected_return_string))) - { - fail_msg("Cannot get expected 'return' parameter from test case data: %s", - zbx_mock_error_string(error)); - } - else - { - if (0 == strcmp("SYSINFO_RET_OK", expected_return_string)) - expected_result = SYSINFO_RET_OK; - else if (0 == strcmp("SYSINFO_RET_FAIL", expected_return_string)) - expected_result = SYSINFO_RET_FAIL; - else - fail_msg("Get unexpected 'return' parameter from test case data: %s", expected_return_string); - } - - if (ZBX_MOCK_SUCCESS != (error = zbx_mock_in_parameter("param", ¶m_handle)) || - ZBX_MOCK_SUCCESS != (error = zbx_mock_string(param_handle, &init_param))) - { - fail_msg("Cannot get input 'param' from test case data: %s", zbx_mock_error_string(error)); - } - - if (ZBX_MOCK_SUCCESS != (error = zbx_mock_out_parameter("result", ¶m_handle)) || - ZBX_MOCK_SUCCESS != (error = zbx_mock_string(param_handle, &expected_param_value_string))) - { - fail_msg("Cannot get expected 'result' parameters from test case data: %s", - zbx_mock_error_string(error)); - } - else - { - if (FAIL == is_uint64(expected_param_value_string, &expected_param_value) && - SYSINFO_RET_OK == expected_result) - { - fail_msg("Cannot get expected numeric parameter from test case data: %s", - expected_param_value_string); - } - } - - init_request(&request); - init_result(¶m_result); - if (SUCCEED != parse_item_key(init_param, &request)) - fail_msg("Cannot parse item key: %s", init_param); - - if (expected_result != (actual_result = NET_IF_TOTAL(&request,¶m_result))) - { - fail_msg("Got %s instead of %s as a result.", zbx_sysinfo_ret_string(actual_result), - zbx_sysinfo_ret_string(expected_result)); - } - - if (SYSINFO_RET_OK == expected_result) - { - if (NULL == GET_UI64_RESULT(¶m_result) || expected_param_value != *GET_UI64_RESULT(¶m_result)) - { - if (NULL != GET_UI64_RESULT(¶m_result)) - { - fail_msg("Got '" ZBX_FS_UI64 "' instead of '%s' as a value.", - *GET_UI64_RESULT(¶m_result), expected_param_value_string); - } - else - fail_msg("Got 'NULL' instead of '%s' as a value.", expected_param_value_string); - } - } - else /* SYSINFO_RET_FAIL == expected_result */ - { - if (NULL == GET_MSG_RESULT(¶m_result) || - 0 != strcmp(expected_param_value_string, *GET_MSG_RESULT(¶m_result))) - { - fail_msg("Got '%s' instead of '%s' as a value.", - (NULL != GET_MSG_RESULT(¶m_result) ? - *GET_MSG_RESULT(¶m_result) : "NULL"), - expected_param_value_string); - } - } - - free_request(&request); - free_result(¶m_result); + zbx_mock_test_entry_NET_IF_COMMON(state, ZABBIX_MOCK_NET_IF_TOTAL); } diff --git a/tests/zbxmockassert.h b/tests/zbxmockassert.h index 7d3f07d212f..3ee3bf7c129 100644 --- a/tests/zbxmockassert.h +++ b/tests/zbxmockassert.h @@ -22,8 +22,6 @@ #include "common.h" -extern double ZBX_DOUBLE_EPSILON; - void __zbx_mock_assert_str_eq(const char *file, int line, const char *prefix_msg, const char *expected_value, const char *returned_value); |