diff mbox

[ovs-dev,3/4] expr: Improve test so that it would have found the bugs I just fixed.

Message ID 1475811039-31662-3-git-send-email-blp@ovn.org
State Accepted
Headers show

Commit Message

Ben Pfaff Oct. 7, 2016, 3:30 a.m. UTC
The test didn't check for x == 0/0 or x != 0/0 cases, and thus they were
buggy.

Also, add "expression" as a keyword for tests that only had "expressions"
(plural).

Signed-off-by: Ben Pfaff <blp@ovn.org>
---
 tests/ovn.at     | 28 +++++++++++++++++-----------
 tests/test-ovn.c | 10 ++++------
 2 files changed, 21 insertions(+), 17 deletions(-)

Comments

Andy Zhou Oct. 10, 2016, 11:51 p.m. UTC | #1
On Thu, Oct 6, 2016 at 8:30 PM, Ben Pfaff <blp@ovn.org> wrote:

> The test didn't check for x == 0/0 or x != 0/0 cases, and thus they were
> buggy.
>
> Also, add "expression" as a keyword for tests that only had "expressions"
> (plural).
>
> Signed-off-by: Ben Pfaff <blp@ovn.org>
>
Acked-by: Andy Zhou <azhou@ovn.org>
diff mbox

Patch

diff --git a/tests/ovn.at b/tests/ovn.at
index 47153a4..be85004 100644
--- a/tests/ovn.at
+++ b/tests/ovn.at
@@ -397,19 +397,19 @@  AT_CLEANUP
 
 AT_SETUP([ovn -- 2-term expression conversion])
 AT_CHECK([ovstest test-ovn exhaustive --operation=convert 2], [0],
-  [Tested converting 570 expressions of 2 terminals with 2 numeric vars (each 3 bits) in terms of operators == != < <= > >= and 2 string vars.
+  [Tested converting 578 expressions of 2 terminals with 2 numeric vars (each 3 bits) in terms of operators == != < <= > >= and 2 string vars.
 ])
 AT_CLEANUP
 
 AT_SETUP([ovn -- 3-term expression conversion])
 AT_CHECK([ovstest test-ovn exhaustive --operation=convert --bits=2 3], [0],
-  [Tested converting 62418 expressions of 3 terminals with 2 numeric vars (each 2 bits) in terms of operators == != < <= > >= and 2 string vars.
+  [Tested converting 67410 expressions of 3 terminals with 2 numeric vars (each 2 bits) in terms of operators == != < <= > >= and 2 string vars.
 ])
 AT_CLEANUP
 
 AT_SETUP([ovn -- 3-term numeric expression simplification])
 AT_CHECK([ovstest test-ovn exhaustive --operation=simplify --nvars=2 --svars=0 3], [0],
-  [Tested simplifying 477138 expressions of 3 terminals with 2 numeric vars (each 3 bits) in terms of operators == != < <= > >=.
+  [Tested simplifying 490770 expressions of 3 terminals with 2 numeric vars (each 3 bits) in terms of operators == != < <= > >=.
 ])
 AT_CLEANUP
 
@@ -421,7 +421,7 @@  AT_CLEANUP
 
 AT_SETUP([ovn -- 3-term mixed expression simplification])
 AT_CHECK([ovstest test-ovn exhaustive --operation=simplify --nvars=1 --svars=1 3], [0],
-  [Tested simplifying 124410 expressions of 3 terminals with 1 numeric vars (each 3 bits) in terms of operators == != < <= > >= and 1 string vars.
+  [Tested simplifying 127890 expressions of 3 terminals with 1 numeric vars (each 3 bits) in terms of operators == != < <= > >= and 1 string vars.
 ])
 AT_CLEANUP
 
@@ -437,7 +437,7 @@  AT_CLEANUP
 
 AT_SETUP([ovn -- 4-term numeric expression normalization])
 AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=3 --svars=0 --bits=1 4], [0],
-  [Tested normalizing 1207162 expressions of 4 terminals with 3 numeric vars (each 1 bits) in terms of operators == != < <= > >=.
+  [Tested normalizing 1874026 expressions of 4 terminals with 3 numeric vars (each 1 bits) in terms of operators == != < <= > >=.
 ])
 AT_CLEANUP
 
@@ -449,13 +449,13 @@  AT_CLEANUP
 
 AT_SETUP([ovn -- 4-term mixed expression normalization])
 AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=1 --bits=1 --svars=2 4], [0],
-  [Tested normalizing 128282 expressions of 4 terminals with 1 numeric vars (each 1 bits) in terms of operators == != < <= > >= and 2 string vars.
+  [Tested normalizing 175978 expressions of 4 terminals with 1 numeric vars (each 1 bits) in terms of operators == != < <= > >= and 2 string vars.
 ])
 AT_CLEANUP
 
 AT_SETUP([ovn -- 5-term numeric expression normalization])
 AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=3 --svars=0 --bits=1 --relops='==' 5], [0],
-  [Tested normalizing 368550 expressions of 5 terminals with 3 numeric vars (each 1 bits) in terms of operators ==.
+  [Tested normalizing 1317600 expressions of 5 terminals with 3 numeric vars (each 1 bits) in terms of operators ==.
 ])
 AT_CLEANUP
 
@@ -467,35 +467,40 @@  AT_CLEANUP
 
 AT_SETUP([ovn -- 5-term mixed expression normalization])
 AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=1 --svars=1 --bits=1 --relops='==' 5], [0],
-  [Tested normalizing 116550 expressions of 5 terminals with 1 numeric vars (each 1 bits) in terms of operators == and 1 string vars.
+  [Tested normalizing 216000 expressions of 5 terminals with 1 numeric vars (each 1 bits) in terms of operators == and 1 string vars.
 ])
 AT_CLEANUP
 
 AT_SETUP([ovn -- 4-term numeric expressions to flows])
+AT_KEYWORDS([expression])
 AT_CHECK([ovstest test-ovn exhaustive --operation=flow --nvars=2 --svars=0 --bits=2 --relops='==' 4], [0],
-  [Tested converting to flows 128282 expressions of 4 terminals with 2 numeric vars (each 2 bits) in terms of operators ==.
+  [Tested converting to flows 175978 expressions of 4 terminals with 2 numeric vars (each 2 bits) in terms of operators ==.
 ])
 AT_CLEANUP
 
 AT_SETUP([ovn -- 4-term string expressions to flows])
+AT_KEYWORDS([expression])
 AT_CHECK([ovstest test-ovn exhaustive --operation=flow --nvars=0 --svars=4 4], [0],
   [Tested converting to flows 21978 expressions of 4 terminals with 4 string vars.
 ])
 AT_CLEANUP
 
 AT_SETUP([ovn -- 4-term mixed expressions to flows])
+AT_KEYWORDS([expression])
 AT_CHECK([ovstest test-ovn exhaustive --operation=flow --nvars=1 --bits=2 --svars=1 --relops='==' 4], [0],
-  [Tested converting to flows 37994 expressions of 4 terminals with 1 numeric vars (each 2 bits) in terms of operators == and 1 string vars.
+  [Tested converting to flows 48312 expressions of 4 terminals with 1 numeric vars (each 2 bits) in terms of operators == and 1 string vars.
 ])
 AT_CLEANUP
 
 AT_SETUP([ovn -- 3-term numeric expressions to flows])
+AT_KEYWORDS([expression])
 AT_CHECK([ovstest test-ovn exhaustive --operation=flow --nvars=3 --svars=0 --bits=3 --relops='==' 3], [0],
-  [Tested converting to flows 38394 expressions of 3 terminals with 3 numeric vars (each 3 bits) in terms of operators ==.
+  [Tested converting to flows 41328 expressions of 3 terminals with 3 numeric vars (each 3 bits) in terms of operators ==.
 ])
 AT_CLEANUP
 
 AT_SETUP([ovn -- converting expressions to flows -- string fields])
+AT_KEYWORDS([expression])
 expr_to_flow () {
     echo "$1" | ovstest test-ovn expr-to-flows | sort
 }
@@ -532,6 +537,7 @@  AT_CHECK([expr_to_flow 'inport == "eth0" && inport == "eth1"'], [0], [dnl
 AT_CLEANUP
 
 AT_SETUP([ovn -- converting expressions to flows -- address sets])
+AT_KEYWORDS([expression])
 expr_to_flow () {
     echo "$1" | ovstest test-ovn expr-to-flows | sort
 }
diff --git a/tests/test-ovn.c b/tests/test-ovn.c
index 67543b1..637ac7d 100644
--- a/tests/test-ovn.c
+++ b/tests/test-ovn.c
@@ -626,7 +626,7 @@  init_terminal(struct expr *expr, int phase,
         memset(&expr->cmp.value, 0, sizeof expr->cmp.value);
         memset(&expr->cmp.mask, 0, sizeof expr->cmp.mask);
         expr->cmp.value.integer = htonll(0);
-        expr->cmp.mask.integer = htonll(1);
+        expr->cmp.mask.integer = htonll(0);
         return;
     }
 
@@ -721,15 +721,13 @@  next_terminal(struct expr *expr,
                     return true;
                 }
             }
-            next = 0;
-        } else if (m == 0) {
-            /* Skip: empty mask is pathological. */
+            next = UINT_MAX;
         } else if (v & ~m) {
             /* Skip: 1-bits in value correspond to 0-bits in mask. */
-        } else if (turn_off_rightmost_1s(m)
+        } else if ((!m || turn_off_rightmost_1s(m))
                    && (expr->cmp.relop != EXPR_R_EQ &&
                        expr->cmp.relop != EXPR_R_NE)) {
-            /* Skip: can't have discontiguous mask for > >= < <=. */
+            /* Skip: can't have discontiguous or all-0 mask for > >= < <=. */
         } else {
             expr->cmp.value.integer = htonll(v);
             expr->cmp.mask.integer = htonll(m);