From 390ba7d40198a429da4189a77465ab273e32d21a Mon Sep 17 00:00:00 2001 From: Andris Zeila Date: Fri, 14 Jan 2022 09:30:58 +0200 Subject: ........S. [ZBXNEXT-7411] renamed problem housekeeper to trigger housekeeper --- tests/zbxmocktest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/zbxmocktest.c b/tests/zbxmocktest.c index 13c844c3d07..bc42f2fc478 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; -- cgit v1.2.3 From a2e97b410d4bcf8ede297c3978e234a37c491a88 Mon Sep 17 00:00:00 2001 From: Vladislavs Sokurenko Date: Fri, 14 Jan 2022 12:13:30 +0200 Subject: .......... [ZBXNEXT-7411] fixed cmocka tests on non Linux systems --- tests/conf_tests.m4 | 39 ++++++++++++++++++++++++++++--- tests/libs/zbxalgo/queue.c | 2 +- tests/libs/zbxsysinfo/aix/Makefile.am | 1 + tests/libs/zbxsysinfo/freebsd/Makefile.am | 1 + tests/libs/zbxsysinfo/hpux/Makefile.am | 1 + tests/libs/zbxsysinfo/netbsd/Makefile.am | 1 + tests/libs/zbxsysinfo/openbsd/Makefile.am | 1 + tests/libs/zbxsysinfo/osf/Makefile.am | 1 + tests/libs/zbxsysinfo/osx/Makefile.am | 1 + tests/libs/zbxsysinfo/solaris/Makefile.am | 1 + tests/libs/zbxsysinfo/unknown/Makefile.am | 1 + tests/zbxmockexit.c | 10 ++++---- tests/zbxmockfile.c | 16 ++----------- tests/zbxmockutil.c | 2 +- 14 files changed, 55 insertions(+), 23 deletions(-) create mode 100644 tests/libs/zbxsysinfo/aix/Makefile.am create mode 100644 tests/libs/zbxsysinfo/freebsd/Makefile.am create mode 100644 tests/libs/zbxsysinfo/hpux/Makefile.am create mode 100644 tests/libs/zbxsysinfo/netbsd/Makefile.am create mode 100644 tests/libs/zbxsysinfo/openbsd/Makefile.am create mode 100644 tests/libs/zbxsysinfo/osf/Makefile.am create mode 100644 tests/libs/zbxsysinfo/osx/Makefile.am create mode 100644 tests/libs/zbxsysinfo/solaris/Makefile.am create mode 100644 tests/libs/zbxsysinfo/unknown/Makefile.am (limited to 'tests') diff --git a/tests/conf_tests.m4 b/tests/conf_tests.m4 index 84b091db560..7ddc6c5d40e 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,37 @@ 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 ]) 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 +#include #include "zbxalgo.h" 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/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/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..3d68b50a76a 100644 --- a/tests/zbxmockfile.c +++ b/tests/zbxmockfile.c @@ -45,16 +45,14 @@ 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); -int __wrap___fxstat(int __ver, int __fildes, struct stat *__stat_buf); int __real_open(const char *path, int oflag, ...); int __real_stat(const char *path, struct stat *buf); -int __real___fxstat(int __ver, int __fildes, struct stat *__stat_buf); static int is_profiler_path(const char *path) { @@ -168,7 +166,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; @@ -282,13 +280,3 @@ int __wrap___xstat(int ver, const char *pathname, struct stat *buf) return __wrap_stat(pathname, buf); } - -int __wrap___fxstat(int __ver, int __fildes, struct stat *__stat_buf) -{ - if (__fildes != INT_MAX) - return __real___fxstat(__ver, __fildes, __stat_buf); - - __stat_buf->st_size = zbx_mock_get_parameter_uint64("in.file_len"); - - return 0; -} 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 +#include const char *zbx_mock_get_parameter_string(const char *path) { -- cgit v1.2.3 From d1b45ddb51ca9663e0dffafba833e9a99d13ecee Mon Sep 17 00:00:00 2001 From: Vladislavs Sokurenko Date: Fri, 14 Jan 2022 15:53:13 +0200 Subject: .......... [ZBXNEXT-7411] fixed some cmocka compilation errors when using clang --- tests/zabbix_server/service/Makefile.am | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests') diff --git a/tests/zabbix_server/service/Makefile.am b/tests/zabbix_server/service/Makefile.am index f9b85c60d95..08aa9e3a7a0 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 \ -- cgit v1.2.3 From 51e09a6fb309b0f7a7ebcf05de642da51aa2c16c Mon Sep 17 00:00:00 2001 From: Andris Zeila Date: Fri, 14 Jan 2022 15:54:38 +0200 Subject: .......... [ZBXNEXT-7411] updated zbx_eval_exec test case to allow result variances because of math functions --- tests/libs/zbxeval/zbx_eval_execute.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/libs/zbxeval/zbx_eval_execute.c b/tests/libs/zbxeval/zbx_eval_execute.c index e52f15dea88..1f65b10f4f8 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 sytems/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: -- cgit v1.2.3 From 35e168e5de2e159934504bc2e16175061a223b59 Mon Sep 17 00:00:00 2001 From: Vladislavs Sokurenko Date: Sun, 16 Jan 2022 00:41:55 +0200 Subject: .......... [ZBXNEXT-7411] fixed tests on older platforms --- tests/conf_tests.m4 | 11 +++++++++++ tests/zbxmockfile.c | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) (limited to 'tests') diff --git a/tests/conf_tests.m4 b/tests/conf_tests.m4 index 7ddc6c5d40e..9a25dc1c2b7 100644 --- a/tests/conf_tests.m4 +++ b/tests/conf_tests.m4 @@ -82,4 +82,15 @@ AC_DEFUN([CONF_TESTS], AC_CONFIG_FILES([tests/libs/zbxsysinfo/unknown/Makefile]) ;; esac + + +AC_TRY_LINK( +[ +#include +], +[ + __fxstat(0, 0, NULL); +], +AC_DEFINE([HAVE_FXSTAT], [1], [Define to 1 if fxstat function is available])) + ]) diff --git a/tests/zbxmockfile.c b/tests/zbxmockfile.c index 3d68b50a76a..2b15d2cfe2a 100644 --- a/tests/zbxmockfile.c +++ b/tests/zbxmockfile.c @@ -50,9 +50,15 @@ 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) { @@ -280,3 +286,15 @@ 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) + return __real___fxstat(__ver, __fildes, __stat_buf); + + __stat_buf->st_size = zbx_mock_get_parameter_uint64("in.file_len"); + + return 0; +} +#endif -- cgit v1.2.3 From 1a92b34b2ab3df712a2d0a7d2171d0fe458b8197 Mon Sep 17 00:00:00 2001 From: Andris Zeila Date: Mon, 17 Jan 2022 11:27:43 +0200 Subject: .......... [ZBXNEXT-7411] fixed cmocka test building on freebsd using clang compiler --- tests/libs/zbxserver/macro_fmttime.c | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'tests') 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; -- cgit v1.2.3 From 09db04f1c6bcdb0d41ef5a389b5fe9349870c72d Mon Sep 17 00:00:00 2001 From: Andris Zeila Date: Wed, 19 Jan 2022 21:44:42 +0200 Subject: .......PS. [ZBXNEXT-7411] include, comment fixes according to pr comments --- tests/libs/zbxeval/zbx_eval_execute.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/libs/zbxeval/zbx_eval_execute.c b/tests/libs/zbxeval/zbx_eval_execute.c index 1f65b10f4f8..97d58b01c1d 100644 --- a/tests/libs/zbxeval/zbx_eval_execute.c +++ b/tests/libs/zbxeval/zbx_eval_execute.c @@ -78,7 +78,7 @@ void zbx_mock_test_entry(void **state) if (SUCCEED == expected_ret) { /* use custom epsilon for floating point values to account for */ - /* rounding differences with various sytems/libs */ + /* rounding differences with various systems/libs */ if (ZBX_VARIANT_DBL == value.type) { double expected_value; -- cgit v1.2.3