run_cpuctl_test.sh revision 2557afd4238c16f16876c8e789d9f2b584e0153e
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	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 >> $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			i=`expr $i + 1`
123		done
124		else
125			echo "Source file not compiled..Plz check Makefile...Exiting test"
126			cleanup;
127			exit -1;
128		fi;
129		TOTAL_TASKS=$NUM_GROUPS;
130		;;
131	"4" )
132		if [ -f cpuctl_test02 ]
133		then
134		echo `date` >> $LTPROOT/output/cpuctl_results_$FILE.txt;
135		echo `uname -a` >> $LTPROOT/output/cpuctl_results_$FILE.txt;
136		echo TEST:- $TEST_NAME $TEST_NUM >> $LTPROOT/output/cpuctl_results_$FILE.txt;
137		echo NUM_GROUPS=$NUM_GROUPS >> $LTPROOT/output/cpuctl_results_$FILE.txt;
138		for i in $(seq 1 $NUM_GROUPS)
139		do
140			MYGROUP=/dev/cpuctl/group_$i
141			TASKS_IN_GROUP=`expr $i \* 2`;
142			for j in $(seq 1 $TASKS_IN_GROUP)
143			do
144			TASK_NUM=`expr $TASK_NUM + 1`;
145			cp cpuctl_test02 cpuctl_task_$TASK_NUM ;
146			chmod +x cpuctl_task_$TASK_NUM;
147			if [ $i -eq 1 ]	# Renice all tasks of group 1
148			then
149				NICELEVEL=$NICEVALUE;
150			else
151				NICELEVEL=0;
152			fi;
153
154			GROUP_NUM=$i MYGROUP=$MYGROUP SCRIPT_PID=$SCRIPT_PID NUM_CPUS=$NUM_CPUS \
155			TEST_NUM=$TEST_NUM TASK_NUM=$TASK_NUM nice -n $NICELEVEL ./cpuctl_task_$TASK_NUM \
156			>>$LTPROOT/output/cpuctl_results_$FILE.txt &
157			if [ $? -ne 0 ]
158			then
159				echo "Error: Could not run ./cpuctl_task_$TASK_NUM"
160				cleanup;
161				exit -1;
162			else
163				PID[$TASK_NUM]=$!;
164			fi;
165			j=`expr $j + 1`
166			done;		# end j loop
167			i=`expr $i + 1`
168		done;			# end i loop
169		else
170			echo "Source file not compiled..Plz check Makefile...Exiting test"
171			cleanup;
172			exit -1;
173		fi;
174		TOTAL_TASKS=$TASK_NUM;
175		;;
176	"5" )
177		if [ -f cpuctl_test02 ]
178		then
179		echo `date` >> $LTPROOT/output/cpuctl_results_$FILE.txt;
180		echo `uname -a` >> $LTPROOT/output/cpuctl_results_$FILE.txt;
181		echo TEST:- $TEST_NAME $TEST_NUM >> $LTPROOT/output/cpuctl_results_$FILE.txt;
182		echo NUM_GROUPS=$NUM_GROUPS >> $LTPROOT/output/cpuctl_results_$FILE.txt;
183		TASKS_IN_GROUP=3;
184		for i in $(seq 1 $NUM_GROUPS)
185		do
186			MYGROUP=/dev/cpuctl/group_$i
187			for j in $(seq 1 $TASKS_IN_GROUP)
188			do
189			TASK_NUM=`expr $TASK_NUM + 1`;
190			cp cpuctl_test02 cpuctl_task_$TASK_NUM ;
191			chmod +x cpuctl_task_$TASK_NUM;
192
193			GROUP_NUM=$i MYGROUP=$MYGROUP SCRIPT_PID=$SCRIPT_PID NUM_CPUS=$NUM_CPUS \
194			TEST_NUM=$TEST_NUM TASK_NUM=$TASK_NUM ./cpuctl_task_$TASK_NUM \
195			>>$LTPROOT/output/cpuctl_results_$FILE.txt &
196			if [ $? -ne 0 ]
197			then
198				echo "Error: Could not run ./cpuctl_task_$TASK_NUM"
199				cleanup;
200				exit -1;
201			else
202				PID[$TASK_NUM]=$!;
203			fi;
204			j=`expr $j + 1`
205			done;		# end j loop
206			i=`expr $i + 1`
207		done;			# end i loop
208		else
209			echo "Source file not compiled..Plz check Makefile...Exiting test"
210			cleanup;
211			exit -1;
212		fi;
213		TOTAL_TASKS=$TASK_NUM;
214		;;
215	 *  )
216		echo "Could not start cpu controller test";
217		echo "usage: run_cpuctl_test.sh test_num";
218		echo "Skipping the test...";
219		exit -1;;
220	esac
221
222	sleep 3
223	echo TASKS FIRED
224	echo helloworld > myfifo;
225
226	#wait for the tasks to finish for cleanup and status report to pan
227	for i in $(seq 1 $TOTAL_TASKS)
228	do
229		wait ${PID[$i]};
230		RC=$?;	# Return status of the task being waited
231		# In abnormal termination of anyone trap will kill all others
232		# and they will return non zero exit status. So Test broke!!
233		if [ $RC -ne 0 ]
234		then
235			echo "Task $i exited abnormaly with return value: $RC";
236			tst_resm TINFO "Test could not execute for the expected duration";
237			cleanup;
238			exit -1;
239		fi
240	done
241	echo "Cpu controller test executed successfully.Results written to file";
242	echo "Please review the results in $LTPROOT/output/cpuctl_results_$FILE.txt"
243	cleanup;
244	cd $PWD
245	exit 0;		#to let PAN reprt success of test
246