• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# usage ./runcpuctl_stress_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_stress_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#               This same script can run 4 testcases depending on test number   #
29#               depending on the test number passed by the calling script.      #
30#                                                                               #
31# Test 06:      N X M (N groups with M tasks each)                              #
32# Test 07:      N*M X 1 (N*M groups with 1 task each)                           #
33# Test 08:      1 X N*M (1 group with N*M tasks)                                #
34# Test 09:      Heavy stress test with nice value change                        #
35# Test 10:      Heavy stress test (effect of heavy group on light group)        #
36#                                                                               #
37# Precaution:   Avoid system use by other applications/users to get fair and    #
38#               appropriate results                                             #
39#                                                                               #
40# Author:       Sudhir Kumar   <skumar@linux.vnet.ibm.com>                      #
41#                                                                               #
42# History:                                                                      #
43#                                                                               #
44#  DATE         NAME           EMAIL                         DESC               #
45#                                                                               #
46#  20/12/07  Sudhir Kumar <skumar@linux.vnet.ibm.com>   Created this test       #
47#                                                                               #
48#################################################################################
49
50
51export TCID="cpuctl_test06";
52export TST_TOTAL=4;
53export TST_COUNT=1;	# how to tell here ??
54
55RC=0;			# return code from functions
56NUM_CPUS=1;		# at least 1 cpu is there
57NUM_GROUPS=2;		# min number of groups
58TEST_NUM=$1;            # To run the desired test (1 or 2)
59TASK_NUM=0;		# The serial number of a task
60TOTAL_TASKS=0;		# Total num of tasks in any test
61TASKS_IN_GROUP=0;	# Total num of tasks in a group
62NICEVALUE=0;
63SCRIPT_PID=$$;
64FILE="stress-678";		# suffix for results file
65TEST_NAME="CPUCTL NUM_GROUPS vs NUM_TASKS TEST:";
66
67NUM_CPUS=`tst_ncpus`
68N=$NUM_CPUS;		# Default total num of groups (classes)
69M=10;			# Default total num of tasks in a group
70
71PWD=`pwd`
72cd $LTPROOT/testcases/bin/
73
74. parameters.sh
75
76usage ()
77{
78  	echo "Could not start cpu controller stress test";
79	echo "Check entry in file $LTPROOT/testcases/kernel/controllers/test_controllers.sh";
80	echo "usage: run_cpuctl_stress_test.sh test_num";
81	echo "Skipping the test...";
82	exit -1;
83}
84##########################  main   #######################
85		# For testcase 1, 2 & 3 N--> $NUM_CPUS
86		# 1,2 & 3 are not heavy stress test
87
88	case ${TEST_NUM} in
89
90	"6" )	# N X M (N groups with M tasks each)
91		if [ $N -eq 1 ]
92		then
93			N=2;	# Min 2 groups for group scheduling
94		fi;
95		NUM_GROUPS=$N;
96		TASKS_IN_GROUP=$M;
97		echo `date` >> $LTPROOT/output/cpuctl_results_$FILE.txt;
98		;;
99	"7" )   # N*M X 1 (N*M groups with 1 task each)
100		if [ $N -eq 1 ]
101		then
102			N=2;	# To keep total tasks same as in case 1
103		fi;
104		NUM_GROUPS=`expr $N \* $M`;
105		TASKS_IN_GROUP=1;
106		;;
107	"8" )	# 1 X N*M (1 group with N*M tasks)
108		if [ $N -eq 1 ]
109		then
110			N=2;	# To keep total tasks same as in case 1
111		fi;
112		NUM_GROUPS=1;
113		TASKS_IN_GROUP=`expr $N \* $M`;
114		;;
115	"9" )	# Heavy stress test
116		NUM_GROUPS=`expr $N \* $M`;
117		TASKS_IN_GROUP=`expr 1 \* $M`;
118		FILE="stress-9";
119		TEST_NAME="HEAVY STRESS TEST(RENICED):";
120		echo `date` >> $LTPROOT/output/cpuctl_results_$FILE.txt;
121		;;
122	"10" )	# Heavy stress test
123		NUM_GROUPS=2;
124		M=`expr $N \* 100`;
125		FILE="stress-10";
126		TEST_NAME="LIGHT GRP vs HEAVY GRP TEST:";
127		echo `date` >> $LTPROOT/output/cpuctl_results_$FILE.txt;
128		;;
129	  * )
130		usage;
131		;;
132	esac
133
134	echo "TEST $TEST_NUM: CPU CONTROLLER STRESS TESTING";
135	echo "RUNNING SETUP.....";
136	do_setup;
137
138	# Trap the signal from any abnormaly terminated task
139	# and kill all others and let cleanup be called
140	trap 'echo "signal caught from task"; killall cpuctl_task_*;' SIGUSR1;
141
142	echo "TEST STARTED: Please avoid using system while this test executes";
143	#Check if  c source  file has been compiled and then run it in different groups
144
145	case $TEST_NUM in
146
147	"6" | "7" | "8" )
148
149		if [ -f cpuctl_test03 ]
150		then
151		echo TEST NAME:- $TEST_NAME: $TEST_NUM >> $LTPROOT/output/cpuctl_results_$FILE.txt;
152		echo Test $TEST_NUM: NUM_GROUPS=$NUM_GROUPS +1 \(DEF\)>> $LTPROOT/output/cpuctl_results_$FILE.txt;
153		echo Test $TEST_NUM: TASKS PER GROUP=$TASKS_IN_GROUP >> $LTPROOT/output/cpuctl_results_$FILE.txt;
154		echo "==========================================" >> $LTPROOT/output/cpuctl_results_$FILE.txt;
155		for i in $(seq 1 $NUM_GROUPS)
156		do
157			MYGROUP=/dev/cpuctl/group_$i
158			for j in $(seq 1 $TASKS_IN_GROUP)
159			do
160			TASK_NUM=`expr $TASK_NUM + 1`;
161			cp cpuctl_test03 cpuctl_task_$TASK_NUM ;
162			chmod +x cpuctl_task_$TASK_NUM;
163
164			GROUP_NUM=$i MYGROUP=$MYGROUP SCRIPT_PID=$SCRIPT_PID NUM_CPUS=$NUM_CPUS \
165			TEST_NUM=$TEST_NUM TASK_NUM=$TASK_NUM ./cpuctl_task_$TASK_NUM \
166			>>$LTPROOT/output/cpuctl_results_$FILE.txt &
167			if [ $? -ne 0 ]
168			then
169				echo "Error: Could not run ./cpuctl_task_$TASK_NUM"
170				cleanup;
171				exit -1;
172			else
173				PID[$TASK_NUM]=$!;
174			fi;
175			j=`expr $j + 1`
176			done;		# end j loop
177			i=`expr $i + 1`
178		done;			# end i loop
179		else
180			echo "Source file not compiled..Plz check Makefile...Exiting test"
181			cleanup;
182			exit -1;
183		fi;
184		TOTAL_TASKS=$TASK_NUM;
185		# Run the default task in a default group
186		set_def_group;
187		if [ ! -f cpuctl_def_task03 ]; then
188			echo "Source file for default task not compiled";
189			echo "Plz check Makefile...Exiting test";
190			cleanup;
191			exit -1;
192		fi
193		MYGROUP=/dev/cpuctl/group_def ;
194		GROUP_NUM=0 MYGROUP=$MYGROUP SCRIPT_PID=$SCRIPT_PID \
195		NUM_CPUS=$NUM_CPUS TEST_NUM=$TEST_NUM TASK_NUM=0 \
196		./cpuctl_def_task03 >>$LTPROOT/output/cpuctl_results_$FILE.txt &
197		if [ $? -ne 0 ]
198		then
199			echo "Error: Could not run ./cpuctl_def_task03"
200			cleanup;
201			exit -1;
202		else
203			echo "Succesfully launched def task $! too";
204		fi
205		;;
206	"9" )
207
208		if [ -f cpuctl_test04 ]
209		then
210		echo TEST NAME:- $TEST_NAME: $TEST_NUM >> $LTPROOT/output/cpuctl_results_$FILE.txt;
211		echo NUM_GROUPS=$NUM_GROUPS +1 \(DEF\)>> $LTPROOT/output/cpuctl_results_$FILE.txt;
212		echo TASKS PER GROUP=$TASKS_IN_GROUP >> $LTPROOT/output/cpuctl_results_$FILE.txt;
213		echo "===============================" >> $LTPROOT/output/cpuctl_results_$FILE.txt;
214
215		# Create 4 priority windows
216		RANGE1=`expr $NUM_GROUPS / 4`;
217		RANGE2=`expr $RANGE1 + $RANGE1`;
218		RANGE3=`expr $RANGE2 + $RANGE1`;
219		for i in $(seq 1 $NUM_GROUPS)
220		do
221			MYGROUP=/dev/cpuctl/group_$i
222			for j in $(seq 1 $TASKS_IN_GROUP)
223			do
224			TASK_NUM=`expr $TASK_NUM + 1`;
225			cp cpuctl_test04 cpuctl_task_$TASK_NUM ;
226			chmod +x cpuctl_task_$TASK_NUM;
227
228			# Per group nice value change must not affect group/task fairness
229			if [ $i -le $RANGE1 ]
230			then
231				NICEVALUE=-16;
232			elif [ $i -gt $RANGE1 ] && [ $i -le $RANGE2 ]
233			then
234				NICEVALUE=-17;
235			elif [ $i -gt $RANGE2 ] && [ $i -le $RANGE3 ]
236			then
237				NICEVALUE=-18;
238			else
239				NICEVALUE=-19;
240			fi
241
242			GROUP_NUM=$i MYGROUP=$MYGROUP SCRIPT_PID=$SCRIPT_PID NUM_CPUS=$NUM_CPUS \
243			TEST_NUM=$TEST_NUM TASK_NUM=$TASK_NUM nice -n $NICEVALUE ./cpuctl_task_$TASK_NUM \
244			>>$LTPROOT/output/cpuctl_results_$FILE.txt &
245			if [ $? -ne 0 ]
246			then
247				echo "Error: Could not run ./cpuctl_task_$TASK_NUM"
248				cleanup;
249				exit -1;
250			else
251				PID[$TASK_NUM]=$!;
252			fi;
253			j=`expr $j + 1`
254			done;		# end j loop
255			i=`expr $i + 1`
256		done;			# end i loop
257		else
258			echo "Source file not compiled..Plz check Makefile...Exiting test"
259			cleanup;
260			exit -1;
261		fi;
262		TOTAL_TASKS=$TASK_NUM;
263
264		# Run the default task in a default group
265		set_def_group;
266		if [ ! -f cpuctl_def_task04 ]; then
267			echo "Source file for default task not compiled";
268			echo "Plz check Makefile...Exiting test";
269			cleanup;
270			exit -1;
271		fi
272		MYGROUP=/dev/cpuctl/group_def ;
273		GROUP_NUM=0 MYGROUP=$MYGROUP SCRIPT_PID=$SCRIPT_PID \
274		NUM_CPUS=$NUM_CPUS TEST_NUM=$TEST_NUM TASK_NUM=0 \
275		./cpuctl_def_task04 >>$LTPROOT/output/cpuctl_results_$FILE.txt &
276		if [ $? -ne 0 ]
277		then
278			echo "Error: Could not run ./cpuctl_def_task04"
279			cleanup;
280			exit -1;
281		else
282			echo "Succesfully launched def task $! too";
283		fi
284		;;
285	"10" )
286
287		if [ -f cpuctl_test04 ]
288		then
289		echo TEST NAME:- $TEST_NAME: $TEST_NUM >> $LTPROOT/output/cpuctl_results_$FILE.txt;
290		echo NUM_GROUPS=$NUM_GROUPS +1 \(DEF\)>> $LTPROOT/output/cpuctl_results_$FILE.txt;
291		echo TASKS PER GROUP=VARIABLE >> $LTPROOT/output/cpuctl_results_$FILE.txt;
292		echo "===============================" >> $LTPROOT/output/cpuctl_results_$FILE.txt;
293
294		for i in $(seq 1 $NUM_GROUPS)
295		do
296			MYGROUP=/dev/cpuctl/group_$i;
297			if [ $i -eq 1 ]
298			then
299				TASKS_IN_GROUP=$N;
300			else
301				TASKS_IN_GROUP=$M;
302			fi;
303			for j in $(seq 1 $TASKS_IN_GROUP)
304			do
305			TASK_NUM=`expr $TASK_NUM + 1`;
306			cp cpuctl_test04 cpuctl_task_$TASK_NUM ;
307			chmod +x cpuctl_task_$TASK_NUM;
308
309			GROUP_NUM=$i MYGROUP=$MYGROUP SCRIPT_PID=$SCRIPT_PID NUM_CPUS=$NUM_CPUS \
310			TEST_NUM=$TEST_NUM TASK_NUM=$TASK_NUM ./cpuctl_task_$TASK_NUM \
311			>>$LTPROOT/output/cpuctl_results_$FILE.txt &
312			if [ $? -ne 0 ]
313			then
314				echo "Error: Could not run ./cpuctl_task_$TASK_NUM"
315				cleanup;
316				exit -1;
317			else
318				PID[$TASK_NUM]=$!;
319			fi;
320			j=`expr $j + 1`
321			done;		# end j loop
322			i=`expr $i + 1`
323		done;			# end i loop
324		else
325			echo "Source file not compiled..Plz check Makefile...Exiting test"
326			cleanup;
327			exit -1;
328		fi;
329		TOTAL_TASKS=$TASK_NUM;
330
331		# Run the default task in a default group
332		set_def_group;
333		if [ ! -f cpuctl_def_task04 ]; then
334			echo "Source file for default task not compiled";
335			echo "Plz check Makefile...Exiting test";
336			cleanup;
337			exit -1;
338		fi
339		MYGROUP=/dev/cpuctl/group_def ;
340		GROUP_NUM=0 MYGROUP=$MYGROUP SCRIPT_PID=$SCRIPT_PID \
341		NUM_CPUS=$NUM_CPUS TEST_NUM=$TEST_NUM TASK_NUM=0 \
342		./cpuctl_def_task04 >>$LTPROOT/output/cpuctl_results_$FILE.txt &
343		if [ $? -ne 0 ]
344		then
345			echo "Error: Could not run ./cpuctl_def_task04"
346			cleanup;
347			exit -1;
348		else
349			echo "Succesfully launched def task $! too";
350		fi
351		;;
352	  * )
353		usage;
354		;;
355	esac
356
357	sleep 8
358	echo TASKS FIRED
359	echo helloworld > myfifo;
360
361	#wait for the tasks to finish for cleanup and status report to pan
362	for i in $(seq 1 $TOTAL_TASKS)
363	do
364		wait ${PID[$i]};
365		RC=$?;	# Return status of the task being waited
366		# In abnormal termination of anyone trap will kill all others
367		# and they will return non zero exit status. So Test broke!!
368		if [ $RC -ne 0 ]
369		then
370			echo "Task $i exited abnormaly with return value: $RC";
371			tst_resm TINFO "Test could not execute for the expected duration";
372			cleanup;
373			exit -1;
374		fi
375	done
376	echo "Cpu controller test executed successfully.Results written to file";
377	echo "Please review the results in $LTPROOT/output/cpuctl_results_$FILE.txt"
378	cleanup;
379	cd $PWD
380	exit 0;		#to let PAN reprt success of test
381