run_cpuctl_stress_test.sh 13 KB

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