Skip to content

Commit 9309458

Browse files
committed
TESTrun: Add detailed tests for AND/OR reductions.
Six tests make it easy to see another regression I have introduced in commit 1687065.
1 parent 2e15d1a commit 9309458

File tree

1 file changed

+158
-0
lines changed

1 file changed

+158
-0
lines changed

testprogs/TESTrun

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17240,6 +17240,146 @@ my @accept_blocks = (
1724017240
(004) ret #262144
1724117241
',
1724217242
}, # byte_and
17243+
17244+
# Assorted AND/OR reductions.
17245+
#
17246+
# On DLT_IPV4 in the current implementation:
17247+
# * "ip" produces a "true" block,
17248+
# * "ip6" produces a "false" block,
17249+
# * "not ip" produces a "not true" block, and
17250+
# * "not ip6" produces a "not false" block.
17251+
# The "true" and "not false" blocks comprise sequences of statements
17252+
# that are not identical, but have equivalent effect, the same holds
17253+
# for the "false" and "not true" pair. The aliases below will have to
17254+
# account for these differences until these have converged.
17255+
{
17256+
name => 'bool_reduction_returns_true',
17257+
DLT => 'IPV4',
17258+
aliases => [
17259+
# gen_and()
17260+
'ip and ip', # [1] True and true is true.
17261+
'not ip6 and ip', # [1] Not false and true is true.
17262+
# gen_or()
17263+
'ip or ip6', # [2] True or false is true.
17264+
'ip or not ip', # [2] True or not true is true.
17265+
'ip6 or ip', # [3] False or true is true.
17266+
'not ip or ip', # [3] Not true or true is true.
17267+
'ip or ip', # [4] True or true is true.
17268+
'not ip6 or ip', # [4] Not false or true is not false. (BUG!)
17269+
],
17270+
opt => '
17271+
(000) ret #262144
17272+
',
17273+
unopt => '
17274+
(000) ld #0x0
17275+
(001) jeq #0x0 jt 2 jf 3
17276+
(002) ret #262144
17277+
(003) ret #0
17278+
',
17279+
}, # bool_reduction_returns_true
17280+
{
17281+
name => 'bool_reduction_returns_not_false',
17282+
DLT => 'IPV4',
17283+
aliases => [
17284+
# gen_and()
17285+
'not ip6 and not ip6', # [1] Not false and not false is not false.
17286+
'ip and not ip6', # [1] True and not false is not false.
17287+
# gen_or()
17288+
'not ip6 or ip6', # [2] Not false or false is not false.
17289+
'not ip6 or not ip', # [2] Not false or not true is not false.
17290+
'ip6 or not ip6', # [3] False or not false is not false.
17291+
'not ip or not ip6', # [3] Not true or not false is not false.
17292+
'not ip6 or not ip6', # [4] Not false or not false is not false.
17293+
'ip or not ip6', # [4] True or not false is true. (BUG!)
17294+
],
17295+
opt => '
17296+
(000) ret #262144
17297+
',
17298+
unopt => '
17299+
(000) ld #0x1
17300+
(001) jeq #0x0 jt 2 jf 3
17301+
(002) ret #0
17302+
(003) ret #262144
17303+
',
17304+
}, # bool_reduction_returns_not_false
17305+
{
17306+
name => 'bool_reduction_returns_x',
17307+
DLT => 'IPV4',
17308+
aliases => [
17309+
# gen_and()
17310+
'ip and igmp', # [5] True and X is X.
17311+
'not ip6 and igmp', # [5] Not false and X is X.
17312+
'igmp and ip', # [6] X and true is X.
17313+
'igmp and not ip6', # [6] X and not false is X.
17314+
# gen_or()
17315+
'ip6 or igmp', # [7] False or X is X.
17316+
'not ip or igmp', # [7] Not true or X is X.
17317+
'igmp or ip6', # [8] X or false is X.
17318+
'igmp or not ip', # [8] X or not true is X.
17319+
'ip or igmp', # [9] True or X is true. (BUG!)
17320+
'not ip6 or igmp', # [9] Not false or X is not false. (BUG!)
17321+
'igmp or ip', # [10] X or true is true. (BUG!)
17322+
'igmp or not ip6', # [10] X or not false is not false. (BUG!)
17323+
],
17324+
optunopt => '
17325+
(000) ldb [9]
17326+
(001) jeq #0x2 jt 2 jf 3
17327+
(002) ret #262144
17328+
(003) ret #0
17329+
',
17330+
}, # bool_reduction_returns_x
17331+
{
17332+
name => 'bool_reduction_returns_false',
17333+
DLT => 'IPV4',
17334+
aliases => [
17335+
# gen_and()
17336+
'ip6 and ip6', # [11] False and false is false.
17337+
'ip6 and not ip', # [11] False and not true is false.
17338+
'ip6 and ip', # [12] False and true is false.
17339+
'ip6 and not ip6', # [12] False and not false is false.
17340+
'ip and ip6', # [13] True and false is false.
17341+
'not ip6 and ip6', # [13] Not false and false is false.
17342+
'ip6 and igmp', # [14] False and X is false.
17343+
'igmp and ip6', # [15] X and false is false.
17344+
# gen_or()
17345+
'ip6 or ip6', # [16] False or false is false.
17346+
'not ip or ip6', # [16] Not true or false is false.
17347+
],
17348+
# The "opt" leg of this block is a reject test.
17349+
opt => undef,
17350+
unopt => '
17351+
(000) ld #0x1
17352+
(001) jeq #0x0 jt 2 jf 3
17353+
(002) ret #262144
17354+
(003) ret #0
17355+
',
17356+
}, # bool_reduction_returns_false
17357+
{
17358+
name => 'bool_reduction_returns_not_true',
17359+
DLT => 'IPV4',
17360+
aliases => [
17361+
# gen_and()
17362+
'not ip and ip6', # [11] Not true and false is not true.
17363+
'not ip and not ip', # [11] Not true and not true is not true.
17364+
'not ip and ip', # [12] Not true and true is not true.
17365+
'not ip and not ip6', # [12] Not true and not false is not true.
17366+
'ip and not ip', # [13] True and not true is not true.
17367+
'not ip6 and not ip', # [13] Not false and not true is not true.
17368+
'not ip and igmp', # [14] Not true and X is not true.
17369+
'igmp and not ip', # [15] X and not true is not true.
17370+
# gen_or()
17371+
'not ip or not ip', # [16] Not true or not true is not true.
17372+
'ip6 or not ip', # [16] False or not true is not true.
17373+
],
17374+
# The "opt" leg of this block is a reject test.
17375+
opt => undef,
17376+
unopt => '
17377+
(000) ld #0x0
17378+
(001) jeq #0x0 jt 2 jf 3
17379+
(002) ret #0
17380+
(003) ret #262144
17381+
',
17382+
}, # bool_reduction_returns_not_true
1724317383
);
1724417384

1724517385
# In apply_blocks each test block always generates two tests: optimized and
@@ -19413,6 +19553,24 @@ my @reject_tests = (
1941319553
savefile => 'shb-option-too-long.pcapng',
1941419554
errstr => 'Failed opening: block total length in header and trailer don\'t match',
1941519555
},
19556+
19557+
{
19558+
name => 'bool_reduction_returns_false',
19559+
DLT => 'IPV4',
19560+
# Test only one alias of the accept block: so long as the
19561+
# accept block passes, all accept aliases produce the same
19562+
# unoptimized instruction block, therefore the optimized
19563+
# result will be the same.
19564+
expr => 'ip6 and igmp',
19565+
errstr => errstr_rejects_all,
19566+
},
19567+
{
19568+
name => 'bool_reduction_returns_not true',
19569+
DLT => 'IPV4',
19570+
# Idem.
19571+
expr => 'not ip and ip6',
19572+
errstr => errstr_rejects_all,
19573+
},
1941619574
);
1941719575

1941819576
# "proto" qualifiers without any lexer-level aliases (the entries correspond

0 commit comments

Comments
 (0)