diff options
author | Michael Veksler <Mihails.Vekslers@zabbix.com> | 2019-09-20 10:00:39 +0300 |
---|---|---|
committer | Michael Veksler <Mihails.Vekslers@zabbix.com> | 2019-09-20 10:27:04 +0300 |
commit | f67a0a6af8802c64394c8c2e0077ecd4910a19e9 (patch) | |
tree | b6d4d34ab561c4b75839d414b2cc9fd2c0288aa4 /tests/libs/zbxdbhigh | |
parent | 5a31f1f3f2eafcd006ae680982bd66980c6e82cf (diff) |
.......PS. [ZBX-13266] implementation of DBadd_condition_alloc() without BETWEEN logic
* commit '11810c78c9f674e651aea2c6d85ae71927200f9f':
.......PS. [ZBX-13266] added ChangeLog entry
.......PS. [ZBX-13266] introduced new target 'cmocka-ora-tests' of 'build-backend.xml' for cmocka tests with Oracle
.......PS. [ZBX-13266] implementation of 'IN' logic for all db except Oracle
.......PS. [ZBX-13266] debug output of 'in' query size
.......PS. [ZBX-13266] regexp improvement for regular sql case #902501
.......PS. [ZBX-13266] changes of ant script to support cmocka tests of only PROXY
.......PS. [ZBX-13266] cmocka changes of zbxjson/Makefile.am for support PROXY
.......PS. [ZBX-13266] revert changes for cmocka zbxjson/Makefile.am
.......PS. [ZBX-13266] proxy implementation of cmocka test for DBadd_condition_alloc()
.......PS. [ZBX-13266] cmocka test implementation for DBadd_condition_alloc()
.......PS. [ZBX-13266] implementation of DBadd_condition_alloc() without BETWEEN logic
(cherry picked from commit 8933485910490aad25550bffc20cab5537844a43)
(cherry picked from commit bb36e864fa1ccf08c17eb6491d176fae03480891)
Diffstat (limited to 'tests/libs/zbxdbhigh')
-rw-r--r-- | tests/libs/zbxdbhigh/DBadd_condition_alloc.c | 102 | ||||
-rw-r--r-- | tests/libs/zbxdbhigh/DBadd_condition_alloc.yaml | 155 | ||||
-rw-r--r-- | tests/libs/zbxdbhigh/Makefile.am | 125 |
3 files changed, 348 insertions, 34 deletions
diff --git a/tests/libs/zbxdbhigh/DBadd_condition_alloc.c b/tests/libs/zbxdbhigh/DBadd_condition_alloc.c new file mode 100644 index 00000000000..1bb89291e4b --- /dev/null +++ b/tests/libs/zbxdbhigh/DBadd_condition_alloc.c @@ -0,0 +1,102 @@ +/* +** Zabbix +** Copyright (C) 2001-2019 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 "zbxmockutil.h" + +#include "config.h" +#include "common.h" +#include "zbxalgo.h" +#include "zbxregexp.h" +#include "db.h" + +void zbx_mock_test_entry(void **state) +{ +#if defined(HAVE_SQLITE3) +# define RESULT "out.sqlite_regex" +#else +#if defined(HAVE_ORACLE) +# define RESULT "out.sqlora_regex" +#else +# define RESULT "out.sql_regex" +#endif +#endif + const char *sql_where, *sql_rgx, *field_name; + zbx_vector_uint64_t in_ids; + int i, count1, count2, shift, repeat; + uint64_t value_id, value; + char *sql; + size_t sql_alloc = 4 * ZBX_KIBIBYTE, sql_offset = 0; + + ZBX_UNUSED(state); + + sql_where = zbx_mock_get_parameter_string("in.sql_where"); + field_name = zbx_mock_get_parameter_string("in.field_name"); + value_id = zbx_mock_get_parameter_uint64("in.start_id"); + count1 = atoi(zbx_mock_get_parameter_string("in.count1")); + count2 = atoi(zbx_mock_get_parameter_string("in.count2")); + shift = atoi(zbx_mock_get_parameter_string("in.shift")); + repeat = atoi(zbx_mock_get_parameter_string("in.repeat")); + sql_rgx = zbx_mock_get_parameter_string(RESULT); + sql = (char *)zbx_malloc(NULL, sql_alloc); + zbx_vector_uint64_create(&in_ids); + value = value_id; + + do + { + for (i = 0; i < count1; i++) + zbx_vector_uint64_append(&in_ids, value++); + + value_id += shift; + value = value_id; + + for (i = 0; i < count2; i++) + zbx_vector_uint64_append(&in_ids, value++); + + if (0 != count2) + { + value_id += shift; + value = value_id; + } + } + while (repeat--); + + zbx_strcpy_alloc(&sql, &sql_alloc, &sql_offset, sql_where); + DBadd_condition_alloc(&sql, &sql_alloc, &sql_offset, field_name, in_ids.values, in_ids.values_num); + zbx_vector_uint64_destroy(&in_ids); + + if (NULL == zbx_regexp_match(sql, sql_rgx, NULL)) + { + unsigned int len; + + if (sql_offset > (len = 4 * ZBX_KIBIBYTE) * 2) + { + printf("Start of prepared sql (total=%zu): \"%.*s\"\n", sql_offset, len, sql); + printf("End of prepared sql: \"%s\"\n", &sql[sql_offset - len]); + } + else + printf("Prepared sql (total=%zu): \"%s\"\n", sql_offset, sql); + + zbx_free(sql); + fail_msg("Regular expression %s=\"%s\" does not much sql", RESULT, sql_rgx); + } + else + zbx_free(sql); +} diff --git a/tests/libs/zbxdbhigh/DBadd_condition_alloc.yaml b/tests/libs/zbxdbhigh/DBadd_condition_alloc.yaml new file mode 100644 index 00000000000..6159a6c46a2 --- /dev/null +++ b/tests/libs/zbxdbhigh/DBadd_condition_alloc.yaml @@ -0,0 +1,155 @@ +--- +test case: "successfully parsed #1" +in: + start_id: 100 + count1: 1 + count2: 0 + shift: 0 + repeat: 0 + field_name: itemid + sql_where: select * from items where +out: + sql_regex: select \* from items where itemid=100 + sqlora_regex: select \* from items where itemid=100 + sqlite_regex: select \* from items where itemid=100 +--- +test case: "successfully parsed #4" +in: + start_id: 100 + count1: 4 + count2: 0 + shift: 0 + repeat: 0 + field_name: itemid + sql_where: select * from items where +out: + sql_regex: select \* from items where itemid in \(100,(?:\d+,){2}103\) + sqlora_regex: select \* from items where itemid in \(100,(?:\d+,){2}103\) + sqlite_regex: select \* from items where itemid in \(100,(?:\d+,){2}103\) +--- +test case: "successfully parsed #10" +in: + start_id: 100 + count1: 10 + count2: 0 + shift: 0 + repeat: 0 + field_name: itemid + sql_where: select * from items where +out: + sql_regex: select \* from items where itemid in \(100,(?:\d+,){8}109\) + sqlora_regex: select \* from items where itemid between 100 and 109 + sqlite_regex: select \* from items where itemid in \(100,(?:\d+,){8}109\) +--- +test case: "successfully parsed #951" +in: + start_id: 1000 + count1: 951 + count2: 0 + shift: 0 + repeat: 0 + field_name: itemid + sql_where: select * from items where +out: + sql_regex: select \* from items where \(itemid in \(1000,(?:\d+,){948}1949\) or itemid in \(1950\) + sqlora_regex: select \* from items where itemid between 1000 and 1950 + sqlite_regex: select \* from items where \(itemid in \(1000,(?:\d+,){948}1949\) or itemid in \(1950\) +--- +test case: "successfully parsed #1000" +in: + start_id: 1000 + count1: 1000 + count2: 0 + shift: 0 + repeat: 0 + field_name: itemid + sql_where: select * from items where +out: + sql_regex: select \* from items where \(itemid in \(1000,(?:\d+,){948}1949\) or itemid in \(1950,(?:\d+,){48}1999\)\) + sqlora_regex: select \* from items where itemid between 1000 and 1999 + sqlite_regex: select \* from items where \(itemid in \(1000,(?:\d+,){948}1949\) or itemid in \(1950,(?:\d+,){48}1999\)\) +--- +test case: "successfully parsed #2000" +in: + start_id: 100 + count1: 2000 + count2: 0 + shift: 0 + repeat: 0 + field_name: itemid + sql_where: select * from items where +out: + sql_regex: select \* from items where \(itemid in \(100,(?:\d++,){948}1049\) or itemid in \(1050,(?:\d++,){948}1999\) or itemid in \(2000,(?:\d++,){98}2099\)\) + sqlora_regex: select \* from items where itemid between 100 and 2099 + sqlite_regex: select \* from items where \(itemid in \(100,(?:\d++,){948}1049\) or itemid in \(1050,(?:\d++,){948}1999\) or itemid in \(2000,(?:\d++,){98}2099\)\) +--- +test case: "successfully parsed #902501" +in: + start_id: 0 + count1: 902501 + count2: 0 + shift: 0 + repeat: 0 + field_name: itemid + sql_where: select * from items where +out: + sql_regex: select \* from items where \((?:itemid in \((?:\d++,)++\d++\) or ){950}itemid in \(902500\)\) + sqlora_regex: select \* from items where itemid between 0 and 902500 + sqlite_regex: select \* from items where \((?:\((?:itemid in \((?:\d++,)++\d++\) or ){949}itemid in \((?:\d++,)++\d++\)\) or ){1}\(itemid in \(902500\)\)\) +--- +test case: "successfully parsed #4x2" +in: + start_id: 10 + count1: 4 + count2: 0 + shift: 100 + repeat: 1 + field_name: itemid + sql_where: select * from items where +out: + sql_regex: select \* from items where itemid in \(10,(?:\d+,){6}113\) + sqlora_regex: select \* from items where itemid in \(10,(?:\d+,){6}113\) + sqlite_regex: select \* from items where itemid in \(10,(?:\d+,){6}113\) +--- +test case: "successfully parsed #5x2" +in: + start_id: 10 + count1: 5 + count2: 0 + shift: 100 + repeat: 1 + field_name: itemid + sql_where: select * from items where +out: + sql_regex: select \* from items where itemid in \(10,(?:\d+,){8}114\) + sqlora_regex: select \* from items where \(itemid between 10 and 14 or itemid between 110 and 114\) + sqlite_regex: select \* from items where itemid in \(10,(?:\d+,){8}114\) +--- +test case: "successfully parsed #5x4x1" +in: + start_id: 10 + count1: 5 + count2: 4 + shift: 100 + repeat: 0 + field_name: itemid + sql_where: select * from items where +out: + sql_regex: select \* from items where itemid in \(10,(?:\d+,){7}113\) + sqlora_regex: select \* from items where \(itemid between 10 and 14 or itemid in \(110,(?:\d+,){2}113\)\) + sqlite_regex: select \* from items where itemid in \(10,(?:\d+,){7}113\) +--- +test case: "successfully parsed #5x4x2" +in: + start_id: 10 + count1: 5 + count2: 4 + shift: 100 + repeat: 1 + field_name: itemid + sql_where: select * from items where +out: + sql_regex: select \* from items where itemid in \(10,(?:\d+,){16}313\) + sqlora_regex: select \* from items where \(itemid between 10 and 14 or itemid between 210 and 214 or itemid in \(110,(?:\d+,){6}313\)\) + sqlite_regex: select \* from items where itemid in \(10,(?:\d+,){16}313\) +... diff --git a/tests/libs/zbxdbhigh/Makefile.am b/tests/libs/zbxdbhigh/Makefile.am index c8b3efcbce1..ae8ae7fb442 100644 --- a/tests/libs/zbxdbhigh/Makefile.am +++ b/tests/libs/zbxdbhigh/Makefile.am @@ -1,13 +1,48 @@ if SERVER -noinst_PROGRAMS = DBselect_uint64 +noinst_PROGRAMS = \ + DBselect_uint64 \ + DBadd_condition_alloc +else +if PROXY +noinst_PROGRAMS = \ + DBadd_condition_alloc +endif +endif -DBselect_uint64_SOURCES = \ - DBselect_uint64.c \ +COMMON_SRC = \ ../../zbxmocktest.h -DBselect_uint64_LDADD = \ +COMMON_FLAGS = -I@top_srcdir@/tests + +COMMON_LIB = \ + $(top_srcdir)/src/libs/zbxserver/libzbxserver.a \ + $(top_srcdir)/src/libs/zbxhistory/libzbxhistory.a \ + $(top_srcdir)/src/libs/zbxmemory/libzbxmemory.a \ + $(top_srcdir)/src/libs/zbxexec/libzbxexec.a \ + $(top_srcdir)/src/libs/zbxjson/libzbxjson.a \ + $(top_srcdir)/src/libs/zbxhttp/libzbxhttp.a \ + $(top_srcdir)/src/libs/zbxmodules/libzbxmodules.a \ + $(top_srcdir)/src/libs/zbxdb/libzbxdb.a \ + $(top_srcdir)/src/libs/zbxcommon/libzbxcommon.a \ + $(top_srcdir)/src/libs/zbxcomms/libzbxcomms.a \ + $(top_srcdir)/src/libs/zbxcommon/libzbxcommon.a \ + $(top_srcdir)/src/libs/zbxcompress/libzbxcompress.a \ + $(top_srcdir)/src/libs/zbxnix/libzbxnix.a \ + $(top_srcdir)/src/libs/zbxalgo/libzbxalgo.a \ + $(top_srcdir)/src/libs/zbxsys/libzbxsys.a \ + $(top_srcdir)/src/libs/zbxregexp/libzbxregexp.a \ + $(top_srcdir)/src/libs/zbxcrypto/libzbxcrypto.a \ + $(top_srcdir)/src/libs/zbxlog/libzbxlog.a \ + $(top_srcdir)/src/libs/zbxconf/libzbxconf.a \ + $(top_srcdir)/tests/libzbxmocktest.a \ + $(top_srcdir)/tests/libzbxmockdata.a + + +if SERVER +SERVER_COMMON_LIB = \ $(top_srcdir)/src/libs/zbxdbhigh/libzbxdbhigh.a \ $(top_srcdir)/src/zabbix_server/libzbxserver.a \ + $(top_srcdir)/src/libs/zbxdbhigh/libzbxdbhigh.a \ $(top_srcdir)/src/zabbix_server/escalator/libzbxescalator.a \ $(top_srcdir)/src/zabbix_server/scripts/libzbxscripts.a \ $(top_srcdir)/src/zabbix_server/poller/libzbxpoller.a \ @@ -39,39 +74,61 @@ DBselect_uint64_LDADD = \ $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo.a \ $(top_srcdir)/src/libs/zbxsysinfo/simple/libsimplesysinfo.a \ $(top_srcdir)/src/libs/zbxdbcache/libzbxdbcache.a \ - $(top_srcdir)/src/libs/zbxhistory/libzbxhistory.a \ - $(top_srcdir)/src/libs/zbxmemory/libzbxmemory.a \ - $(top_srcdir)/src/libs/zbxregexp/libzbxregexp.a \ - $(top_srcdir)/src/libs/zbxself/libzbxself.a \ - $(top_srcdir)/src/libs/zbxnix/libzbxnix.a \ - $(top_srcdir)/src/libs/zbxalgo/libzbxalgo.a \ - $(top_srcdir)/src/libs/zbxsys/libzbxsys.a \ - $(top_srcdir)/src/libs/zbxconf/libzbxconf.a \ - $(top_srcdir)/src/libs/zbxmedia/libzbxmedia.a \ - $(top_srcdir)/src/libs/zbxcommon/libzbxcommon.a \ - $(top_srcdir)/src/libs/zbxcrypto/libzbxcrypto.a \ - $(top_srcdir)/src/libs/zbxcomms/libzbxcomms.a \ - $(top_srcdir)/src/libs/zbxcompress/libzbxcompress.a \ - $(top_srcdir)/src/libs/zbxcommon/libzbxcommon.a \ - $(top_srcdir)/src/libs/zbxcrypto/libzbxcrypto.a \ - $(top_srcdir)/src/libs/zbxcommshigh/libzbxcommshigh.a \ - $(top_srcdir)/src/libs/zbxjson/libzbxjson.a \ - $(top_srcdir)/src/libs/zbxhttp/libzbxhttp.a \ - $(top_srcdir)/src/libs/zbxipcservice/libzbxipcservice.a \ - $(top_srcdir)/src/libs/zbxexec/libzbxexec.a \ - $(top_srcdir)/src/libs/zbxicmpping/libzbxicmpping.a \ - $(top_srcdir)/src/libs/zbxdbupgrade/libzbxdbupgrade.a \ - $(top_srcdir)/src/libs/zbxdbhigh/libzbxdbhigh.a \ - $(top_srcdir)/src/libs/zbxdb/libzbxdb.a \ - $(top_srcdir)/src/libs/zbxmodules/libzbxmodules.a \ - $(top_srcdir)/src/libs/zbxtasks/libzbxtasks.a \ - $(top_srcdir)/src/libs/zbxlog/libzbxlog.a \ - $(top_srcdir)/tests/libzbxmocktest.a \ - $(top_srcdir)/tests/libzbxmockdata.a + $(COMMON_LIB) + +DBselect_uint64_SOURCES = \ + DBselect_uint64.c \ + $(COMMON_SRC) + +DBselect_uint64_LDADD = \ + $(SERVER_COMMON_LIB) DBselect_uint64_LDADD += @SERVER_LIBS@ DBselect_uint64_LDFLAGS = @SERVER_LDFLAGS@ -DBselect_uint64_CFLAGS = -I@top_srcdir@/tests +DBselect_uint64_CFLAGS = $(COMMON_FLAGS) + + +DBadd_condition_alloc_SOURCES = \ + DBadd_condition_alloc.c \ + $(COMMON_SRC) + +DBadd_condition_alloc_LDADD = \ + $(SERVER_COMMON_LIB) + +DBadd_condition_alloc_LDADD += @SERVER_LIBS@ + +DBadd_condition_alloc_LDFLAGS = @SERVER_LDFLAGS@ + +DBadd_condition_alloc_CFLAGS = $(COMMON_FLAGS) + +else +if PROXY + +PROXY_COMMON_LIB = \ + $(top_srcdir)/src/libs/zbxdbhigh/libzbxdbhigh.a \ + $(top_srcdir)/src/libs/zbxdbcache/libzbxdbcache.a \ + $(top_srcdir)/src/libs/zbxdbhigh/libzbxdbhigh.a \ + $(top_srcdir)/src/zabbix_proxy/libzbxproxy.a \ + $(top_srcdir)/src/libs/zbxsysinfo/libzbxproxysysinfo.a \ + $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo.a \ + $(top_srcdir)/src/libs/zbxsysinfo/simple/libsimplesysinfo.a \ + $(top_srcdir)/src/libs/zbxsysinfo/linux/libspechostnamesysinfo.a \ + $(COMMON_LIB) + +DBadd_condition_alloc_SOURCES = \ + DBadd_condition_alloc.c \ + $(COMMON_SRC) + +DBadd_condition_alloc_LDADD = \ + $(PROXY_COMMON_LIB) + +DBadd_condition_alloc_LDADD += @PROXY_LIBS@ + +DBadd_condition_alloc_LDFLAGS = @PROXY_LDFLAGS@ + +DBadd_condition_alloc_CFLAGS = $(COMMON_FLAGS) + +endif endif |