run_cpuctl_test.sh revision 6b78bd97ae956c84863ab786cb34f5ce592d2300
1#!/bin/bash 2# usage ./runcpuctl_test.sh 3 4################################################################################# 5# Copyright (c) International Business Machines Corp., 2007 # 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, # 13# but WITHOUT ANY WARRANTY; without even the implied warranty of # 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See # 15# the GNU General Public License 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # 20# # 21################################################################################# 22# Name Of File: run_cpuctl_test.sh # 23# # 24# Description: This file runs the setup for testing cpucontroller. # 25# After setup it runs some of the tasks in different groups. # 26# setup includes creating controller device, mounting it with # 27# cgroup filesystem with option cpu and creating groups in it. # 28# # 29# Functions: get_num_groups(): decides number of groups based on num of cpus # 30# setup(): creaes /dev/cpuctl, mounts cgroup fs on it, creates # 31# groups in that, creates fifo to fire tasks at one time. # 32# # 33# Precaution: Avoid system use by other applications/users to get fair and # 34# appropriate results # 35# # 36# Author: Sudhir Kumar <sudhirkumarmalik@In.ibm.com> # 37# # 38# History: # 39# # 40# DATE NAME EMAIL DESC # 41# # 42# 20/12/07 Sudhir Kumar <sudhirkumarmalik@in.ibm.com> Created this test # 43# # 44################################################################################# 45 46 47export TCID="cpuctl_test01"; 48export TST_TOTAL=1; 49export TST_COUNT=1; 50 51RC=0; # return code from functions 52NUM_CPUS=1; # at least 1 cpu is there 53NUM_GROUPS=2; # min number of groups 54 55PWD=`pwd` 56cd $LTPROOT/testcases/bin/ 57 58get_num_groups() # Number of tasks should be >= number of cpu's (to check scheduling fairness) 59{ 60 NUM_CPUS=`cat /proc/cpuinfo | grep -w processor | wc -l` 61 num_grps=$(echo "$NUM_CPUS * 1.5"|bc) # temp variable num_grps 62 int_part=`echo $num_grps | cut -d"." -f1` 63 dec_part=`echo $num_grps | cut -d"." -f2` 64 65 if [ $dec_part -gt 0 ] 66 then 67 NUM_GROUPS=$(echo "$int_part + 1"|bc) 68 else 69 NUM_GROUPS=$int_part; 70 fi 71} 72 73# Write the cleanup function 74cleanup () 75{ 76 echo "Cleanup called" 77 rm -f cpuctl_task_* 2>/dev/null 78 rmdir /dev/cpuctl/group_* 2> /dev/null 79 umount /dev/cpuctl 2> /dev/null 80 rmdir /dev/cpuctl 2> /dev/null 81 rm -f myfifo 2>/dev/null 82 83} 84 # Create /dev/cpuctl & mount the cgroup file system with cpu controller 85 #clean any group created eralier (if any) 86 87setup () 88{ 89 if [ -e /dev/cpuctl ] 90 then 91 echo "WARN:/dev/cpuctl already exist..overwriting"; # or a warning ? 92 cleanup; 93 mkdir /dev/cpuctl; 94 else 95 mkdir /dev/cpuctl 96 fi 97 mount -t cgroup -ocpu cgroup /dev/cpuctl 2> /dev/null 98 if [ $? -ne 0 ] 99 then 100 echo "ERROR: Could not mount cgroup filesystem on /dev/cpuctl..Exiting test"; 101 cleanup; 102 exit -1; 103 fi 104 105 # Group created earlier may again be visible if not cleaned properly...so clean them 106 if [ -e /dev/cpuctl/group_1 ] 107 then 108 rmdir /dev/cpuctl/group* 109 echo "WARN: Earlier groups found and removed..."; 110 fi 111 112 #Create a fifo to make all tasks wait on it 113 mkfifo myfifo 2> /dev/null; 114 if [ $? -ne 0 ] 115 then 116 echo "ERROR: Can't create fifo...Check your permissions..Exiting test"; 117 cleanup; 118 exit -1; 119 fi 120 121 # Create different groups 122 i=1; 123 while [ $i -le $NUM_GROUPS ] 124 do 125 group=group_$i; 126 mkdir /dev/cpuctl/$group;# 2>/dev/null 127 if [ $? -ne 0 ] 128 then 129 echo "ERROR: Can't create $group...Check your permissions..Exiting test"; 130 cleanup; 131 exit -1; 132 fi 133 i=`expr $i + 1` 134 done 135} 136 137########################## main ####################### 138 echo "TEST: CPU CONTROLLER TESTING"; 139 echo "RUNNING SETUP....."; 140 get_num_groups; 141 if [ $NUM_GROUPS -lt 2 ] 142 then 143 NUM_GROUPS=2; # min num of groups for testing 144 fi 145 146 setup; 147 148 # Trap the signal from any abnormaly terminated task 149 # and kill all others and let cleanup be called 150 trap 'echo "signal caught from task"; killall cpuctl_task_*;' SIGUSR1; 151 152 echo "TEST STARTED: Please avoid using system while this test executes"; 153 #Check if c source file has been compiled and then run it in different groups 154 if [ -f cpuctl_test01 ] 155 then 156 echo `date` >> $LTPROOT/output/cpuctl_results.txt; 157 for i in $(seq 1 $NUM_GROUPS) 158 do 159 cp cpuctl_test01 cpuctl_task_$i 2>/dev/null; 160 chmod +x cpuctl_task_$i; 161 ./cpuctl_task_$i $i /dev/cpuctl/group_$i $$ $NUM_CPUS >>$LTPROOT/output/cpuctl_results.txt 2>/dev/null & 162 if [ $? -ne 0 ] 163 then 164 echo "Error: Could not run ./cpuctl_task_$i" 165 cleanup; 166 exit -1; 167 else 168 PID[$i]=$!; 169 fi 170 i=`expr $i + 1` 171 done 172 else 173 echo "Source file not compiled..Plz check Makefile...Exiting test" 174 cleanup; 175 exit -1; 176 fi 177 sleep 3 178 echo TASKS FIRED 179 echo helloworld > myfifo; 180 181 #wait for the tasks to finish for cleanup and status report to pan 182 for i in $(seq 1 $NUM_GROUPS) 183 do 184 wait ${PID[$i]}; 185 RC=$?; # Return status of the task being waited 186 # In abnormal termination of anyone trap will kill all others 187 # and they will return non zero exit status. So Test broke!! 188 if [ $RC -ne 0 ] 189 then 190 echo "Task $i exited abnormalywith return value: $RC"; 191 tst_resm TINFO "Test could not execute for the expected duration"; 192 cleanup; 193 exit -1; 194 fi 195 done 196 echo "Cpu controller test executed successfully.Results written to file"; 197 echo "Please review the results in $LTPROOT/output/cpuctl_results.txt" 198 cleanup; 199 cd $PWD 200 exit 0; #to let PAN reprt success of test 201