2 # SPDX-License-Identifier: GPL-2.0
4 # This test is for checking the psample module. It makes use of netdevsim
5 # which periodically generates "sampled" packets.
7 lib_dir=$(dirname $0)/../../../net/forwarding
11 psample_group_num_test
14 NETDEVSIM_PATH=/sys/bus/netdevsim/
16 DEV=netdevsim${DEV_ADDR}
17 DEVLINK_DEV=netdevsim/${DEV}
18 SYSFS_NET_DIR=/sys/bus/netdevsim/devices/$DEV/net/
19 PSAMPLE_DIR=/sys/kernel/debug/netdevsim/$DEV/psample/
20 CAPTURE_FILE=$(mktemp)
22 source $lib_dir/lib.sh
23 source $lib_dir/devlink_lib.sh
25 # Available at https://github.com/Mellanox/libpsample
26 require_command psample
32 timeout 2 ip netns exec testns1 psample &> $CAPTURE_FILE
39 echo 1 > $PSAMPLE_DIR/enable
40 check_err $? "Failed to enable sampling when should not"
42 echo 1 > $PSAMPLE_DIR/enable 2>/dev/null
43 check_fail $? "Sampling enablement succeeded when should fail"
46 if [ $(cat $CAPTURE_FILE | wc -l) -eq 0 ]; then
47 check_err 1 "Failed to capture sampled packets"
50 echo 0 > $PSAMPLE_DIR/enable
51 check_err $? "Failed to disable sampling when should not"
53 echo 0 > $PSAMPLE_DIR/enable 2>/dev/null
54 check_fail $? "Sampling disablement succeeded when should fail"
57 if [ $(cat $CAPTURE_FILE | wc -l) -ne 0 ]; then
58 check_err 1 "Captured sampled packets when should not"
61 log_test "psample enable / disable"
64 psample_group_num_test()
68 echo 1234 > $PSAMPLE_DIR/group_num
69 echo 1 > $PSAMPLE_DIR/enable
72 grep -q -e "group 1234" $CAPTURE_FILE
73 check_err $? "Sampled packets reported with wrong group number"
75 # New group number should only be used after disable / enable.
76 echo 4321 > $PSAMPLE_DIR/group_num
79 grep -q -e "group 4321" $CAPTURE_FILE
80 check_fail $? "Group number changed while sampling is active"
82 echo 0 > $PSAMPLE_DIR/enable && echo 1 > $PSAMPLE_DIR/enable
85 grep -q -e "group 4321" $CAPTURE_FILE
86 check_err $? "Group number did not change after restarting sampling"
88 log_test "psample group number"
90 echo 0 > $PSAMPLE_DIR/enable
97 echo 1 > $PSAMPLE_DIR/enable
99 echo 1234 > $PSAMPLE_DIR/in_ifindex
100 echo 4321 > $PSAMPLE_DIR/out_ifindex
103 grep -q -e "in-ifindex 1234" $CAPTURE_FILE
104 check_err $? "Sampled packets reported with wrong in-ifindex"
106 grep -q -e "out-ifindex 4321" $CAPTURE_FILE
107 check_err $? "Sampled packets reported with wrong out-ifindex"
109 echo 5 > $PSAMPLE_DIR/out_tc
112 grep -q -e "out-tc 5" $CAPTURE_FILE
113 check_err $? "Sampled packets reported with wrong out-tc"
115 echo $((2**16 - 1)) > $PSAMPLE_DIR/out_tc
118 grep -q -e "out-tc " $CAPTURE_FILE
119 check_fail $? "Sampled packets reported with out-tc when should not"
121 echo 1 > $PSAMPLE_DIR/out_tc
122 echo 10000 > $PSAMPLE_DIR/out_tc_occ_max
125 grep -q -e "out-tc-occ " $CAPTURE_FILE
126 check_err $? "Sampled packets not reported with out-tc-occ when should"
128 echo 0 > $PSAMPLE_DIR/out_tc_occ_max
131 grep -q -e "out-tc-occ " $CAPTURE_FILE
132 check_fail $? "Sampled packets reported with out-tc-occ when should not"
134 echo 10000 > $PSAMPLE_DIR/latency_max
137 grep -q -e "latency " $CAPTURE_FILE
138 check_err $? "Sampled packets not reported with latency when should"
140 echo 0 > $PSAMPLE_DIR/latency_max
143 grep -q -e "latency " $CAPTURE_FILE
144 check_fail $? "Sampled packets reported with latency when should not"
146 log_test "psample metadata"
148 echo 0 > $PSAMPLE_DIR/enable
153 modprobe netdevsim &> /dev/null
155 echo "$DEV_ADDR 1" > ${NETDEVSIM_PATH}/new_device
156 while [ ! -d $SYSFS_NET_DIR ] ; do :; done
161 devlink dev reload $DEVLINK_DEV netns testns1
171 echo "$DEV_ADDR" > ${NETDEVSIM_PATH}/del_device
172 modprobe -r netdevsim &> /dev/null