Skip to contentSkip to conversation

tests: shell: iptables/0010-wait_0 is unreliable

PATCH In review Phil Sutter 1 participant 6 messages Nov 6, 2024

Subsystems (2)
lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/5 tests: shell: iptables/0010-wait_0 is unreliable

Sometimes the test would fail, especially after removing /run/xtables.lock file. Looks like the supposedly blocking iptables-restore coproc sometimes takes a moment to set things up.

Fixes 63ab5b8906f69 ("iptables-legacy: Fix for mandatory lock waiting")
---
 iptables/tests/shell/testcases/iptables/0010-wait_0 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
iptables/tests/shell/testcases/iptables/0010-wait_0 +1 -1
index 4481f966ce435..37a7a58fc5dca 100755
@@ -11,7 +11,7 @@ esac
 
 coproc RESTORE { $XT_MULTI iptables-restore; }
 echo "*filter" >&${RESTORE[1]}
-
+sleep 0.5
 
 $XT_MULTI iptables -A FORWARD -j ACCEPT &
 ipt_pid=$!
Signature · 1 line
2.47.0
author reviewer
#1 lore raw

PATCH 2/5 tests: shell: Print escape sequences with terminals only

If stdout is not a terminal, don't print the '[EXECUTING]' status line which has to be cleared again.

---
 iptables/tests/shell/run-tests.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
iptables/tests/shell/run-tests.sh +2 -2
index 2ad259c21644c..565b654e9f134 100755
@@ -165,7 +165,7 @@ do_test() {
 
 	rc_spec=`echo $(basename ${testfile}) | cut -d _ -f2-`
 
-	msg_info "[EXECUTING]   $testfile"
+	[ -t 1 ] && msg_info "[EXECUTING]   $testfile"
 
 	if [ "$VERBOSE" = "y" ]; then
 		XT_MULTI=$xtables_multi unshare -n ${testfile}
@@ -173,7 +173,7 @@ do_test() {
 	else
 		XT_MULTI=$xtables_multi unshare -n ${testfile} > /dev/null 2>&1
 		rc_got=$?
-		echo -en "\033[1A\033[K" # clean the [EXECUTING] foobar line
+		[ -t 1 ] && echo -en "\033[1A\033[K" # clean the [EXECUTING] foobar line
 	fi
 
 	if [ "$rc_got" == "$rc_spec" ] ; then
Signature · 1 line
2.47.0
author reviewer
#2 lore raw

PATCH 3/5 tests: iptables-test: Fix for 'make distcheck'

In reply to Phil Sutter

This was a tricky one: Since called from VPATH topdir, extensions/ do not contain test files at all. The script consequently passed since 0 tests failed (of 0 in total).

Fix this by introducing TESTS_PATH which is extensions/ below the directory of the running iptables-test.py. Keep EXTENSIONS_PATH as-is: The built extensions are indeed there and XTABLES_LIBDIR must point to them.

---
 iptables-test.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
iptables-test.py +4 -3
index 141fec7b4ed16..66db552185bc3 100755
@@ -30,6 +30,7 @@ EBTABLES_SAVE = "ebtables-save"
 #IP6TABLES_SAVE = ['xtables-save','-6']
 
 EXTENSIONS_PATH = "extensions"
+TESTS_PATH = os.path.join(os.path.dirname(sys.argv[0]), "extensions")
 LOGFILE="/tmp/iptables-test.log"
 log_file = None
 
@@ -558,7 +559,7 @@ STDERR_IS_TTY = sys.stderr.isatty()
     '''
     Show the list of missing test files
     '''
-    file_list = os.listdir(EXTENSIONS_PATH)
+    file_list = os.listdir(TESTS_PATH)
     testfiles = [i for i in file_list if i.endswith('.t')]
     libfiles = [i for i in file_list
                 if i.startswith('lib') and i.endswith('.c')]
@@ -669,8 +670,8 @@ STDERR_IS_TTY = sys.stderr.isatty()
         if args.filename:
             file_list = args.filename
         else:
-            file_list = [os.path.join(EXTENSIONS_PATH, i)
-                         for i in os.listdir(EXTENSIONS_PATH)
+            file_list = [os.path.join(TESTS_PATH, i)
+                         for i in os.listdir(TESTS_PATH)
                          if i.endswith('.t')]
             file_list.sort()
 
Signature · 1 line
2.47.0
author reviewer
#3 lore raw

PATCH 4/5 tests: xlate-test: Fix for 'make distcheck'

In reply to Phil Sutter

Similar problem as with the other suites: The build directory does not contain test cases, only build results.

---
 xlate-test.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
xlate-test.py +4 -2
index b6a78bb250e27..1c8cfe71ffd46 100755
@@ -188,8 +188,10 @@ xtables_nft_multi = 'xtables-nft-multi'
 
 def load_test_files():
     test_files = total_tests = total_passed = total_error = total_failed = 0
-    tests = sorted(os.listdir("extensions"))
-    for test in ['extensions/' + f for f in tests if f.endswith(".txlate")]:
+    tests_path = os.path.join(os.path.dirname(sys.argv[0]), "extensions")
+    tests = sorted(os.listdir(tests_path))
+    for test in [os.path.join(tests_path, f)
+                 for f in tests if f.endswith(".txlate")]:
         with open(test, "r") as payload:
             tests, passed, failed, errors = run_test(test, payload)
             test_files += 1
Signature · 1 line
2.47.0
author reviewer
#4 lore raw

PATCH 5/5 Makefile.am: Revert to old serial test harness

In reply to Phil Sutter

Running the different testsuites in parallel is dangerous since despite running in different netns, legacy iptables still synchronizes via the common XTABLES_LOCKFILE.

Fixes e1eaa04e31e44 ("Makefile.am: Integrate testsuites")
---
 Makefile.am | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile.am +1 -1
index 299ab46d7b8e2..d0ba059c00110 100644
@@ -1,7 +1,7 @@
 # -*- Makefile -*-
 
 ACLOCAL_AMFLAGS  = -I m4
-AUTOMAKE_OPTIONS = foreign subdir-objects dist-xz no-dist-gzip
+AUTOMAKE_OPTIONS = foreign subdir-objects dist-xz no-dist-gzip serial-tests
 
 SUBDIRS          = libiptc libxtables
 if ENABLE_DEVEL
Signature · 1 line
2.47.0
author reviewer
#5 lore raw
In reply to Phil Sutter
Quoted 6 lines · Phil Sutter

Sometimes the test would fail, especially after removing /run/xtables.lock file. Looks like the supposedly blocking iptables-restore coproc sometimes takes a moment to set things up.

Fixes 63ab5b8906f69 ("iptables-legacy: Fix for mandatory lock waiting")

Series applied.