]> git.ipfire.org Git - thirdparty/ipset.git/commitdiff
tests: add namespace test and take into account delayed set removal at module remove
authorJozsef Kadlecsik <kadlec@netfilter.org>
Tue, 4 Jun 2024 08:04:33 +0000 (10:04 +0200)
committerJozsef Kadlecsik <kadlec@netfilter.org>
Tue, 4 Jun 2024 08:04:33 +0000 (10:04 +0200)
tests/setlist.t
tests/setlist_ns.sh [new file with mode: 0755]
tests/setlist_resize.sh

index 316daf86b37a82771b679dac8906d2bc7169d62a..a2780d7aa825d1a577aed59f2a2f658e9869d744 100644 (file)
@@ -211,4 +211,6 @@ skip which sendip >/dev/null
 0 ipset f
 # Counters and timeout: destroy sets
 0 ipset x
+# Use namespace and test list:set with comments (takes longer)
+0 ./setlist_ns.sh
 # eof
diff --git a/tests/setlist_ns.sh b/tests/setlist_ns.sh
new file mode 100755 (executable)
index 0000000..9e47d65
--- /dev/null
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+set -e
+
+CMD=$(cat <<EOF
+for x in \$(seq 0 127); do
+    echo "create h\$x hash:ip"
+    echo "create l\$x list:set timeout 10 comment"
+done | ipset restore
+for x in \$(seq 0 127); do
+    for y in \$(seq 0 127); do
+        echo "add l\$x h\$y timeout 1000 comment \"l\$x h\$y\""
+    done
+done | ipset restore
+# Wait for GC
+sleep 15
+EOF
+)
+
+for x in seq 0 123; do
+    unshare -Urn bash -c "$CMD"
+done
index 848f1d123b2a00aa426e19a07172f8b8378d8e26..1c2be327b841a6956d243e3601610298766d94a7 100755 (executable)
@@ -1,19 +1,26 @@
 #!/bin/sh
 
+set -e
 # set -x
+# exec > setlist.res
+# exec 2>&1
 
 ipset=${IPSET_BIN:-../src/ipset}
 
 loop=8
 
-for x in ip_set_list_set ip_set_hash_netiface ip_set_hash_ipportnet \
-        ip_set_hash_netport ip_set_hash_net ip_set_hash_ipportip \
-        ip_set_hash_ipport ip_set_hash_ip ip_set_hash_netnet \
-        ip_set_hash_netportnet ip_set_hash_ipmark ip_set_hash_mac \
-        ip_set_bitmap_port ip_set_bitmap_ipmac \
-        ip_set_bitmap_ip xt_set ip_set; do
-    rmmod $x >/dev/null 2>&1
+n=0
+while [ $n -le 9 ]; do
+    egrep '^(ip_set_|xt_set)' /proc/modules | while read x y; do
+       rmmod $x >/dev/null 2>&1
+    done
+    if [ "`egrep '^(ip_set_|xt_set)' /proc/modules`" ]; then
+       sleep 1s
+    else
+       n=10
+    fi
 done
+rmmod ip_set >/dev/null 2>&1
 
 create() {
     n=$1
@@ -30,7 +37,23 @@ for x in `seq 1 $loop`; do
     wait
     test `$ipset l -n | wc -l` -eq 1024 || exit 1
     $ipset x
-    test `lsmod|grep -w ^ip_set_hash_ip | awk '{print $3}'` -eq 0 || exit 1
+    # Wait for destroy to be finished and reference counts releases
+    n=0
+    ref=0
+    while [ $n -le 9 ]; do
+       ref=`lsmod|grep -w ^ip_set_hash_ip | awk '{print $3}'`
+       if [ $ref -eq 0 ]; then
+           n=10;
+       else
+           sleep 1s
+           n=$((n+1))
+       fi
+    done
+    if [ "$ref" -ne 0 ]; then
+       lsmod
+       echo $ref
+    fi
+    test "$ref" -eq 0 || exit 1
     rmmod ip_set_hash_ip >/dev/null 2>&1
     rmmod ip_set >/dev/null 2>&1
 done