tools/testing/selftests/drivers/net/netdevsim/psample.sh

Source file repositories/reference/linux-study-clean/tools/testing/selftests/drivers/net/netdevsim/psample.sh

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/drivers/net/netdevsim/psample.sh
Extension
.sh
Size
4114 bytes
Lines
184
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: tools
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
#
# This test is for checking the psample module. It makes use of netdevsim
# which periodically generates "sampled" packets.

lib_dir=$(dirname $0)/../../../net/forwarding

ALL_TESTS="
	psample_enable_test
	psample_group_num_test
	psample_md_test
"
NETDEVSIM_PATH=/sys/bus/netdevsim/
DEV_ADDR=1337
DEV=netdevsim${DEV_ADDR}
SYSFS_NET_DIR=/sys/bus/netdevsim/devices/$DEV/net/
PSAMPLE_DIR=/sys/kernel/debug/netdevsim/$DEV/psample/
CAPTURE_FILE=$(mktemp)
NUM_NETIFS=0
source $lib_dir/lib.sh

DEVLINK_DEV=
source $lib_dir/devlink_lib.sh
DEVLINK_DEV=netdevsim/${DEV}

# Available at https://github.com/Mellanox/libpsample
require_command psample

psample_capture()
{
	rm -f $CAPTURE_FILE

	timeout 2 ip netns exec testns1 psample &> $CAPTURE_FILE
}

psample_enable_test()
{
	RET=0

	echo 1 > $PSAMPLE_DIR/enable
	check_err $? "Failed to enable sampling when should not"

	echo 1 > $PSAMPLE_DIR/enable 2>/dev/null
	check_fail $? "Sampling enablement succeeded when should fail"

	psample_capture
	if [ $(cat $CAPTURE_FILE | wc -l) -eq 0 ]; then
		check_err 1 "Failed to capture sampled packets"
	fi

	echo 0 > $PSAMPLE_DIR/enable
	check_err $? "Failed to disable sampling when should not"

	echo 0 > $PSAMPLE_DIR/enable 2>/dev/null
	check_fail $? "Sampling disablement succeeded when should fail"

	psample_capture
	if [ $(cat $CAPTURE_FILE | wc -l) -ne 0 ]; then
		check_err 1 "Captured sampled packets when should not"
	fi

	log_test "psample enable / disable"
}

psample_group_num_test()
{
	RET=0

	echo 1234 > $PSAMPLE_DIR/group_num

Annotation

Implementation Notes