diff options
author | João Valverde <j@v6e.pt> | 2022-12-26 01:25:25 +0000 |
---|---|---|
committer | João Valverde <j@v6e.pt> | 2022-12-26 20:50:44 +0000 |
commit | 3ddb017a88797f520cda45961819c7084a0a5b29 (patch) | |
tree | 18f5d01760b2f5a9c00a67a56fa666352b753662 /test | |
parent | c37552c43ce36868761076dbdbfcb679c168e52f (diff) |
dfilter: Allow arithmetic expression to commute
Allow an arithmetic expression like 1 + some.field. If we
cannot assign a type to the LHS commute the terms and
try again.
Before:
Filter: _ws.ftypes.int32 + 1 == 10
Syntax tree:
0 TEST_ANY_EQ:
1 OP_ADD:
2 FIELD(_ws.ftypes.int32 <FT_INT32>)
2 FVALUE(1 <FT_INT32>)
1 FVALUE(10 <FT_INT32>)
Instructions:
00000 READ_TREE _ws.ftypes.int32 <FT_INT32> -> reg#0
00001 IF_FALSE_GOTO 4
00002 ADD reg#0 + 1 <FT_INT32> -> reg#1
00003 ANY_EQ reg#1 == 10 <FT_INT32>
00004 RETURN
Filter: 1 + _ws.ftypes.int32 == 10
dftest: Constant arithmetic expression on the LHS is invalid.
1 + _ws.ftypes.int32 == 10
^
After:
Filter: _ws.ftypes.int32 + 1 == 10
Syntax tree:
0 TEST_ANY_EQ:
1 OP_ADD:
2 FIELD(_ws.ftypes.int32 <FT_INT32>)
2 FVALUE(1 <FT_INT32>)
1 FVALUE(10 <FT_INT32>)
Instructions:
00000 READ_TREE _ws.ftypes.int32 <FT_INT32> -> reg#0
00001 IF_FALSE_GOTO 4
00002 ADD reg#0 + 1 <FT_INT32> -> reg#1
00003 ANY_EQ reg#1 == 10 <FT_INT32>
00004 RETURN
Filter: 1 + _ws.ftypes.int32 == 10
Syntax tree:
0 TEST_ANY_EQ:
1 OP_ADD:
2 FVALUE(1 <FT_INT32>)
2 FIELD(_ws.ftypes.int32 <FT_INT32>)
1 FVALUE(10 <FT_INT32>)
Instructions:
00000 READ_TREE _ws.ftypes.int32 <FT_INT32> -> reg#0
00001 IF_FALSE_GOTO 4
00002 ADD 1 <FT_INT32> + reg#0 -> reg#1
00003 ANY_EQ reg#1 == 10 <FT_INT32>
00004 RETURN
Diffstat (limited to 'test')
-rw-r--r-- | test/suite_dfilter/group_syntax.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/test/suite_dfilter/group_syntax.py b/test/suite_dfilter/group_syntax.py index c7746ec181..e669e25415 100644 --- a/test/suite_dfilter/group_syntax.py +++ b/test/suite_dfilter/group_syntax.py @@ -231,10 +231,9 @@ class case_unary_minus(unittest.TestCase): dfilter = "tcp.window_size_scalefactor == +tcp.dstport" checkDFilterCount(dfilter, 0) - def test_unary_3(self, checkDFilterFail): - error = 'Constant arithmetic expression on the LHS is invalid' + def test_unary_3(self, checkDFilterCount): dfilter = "-2 == tcp.dstport" - checkDFilterFail(dfilter, error) + checkDFilterCount(dfilter, 0) def test_unary_4(self, checkDFilterCount): dfilter = "tcp.window_size_scalefactor == -{tcp.dstport * 20}" @@ -256,9 +255,13 @@ class case_arithmetic(unittest.TestCase): dfilter = "udp.dstport == 66+1" checkDFilterCount(dfilter, 2) - def test_add_3(self, checkDFilterFail): - error = 'Constant arithmetic expression on the LHS is invalid' - dfilter = "2 + 3 == frame.number" + def test_add_4(self, checkDFilterCount): + dfilter = "1 + 2 == frame.number" + checkDFilterCount(dfilter, 1) + + def test_add_5(self, checkDFilterFail): + error = 'Constant expression is invalid' + dfilter = "1 + 2 == 2 + 1" checkDFilterFail(dfilter, error) def test_sub_1(self, checkDFilterCount): |