drm/bridge: adv7511: Switch to atomic operations
[drm/drm-misc.git] / tools / testing / selftests / net / busy_poll_test.sh
blob7db292ec4884a94677b086bde7cd070c043ed56b
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 source net_helper.sh
5 NSIM_SV_ID=$((256 + RANDOM % 256))
6 NSIM_SV_SYS=/sys/bus/netdevsim/devices/netdevsim$NSIM_SV_ID
7 NSIM_CL_ID=$((512 + RANDOM % 256))
8 NSIM_CL_SYS=/sys/bus/netdevsim/devices/netdevsim$NSIM_CL_ID
10 NSIM_DEV_SYS_NEW=/sys/bus/netdevsim/new_device
11 NSIM_DEV_SYS_DEL=/sys/bus/netdevsim/del_device
12 NSIM_DEV_SYS_LINK=/sys/bus/netdevsim/link_device
13 NSIM_DEV_SYS_UNLINK=/sys/bus/netdevsim/unlink_device
15 SERVER_IP=192.168.1.1
16 CLIENT_IP=192.168.1.2
17 SERVER_PORT=48675
19 # busy poll config
20 MAX_EVENTS=8
21 BUSY_POLL_USECS=0
22 BUSY_POLL_BUDGET=16
23 PREFER_BUSY_POLL=1
25 # IRQ deferral config
26 NAPI_DEFER_HARD_IRQS=100
27 GRO_FLUSH_TIMEOUT=50000
28 SUSPEND_TIMEOUT=20000000
30 setup_ns()
32 set -e
33 ip netns add nssv
34 ip netns add nscl
36 NSIM_SV_NAME=$(find $NSIM_SV_SYS/net -maxdepth 1 -type d ! \
37 -path $NSIM_SV_SYS/net -exec basename {} \;)
38 NSIM_CL_NAME=$(find $NSIM_CL_SYS/net -maxdepth 1 -type d ! \
39 -path $NSIM_CL_SYS/net -exec basename {} \;)
41 # ensure the server has 1 queue
42 ethtool -L $NSIM_SV_NAME combined 1 2>/dev/null
44 ip link set $NSIM_SV_NAME netns nssv
45 ip link set $NSIM_CL_NAME netns nscl
47 ip netns exec nssv ip addr add "${SERVER_IP}/24" dev $NSIM_SV_NAME
48 ip netns exec nscl ip addr add "${CLIENT_IP}/24" dev $NSIM_CL_NAME
50 ip netns exec nssv ip link set dev $NSIM_SV_NAME up
51 ip netns exec nscl ip link set dev $NSIM_CL_NAME up
53 set +e
56 cleanup_ns()
58 ip netns del nscl
59 ip netns del nssv
62 test_busypoll()
64 suspend_value=${1:-0}
65 tmp_file=$(mktemp)
66 out_file=$(mktemp)
68 # fill a test file with random data
69 dd if=/dev/urandom of=${tmp_file} bs=1M count=1 2> /dev/null
71 timeout -k 1s 30s ip netns exec nssv ./busy_poller \
72 -p${SERVER_PORT} \
73 -b${SERVER_IP} \
74 -m${MAX_EVENTS} \
75 -u${BUSY_POLL_USECS} \
76 -P${PREFER_BUSY_POLL} \
77 -g${BUSY_POLL_BUDGET} \
78 -i${NSIM_SV_IFIDX} \
79 -s${suspend_value} \
80 -o${out_file}&
82 wait_local_port_listen nssv ${SERVER_PORT} tcp
84 ip netns exec nscl socat -u $tmp_file TCP:${SERVER_IP}:${SERVER_PORT}
86 wait
88 tmp_file_md5sum=$(md5sum $tmp_file | cut -f1 -d' ')
89 out_file_md5sum=$(md5sum $out_file | cut -f1 -d' ')
91 if [ "$tmp_file_md5sum" = "$out_file_md5sum" ]; then
92 res=0
93 else
94 echo "md5sum mismatch"
95 echo "input file md5sum: ${tmp_file_md5sum}";
96 echo "output file md5sum: ${out_file_md5sum}";
97 res=1
100 rm $out_file $tmp_file
102 return $res
105 test_busypoll_with_suspend()
107 test_busypoll ${SUSPEND_TIMEOUT}
109 return $?
113 ### Code start
116 modprobe netdevsim
118 # linking
120 echo $NSIM_SV_ID > $NSIM_DEV_SYS_NEW
121 echo $NSIM_CL_ID > $NSIM_DEV_SYS_NEW
122 udevadm settle
124 setup_ns
126 NSIM_SV_FD=$((256 + RANDOM % 256))
127 exec {NSIM_SV_FD}</var/run/netns/nssv
128 NSIM_SV_IFIDX=$(ip netns exec nssv cat /sys/class/net/$NSIM_SV_NAME/ifindex)
130 NSIM_CL_FD=$((256 + RANDOM % 256))
131 exec {NSIM_CL_FD}</var/run/netns/nscl
132 NSIM_CL_IFIDX=$(ip netns exec nscl cat /sys/class/net/$NSIM_CL_NAME/ifindex)
134 echo "$NSIM_SV_FD:$NSIM_SV_IFIDX $NSIM_CL_FD:$NSIM_CL_IFIDX" > \
135 $NSIM_DEV_SYS_LINK
137 if [ $? -ne 0 ]; then
138 echo "linking netdevsim1 with netdevsim2 should succeed"
139 cleanup_ns
140 exit 1
143 test_busypoll
144 if [ $? -ne 0 ]; then
145 echo "test_busypoll failed"
146 cleanup_ns
147 exit 1
150 test_busypoll_with_suspend
151 if [ $? -ne 0 ]; then
152 echo "test_busypoll_with_suspend failed"
153 cleanup_ns
154 exit 1
157 echo "$NSIM_SV_FD:$NSIM_SV_IFIDX" > $NSIM_DEV_SYS_UNLINK
159 echo $NSIM_CL_ID > $NSIM_DEV_SYS_DEL
161 cleanup_ns
163 modprobe -r netdevsim
165 exit 0