[LTP] [PATCH v2 14/16] controllers: Update pids.sh to use newer cgroup lib
Luke Nowakowski-Krijger
luke.nowakowskikrijger@canonical.com
Sat Mar 5 00:18:24 CET 2022
Updated to use the newer cgroup_lib to make mounting and cleanup
nicer.
Signed-off-by: Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com>
---
v2: Use version number 2 instead of v2
testcases/kernel/controllers/pids/pids.sh | 67 +++--------------------
1 file changed, 9 insertions(+), 58 deletions(-)
diff --git a/testcases/kernel/controllers/pids/pids.sh b/testcases/kernel/controllers/pids/pids.sh
index a3d644eff..ffde41df0 100755
--- a/testcases/kernel/controllers/pids/pids.sh
+++ b/testcases/kernel/controllers/pids/pids.sh
@@ -13,7 +13,7 @@ TST_USAGE=usage
TST_NEEDS_ROOT=1
TST_NEEDS_CMDS="killall"
-. tst_test.sh
+. cgroup_lib.sh
caseno=$1
max=$2
@@ -38,66 +38,17 @@ cleanup()
{
killall -9 pids_task2 >/dev/null 2>&1
- tst_res TINFO "removing created directories"
- rmdir $testpath
- if [ "$mounted" -ne "1" ]; then
- tst_res TINFO "Umounting pids"
- umount $mount_point
- rmdir $mount_point
- fi
-}
-
-setup_cgroupv2()
-{
- mount_point=$(grep -w cgroup2 /proc/mounts | cut -f 2 | cut -d " " -f2)
- if ! grep -q pids "$mount_point"/cgroup.controllers; then
- tst_res TINFO "pids not supported on cgroup v2."
- return
- fi
-
- testpath="$mount_point/ltp_pids_$caseno"
- ROD mkdir -p "$testpath"
- task_list="cgroup.procs"
- cgroup_v="v2"
-}
-
-setup_cgroupv1()
-{
- exist=`grep -w pids /proc/cgroups | cut -f1`;
- if [ "$exist" = "" ]; then
- tst_brk TCONF NULL "pids not supported"
- fi
-
- mount_point=`grep -w pids /proc/mounts | cut -f 2 | cut -d " " -f2`
-
- if [ "$mount_point" = "" ]; then
- mounted=0
- mount_point=/dev/cgroup
- fi
-
- testpath=$mount_point/ltp_pids_$caseno
-
- if [ "$mounted" -eq "0" ]; then
- ROD mkdir -p $mount_point
- ROD mount -t cgroup -o pids none $mount_point
- fi
- ROD mkdir -p $testpath
- task_list="tasks"
- cgroup_v="v1"
+ cgroup_cleanup
}
setup()
{
- # If cgroup2 is mounted already, then let's
- # try to start with cgroup v2.
- if grep -q cgroup2 /proc/mounts; then
- setup_cgroupv2
- fi
- if [ -z "$cgroup_v" ]; then
- setup_cgroupv1
- fi
+ cgroup_require "pids"
+ cgroup_version=$(cgroup_get_version "pids")
+ testpath=$(cgroup_get_test_path "pids")
+ task_list=$(cgroup_get_task_list "pids")
- tst_res TINFO "test starts with cgroup $cgroup_v"
+ tst_res TINFO "test starts with cgroup version $cgroup_version"
}
start_pids_tasks2()
@@ -298,7 +249,7 @@ case8()
{
tst_res TINFO "set child cgroup limit smaller than its parent limit"
ROD echo $max \> $testpath/pids.max
- if [ "$cgroup_v" = "v2" ]; then
+ if [ "$cgroup_version" = "2" ]; then
ROD echo +pids \> "$testpath"/cgroup.subtree_control
fi
mkdir $testpath/child
@@ -328,7 +279,7 @@ case9()
tst_res TINFO "migrate cgroup"
lim=$((max - 1))
- if [ "$cgroup_v" = "v2" ]; then
+ if [ "$cgroup_version" = "2" ]; then
ROD echo +pids \> "$testpath"/cgroup.subtree_control
fi
for i in 1 2; do
--
2.32.0
More information about the ltp
mailing list