expr: Properly handle several cases involving string variables.
[cascardo/ovs.git] / tests / ovn.at
1 AT_BANNER([OVN])
2
3 AT_SETUP([ovn -- lexer])
4 dnl For lines without =>, input and expected output are identical.
5 dnl For lines with =>, input precedes => and expected output follows =>.
6 AT_DATA([test-cases.txt], [dnl
7 foo bar baz quuxquuxquux _abcd_ a.b.c.d a123_.456
8 "abc\u0020def" => "abc def"
9 " => error("Input ends inside quoted string.")dnl "
10
11 a/*b*/c => a c
12 a//b c => a
13 a/**/b => a b
14 a/*/b => a error("`/*' without matching `*/'.")
15 a/*/**/b => a b
16 a/b => a error("`/' is only valid as part of `//' or `/*'.") b
17
18 0 1 12345 18446744073709551615
19 18446744073709551616 => error("Decimal constants must be less than 2**64.")
20 9999999999999999999999 => error("Decimal constants must be less than 2**64.")
21 01 => error("Decimal constants must not have leading zeros.")
22
23 0/0
24 0/1
25 1/0 => error("Value contains unmasked 1-bits.")
26 1/1
27 128/384
28 1/3
29 1/ => error("Integer constant expected.")
30
31 1/0x123 => error("Value and mask have incompatible formats.")
32
33 0x1234
34 0x01234 => 0x1234
35 0x0 => 0
36 0x000 => 0
37 0xfedcba9876543210
38 0XFEDCBA9876543210 => 0xfedcba9876543210
39 0xfedcba9876543210fedcba9876543210
40 0x0000fedcba9876543210fedcba9876543210 => 0xfedcba9876543210fedcba9876543210
41 0x => error("Hex digits expected following 0x.")
42 0X => error("Hex digits expected following 0X.")
43 0x0/0x0 => 0/0
44 0x0/0x1 => 0/0x1
45 0x1/0x0 => error("Value contains unmasked 1-bits.")
46 0xffff/0x1ffff
47 0x. => error("Invalid syntax in hexadecimal constant.")
48
49 192.168.128.1 1.2.3.4 255.255.255.255 0.0.0.0
50 256.1.2.3 => error("Invalid numeric constant.")
51 192.168.0.0/16
52 192.168.0.0/255.255.0.0 => 192.168.0.0/16
53 192.168.0.0/255.255.255.0 => 192.168.0.0/24
54 192.168.0.0/255.255.0.255
55 192.168.0.0/255.0.0.0 => error("Value contains unmasked 1-bits.")
56 192.168.0.0/32
57 192.168.0.0/255.255.255.255 => 192.168.0.0/32
58
59 ::
60 ::1
61 ff00::1234 => ff00::1234
62 2001:db8:85a3::8a2e:370:7334
63 2001:db8:85a3:0:0:8a2e:370:7334 => 2001:db8:85a3::8a2e:370:7334
64 2001:0db8:85a3:0000:0000:8a2e:0370:7334 => 2001:db8:85a3::8a2e:370:7334
65 ::ffff:192.0.2.128
66 ::ffff:c000:0280 => ::ffff:192.0.2.128
67 ::1/::1
68 ::1/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff => ::1/128
69 ::1/128
70 ff00::/8
71 ff00::/ff00:: => ff00::/8
72
73 01:23:45:67:ab:cd
74 01:23:45:67:AB:CD => 01:23:45:67:ab:cd
75 fe:dc:ba:98:76:54
76 FE:DC:ba:98:76:54 => fe:dc:ba:98:76:54
77 01:00:00:00:00:00/01:00:00:00:00:00
78 ff:ff:ff:ff:ff:ff/ff:ff:ff:ff:ff:ff
79 fe:ff:ff:ff:ff:ff/ff:ff:ff:ff:ff:ff
80 ff:ff:ff:ff:ff:ff/fe:ff:ff:ff:ff:ff => error("Value contains unmasked 1-bits.")
81 fe:x => error("Invalid numeric constant.")
82 00:01:02:03:04:x => error("Invalid numeric constant.")
83
84 (){}[[]]==!=<<=>>=!&&||..,;= => ( ) { } [[ ]] == != < <= > >= ! && || .. , ; =
85 & => error("`&' is only valid as part of `&&'.")
86 | => error("`|' is only valid as part of `||'.")
87
88 ^ => error("Invalid character `^' in input.")
89 ])
90 AT_CAPTURE_FILE([input.txt])
91 sed 's/ =>.*//' test-cases.txt > input.txt
92 sed 's/.* => //' test-cases.txt > expout
93 AT_CHECK([ovstest test-ovn lex < input.txt], [0], [expout])
94 AT_CLEANUP
95
96 AT_SETUP([ovn -- expression parser])
97 dnl For lines without =>, input and expected output are identical.
98 dnl For lines with =>, input precedes => and expected output follows =>.
99 AT_DATA([test-cases.txt], [[
100 eth.type == 0x800
101 eth.type==0x800 => eth.type == 0x800
102 eth.type[0..15] == 0x800 => eth.type == 0x800
103
104 vlan.present
105 vlan.present == 1 => vlan.present
106 !(vlan.present == 0) => vlan.present
107 !(vlan.present != 1) => vlan.present
108 !vlan.present
109 vlan.present == 0 => !vlan.present
110 vlan.present != 1 => !vlan.present
111 !(vlan.present == 1) => !vlan.present
112 !(vlan.present != 0) => !vlan.present
113
114 eth.dst[0]
115 eth.dst[0] == 1 => eth.dst[0]
116 eth.dst[0] != 0 => eth.dst[0]
117 !(eth.dst[0] == 0) => eth.dst[0]
118 !(eth.dst[0] != 1) => eth.dst[0]
119
120 !eth.dst[0]
121 eth.dst[0] == 0 => !eth.dst[0]
122 eth.dst[0] != 1 => !eth.dst[0]
123 !(eth.dst[0] == 1) => !eth.dst[0]
124 !(eth.dst[0] != 0) => !eth.dst[0]
125
126 vlan.tci[12..15] == 0x3
127 vlan.tci == 0x3000/0xf000 => vlan.tci[12..15] == 0x3
128 vlan.tci[12..15] != 0x3
129 vlan.tci != 0x3000/0xf000 => vlan.tci[12..15] != 0x3
130
131 !vlan.pcp => vlan.pcp == 0
132 !(vlan.pcp) => vlan.pcp == 0
133 vlan.pcp == 0x4
134 vlan.pcp != 0x4
135 vlan.pcp > 0x4
136 vlan.pcp >= 0x4
137 vlan.pcp < 0x4
138 vlan.pcp <= 0x4
139 !(vlan.pcp != 0x4) => vlan.pcp == 0x4
140 !(vlan.pcp == 0x4) => vlan.pcp != 0x4
141 !(vlan.pcp <= 0x4) => vlan.pcp > 0x4
142 !(vlan.pcp < 0x4) => vlan.pcp >= 0x4
143 !(vlan.pcp >= 0x4) => vlan.pcp < 0x4
144 !(vlan.pcp > 0x4) => vlan.pcp <= 0x4
145 0x4 == vlan.pcp => vlan.pcp == 0x4
146 0x4 != vlan.pcp => vlan.pcp != 0x4
147 0x4 < vlan.pcp => vlan.pcp > 0x4
148 0x4 <= vlan.pcp => vlan.pcp >= 0x4
149 0x4 > vlan.pcp => vlan.pcp < 0x4
150 0x4 >= vlan.pcp => vlan.pcp <= 0x4
151 !(0x4 != vlan.pcp) => vlan.pcp == 0x4
152 !(0x4 == vlan.pcp) => vlan.pcp != 0x4
153 !(0x4 >= vlan.pcp) => vlan.pcp > 0x4
154 !(0x4 > vlan.pcp) => vlan.pcp >= 0x4
155 !(0x4 <= vlan.pcp) => vlan.pcp < 0x4
156 !(0x4 < vlan.pcp) => vlan.pcp <= 0x4
157
158 1 < vlan.pcp < 4 => vlan.pcp > 0x1 && vlan.pcp < 0x4
159 1 <= vlan.pcp <= 4 => vlan.pcp >= 0x1 && vlan.pcp <= 0x4
160 1 < vlan.pcp <= 4 => vlan.pcp > 0x1 && vlan.pcp <= 0x4
161 1 <= vlan.pcp < 4 => vlan.pcp >= 0x1 && vlan.pcp < 0x4
162 1 <= vlan.pcp <= 4 => vlan.pcp >= 0x1 && vlan.pcp <= 0x4
163 4 > vlan.pcp > 1 => vlan.pcp < 0x4 && vlan.pcp > 0x1
164 4 >= vlan.pcp > 1 => vlan.pcp <= 0x4 && vlan.pcp > 0x1
165 4 > vlan.pcp >= 1 => vlan.pcp < 0x4 && vlan.pcp >= 0x1
166 4 >= vlan.pcp >= 1 => vlan.pcp <= 0x4 && vlan.pcp >= 0x1
167 !(1 < vlan.pcp < 4) => vlan.pcp <= 0x1 || vlan.pcp >= 0x4
168 !(1 <= vlan.pcp <= 4) => vlan.pcp < 0x1 || vlan.pcp > 0x4
169 !(1 < vlan.pcp <= 4) => vlan.pcp <= 0x1 || vlan.pcp > 0x4
170 !(1 <= vlan.pcp < 4) => vlan.pcp < 0x1 || vlan.pcp >= 0x4
171 !(1 <= vlan.pcp <= 4) => vlan.pcp < 0x1 || vlan.pcp > 0x4
172 !(4 > vlan.pcp > 1) => vlan.pcp >= 0x4 || vlan.pcp <= 0x1
173 !(4 >= vlan.pcp > 1) => vlan.pcp > 0x4 || vlan.pcp <= 0x1
174 !(4 > vlan.pcp >= 1) => vlan.pcp >= 0x4 || vlan.pcp < 0x1
175 !(4 >= vlan.pcp >= 1) => vlan.pcp > 0x4 || vlan.pcp < 0x1
176
177 vlan.pcp == {1, 2, 3, 4} => vlan.pcp == 0x1 || vlan.pcp == 0x2 || vlan.pcp == 0x3 || vlan.pcp == 0x4
178 vlan.pcp == 1 || ((vlan.pcp == 2 || vlan.pcp == 3) || vlan.pcp == 4) => vlan.pcp == 0x1 || vlan.pcp == 0x2 || vlan.pcp == 0x3 || vlan.pcp == 0x4
179
180 vlan.pcp != {1, 2, 3, 4} => vlan.pcp != 0x1 && vlan.pcp != 0x2 && vlan.pcp != 0x3 && vlan.pcp != 0x4
181 vlan.pcp == 1 && ((vlan.pcp == 2 && vlan.pcp == 3) && vlan.pcp == 4) => vlan.pcp == 0x1 && vlan.pcp == 0x2 && vlan.pcp == 0x3 && vlan.pcp == 0x4
182
183 vlan.pcp == 1 && !((vlan.pcp == 2 && vlan.pcp == 3) && vlan.pcp == 4) => vlan.pcp == 0x1 && (vlan.pcp != 0x2 || vlan.pcp != 0x3 || vlan.pcp != 0x4)
184 vlan.pcp == 1 && (!(vlan.pcp == 2 && vlan.pcp == 3) && vlan.pcp == 4) => vlan.pcp == 0x1 && (vlan.pcp != 0x2 || vlan.pcp != 0x3) && vlan.pcp == 0x4
185 vlan.pcp == 1 && !(!(vlan.pcp == 2 && vlan.pcp == 3) && vlan.pcp == 4) => vlan.pcp == 0x1 && ((vlan.pcp == 0x2 && vlan.pcp == 0x3) || vlan.pcp != 0x4)
186
187 ip4.src == {10.0.0.0/8, 192.168.0.0/16, 172.16.20.0/24, 8.8.8.8} => ip4.src[24..31] == 0xa || ip4.src[16..31] == 0xc0a8 || ip4.src[8..31] == 0xac1014 || ip4.src == 0x8080808
188 ip6.src == ::1 => ip6.src == 0x1
189
190 ip4.src == 1.2.3.4 => ip4.src == 0x1020304
191 ip4.src == ::1.2.3.4/::ffff:ffff => ip4.src == 0x1020304
192 ip6.src == ::1 => ip6.src == 0x1
193
194 1
195 0
196 !1 => 0
197 !0 => 1
198
199 inport == "eth0"
200 !(inport != "eth0") => inport == "eth0"
201
202 ip4.src == "eth0" => Integer field ip4.src is not compatible with string constant.
203 inport == 1 => String field inport is not compatible with integer constant.
204
205 ip4.src > {1, 2, 3} => Only == and != operators may be used with value sets.
206 eth.type > 0x800 => Only == and != operators may be used with nominal field eth.type.
207 vlan.present > 0 => Only == and != operators may be used with Boolean field vlan.present.
208
209 inport != "eth0" => Nominal field inport may only be tested for equality (taking enclosing `!' operators into account).
210 !(inport == "eth0") => Nominal field inport may only be tested for equality (taking enclosing `!' operators into account).
211 eth.type != 0x800 => Nominal field eth.type may only be tested for equality (taking enclosing `!' operators into account).
212 !(eth.type == 0x800) => Nominal field eth.type may only be tested for equality (taking enclosing `!' operators into account).
213
214 123 == 123 => Syntax error at `123' expecting field name.
215
216 123 == xyzzy => Syntax error at `xyzzy' expecting field name.
217 xyzzy == 1 => Syntax error at `xyzzy' expecting field name.
218
219 inport[1] == 1 => Cannot select subfield of string field inport.
220
221 eth.type[] == 1 => Syntax error at `@:>@' expecting small integer.
222 eth.type[::1] == 1 => Syntax error at `::1' expecting small integer.
223 eth.type[18446744073709551615] == 1 => Syntax error at `18446744073709551615' expecting small integer.
224
225 eth.type[5!] => Syntax error at `!' expecting `@:>@'.
226
227 eth.type[5..1] => Invalid bit range 5 to 1.
228
229 eth.type[12..16] => Cannot select bits 12 to 16 of 16-bit field eth.type.
230
231 eth.type[10] == 1 => Cannot select subfield of nominal field eth.type.
232
233 eth.type => Explicit `!= 0' is required for inequality test of multibit field against 0.
234
235 !(!(vlan.pcp)) => Explicit `!= 0' is required for inequality test of multibit field against 0.
236
237 123 => Syntax error at end of input expecting relational operator.
238
239 123 x => Syntax error at `x' expecting relational operator.
240
241 {1, "eth0"} => Syntax error at `"eth0"' expecting integer.
242
243 eth.type == xyzzy => Syntax error at `xyzzy' expecting constant.
244
245 (1 x) => Syntax error at `x' expecting `)'.
246
247 !0x800 != eth.type => Missing parentheses around operand of !.
248
249 eth.type == 0x800 || eth.type == 0x86dd && ip.proto == 17 => && and || must be parenthesized when used together.
250
251 eth.dst == {} => Syntax error at `}' expecting constant.
252
253 eth.src > 00:00:00:00:11:11/00:00:00:00:ff:ff => Only == and != operators may be used with masked constants.  Consider using subfields instead (e.g. eth.src[0..15] > 0x1111 in place of eth.src > 00:00:00:00:11:11/00:00:00:00:ff:ff).
254
255 ip4.src == ::1 => 128-bit constant is not compatible with 32-bit field ip4.src.
256
257 1 == eth.type == 2 => Range expressions must have the form `x < field < y' or `x > field > y', with each `<' optionally replaced by `<=' or `>' by `>=').
258
259 eth.dst[40] x => Extra tokens at end of input.
260 ]])
261 sed 's/ =>.*//' test-cases.txt > input.txt
262 sed 's/.* => //' test-cases.txt > expout
263 AT_CHECK([ovstest test-ovn parse-expr < input.txt], [0], [expout])
264 AT_CLEANUP
265
266 AT_SETUP([ovn -- expression annotation])
267 dnl Input precedes =>, expected output follows =>.
268 AT_DATA([test-cases.txt], [[
269 ip4.src == 1.2.3.4 => ip4.src == 0x1020304 && eth.type == 0x800
270 ip4.src != 1.2.3.4 => ip4.src != 0x1020304 && eth.type == 0x800
271 ip.proto == 123 => ip.proto == 0x7b && (eth.type == 0x800 || eth.type == 0x86dd)
272 ip.proto == {123, 234} => (ip.proto == 0x7b && (eth.type == 0x800 || eth.type == 0x86dd)) || (ip.proto == 0xea && (eth.type == 0x800 || eth.type == 0x86dd))
273 ip4.src == 1.2.3.4 && ip4.dst == 5.6.7.8 => ip4.src == 0x1020304 && eth.type == 0x800 && ip4.dst == 0x5060708 && eth.type == 0x800
274
275 ip => eth.type == 0x800 || eth.type == 0x86dd
276 ip == 1 => eth.type == 0x800 || eth.type == 0x86dd
277 ip[0] == 1 => eth.type == 0x800 || eth.type == 0x86dd
278 ip > 0 => Only == and != operators may be used with nominal field ip.
279 !ip => Nominal predicate ip may only be tested positively, e.g. `ip' or `ip == 1' but not `!ip' or `ip == 0'.
280 ip == 0 => Nominal predicate ip may only be tested positively, e.g. `ip' or `ip == 1' but not `!ip' or `ip == 0'.
281
282 vlan.present => vlan.tci[12]
283 !vlan.present => !vlan.tci[12]
284
285 !vlan.pcp => vlan.tci[13..15] == 0 && vlan.tci[12]
286 vlan.pcp == 1 && vlan.vid == 2 => vlan.tci[13..15] == 0x1 && vlan.tci[12] && vlan.tci[0..11] == 0x2 && vlan.tci[12]
287 !reg0 && !reg1 && !reg2 && !reg3 => xreg0[32..63] == 0 && xreg0[0..31] == 0 && xreg1[32..63] == 0 && xreg1[0..31] == 0
288
289 ip.first_frag => ip.frag[0] && (eth.type == 0x800 || eth.type == 0x86dd) && (!ip.frag[1] || (eth.type != 0x800 && eth.type != 0x86dd))
290 !ip.first_frag => !ip.frag[0] || (eth.type != 0x800 && eth.type != 0x86dd) || (ip.frag[1] && (eth.type == 0x800 || eth.type == 0x86dd))
291 ip.later_frag => ip.frag[1] && (eth.type == 0x800 || eth.type == 0x86dd)
292
293 bad_prereq != 0 => Error parsing expression `xyzzy' encountered as prerequisite or predicate of initial expression: Syntax error at `xyzzy' expecting field name.
294 self_recurse != 0 => Error parsing expression `self_recurse != 0' encountered as prerequisite or predicate of initial expression: Recursive expansion of symbol `self_recurse'.
295 mutual_recurse_1 != 0 => Error parsing expression `mutual_recurse_2 != 0' encountered as prerequisite or predicate of initial expression: Error parsing expression `mutual_recurse_1 != 0' encountered as prerequisite or predicate of initial expression: Recursive expansion of symbol `mutual_recurse_1'.
296 mutual_recurse_2 != 0 => Error parsing expression `mutual_recurse_1 != 0' encountered as prerequisite or predicate of initial expression: Error parsing expression `mutual_recurse_2 != 0' encountered as prerequisite or predicate of initial expression: Recursive expansion of symbol `mutual_recurse_2'.
297 ]])
298 sed 's/ =>.*//' test-cases.txt > input.txt
299 sed 's/.* => //' test-cases.txt > expout
300 AT_CHECK([ovstest test-ovn annotate-expr < input.txt], [0], [expout])
301 AT_CLEANUP
302
303 AT_SETUP([ovn -- 1-term expression conversion])
304 AT_CHECK([ovstest test-ovn exhaustive --operation=convert 1], [0],
305   [Tested converting all 1-terminal expressions with 2 numeric vars (each 3 bits) in terms of operators == != < <= > >= and 2 string vars.
306 ])
307 AT_CLEANUP
308
309 AT_SETUP([ovn -- 2-term expression conversion])
310 AT_CHECK([ovstest test-ovn exhaustive --operation=convert 2], [0],
311   [Tested converting 570 expressions of 2 terminals with 2 numeric vars (each 3 bits) in terms of operators == != < <= > >= and 2 string vars.
312 ])
313 AT_CLEANUP
314
315 AT_SETUP([ovn -- 3-term expression conversion])
316 AT_CHECK([ovstest test-ovn exhaustive --operation=convert --bits=2 3], [0],
317   [Tested converting 62418 expressions of 3 terminals with 2 numeric vars (each 2 bits) in terms of operators == != < <= > >= and 2 string vars.
318 ])
319 AT_CLEANUP
320
321 AT_SETUP([ovn -- 3-term numeric expression simplification])
322 AT_CHECK([ovstest test-ovn exhaustive --operation=simplify --nvars=2 --svars=0 3], [0],
323   [Tested simplifying 477138 expressions of 3 terminals with 2 numeric vars (each 3 bits) in terms of operators == != < <= > >=.
324 ])
325 AT_CLEANUP
326
327 AT_SETUP([ovn -- 4-term string expression simplification])
328 AT_CHECK([ovstest test-ovn exhaustive --operation=simplify --nvars=0 --svars=4 4], [0],
329   [Tested simplifying 21978 expressions of 4 terminals with 4 string vars.
330 ])
331 AT_CLEANUP
332
333 AT_SETUP([ovn -- 3-term mixed expression simplification])
334 AT_CHECK([ovstest test-ovn exhaustive --operation=simplify --nvars=1 --svars=1 3], [0],
335   [Tested simplifying 124410 expressions of 3 terminals with 1 numeric vars (each 3 bits) in terms of operators == != < <= > >= and 1 string vars.
336 ])
337 AT_CLEANUP
338
339 AT_SETUP([ovn -- 4-term numeric expression normalization])
340 AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=3 --svars=0 --bits=1 4], [0],
341   [Tested normalizing 1207162 expressions of 4 terminals with 3 numeric vars (each 1 bits) in terms of operators == != < <= > >=.
342 ])
343 AT_CLEANUP
344
345 AT_SETUP([ovn -- 4-term string expression normalization])
346 AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=0 --svars=3 --bits=1 4], [0],
347   [Tested normalizing 11242 expressions of 4 terminals with 3 string vars.
348 ])
349 AT_CLEANUP
350
351 AT_SETUP([ovn -- 4-term mixed expression normalization])
352 AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=1 --bits=1 --svars=2 4], [0],
353   [Tested normalizing 128282 expressions of 4 terminals with 1 numeric vars (each 1 bits) in terms of operators == != < <= > >= and 2 string vars.
354 ])
355 AT_CLEANUP
356
357 AT_SETUP([ovn -- 5-term numeric expression normalization])
358 AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=3 --svars=0 --bits=1 --relops='==' 5], [0],
359   [Tested normalizing 368550 expressions of 5 terminals with 3 numeric vars (each 1 bits) in terms of operators ==.
360 ])
361 AT_CLEANUP
362
363 AT_SETUP([ovn -- 5-term string expression normalization])
364 AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=0 --svars=3 --bits=1 --relops='==' 5], [0],
365   [Tested normalizing 368550 expressions of 5 terminals with 3 string vars.
366 ])
367 AT_CLEANUP
368
369 AT_SETUP([ovn -- 5-term mixed expression normalization])
370 AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=1 --svars=1 --bits=1 --relops='==' 5], [0],
371   [Tested normalizing 116550 expressions of 5 terminals with 1 numeric vars (each 1 bits) in terms of operators == and 1 string vars.
372 ])
373 AT_CLEANUP
374
375 AT_SETUP([ovn -- 4-term numeric expressions to flows])
376 AT_CHECK([ovstest test-ovn exhaustive --operation=flow --nvars=2 --svars=0 --bits=2 --relops='==' 4], [0],
377   [Tested converting to flows 128282 expressions of 4 terminals with 2 numeric vars (each 2 bits) in terms of operators ==.
378 ])
379 AT_CLEANUP
380
381 AT_SETUP([ovn -- 4-term string expressions to flows])
382 AT_CHECK([ovstest test-ovn exhaustive --operation=flow --nvars=0 --svars=4 4], [0],
383   [Tested converting to flows 21978 expressions of 4 terminals with 4 string vars.
384 ])
385 AT_CLEANUP
386
387 AT_SETUP([ovn -- 4-term mixed expressions to flows])
388 AT_CHECK([ovstest test-ovn exhaustive --operation=flow --nvars=1 --bits=2 --svars=1 --relops='==' 4], [0],
389   [Tested converting to flows 37994 expressions of 4 terminals with 1 numeric vars (each 2 bits) in terms of operators == and 1 string vars.
390 ])
391 AT_CLEANUP
392
393 AT_SETUP([ovn -- 3-term numeric expressions to flows])
394 AT_CHECK([ovstest test-ovn exhaustive --operation=flow --nvars=3 --svars=0 --bits=3 --relops='==' 3], [0],
395   [Tested converting to flows 38394 expressions of 3 terminals with 3 numeric vars (each 3 bits) in terms of operators ==.
396 ])
397 AT_CLEANUP
398
399 AT_SETUP([ovn -- converting expressions to flows -- string fields])
400 expr_to_flow () {
401     echo "$1" | ovstest test-ovn expr-to-flows | sort
402 }
403 AT_CHECK([expr_to_flow 'inport == "eth0"'], [0], [reg6=0x5
404 ])
405 AT_CHECK([expr_to_flow 'inport == "eth1"'], [0], [reg6=0x6
406 ])
407 AT_CHECK([expr_to_flow 'inport == "eth2"'], [0], [(no flows)
408 ])
409 AT_CHECK([expr_to_flow 'inport == "eth0" && ip'], [0], [dnl
410 ip,reg6=0x5
411 ipv6,reg6=0x5
412 ])
413 AT_CHECK([expr_to_flow 'inport == "eth1" && ip'], [0], [dnl
414 ip,reg6=0x6
415 ipv6,reg6=0x6
416 ])
417 AT_CHECK([expr_to_flow 'inport == "eth2" && ip'], [0], [(no flows)
418 ])
419 AT_CHECK([expr_to_flow 'inport == {"eth0", "eth1", "eth2", "LOCAL"}'], [0],
420 [reg6=0x5
421 reg6=0x6
422 reg6=0xfffe
423 ])
424 AT_CHECK([expr_to_flow 'inport == {"eth0", "eth1", "eth2"} && ip'], [0], [dnl
425 ip,reg6=0x5
426 ip,reg6=0x6
427 ipv6,reg6=0x5
428 ipv6,reg6=0x6
429 ])
430 AT_CHECK([expr_to_flow 'inport == "eth0" && inport == "eth1"'], [0], [dnl
431 (no flows)
432 ])
433 AT_CLEANUP
434
435 AT_SETUP([ovn -- action parsing])
436 dnl Text before => is input, text after => is expected output.
437 AT_DATA([test-cases.txt], [[
438 # Positive tests.
439 drop; => actions=drop, prereqs=1
440 next; => actions=resubmit(,11), prereqs=1
441 output; => actions=resubmit(,64), prereqs=1
442 outport="eth0"; next; outport="LOCAL"; next; => actions=set_field:0x5->reg7,resubmit(,11),set_field:0xfffe->reg7,resubmit(,11), prereqs=1
443 tcp.dst=80; => actions=set_field:80->tcp_dst, prereqs=ip.proto == 0x6 && (eth.type == 0x800 || eth.type == 0x86dd)
444 eth.dst[40] = 1; => actions=set_field:01:00:00:00:00:00/01:00:00:00:00:00->eth_dst, prereqs=1
445 vlan.pcp = 2; => actions=set_field:0x4000/0xe000->vlan_tci, prereqs=vlan.tci[12]
446 vlan.tci[13..15] = 2; => actions=set_field:0x4000/0xe000->vlan_tci, prereqs=1
447
448 ## Negative tests.
449
450 ; => Syntax error at `;'.
451 xyzzy; => Syntax error at `xyzzy' expecting action.
452 next; 123; => Syntax error at `123'.
453 next; xyzzy; => Syntax error at `xyzzy' expecting action.
454
455 # "drop;" must be on its own:
456 drop; next; => Syntax error at `next' expecting end of input.
457 next; drop; => Syntax error at `drop' expecting action.
458
459 # Missing ";":
460 next => Syntax error at end of input expecting ';'.
461
462 inport[1] = 1; => Cannot select subfield of string field inport.
463 ip.proto[1] = 1; => Cannot select subfield of nominal field ip.proto.
464 eth.dst[40] == 1; => Syntax error at `==' expecting `='.
465 ip = 1; => Can't assign to predicate symbol ip.
466 ip.proto = 6; => Field ip.proto is not modifiable.
467 inport = {"a", "b"}; => Assignments require a single value.
468 inport = {}; => Syntax error at `}' expecting constant.
469 bad_prereq = 123; => Error parsing expression `xyzzy' encountered as prerequisite or predicate of initial expression: Syntax error at `xyzzy' expecting field name.
470 self_recurse = 123; => Error parsing expression `self_recurse != 0' encountered as prerequisite or predicate of initial expression: Error parsing expression `self_recurse != 0' encountered as prerequisite or predicate of initial expression: Recursive expansion of symbol `self_recurse'.
471 vlan.present = 0; => Can't assign to predicate symbol vlan.present.
472 ]])
473 sed 's/ =>.*//' test-cases.txt > input.txt
474 sed 's/.* => //' test-cases.txt > expout
475 AT_CHECK([ovstest test-ovn parse-actions < input.txt], [0], [expout])
476 AT_CLEANUP