1#!/bin/sh 2 3################################################################################ 4## ## 5## Copyright (c) 2009 FUJITSU LIMITED ## 6## Author: Shi Weihua <shiwh@cn.fujitsu.com> ## 7## Copyright (c) 2015 Cedric Hnyda <chnyda@suse.com> ## 8## Copyright (c) 2015-2016 Cyril Hrubis <chrubis@suse.cz> ## 9## ## 10## This program is free software; you can redistribute it and#or modify ## 11## it under the terms of the GNU General Public License as published by ## 12## the Free Software Foundation; either version 2 of the License, or ## 13## (at your option) any later version. ## 14## ## 15## This program is distributed in the hope that it will be useful, but ## 16## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## 17## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## 18## for more details. ## 19## ## 20## You should have received a copy of the GNU General Public License ## 21## along with this program; if not, write to the Free Software Foundation, ## 22## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ## 23## ## 24################################################################################ 25 26for arg; do 27 TCID="${TCID}_$arg" 28done 29 30. test.sh 31 32exist_subsystem() 33{ 34 local subsystem="$1" 35 local exist=`grep -w $subsystem /proc/cgroups | cut -f1` 36 37 if [ "$exist" = "" ]; then 38 tst_brkm TCONF "Subsystem $subsystem not supported" 39 fi 40} 41 42attach_and_check() 43{ 44 local pid="$1" 45 local path="$2" 46 local task 47 shift 48 49 tst_resm TINFO "Attaching task $pid to $path" 50 51 ROD echo "$pid" \> "$path/tasks" 52 53 for task in $(cat "$path/tasks"); do 54 if [ "$task" -ne "$pid" ]; then 55 tst_resm TINFO "Unexpected pid $task in $path/tasks, expected $pid" 56 return 1 57 fi 58 done 59 60 return 0 61} 62 63create_subgroup() 64{ 65 path="$1" 66 67 ROD mkdir "$path" 68 69 # cpuset.cpus and cpuset.mems must be initialized with suitable value 70 # before any pids are attached 71 if [ "$subsystem" == "cpuset" ]; then 72 ROD cat "$mount_point/cpuset.cpus" \> "$path/cpuset.cpus" 73 ROD cat "$mount_point/cpuset.mems" \> "$path/cpuset.mems" 74 fi 75} 76 77 78setup() 79{ 80 tst_require_root 81 82 if [ ! -f /proc/cgroups ]; then 83 tst_brkm TCONF "Kernel does not support for control groups" 84 fi 85 86 exist_subsystem "$subsystem" 87 88 tst_tmpdir 89 TST_CLEANUP=cleanup 90 91 mount_point=`grep -w $subsystem /proc/mounts | cut -f 2 | cut -d " " -f2` 92 93 if [ "$mount_point" == "" ]; then 94 try_umount=1 95 mount_point="/dev/cgroup" 96 tst_resm TINFO "Subsystem $subsystem is not mounted, mounting it at $mount_point" 97 ROD mkdir $mount_point 98 ROD mount -t cgroup -o "$subsystem" "ltp_cgroup" "$mount_point" 99 else 100 tst_resm TINFO "Subsystem $subsystem is mounted at $mount_point" 101 fi 102} 103 104cleanup() 105{ 106 tst_rmdir 107 108 killall -9 cgroup_fj_proc >/dev/null 2>&1 109 110 tst_resm TINFO "Removing all ltp subgroups..." 111 112 find "$mount_point/ltp/" -depth -type d -exec rmdir '{}' \; 113 114 if [ -z "$try_umount" ]; then 115 return 116 fi 117 118 if grep -q "$mount_point" /proc/mounts; then 119 umount "$mount_point" 120 fi 121 122 if [ -e "$mount_point" ]; then 123 rmdir "$mount_point" 124 fi 125} 126