tests: iptables-test: Fix for duplicate supposed-to-fail errors
Phil Sutter
reviewerPATCH 1/1 tests: iptables-test: Fix for duplicate supposed-to-fail errors
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.
--- iptables-test.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
iptables-test.py +10 -10
@@ -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
Signature · 1 line
2.47.0
Phil Sutter
reviewerQuoted 10 lines · Phil Sutter
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 <[email protected]>
Patch applied.