mirror of
https://github.com/torvalds/linux.git
synced 2024-11-29 23:51:37 +00:00
f20f064e84
Currently, some test scripts are experiencing minor errors related to executing tests. $ sudo ./test_cgrp2_sock.sh ./test_cgrp2_sock.sh: 22: test_cgrp2_sock: not found This problem occurs because the path to the execution target is not properly specified. Therefore, this commit solves this problem by specifying a relative path to its executables. This commit also makes a concise refactoring of hard-coded BPF program names. Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com> Link: https://lore.kernel.org/r/20230115071613.125791-3-danieltimlee@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
138 lines
2.9 KiB
Bash
Executable File
138 lines
2.9 KiB
Bash
Executable File
#!/bin/sh
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
# Test various socket options that can be set by attaching programs to cgroups.
|
|
|
|
MY_DIR=$(dirname $0)
|
|
TEST=$MY_DIR/test_cgrp2_sock
|
|
CGRP_MNT="/tmp/cgroupv2-test_cgrp2_sock"
|
|
|
|
################################################################################
|
|
#
|
|
print_result()
|
|
{
|
|
local rc=$1
|
|
local status=" OK "
|
|
|
|
[ $rc -ne 0 ] && status="FAIL"
|
|
|
|
printf "%-50s [%4s]\n" "$2" "$status"
|
|
}
|
|
|
|
check_sock()
|
|
{
|
|
out=$($TEST)
|
|
echo $out | grep -q "$1"
|
|
if [ $? -ne 0 ]; then
|
|
print_result 1 "IPv4: $2"
|
|
echo " expected: $1"
|
|
echo " have: $out"
|
|
rc=1
|
|
else
|
|
print_result 0 "IPv4: $2"
|
|
fi
|
|
}
|
|
|
|
check_sock6()
|
|
{
|
|
out=$($TEST -6)
|
|
echo $out | grep -q "$1"
|
|
if [ $? -ne 0 ]; then
|
|
print_result 1 "IPv6: $2"
|
|
echo " expected: $1"
|
|
echo " have: $out"
|
|
rc=1
|
|
else
|
|
print_result 0 "IPv6: $2"
|
|
fi
|
|
}
|
|
|
|
################################################################################
|
|
#
|
|
|
|
cleanup()
|
|
{
|
|
echo $$ >> ${CGRP_MNT}/cgroup.procs
|
|
rmdir ${CGRP_MNT}/sockopts
|
|
}
|
|
|
|
cleanup_and_exit()
|
|
{
|
|
local rc=$1
|
|
local msg="$2"
|
|
|
|
[ -n "$msg" ] && echo "ERROR: $msg"
|
|
|
|
$TEST -d ${CGRP_MNT}/sockopts
|
|
ip li del cgrp2_sock
|
|
umount ${CGRP_MNT}
|
|
|
|
exit $rc
|
|
}
|
|
|
|
|
|
################################################################################
|
|
# main
|
|
|
|
rc=0
|
|
|
|
ip li add cgrp2_sock type dummy 2>/dev/null
|
|
|
|
set -e
|
|
mkdir -p ${CGRP_MNT}
|
|
mount -t cgroup2 none ${CGRP_MNT}
|
|
set +e
|
|
|
|
|
|
# make sure we have a known start point
|
|
cleanup 2>/dev/null
|
|
|
|
mkdir -p ${CGRP_MNT}/sockopts
|
|
[ $? -ne 0 ] && cleanup_and_exit 1 "Failed to create cgroup hierarchy"
|
|
|
|
|
|
# set pid into cgroup
|
|
echo $$ > ${CGRP_MNT}/sockopts/cgroup.procs
|
|
|
|
# no bpf program attached, so socket should show no settings
|
|
check_sock "dev , mark 0, priority 0" "No programs attached"
|
|
check_sock6 "dev , mark 0, priority 0" "No programs attached"
|
|
|
|
# verify device is set
|
|
#
|
|
$TEST -b cgrp2_sock ${CGRP_MNT}/sockopts
|
|
if [ $? -ne 0 ]; then
|
|
cleanup_and_exit 1 "Failed to install program to set device"
|
|
fi
|
|
check_sock "dev cgrp2_sock, mark 0, priority 0" "Device set"
|
|
check_sock6 "dev cgrp2_sock, mark 0, priority 0" "Device set"
|
|
|
|
# verify mark is set
|
|
#
|
|
$TEST -m 666 ${CGRP_MNT}/sockopts
|
|
if [ $? -ne 0 ]; then
|
|
cleanup_and_exit 1 "Failed to install program to set mark"
|
|
fi
|
|
check_sock "dev , mark 666, priority 0" "Mark set"
|
|
check_sock6 "dev , mark 666, priority 0" "Mark set"
|
|
|
|
# verify priority is set
|
|
#
|
|
$TEST -p 123 ${CGRP_MNT}/sockopts
|
|
if [ $? -ne 0 ]; then
|
|
cleanup_and_exit 1 "Failed to install program to set priority"
|
|
fi
|
|
check_sock "dev , mark 0, priority 123" "Priority set"
|
|
check_sock6 "dev , mark 0, priority 123" "Priority set"
|
|
|
|
# all 3 at once
|
|
#
|
|
$TEST -b cgrp2_sock -m 666 -p 123 ${CGRP_MNT}/sockopts
|
|
if [ $? -ne 0 ]; then
|
|
cleanup_and_exit 1 "Failed to install program to set device, mark and priority"
|
|
fi
|
|
check_sock "dev cgrp2_sock, mark 666, priority 123" "Priority set"
|
|
check_sock6 "dev cgrp2_sock, mark 666, priority 123" "Priority set"
|
|
|
|
cleanup_and_exit $rc
|