From b19bed43d19207355520b360cb7e7ed41a7b68c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Valverde?= Date: Mon, 26 Dec 2022 03:42:07 +0000 Subject: dfilter: Allow constants as the first or only argument to min/max The strategy here is to delay resolving literals to values until we have looked at the entire argument list. Also we will try to commute the relation in a comparison if we do not have a type for the return value of the function, like any other constant. Before: Filter: max(1,_ws.ftypes.int8) == 1 dftest: Argument '1' is not valid for max() max(1,_ws.ftypes.int8) == 1 ^ After: Filter: max(1,_ws.ftypes.int8) == 1 Syntax tree: 0 TEST_ANY_EQ: 1 FUNCTION(max#2): 2 FVALUE(1 ) 2 FIELD(_ws.ftypes.int8 ) 1 FVALUE(1 ) Instructions: 00000 STACK_PUSH 1 00001 READ_TREE _ws.ftypes.int8 -> reg#1 00002 IF_FALSE_GOTO 3 00003 STACK_PUSH reg#1 00004 CALL_FUNCTION max(reg#1, 1 ) -> reg#0 00005 STACK_POP 2 00006 IF_FALSE_GOTO 8 00007 ANY_EQ reg#0 == 1 00008 RETURN --- test/suite_dfilter/group_function.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/suite_dfilter/group_function.py b/test/suite_dfilter/group_function.py index 9d80082b3f..517fa91f34 100644 --- a/test/suite_dfilter/group_function.py +++ b/test/suite_dfilter/group_function.py @@ -66,10 +66,13 @@ class case_dfunction_maxmin(unittest.TestCase): dfilter = 'max(udp.srcport, udp.dstport) < 5060' checkDFilterCount(dfilter, 1) - def test_max_4(self, checkDFilterFail): - error = 'Argument \'1\' is not valid for max()' - dfilter = 'max(1,_ws.ftypes.int8) == 1' - checkDFilterFail(dfilter, error) + def test_max_4(self, checkDFilterCount): + dfilter = 'max(5060, udp.dstport) == udp.srcport' + checkDFilterCount(dfilter, 2) + + def test_max_5(self, checkDFilterCount): + dfilter = 'max(5060, 5070) == udp.srcport' + checkDFilterCount(dfilter, 1) @fixtures.uses_fixtures class case_dfunction_abs(unittest.TestCase): -- cgit v1.2.3