~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/drivers/net/netdevsim/psample.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/bash
  2 # SPDX-License-Identifier: GPL-2.0
  3 #
  4 # This test is for checking the psample module. It makes use of netdevsim
  5 # which periodically generates "sampled" packets.
  6 
  7 lib_dir=$(dirname $0)/../../../net/forwarding
  8 
  9 ALL_TESTS="
 10         psample_enable_test
 11         psample_group_num_test
 12         psample_md_test
 13 "
 14 NETDEVSIM_PATH=/sys/bus/netdevsim/
 15 DEV_ADDR=1337
 16 DEV=netdevsim${DEV_ADDR}
 17 SYSFS_NET_DIR=/sys/bus/netdevsim/devices/$DEV/net/
 18 PSAMPLE_DIR=/sys/kernel/debug/netdevsim/$DEV/psample/
 19 CAPTURE_FILE=$(mktemp)
 20 NUM_NETIFS=0
 21 source $lib_dir/lib.sh
 22 
 23 DEVLINK_DEV=
 24 source $lib_dir/devlink_lib.sh
 25 DEVLINK_DEV=netdevsim/${DEV}
 26 
 27 # Available at https://github.com/Mellanox/libpsample
 28 require_command psample
 29 
 30 psample_capture()
 31 {
 32         rm -f $CAPTURE_FILE
 33 
 34         timeout 2 ip netns exec testns1 psample &> $CAPTURE_FILE
 35 }
 36 
 37 psample_enable_test()
 38 {
 39         RET=0
 40 
 41         echo 1 > $PSAMPLE_DIR/enable
 42         check_err $? "Failed to enable sampling when should not"
 43 
 44         echo 1 > $PSAMPLE_DIR/enable 2>/dev/null
 45         check_fail $? "Sampling enablement succeeded when should fail"
 46 
 47         psample_capture
 48         if [ $(cat $CAPTURE_FILE | wc -l) -eq 0 ]; then
 49                 check_err 1 "Failed to capture sampled packets"
 50         fi
 51 
 52         echo 0 > $PSAMPLE_DIR/enable
 53         check_err $? "Failed to disable sampling when should not"
 54 
 55         echo 0 > $PSAMPLE_DIR/enable 2>/dev/null
 56         check_fail $? "Sampling disablement succeeded when should fail"
 57 
 58         psample_capture
 59         if [ $(cat $CAPTURE_FILE | wc -l) -ne 0 ]; then
 60                 check_err 1 "Captured sampled packets when should not"
 61         fi
 62 
 63         log_test "psample enable / disable"
 64 }
 65 
 66 psample_group_num_test()
 67 {
 68         RET=0
 69 
 70         echo 1234 > $PSAMPLE_DIR/group_num
 71         echo 1 > $PSAMPLE_DIR/enable
 72 
 73         psample_capture
 74         grep -q -e "group 1234" $CAPTURE_FILE
 75         check_err $? "Sampled packets reported with wrong group number"
 76 
 77         # New group number should only be used after disable / enable.
 78         echo 4321 > $PSAMPLE_DIR/group_num
 79 
 80         psample_capture
 81         grep -q -e "group 4321" $CAPTURE_FILE
 82         check_fail $? "Group number changed while sampling is active"
 83 
 84         echo 0 > $PSAMPLE_DIR/enable && echo 1 > $PSAMPLE_DIR/enable
 85 
 86         psample_capture
 87         grep -q -e "group 4321" $CAPTURE_FILE
 88         check_err $? "Group number did not change after restarting sampling"
 89 
 90         log_test "psample group number"
 91 
 92         echo 0 > $PSAMPLE_DIR/enable
 93 }
 94 
 95 psample_md_test()
 96 {
 97         RET=0
 98 
 99         echo 1 > $PSAMPLE_DIR/enable
100 
101         echo 1234 > $PSAMPLE_DIR/in_ifindex
102         echo 4321 > $PSAMPLE_DIR/out_ifindex
103         psample_capture
104 
105         grep -q -e "in-ifindex 1234" $CAPTURE_FILE
106         check_err $? "Sampled packets reported with wrong in-ifindex"
107 
108         grep -q -e "out-ifindex 4321" $CAPTURE_FILE
109         check_err $? "Sampled packets reported with wrong out-ifindex"
110 
111         echo 5 > $PSAMPLE_DIR/out_tc
112         psample_capture
113 
114         grep -q -e "out-tc 5" $CAPTURE_FILE
115         check_err $? "Sampled packets reported with wrong out-tc"
116 
117         echo $((2**16 - 1)) > $PSAMPLE_DIR/out_tc
118         psample_capture
119 
120         grep -q -e "out-tc " $CAPTURE_FILE
121         check_fail $? "Sampled packets reported with out-tc when should not"
122 
123         echo 1 > $PSAMPLE_DIR/out_tc
124         echo 10000 > $PSAMPLE_DIR/out_tc_occ_max
125         psample_capture
126 
127         grep -q -e "out-tc-occ " $CAPTURE_FILE
128         check_err $? "Sampled packets not reported with out-tc-occ when should"
129 
130         echo 0 > $PSAMPLE_DIR/out_tc_occ_max
131         psample_capture
132 
133         grep -q -e "out-tc-occ " $CAPTURE_FILE
134         check_fail $? "Sampled packets reported with out-tc-occ when should not"
135 
136         echo 10000 > $PSAMPLE_DIR/latency_max
137         psample_capture
138 
139         grep -q -e "latency " $CAPTURE_FILE
140         check_err $? "Sampled packets not reported with latency when should"
141 
142         echo 0 > $PSAMPLE_DIR/latency_max
143         psample_capture
144 
145         grep -q -e "latency " $CAPTURE_FILE
146         check_fail $? "Sampled packets reported with latency when should not"
147 
148         log_test "psample metadata"
149 
150         echo 0 > $PSAMPLE_DIR/enable
151 }
152 
153 setup_prepare()
154 {
155         modprobe netdevsim &> /dev/null
156 
157         echo "$DEV_ADDR 1" > ${NETDEVSIM_PATH}/new_device
158         while [ ! -d $SYSFS_NET_DIR ] ; do :; done
159 
160         set -e
161 
162         ip netns add testns1
163         devlink dev reload $DEVLINK_DEV netns testns1
164 
165         set +e
166 }
167 
168 cleanup()
169 {
170         pre_cleanup
171         rm -f $CAPTURE_FILE
172         ip netns del testns1
173         echo "$DEV_ADDR" > ${NETDEVSIM_PATH}/del_device
174         modprobe -r netdevsim &> /dev/null
175 }
176 
177 trap cleanup EXIT
178 
179 setup_prepare
180 
181 tests_run
182 
183 exit $EXIT_STATUS

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php