• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #!/bin/bash
2 # usage ./runcpuctl_test.sh test_num
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA      #
20 #                                                                               #
21 #################################################################################
22 # Name Of File: run_cpuctl_test.sh                                              #
23 #                                                                               #
24 # Description: This file runs the setup for testing diff cpucontroller feature. #
25 #              After setup it runs diff test cases in diff setup.               #
26 #                                                                               #
27 # Test 01:     Tests fairness with respect to absolute share values             #
28 # Test 02:     Tests if fairness persists among different runs                  #
29 # Test 03:     Granularity test with respect to shares values                   #
30 # Test 04:     Nice value effect on group scheduling                            #
31 # Test 05:     Task migration test                                              #
32 #                                                                               #
33 # Precaution:   Avoid system use by other applications/users to get fair and    #
34 #               appropriate results                                             #
35 #                                                                               #
36 # Author:       Sudhir Kumar   <skumar@linux.vnet.ibm.com>                      #
37 #                                                                               #
38 # History:                                                                      #
39 #                                                                               #
40 #  DATE         NAME           EMAIL                         DESC               #
41 #                                                                               #
42 #  20/12/07  Sudhir Kumar <skumar@linux.vnet.ibm.com>   Created this test       #
43 #                                                                               #
44 #################################################################################
45 
46 
47 export TCID="cpuctl_test01";
48 export TST_TOTAL=1;
49 export TST_COUNT=1;
50 
51 RC=0;			# return code from functions
52 NUM_CPUS=1;		# at least 1 cpu is there
53 NUM_GROUPS=2;		# min number of groups
54 TEST_NUM=$1;            # To run the desired test (1 or 2)
55 TASK_NUM=0;		# The serial number of a task
56 TOTAL_TASKS=0;		# Total num of tasks in any test
57 TASKS_IN_GROUP=0	# Total num of tasks in a group
58 NICEVALUE=-20;		# Nice value to renice a task with
59 SCRIPT_PID=$$;
60 PWD=`pwd`
61 cd $LTPROOT/testcases/bin/
62 NUM_CPUS=`tst_ncpus`
63 
64 . parameters.sh
65 
66 ##########################  main   #######################
67 	case ${TEST_NUM} in
68 	"1" )	get_num_groups;	# contains test case 1 and 2
69 		TEST_NAME="FAIRNESS TEST:"
70 		FILE="12";
71 		;;
72 	"3" )   NUM_GROUPS=`expr 2 \* $NUM_CPUS`;
73 		TEST_NAME="GRANULARITY TEST:";
74 		FILE=$TEST_NUM;
75 		;;
76 	"4" )   NUM_GROUPS=$NUM_CPUS;
77 		TEST_NAME="NICE VALUE TEST:";
78 		FILE=$TEST_NUM;
79 		;;
80 	"5" )   NUM_GROUPS=$NUM_CPUS;
81 		TEST_NAME=" TASK MIGRATION TEST:";
82 		FILE=$TEST_NUM;
83 		;;
84 	 *  )  	echo "Could not start cpu controller test";
85 		echo "usage: run_cpuctl_test.sh test_num";
86 		echo "Skipping the test...";
87 		exit -1;;
88 	esac
89 	echo "TEST $TEST_NUM: CPU CONTROLLER TESTING";
90 	echo "RUNNING SETUP.....";
91 	do_setup;
92 
93 	# Trap the signal from any abnormaly terminated task
94 	# and kill all others and let cleanup be called
95 	trap 'echo "signal caught from task"; killall cpuctl_task_*;' SIGUSR1;
96 
97 	echo "TEST STARTED: Please avoid using system while this test executes";
98 	#Check if  c source  file has been compiled and then run it in different groups
99 
100 	case $TEST_NUM in
101 	"1" | "3" )
102 		if [ -f cpuctl_test01 ]
103 		then
104 		echo `date` >> $LTPROOT/output/cpuctl_results_$FILE.txt;
105 		echo `uname -a` >> $LTPROOT/output/cpuctl_results_$FILE.txt;
106 		echo TEST:- $TEST_NAME $TEST_NUM:  >> $LTPROOT/output/cpuctl_results_$FILE.txt;
107 		echo NUM_GROUPS=$NUM_GROUPS + 1\(DEF\) >> $LTPROOT/output/cpuctl_results_$FILE.txt;
108 		for i in $(seq 1 $NUM_GROUPS)
109 		do
110 			cp cpuctl_test01 cpuctl_task_$i ;
111 			chmod +x cpuctl_task_$i;
112 			./cpuctl_task_$i $i /dev/cpuctl/group_$i $$ $NUM_CPUS $TEST_NUM \
113 			 >>$LTPROOT/output/cpuctl_results_$FILE.txt &
114 			if [ $? -ne 0 ]
115 			then
116 				echo "Error: Could not run ./cpuctl_task_$i"
117 				cleanup;
118 				exit -1;
119 			else
120 				PID[$i]=$!;
121 			fi
122 		done
123 		else
124 			echo "Source file not compiled..Plz check Makefile...Exiting test"
125 			cleanup;
126 			exit -1;
127 		fi;
128 		i=`expr $i + 1`
129 
130 		TOTAL_TASKS=$NUM_GROUPS;
131 		# Run the default task in a default group
132 		set_def_group;
133 		if [ ! -f cpuctl_def_task01 ]; then
134 			echo "Source file for default task not compiled";
135 			echo "Plz check Makefile...Exiting test";
136 			cleanup;
137 			exit -1;
138 		fi
139 		./cpuctl_def_task01 $i /dev/cpuctl/group_def $$ $NUM_CPUS \
140 		$TEST_NUM  >>$LTPROOT/output/cpuctl_results_$FILE.txt &
141 		if [ $? -ne 0 ]
142 		then
143 			echo "Error: Could not run ./cpuctl_def_task01"
144 			cleanup;
145 			exit -1;
146 		else
147 			echo "Succesfully launched def task $! too";
148 		fi
149 		;;
150 	"4" )
151 		if [ -f cpuctl_test02 ]
152 		then
153 		echo `date` >> $LTPROOT/output/cpuctl_results_$FILE.txt;
154 		echo `uname -a` >> $LTPROOT/output/cpuctl_results_$FILE.txt;
155 		echo TEST:- $TEST_NAME $TEST_NUM >> $LTPROOT/output/cpuctl_results_$FILE.txt;
156 		echo NUM_GROUPS=$NUM_GROUPS +1 \(DEF\) >> $LTPROOT/output/cpuctl_results_$FILE.txt;
157 		for i in $(seq 1 $NUM_GROUPS)
158 		do
159 			MYGROUP=/dev/cpuctl/group_$i
160 			TASKS_IN_GROUP=`expr $i \* 2`;
161 			for j in $(seq 1 $TASKS_IN_GROUP)
162 			do
163 			TASK_NUM=`expr $TASK_NUM + 1`;
164 			cp cpuctl_test02 cpuctl_task_$TASK_NUM ;
165 			chmod +x cpuctl_task_$TASK_NUM;
166 			if [ $i -eq 1 ]	# Renice all tasks of group 1
167 			then
168 				NICELEVEL=$NICEVALUE;
169 			else
170 				NICELEVEL=0;
171 			fi;
172 
173 			GROUP_NUM=$i MYGROUP=$MYGROUP SCRIPT_PID=$SCRIPT_PID NUM_CPUS=$NUM_CPUS \
174 			TEST_NUM=$TEST_NUM TASK_NUM=$TASK_NUM nice -n $NICELEVEL ./cpuctl_task_$TASK_NUM \
175 			>>$LTPROOT/output/cpuctl_results_$FILE.txt &
176 			if [ $? -ne 0 ]
177 			then
178 				echo "Error: Could not run ./cpuctl_task_$TASK_NUM"
179 				cleanup;
180 				exit -1;
181 			else
182 				PID[$TASK_NUM]=$!;
183 			fi;
184 			j=`expr $j + 1`
185 			done;		# end j loop
186 			i=`expr $i + 1`
187 		done;			# end i loop
188 		else
189 			echo "Source file not compiled..Plz check Makefile...Exiting test"
190 			cleanup;
191 			exit -1;
192 		fi;
193 		TOTAL_TASKS=$TASK_NUM;
194 
195 		# Run the default task in a default group
196 		set_def_group;
197 		if [ ! -f cpuctl_def_task02 ]; then
198 			echo "Source file for default task not compiled";
199 			echo "Plz check Makefile...Exiting test";
200 			cleanup;
201 			exit -1;
202 		fi
203 		MYGROUP=/dev/cpuctl/group_def ;
204 		GROUP_NUM=0 MYGROUP=$MYGROUP SCRIPT_PID=$SCRIPT_PID \
205 		NUM_CPUS=$NUM_CPUS TEST_NUM=$TEST_NUM TASK_NUM=0 \
206 		./cpuctl_def_task02 >>$LTPROOT/output/cpuctl_results_$FILE.txt &
207 		if [ $? -ne 0 ]
208 		then
209 			echo "Error: Could not run ./cpuctl_def_task02"
210 			cleanup;
211 			exit -1;
212 		else
213 			echo "Succesfully launched def task $! too";
214 		fi
215 		;;
216 	"5" )
217 		if [ -f cpuctl_test02 ]
218 		then
219 		echo `date` >> $LTPROOT/output/cpuctl_results_$FILE.txt;
220 		echo `uname -a` >> $LTPROOT/output/cpuctl_results_$FILE.txt;
221 		echo TEST:- $TEST_NAME $TEST_NUM >> $LTPROOT/output/cpuctl_results_$FILE.txt;
222 		echo NUM_GROUPS=$NUM_GROUPS +1 \(DEF\)>> $LTPROOT/output/cpuctl_results_$FILE.txt;
223 		TASKS_IN_GROUP=3;
224 		for i in $(seq 1 $NUM_GROUPS)
225 		do
226 			MYGROUP=/dev/cpuctl/group_$i
227 			for j in $(seq 1 $TASKS_IN_GROUP)
228 			do
229 			TASK_NUM=`expr $TASK_NUM + 1`;
230 			cp cpuctl_test02 cpuctl_task_$TASK_NUM ;
231 			chmod +x cpuctl_task_$TASK_NUM;
232 
233 			GROUP_NUM=$i MYGROUP=$MYGROUP SCRIPT_PID=$SCRIPT_PID NUM_CPUS=$NUM_CPUS \
234 			TEST_NUM=$TEST_NUM TASK_NUM=$TASK_NUM ./cpuctl_task_$TASK_NUM \
235 			>>$LTPROOT/output/cpuctl_results_$FILE.txt &
236 			if [ $? -ne 0 ]
237 			then
238 				echo "Error: Could not run ./cpuctl_task_$TASK_NUM"
239 				cleanup;
240 				exit -1;
241 			else
242 				PID[$TASK_NUM]=$!;
243 			fi;
244 			j=`expr $j + 1`
245 			done;		# end j loop
246 			i=`expr $i + 1`
247 		done;			# end i loop
248 		else
249 			echo "Source file not compiled..Plz check Makefile...Exiting test"
250 			cleanup;
251 			exit -1;
252 		fi;
253 		TOTAL_TASKS=$TASK_NUM;
254 
255 		# Run the default task in a default group
256 		set_def_group;
257 		if [ ! -f cpuctl_def_task02 ]; then
258 			echo "Source file for default task not compiled";
259 			echo "Plz check Makefile...Exiting test";
260 			cleanup;
261 			exit -1;
262 		fi
263 		MYGROUP=/dev/cpuctl/group_def ;
264 		GROUP_NUM=0 MYGROUP=$MYGROUP SCRIPT_PID=$SCRIPT_PID \
265 		NUM_CPUS=$NUM_CPUS TEST_NUM=$TEST_NUM TASK_NUM=0 \
266 		./cpuctl_def_task02 >>$LTPROOT/output/cpuctl_results_$FILE.txt &
267 		if [ $? -ne 0 ]
268 		then
269 			echo "Error: Could not run ./cpuctl_def_task02"
270 			cleanup;
271 			exit -1;
272 		else
273 			echo "Succesfully launched def task $! too";
274 		fi
275 		;;
276 
277 	 *  )
278 		echo "Could not start cpu controller test";
279 		echo "usage: run_cpuctl_test.sh test_num";
280 		echo "Skipping the test...";
281 		exit -1;;
282 	esac
283 
284 	sleep 3
285 	echo TASKS FIRED
286 	echo helloworld > myfifo;
287 
288 	#wait for the tasks to finish for cleanup and status report to pan
289 	for i in $(seq 1 $TOTAL_TASKS)
290 	do
291 		wait ${PID[$i]};
292 		RC=$?;	# Return status of the task being waited
293 		# In abnormal termination of anyone trap will kill all others
294 		# and they will return non zero exit status. So Test broke!!
295 		if [ $RC -ne 0 ]
296 		then
297 			echo "Task $i exited abnormaly with return value: $RC";
298 			tst_resm TINFO "Test could not execute for the expected duration";
299 			cleanup;
300 			exit -1;
301 		fi
302 	done
303 	echo "Cpu controller test executed successfully.Results written to file";
304 	echo "Please review the results in $LTPROOT/output/cpuctl_results_$FILE.txt"
305 	cleanup;
306 	cd $PWD
307 	exit 0;		#to let PAN reprt success of test
308