run_cpuctl_test.sh revision 9073840d951e26db57af6a14a10ff0dc006642c9
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., 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 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
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
54TEST_NUM=$1;            # To run the desired test (1 or 2)
55TASK_NUM=0;		# The serial number of a task
56TOTAL_TASKS=0;		# Total num of tasks in any test
57TASKS_IN_GROUP=0	# Total num of tasks in a group
58NICEVALUE=-20;		# Nice value to renice a task with
59SCRIPT_PID=$$;
60PWD=`pwd`
61cd $LTPROOT/testcases/bin/
62NUM_CPUS=`cat /proc/cpuinfo | grep -w processor | wc -l`
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 >> $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	"5" )
196		if [ -f cpuctl_test02 ]
197		then
198		echo `date` >> $LTPROOT/output/cpuctl_results_$FILE.txt;
199		echo `uname -a` >> $LTPROOT/output/cpuctl_results_$FILE.txt;
200		echo TEST:- $TEST_NAME $TEST_NUM >> $LTPROOT/output/cpuctl_results_$FILE.txt;
201		echo NUM_GROUPS=$NUM_GROUPS >> $LTPROOT/output/cpuctl_results_$FILE.txt;
202		TASKS_IN_GROUP=3;
203		for i in $(seq 1 $NUM_GROUPS)
204		do
205			MYGROUP=/dev/cpuctl/group_$i
206			for j in $(seq 1 $TASKS_IN_GROUP)
207			do
208			TASK_NUM=`expr $TASK_NUM + 1`;
209			cp cpuctl_test02 cpuctl_task_$TASK_NUM ;
210			chmod +x cpuctl_task_$TASK_NUM;
211
212			GROUP_NUM=$i MYGROUP=$MYGROUP SCRIPT_PID=$SCRIPT_PID NUM_CPUS=$NUM_CPUS \
213			TEST_NUM=$TEST_NUM TASK_NUM=$TASK_NUM ./cpuctl_task_$TASK_NUM \
214			>>$LTPROOT/output/cpuctl_results_$FILE.txt &
215			if [ $? -ne 0 ]
216			then
217				echo "Error: Could not run ./cpuctl_task_$TASK_NUM"
218				cleanup;
219				exit -1;
220			else
221				PID[$TASK_NUM]=$!;
222			fi;
223			j=`expr $j + 1`
224			done;		# end j loop
225			i=`expr $i + 1`
226		done;			# end i loop
227		else
228			echo "Source file not compiled..Plz check Makefile...Exiting test"
229			cleanup;
230			exit -1;
231		fi;
232		TOTAL_TASKS=$TASK_NUM;
233		;;
234	 *  )
235		echo "Could not start cpu controller test";
236		echo "usage: run_cpuctl_test.sh test_num";
237		echo "Skipping the test...";
238		exit -1;;
239	esac
240
241	sleep 3
242	echo TASKS FIRED
243	echo helloworld > myfifo;
244
245	#wait for the tasks to finish for cleanup and status report to pan
246	for i in $(seq 1 $TOTAL_TASKS)
247	do
248		wait ${PID[$i]};
249		RC=$?;	# Return status of the task being waited
250		# In abnormal termination of anyone trap will kill all others
251		# and they will return non zero exit status. So Test broke!!
252		if [ $RC -ne 0 ]
253		then
254			echo "Task $i exited abnormaly with return value: $RC";
255			tst_resm TINFO "Test could not execute for the expected duration";
256			cleanup;
257			exit -1;
258		fi
259	done
260	echo "Cpu controller test executed successfully.Results written to file";
261	echo "Please review the results in $LTPROOT/output/cpuctl_results_$FILE.txt"
262	cleanup;
263	cd $PWD
264	exit 0;		#to let PAN reprt success of test
265