diff options
author | Andris Zeila <andris.zeila@zabbix.com> | 2021-03-23 16:25:11 +0300 |
---|---|---|
committer | Andris Zeila <andris.zeila@zabbix.com> | 2021-03-23 16:25:11 +0300 |
commit | 846685c1cace29224c167e9a21672456e61d8e0c (patch) | |
tree | e8b5e08f5f8c5aa5fbd85b6108f95778605f2b8b /tests/libs/zbxeval | |
parent | 9b31d39d20d04a49855d44f85427bab094935d93 (diff) | |
parent | a2c088a337983a28ff2795fdab564a32a4f074b2 (diff) |
.......... [ZBXNEXT-6457] merged branch 'feature/ZBXNEXT-6451-5.3' into feature/ZBXNEXT-6457-5.3
Diffstat (limited to 'tests/libs/zbxeval')
-rw-r--r-- | tests/libs/zbxeval/mock_eval.c | 2 | ||||
-rw-r--r-- | tests/libs/zbxeval/zbx_eval_parse_expression.c | 4 | ||||
-rw-r--r-- | tests/libs/zbxeval/zbx_eval_parse_expression.yaml | 198 |
3 files changed, 189 insertions, 15 deletions
diff --git a/tests/libs/zbxeval/mock_eval.c b/tests/libs/zbxeval/mock_eval.c index 5e4b493aac8..15d2b0d98bd 100644 --- a/tests/libs/zbxeval/mock_eval.c +++ b/tests/libs/zbxeval/mock_eval.c @@ -60,6 +60,8 @@ zbx_uint64_t mock_eval_read_rules(const char *path) rules |= ZBX_EVAL_COMPOSE_FUNCTIONID; else if (0 == strcmp(flag, "ZBX_EVAL_PROCESS_ERROR")) rules |= ZBX_EVAL_PROCESS_ERROR; + else if (0 == strcmp(flag, "ZBX_EVAL_PARSE_COMPOUND_CONST")) + rules |= ZBX_EVAL_PARSE_COMPOUND_CONST; else fail_msg("Unsupported flag: %s", flag); diff --git a/tests/libs/zbxeval/zbx_eval_parse_expression.c b/tests/libs/zbxeval/zbx_eval_parse_expression.c index d6751f0020c..4669d5e81d3 100644 --- a/tests/libs/zbxeval/zbx_eval_parse_expression.c +++ b/tests/libs/zbxeval/zbx_eval_parse_expression.c @@ -58,7 +58,7 @@ static const char *mock_token_type2str(zbx_uint32_t type) ZBX_MOCK_TOKEN_CASE(GROUP_CLOSE) ZBX_MOCK_TOKEN_CASE(COMMA) ZBX_MOCK_TOKEN_CASE(ARG_QUERY) - ZBX_MOCK_TOKEN_CASE(ARG_TIME) + ZBX_MOCK_TOKEN_CASE(ARG_PERIOD) ZBX_MOCK_TOKEN_CASE(ARG_NULL) ZBX_MOCK_TOKEN_CASE(ARG_RAW) } @@ -99,7 +99,7 @@ static zbx_uint32_t mock_token_str2type(const char *str) ZBX_MOCK_TOKEN_IF(GROUP_CLOSE) ZBX_MOCK_TOKEN_IF(COMMA) ZBX_MOCK_TOKEN_IF(ARG_QUERY) - ZBX_MOCK_TOKEN_IF(ARG_TIME) + ZBX_MOCK_TOKEN_IF(ARG_PERIOD) ZBX_MOCK_TOKEN_IF(ARG_NULL) ZBX_MOCK_TOKEN_IF(ARG_RAW) diff --git a/tests/libs/zbxeval/zbx_eval_parse_expression.yaml b/tests/libs/zbxeval/zbx_eval_parse_expression.yaml index 91849fcb58f..0be187fded3 100644 --- a/tests/libs/zbxeval/zbx_eval_parse_expression.yaml +++ b/tests/libs/zbxeval/zbx_eval_parse_expression.yaml @@ -17,6 +17,24 @@ out: opt: 0 result: SUCCEED --- +test case: Succeed '1s' +in: + rules: [] + expression: '1s' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_NUM + token: '1s' + opt: 0 + result: SUCCEED +--- +test case: FAIL 's' +in: + rules: [] + expression: 's' +out: + result: FAIL +--- test case: Succeed '0.1' in: rules: [] @@ -226,6 +244,64 @@ in: expression: '{$MACRO:"context:\"context\"}' out: result: FAIL +--- +test case: Fail '{$MACRO}1' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO] + expression: '{$MACRO}1' +out: + result: FAIL +--- +test case: Succeed '{$MACRO}1' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PARSE_COMPOUND_CONST] + expression: '{$MACRO}1' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_NUM + token: '{$MACRO}1' + opt: 0 + result: SUCCEED +--- +test case: Succeed '1{$MACRO}' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PARSE_COMPOUND_CONST] + expression: '1{$MACRO}' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_NUM + token: '1{$MACRO}' + opt: 0 + result: SUCCEED +--- +test case: Succeed '{$USER}{$MACRO}' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PARSE_COMPOUND_CONST] + expression: '{$USER}{$MACRO}' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_NUM + token: '{$USER}{$MACRO}' + opt: 0 + result: SUCCEED +--- +test case: Succeed '{$MACRO}s' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PARSE_COMPOUND_CONST] + expression: '{$MACRO}s' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_NUM + token: '{$MACRO}s' + opt: 0 + result: SUCCEED +--- +test case: Succeed '{$MACRO}x' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PARSE_COMPOUND_CONST] + expression: '{$MACRO}x' +out: + result: FAIL --- # LLD macros test case: Succeed '{#LLD}' in: @@ -251,6 +327,7 @@ in: expression: '{#LLD' out: result: FAIL +--- test case: Succeed '{{#LLD}.function()}' in: rules: [ZBX_EVAL_PARSE_LLDMACRO] @@ -261,6 +338,57 @@ out: token: '{{#LLD}.function()}}' opt: 0 result: SUCCEED +--- +test case: Succeed '1{{#LLD}.function()}' +in: + rules: [ZBX_EVAL_PARSE_COMPOUND_CONST,ZBX_EVAL_PARSE_LLDMACRO] + expression: '1{{#LLD}.function()}' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_NUM + token: '1{{#LLD}.function()}}' + opt: 0 + result: SUCCEED +--- +test case: Succeed '.{{#LLD}.function()}' +in: + rules: [ZBX_EVAL_PARSE_COMPOUND_CONST,ZBX_EVAL_PARSE_LLDMACRO] + expression: '.{{#LLD}.function()}' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_NUM + token: '.{{#LLD}.function()}}' + opt: 0 + result: SUCCEED +--- +test case: Succeed '{{#LLD}.function()}.{{#LLD}.function()}' +in: + rules: [ZBX_EVAL_PARSE_COMPOUND_CONST,ZBX_EVAL_PARSE_LLDMACRO] + expression: '{{#LLD}.function()}.{{#LLD}.function()}' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_NUM + token: '{{#LLD}.function()}.{{#LLD}.function()}}' + opt: 0 + result: SUCCEED +--- +test case: Succeed '{{#LLD}.function()}e{{#LLD}.function()}' +in: + rules: [ZBX_EVAL_PARSE_COMPOUND_CONST,ZBX_EVAL_PARSE_LLDMACRO] + expression: '{{#LLD}.function()}e{{#LLD}.function()}' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_NUM + token: '{{#LLD}.function()}e{{#LLD}.function()}}' + opt: 0 + result: SUCCEED +--- +test case: Succeed 'e{{#LLD}.function()}' +in: + rules: [ZBX_EVAL_PARSE_COMPOUND_CONST,ZBX_EVAL_PARSE_LLDMACRO] + expression: 'e{{#LLD}.function()}' +out: + result: FAIL --- # parenthesis test case: Fail '()' in: @@ -1201,7 +1329,7 @@ in: out: stack: - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '/host/key', opt: 0} - - {type: ZBX_EVAL_TOKEN_ARG_TIME, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_PERIOD, token: '1', opt: 0} - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'min', opt: 2} result: SUCCEED --- @@ -1226,7 +1354,7 @@ in: out: stack: - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '/host/key', opt: 0} - - {type: ZBX_EVAL_TOKEN_ARG_TIME, token: '5m', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_PERIOD, token: '5m', opt: 0} - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'min', opt: 2} result: SUCCEED --- @@ -1237,22 +1365,66 @@ in: out: stack: - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '/host/key', opt: 0} - - {type: ZBX_EVAL_TOKEN_ARG_TIME, token: '5m:now-1h', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_PERIOD, token: '5m:now-1h', opt: 0} - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'min', opt: 2} result: SUCCEED ---- # time variables -test case: Succeed '1w + 2d + 3h + 4m + 5s' +--- +test case: Succeed 'min(/host/key,#10)' +in: + rules: [ZBX_EVAL_PARSE_ITEM_QUERY,ZBX_EVAL_PARSE_FUNCTION] + expression: 'min(/host/key,#10)' +out: + stack: + - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '/host/key', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_PERIOD, token: '#10', opt: 0} + - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'min', opt: 2} + result: SUCCEED +--- +test case: Succeed 'min(/host/key,{$MACRO})' +in: + rules: [ZBX_EVAL_PARSE_ITEM_QUERY,ZBX_EVAL_PARSE_FUNCTION] + expression: 'min(/host/key,{$MACRO})' +out: + stack: + - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '/host/key', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_PERIOD, token: '{$MACRO}', opt: 0} + - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'min', opt: 2} + result: SUCCEED +--- +test case: Succeed 'min(/host/key,#{$MACRO})' +in: + rules: [ZBX_EVAL_PARSE_ITEM_QUERY,ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_COMPOUND_CONST] + expression: 'min(/host/key,#{$MACRO})' +out: + stack: + - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '/host/key', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_PERIOD, token: '#{$MACRO}', opt: 0} + - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'min', opt: 2} + result: SUCCEED +--- +test case: Succeed 'min(/host/key,#{{#LLD}.func})' +in: + rules: [ZBX_EVAL_PARSE_ITEM_QUERY,ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_COMPOUND_CONST] + expression: 'min(/host/key,#{{#LLD}.func})' +out: + stack: + - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '/host/key', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_PERIOD, token: '#{{#LLD}.func}', opt: 0} + - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'min', opt: 2} + result: SUCCEED +--- # suffixed numbers +test case: Succeed '1w + 2G + 3h + 4K + 5s' in: rules: [ZBX_EVAL_PARSE_CONST_INDEX] - expression: '1w + 2d + 3h + 4m + 5s ' + expression: '1w + 2G + 3h + 4K + 5s ' out: stack: - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1w', opt: 0} - - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2d', opt: 1} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2G', opt: 1} - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '3h', opt: 2} - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} - - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '4m', opt: 3} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '4K', opt: 3} - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '5s', opt: 4} - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} @@ -1353,7 +1525,7 @@ in: out: stack: - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '/host/key', opt: 0} - - {type: ZBX_EVAL_TOKEN_ARG_TIME, token: '#1', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_PERIOD, token: '#1', opt: 0} - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'last', opt: 2} result: SUCCEED --- @@ -1364,7 +1536,7 @@ in: out: stack: - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '//trap[1]', opt: 0} - - {type: ZBX_EVAL_TOKEN_ARG_TIME, token: '#5', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_PERIOD, token: '#5', opt: 0} - {type: ZBX_EVAL_TOKEN_ARG_NULL, token: '', opt: 0} - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '0', opt: 0} - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'count', opt: 4} @@ -1377,12 +1549,12 @@ in: out: stack: - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '//trap[1]', opt: 0} - - {type: ZBX_EVAL_TOKEN_ARG_TIME, token: '#5', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_PERIOD, token: '#5', opt: 0} - {type: ZBX_EVAL_TOKEN_ARG_NULL, token: '', opt: 0} - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '0', opt: 0} - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'count', opt: 4} - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '/Trapper/trap[1]', opt: 0} - - {type: ZBX_EVAL_TOKEN_ARG_TIME, token: '5m', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_PERIOD, token: '5m', opt: 0} - {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"1h"', opt: 0} - {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"1"', opt: 0} - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'count', opt: 4} @@ -1446,7 +1618,7 @@ in: out: stack: - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '/host/key', opt: 0} - - {type: ZBX_EVAL_TOKEN_ARG_TIME, token: '#1:now-1h', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_PERIOD, token: '#1:now-1h', opt: 0} - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'last', opt: 2} result: SUCCEED ... |