]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
tests: don't depend on set element order
authorFlorian Westphal <fw@strlen.de>
Thu, 17 Sep 2015 21:23:25 +0000 (23:23 +0200)
committerFlorian Westphal <fw@strlen.de>
Thu, 17 Sep 2015 22:00:24 +0000 (00:00 +0200)
Pablo reported test failures because the order of returned set entries
is not deterministic.

This sorts set elements before comparision.
Patrick suggested to move ordering into libnftnl (since we could f.e.
also get duplicate entries due to how netlink dumps work), but thats a bit
more work.  Hence this quick workaround.

Reported-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
tests/regression/any/ct.t.payload
tests/regression/nft-test.py

index 2e7c1ff7ddeac05920ef1e55d1ea640bc7a1dd66..2bebaccd4dbb43ad959e54615a3896539ac523d4 100644 (file)
@@ -267,7 +267,7 @@ ip test-ip4 output
 # ct state . ct mark vmap { new . 0x12345678 : drop}
 map%d test-ip4 b
 map%d test-ip4 0
-        element 00000008 12345678  : 0 [end]
+       element 00000008 12345678  : 0 [end]
 ip test-ip4 output
   [ ct load state => reg 1 ]
   [ ct load mark => reg 9 ]
index 8168203b90a581d17e7b6730fdf82507bc042f09..d2fbe458c88380934f3d8028a6ab157b90c47457 100755 (executable)
@@ -424,6 +424,32 @@ def output_clean(pre_output, chain):
         return ""
     return rule
 
+def payload_check_elems_to_set(elems):
+    newset = set()
+
+    for n, line in enumerate(elems.split('[end]')):
+        e = line.strip()
+        if e in newset:
+            print_error("duplicate", e, n)
+            return newset
+
+        newset.add(e)
+
+    return newset
+
+def payload_check_set_elems(want, got):
+
+    if want.find('element') < 0 or want.find('[end]') < 0:
+        return 0
+
+    if got.find('element') < 0 or got.find('[end]') < 0:
+        return 0
+
+    set_want = payload_check_elems_to_set(want)
+    set_got = payload_check_elems_to_set(got)
+
+    return set_want == set_got
+
 def payload_check(payload_buffer, file, cmd):
 
     file.seek(0, 0)
@@ -443,6 +469,9 @@ def payload_check(payload_buffer, file, cmd):
         if want_line.find(']') < 0 and line.find(']') < 0:
             continue
 
+        if payload_check_set_elems(want_line, line):
+            continue
+
         print_differences_warning(file.name, lineno, want_line.strip(), line.strip(), cmd);
         return 0