1 #!/bin/sh 2 3 ################################################################################ 4 ## ## 5 ## Copyright (c) 2009 FUJITSU LIMITED ## 6 ## Author: Shi Weihua <shiwh (at] cn.fujitsu.com> ## 7 ## Copyright (c) 2015 Cedric Hnyda <chnyda (at] suse.com> ## 8 ## Copyright (c) 2015-2016 Cyril Hrubis <chrubis (at] 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 26 TCID="cgroup_fj_stress" 27 TST_TOTAL=1 28 29 . cgroup_fj_common.sh 30 31 subsystem="$1" 32 subgroup_num="$2" 33 subgroup_depth="$3" 34 attach_operation="$4" 35 36 usage_and_exit() 37 { 38 echo "usage of cgroup_fj_stress.sh: " 39 echo " ./cgroup_fj_stress.sh subsystem subgroup_num subgroup_depth attach_operation" 40 echo " subgroup_num" 41 echo " number of subgroups created in group" 42 echo " subgroup_depth" 43 echo " depth of the created tree" 44 echo " attach_operation" 45 echo " none - do not attach anything" 46 echo " one - move one processe around" 47 echo " each - attach process to each subgroup" 48 echo "example: ./cgroup_fj_stress.sh cpuset 1 1 one" 49 echo 50 tst_brkm TBROK "$1" 51 } 52 53 if [ "$#" -ne "4" ]; then 54 usage_and_exit "Wrong number of parameters, expected 4" 55 fi 56 57 case $subgroup_num in 58 ''|*[!0-9]*) usage_and_exit "Number of subgroups must be possitive integer";; 59 *) ;; 60 esac 61 62 case $subgroup_depth in 63 ''|*[!0-9]*) usage_and_exit "Depth of the subgroup tree must be possitive integer";; 64 *) ;; 65 esac 66 67 case $attach_operation in 68 'none'|'one'|'each');; 69 *) usage_and_exit "Invalid attach operation: $attach_operation";; 70 esac 71 72 setup 73 74 export TMPFILE=./tmp_tasks.$$ 75 76 count=0 77 78 build_subgroups() 79 { 80 local cur_path="$1" 81 local cur_depth="$2" 82 local i 83 84 if [ "$cur_depth" -gt "$subgroup_depth" ]; then 85 return 86 fi 87 88 create_subgroup "$cur_path" 89 count=$((count+1)) 90 91 for i in $(seq 1 $subgroup_num); do 92 build_subgroups "$cur_path/$i" $((cur_depth+1)) 93 done 94 } 95 96 attach_task() 97 { 98 local cur_path="$1" 99 local cur_depth="$2" 100 local ppid="$3" 101 local i 102 103 if [ "$cur_depth" -gt "$subgroup_depth" ]; then 104 return 105 fi 106 107 if [ -z "$ppid" ]; then 108 cgroup_fj_proc& 109 pid=$! 110 else 111 pid="$ppid" 112 fi 113 114 if ! attach_and_check "$pid" "$cur_path"; then 115 fail=1 116 fi 117 118 for i in $(seq 1 $subgroup_num); do 119 local new_path="$cur_path/$i" 120 attach_task "$new_path" $((cur_depth+1)) "$ppid" 121 done 122 123 if [ -n "$ppid" ]; then 124 if ! attach_and_check "$pid" "$cur_path"; then 125 fail=1 126 fi 127 fi 128 } 129 130 start_path="$mount_point/ltp" 131 132 tst_resm TINFO "Creating subgroups ..." 133 134 build_subgroups "$start_path" 0 135 136 tst_resm TINFO "... mkdired $count times" 137 138 case $attach_operation in 139 "one" ) 140 cgroup_fj_proc & 141 pid=$! 142 143 tst_resm TINFO "Moving one task around" 144 attach_task "$start_path" 0 "$pid" 145 ROD kill -9 "$pid" 146 wait "$pid" 147 ;; 148 "each" ) 149 tst_resm TINFO "Attaching task to each subgroup" 150 attach_task "$start_path" 0 151 ROD killall -9 "cgroup_fj_proc" 152 # Wait for attached tasks to terminate 153 wait 154 ;; 155 * ) 156 ;; 157 esac 158 159 if [ -n "$fail" ]; then 160 tst_resm TFAIL "Attaching tasks failed!" 161 else 162 tst_resm TPASS "All done!" 163 fi 164 165 tst_exit 166