Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8b4ac13

Browse files
liuhangbinborkmann
authored andcommitted
selftests/bpf/xdp_redirect_multi: Put the logs to tmp folder
The xdp_redirect_multi test logs are created in selftest folder and not cleaned after test. Let's creat a tmp dir and remove the logs after testing. Fixes: d232924 ("selftests/bpf: Add xdp_redirect_multi test") Suggested-by: Jiri Benc <[email protected]> Signed-off-by: Hangbin Liu <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 64165dd commit 8b4ac13

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

tools/testing/selftests/bpf/test_xdp_redirect_multi.sh

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ IFACES=""
3131
DRV_MODE="xdpgeneric xdpdrv xdpegress"
3232
PASS=0
3333
FAIL=0
34+
LOG_DIR=$(mktemp -d)
3435

3536
test_pass()
3637
{
@@ -100,17 +101,17 @@ do_egress_tests()
100101
local mode=$1
101102

102103
# mac test
103-
ip netns exec ns2 tcpdump -e -i veth0 -nn -l -e &> mac_ns1-2_${mode}.log &
104-
ip netns exec ns3 tcpdump -e -i veth0 -nn -l -e &> mac_ns1-3_${mode}.log &
104+
ip netns exec ns2 tcpdump -e -i veth0 -nn -l -e &> ${LOG_DIR}/mac_ns1-2_${mode}.log &
105+
ip netns exec ns3 tcpdump -e -i veth0 -nn -l -e &> ${LOG_DIR}/mac_ns1-3_${mode}.log &
105106
sleep 0.5
106107
ip netns exec ns1 ping 192.0.2.254 -i 0.1 -c 4 &> /dev/null
107108
sleep 0.5
108109
pkill -9 tcpdump
109110

110111
# mac check
111-
grep -q "${veth_mac[2]} > ff:ff:ff:ff:ff:ff" mac_ns1-2_${mode}.log && \
112+
grep -q "${veth_mac[2]} > ff:ff:ff:ff:ff:ff" ${LOG_DIR}/mac_ns1-2_${mode}.log && \
112113
test_pass "$mode mac ns1-2" || test_fail "$mode mac ns1-2"
113-
grep -q "${veth_mac[3]} > ff:ff:ff:ff:ff:ff" mac_ns1-3_${mode}.log && \
114+
grep -q "${veth_mac[3]} > ff:ff:ff:ff:ff:ff" ${LOG_DIR}/mac_ns1-3_${mode}.log && \
114115
test_pass "$mode mac ns1-3" || test_fail "$mode mac ns1-3"
115116
}
116117

@@ -121,9 +122,9 @@ do_ping_tests()
121122
# ping6 test: echo request should be redirect back to itself, not others
122123
ip netns exec ns1 ip neigh add 2001:db8::2 dev veth0 lladdr 00:00:00:00:00:02
123124

124-
ip netns exec ns1 tcpdump -i veth0 -nn -l -e &> ns1-1_${mode}.log &
125-
ip netns exec ns2 tcpdump -i veth0 -nn -l -e &> ns1-2_${mode}.log &
126-
ip netns exec ns3 tcpdump -i veth0 -nn -l -e &> ns1-3_${mode}.log &
125+
ip netns exec ns1 tcpdump -i veth0 -nn -l -e &> ${LOG_DIR}/ns1-1_${mode}.log &
126+
ip netns exec ns2 tcpdump -i veth0 -nn -l -e &> ${LOG_DIR}/ns1-2_${mode}.log &
127+
ip netns exec ns3 tcpdump -i veth0 -nn -l -e &> ${LOG_DIR}/ns1-3_${mode}.log &
127128
sleep 0.5
128129
# ARP test
129130
ip netns exec ns1 ping 192.0.2.254 -i 0.1 -c 4 &> /dev/null
@@ -135,32 +136,32 @@ do_ping_tests()
135136
pkill -9 tcpdump
136137

137138
# All netns should receive the redirect arp requests
138-
[ $(grep -c "who-has 192.0.2.254" ns1-1_${mode}.log) -gt 4 ] && \
139+
[ $(grep -c "who-has 192.0.2.254" ${LOG_DIR}/ns1-1_${mode}.log) -gt 4 ] && \
139140
test_pass "$mode arp(F_BROADCAST) ns1-1" || \
140141
test_fail "$mode arp(F_BROADCAST) ns1-1"
141-
[ $(grep -c "who-has 192.0.2.254" ns1-2_${mode}.log) -le 4 ] && \
142+
[ $(grep -c "who-has 192.0.2.254" ${LOG_DIR}/ns1-2_${mode}.log) -le 4 ] && \
142143
test_pass "$mode arp(F_BROADCAST) ns1-2" || \
143144
test_fail "$mode arp(F_BROADCAST) ns1-2"
144-
[ $(grep -c "who-has 192.0.2.254" ns1-3_${mode}.log) -le 4 ] && \
145+
[ $(grep -c "who-has 192.0.2.254" ${LOG_DIR}/ns1-3_${mode}.log) -le 4 ] && \
145146
test_pass "$mode arp(F_BROADCAST) ns1-3" || \
146147
test_fail "$mode arp(F_BROADCAST) ns1-3"
147148

148149
# ns1 should not receive the redirect echo request, others should
149-
[ $(grep -c "ICMP echo request" ns1-1_${mode}.log) -eq 4 ] && \
150+
[ $(grep -c "ICMP echo request" ${LOG_DIR}/ns1-1_${mode}.log) -eq 4 ] && \
150151
test_pass "$mode IPv4 (F_BROADCAST|F_EXCLUDE_INGRESS) ns1-1" || \
151152
test_fail "$mode IPv4 (F_BROADCAST|F_EXCLUDE_INGRESS) ns1-1"
152-
[ $(grep -c "ICMP echo request" ns1-2_${mode}.log) -eq 4 ] && \
153+
[ $(grep -c "ICMP echo request" ${LOG_DIR}/ns1-2_${mode}.log) -eq 4 ] && \
153154
test_pass "$mode IPv4 (F_BROADCAST|F_EXCLUDE_INGRESS) ns1-2" || \
154155
test_fail "$mode IPv4 (F_BROADCAST|F_EXCLUDE_INGRESS) ns1-2"
155-
[ $(grep -c "ICMP echo request" ns1-3_${mode}.log) -eq 4 ] && \
156+
[ $(grep -c "ICMP echo request" ${LOG_DIR}/ns1-3_${mode}.log) -eq 4 ] && \
156157
test_pass "$mode IPv4 (F_BROADCAST|F_EXCLUDE_INGRESS) ns1-3" || \
157158
test_fail "$mode IPv4 (F_BROADCAST|F_EXCLUDE_INGRESS) ns1-3"
158159

159160
# ns1 should receive the echo request, ns2 should not
160-
[ $(grep -c "ICMP6, echo request" ns1-1_${mode}.log) -eq 4 ] && \
161+
[ $(grep -c "ICMP6, echo request" ${LOG_DIR}/ns1-1_${mode}.log) -eq 4 ] && \
161162
test_pass "$mode IPv6 (no flags) ns1-1" || \
162163
test_fail "$mode IPv6 (no flags) ns1-1"
163-
[ $(grep -c "ICMP6, echo request" ns1-2_${mode}.log) -eq 0 ] && \
164+
[ $(grep -c "ICMP6, echo request" ${LOG_DIR}/ns1-2_${mode}.log) -eq 0 ] && \
164165
test_pass "$mode IPv6 (no flags) ns1-2" || \
165166
test_fail "$mode IPv6 (no flags) ns1-2"
166167
}
@@ -176,7 +177,7 @@ do_tests()
176177
xdpgeneric) drv_p="-S";;
177178
esac
178179

179-
./xdp_redirect_multi $drv_p $IFACES &> xdp_redirect_${mode}.log &
180+
./xdp_redirect_multi $drv_p $IFACES &> ${LOG_DIR}/xdp_redirect_${mode}.log &
180181
xdp_pid=$!
181182
sleep 1
182183

@@ -192,13 +193,13 @@ do_tests()
192193
trap clean_up 0 2 3 6 9
193194

194195
check_env
195-
rm -f xdp_redirect_*.log ns*.log mac_ns*.log
196196

197197
for mode in ${DRV_MODE}; do
198198
setup_ns $mode
199199
do_tests $mode
200200
clean_up
201201
done
202+
rm -rf ${LOG_DIR}
202203

203204
echo "Summary: PASS $PASS, FAIL $FAIL"
204205
[ $FAIL -eq 0 ] && exit 0 || exit 1

0 commit comments

Comments
 (0)