1#!/bin/sh 2 3################################################################################ 4## ## 5## Copyright (c) 2015 SUSE ## 6## ## 7## This program is free software; you can redistribute it and#or modify ## 8## it under the terms of the GNU General Public License as published by ## 9## the Free Software Foundation; either version 2 of the License, or ## 10## (at your option) any later version. ## 11## ## 12## This program is distributed in the hope that it will be useful, but ## 13## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## 14## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## 15## for more details. ## 16## ## 17## You should have received a copy of the GNU General Public License ## 18## along with this program; if not, write to the Free Software ## 19## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 ## 20## USA ## 21## ## 22## Author: Cedric Hnyda <chnyda@suse.com> ## 23## ## 24################################################################################ 25 26# Usage 27# ./cpuacct.sh nbsubgroup nbprocess 28# 29# 1) nbsubgroup : number of subgroup to create 30# 2) nbprocess : number of process to attach to each subgroup 31# 32# Description 33# 34# 1) Find if cpuacct is mounted, if not mounted, cpuacct will be mounted 35# 2) Check that sum ltp_test/subgroup*/cpuacct.usage = ltp_test/cpuacct.usage 36# 37 38TST_SETUP=setup 39TST_CLEANUP=cleanup 40TST_TESTFUNC=do_test 41TST_POS_ARGS=2 42TST_USAGE=usage 43TST_NEEDS_ROOT=1 44TST_NEEDS_TMPDIR=1 45 46. tst_test.sh 47 48mounted=1 49max=$1 50nbprocess=$2 51 52usage() 53{ 54 cat << EOF 55usage: $0 nsubgroup nprocess 56 57nsubgroup - number of subgroups to create 58nprocess - number of processes to attach to each subgroup 59 60OPTIONS 61EOF 62} 63 64setup() 65{ 66 if ! grep -q -w cpuacct /proc/cgroups; then 67 tst_brk TCONF "cpuacct not supported on this system" 68 fi 69 70 mount_point=`grep -w cpuacct /proc/mounts | cut -f 2 | cut -d " " -f2` 71 tst_res TINFO "cpuacct: $mount_point" 72 if [ "$mount_point" = "" ]; then 73 mounted=0 74 mount_point=/dev/cgroup 75 fi 76 77 testpath=$mount_point/ltp_$TST_ID 78 79 if [ "$mounted" -eq "0" ]; then 80 ROD mkdir -p $mount_point 81 ROD mount -t cgroup -o cpuacct none $mount_point 82 fi 83 84 ROD mkdir $testpath 85 86 # create subgroups 87 for i in `seq 1 $max`; do 88 ROD mkdir $testpath/subgroup_$i 89 done 90 91} 92 93cleanup() 94{ 95 tst_res TINFO "removing created directories" 96 97 if [ -d "$testpath/subgroup_1" ]; then 98 rmdir $testpath/subgroup_* 99 fi 100 101 rmdir $testpath 102 103 if [ "$mounted" -ne 1 ]; then 104 tst_res TINFO "Umounting cpuacct" 105 umount $mount_point 106 rmdir $mount_point 107 fi 108} 109 110do_test() 111{ 112 tst_res TINFO "Creating $max subgroups each with $nbprocess processes" 113 114 # create and attach process to subgroups 115 for i in `seq 1 $max`; do 116 for j in `seq 1 $nbprocess`; do 117 cpuacct_task $testpath/subgroup_$i/tasks & 118 echo $! >> task_pids 119 done 120 done 121 122 for pid in $(cat task_pids); do wait $pid; done 123 rm -f task_pids 124 125 acc=0 126 fails=0 127 for i in `seq 1 $max`; do 128 tmp=`cat $testpath/subgroup_$i/cpuacct.usage` 129 if [ "$tmp" -eq "0" ]; then 130 fails=$((fails + 1)) 131 fi 132 acc=$((acc + tmp)) 133 done 134 135 ## check that cpuacct.usage != 0 for every subgroup 136 if [ "$fails" -gt "0" ]; then 137 tst_res TFAIL "cpuacct.usage is not equal to 0 for $fails subgroups" 138 else 139 tst_res TPASS "cpuacct.usage is not equal to 0 for every subgroup" 140 fi 141 142 ## check that ltp_subgroup/cpuacct.usage == sum ltp_subgroup/subgroup*/cpuacct.usage 143 ref=`cat $testpath/cpuacct.usage` 144 if [ "$ref" -ne "$acc" ]; then 145 tst_res TFAIL "cpuacct.usage $ref not equal to subgroup*/cpuacct.usage $acc" 146 else 147 tst_res TPASS "cpuacct.usage equal to subgroup*/cpuacct.usage" 148 fi 149} 150 151tst_run 152