On 1/5/24 16:16, Simon Horman wrote:
On Fri, Jan 05, 2024 at 12:46:54PM +0100, Adrian Moreno wrote:
Parsing of info and matches was being tested as generic k-v parsing.
Also verify we don't find any unexpected field.

Signed-off-by: Adrian Moreno <[email protected]>
---
  python/ovs/tests/test_ofp.py | 73 +++++++++++++++++++++++++++---------
  1 file changed, 55 insertions(+), 18 deletions(-)

diff --git a/python/ovs/tests/test_ofp.py b/python/ovs/tests/test_ofp.py
index 27bcf0c47..5d2736ab4 100644
--- a/python/ovs/tests/test_ofp.py
+++ b/python/ovs/tests/test_ofp.py
@@ -6,6 +6,30 @@ from ovs.flow.kv import KeyValue, ParseError
  from ovs.flow.decoders import EthMask, IPMask, decode_mask
+def do_test_section(input_string, section, expected):
+    flow = OFPFlow(input_string)
+    kv_list = flow.section(section).data
+
+    for i in range(len(expected)):
+        assert expected[i].key == kv_list[i].key
+        assert expected[i].value == kv_list[i].value
+
+        # Assert positions relative to action string are OK.
+        pos = flow.section(section).pos
+        string = flow.section(section).string
+
+        kpos = kv_list[i].meta.kpos
+        kstr = kv_list[i].meta.kstring
+        vpos = kv_list[i].meta.vpos
+        vstr = kv_list[i].meta.vstring
+        assert string[kpos : kpos + len(kstr)] == kstr
+        if vpos != -1:
+            assert string[vpos : vpos + len(vstr)] == vstr
+
+        # Assert string meta is correct.
+        assert input_string[pos : pos + len(string)] == string

Hi Adrian,

I'm probably missing something obvious.
But I wonder if there a possibility that kv_list contains more elements
than expected, and if so, is that something we should check for?


That's a good point. We could also assert on the length of kv_list.
I'll send another version.

+
+
  @pytest.mark.parametrize(
      "input_string,expected",
      [

...


--
Adrián Moreno

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to