diff mbox series

[iptables] tests: iptables-test: Fix for duplicate supposed-to-fail errors

Message ID 20241022150426.14520-1-phil@nwl.cc
State Accepted
Headers show
Series [iptables] tests: iptables-test: Fix for duplicate supposed-to-fail errors | expand

Commit Message

Phil Sutter Oct. 22, 2024, 3:04 p.m. UTC
Unexpected results for lines which are supposed to fail are reported
twice: Once when fast mode runs them individually to clear the path
before batch-handling all others, a second time when non-fast mode takes
over after fast mode had failed and runs all tests individually again.

Sort this nuisance by running these tests silently in fast mode, knowing
that they will run again if failing anyway.

Fixes: 0e80cfea3762b ("tests: iptables-test: Implement fast test mode")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 iptables-test.py | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

Comments

Phil Sutter Nov. 5, 2024, 11:01 p.m. UTC | #1
On Tue, Oct 22, 2024 at 05:04:25PM +0200, Phil Sutter wrote:
> Unexpected results for lines which are supposed to fail are reported
> twice: Once when fast mode runs them individually to clear the path
> before batch-handling all others, a second time when non-fast mode takes
> over after fast mode had failed and runs all tests individually again.
> 
> Sort this nuisance by running these tests silently in fast mode, knowing
> that they will run again if failing anyway.
> 
> Fixes: 0e80cfea3762b ("tests: iptables-test: Implement fast test mode")
> Signed-off-by: Phil Sutter <phil@nwl.cc>

Patch applied.
diff mbox series

Patch

diff --git a/iptables-test.py b/iptables-test.py
index 77278925d7217..28029ad32bb24 100755
--- a/iptables-test.py
+++ b/iptables-test.py
@@ -47,12 +47,12 @@  STDERR_IS_TTY = sys.stderr.isatty()
     )
 
 
-def print_error(reason, filename=None, lineno=None):
+def print_error(reason, filename=None, lineno=None, log_file=sys.stderr):
     '''
     Prints an error with nice colors, indicating file and line number.
     '''
-    print(filename + ": " + maybe_colored('red', "ERROR", STDERR_IS_TTY) +
-        ": line %d (%s)" % (lineno, reason), file=sys.stderr)
+    print(filename + ": " + maybe_colored('red', "ERROR", log_file.isatty()) +
+        ": line %d (%s)" % (lineno, reason), file=log_file)
 
 
 def delete_rule(iptables, rule, filename, lineno, netns = None):
@@ -69,7 +69,7 @@  STDERR_IS_TTY = sys.stderr.isatty()
     return 0
 
 
-def run_test(iptables, rule, rule_save, res, filename, lineno, netns):
+def run_test(iptables, rule, rule_save, res, filename, lineno, netns, stderr=sys.stderr):
     '''
     Executes an unit test. Returns the output of delete_rule().
 
@@ -93,7 +93,7 @@  STDERR_IS_TTY = sys.stderr.isatty()
     if ret:
         if res != "FAIL":
             reason = "cannot load: " + cmd
-            print_error(reason, filename, lineno)
+            print_error(reason, filename, lineno, stderr)
             return -1
         else:
             # do not report this error
@@ -101,7 +101,7 @@  STDERR_IS_TTY = sys.stderr.isatty()
     else:
         if res == "FAIL":
             reason = "should fail: " + cmd
-            print_error(reason, filename, lineno)
+            print_error(reason, filename, lineno, stderr)
             delete_rule(iptables, rule, filename, lineno, netns)
             return -1
 
@@ -140,7 +140,7 @@  STDERR_IS_TTY = sys.stderr.isatty()
     #
     if proc.returncode == -11:
         reason = command + " segfaults!"
-        print_error(reason, filename, lineno)
+        print_error(reason, filename, lineno, stderr)
         delete_rule(iptables, rule, filename, lineno, netns)
         return -1
 
@@ -150,7 +150,7 @@  STDERR_IS_TTY = sys.stderr.isatty()
     if matching < 0:
         if res == "OK":
             reason = "cannot find: " + iptables + " -I " + rule
-            print_error(reason, filename, lineno)
+            print_error(reason, filename, lineno, stderr)
             delete_rule(iptables, rule, filename, lineno, netns)
             return -1
         else:
@@ -159,7 +159,7 @@  STDERR_IS_TTY = sys.stderr.isatty()
     else:
         if res != "OK":
             reason = "should not match: " + cmd
-            print_error(reason, filename, lineno)
+            print_error(reason, filename, lineno, stderr)
             delete_rule(iptables, rule, filename, lineno, netns)
             return -1
 
@@ -298,7 +298,7 @@  STDERR_IS_TTY = sys.stderr.isatty()
             if res != "OK":
                 rule = chain + " -t " + table + " " + item[0]
                 ret = run_test(iptables, rule, rule_save,
-                               res, filename, lineno + 1, netns)
+                               res, filename, lineno + 1, netns, log_file)
 
                 if ret < 0:
                     return -1