aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJoão Valverde <j@v6e.pt>2022-12-26 03:42:07 +0000
committerJoão Valverde <j@v6e.pt>2022-12-27 02:21:06 +0000
commitb19bed43d19207355520b360cb7e7ed41a7b68c2 (patch)
tree3a26a1a5b072eb78dd6e50da32bd688de4521918 /test
parent6399f724d9c8f7926ba7bbd16eceb503f11b8602 (diff)
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 <FT_INT8>) 2 FIELD(_ws.ftypes.int8 <FT_INT8>) 1 FVALUE(1 <FT_INT8>) Instructions: 00000 STACK_PUSH 1 <FT_INT8> 00001 READ_TREE _ws.ftypes.int8 <FT_INT8> -> reg#1 00002 IF_FALSE_GOTO 3 00003 STACK_PUSH reg#1 00004 CALL_FUNCTION max(reg#1, 1 <FT_INT8>) -> reg#0 00005 STACK_POP 2 00006 IF_FALSE_GOTO 8 00007 ANY_EQ reg#0 == 1 <FT_INT8> 00008 RETURN
Diffstat (limited to 'test')
-rw-r--r--test/suite_dfilter/group_function.py11
1 files changed, 7 insertions, 4 deletions
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):