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:
authorArtjoms Rimdjonoks <artjoms.rimdjonoks@zabbix.com>2021-05-07 13:47:40 +0300
committerArtjoms Rimdjonoks <artjoms.rimdjonoks@zabbix.com>2021-05-07 13:49:05 +0300
commit41e3dd118cc870619ab69d9ed0b97d568bde55f4 (patch)
tree2587d08132a68bac434cd6f125cb27cf973e0aa8 /tests
parent5e5c5444e2f0102bdf34cec94851e4781b719022 (diff)
parentf9b34c32c38493307a3b2ebc73a4130223be96b5 (diff)
........S. [DEV-1836] updated to the latest master
Diffstat (limited to 'tests')
-rw-r--r--tests/libs/zbxcommon/Makefile.am17
-rw-r--r--tests/libs/zbxcommon/zbx_get_report_nextcheck.c116
-rw-r--r--tests/libs/zbxcommon/zbx_get_report_nextcheck.yaml184
-rw-r--r--tests/libs/zbxdbcache/valuecache_test.c21
-rw-r--r--tests/libs/zbxdbcache/zbx_vc_add_values.c3
-rw-r--r--tests/libs/zbxdbcache/zbx_vc_get_value.c4
-rw-r--r--tests/libs/zbxdbcache/zbx_vc_get_values.c4
-rw-r--r--tests/libs/zbxserver/evaluate_function.c1
8 files changed, 331 insertions, 19 deletions
diff --git a/tests/libs/zbxcommon/Makefile.am b/tests/libs/zbxcommon/Makefile.am
index 2429c67b46a..fee717b1838 100644
--- a/tests/libs/zbxcommon/Makefile.am
+++ b/tests/libs/zbxcommon/Makefile.am
@@ -25,7 +25,8 @@ SERVER_tests = \
zbx_tm_add \
zbx_tm_sub \
zbx_tm_round_up \
- zbx_tm_round_down
+ zbx_tm_round_down \
+ zbx_get_report_nextcheck
endif
noinst_PROGRAMS = $(SERVER_tests)
@@ -466,4 +467,18 @@ zbx_tm_round_down_LDFLAGS = @SERVER_LDFLAGS@
zbx_tm_round_down_CFLAGS = $(COMMON_COMPILER_FLAGS)
+# zbx_get_report_nextcheck
+
+zbx_get_report_nextcheck_SOURCES = \
+ zbx_get_report_nextcheck.c \
+ $(COMMON_SRC_FILES)
+
+zbx_get_report_nextcheck_LDADD = \
+ $(COMMON_LIB_FILES)
+
+zbx_get_report_nextcheck_LDADD += @SERVER_LIBS@
+
+zbx_get_report_nextcheck_LDFLAGS = @SERVER_LDFLAGS@
+
+zbx_get_report_nextcheck_CFLAGS = $(COMMON_COMPILER_FLAGS)
endif
diff --git a/tests/libs/zbxcommon/zbx_get_report_nextcheck.c b/tests/libs/zbxcommon/zbx_get_report_nextcheck.c
new file mode 100644
index 00000000000..a87ba63b337
--- /dev/null
+++ b/tests/libs/zbxcommon/zbx_get_report_nextcheck.c
@@ -0,0 +1,116 @@
+/*
+** Zabbix
+** Copyright (C) 2001-2021 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 "zbxmocktest.h"
+#include "zbxmockdata.h"
+#include "zbxmockassert.h"
+#include "zbxmockutil.h"
+
+#include "common.h"
+#include "log.h"
+
+static unsigned char mock_get_cycle(const char *path)
+{
+ const char *value;
+
+ value = zbx_mock_get_parameter_string(path);
+
+ if (0 == strcmp(value, "ZBX_REPORT_CYCLE_DAILY"))
+ return ZBX_REPORT_CYCLE_DAILY;
+ if (0 == strcmp(value, "ZBX_REPORT_CYCLE_WEEKLY"))
+ return ZBX_REPORT_CYCLE_WEEKLY;
+ if (0 == strcmp(value, "ZBX_REPORT_CYCLE_MONTHLY"))
+ return ZBX_REPORT_CYCLE_MONTHLY;
+ if (0 == strcmp(value, "ZBX_REPORT_CYCLE_YEARLY"))
+ return ZBX_REPORT_CYCLE_YEARLY;
+
+ fail_msg("Unsupported report cycle: %s", value);
+ return 0;
+}
+
+static unsigned char mock_get_weekdays(const char *path)
+{
+ zbx_mock_handle_t hweekdays, hvalue;
+ zbx_mock_error_t err;
+ unsigned char weekdays = 0;
+
+ hweekdays = zbx_mock_get_parameter_handle(path);
+ while (ZBX_MOCK_END_OF_VECTOR != (err = (zbx_mock_vector_element(hweekdays, &hvalue))))
+ {
+ const char *value;
+
+ if (ZBX_MOCK_SUCCESS != err || ZBX_MOCK_SUCCESS != (err = zbx_mock_string(hvalue, &value)))
+ fail_msg("Cannot read weekday flag");
+
+ weekdays |= (1 << atoi(value));
+ }
+
+ return weekdays;
+}
+
+void zbx_mock_test_entry(void **state)
+{
+ unsigned char cycle, weekdays;
+ zbx_timespec_t ts;
+ time_t now, nextcheck;
+ int start_time, step = 1;
+ zbx_mock_handle_t htimes, htime;
+ zbx_mock_error_t err;
+ char buf[MAX_STRING_LEN];
+ const char *report_tz;
+
+ ZBX_UNUSED(state);
+
+ report_tz = zbx_mock_get_parameter_string("in.timezone");
+ if (0 != setenv("TZ", report_tz, 1))
+ fail_msg("Cannot set 'TZ' environment variable: %s", zbx_strerror(errno));
+
+ tzset();
+
+ cycle = mock_get_cycle("in.cycle");
+ weekdays = mock_get_weekdays("in.weekdays");
+
+ if (ZBX_MOCK_SUCCESS != zbx_strtime_to_timespec(zbx_mock_get_parameter_string("in.now"), &ts))
+ fail_msg("Invalid time format for 'now' parameter");
+ now = ts.sec;
+
+ if (ZBX_MOCK_SUCCESS != zbx_strtime_to_timespec(zbx_mock_get_parameter_string("in.start_time"), &ts))
+ fail_msg("Invalid time format for 'start_time' parameter");
+ start_time = ts.sec;
+
+ htimes = zbx_mock_get_parameter_handle("out.reports");
+ while (ZBX_MOCK_END_OF_VECTOR != (err = (zbx_mock_vector_element(htimes, &htime))))
+ {
+ const char *value;
+
+ if (ZBX_MOCK_SUCCESS != err || ZBX_MOCK_SUCCESS != (err = zbx_mock_string(htime, &value)))
+ fail_msg("[%d] cannot read nextcheck timestamp", step);
+
+ if (ZBX_MOCK_SUCCESS != (err = zbx_strtime_to_timespec(value, &ts)))
+ fail_msg("[%d] cannot parse nextcheck timestamp: %s", step, zbx_mock_error_string(err));
+
+ if (FAIL == (nextcheck = zbx_get_report_nextcheck(now, cycle, weekdays, start_time, report_tz)))
+ fail_msg("[%d] cannot calculate report nextcheck", step);
+
+ zbx_snprintf(buf, sizeof(buf), "[%d] invalid report nextchek value", step++);
+ zbx_mock_assert_time_eq(buf, ts.sec, nextcheck);
+
+ now = nextcheck;
+ }
+}
diff --git a/tests/libs/zbxcommon/zbx_get_report_nextcheck.yaml b/tests/libs/zbxcommon/zbx_get_report_nextcheck.yaml
new file mode 100644
index 00000000000..888b8fe9801
--- /dev/null
+++ b/tests/libs/zbxcommon/zbx_get_report_nextcheck.yaml
@@ -0,0 +1,184 @@
+---
+test case: Daily reports for day
+in:
+ timezone: :Europe/Riga
+ now: 2021-03-04 14:00:00 +02:00
+ cycle: ZBX_REPORT_CYCLE_DAILY
+ weekdays: []
+ start_time: 12:00:00
+out:
+ reports:
+ - 2021-03-05 12:00:00 +02:00
+ - 2021-03-06 12:00:00 +02:00
+ - 2021-03-07 12:00:00 +02:00
+ - 2021-03-08 12:00:00 +02:00
+ - 2021-03-09 12:00:00 +02:00
+ - 2021-03-10 12:00:00 +02:00
+ - 2021-03-11 12:00:00 +02:00
+ - 2021-03-12 12:00:00 +02:00
+---
+test case: Weekly reports every day
+in:
+ timezone: :Europe/Riga
+ now: 2021-03-04 14:00:00 +02:00
+ cycle: ZBX_REPORT_CYCLE_WEEKLY
+ weekdays: [0, 1, 2, 3, 4, 5, 6]
+ start_time: 12:00:00
+out:
+ reports:
+ - 2021-03-05 12:00:00 +02:00
+ - 2021-03-06 12:00:00 +02:00
+ - 2021-03-07 12:00:00 +02:00
+ - 2021-03-08 12:00:00 +02:00
+ - 2021-03-09 12:00:00 +02:00
+ - 2021-03-10 12:00:00 +02:00
+ - 2021-03-11 12:00:00 +02:00
+ - 2021-03-12 12:00:00 +02:00
+---
+test case: Weekly reports on workdays
+in:
+ timezone: :Europe/Riga
+ now: 2021-03-04 14:00:00 +02:00
+ cycle: ZBX_REPORT_CYCLE_WEEKLY
+ weekdays: [0, 1, 2, 3, 4]
+ start_time: 12:00:00
+out:
+ reports:
+ - 2021-03-05 12:00:00 +02:00
+ - 2021-03-08 12:00:00 +02:00
+ - 2021-03-09 12:00:00 +02:00
+ - 2021-03-10 12:00:00 +02:00
+ - 2021-03-11 12:00:00 +02:00
+ - 2021-03-12 12:00:00 +02:00
+ - 2021-03-15 12:00:00 +02:00
+---
+test case: Weekly reports on mondays
+in:
+ timezone: :Europe/Riga
+ now: 2021-03-04 10:00:00 +02:00
+ cycle: ZBX_REPORT_CYCLE_WEEKLY
+ weekdays: [0]
+ start_time: 12:00:00
+out:
+ reports:
+ - 2021-03-08 12:00:00 +02:00
+ - 2021-03-15 12:00:00 +02:00
+---
+test case: Monthly reports
+in:
+ timezone: :Europe/Riga
+ now: 2021-03-04 10:00:00 +02:00
+ cycle: ZBX_REPORT_CYCLE_MONTHLY
+ weekdays: []
+ start_time: 8:30:00
+out:
+ reports:
+ - 2021-04-01 8:30:00 +03:00
+ - 2021-05-01 8:30:00 +03:00
+ - 2021-06-01 8:30:00 +03:00
+---
+test case: Yearly reports
+in:
+ timezone: :Europe/Riga
+ now: 2010-03-04 10:00:00 +02:00
+ cycle: ZBX_REPORT_CYCLE_YEARLY
+ weekdays: []
+ start_time: 8:30:00
+out:
+ reports:
+ - 2011-01-01 8:30:00 +02:00
+ - 2012-01-01 8:30:00 +02:00
+ - 2013-01-01 8:30:00 +02:00
+---
+test case: Daily reports for day (same day)
+in:
+ timezone: :Europe/Riga
+ now: 2021-03-04 08:00:00 +02:00
+ cycle: ZBX_REPORT_CYCLE_DAILY
+ weekdays: []
+ start_time: 12:00:00
+out:
+ reports:
+ - 2021-03-04 12:00:00 +02:00
+ - 2021-03-05 12:00:00 +02:00
+ - 2021-03-06 12:00:00 +02:00
+ - 2021-03-07 12:00:00 +02:00
+ - 2021-03-08 12:00:00 +02:00
+ - 2021-03-09 12:00:00 +02:00
+ - 2021-03-10 12:00:00 +02:00
+ - 2021-03-11 12:00:00 +02:00
+ - 2021-03-12 12:00:00 +02:00
+---
+test case: Daily reports for day (next day)
+in:
+ timezone: :Europe/Riga
+ now: 2021-03-04 16:00:00 +02:00
+ cycle: ZBX_REPORT_CYCLE_DAILY
+ weekdays: []
+ start_time: 12:00:00
+out:
+ reports:
+ - 2021-03-05 12:00:00 +02:00
+ - 2021-03-06 12:00:00 +02:00
+ - 2021-03-07 12:00:00 +02:00
+ - 2021-03-08 12:00:00 +02:00
+ - 2021-03-09 12:00:00 +02:00
+ - 2021-03-10 12:00:00 +02:00
+ - 2021-03-11 12:00:00 +02:00
+ - 2021-03-12 12:00:00 +02:00
+---
+test case: Daily reports for day (2)
+in:
+ timezone: :Europe/Riga
+ now: 2021-03-12 10:00:00 +02:00
+ cycle: ZBX_REPORT_CYCLE_DAILY
+ weekdays: []
+ start_time: 11:00:00
+out:
+ reports:
+ - 2021-03-12 11:00:00 +02:00
+ - 2021-03-13 11:00:00 +02:00
+ - 2021-03-14 11:00:00 +02:00
+ - 2021-03-15 11:00:00 +02:00
+---
+test case: Daily reports for day (3)
+in:
+ timezone: :Europe/Riga
+ now: 2021-03-25 15:17:24 +02:00
+ cycle: ZBX_REPORT_CYCLE_DAILY
+ weekdays: []
+ start_time: 00:00:00
+out:
+ reports:
+ - 2021-03-26 00:00:00 +02:00
+ - 2021-03-27 00:00:00 +02:00
+ - 2021-03-28 00:00:00 +02:00
+---
+test case: Daily reports for day (4)
+in:
+ timezone: :Europe/Riga
+ now: 2021-03-12 10:00:00 +02:00
+ cycle: ZBX_REPORT_CYCLE_DAILY
+ weekdays: []
+ start_time: 10:00:00
+out:
+ reports:
+ - 2021-03-13 10:00:00 +02:00
+ - 2021-03-14 10:00:00 +02:00
+ - 2021-03-15 10:00:00 +02:00
+---
+test case: Daily reports for day (5)
+in:
+ timezone: :Etc/UTC
+ now: 2021-03-12 00:00:00 +0:00
+ cycle: ZBX_REPORT_CYCLE_DAILY
+ weekdays: []
+ start_time: 10:00:00
+out:
+ reports:
+ - 2021-03-12 10:00:00 +0:00
+ - 2021-03-13 10:00:00 +0:00
+ - 2021-03-14 10:00:00 +0:00
+ - 2021-03-15 10:00:00 +0:00
+...
+
diff --git a/tests/libs/zbxdbcache/valuecache_test.c b/tests/libs/zbxdbcache/valuecache_test.c
index 1570e039828..d85bdf04273 100644
--- a/tests/libs/zbxdbcache/valuecache_test.c
+++ b/tests/libs/zbxdbcache/valuecache_test.c
@@ -31,8 +31,6 @@ int zbx_vc_get_cached_values(zbx_uint64_t itemid, unsigned char value_type, zbx_
int i;
zbx_vc_chunk_t *chunk;
- vc_try_lock();
-
if (NULL == (item = zbx_hashset_search(&vc_cache->items, &itemid)))
return FAIL;
@@ -45,8 +43,6 @@ int zbx_vc_get_cached_values(zbx_uint64_t itemid, unsigned char value_type, zbx_
vc_history_record_vector_append(values, value_type, &chunk->slots[i]);
}
- vc_try_unlock();
-
return SUCCEED;
}
@@ -56,8 +52,6 @@ int zbx_vc_precache_values(zbx_uint64_t itemid, int value_type, int seconds, int
int ret;
zbx_vector_history_record_t values;
- vc_try_lock();
-
/* add item to cache if necessary */
if (NULL == (item = (zbx_vc_item_t *)zbx_hashset_search(&vc_cache->items, &itemid)))
{
@@ -66,18 +60,17 @@ int zbx_vc_precache_values(zbx_uint64_t itemid, int value_type, int seconds, int
}
/* perform request to cache values */
- vc_item_addref(item);
zbx_history_record_vector_create(&values);
+ RDLOCK_CACHE;
ret = vch_item_get_values(item, &values, seconds, count, ts);
+ UNLOCK_CACHE;
+ zbx_vc_flush_stats();
zbx_history_record_vector_destroy(&values, value_type);
- vc_item_release(item);
/* reset cache statistics */
vc_cache->hits = 0;
vc_cache->misses = 0;
- vc_try_unlock();
-
return ret;
}
@@ -87,8 +80,6 @@ int zbx_vc_get_item_state(zbx_uint64_t itemid, int *status, int *active_range, i
zbx_vc_item_t *item;
int ret = FAIL;
- vc_try_lock();
-
if (NULL != (item = (zbx_vc_item_t *)zbx_hashset_search(&vc_cache->items, &itemid)))
{
*status = item->status;
@@ -99,8 +90,6 @@ int zbx_vc_get_item_state(zbx_uint64_t itemid, int *status, int *active_range, i
ret = SUCCEED;
}
- vc_try_unlock();
-
return ret;
}
@@ -109,13 +98,9 @@ int zbx_vc_get_cache_state(int *mode, zbx_uint64_t *hits, zbx_uint64_t *misses)
if (NULL == vc_cache)
return FAIL;
- vc_try_lock();
-
*mode = vc_cache->mode;
*hits = vc_cache->hits;
*misses = vc_cache->misses;
- vc_try_unlock();
-
return SUCCEED;
}
diff --git a/tests/libs/zbxdbcache/zbx_vc_add_values.c b/tests/libs/zbxdbcache/zbx_vc_add_values.c
index 42d45860431..ac80bedbb50 100644
--- a/tests/libs/zbxdbcache/zbx_vc_add_values.c
+++ b/tests/libs/zbxdbcache/zbx_vc_add_values.c
@@ -53,6 +53,9 @@ void zbx_mock_test_entry(void **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);
diff --git a/tests/libs/zbxdbcache/zbx_vc_get_value.c b/tests/libs/zbxdbcache/zbx_vc_get_value.c
index f20fe48a077..aa7ea5bde3d 100644
--- a/tests/libs/zbxdbcache/zbx_vc_get_value.c
+++ b/tests/libs/zbxdbcache/zbx_vc_get_value.c
@@ -52,6 +52,9 @@ void zbx_mock_test_entry(void **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);
@@ -89,6 +92,7 @@ void zbx_mock_test_entry(void **state)
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);
diff --git a/tests/libs/zbxdbcache/zbx_vc_get_values.c b/tests/libs/zbxdbcache/zbx_vc_get_values.c
index 76816f9cf33..cbff161a96e 100644
--- a/tests/libs/zbxdbcache/zbx_vc_get_values.c
+++ b/tests/libs/zbxdbcache/zbx_vc_get_values.c
@@ -52,6 +52,9 @@ void zbx_mock_test_entry(void **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);
@@ -83,6 +86,7 @@ void zbx_mock_test_entry(void **state)
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);
/* validate results */
diff --git a/tests/libs/zbxserver/evaluate_function.c b/tests/libs/zbxserver/evaluate_function.c
index 0ae935bf135..b0d31bf859f 100644
--- a/tests/libs/zbxserver/evaluate_function.c
+++ b/tests/libs/zbxserver/evaluate_function.c
@@ -99,6 +99,7 @@ void zbx_mock_test_entry(void **state)
if (SUCCEED != (returned_ret = evaluate_function(&returned_value, &item, function, params, &ts, &error)))
printf("evaluate_function returned error: %s\n", error);
+ zbx_vc_flush_stats();
expected_ret = zbx_mock_str_to_return_code(zbx_mock_get_parameter_string("out.return"));
zbx_mock_assert_result_eq("return value", expected_ret, returned_ret);