Linux Netfilter development
 help / color / mirror / Atom feed
* [iptables PATCH] tests: iptables-test: Fix for duplicate supposed-to-fail errors
@ 2024-10-22 15:04 Phil Sutter
  2024-11-05 23:01 ` Phil Sutter
  0 siblings, 1 reply; 2+ messages in thread
From: Phil Sutter @ 2024-10-22 15:04 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Pablo Neira Ayuso

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(-)

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
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-11-05 23:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-22 15:04 [iptables PATCH] tests: iptables-test: Fix for duplicate supposed-to-fail errors Phil Sutter
2024-11-05 23:01 ` Phil Sutter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox