run_cpuctl_test.sh revision 0485d3d69c54bbedcca900176023e8d3d2525e85
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
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;;
69	"2" )   NUM_GROUPS=`expr 2 \* $NUM_CPUS`;;
70	"3" )   NUM_GROUPS=$NUM_CPUS;;
71	"4" )   NUM_GROUPS=$NUM_CPUS;;
72	 *  )  	echo "Could not start cpu controller test";
73		echo "usage: run_cpuctl_test.sh test_num";
74		echo "Skipping the test...";
75		exit -1;;
76	esac
77	echo "TEST $TEST_NUM: CPU CONTROLLER TESTING";
78	echo "RUNNING SETUP.....";
79	setup;
80
81	# Trap the signal from any abnormaly terminated task
82	# and kill all others and let cleanup be called
83	trap 'echo "signal caught from task"; killall cpuctl_task_*;' SIGUSR1;
84
85	echo "TEST STARTED: Please avoid using system while this test executes";
86	#Check if  c source  file has been compiled and then run it in different groups
87
88	case $TEST_NUM in
89	"1" | "2" )
90		if [ -f cpuctl_test01 ]
91		then
92		echo `date` >> $LTPROOT/output/cpuctl_results_$TEST_NUM.txt;
93		for i in $(seq 1 $NUM_GROUPS)
94		do
95			cp cpuctl_test01 cpuctl_task_$i 2>/dev/null;
96			chmod +x cpuctl_task_$i;
97			./cpuctl_task_$i $i /dev/cpuctl/group_$i $$ $NUM_CPUS $TEST_NUM >>$LTPROOT/output/cpuctl_results_$TEST_NUM.txt 2>/dev/null &
98			if [ $? -ne 0 ]
99			then
100				echo "Error: Could not run ./cpuctl_task_$i"
101				cleanup;
102				exit -1;
103			else
104				PID[$i]=$!;
105			fi
106			i=`expr $i + 1`
107		done
108		else
109			echo "Source file not compiled..Plz check Makefile...Exiting test"
110			cleanup;
111			exit -1;
112		fi;
113		TOTAL_TASKS=$NUM_GROUPS;
114		;;
115	"3" )
116		if [ -f cpuctl_test02 ]
117		then
118		echo `date` >> $LTPROOT/output/cpuctl_results_$TEST_NUM.txt;
119		for i in $(seq 1 $NUM_GROUPS)
120		do
121			MYGROUP=/dev/cpuctl/group_$i
122			TASKS_IN_GROUP=`expr $i \* 2`;
123			for j in $(seq 1 $TASKS_IN_GROUP)
124			do
125			TASK_NUM=`expr $TASK_NUM + 1`;
126			cp cpuctl_test02 cpuctl_task_$TASK_NUM 2>/dev/null;
127			chmod +x cpuctl_task_$TASK_NUM;
128			if [ $i -eq 1 ]	# Renice 1 task in each group
129			then
130				NICELEVEL=$NICEVALUE;
131			else
132				NICELEVEL=0;
133			fi;
134
135			GROUP_NUM=$i MYGROUP=$MYGROUP SCRIPT_PID=$SCRIPT_PID NUM_CPUS=$NUM_CPUS \
136			TEST_NUM=$TEST_NUM TASK_NUM=$TASK_NUM nice -n $NICELEVEL ./cpuctl_task_$TASK_NUM \
137			>>$LTPROOT/output/cpuctl_results_$TEST_NUM.txt 2>/dev/null &
138			if [ $? -ne 0 ]
139			then
140				echo "Error: Could not run ./cpuctl_task_$TASK_NUM"
141				cleanup;
142				exit -1;
143			else
144				PID[$TASK_NUM]=$!;
145			fi;
146			j=`expr $j + 1`
147			done;		# end j loop
148			i=`expr $i + 1`
149		done;			# end i loop
150		else
151			echo "Source file not compiled..Plz check Makefile...Exiting test"
152			cleanup;
153			exit -1;
154		fi;
155		TOTAL_TASKS=$TASK_NUM;
156		;;
157	"4" )
158		if [ -f cpuctl_test02 ]
159		then
160		echo `date` >> $LTPROOT/output/cpuctl_results_$TEST_NUM.txt;
161		TASKS_IN_GROUP=3;
162		for i in $(seq 1 $NUM_GROUPS)
163		do
164			MYGROUP=/dev/cpuctl/group_$i
165			for j in $(seq 1 $TASKS_IN_GROUP)
166			do
167			TASK_NUM=`expr $TASK_NUM + 1`;
168			cp cpuctl_test02 cpuctl_task_$TASK_NUM 2>/dev/null;
169			chmod +x cpuctl_task_$TASK_NUM;
170
171			GROUP_NUM=$i MYGROUP=$MYGROUP SCRIPT_PID=$SCRIPT_PID NUM_CPUS=$NUM_CPUS \
172			TEST_NUM=$TEST_NUM TASK_NUM=$TASK_NUM ./cpuctl_task_$TASK_NUM \
173			>>$LTPROOT/output/cpuctl_results_$TEST_NUM.txt 2>/dev/null &
174			if [ $? -ne 0 ]
175			then
176				echo "Error: Could not run ./cpuctl_task_$TASK_NUM"
177				cleanup;
178				exit -1;
179			else
180				PID[$TASK_NUM]=$!;
181			fi;
182			j=`expr $j + 1`
183			done;		# end j loop
184			i=`expr $i + 1`
185		done;			# end i loop
186		else
187			echo "Source file not compiled..Plz check Makefile...Exiting test"
188			cleanup;
189			exit -1;
190		fi;
191		TOTAL_TASKS=$TASK_NUM;
192		;;
193	 *  )
194		echo "Could not start cpu controller test";
195		echo "usage: run_cpuctl_test.sh test_num";
196		echo "Skipping the test...";
197		exit -1;;
198	esac
199
200	sleep 3
201	echo TASKS FIRED
202	echo helloworld > myfifo;
203
204	#wait for the tasks to finish for cleanup and status report to pan
205	for i in $(seq 1 $TOTAL_TASKS)
206	do
207		wait ${PID[$i]};
208		RC=$?;	# Return status of the task being waited
209		# In abnormal termination of anyone trap will kill all others
210		# and they will return non zero exit status. So Test broke!!
211		if [ $RC -ne 0 ]
212		then
213			echo "Task $i exited abnormaly with return value: $RC";
214			tst_resm TINFO "Test could not execute for the expected duration";
215			cleanup;
216			exit -1;
217		fi
218	done
219	echo "Cpu controller test executed successfully.Results written to file";
220	echo "Please review the results in $LTPROOT/output/cpuctl_results_$TEST_NUM.txt"
221	cleanup;
222	cd $PWD
223	exit 0;		#to let PAN reprt success of test
224