Debian Codegraph @

tests/shell/testcases/sets/automerge_0

raw
1 #!/bin/bash
2
3 # NFT_TEST_SKIP(NFT_TEST_SKIP_slow)
4
5 set -e
6
7 RULESET="table inet x {
8 set y {
9 type inet_service
10 flags interval
11 auto-merge
12 }
13 }"
14
15 HOWMANY=65535
16 if [ "$NFT_TEST_HAS_SOCKET_LIMITS" = y ] ; then
17 # The socket limit /proc/sys/net/core/wmem_max may be unsuitable for
18 # the test.
19 #
20 # Run only a subset of the test and mark as skipped at the end.
21 HOWMANY=5000
22 fi
23
24 $NFT -f - <<< $RULESET
25
26 tmpfile=$(mktemp)
27 echo -n "add element inet x y { " > $tmpfile
28 for ((i=0;i<$HOWMANY;i+=2))
29 do
30 echo -n "$i, " >> $tmpfile
31 if [ $i -eq $((HOWMANY-1)) ]
32 then
33 echo -n "$i" >> $tmpfile
34 fi
35 done
36 echo "}" >> $tmpfile
37
38 $NFT -f $tmpfile
39
40 tmpfile2=$(mktemp)
41 for ((i=1;i<$HOWMANY;i+=2))
42 do
43 echo "$i" >> $tmpfile2
44 done
45
46 tmpfile3=$(mktemp)
47 shuf "$tmpfile2" --random-source=<("$NFT_TEST_BASEDIR/helpers/random-source.sh" "automerge-shuf-tmpfile2" "$NFT_TEST_RANDOM_SEED") > "$tmpfile3"
48 i=0
49 cat $tmpfile3 | while read line && [ $i -lt 10 ]
50 do
51 $NFT add element inet x y { $line }
52 if [ $? -ne 0 ]
53 then
54 echo "failed to add $line"
55 exit 1
56 fi
57 i=$((i+1))
58 done
59
60 for ((i=0;i<10;i++))
61 do
62 from=$(($RANDOM%$HOWMANY))
63 to=$(($from+100))
64 $NFT add element inet x y { $from-$to }
65 if [ $? -ne 0 ]
66 then
67 echo "failed to add $from-$to"
68 exit 1
69 fi
70
71 $NFT get element inet x y { $from-$to } 1>/dev/null
72 if [ $? -ne 0 ]
73 then
74 echo "failed to get $from-$to"
75 exit 1
76 fi
77
78 # partial removals in the previous random range
79 from2=$(($from+10))
80 to2=$(($to-10))
81 $NFT delete element inet x y { $from, $to, $from2-$to2 }
82 if [ $? -ne 0 ]
83 then
84 echo "failed to delete $from, $to, $from2-$to2"
85 exit 1
86 fi
87
88 # check deletions are correct
89 from=$(($from+1))
90 $NFT get element inet x y { $from } 1>/dev/null
91 if [ $? -ne 0 ]
92 then
93 echo "failed to get $from"
94 exit 1
95 fi
96
97 to=$(($to-1))
98 $NFT get element inet x y { $to } 1>/dev/null
99 if [ $? -ne 0 ]
100 then
101 echo "failed to get $to"
102 exit 1
103 fi
104
105 from2=$(($from2-1))
106 $NFT get element inet x y { $from2 } 1>/dev/null
107 if [ $? -ne 0 ]
108 then
109 echo "failed to get $from2"
110 exit 1
111 fi
112 to2=$(($to2+1))
113
114 $NFT get element inet x y { $to2 } 1>/dev/null
115 if [ $? -ne 0 ]
116 then
117 echo "failed to get $to2"
118 exit 1
119 fi
120 done
121
122 rm -f $tmpfile
123 rm -f $tmpfile2
124 rm -f $tmpfile3
125
126 if [ "$HOWMANY" != 65535 ] ; then
127 echo "NFT_TEST_HAS_SOCKET_LIMITS indicates that the socket limit for"
128 echo "/proc/sys/net/core/wmem_max is too small for this test. Mark as SKIPPED"
129 echo "You may bump the limit and rerun with \`NFT_TEST_HAS_SOCKET_LIMITS=n\`."
130 exit 77
131 fi