Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndris Zeila <andris.zeila@zabbix.com>2022-02-18 13:27:53 +0300
committerAndris Zeila <andris.zeila@zabbix.com>2022-02-18 13:27:53 +0300
commit445763931bafb7ec97d7d5f4fddfbbd655e25116 (patch)
tree654e4c3dd9b214b23bacb09271242b971632e654 /tests
parentfef57d6f5d45f9fe9bffd65fd402f908b08c2802 (diff)
parentf1616eca99189afcd8e57d2ad86a0dd0506bf2f2 (diff)
.......... [ZBXNEXT-7402] merged branch 'master' of ssh://git.zabbix.lan:7999/zbx/zabbix into feature/ZBXNEXT-7402-5.5
Diffstat (limited to 'tests')
-rw-r--r--tests/conf_tests.m450
-rw-r--r--tests/libs/zbxalgo/queue.c2
-rw-r--r--tests/libs/zbxcommon/Makefile.am2
-rw-r--r--tests/libs/zbxcommon/zbx_common_trim_utf8.c67
-rw-r--r--tests/libs/zbxcommon/zbx_common_trim_utf8.h27
-rw-r--r--tests/libs/zbxcommon/zbx_ltrim_utf8.c42
-rw-r--r--tests/libs/zbxcommon/zbx_rtrim_utf8.c41
-rw-r--r--tests/libs/zbxcomms/zbx_tcp_check_allowed_peers.c1
-rw-r--r--tests/libs/zbxdbcache/Makefile.am3
-rw-r--r--tests/libs/zbxdbcache/dc_check_maintenance_period.c1
-rw-r--r--tests/libs/zbxdbcache/dc_expand_user_macros_in_func_params.c2
-rw-r--r--tests/libs/zbxdbcache/dc_item_poller_type_update.c1
-rw-r--r--tests/libs/zbxdbcache/dc_maintenance_match_tags.c2
-rw-r--r--tests/libs/zbxdbcache/zbx_vc_add_values.c146
-rw-r--r--tests/libs/zbxdbcache/zbx_vc_common.c187
-rw-r--r--tests/libs/zbxdbcache/zbx_vc_common.h51
-rw-r--r--tests/libs/zbxdbcache/zbx_vc_get_value.c160
-rw-r--r--tests/libs/zbxdbcache/zbx_vc_get_values.c152
-rw-r--r--tests/libs/zbxeval/zbx_eval_execute.c17
-rw-r--r--tests/libs/zbxserver/macro_fmttime.c42
-rw-r--r--tests/libs/zbxsysinfo/aix/Makefile.am1
-rw-r--r--tests/libs/zbxsysinfo/freebsd/Makefile.am1
-rw-r--r--tests/libs/zbxsysinfo/hpux/Makefile.am1
-rw-r--r--tests/libs/zbxsysinfo/linux/KERNEL_COMMON.c105
-rw-r--r--tests/libs/zbxsysinfo/linux/KERNEL_COMMON.h27
-rw-r--r--tests/libs/zbxsysinfo/linux/KERNEL_MAXFILES.c73
-rw-r--r--tests/libs/zbxsysinfo/linux/KERNEL_MAXPROC.c73
-rw-r--r--tests/libs/zbxsysinfo/linux/Makefile.am5
-rw-r--r--tests/libs/zbxsysinfo/linux/NET_IF_COMMON.c126
-rw-r--r--tests/libs/zbxsysinfo/linux/NET_IF_COMMON.h28
-rw-r--r--tests/libs/zbxsysinfo/linux/NET_IF_IN.c93
-rw-r--r--tests/libs/zbxsysinfo/linux/NET_IF_OUT.c93
-rw-r--r--tests/libs/zbxsysinfo/linux/NET_IF_TOTAL.c93
-rw-r--r--tests/libs/zbxsysinfo/netbsd/Makefile.am1
-rw-r--r--tests/libs/zbxsysinfo/openbsd/Makefile.am1
-rw-r--r--tests/libs/zbxsysinfo/osf/Makefile.am1
-rw-r--r--tests/libs/zbxsysinfo/osx/Makefile.am1
-rw-r--r--tests/libs/zbxsysinfo/solaris/Makefile.am1
-rw-r--r--tests/libs/zbxsysinfo/unknown/Makefile.am1
-rw-r--r--tests/mocks/configcache/configcache.c22
-rw-r--r--tests/mocks/configcache/configcache.h16
-rw-r--r--tests/mocks/configcache/configcache_mock.h12
-rw-r--r--tests/mocks/configcache/hosts.c3
-rw-r--r--tests/mocks/configcache/usermacros.c10
-rw-r--r--tests/zabbix_server/service/Makefile.am4
-rw-r--r--tests/zbxmockassert.h2
-rw-r--r--tests/zbxmockexit.c10
-rw-r--r--tests/zbxmockfile.c10
-rw-r--r--tests/zbxmocktest.c2
-rw-r--r--tests/zbxmocktest.h2
-rw-r--r--tests/zbxmockutil.c2
51 files changed, 851 insertions, 965 deletions
diff --git a/tests/conf_tests.m4 b/tests/conf_tests.m4
index 84b091db560..9a25dc1c2b7 100644
--- a/tests/conf_tests.m4
+++ b/tests/conf_tests.m4
@@ -17,8 +17,9 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
-AC_DEFUN([CONF_TESTS],[
- AM_COND_IF([$1],[
+AC_DEFUN([CONF_TESTS],
+[
+ AM_COND_IF([ZBXCMOCKA],[
AC_CONFIG_FILES([
tests/Makefile
tests/libs/Makefile
@@ -37,7 +38,6 @@ AC_DEFUN([CONF_TESTS],[
tests/libs/zbxserver/Makefile
tests/libs/zbxsysinfo/Makefile
tests/libs/zbxsysinfo/common/Makefile
- tests/libs/zbxsysinfo/linux/Makefile
tests/libs/zbxtrends/Makefile
tests/zabbix_server/Makefile
tests/zabbix_server/preprocessor/Makefile
@@ -49,4 +49,48 @@ AC_DEFUN([CONF_TESTS],[
])
AC_DEFINE([HAVE_TESTS], [1], ["Define to 1 if tests directory is present"])
])
+
+ case "$ARCH" in
+ linux)
+ AC_CONFIG_FILES([tests/libs/zbxsysinfo/linux/Makefile])
+ ;;
+ aix)
+ AC_CONFIG_FILES([tests/libs/zbxsysinfo/aix/Makefile])
+ ;;
+ osx)
+ AC_CONFIG_FILES([tests/libs/zbxsysinfo/osx/Makefile])
+ ;;
+ solaris)
+ AC_CONFIG_FILES([tests/libs/zbxsysinfo/solaris/Makefile])
+ ;;
+ hpux)
+ AC_CONFIG_FILES([tests/libs/zbxsysinfo/hpux/Makefile])
+ ;;
+ freebsd)
+ AC_CONFIG_FILES([tests/libs/zbxsysinfo/freebsd/Makefile])
+ ;;
+ netbsd)
+ AC_CONFIG_FILES([tests/libs/zbxsysinfo/netbsd/Makefile])
+ ;;
+ osf)
+ AC_CONFIG_FILES([tests/libs/zbxsysinfo/osf/Makefile])
+ ;;
+ openbsd)
+ AC_CONFIG_FILES([tests/libs/zbxsysinfo/openbsd/Makefile])
+ ;;
+ unknown)
+ AC_CONFIG_FILES([tests/libs/zbxsysinfo/unknown/Makefile])
+ ;;
+ esac
+
+
+AC_TRY_LINK(
+[
+#include <stdlib.h>
+],
+[
+ __fxstat(0, 0, NULL);
+],
+AC_DEFINE([HAVE_FXSTAT], [1], [Define to 1 if fxstat function is available]))
+
])
diff --git a/tests/libs/zbxalgo/queue.c b/tests/libs/zbxalgo/queue.c
index 014e97d0568..7a5facce8bd 100644
--- a/tests/libs/zbxalgo/queue.c
+++ b/tests/libs/zbxalgo/queue.c
@@ -21,7 +21,7 @@
#include "zbxmockdata.h"
#include "zbxmockassert.h"
#include "zbxmockutil.h"
-#include <malloc.h>
+#include <stdlib.h>
#include "zbxalgo.h"
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/zbxcomms/zbx_tcp_check_allowed_peers.c b/tests/libs/zbxcomms/zbx_tcp_check_allowed_peers.c
index 83684cf51cf..9496bf3d127 100644
--- a/tests/libs/zbxcomms/zbx_tcp_check_allowed_peers.c
+++ b/tests/libs/zbxcomms/zbx_tcp_check_allowed_peers.c
@@ -41,6 +41,7 @@ static void mock_accept(zbx_socket_t *s)
break;
default:
fail_msg("Unexpected family");
+ return;
}
if (1 != inet_pton(s->peer_info.ss_family, (peer = zbx_mock_get_parameter_string("in.peer")), buf))
diff --git a/tests/libs/zbxdbcache/Makefile.am b/tests/libs/zbxdbcache/Makefile.am
index 3b9a934cb73..d141a1c1ff1 100644
--- a/tests/libs/zbxdbcache/Makefile.am
+++ b/tests/libs/zbxdbcache/Makefile.am
@@ -104,6 +104,7 @@ COMMON_WRAP_FUNCS = \
-Wl,--wrap=time
zbx_vc_get_values_SOURCES = \
+ zbx_vc_common.c \
zbx_vc_get_values.c \
@top_srcdir@/src/libs/zbxdbcache/valuecache.c \
@top_srcdir@/src/libs/zbxhistory/history.c \
@@ -119,6 +120,7 @@ zbx_vc_get_values_CFLAGS = \
-I@top_srcdir@/tests
zbx_vc_add_values_SOURCES = \
+ zbx_vc_common.c \
zbx_vc_add_values.c \
@top_srcdir@/src/libs/zbxdbcache/valuecache.c \
@top_srcdir@/src/libs/zbxhistory/history.c \
@@ -134,6 +136,7 @@ zbx_vc_add_values_CFLAGS = \
-I@top_srcdir@/tests
zbx_vc_get_value_SOURCES = \
+ zbx_vc_common.c \
zbx_vc_get_value.c \
@top_srcdir@/src/libs/zbxdbcache/valuecache.c \
@top_srcdir@/src/libs/zbxhistory/history.c \
diff --git a/tests/libs/zbxdbcache/dc_check_maintenance_period.c b/tests/libs/zbxdbcache/dc_check_maintenance_period.c
index a942ff7577f..cc49551eaf4 100644
--- a/tests/libs/zbxdbcache/dc_check_maintenance_period.c
+++ b/tests/libs/zbxdbcache/dc_check_maintenance_period.c
@@ -28,7 +28,6 @@
#include "dbcache.h"
#include "log.h"
-#define ZBX_DBCONFIG_IMPL
#include "dbconfig.h"
#include "dbconfig_maintenance_test.h"
diff --git a/tests/libs/zbxdbcache/dc_expand_user_macros_in_func_params.c b/tests/libs/zbxdbcache/dc_expand_user_macros_in_func_params.c
index be351068c26..75048dc4cb2 100644
--- a/tests/libs/zbxdbcache/dc_expand_user_macros_in_func_params.c
+++ b/tests/libs/zbxdbcache/dc_expand_user_macros_in_func_params.c
@@ -27,8 +27,6 @@
#include "zbxalgo.h"
#include "dbcache.h"
#include "mutexs.h"
-
-#define ZBX_DBCONFIG_IMPL
#include "dbconfig.h"
#include "configcache_mock.h"
diff --git a/tests/libs/zbxdbcache/dc_item_poller_type_update.c b/tests/libs/zbxdbcache/dc_item_poller_type_update.c
index 656f1750f50..674c1f2d59a 100644
--- a/tests/libs/zbxdbcache/dc_item_poller_type_update.c
+++ b/tests/libs/zbxdbcache/dc_item_poller_type_update.c
@@ -32,7 +32,6 @@
#include "common.h"
#include "mutexs.h"
-#define ZBX_DBCONFIG_IMPL
#include "dbcache.h"
#include "dbconfig.h"
#include "dc_item_poller_type_update_test.h"
diff --git a/tests/libs/zbxdbcache/dc_maintenance_match_tags.c b/tests/libs/zbxdbcache/dc_maintenance_match_tags.c
index f4faf31a7cd..81422212403 100644
--- a/tests/libs/zbxdbcache/dc_maintenance_match_tags.c
+++ b/tests/libs/zbxdbcache/dc_maintenance_match_tags.c
@@ -26,8 +26,6 @@
#include "mutexs.h"
#include "zbxalgo.h"
#include "dbcache.h"
-
-#define ZBX_DBCONFIG_IMPL
#include "dbconfig.h"
#include "dbconfig_maintenance_test.h"
diff --git a/tests/libs/zbxdbcache/zbx_vc_add_values.c b/tests/libs/zbxdbcache/zbx_vc_add_values.c
index 9a22562ae09..f1b33972ece 100644
--- a/tests/libs/zbxdbcache/zbx_vc_add_values.c
+++ b/tests/libs/zbxdbcache/zbx_vc_add_values.c
@@ -29,138 +29,30 @@
extern zbx_uint64_t CONFIG_VALUE_CACHE_SIZE;
-void zbx_mock_test_entry(void **state)
-{
- int err, seconds, count, item_status, item_active_range, item_db_cached_from,
- item_values_total, cache_mode, ret_flush;
- zbx_vector_history_record_t expected, returned;
- const char *data;
- char *error;
- zbx_mock_handle_t handle, hitem, hitems, hstatus;
- zbx_mock_error_t mock_err;
- zbx_uint64_t itemid, cache_hits, cache_misses;
- unsigned char value_type;
- zbx_vector_ptr_t history;
- zbx_timespec_t ts;
-
- ZBX_UNUSED(state);
-
- /* set small cache size to force smaller cache free request size (5% of cache size) */
- CONFIG_VALUE_CACHE_SIZE = ZBX_KIBIBYTE;
-
- err = zbx_locks_create(&error);
- zbx_mock_assert_result_eq("Lock initialization failed", SUCCEED, err);
-
- err = zbx_vc_init(&error);
- zbx_mock_assert_result_eq("Value cache initialization failed", SUCCEED, err);
-
- zbx_vc_enable();
-
- zbx_vcmock_ds_init();
- zbx_history_record_vector_create(&expected);
- zbx_history_record_vector_create(&returned);
-
- /* precache values */
- if (ZBX_MOCK_SUCCESS == zbx_mock_parameter("in.precache", &handle))
- {
- while (ZBX_MOCK_END_OF_VECTOR != (mock_err = (zbx_mock_vector_element(handle, &hitem))))
- {
- zbx_vcmock_set_time(hitem, "time");
- zbx_vcmock_set_mode(hitem, "cache mode");
- zbx_vcmock_set_cache_size(hitem, "cache size");
-
- zbx_vcmock_get_request_params(hitem, &itemid, &value_type, &seconds, &count, &ts);
- zbx_vc_precache_values(itemid, value_type, seconds, count, &ts);
- }
- }
+#include "zbx_vc_common.h"
+void zbx_vc_test_add_values_setup(zbx_mock_handle_t *handle, zbx_vector_ptr_t *history, int *err, const char **data,
+ int *ret_flush)
+{
/* execute request */
- handle = zbx_mock_get_parameter_handle("in.test");
- zbx_vcmock_set_time(handle, "time");
- zbx_vcmock_set_mode(handle, "cache mode");
- zbx_vcmock_set_cache_size(handle, "cache size");
-
- zbx_vector_ptr_create(&history);
- zbx_vcmock_get_dc_history(zbx_mock_get_object_member_handle(handle, "values"), &history);
-
- err = zbx_vc_add_values(&history, &ret_flush);
- data = zbx_mock_get_parameter_string("out.return");
- zbx_mock_assert_int_eq("zbx_vc_add_values()", zbx_mock_str_to_return_code(data), err);
-
- zbx_vector_ptr_clear_ext(&history, zbx_vcmock_free_dc_history);
- zbx_vector_ptr_destroy(&history);
-
- /* validate cache contents */
-
- hitems = zbx_mock_get_parameter_handle("out.cache.items");
-
- while (ZBX_MOCK_END_OF_VECTOR != (mock_err = (zbx_mock_vector_element(hitems, &hitem))))
- {
- if (ZBX_MOCK_NOT_A_VECTOR == mock_err)
- fail_msg("out.cache.items parameter is not a vector");
-
- data = zbx_mock_get_object_member_string(hitem, "itemid");
- if (SUCCEED != is_uint64(data, &itemid))
- fail_msg("Invalid itemid \"%s\"", data);
-
- err = zbx_vc_get_item_state(itemid, &item_status, &item_active_range, &item_values_total,
- &item_db_cached_from);
+ *handle = zbx_mock_get_parameter_handle("in.test");
+ zbx_vcmock_set_time(*handle, "time");
+ zbx_vcmock_set_mode(*handle, "cache mode");
+ zbx_vcmock_set_cache_size(*handle, "cache size");
- mock_err = zbx_mock_object_member(hitem, "status", &hstatus);
+ zbx_vector_ptr_create(history);
+ zbx_vcmock_get_dc_history(zbx_mock_get_object_member_handle(*handle, "values"), history);
- if (ZBX_MOCK_SUCCESS == mock_err)
- {
- zbx_mock_assert_result_eq("zbx_vc_get_item_state() return value", SUCCEED, err);
+ *err = zbx_vc_add_values(history, ret_flush);
+ *data = zbx_mock_get_parameter_string("out.return");
+ zbx_mock_assert_int_eq("zbx_vc_add_values()", zbx_mock_str_to_return_code(*data), *err);
- if (ZBX_MOCK_SUCCESS != (mock_err = zbx_mock_string(hstatus, &data)))
- fail_msg("Cannot read item status: %s", zbx_mock_error_string(mock_err));
-
- zbx_mock_assert_int_eq("item.status", zbx_vcmock_str_to_item_status(data), item_status);
-
- data = zbx_mock_get_object_member_string(hitem, "active_range");
- zbx_mock_assert_int_eq("item.active_range", atoi(data), item_active_range);
-
- data = zbx_mock_get_object_member_string(hitem, "values_total");
- zbx_mock_assert_int_eq("item.values_total", atoi(data), item_values_total);
-
- if (ZBX_MOCK_SUCCESS != (mock_err = zbx_strtime_to_timespec(
- zbx_mock_get_object_member_string(hitem, "db_cached_from"), &ts)))
- {
- fail_msg("Cannot read out.item.db_cached_from timestamp: %s",
- zbx_mock_error_string(mock_err));
- }
-
- zbx_mock_assert_time_eq("item.db_cached_from", ts.sec, item_db_cached_from);
-
- value_type = zbx_mock_str_to_value_type(zbx_mock_get_object_member_string(hitem, "value type"));
-
- zbx_vcmock_read_values(zbx_mock_get_object_member_handle(hitem, "data"), value_type, &expected);
- zbx_vc_get_cached_values(itemid, value_type, &returned);
-
- zbx_vcmock_check_records("Cached values", value_type, &expected, &returned);
-
- zbx_history_record_vector_clean(&expected, value_type);
- zbx_history_record_vector_clean(&returned, value_type);
- }
- else
- zbx_mock_assert_result_eq("zbx_vc_get_item_state() return value", FAIL, err);
- }
-
- /* validate cache state */
-
- zbx_vc_get_cache_state(&cache_mode, &cache_hits, &cache_misses);
- zbx_mock_assert_int_eq("cache.mode", zbx_vcmock_str_to_cache_mode(zbx_mock_get_parameter_string("out.cache.mode")),
- cache_mode);
-
- /* cleanup */
-
- zbx_vector_history_record_destroy(&returned);
- zbx_vector_history_record_destroy(&expected);
-
- zbx_vcmock_ds_destroy();
-
- zbx_vc_reset();
- zbx_vc_destroy();
+ zbx_vector_ptr_clear_ext(history, zbx_vcmock_free_dc_history);
+ zbx_vector_ptr_destroy(history);
+}
+void zbx_mock_test_entry(void **state)
+{
+ zbx_vc_common_test_func(state, zbx_vc_test_add_values_setup, NULL, NULL, 0);
}
diff --git a/tests/libs/zbxdbcache/zbx_vc_common.c b/tests/libs/zbxdbcache/zbx_vc_common.c
new file mode 100644
index 00000000000..1ba205a06ed
--- /dev/null
+++ b/tests/libs/zbxdbcache/zbx_vc_common.c
@@ -0,0 +1,187 @@
+/*
+** 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_vc_common.h"
+
+#include "zbxmocktest.h"
+#include "zbxmockassert.h"
+#include "zbxmockutil.h"
+
+#include "common.h"
+#include "mutexs.h"
+#include "valuecache.h"
+#include "valuecache_test.h"
+#include "mocks/valuecache/valuecache_mock.h"
+
+extern zbx_uint64_t CONFIG_VALUE_CACHE_SIZE;
+
+static void zbx_vc_test_check_result(zbx_uint64_t cache_hits, zbx_uint64_t cache_misses)
+{
+ zbx_uint64_t expected_hits, expected_misses;
+
+ if (FAIL == is_uint64(zbx_mock_get_parameter_string("out.cache.hits"), &expected_hits))
+ fail_msg("Invalid out.cache.hits value");
+ zbx_mock_assert_uint64_eq("cache.hits", expected_hits, cache_hits);
+
+ if (FAIL == is_uint64(zbx_mock_get_parameter_string("out.cache.misses"), &expected_misses))
+ fail_msg("Invalid out.cache.misses value");
+ zbx_mock_assert_uint64_eq("cache.misses", expected_misses, cache_misses);
+}
+
+void zbx_vc_common_test_func(
+ void **state,
+ zbx_vc_test_add_values_setup_cb add_values_cb,
+ zbx_vc_test_get_value_setup_cb get_value_cb,
+ zbx_vc_test_get_values_setup_cb get_values_cb,
+ int test_check_result)
+{
+ int err, seconds, count, cache_mode;
+ zbx_vector_history_record_t expected, returned;
+ const char *data;
+ char *error;
+ zbx_mock_handle_t handle, hitem, hitems;
+ zbx_mock_error_t mock_err;
+ zbx_uint64_t itemid, cache_hits, cache_misses;
+ unsigned char value_type;
+ zbx_timespec_t ts;
+
+ ZBX_UNUSED(state);
+
+ /* set small cache size to force smaller cache free request size (5% of cache size) */
+ CONFIG_VALUE_CACHE_SIZE = ZBX_KIBIBYTE;
+
+ err = zbx_locks_create(&error);
+ zbx_mock_assert_result_eq("Lock initialization failed", SUCCEED, err);
+
+ err = zbx_vc_init(&error);
+ zbx_mock_assert_result_eq("Value cache initialization failed", SUCCEED, err);
+
+ zbx_vc_enable();
+
+ zbx_vcmock_ds_init();
+ zbx_history_record_vector_create(&expected);
+ zbx_history_record_vector_create(&returned);
+
+ /* precache values */
+ if (ZBX_MOCK_SUCCESS == zbx_mock_parameter("in.precache", &handle))
+ {
+ while (ZBX_MOCK_END_OF_VECTOR != (mock_err = (zbx_mock_vector_element(handle, &hitem))))
+ {
+ zbx_vcmock_set_time(hitem, "time");
+ zbx_vcmock_set_mode(hitem, "cache mode");
+ zbx_vcmock_set_cache_size(hitem, "cache size");
+
+ zbx_vcmock_get_request_params(hitem, &itemid, &value_type, &seconds, &count, &ts);
+ zbx_vc_precache_values(itemid, value_type, seconds, count, &ts);
+ }
+ }
+
+ if (NULL != add_values_cb)
+ {
+ int ret_flush;
+ zbx_vector_ptr_t history;
+
+ add_values_cb(&handle, &history, &err, &data, &ret_flush);
+ }
+ else if (NULL != get_value_cb)
+ {
+ get_value_cb(&handle, &itemid, &value_type, &ts, &err, &expected, &returned);
+ }
+ else if (NULL != get_values_cb)
+ {
+ get_values_cb(&handle, &itemid, &value_type, &ts, &err, &expected, &returned, &seconds,
+ &count);
+ }
+
+ hitems = zbx_mock_get_parameter_handle("out.cache.items");
+
+ while (ZBX_MOCK_END_OF_VECTOR != (mock_err = (zbx_mock_vector_element(hitems, &hitem))))
+ {
+ int item_status, item_active_range, item_db_cached_from, item_values_total;
+ zbx_mock_handle_t hstatus;
+
+ if (ZBX_MOCK_NOT_A_VECTOR == mock_err)
+ fail_msg("out.cache.items parameter is not a vector");
+
+ data = zbx_mock_get_object_member_string(hitem, "itemid");
+ if (SUCCEED != is_uint64(data, &itemid))
+ fail_msg("Invalid itemid \"%s\"", data);
+
+ err = zbx_vc_get_item_state(itemid, &item_status, &item_active_range, &item_values_total,
+ &item_db_cached_from);
+
+ mock_err = zbx_mock_object_member(hitem, "status", &hstatus);
+
+ if (ZBX_MOCK_SUCCESS == mock_err)
+ {
+ zbx_mock_assert_result_eq("zbx_vc_get_item_state() return value", SUCCEED, err);
+
+ if (ZBX_MOCK_SUCCESS != (mock_err = zbx_mock_string(hstatus, &data)))
+ fail_msg("Cannot read item status: %s", zbx_mock_error_string(mock_err));
+
+ zbx_mock_assert_int_eq("item.status", zbx_vcmock_str_to_item_status(data), item_status);
+
+ data = zbx_mock_get_object_member_string(hitem, "active_range");
+ zbx_mock_assert_int_eq("item.active_range", atoi(data), item_active_range);
+
+ data = zbx_mock_get_object_member_string(hitem, "values_total");
+ zbx_mock_assert_int_eq("item.values_total", atoi(data), item_values_total);
+
+ if (ZBX_MOCK_SUCCESS != (mock_err = zbx_strtime_to_timespec(
+ zbx_mock_get_object_member_string(hitem, "db_cached_from"), &ts)))
+ {
+ fail_msg("Cannot read out.item.db_cached_from timestamp: %s",
+ zbx_mock_error_string(mock_err));
+ }
+
+ zbx_mock_assert_time_eq("item.db_cached_from", ts.sec, item_db_cached_from);
+
+ value_type = zbx_mock_str_to_value_type(zbx_mock_get_object_member_string(hitem, "value type"));
+
+ zbx_vcmock_read_values(zbx_mock_get_object_member_handle(hitem, "data"), value_type, &expected);
+ zbx_vc_get_cached_values(itemid, value_type, &returned);
+
+ zbx_vcmock_check_records("Cached values", value_type, &expected, &returned);
+
+ zbx_history_record_vector_clean(&expected, value_type);
+ zbx_history_record_vector_clean(&returned, value_type);
+ }
+ else
+ zbx_mock_assert_result_eq("zbx_vc_get_item_state() return value", FAIL, err);
+ }
+
+ /* validate cache state */
+
+ zbx_vc_get_cache_state(&cache_mode, &cache_hits, &cache_misses);
+ zbx_mock_assert_int_eq("cache.mode",
+ zbx_vcmock_str_to_cache_mode(zbx_mock_get_parameter_string("out.cache.mode")), cache_mode);
+
+ if (1 == test_check_result)
+ zbx_vc_test_check_result(cache_hits, cache_misses);
+
+ /* cleanup */
+
+ zbx_vector_history_record_destroy(&returned);
+ zbx_vector_history_record_destroy(&expected);
+
+ zbx_vcmock_ds_destroy();
+
+ zbx_vc_reset();
+ zbx_vc_destroy();
+}
diff --git a/tests/libs/zbxdbcache/zbx_vc_common.h b/tests/libs/zbxdbcache/zbx_vc_common.h
new file mode 100644
index 00000000000..e7ef5d9dd02
--- /dev/null
+++ b/tests/libs/zbxdbcache/zbx_vc_common.h
@@ -0,0 +1,51 @@
+/*
+** 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 ZBX_VC_COMMON_H
+#define ZBX_VC_COMMON_H
+
+#include "zbxalgo.h"
+#include "zbxhistory.h"
+#include "zbxmockdata.h"
+
+typedef void (*zbx_vc_test_add_values_setup_cb)(zbx_mock_handle_t *handle, zbx_vector_ptr_t *history, int *err,
+ const char **data, int *ret_flush);
+typedef void (*zbx_vc_test_get_value_setup_cb)(zbx_mock_handle_t *handle, zbx_uint64_t *itemid,
+ unsigned char *value_type, zbx_timespec_t *ts, int *err, zbx_vector_history_record_t *expected,
+ zbx_vector_history_record_t *returned);
+typedef void (*zbx_vc_test_get_values_setup_cb)(zbx_mock_handle_t *handle, zbx_uint64_t *itemid,
+ unsigned char *value_type, zbx_timespec_t *ts, int *err, zbx_vector_history_record_t *expected,
+ zbx_vector_history_record_t *returned, int *seconds, int *count);
+
+void zbx_vc_test_add_values_setup(zbx_mock_handle_t *handle, zbx_vector_ptr_t *history, int *err, const char **data,
+ int *ret_flush);
+void zbx_vc_test_get_value_setup(zbx_mock_handle_t *handle, zbx_uint64_t *itemid, unsigned char *value_type,
+ zbx_timespec_t *ts, int *err, zbx_vector_history_record_t *expected,
+ zbx_vector_history_record_t *returned);
+void zbx_vc_test_get_values_setup(zbx_mock_handle_t *handle, zbx_uint64_t *itemid, unsigned char *value_type,
+ zbx_timespec_t *ts, int *err, zbx_vector_history_record_t *expected,
+ zbx_vector_history_record_t *returned, int *seconds, int *count);
+
+void zbx_vc_common_test_func(
+ void **state,
+ zbx_vc_test_add_values_setup_cb add_values_cb,
+ zbx_vc_test_get_value_setup_cb get_value_cb,
+ zbx_vc_test_get_values_setup_cb get_values_cb,
+ int test_check_result);
+#endif
diff --git a/tests/libs/zbxdbcache/zbx_vc_get_value.c b/tests/libs/zbxdbcache/zbx_vc_get_value.c
index 35d4af0f242..90544bc9dde 100644
--- a/tests/libs/zbxdbcache/zbx_vc_get_value.c
+++ b/tests/libs/zbxdbcache/zbx_vc_get_value.c
@@ -27,156 +27,42 @@
#include "valuecache_test.h"
#include "mocks/valuecache/valuecache_mock.h"
+#include "zbx_vc_common.h"
+
extern zbx_uint64_t CONFIG_VALUE_CACHE_SIZE;
-void zbx_mock_test_entry(void **state)
+void zbx_vc_test_get_value_setup(zbx_mock_handle_t *handle, zbx_uint64_t *itemid, unsigned char *value_type,
+ zbx_timespec_t *ts, int *err, zbx_vector_history_record_t *expected,
+ zbx_vector_history_record_t *returned)
{
- char *error = NULL;
- const char *data;
- int err, seconds, count, item_status, item_active_range, item_db_cached_from,
- item_values_total, cache_mode;
- zbx_vector_history_record_t expected, returned;
- zbx_timespec_t ts;
- zbx_uint64_t itemid, cache_hits, cache_misses, expected_hits, expected_misses;
- unsigned char value_type;
- zbx_mock_handle_t handle, hitems, hitem, hstatus;
- zbx_mock_error_t mock_err;
-
- ZBX_UNUSED(state);
-
- /* set small cache size to force smaller cache free request size (5% of cache size) */
- CONFIG_VALUE_CACHE_SIZE = ZBX_KIBIBYTE;
-
- err = zbx_locks_create(&error);
- zbx_mock_assert_result_eq("Lock initialization failed", SUCCEED, err);
-
- err = zbx_vc_init(&error);
- zbx_mock_assert_result_eq("Value cache initialization failed", SUCCEED, err);
-
- zbx_vc_enable();
-
- zbx_vcmock_ds_init();
- zbx_history_record_vector_create(&expected);
- zbx_history_record_vector_create(&returned);
-
- /* precache values */
- if (ZBX_MOCK_SUCCESS == zbx_mock_parameter("in.precache", &handle))
- {
- while (ZBX_MOCK_END_OF_VECTOR != (mock_err = (zbx_mock_vector_element(handle, &hitem))))
- {
- zbx_vcmock_set_time(hitem, "time");
- zbx_vcmock_set_mode(hitem, "cache mode");
- zbx_vcmock_set_cache_size(hitem, "cache size");
-
- zbx_vcmock_get_request_params(hitem, &itemid, &value_type, &seconds, &count, &ts);
- zbx_vc_precache_values(itemid, value_type, seconds, count, &ts);
- }
- }
-
/* perform request */
- handle = zbx_mock_get_parameter_handle("in.test");
- zbx_vcmock_set_time(handle, "time");
- zbx_vcmock_set_mode(handle, "cache mode");
+ *handle = zbx_mock_get_parameter_handle("in.test");
+ zbx_vcmock_set_time(*handle, "time");
+ zbx_vcmock_set_mode(*handle, "cache mode");
- if (FAIL == is_uint64(zbx_mock_get_object_member_string(handle, "itemid"), &itemid))
+ if (FAIL == is_uint64(zbx_mock_get_object_member_string(*handle, "itemid"), itemid))
fail_msg("Invalid itemid value");
- value_type = zbx_mock_str_to_value_type(zbx_mock_get_object_member_string(handle, "value type"));
- zbx_strtime_to_timespec(zbx_mock_get_object_member_string(handle, "end"), &ts);
+ *value_type = zbx_mock_str_to_value_type(zbx_mock_get_object_member_string(*handle, "value type"));
+ zbx_strtime_to_timespec(zbx_mock_get_object_member_string(*handle, "end"), ts);
- zbx_vector_history_record_reserve(&returned, 1);
- err = zbx_vc_get_value(itemid, value_type, &ts, &returned.values[0]);
+ zbx_vector_history_record_reserve(returned, 1);
+ *err = zbx_vc_get_value(*itemid, *value_type, ts, &(*returned).values[0]);
zbx_vc_flush_stats();
- returned.values_num = 1;
- zbx_mock_assert_result_eq("zbx_vc_get_values() return value", SUCCEED, err);
+ returned->values_num = 1;
+ zbx_mock_assert_result_eq("zbx_vc_get_values() return value", SUCCEED, *err);
/* validate results */
- zbx_vcmock_read_values(zbx_mock_get_parameter_handle("out.values"), value_type, &expected);
- zbx_vcmock_check_records("Returned values", value_type, &expected, &returned);
-
- zbx_history_record_vector_clean(&returned, value_type);
- zbx_history_record_vector_clean(&expected, value_type);
-
- /* validate cache contents */
-
- hitems = zbx_mock_get_parameter_handle("out.cache.items");
-
- while (ZBX_MOCK_END_OF_VECTOR != (mock_err = (zbx_mock_vector_element(hitems, &hitem))))
- {
- if (ZBX_MOCK_NOT_A_VECTOR == mock_err)
- fail_msg("out.cache.items parameter is not a vector");
-
- data = zbx_mock_get_object_member_string(hitem, "itemid");
- if (SUCCEED != is_uint64(data, &itemid))
- fail_msg("Invalid itemid \"%s\"", data);
-
- err = zbx_vc_get_item_state(itemid, &item_status, &item_active_range, &item_values_total,
- &item_db_cached_from);
-
- mock_err = zbx_mock_object_member(hitem, "status", &hstatus);
-
- if (ZBX_MOCK_SUCCESS == mock_err)
- {
- zbx_mock_assert_result_eq("zbx_vc_get_item_state() return value", SUCCEED, err);
-
- if (ZBX_MOCK_SUCCESS != (mock_err = zbx_mock_string(hstatus, &data)))
- fail_msg("Cannot read item status: %s", zbx_mock_error_string(mock_err));
+ zbx_vcmock_read_values(zbx_mock_get_parameter_handle("out.values"), *value_type, expected);
+ zbx_vcmock_check_records("Returned values", *value_type, expected, returned);
- zbx_mock_assert_int_eq("item.status", zbx_vcmock_str_to_item_status(data), item_status);
-
- data = zbx_mock_get_object_member_string(hitem, "active_range");
- zbx_mock_assert_int_eq("item.active_range", atoi(data), item_active_range);
-
- data = zbx_mock_get_object_member_string(hitem, "values_total");
- zbx_mock_assert_int_eq("item.values_total", atoi(data), item_values_total);
-
- if (ZBX_MOCK_SUCCESS != (mock_err = zbx_strtime_to_timespec(
- zbx_mock_get_object_member_string(hitem, "db_cached_from"), &ts)))
- {
- fail_msg("Cannot read out.item.db_cached_from timestamp: %s",
- zbx_mock_error_string(mock_err));
- }
-
- zbx_mock_assert_time_eq("item.db_cached_from", ts.sec, item_db_cached_from);
-
- value_type = zbx_mock_str_to_value_type(zbx_mock_get_object_member_string(hitem, "value type"));
-
- zbx_vcmock_read_values(zbx_mock_get_object_member_handle(hitem, "data"), value_type, &expected);
- zbx_vc_get_cached_values(itemid, value_type, &returned);
-
- zbx_vcmock_check_records("Cached values", value_type, &expected, &returned);
-
- zbx_history_record_vector_clean(&expected, value_type);
- zbx_history_record_vector_clean(&returned, value_type);
- }
- else
- zbx_mock_assert_result_eq("zbx_vc_get_item_state() return value", FAIL, err);
- }
-
- /* validate cache state */
-
- zbx_vc_get_cache_state(&cache_mode, &cache_hits, &cache_misses);
- zbx_mock_assert_int_eq("cache.mode", zbx_vcmock_str_to_cache_mode(zbx_mock_get_parameter_string("out.cache.mode")),
- cache_mode);
-
- if (FAIL == is_uint64(zbx_mock_get_parameter_string("out.cache.hits"), &expected_hits))
- fail_msg("Invalid out.cache.hits value");
- zbx_mock_assert_uint64_eq("cache.hits", expected_hits, cache_hits);
-
- if (FAIL == is_uint64(zbx_mock_get_parameter_string("out.cache.misses"), &expected_misses))
- fail_msg("Invalid out.cache.misses value");
- zbx_mock_assert_uint64_eq("cache.misses", expected_misses, cache_misses);
-
- /* cleanup */
-
- zbx_vector_history_record_destroy(&returned);
- zbx_vector_history_record_destroy(&expected);
-
- zbx_vcmock_ds_destroy();
-
- zbx_vc_reset();
- zbx_vc_destroy();
+ zbx_history_record_vector_clean(returned, *value_type);
+ zbx_history_record_vector_clean(expected, *value_type);
}
+void zbx_mock_test_entry(void **state)
+{
+ zbx_vc_common_test_func(state, NULL, zbx_vc_test_get_value_setup, NULL, 1);
+}
diff --git a/tests/libs/zbxdbcache/zbx_vc_get_values.c b/tests/libs/zbxdbcache/zbx_vc_get_values.c
index c90ca2de676..aae57dae753 100644
--- a/tests/libs/zbxdbcache/zbx_vc_get_values.c
+++ b/tests/libs/zbxdbcache/zbx_vc_get_values.c
@@ -27,149 +27,35 @@
#include "valuecache_test.h"
#include "mocks/valuecache/valuecache_mock.h"
+#include "zbx_vc_common.h"
+
extern zbx_uint64_t CONFIG_VALUE_CACHE_SIZE;
-void zbx_mock_test_entry(void **state)
+void zbx_vc_test_get_values_setup(zbx_mock_handle_t *handle, zbx_uint64_t *itemid, unsigned char *value_type,
+ zbx_timespec_t *ts, int *err, zbx_vector_history_record_t *expected,
+ zbx_vector_history_record_t *returned, int *seconds, int *count)
{
- char *error = NULL;
- const char *data;
- int err, seconds, count, item_status, item_active_range, item_db_cached_from,
- item_values_total, cache_mode;
- zbx_vector_history_record_t expected, returned;
- zbx_timespec_t ts;
- zbx_uint64_t itemid, cache_hits, cache_misses, expected_hits, expected_misses;
- unsigned char value_type;
- zbx_mock_handle_t handle, hitems, hitem, hstatus;
- zbx_mock_error_t mock_err;
-
- ZBX_UNUSED(state);
-
- /* set small cache size to force smaller cache free request size (5% of cache size) */
- CONFIG_VALUE_CACHE_SIZE = ZBX_KIBIBYTE;
-
- err = zbx_locks_create(&error);
- zbx_mock_assert_result_eq("Lock initialization failed", SUCCEED, err);
-
- err = zbx_vc_init(&error);
- zbx_mock_assert_result_eq("Value cache initialization failed", SUCCEED, err);
-
- zbx_vc_enable();
-
- zbx_vcmock_ds_init();
- zbx_history_record_vector_create(&expected);
- zbx_history_record_vector_create(&returned);
-
- /* precache values */
- if (ZBX_MOCK_SUCCESS == zbx_mock_parameter("in.precache", &handle))
- {
- while (ZBX_MOCK_END_OF_VECTOR != (mock_err = (zbx_mock_vector_element(handle, &hitem))))
- {
- zbx_vcmock_set_time(hitem, "time");
- zbx_vcmock_set_mode(hitem, "cache mode");
- zbx_vcmock_set_cache_size(hitem, "cache size");
-
- zbx_vcmock_get_request_params(hitem, &itemid, &value_type, &seconds, &count, &ts);
- zbx_vc_precache_values(itemid, value_type, seconds, count, &ts);
- }
- }
-
/* perform request */
- handle = zbx_mock_get_parameter_handle("in.test");
- zbx_vcmock_set_time(handle, "time");
- zbx_vcmock_set_mode(handle, "cache mode");
+ *handle = zbx_mock_get_parameter_handle("in.test");
+ zbx_vcmock_set_time(*handle, "time");
+ zbx_vcmock_set_mode(*handle, "cache mode");
- zbx_vcmock_get_request_params(handle, &itemid, &value_type, &seconds, &count, &ts);
- err = zbx_vc_get_values(itemid, value_type, &returned, seconds, count, &ts);
+ zbx_vcmock_get_request_params(*handle, itemid, value_type, seconds, count, ts);
+ *err = zbx_vc_get_values(*itemid, *value_type, returned, *seconds, *count, ts);
zbx_vc_flush_stats();
- zbx_mock_assert_result_eq("zbx_vc_get_values() return value", SUCCEED, err);
+ zbx_mock_assert_result_eq("zbx_vc_get_values() return value", SUCCEED, *err);
/* validate results */
- zbx_vcmock_read_values(zbx_mock_get_parameter_handle("out.values"), value_type, &expected);
- zbx_vcmock_check_records("Returned values", value_type, &expected, &returned);
-
- zbx_history_record_vector_clean(&returned, value_type);
- zbx_history_record_vector_clean(&expected, value_type);
-
- /* validate cache contents */
-
- hitems = zbx_mock_get_parameter_handle("out.cache.items");
-
- while (ZBX_MOCK_END_OF_VECTOR != (mock_err = (zbx_mock_vector_element(hitems, &hitem))))
- {
- if (ZBX_MOCK_NOT_A_VECTOR == mock_err)
- fail_msg("out.cache.items parameter is not a vector");
-
- data = zbx_mock_get_object_member_string(hitem, "itemid");
- if (SUCCEED != is_uint64(data, &itemid))
- fail_msg("Invalid itemid \"%s\"", data);
-
- err = zbx_vc_get_item_state(itemid, &item_status, &item_active_range, &item_values_total,
- &item_db_cached_from);
-
- mock_err = zbx_mock_object_member(hitem, "status", &hstatus);
-
- if (ZBX_MOCK_SUCCESS == mock_err)
- {
- zbx_mock_assert_result_eq("zbx_vc_get_item_state() return value", SUCCEED, err);
-
- if (ZBX_MOCK_SUCCESS != (mock_err = zbx_mock_string(hstatus, &data)))
- fail_msg("Cannot read item status: %s", zbx_mock_error_string(mock_err));
+ zbx_vcmock_read_values(zbx_mock_get_parameter_handle("out.values"), *value_type, expected);
+ zbx_vcmock_check_records("Returned values", *value_type, expected, returned);
- zbx_mock_assert_int_eq("item.status", zbx_vcmock_str_to_item_status(data), item_status);
-
- data = zbx_mock_get_object_member_string(hitem, "active_range");
- zbx_mock_assert_int_eq("item.active_range", atoi(data), item_active_range);
-
- data = zbx_mock_get_object_member_string(hitem, "values_total");
- zbx_mock_assert_int_eq("item.values_total", atoi(data), item_values_total);
-
- if (ZBX_MOCK_SUCCESS != (mock_err = zbx_strtime_to_timespec(
- zbx_mock_get_object_member_string(hitem, "db_cached_from"), &ts)))
- {
- fail_msg("Cannot read out.item.db_cached_from timestamp: %s",
- zbx_mock_error_string(mock_err));
- }
-
- zbx_mock_assert_time_eq("item.db_cached_from", ts.sec, item_db_cached_from);
-
- value_type = zbx_mock_str_to_value_type(zbx_mock_get_object_member_string(hitem, "value type"));
-
- zbx_vcmock_read_values(zbx_mock_get_object_member_handle(hitem, "data"), value_type, &expected);
- zbx_vc_get_cached_values(itemid, value_type, &returned);
-
- zbx_vcmock_check_records("Cached values", value_type, &expected, &returned);
-
- zbx_history_record_vector_clean(&expected, value_type);
- zbx_history_record_vector_clean(&returned, value_type);
- }
- else
- zbx_mock_assert_result_eq("zbx_vc_get_item_state() return value", FAIL, err);
- }
-
- /* validate cache state */
-
- zbx_vc_get_cache_state(&cache_mode, &cache_hits, &cache_misses);
- zbx_mock_assert_int_eq("cache.mode", zbx_vcmock_str_to_cache_mode(zbx_mock_get_parameter_string("out.cache.mode")),
- cache_mode);
-
- if (FAIL == is_uint64(zbx_mock_get_parameter_string("out.cache.hits"), &expected_hits))
- fail_msg("Invalid out.cache.hits value");
- zbx_mock_assert_uint64_eq("cache.hits", expected_hits, cache_hits);
-
- if (FAIL == is_uint64(zbx_mock_get_parameter_string("out.cache.misses"), &expected_misses))
- fail_msg("Invalid out.cache.misses value");
- zbx_mock_assert_uint64_eq("cache.misses", expected_misses, cache_misses);
-
- /* cleanup */
-
- zbx_vector_history_record_destroy(&returned);
- zbx_vector_history_record_destroy(&expected);
-
- zbx_vcmock_ds_destroy();
-
- zbx_vc_reset();
- zbx_vc_destroy();
+ zbx_history_record_vector_clean(returned, *value_type);
+ zbx_history_record_vector_clean(expected, *value_type);
}
+void zbx_mock_test_entry(void **state)
+{
+ zbx_vc_common_test_func(state, NULL, NULL, zbx_vc_test_get_values_setup, 1);
+}
diff --git a/tests/libs/zbxeval/zbx_eval_execute.c b/tests/libs/zbxeval/zbx_eval_execute.c
index e52f15dea88..97d58b01c1d 100644
--- a/tests/libs/zbxeval/zbx_eval_execute.c
+++ b/tests/libs/zbxeval/zbx_eval_execute.c
@@ -77,8 +77,23 @@ void zbx_mock_test_entry(void **state)
if (SUCCEED == expected_ret)
{
- zbx_mock_assert_str_eq("output value", zbx_mock_get_parameter_string("out.value"),
+ /* use custom epsilon for floating point values to account for */
+ /* rounding differences with various systems/libs */
+ if (ZBX_VARIANT_DBL == value.type)
+ {
+ double expected_value;
+
+ expected_value = atof(zbx_mock_get_parameter_string("out.value"));
+
+ if (1e-12 < fabs(value.data.dbl - expected_value))
+ fail_msg("Expected value \"%f\" while got \"%f\"", expected_value, value.data.dbl);
+ }
+ else
+ {
+ zbx_mock_assert_str_eq("output value", zbx_mock_get_parameter_string("out.value"),
zbx_variant_value_desc(&value));
+ }
+
zbx_variant_clear(&value);
}
out:
diff --git a/tests/libs/zbxserver/macro_fmttime.c b/tests/libs/zbxserver/macro_fmttime.c
index 6ff357093b9..a2e8bee1eb1 100644
--- a/tests/libs/zbxserver/macro_fmttime.c
+++ b/tests/libs/zbxserver/macro_fmttime.c
@@ -25,10 +25,52 @@
#include "common.h"
#include "macrofunc.h"
#include "log.h"
+#include "zbxserver.h"
#include "valuecache.h"
#include "mocks/valuecache/valuecache_mock.h"
+int __wrap_substitute_simple_macros(zbx_uint64_t *actionid, const DB_EVENT *event, const DB_EVENT *r_event,
+ zbx_uint64_t *userid, const zbx_uint64_t *hostid, const DC_HOST *dc_host, const DC_ITEM *dc_item,
+ DB_ALERT *alert, const DB_ACKNOWLEDGE *ack, const zbx_service_alarm_t *service_alarm,
+ const DB_SERVICE *service, const char *tz, char **data, int macro_type, char *error,
+ int maxerrlen);
+
+int __wrap_DCget_data_expected_from(zbx_uint64_t itemid, int *seconds);
+
+int __wrap_substitute_simple_macros(zbx_uint64_t *actionid, const DB_EVENT *event, const DB_EVENT *r_event,
+ zbx_uint64_t *userid, const zbx_uint64_t *hostid, const DC_HOST *dc_host, const DC_ITEM *dc_item,
+ DB_ALERT *alert, const DB_ACKNOWLEDGE *ack, const zbx_service_alarm_t *service_alarm,
+ const DB_SERVICE *service, const char *tz, char **data, int macro_type, char *error,
+ int maxerrlen)
+{
+ ZBX_UNUSED(actionid);
+ ZBX_UNUSED(event);
+ ZBX_UNUSED(r_event);
+ ZBX_UNUSED(userid);
+ ZBX_UNUSED(hostid);
+ ZBX_UNUSED(dc_host);
+ ZBX_UNUSED(dc_item);
+ ZBX_UNUSED(alert);
+ ZBX_UNUSED(ack);
+ ZBX_UNUSED(tz);
+ ZBX_UNUSED(data);
+ ZBX_UNUSED(macro_type);
+ ZBX_UNUSED(error);
+ ZBX_UNUSED(maxerrlen);
+ ZBX_UNUSED(service_alarm);
+ ZBX_UNUSED(service);
+
+ return SUCCEED;
+}
+
+int __wrap_DCget_data_expected_from(zbx_uint64_t itemid, int *seconds)
+{
+ ZBX_UNUSED(itemid);
+ *seconds = zbx_vcmock_get_ts().sec - 600;
+ return SUCCEED;
+}
+
void zbx_mock_test_entry(void **state)
{
const size_t macro_pos = 1, macro_pos_end = 6, func_pos = 8, func_param_pos = 15;
diff --git a/tests/libs/zbxsysinfo/aix/Makefile.am b/tests/libs/zbxsysinfo/aix/Makefile.am
new file mode 100644
index 00000000000..a53a4f35a6f
--- /dev/null
+++ b/tests/libs/zbxsysinfo/aix/Makefile.am
@@ -0,0 +1 @@
+noinst_PROGRAMS = $(AGENT_tests)
diff --git a/tests/libs/zbxsysinfo/freebsd/Makefile.am b/tests/libs/zbxsysinfo/freebsd/Makefile.am
new file mode 100644
index 00000000000..a53a4f35a6f
--- /dev/null
+++ b/tests/libs/zbxsysinfo/freebsd/Makefile.am
@@ -0,0 +1 @@
+noinst_PROGRAMS = $(AGENT_tests)
diff --git a/tests/libs/zbxsysinfo/hpux/Makefile.am b/tests/libs/zbxsysinfo/hpux/Makefile.am
new file mode 100644
index 00000000000..a53a4f35a6f
--- /dev/null
+++ b/tests/libs/zbxsysinfo/hpux/Makefile.am
@@ -0,0 +1 @@
+noinst_PROGRAMS = $(AGENT_tests)
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", &param_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", &param_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(&param_result);
+
+ if (ZABBIX_MOCK_KERNEL_MAXPROC == kernel_func)
+ actual_result = KERNEL_MAXPROC(&request, &param_result);
+ else if (ZABBIX_MOCK_KERNEL_MAXFILES == kernel_func)
+ actual_result = KERNEL_MAXFILES(&request, &param_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(&param_result))
+ fail_msg("Got 'NULL' instead of '%s' as a value.", expected_param_value_string);
+
+ if (expected_param_value != *GET_UI64_RESULT(&param_result))
+ {
+ fail_msg("Got '" ZBX_FS_UI64 "' instead of '%s' as a value.", *GET_UI64_RESULT(&param_result),
+ expected_param_value_string);
+ }
+ }
+
+ if (SYSINFO_RET_FAIL == expected_result)
+ {
+ if (NULL == GET_MSG_RESULT(&param_result) || 0 != strcmp(expected_param_value_string,
+ *GET_MSG_RESULT(&param_result)))
+ {
+ fail_msg("Got '%s' instead of '%s' as a value.",
+ (NULL != GET_MSG_RESULT(&param_result) ?
+ *GET_MSG_RESULT(&param_result) : "NULL"),
+ expected_param_value_string);
+ }
+ }
+
+ free_request(&request);
+ free_result(&param_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", &param_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", &param_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(&param_result);
-
- if (expected_result != (actual_result = KERNEL_MAXFILES(&request, &param_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(&param_result))
- fail_msg("Got 'NULL' instead of '%s' as a value.", expected_param_value_string);
-
- if (expected_param_value != *GET_UI64_RESULT(&param_result))
- {
- fail_msg("Got '" ZBX_FS_UI64 "' instead of '%s' as a value.", *GET_UI64_RESULT(&param_result),
- expected_param_value_string);
- }
- }
-
- if (SYSINFO_RET_FAIL == expected_result)
- {
- if (NULL == GET_MSG_RESULT(&param_result) ||
- 0 != strcmp(expected_param_value_string, *GET_MSG_RESULT(&param_result)))
- {
- fail_msg("Got '%s' instead of '%s' as a value.",
- (NULL != GET_MSG_RESULT(&param_result) ?
- *GET_MSG_RESULT(&param_result) : "NULL"),
- expected_param_value_string);
- }
- }
-
- free_request(&request);
- free_result(&param_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", &param_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", &param_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(&param_result);
-
- if (expected_result != (actual_result = KERNEL_MAXPROC(&request, &param_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(&param_result))
- fail_msg("Got 'NULL' instead of '%s' as a value.", expected_param_value_string);
-
- if (expected_param_value != *GET_UI64_RESULT(&param_result))
- {
- fail_msg("Got '" ZBX_FS_UI64 "' instead of '%s' as a value.", *GET_UI64_RESULT(&param_result),
- expected_param_value_string);
- }
- }
-
- if (SYSINFO_RET_FAIL == expected_result)
- {
- if (NULL == GET_MSG_RESULT(&param_result) || 0 != strcmp(expected_param_value_string,
- *GET_MSG_RESULT(&param_result)))
- {
- fail_msg("Got '%s' instead of '%s' as a value.",
- (NULL != GET_MSG_RESULT(&param_result) ?
- *GET_MSG_RESULT(&param_result) : "NULL"),
- expected_param_value_string);
- }
- }
-
- free_request(&request);
- free_result(&param_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", &param_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", &param_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", &param_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(&param_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, &param_result);
+ else if (ZABBIX_MOCK_NET_IF_OUT == net_if_func)
+ actual_result = NET_IF_OUT(&request, &param_result);
+ else if (ZABBIX_MOCK_NET_IF_TOTAL == net_if_func)
+ actual_result = NET_IF_TOTAL(&request, &param_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(&param_result) || expected_param_value != *GET_UI64_RESULT(&param_result))
+ {
+ if (NULL != GET_UI64_RESULT(&param_result))
+ {
+ fail_msg("Got '" ZBX_FS_UI64 "' instead of '%s' as a value.",
+ *GET_UI64_RESULT(&param_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(&param_result) ||
+ 0 != strcmp(expected_param_value_string, *GET_MSG_RESULT(&param_result)))
+ {
+ fail_msg("Got '%s' instead of '%s' as a value.",
+ (NULL != GET_MSG_RESULT(&param_result) ?
+ *GET_MSG_RESULT(&param_result) : "NULL"),
+ expected_param_value_string);
+ }
+ }
+
+ free_request(&request);
+ free_result(&param_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", &param_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", &param_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", &param_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(&param_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,&param_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(&param_result) || expected_param_value != *GET_UI64_RESULT(&param_result))
- {
- if (NULL != GET_UI64_RESULT(&param_result))
- {
- fail_msg("Got '" ZBX_FS_UI64 "' instead of '%s' as a value.",
- *GET_UI64_RESULT(&param_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(&param_result) ||
- 0 != strcmp(expected_param_value_string, *GET_MSG_RESULT(&param_result)))
- {
- fail_msg("Got '%s' instead of '%s' as a value.",
- (NULL != GET_MSG_RESULT(&param_result) ?
- *GET_MSG_RESULT(&param_result) : "NULL"),
- expected_param_value_string);
- }
- }
-
- free_request(&request);
- free_result(&param_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", &param_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", &param_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", &param_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(&param_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,&param_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(&param_result) || expected_param_value != *GET_UI64_RESULT(&param_result))
- {
- if (NULL != GET_UI64_RESULT(&param_result))
- {
- fail_msg("Got '" ZBX_FS_UI64 "' instead of '%s' as a value.",
- *GET_UI64_RESULT(&param_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(&param_result) ||
- 0 != strcmp(expected_param_value_string, *GET_MSG_RESULT(&param_result)))
- {
- fail_msg("Got '%s' instead of '%s' as a value.",
- (NULL != GET_MSG_RESULT(&param_result) ?
- *GET_MSG_RESULT(&param_result) : "NULL"),
- expected_param_value_string);
- }
- }
-
- free_request(&request);
- free_result(&param_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", &param_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", &param_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", &param_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(&param_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,&param_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(&param_result) || expected_param_value != *GET_UI64_RESULT(&param_result))
- {
- if (NULL != GET_UI64_RESULT(&param_result))
- {
- fail_msg("Got '" ZBX_FS_UI64 "' instead of '%s' as a value.",
- *GET_UI64_RESULT(&param_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(&param_result) ||
- 0 != strcmp(expected_param_value_string, *GET_MSG_RESULT(&param_result)))
- {
- fail_msg("Got '%s' instead of '%s' as a value.",
- (NULL != GET_MSG_RESULT(&param_result) ?
- *GET_MSG_RESULT(&param_result) : "NULL"),
- expected_param_value_string);
- }
- }
-
- free_request(&request);
- free_result(&param_result);
+ zbx_mock_test_entry_NET_IF_COMMON(state, ZABBIX_MOCK_NET_IF_TOTAL);
}
diff --git a/tests/libs/zbxsysinfo/netbsd/Makefile.am b/tests/libs/zbxsysinfo/netbsd/Makefile.am
new file mode 100644
index 00000000000..a53a4f35a6f
--- /dev/null
+++ b/tests/libs/zbxsysinfo/netbsd/Makefile.am
@@ -0,0 +1 @@
+noinst_PROGRAMS = $(AGENT_tests)
diff --git a/tests/libs/zbxsysinfo/openbsd/Makefile.am b/tests/libs/zbxsysinfo/openbsd/Makefile.am
new file mode 100644
index 00000000000..a53a4f35a6f
--- /dev/null
+++ b/tests/libs/zbxsysinfo/openbsd/Makefile.am
@@ -0,0 +1 @@
+noinst_PROGRAMS = $(AGENT_tests)
diff --git a/tests/libs/zbxsysinfo/osf/Makefile.am b/tests/libs/zbxsysinfo/osf/Makefile.am
new file mode 100644
index 00000000000..a53a4f35a6f
--- /dev/null
+++ b/tests/libs/zbxsysinfo/osf/Makefile.am
@@ -0,0 +1 @@
+noinst_PROGRAMS = $(AGENT_tests)
diff --git a/tests/libs/zbxsysinfo/osx/Makefile.am b/tests/libs/zbxsysinfo/osx/Makefile.am
new file mode 100644
index 00000000000..a53a4f35a6f
--- /dev/null
+++ b/tests/libs/zbxsysinfo/osx/Makefile.am
@@ -0,0 +1 @@
+noinst_PROGRAMS = $(AGENT_tests)
diff --git a/tests/libs/zbxsysinfo/solaris/Makefile.am b/tests/libs/zbxsysinfo/solaris/Makefile.am
new file mode 100644
index 00000000000..a53a4f35a6f
--- /dev/null
+++ b/tests/libs/zbxsysinfo/solaris/Makefile.am
@@ -0,0 +1 @@
+noinst_PROGRAMS = $(AGENT_tests)
diff --git a/tests/libs/zbxsysinfo/unknown/Makefile.am b/tests/libs/zbxsysinfo/unknown/Makefile.am
new file mode 100644
index 00000000000..a53a4f35a6f
--- /dev/null
+++ b/tests/libs/zbxsysinfo/unknown/Makefile.am
@@ -0,0 +1 @@
+noinst_PROGRAMS = $(AGENT_tests)
diff --git a/tests/mocks/configcache/configcache.c b/tests/mocks/configcache/configcache.c
index 4319cca2f23..eb9566bf105 100644
--- a/tests/mocks/configcache/configcache.c
+++ b/tests/mocks/configcache/configcache.c
@@ -18,20 +18,7 @@
**/
#include "configcache.h"
-
-#include "zbxmocktest.h"
-#include "zbxmockdata.h"
-#include "zbxmockassert.h"
-#include "zbxmockutil.h"
-
-#include "zbxserver.h"
-#include "common.h"
-#include "zbxalgo.h"
-#include "dbcache.h"
-#include "mutexs.h"
-
-#define ZBX_DBCONFIG_IMPL
-#include "dbconfig.h"
+#include "configcache_mock.h"
zbx_mock_config_t mock_config;
@@ -45,6 +32,13 @@ void *__wrap_zbx_hashset_search(zbx_hashset_t *hs, const void *data)
{
int i;
+ if (&mock_config.dc.items == hs)
+ {
+ static ZBX_DC_ITEM item = {.hostid = 1};
+
+ return &item;
+ }
+
if (0 != (mock_config.initialized & ZBX_MOCK_CONFIG_USERMACROS))
{
if (hs == &mock_config.dc.hmacros_hm)
diff --git a/tests/mocks/configcache/configcache.h b/tests/mocks/configcache/configcache.h
index 944e98730a0..736a3b3e2b6 100644
--- a/tests/mocks/configcache/configcache.h
+++ b/tests/mocks/configcache/configcache.h
@@ -17,25 +17,13 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
-#include "zbxmocktest.h"
-#include "zbxmockdata.h"
-#include "zbxmockassert.h"
-#include "zbxmockutil.h"
+#ifndef ZABBIX_CONFIGCACHE_H
+#define ZABBIX_CONFIGCACHE_H
-#include "zbxserver.h"
#include "common.h"
#include "zbxalgo.h"
-#include "dbcache.h"
-#include "mutexs.h"
-
-#define ZBX_DBCONFIG_IMPL
#include "dbconfig.h"
-#include "configcache_mock.h"
-
-#ifndef ZABBIX_CONFIGCACHE_H
-#define ZABBIX_CONFIGCACHE_H
-
typedef struct
{
ZBX_DC_CONFIG dc;
diff --git a/tests/mocks/configcache/configcache_mock.h b/tests/mocks/configcache/configcache_mock.h
index 4a11e1f2b81..603b09cc0ac 100644
--- a/tests/mocks/configcache/configcache_mock.h
+++ b/tests/mocks/configcache/configcache_mock.h
@@ -17,17 +17,6 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
-#include "zbxmocktest.h"
-#include "zbxmockdata.h"
-#include "zbxmockassert.h"
-#include "zbxmockutil.h"
-
-#include "zbxserver.h"
-#include "common.h"
-#include "zbxalgo.h"
-#include "dbcache.h"
-#include "mutexs.h"
-
#ifndef ZABBIX_CONFIGCACHE_MOCK_H
#define ZABBIX_CONFIGCACHE_MOCK_H
@@ -37,5 +26,4 @@ void mock_config_free(void);
void mock_config_load_user_macros(const char *path);
void mock_config_load_hosts(const char *path);
-
#endif
diff --git a/tests/mocks/configcache/hosts.c b/tests/mocks/configcache/hosts.c
index ea67b094aa2..e99604ec048 100644
--- a/tests/mocks/configcache/hosts.c
+++ b/tests/mocks/configcache/hosts.c
@@ -27,10 +27,9 @@
#include "zbxalgo.h"
#include "dbcache.h"
#include "mutexs.h"
-#define ZBX_DBCONFIG_IMPL
#include "dbconfig.h"
-
#include "configcache.h"
+#include "configcache_mock.h"
extern zbx_mock_config_t mock_config;
diff --git a/tests/mocks/configcache/usermacros.c b/tests/mocks/configcache/usermacros.c
index fb80e499d58..44b8885f726 100644
--- a/tests/mocks/configcache/usermacros.c
+++ b/tests/mocks/configcache/usermacros.c
@@ -19,18 +19,10 @@
#include "zbxmocktest.h"
#include "zbxmockdata.h"
-#include "zbxmockassert.h"
#include "zbxmockutil.h"
-
-#include "zbxserver.h"
-#include "common.h"
-#include "zbxalgo.h"
-#include "dbcache.h"
-#include "mutexs.h"
-#define ZBX_DBCONFIG_IMPL
#include "dbconfig.h"
-
#include "configcache.h"
+#include "configcache_mock.h"
extern zbx_mock_config_t mock_config;
diff --git a/tests/zabbix_server/service/Makefile.am b/tests/zabbix_server/service/Makefile.am
index 7bef71d44f1..622d172f973 100644
--- a/tests/zabbix_server/service/Makefile.am
+++ b/tests/zabbix_server/service/Makefile.am
@@ -20,12 +20,16 @@ COMMON_LIBS = \
$(top_srcdir)/src/zabbix_server/availability/libavailability.a \
$(top_srcdir)/src/libs/zbxipcservice/libzbxipcservice.a \
$(top_srcdir)/src/libs/zbxtrends/libzbxtrends.a \
+ $(top_srcdir)/src/libs/zbxtrends/libzbxtrends_baseline.a \
$(top_srcdir)/src/zabbix_server/libzbxserver.a \
$(top_srcdir)/src/libs/zbxserver/libzbxserver.a \
$(top_srcdir)/src/libs/zbxservice/libzbxservice.a \
$(top_srcdir)/src/zabbix_server/service/libservice.a \
+ $(top_srcdir)/src/libs/zbxxml/libzbxxml.a \
$(top_srcdir)/src/libs/zbxeval/libzbxeval.a \
$(top_srcdir)/src/libs/zbxsysinfo/libzbxserversysinfo.a \
+ $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo_httpmetrics.a \
+ $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo_http.a \
$(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo.a \
$(top_srcdir)/src/libs/zbxsysinfo/simple/libsimplesysinfo.a \
$(top_srcdir)/src/libs/zbxhistory/libzbxhistory.a \
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);
diff --git a/tests/zbxmockexit.c b/tests/zbxmockexit.c
index 932aa63bec6..2a1d5a73dd2 100644
--- a/tests/zbxmockexit.c
+++ b/tests/zbxmockexit.c
@@ -34,10 +34,12 @@ void __wrap_exit(int status)
int expected_status;
if (ZBX_MOCK_NO_EXIT_CODE == (error = zbx_mock_exit_code(&expected_status)))
- fail_msg("exit() was not expected, exitcode: %d.", status);
-
- if (ZBX_MOCK_SUCCESS != error)
- fail_msg("Cannot get exit code from test case data: %s", zbx_mock_error_string(error));
+ expected_status = EXIT_SUCCESS;
+ else
+ {
+ if (ZBX_MOCK_SUCCESS != error)
+ fail_msg("Cannot get exit code from test case data: %s", zbx_mock_error_string(error));
+ }
switch (status)
{
diff --git a/tests/zbxmockfile.c b/tests/zbxmockfile.c
index de129859439..2b15d2cfe2a 100644
--- a/tests/zbxmockfile.c
+++ b/tests/zbxmockfile.c
@@ -45,16 +45,20 @@ struct zbx_mock_IO_FILE
FILE *__wrap_fopen(const char *path, const char *mode);
int __wrap_fclose(FILE *fp);
char *__wrap_fgets(char *s, int size, FILE *stream);
-int __wrap_connect(int socket, __CONST_SOCKADDR_ARG addr, socklen_t address_len);
+int __wrap_connect(int socket, void *addr, socklen_t address_len);
ssize_t __wrap_read(int fildes, void *buf, size_t nbyte);
int __wrap_open(const char *path, int oflag, ...);
int __wrap_stat(const char *path, struct stat *buf);
int __wrap___xstat(int ver, const char *pathname, struct stat *buf);
+#ifdef HAVE_FXSTAT
int __wrap___fxstat(int __ver, int __fildes, struct stat *__stat_buf);
+#endif
int __real_open(const char *path, int oflag, ...);
int __real_stat(const char *path, struct stat *buf);
+#ifdef HAVE_FXSTAT
int __real___fxstat(int __ver, int __fildes, struct stat *__stat_buf);
+#endif
static int is_profiler_path(const char *path)
{
@@ -168,7 +172,7 @@ char *__wrap_fgets(char *s, int size, FILE *stream)
return s;
}
-int __wrap_connect(int socket, __CONST_SOCKADDR_ARG addr, socklen_t address_len)
+int __wrap_connect(int socket, void *addr, socklen_t address_len)
{
zbx_mock_error_t error;
@@ -283,6 +287,7 @@ int __wrap___xstat(int ver, const char *pathname, struct stat *buf)
return __wrap_stat(pathname, buf);
}
+#ifdef HAVE_FXSTAT
int __wrap___fxstat(int __ver, int __fildes, struct stat *__stat_buf)
{
if (__fildes != INT_MAX)
@@ -292,3 +297,4 @@ int __wrap___fxstat(int __ver, int __fildes, struct stat *__stat_buf)
return 0;
}
+#endif
diff --git a/tests/zbxmocktest.c b/tests/zbxmocktest.c
index 190fc7df3f2..9755b65dd42 100644
--- a/tests/zbxmocktest.c
+++ b/tests/zbxmocktest.c
@@ -57,7 +57,7 @@ int CONFIG_PREPROCESSOR_FORKS = 3;
int CONFIG_HISTORYPOLLER_FORKS = 5;
int CONFIG_AVAILMAN_FORKS = 1;
int CONFIG_SERVICEMAN_FORKS = 0;
-int CONFIG_PROBLEMHOUSEKEEPER_FORKS = 0;
+int CONFIG_TRIGGERHOUSEKEEPER_FORKS = 0;
int CONFIG_ODBCPOLLER_FORKS = 5;
int CONFIG_LISTEN_PORT = 0;
diff --git a/tests/zbxmocktest.h b/tests/zbxmocktest.h
index 6e34920ffa9..50f4c135356 100644
--- a/tests/zbxmocktest.h
+++ b/tests/zbxmocktest.h
@@ -34,8 +34,6 @@
# define ZBX_NO_RETURN
#endif
-ZBX_NO_RETURN void _fail(const char * const file, const int line);
-
void zbx_mock_test_entry(void **state);
#endif /* ZABBIX_MOCK_TEST_H */
diff --git a/tests/zbxmockutil.c b/tests/zbxmockutil.c
index 187980dba8e..7e8f9b0521c 100644
--- a/tests/zbxmockutil.c
+++ b/tests/zbxmockutil.c
@@ -26,7 +26,7 @@
#include "module.h"
#include "zbxvariant.h"
-#include <malloc.h>
+#include <stdlib.h>
const char *zbx_mock_get_parameter_string(const char *path)
{