ofproto: Fix potential leak during flow mods.
[sliver-openvswitch.git] / tests / ovsdb-mutation.at
index c1d2fed..fc898b5 100644 (file)
@@ -36,7 +36,7 @@ OVSDB_CHECK_POSITIVE([mutations on scalars],
 
 AT_SETUP([disallowed mutations on scalars])
 AT_KEYWORDS([ovsdb negative mutation])
-OVS_CHECK_LCOV([[test-ovsdb parse-mutations \
+AT_CHECK([[test-ovsdb parse-mutations \
     '{"columns":
         {"i": {"type": "integer"},
          "r": {"type": "real"},
@@ -99,6 +99,18 @@ test-ovsdb: syntax "["u","delete",["uuid","9179ca6d-6d65-400a-b455-3ad92783a099"
 ]])
 AT_CLEANUP
 
+AT_SETUP([disallowed mutations on immutable columns])
+AT_KEYWORDS([ovsdb negative mutation])
+AT_CHECK([[test-ovsdb parse-mutations \
+    '{"columns":
+        {"i": {"type": "integer", "mutable": false}}}' \
+    '[["i", "+=", 1]]'
+]],
+  [1], [],
+  [[test-ovsdb: syntax "["i","+=",1]": constraint violation: Cannot mutate immutable column i in table mytable.
+]])
+AT_CLEANUP
+
 OVSDB_CHECK_POSITIVE([mutations on sets],
   [[parse-mutations \
     '{"columns":
@@ -143,11 +155,11 @@ OVSDB_CHECK_POSITIVE([mutations on sets],
 [["r","/=",4]]
 [["r","insert",["set",[1,2]]]]
 [["r","delete",["set",[1,2,3]]]]
-[["b","insert",["set",[true]]]]
-[["b","delete",["set",[false]]]]
-[["s","insert",["set",["a"]]]]
+[["b","insert",true]]
+[["b","delete",false]]
+[["s","insert","a"]]
 [["s","delete",["set",["a","b"]]]]
-[["u","insert",["set",[["uuid","b10d28f7-af18-4a67-9e78-2a6394516c59"]]]]]
+[["u","insert",["uuid","b10d28f7-af18-4a67-9e78-2a6394516c59"]]]
 [["u","delete",["set",[["uuid","9179ca6d-6d65-400a-b455-3ad92783a099"],["uuid","b10d28f7-af18-4a67-9e78-2a6394516c59"]]]]]]],
   [mutation])
 
@@ -282,6 +294,45 @@ row 5: domain error: Division by zero.
 row 6: domain error: Division by zero.
 ], [mutation])
 
+OVSDB_CHECK_POSITIVE([executing mutations on integers with constraints],
+  [[execute-mutations \
+    '{"columns": {"i": {"type": {"key": {"type": "integer",
+                                         "minInteger": 0,
+                                         "maxInteger": 2}}}}}' \
+    '[[["i", "+=", 1]],
+      [["i", "-=", 2]],
+      [["i", "*=", 3]],
+      [["i", "/=", 4]],
+      [["i", "%=", 2]]]' \
+    '[{"i": 0},
+      {"i": 1},
+      {"i": 2}']]],
+  [mutation  0:
+row 0: {"i":1}
+row 1: {"i":2}
+row 2: constraint violation: 3 is not in the valid range 0 to 2 (inclusive)
+
+mutation  1:
+row 0: constraint violation: -2 is not in the valid range 0 to 2 (inclusive)
+row 1: constraint violation: -1 is not in the valid range 0 to 2 (inclusive)
+row 2: {"i":0}
+
+mutation  2:
+row 0: no change
+row 1: constraint violation: 3 is not in the valid range 0 to 2 (inclusive)
+row 2: constraint violation: 6 is not in the valid range 0 to 2 (inclusive)
+
+mutation  3:
+row 0: no change
+row 1: {"i":0}
+row 2: {"i":0}
+
+mutation  4:
+row 0: no change
+row 1: no change
+row 2: {"i":0}
+], [mutation])
+
 OVSDB_CHECK_POSITIVE([executing mutations on reals],
   [[execute-mutations \
     '{"columns": {"r": {"type": "real"}}}' \
@@ -356,9 +407,45 @@ row 1: domain error: Division by zero.
 row 2: domain error: Division by zero.
 ], [mutation])
 
+OVSDB_CHECK_POSITIVE([executing mutations on reals with constraints],
+  [[execute-mutations \
+    '{"columns": {"r": {"type": {"key": {"type": "real",
+                                         "minReal": -2.5,
+                                         "maxReal": 1.75}}}}}' \
+    '[[["r", "+=", 0.5]],
+      [["r", "-=", 1.5]],
+      [["r", "*=", 2.5]],
+      [["r", "/=", 4]]]' \
+    '[{"r": 0},
+      {"r": -2.5},
+      {"r": 1.25}']]],
+  [mutation  0:
+row 0: {"r":0.5}
+row 1: {"r":-2}
+row 2: {"r":1.75}
+
+mutation  1:
+row 0: {"r":-1.5}
+row 1: constraint violation: -4 is not in the valid range -2.5 to 1.75 (inclusive)
+row 2: {"r":-0.25}
+
+mutation  2:
+row 0: no change
+row 1: constraint violation: -6.25 is not in the valid range -2.5 to 1.75 (inclusive)
+row 2: constraint violation: 3.125 is not in the valid range -2.5 to 1.75 (inclusive)
+
+mutation  3:
+row 0: no change
+row 1: {"r":-0.625}
+row 2: {"r":0.3125}
+], [mutation])
+
 OVSDB_CHECK_POSITIVE([executing mutations on integer sets],
   [[execute-mutations \
-    '{"columns": {"i": {"type": {"key": "integer", "min": 0, "max": "unlimited"}}}}' \
+    '{"columns": {"i": {"type": {"key": {"type": "integer", 
+                                         "maxInteger": 5},
+                                 "min": 0, 
+                                 "max": "unlimited"}}}}' \
     '[[["i", "+=", 1]],
       [["i", "-=", 2]],
       [["i", "*=", 3]],
@@ -374,13 +461,13 @@ OVSDB_CHECK_POSITIVE([executing mutations on integer sets],
       {"i": ["set", [0, 1, 2]]}']]],
   [[mutation  0:
 row 0: no change
-row 1: {"i":["set",[1]]}
+row 1: {"i":1}
 row 2: {"i":["set",[1,2]]}
 row 3: {"i":["set",[1,2,3]]}
 
 mutation  1:
 row 0: no change
-row 1: {"i":["set",[-2]]}
+row 1: {"i":-2}
 row 2: {"i":["set",[-2,-1]]}
 row 3: {"i":["set",[-2,-1,0]]}
 
@@ -388,7 +475,7 @@ mutation  2:
 row 0: no change
 row 1: no change
 row 2: {"i":["set",[0,3]]}
-row 3: {"i":["set",[0,3,6]]}
+row 3: constraint violation: 6 is greater than maximum allowed value 5
 
 mutation  3:
 row 0: no change
@@ -403,7 +490,7 @@ row 2: no change
 row 3: constraint violation: Result of "%=" operation contains duplicates.
 
 mutation  5:
-row 0: {"i":["set",[1]]}
+row 0: {"i":1}
 row 1: {"i":["set",[0,1]]}
 row 2: no change
 row 3: no change
@@ -417,7 +504,7 @@ row 3: {"i":["set",[0,1,2,3]]}
 mutation  7:
 row 0: no change
 row 1: no change
-row 2: {"i":["set",[0]]}
+row 2: {"i":0}
 row 3: {"i":["set",[0,2]]}
 
 mutation  8:
@@ -427,60 +514,101 @@ row 2: no change
 row 3: {"i":["set",[0,1]]}
 ]], [mutation])
 
+OVSDB_CHECK_POSITIVE([executing mutations on integer sets with constraints],
+  [[execute-mutations \
+    '{"columns": {"i": {"type": {"key": "integer",
+                                 "min": 1,
+                                 "max": 2}}}}' \
+    '[[["i", "insert", ["set", [1]]]],
+      [["i", "insert", ["set", [2]]]],
+      [["i", "delete", ["set", [1]]]],
+      [["i", "delete", ["set", [2]]]],
+      [["i", "delete", ["set", [0, 1]]]]]' \
+    '[{"i": ["set", [0]]},
+      {"i": ["set", [2]]},
+      {"i": ["set", [0, 1]]}']]],
+  [[mutation  0:
+row 0: {"i":["set",[0,1]]}
+row 1: {"i":["set",[1,2]]}
+row 2: no change
+
+mutation  1:
+row 0: {"i":["set",[0,2]]}
+row 1: no change
+row 2: constraint violation: Attempted to store 3 elements in set of 1 to 2 integers.
+
+mutation  2:
+row 0: no change
+row 1: no change
+row 2: {"i":0}
+
+mutation  3:
+row 0: no change
+row 1: constraint violation: Attempted to store 0 elements in set of 1 to 2 integers.
+row 2: no change
+
+mutation  4:
+row 0: constraint violation: Attempted to store 0 elements in set of 1 to 2 integers.
+row 1: no change
+row 2: constraint violation: Attempted to store 0 elements in set of 1 to 2 integers.
+]], [mutation])
+
 OVSDB_CHECK_POSITIVE([executing mutations on real sets],
   [[execute-mutations \
-    '{"columns": {"r": {"type": {"key": "real", "min": 0, "max": "unlimited"}}}}' \
+    '{"columns": {"r": {"type": {"key": {"type": "real",
+                                         "maxReal": 6},
+                                 "min": 0, "max": "unlimited"}}}}' \
     '[[["r", "+=", 0.5]],
       [["r", "-=", 1.5]],
       [["r", "*=", 2.5]],
       [["r", "/=", 4]],
       [["r", "*=", 0]],
-      [["r", "insert", ["set", [1.5]]]],
-      [["r", "insert", ["set", [3]]]],
+      [["r", "insert", 1.5]],
+      [["r", "insert", 3]],
       [["r", "delete", ["set", [1.5, 3.5]]]],
       [["r", "delete", ["set", [0.5, 1.5, 2.5]]]]]' \
     '[{"r": ["set", []]},
-      {"r": ["set", [0.5]]},
+      {"r": 0.5},
       {"r": ["set", [0.5, 1.5]]},
       {"r": ["set", [0.5, 1.5, 2.5]]}']]],
   [[mutation  0:
 row 0: no change
-row 1: {"r":["set",[1]]}
+row 1: {"r":1}
 row 2: {"r":["set",[1,2]]}
 row 3: {"r":["set",[1,2,3]]}
 
 mutation  1:
 row 0: no change
-row 1: {"r":["set",[-1]]}
+row 1: {"r":-1}
 row 2: {"r":["set",[-1,0]]}
 row 3: {"r":["set",[-1,0,1]]}
 
 mutation  2:
 row 0: no change
-row 1: {"r":["set",[1.25]]}
+row 1: {"r":1.25}
 row 2: {"r":["set",[1.25,3.75]]}
-row 3: {"r":["set",[1.25,3.75,6.25]]}
+row 3: constraint violation: 6.25 is greater than maximum allowed value 6
 
 mutation  3:
 row 0: no change
-row 1: {"r":["set",[0.125]]}
+row 1: {"r":0.125}
 row 2: {"r":["set",[0.125,0.375]]}
 row 3: {"r":["set",[0.125,0.375,0.625]]}
 
 mutation  4:
 row 0: no change
-row 1: {"r":["set",[0]]}
+row 1: {"r":0}
 row 2: constraint violation: Result of "*=" operation contains duplicates.
 row 3: constraint violation: Result of "*=" operation contains duplicates.
 
 mutation  5:
-row 0: {"r":["set",[1.5]]}
+row 0: {"r":1.5}
 row 1: {"r":["set",[0.5,1.5]]}
 row 2: no change
 row 3: no change
 
 mutation  6:
-row 0: {"r":["set",[3]]}
+row 0: {"r":3}
 row 1: {"r":["set",[0.5,3]]}
 row 2: {"r":["set",[0.5,1.5,3]]}
 row 3: {"r":["set",[0.5,1.5,2.5,3]]}
@@ -488,7 +616,7 @@ row 3: {"r":["set",[0.5,1.5,2.5,3]]}
 mutation  7:
 row 0: no change
 row 1: no change
-row 2: {"r":["set",[0.5]]}
+row 2: {"r":0.5}
 row 3: {"r":["set",[0.5,2.5]]}
 
 mutation  8:
@@ -512,13 +640,13 @@ OVSDB_CHECK_POSITIVE([executing mutations on boolean sets],
       {"b": ["set", [true]]},
       {"b": ["set", [false, true]]}']]],
   [[mutation  0:
-row 0: {"b":["set",[false]]}
+row 0: {"b":false}
 row 1: no change
 row 2: {"b":["set",[false,true]]}
 row 3: no change
 
 mutation  1:
-row 0: {"b":["set",[true]]}
+row 0: {"b":true}
 row 1: {"b":["set",[false,true]]}
 row 2: no change
 row 3: no change
@@ -533,13 +661,13 @@ mutation  3:
 row 0: no change
 row 1: {"b":["set",[]]}
 row 2: no change
-row 3: {"b":["set",[true]]}
+row 3: {"b":true}
 
 mutation  4:
 row 0: no change
 row 1: no change
 row 2: {"b":["set",[]]}
-row 3: {"b":["set",[false]]}
+row 3: {"b":false}
 
 mutation  5:
 row 0: no change
@@ -562,13 +690,13 @@ OVSDB_CHECK_POSITIVE([executing mutations on string sets],
       {"s": ["set", ["a", "b"]]},
       {"s": ["set", ["a", "b", "c", "d"]]}']]],
   [[mutation  0:
-row 0: {"s":["set",["a"]]}
+row 0: {"s":"a"}
 row 1: no change
 row 2: no change
 row 3: no change
 
 mutation  1:
-row 0: {"s":["set",["b"]]}
+row 0: {"s":"b"}
 row 1: {"s":["set",["a","b"]]}
 row 2: no change
 row 3: no change
@@ -582,13 +710,13 @@ row 3: no change
 mutation  3:
 row 0: no change
 row 1: {"s":["set",[]]}
-row 2: {"s":["set",["b"]]}
+row 2: {"s":"b"}
 row 3: {"s":["set",["b","c","d"]]}
 
 mutation  4:
 row 0: no change
 row 1: no change
-row 2: {"s":["set",["a"]]}
+row 2: {"s":"a"}
 row 3: {"s":["set",["a","c","d"]]}
 
 mutation  5:
@@ -612,19 +740,19 @@ OVSDB_CHECK_POSITIVE([executing mutations on uuid sets],
       {"u": ["set", [["uuid", "a60fe7ff-317b-4568-9106-892b37445313"]]]},
       {"u": ["set", [["uuid", "2607d30e-e652-4927-9fec-8bbf1b60c7e9"]]]}']]],
   [[mutation  0:
-row 0: {"u":["set",[["uuid","ddd9e79d-7782-414c-8b22-1046c60b6ec2"]]]}
+row 0: {"u":["uuid","ddd9e79d-7782-414c-8b22-1046c60b6ec2"]}
 row 1: no change
 row 2: {"u":["set",[["uuid","a60fe7ff-317b-4568-9106-892b37445313"],["uuid","ddd9e79d-7782-414c-8b22-1046c60b6ec2"]]]}
 row 3: {"u":["set",[["uuid","2607d30e-e652-4927-9fec-8bbf1b60c7e9"],["uuid","ddd9e79d-7782-414c-8b22-1046c60b6ec2"]]]}
 
 mutation  1:
-row 0: {"u":["set",[["uuid","a60fe7ff-317b-4568-9106-892b37445313"]]]}
+row 0: {"u":["uuid","a60fe7ff-317b-4568-9106-892b37445313"]}
 row 1: {"u":["set",[["uuid","a60fe7ff-317b-4568-9106-892b37445313"],["uuid","ddd9e79d-7782-414c-8b22-1046c60b6ec2"]]]}
 row 2: no change
 row 3: {"u":["set",[["uuid","2607d30e-e652-4927-9fec-8bbf1b60c7e9"],["uuid","a60fe7ff-317b-4568-9106-892b37445313"]]]}
 
 mutation  2:
-row 0: {"u":["set",[["uuid","2607d30e-e652-4927-9fec-8bbf1b60c7e9"]]]}
+row 0: {"u":["uuid","2607d30e-e652-4927-9fec-8bbf1b60c7e9"]}
 row 1: {"u":["set",[["uuid","2607d30e-e652-4927-9fec-8bbf1b60c7e9"],["uuid","ddd9e79d-7782-414c-8b22-1046c60b6ec2"]]]}
 row 2: {"u":["set",[["uuid","2607d30e-e652-4927-9fec-8bbf1b60c7e9"],["uuid","a60fe7ff-317b-4568-9106-892b37445313"]]]}
 row 3: no change
@@ -648,7 +776,6 @@ row 2: no change
 row 3: {"u":["set",[]]}
 ]], [mutation])
 
-
 OVSDB_CHECK_POSITIVE([executing mutations on integer maps],
   [[execute-mutations \
     '{"columns": {"i": {"type": {"key": "integer", "value": "integer", "min": 0, "max": "unlimited"}}}}' \