run_cpuctl_test.sh 11 KB

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