ktest.pl 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954
  1. #!/usr/bin/perl -w
  2. #
  3. # Copyright 2010 - Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.
  4. # Licensed under the terms of the GNU GPL License version 2
  5. #
  6. use strict;
  7. use IPC::Open2;
  8. use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
  9. use File::Path qw(mkpath);
  10. use File::Copy qw(cp);
  11. use FileHandle;
  12. my $VERSION = "0.2";
  13. $| = 1;
  14. my %opt;
  15. my %repeat_tests;
  16. my %repeats;
  17. my %default;
  18. #default opts
  19. $default{"NUM_TESTS"} = 1;
  20. $default{"REBOOT_TYPE"} = "grub";
  21. $default{"TEST_TYPE"} = "test";
  22. $default{"BUILD_TYPE"} = "randconfig";
  23. $default{"MAKE_CMD"} = "make";
  24. $default{"TIMEOUT"} = 120;
  25. $default{"TMP_DIR"} = "/tmp/ktest/\${MACHINE}";
  26. $default{"SLEEP_TIME"} = 60; # sleep time between tests
  27. $default{"BUILD_NOCLEAN"} = 0;
  28. $default{"REBOOT_ON_ERROR"} = 0;
  29. $default{"POWEROFF_ON_ERROR"} = 0;
  30. $default{"REBOOT_ON_SUCCESS"} = 1;
  31. $default{"POWEROFF_ON_SUCCESS"} = 0;
  32. $default{"BUILD_OPTIONS"} = "";
  33. $default{"BISECT_SLEEP_TIME"} = 60; # sleep time between bisects
  34. $default{"PATCHCHECK_SLEEP_TIME"} = 60; # sleep time between patch checks
  35. $default{"CLEAR_LOG"} = 0;
  36. $default{"BISECT_MANUAL"} = 0;
  37. $default{"BISECT_SKIP"} = 1;
  38. $default{"SUCCESS_LINE"} = "login:";
  39. $default{"DETECT_TRIPLE_FAULT"} = 1;
  40. $default{"BOOTED_TIMEOUT"} = 1;
  41. $default{"DIE_ON_FAILURE"} = 1;
  42. $default{"SSH_EXEC"} = "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND";
  43. $default{"SCP_TO_TARGET"} = "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE";
  44. $default{"REBOOT"} = "ssh \$SSH_USER\@\$MACHINE reboot";
  45. $default{"STOP_AFTER_SUCCESS"} = 10;
  46. $default{"STOP_AFTER_FAILURE"} = 60;
  47. $default{"STOP_TEST_AFTER"} = 600;
  48. $default{"LOCALVERSION"} = "-test";
  49. my $ktest_config;
  50. my $version;
  51. my $machine;
  52. my $ssh_user;
  53. my $tmpdir;
  54. my $builddir;
  55. my $outputdir;
  56. my $output_config;
  57. my $test_type;
  58. my $build_type;
  59. my $build_options;
  60. my $pre_build;
  61. my $post_build;
  62. my $pre_build_die;
  63. my $post_build_die;
  64. my $reboot_type;
  65. my $reboot_script;
  66. my $power_cycle;
  67. my $reboot;
  68. my $reboot_on_error;
  69. my $poweroff_on_error;
  70. my $die_on_failure;
  71. my $powercycle_after_reboot;
  72. my $poweroff_after_halt;
  73. my $ssh_exec;
  74. my $scp_to_target;
  75. my $power_off;
  76. my $grub_menu;
  77. my $grub_number;
  78. my $target;
  79. my $make;
  80. my $post_install;
  81. my $noclean;
  82. my $minconfig;
  83. my $start_minconfig;
  84. my $start_minconfig_defined;
  85. my $output_minconfig;
  86. my $ignore_config;
  87. my $addconfig;
  88. my $in_bisect = 0;
  89. my $bisect_bad = "";
  90. my $reverse_bisect;
  91. my $bisect_manual;
  92. my $bisect_skip;
  93. my $config_bisect_good;
  94. my $in_patchcheck = 0;
  95. my $run_test;
  96. my $redirect;
  97. my $buildlog;
  98. my $dmesg;
  99. my $monitor_fp;
  100. my $monitor_pid;
  101. my $monitor_cnt = 0;
  102. my $sleep_time;
  103. my $bisect_sleep_time;
  104. my $patchcheck_sleep_time;
  105. my $ignore_warnings;
  106. my $store_failures;
  107. my $test_name;
  108. my $timeout;
  109. my $booted_timeout;
  110. my $detect_triplefault;
  111. my $console;
  112. my $success_line;
  113. my $stop_after_success;
  114. my $stop_after_failure;
  115. my $stop_test_after;
  116. my $build_target;
  117. my $target_image;
  118. my $localversion;
  119. my $iteration = 0;
  120. my $successes = 0;
  121. my %entered_configs;
  122. my %config_help;
  123. my %variable;
  124. my %force_config;
  125. $config_help{"MACHINE"} = << "EOF"
  126. The machine hostname that you will test.
  127. EOF
  128. ;
  129. $config_help{"SSH_USER"} = << "EOF"
  130. The box is expected to have ssh on normal bootup, provide the user
  131. (most likely root, since you need privileged operations)
  132. EOF
  133. ;
  134. $config_help{"BUILD_DIR"} = << "EOF"
  135. The directory that contains the Linux source code (full path).
  136. EOF
  137. ;
  138. $config_help{"OUTPUT_DIR"} = << "EOF"
  139. The directory that the objects will be built (full path).
  140. (can not be same as BUILD_DIR)
  141. EOF
  142. ;
  143. $config_help{"BUILD_TARGET"} = << "EOF"
  144. The location of the compiled file to copy to the target.
  145. (relative to OUTPUT_DIR)
  146. EOF
  147. ;
  148. $config_help{"TARGET_IMAGE"} = << "EOF"
  149. The place to put your image on the test machine.
  150. EOF
  151. ;
  152. $config_help{"POWER_CYCLE"} = << "EOF"
  153. A script or command to reboot the box.
  154. Here is a digital loggers power switch example
  155. POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
  156. Here is an example to reboot a virtual box on the current host
  157. with the name "Guest".
  158. POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
  159. EOF
  160. ;
  161. $config_help{"CONSOLE"} = << "EOF"
  162. The script or command that reads the console
  163. If you use ttywatch server, something like the following would work.
  164. CONSOLE = nc -d localhost 3001
  165. For a virtual machine with guest name "Guest".
  166. CONSOLE = virsh console Guest
  167. EOF
  168. ;
  169. $config_help{"LOCALVERSION"} = << "EOF"
  170. Required version ending to differentiate the test
  171. from other linux builds on the system.
  172. EOF
  173. ;
  174. $config_help{"REBOOT_TYPE"} = << "EOF"
  175. Way to reboot the box to the test kernel.
  176. Only valid options so far are "grub" and "script".
  177. If you specify grub, it will assume grub version 1
  178. and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
  179. and select that target to reboot to the kernel. If this is not
  180. your setup, then specify "script" and have a command or script
  181. specified in REBOOT_SCRIPT to boot to the target.
  182. The entry in /boot/grub/menu.lst must be entered in manually.
  183. The test will not modify that file.
  184. EOF
  185. ;
  186. $config_help{"GRUB_MENU"} = << "EOF"
  187. The grub title name for the test kernel to boot
  188. (Only mandatory if REBOOT_TYPE = grub)
  189. Note, ktest.pl will not update the grub menu.lst, you need to
  190. manually add an option for the test. ktest.pl will search
  191. the grub menu.lst for this option to find what kernel to
  192. reboot into.
  193. For example, if in the /boot/grub/menu.lst the test kernel title has:
  194. title Test Kernel
  195. kernel vmlinuz-test
  196. GRUB_MENU = Test Kernel
  197. EOF
  198. ;
  199. $config_help{"REBOOT_SCRIPT"} = << "EOF"
  200. A script to reboot the target into the test kernel
  201. (Only mandatory if REBOOT_TYPE = script)
  202. EOF
  203. ;
  204. sub read_yn {
  205. my ($prompt) = @_;
  206. my $ans;
  207. for (;;) {
  208. print "$prompt [Y/n] ";
  209. $ans = <STDIN>;
  210. chomp $ans;
  211. if ($ans =~ /^\s*$/) {
  212. $ans = "y";
  213. }
  214. last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
  215. print "Please answer either 'y' or 'n'.\n";
  216. }
  217. if ($ans !~ /^y$/i) {
  218. return 0;
  219. }
  220. return 1;
  221. }
  222. sub get_ktest_config {
  223. my ($config) = @_;
  224. return if (defined($opt{$config}));
  225. if (defined($config_help{$config})) {
  226. print "\n";
  227. print $config_help{$config};
  228. }
  229. for (;;) {
  230. print "$config = ";
  231. if (defined($default{$config})) {
  232. print "\[$default{$config}\] ";
  233. }
  234. $entered_configs{$config} = <STDIN>;
  235. $entered_configs{$config} =~ s/^\s*(.*\S)\s*$/$1/;
  236. if ($entered_configs{$config} =~ /^\s*$/) {
  237. if ($default{$config}) {
  238. $entered_configs{$config} = $default{$config};
  239. } else {
  240. print "Your answer can not be blank\n";
  241. next;
  242. }
  243. }
  244. last;
  245. }
  246. }
  247. sub get_ktest_configs {
  248. get_ktest_config("MACHINE");
  249. get_ktest_config("SSH_USER");
  250. get_ktest_config("BUILD_DIR");
  251. get_ktest_config("OUTPUT_DIR");
  252. get_ktest_config("BUILD_TARGET");
  253. get_ktest_config("TARGET_IMAGE");
  254. get_ktest_config("POWER_CYCLE");
  255. get_ktest_config("CONSOLE");
  256. get_ktest_config("LOCALVERSION");
  257. my $rtype = $opt{"REBOOT_TYPE"};
  258. if (!defined($rtype)) {
  259. if (!defined($opt{"GRUB_MENU"})) {
  260. get_ktest_config("REBOOT_TYPE");
  261. $rtype = $entered_configs{"REBOOT_TYPE"};
  262. } else {
  263. $rtype = "grub";
  264. }
  265. }
  266. if ($rtype eq "grub") {
  267. get_ktest_config("GRUB_MENU");
  268. } else {
  269. get_ktest_config("REBOOT_SCRIPT");
  270. }
  271. }
  272. sub process_variables {
  273. my ($value) = @_;
  274. my $retval = "";
  275. # We want to check for '\', and it is just easier
  276. # to check the previous characet of '$' and not need
  277. # to worry if '$' is the first character. By adding
  278. # a space to $value, we can just check [^\\]\$ and
  279. # it will still work.
  280. $value = " $value";
  281. while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
  282. my $begin = $1;
  283. my $var = $2;
  284. my $end = $3;
  285. # append beginning of value to retval
  286. $retval = "$retval$begin";
  287. if (defined($variable{$var})) {
  288. $retval = "$retval$variable{$var}";
  289. } else {
  290. # put back the origin piece.
  291. $retval = "$retval\$\{$var\}";
  292. }
  293. $value = $end;
  294. }
  295. $retval = "$retval$value";
  296. # remove the space added in the beginning
  297. $retval =~ s/ //;
  298. return "$retval"
  299. }
  300. sub set_value {
  301. my ($lvalue, $rvalue) = @_;
  302. if (defined($opt{$lvalue})) {
  303. die "Error: Option $lvalue defined more than once!\n";
  304. }
  305. if ($rvalue =~ /^\s*$/) {
  306. delete $opt{$lvalue};
  307. } else {
  308. $rvalue = process_variables($rvalue);
  309. $opt{$lvalue} = $rvalue;
  310. }
  311. }
  312. sub set_variable {
  313. my ($lvalue, $rvalue) = @_;
  314. if ($rvalue =~ /^\s*$/) {
  315. delete $variable{$lvalue};
  316. } else {
  317. $rvalue = process_variables($rvalue);
  318. $variable{$lvalue} = $rvalue;
  319. }
  320. }
  321. sub read_config {
  322. my ($config) = @_;
  323. open(IN, $config) || die "can't read file $config";
  324. my $name = $config;
  325. $name =~ s,.*/(.*),$1,;
  326. my $test_num = 0;
  327. my $default = 1;
  328. my $repeat = 1;
  329. my $num_tests_set = 0;
  330. my $skip = 0;
  331. my $rest;
  332. my $test_case = 0;
  333. while (<IN>) {
  334. # ignore blank lines and comments
  335. next if (/^\s*$/ || /\s*\#/);
  336. if (/^\s*TEST_START(.*)/) {
  337. $rest = $1;
  338. if ($num_tests_set) {
  339. die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
  340. }
  341. my $old_test_num = $test_num;
  342. my $old_repeat = $repeat;
  343. $test_num += $repeat;
  344. $default = 0;
  345. $repeat = 1;
  346. if ($rest =~ /\s+SKIP(.*)/) {
  347. $rest = $1;
  348. $skip = 1;
  349. } else {
  350. $test_case = 1;
  351. $skip = 0;
  352. }
  353. if ($rest =~ /\s+ITERATE\s+(\d+)(.*)$/) {
  354. $repeat = $1;
  355. $rest = $2;
  356. $repeat_tests{"$test_num"} = $repeat;
  357. }
  358. if ($rest =~ /\s+SKIP(.*)/) {
  359. $rest = $1;
  360. $skip = 1;
  361. }
  362. if ($rest !~ /^\s*$/) {
  363. die "$name: $.: Gargbage found after TEST_START\n$_";
  364. }
  365. if ($skip) {
  366. $test_num = $old_test_num;
  367. $repeat = $old_repeat;
  368. }
  369. } elsif (/^\s*DEFAULTS(.*)$/) {
  370. $default = 1;
  371. $rest = $1;
  372. if ($rest =~ /\s+SKIP(.*)/) {
  373. $rest = $1;
  374. $skip = 1;
  375. } else {
  376. $skip = 0;
  377. }
  378. if ($rest !~ /^\s*$/) {
  379. die "$name: $.: Gargbage found after DEFAULTS\n$_";
  380. }
  381. } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
  382. next if ($skip);
  383. my $lvalue = $1;
  384. my $rvalue = $2;
  385. if (!$default &&
  386. ($lvalue eq "NUM_TESTS" ||
  387. $lvalue eq "LOG_FILE" ||
  388. $lvalue eq "CLEAR_LOG")) {
  389. die "$name: $.: $lvalue must be set in DEFAULTS section\n";
  390. }
  391. if ($lvalue eq "NUM_TESTS") {
  392. if ($test_num) {
  393. die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
  394. }
  395. if (!$default) {
  396. die "$name: $.: NUM_TESTS must be set in default section\n";
  397. }
  398. $num_tests_set = 1;
  399. }
  400. if ($default || $lvalue =~ /\[\d+\]$/) {
  401. set_value($lvalue, $rvalue);
  402. } else {
  403. my $val = "$lvalue\[$test_num\]";
  404. set_value($val, $rvalue);
  405. if ($repeat > 1) {
  406. $repeats{$val} = $repeat;
  407. }
  408. }
  409. } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
  410. next if ($skip);
  411. my $lvalue = $1;
  412. my $rvalue = $2;
  413. # process config variables.
  414. # Config variables are only active while reading the
  415. # config and can be defined anywhere. They also ignore
  416. # TEST_START and DEFAULTS, but are skipped if they are in
  417. # on of these sections that have SKIP defined.
  418. # The save variable can be
  419. # defined multiple times and the new one simply overrides
  420. # the prevous one.
  421. set_variable($lvalue, $rvalue);
  422. } else {
  423. die "$name: $.: Garbage found in config\n$_";
  424. }
  425. }
  426. close(IN);
  427. if ($test_num) {
  428. $test_num += $repeat - 1;
  429. $opt{"NUM_TESTS"} = $test_num;
  430. }
  431. # make sure we have all mandatory configs
  432. get_ktest_configs;
  433. # was a test specified?
  434. if (!$test_case) {
  435. print "No test case specified.\n";
  436. print "What test case would you like to run?\n";
  437. my $ans = <STDIN>;
  438. chomp $ans;
  439. $default{"TEST_TYPE"} = $ans;
  440. }
  441. # set any defaults
  442. foreach my $default (keys %default) {
  443. if (!defined($opt{$default})) {
  444. $opt{$default} = $default{$default};
  445. }
  446. }
  447. }
  448. sub __eval_option {
  449. my ($option, $i) = @_;
  450. # Add space to evaluate the character before $
  451. $option = " $option";
  452. my $retval = "";
  453. while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
  454. my $start = $1;
  455. my $var = $2;
  456. my $end = $3;
  457. # Append beginning of line
  458. $retval = "$retval$start";
  459. # If the iteration option OPT[$i] exists, then use that.
  460. # otherwise see if the default OPT (without [$i]) exists.
  461. my $o = "$var\[$i\]";
  462. if (defined($opt{$o})) {
  463. $o = $opt{$o};
  464. $retval = "$retval$o";
  465. } elsif (defined($opt{$var})) {
  466. $o = $opt{$var};
  467. $retval = "$retval$o";
  468. } else {
  469. $retval = "$retval\$\{$var\}";
  470. }
  471. $option = $end;
  472. }
  473. $retval = "$retval$option";
  474. $retval =~ s/^ //;
  475. return $retval;
  476. }
  477. sub eval_option {
  478. my ($option, $i) = @_;
  479. my $prev = "";
  480. # Since an option can evaluate to another option,
  481. # keep iterating until we do not evaluate any more
  482. # options.
  483. my $r = 0;
  484. while ($prev ne $option) {
  485. # Check for recursive evaluations.
  486. # 100 deep should be more than enough.
  487. if ($r++ > 100) {
  488. die "Over 100 evaluations accurred with $option\n" .
  489. "Check for recursive variables\n";
  490. }
  491. $prev = $option;
  492. $option = __eval_option($option, $i);
  493. }
  494. return $option;
  495. }
  496. sub _logit {
  497. if (defined($opt{"LOG_FILE"})) {
  498. open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
  499. print OUT @_;
  500. close(OUT);
  501. }
  502. }
  503. sub logit {
  504. if (defined($opt{"LOG_FILE"})) {
  505. _logit @_;
  506. } else {
  507. print @_;
  508. }
  509. }
  510. sub doprint {
  511. print @_;
  512. _logit @_;
  513. }
  514. sub run_command;
  515. sub reboot {
  516. # try to reboot normally
  517. if (run_command $reboot) {
  518. if (defined($powercycle_after_reboot)) {
  519. sleep $powercycle_after_reboot;
  520. run_command "$power_cycle";
  521. }
  522. } else {
  523. # nope? power cycle it.
  524. run_command "$power_cycle";
  525. }
  526. }
  527. sub do_not_reboot {
  528. my $i = $iteration;
  529. return $test_type eq "build" ||
  530. ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
  531. ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
  532. }
  533. sub dodie {
  534. doprint "CRITICAL FAILURE... ", @_, "\n";
  535. my $i = $iteration;
  536. if ($reboot_on_error && !do_not_reboot) {
  537. doprint "REBOOTING\n";
  538. reboot;
  539. } elsif ($poweroff_on_error && defined($power_off)) {
  540. doprint "POWERING OFF\n";
  541. `$power_off`;
  542. }
  543. if (defined($opt{"LOG_FILE"})) {
  544. print " See $opt{LOG_FILE} for more info.\n";
  545. }
  546. die @_, "\n";
  547. }
  548. sub open_console {
  549. my ($fp) = @_;
  550. my $flags;
  551. my $pid = open($fp, "$console|") or
  552. dodie "Can't open console $console";
  553. $flags = fcntl($fp, F_GETFL, 0) or
  554. dodie "Can't get flags for the socket: $!";
  555. $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
  556. dodie "Can't set flags for the socket: $!";
  557. return $pid;
  558. }
  559. sub close_console {
  560. my ($fp, $pid) = @_;
  561. doprint "kill child process $pid\n";
  562. kill 2, $pid;
  563. print "closing!\n";
  564. close($fp);
  565. }
  566. sub start_monitor {
  567. if ($monitor_cnt++) {
  568. return;
  569. }
  570. $monitor_fp = \*MONFD;
  571. $monitor_pid = open_console $monitor_fp;
  572. return;
  573. open(MONFD, "Stop perl from warning about single use of MONFD");
  574. }
  575. sub end_monitor {
  576. if (--$monitor_cnt) {
  577. return;
  578. }
  579. close_console($monitor_fp, $monitor_pid);
  580. }
  581. sub wait_for_monitor {
  582. my ($time) = @_;
  583. my $line;
  584. doprint "** Wait for monitor to settle down **\n";
  585. # read the monitor and wait for the system to calm down
  586. do {
  587. $line = wait_for_input($monitor_fp, $time);
  588. print "$line" if (defined($line));
  589. } while (defined($line));
  590. print "** Monitor flushed **\n";
  591. }
  592. sub fail {
  593. if ($die_on_failure) {
  594. dodie @_;
  595. }
  596. doprint "FAILED\n";
  597. my $i = $iteration;
  598. # no need to reboot for just building.
  599. if (!do_not_reboot) {
  600. doprint "REBOOTING\n";
  601. reboot;
  602. start_monitor;
  603. wait_for_monitor $sleep_time;
  604. end_monitor;
  605. }
  606. my $name = "";
  607. if (defined($test_name)) {
  608. $name = " ($test_name)";
  609. }
  610. doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
  611. doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
  612. doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
  613. doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
  614. doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
  615. return 1 if (!defined($store_failures));
  616. my @t = localtime;
  617. my $date = sprintf "%04d%02d%02d%02d%02d%02d",
  618. 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
  619. my $type = $build_type;
  620. if ($type =~ /useconfig/) {
  621. $type = "useconfig";
  622. }
  623. my $dir = "$machine-$test_type-$type-fail-$date";
  624. my $faildir = "$store_failures/$dir";
  625. if (!-d $faildir) {
  626. mkpath($faildir) or
  627. die "can't create $faildir";
  628. }
  629. if (-f "$output_config") {
  630. cp "$output_config", "$faildir/config" or
  631. die "failed to copy .config";
  632. }
  633. if (-f $buildlog) {
  634. cp $buildlog, "$faildir/buildlog" or
  635. die "failed to move $buildlog";
  636. }
  637. if (-f $dmesg) {
  638. cp $dmesg, "$faildir/dmesg" or
  639. die "failed to move $dmesg";
  640. }
  641. doprint "*** Saved info to $faildir ***\n";
  642. return 1;
  643. }
  644. sub run_command {
  645. my ($command) = @_;
  646. my $dolog = 0;
  647. my $dord = 0;
  648. my $pid;
  649. $command =~ s/\$SSH_USER/$ssh_user/g;
  650. $command =~ s/\$MACHINE/$machine/g;
  651. doprint("$command ... ");
  652. $pid = open(CMD, "$command 2>&1 |") or
  653. (fail "unable to exec $command" and return 0);
  654. if (defined($opt{"LOG_FILE"})) {
  655. open(LOG, ">>$opt{LOG_FILE}") or
  656. dodie "failed to write to log";
  657. $dolog = 1;
  658. }
  659. if (defined($redirect)) {
  660. open (RD, ">$redirect") or
  661. dodie "failed to write to redirect $redirect";
  662. $dord = 1;
  663. }
  664. while (<CMD>) {
  665. print LOG if ($dolog);
  666. print RD if ($dord);
  667. }
  668. waitpid($pid, 0);
  669. my $failed = $?;
  670. close(CMD);
  671. close(LOG) if ($dolog);
  672. close(RD) if ($dord);
  673. if ($failed) {
  674. doprint "FAILED!\n";
  675. } else {
  676. doprint "SUCCESS\n";
  677. }
  678. return !$failed;
  679. }
  680. sub run_ssh {
  681. my ($cmd) = @_;
  682. my $cp_exec = $ssh_exec;
  683. $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
  684. return run_command "$cp_exec";
  685. }
  686. sub run_scp {
  687. my ($src, $dst) = @_;
  688. my $cp_scp = $scp_to_target;
  689. $cp_scp =~ s/\$SRC_FILE/$src/g;
  690. $cp_scp =~ s/\$DST_FILE/$dst/g;
  691. return run_command "$cp_scp";
  692. }
  693. sub get_grub_index {
  694. if ($reboot_type ne "grub") {
  695. return;
  696. }
  697. return if (defined($grub_number));
  698. doprint "Find grub menu ... ";
  699. $grub_number = -1;
  700. my $ssh_grub = $ssh_exec;
  701. $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
  702. open(IN, "$ssh_grub |")
  703. or die "unable to get menu.lst";
  704. while (<IN>) {
  705. if (/^\s*title\s+$grub_menu\s*$/) {
  706. $grub_number++;
  707. last;
  708. } elsif (/^\s*title\s/) {
  709. $grub_number++;
  710. }
  711. }
  712. close(IN);
  713. die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
  714. if ($grub_number < 0);
  715. doprint "$grub_number\n";
  716. }
  717. sub wait_for_input
  718. {
  719. my ($fp, $time) = @_;
  720. my $rin;
  721. my $ready;
  722. my $line;
  723. my $ch;
  724. if (!defined($time)) {
  725. $time = $timeout;
  726. }
  727. $rin = '';
  728. vec($rin, fileno($fp), 1) = 1;
  729. $ready = select($rin, undef, undef, $time);
  730. $line = "";
  731. # try to read one char at a time
  732. while (sysread $fp, $ch, 1) {
  733. $line .= $ch;
  734. last if ($ch eq "\n");
  735. }
  736. if (!length($line)) {
  737. return undef;
  738. }
  739. return $line;
  740. }
  741. sub reboot_to {
  742. if ($reboot_type eq "grub") {
  743. run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch && reboot)'";
  744. return;
  745. }
  746. run_command "$reboot_script";
  747. }
  748. sub get_sha1 {
  749. my ($commit) = @_;
  750. doprint "git rev-list --max-count=1 $commit ... ";
  751. my $sha1 = `git rev-list --max-count=1 $commit`;
  752. my $ret = $?;
  753. logit $sha1;
  754. if ($ret) {
  755. doprint "FAILED\n";
  756. dodie "Failed to get git $commit";
  757. }
  758. print "SUCCESS\n";
  759. chomp $sha1;
  760. return $sha1;
  761. }
  762. sub monitor {
  763. my $booted = 0;
  764. my $bug = 0;
  765. my $skip_call_trace = 0;
  766. my $loops;
  767. wait_for_monitor 5;
  768. my $line;
  769. my $full_line = "";
  770. open(DMESG, "> $dmesg") or
  771. die "unable to write to $dmesg";
  772. reboot_to;
  773. my $success_start;
  774. my $failure_start;
  775. my $monitor_start = time;
  776. my $done = 0;
  777. my $version_found = 0;
  778. while (!$done) {
  779. if ($bug && defined($stop_after_failure) &&
  780. $stop_after_failure >= 0) {
  781. my $time = $stop_after_failure - (time - $failure_start);
  782. $line = wait_for_input($monitor_fp, $time);
  783. if (!defined($line)) {
  784. doprint "bug timed out after $booted_timeout seconds\n";
  785. doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
  786. last;
  787. }
  788. } elsif ($booted) {
  789. $line = wait_for_input($monitor_fp, $booted_timeout);
  790. if (!defined($line)) {
  791. my $s = $booted_timeout == 1 ? "" : "s";
  792. doprint "Successful boot found: break after $booted_timeout second$s\n";
  793. last;
  794. }
  795. } else {
  796. $line = wait_for_input($monitor_fp);
  797. if (!defined($line)) {
  798. my $s = $timeout == 1 ? "" : "s";
  799. doprint "Timed out after $timeout second$s\n";
  800. last;
  801. }
  802. }
  803. doprint $line;
  804. print DMESG $line;
  805. # we are not guaranteed to get a full line
  806. $full_line .= $line;
  807. if ($full_line =~ /$success_line/) {
  808. $booted = 1;
  809. $success_start = time;
  810. }
  811. if ($booted && defined($stop_after_success) &&
  812. $stop_after_success >= 0) {
  813. my $now = time;
  814. if ($now - $success_start >= $stop_after_success) {
  815. doprint "Test forced to stop after $stop_after_success seconds after success\n";
  816. last;
  817. }
  818. }
  819. if ($full_line =~ /\[ backtrace testing \]/) {
  820. $skip_call_trace = 1;
  821. }
  822. if ($full_line =~ /call trace:/i) {
  823. if (!$bug && !$skip_call_trace) {
  824. $bug = 1;
  825. $failure_start = time;
  826. }
  827. }
  828. if ($bug && defined($stop_after_failure) &&
  829. $stop_after_failure >= 0) {
  830. my $now = time;
  831. if ($now - $failure_start >= $stop_after_failure) {
  832. doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
  833. last;
  834. }
  835. }
  836. if ($full_line =~ /\[ end of backtrace testing \]/) {
  837. $skip_call_trace = 0;
  838. }
  839. if ($full_line =~ /Kernel panic -/) {
  840. $failure_start = time;
  841. $bug = 1;
  842. }
  843. # Detect triple faults by testing the banner
  844. if ($full_line =~ /\bLinux version (\S+).*\n/) {
  845. if ($1 eq $version) {
  846. $version_found = 1;
  847. } elsif ($version_found && $detect_triplefault) {
  848. # We already booted into the kernel we are testing,
  849. # but now we booted into another kernel?
  850. # Consider this a triple fault.
  851. doprint "Aleady booted in Linux kernel $version, but now\n";
  852. doprint "we booted into Linux kernel $1.\n";
  853. doprint "Assuming that this is a triple fault.\n";
  854. doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
  855. last;
  856. }
  857. }
  858. if ($line =~ /\n/) {
  859. $full_line = "";
  860. }
  861. if ($stop_test_after > 0 && !$booted && !$bug) {
  862. if (time - $monitor_start > $stop_test_after) {
  863. doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
  864. $done = 1;
  865. }
  866. }
  867. }
  868. close(DMESG);
  869. if ($bug) {
  870. return 0 if ($in_bisect);
  871. fail "failed - got a bug report" and return 0;
  872. }
  873. if (!$booted) {
  874. return 0 if ($in_bisect);
  875. fail "failed - never got a boot prompt." and return 0;
  876. }
  877. return 1;
  878. }
  879. sub do_post_install {
  880. return if (!defined($post_install));
  881. my $cp_post_install = $post_install;
  882. $cp_post_install =~ s/\$KERNEL_VERSION/$version/g;
  883. run_command "$cp_post_install" or
  884. dodie "Failed to run post install";
  885. }
  886. sub install {
  887. run_scp "$outputdir/$build_target", "$target_image" or
  888. dodie "failed to copy image";
  889. my $install_mods = 0;
  890. # should we process modules?
  891. $install_mods = 0;
  892. open(IN, "$output_config") or dodie("Can't read config file");
  893. while (<IN>) {
  894. if (/CONFIG_MODULES(=y)?/) {
  895. $install_mods = 1 if (defined($1));
  896. last;
  897. }
  898. }
  899. close(IN);
  900. if (!$install_mods) {
  901. do_post_install;
  902. doprint "No modules needed\n";
  903. return;
  904. }
  905. run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
  906. dodie "Failed to install modules";
  907. my $modlib = "/lib/modules/$version";
  908. my $modtar = "ktest-mods.tar.bz2";
  909. run_ssh "rm -rf $modlib" or
  910. dodie "failed to remove old mods: $modlib";
  911. # would be nice if scp -r did not follow symbolic links
  912. run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
  913. dodie "making tarball";
  914. run_scp "$tmpdir/$modtar", "/tmp" or
  915. dodie "failed to copy modules";
  916. unlink "$tmpdir/$modtar";
  917. run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
  918. dodie "failed to tar modules";
  919. run_ssh "rm -f /tmp/$modtar";
  920. do_post_install;
  921. }
  922. sub get_version {
  923. # get the release name
  924. doprint "$make kernelrelease ... ";
  925. $version = `$make kernelrelease | tail -1`;
  926. chomp($version);
  927. doprint "$version\n";
  928. }
  929. sub start_monitor_and_boot {
  930. get_grub_index;
  931. get_version;
  932. install;
  933. start_monitor;
  934. return monitor;
  935. }
  936. sub check_buildlog {
  937. my ($patch) = @_;
  938. my @files = `git show $patch | diffstat -l`;
  939. open(IN, "git show $patch |") or
  940. dodie "failed to show $patch";
  941. while (<IN>) {
  942. if (m,^--- a/(.*),) {
  943. chomp $1;
  944. $files[$#files] = $1;
  945. }
  946. }
  947. close(IN);
  948. open(IN, $buildlog) or dodie "Can't open $buildlog";
  949. while (<IN>) {
  950. if (/^\s*(.*?):.*(warning|error)/) {
  951. my $err = $1;
  952. foreach my $file (@files) {
  953. my $fullpath = "$builddir/$file";
  954. if ($file eq $err || $fullpath eq $err) {
  955. fail "$file built with warnings" and return 0;
  956. }
  957. }
  958. }
  959. }
  960. close(IN);
  961. return 1;
  962. }
  963. sub apply_min_config {
  964. my $outconfig = "$output_config.new";
  965. # Read the config file and remove anything that
  966. # is in the force_config hash (from minconfig and others)
  967. # then add the force config back.
  968. doprint "Applying minimum configurations into $output_config.new\n";
  969. open (OUT, ">$outconfig") or
  970. dodie "Can't create $outconfig";
  971. if (-f $output_config) {
  972. open (IN, $output_config) or
  973. dodie "Failed to open $output_config";
  974. while (<IN>) {
  975. if (/^(# )?(CONFIG_[^\s=]*)/) {
  976. next if (defined($force_config{$2}));
  977. }
  978. print OUT;
  979. }
  980. close IN;
  981. }
  982. foreach my $config (keys %force_config) {
  983. print OUT "$force_config{$config}\n";
  984. }
  985. close OUT;
  986. run_command "mv $outconfig $output_config";
  987. }
  988. sub make_oldconfig {
  989. my @force_list = keys %force_config;
  990. if ($#force_list >= 0) {
  991. apply_min_config;
  992. }
  993. if (!run_command "$make oldnoconfig") {
  994. # Perhaps oldnoconfig doesn't exist in this version of the kernel
  995. # try a yes '' | oldconfig
  996. doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
  997. run_command "yes '' | $make oldconfig" or
  998. dodie "failed make config oldconfig";
  999. }
  1000. }
  1001. # read a config file and use this to force new configs.
  1002. sub load_force_config {
  1003. my ($config) = @_;
  1004. open(IN, $config) or
  1005. dodie "failed to read $config";
  1006. while (<IN>) {
  1007. chomp;
  1008. if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
  1009. $force_config{$1} = $_;
  1010. } elsif (/^# (CONFIG_\S*) is not set/) {
  1011. $force_config{$1} = $_;
  1012. }
  1013. }
  1014. close IN;
  1015. }
  1016. sub build {
  1017. my ($type) = @_;
  1018. unlink $buildlog;
  1019. if (defined($pre_build)) {
  1020. my $ret = run_command $pre_build;
  1021. if (!$ret && defined($pre_build_die) &&
  1022. $pre_build_die) {
  1023. dodie "failed to pre_build\n";
  1024. }
  1025. }
  1026. if ($type =~ /^useconfig:(.*)/) {
  1027. run_command "cp $1 $output_config" or
  1028. dodie "could not copy $1 to .config";
  1029. $type = "oldconfig";
  1030. }
  1031. # old config can ask questions
  1032. if ($type eq "oldconfig") {
  1033. $type = "oldnoconfig";
  1034. # allow for empty configs
  1035. run_command "touch $output_config";
  1036. run_command "mv $output_config $outputdir/config_temp" or
  1037. dodie "moving .config";
  1038. if (!$noclean && !run_command "$make mrproper") {
  1039. dodie "make mrproper";
  1040. }
  1041. run_command "mv $outputdir/config_temp $output_config" or
  1042. dodie "moving config_temp";
  1043. } elsif (!$noclean) {
  1044. unlink "$output_config";
  1045. run_command "$make mrproper" or
  1046. dodie "make mrproper";
  1047. }
  1048. # add something to distinguish this build
  1049. open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
  1050. print OUT "$localversion\n";
  1051. close(OUT);
  1052. if (defined($minconfig)) {
  1053. load_force_config($minconfig);
  1054. }
  1055. if ($type ne "oldnoconfig") {
  1056. run_command "$make $type" or
  1057. dodie "failed make config";
  1058. }
  1059. # Run old config regardless, to enforce min configurations
  1060. make_oldconfig;
  1061. $redirect = "$buildlog";
  1062. my $build_ret = run_command "$make $build_options";
  1063. undef $redirect;
  1064. if (defined($post_build)) {
  1065. my $ret = run_command $post_build;
  1066. if (!$ret && defined($post_build_die) &&
  1067. $post_build_die) {
  1068. dodie "failed to post_build\n";
  1069. }
  1070. }
  1071. if (!$build_ret) {
  1072. # bisect may need this to pass
  1073. return 0 if ($in_bisect);
  1074. fail "failed build" and return 0;
  1075. }
  1076. return 1;
  1077. }
  1078. sub halt {
  1079. if (!run_ssh "halt" or defined($power_off)) {
  1080. if (defined($poweroff_after_halt)) {
  1081. sleep $poweroff_after_halt;
  1082. run_command "$power_off";
  1083. }
  1084. } else {
  1085. # nope? the zap it!
  1086. run_command "$power_off";
  1087. }
  1088. }
  1089. sub success {
  1090. my ($i) = @_;
  1091. $successes++;
  1092. my $name = "";
  1093. if (defined($test_name)) {
  1094. $name = " ($test_name)";
  1095. }
  1096. doprint "\n\n*******************************************\n";
  1097. doprint "*******************************************\n";
  1098. doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
  1099. doprint "*******************************************\n";
  1100. doprint "*******************************************\n";
  1101. if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
  1102. doprint "Reboot and wait $sleep_time seconds\n";
  1103. reboot;
  1104. start_monitor;
  1105. wait_for_monitor $sleep_time;
  1106. end_monitor;
  1107. }
  1108. }
  1109. sub answer_bisect {
  1110. for (;;) {
  1111. doprint "Pass or fail? [p/f]";
  1112. my $ans = <STDIN>;
  1113. chomp $ans;
  1114. if ($ans eq "p" || $ans eq "P") {
  1115. return 1;
  1116. } elsif ($ans eq "f" || $ans eq "F") {
  1117. return 0;
  1118. } else {
  1119. print "Please answer 'P' or 'F'\n";
  1120. }
  1121. }
  1122. }
  1123. sub child_run_test {
  1124. my $failed = 0;
  1125. # child should have no power
  1126. $reboot_on_error = 0;
  1127. $poweroff_on_error = 0;
  1128. $die_on_failure = 1;
  1129. run_command $run_test or $failed = 1;
  1130. exit $failed;
  1131. }
  1132. my $child_done;
  1133. sub child_finished {
  1134. $child_done = 1;
  1135. }
  1136. sub do_run_test {
  1137. my $child_pid;
  1138. my $child_exit;
  1139. my $line;
  1140. my $full_line;
  1141. my $bug = 0;
  1142. wait_for_monitor 1;
  1143. doprint "run test $run_test\n";
  1144. $child_done = 0;
  1145. $SIG{CHLD} = qw(child_finished);
  1146. $child_pid = fork;
  1147. child_run_test if (!$child_pid);
  1148. $full_line = "";
  1149. do {
  1150. $line = wait_for_input($monitor_fp, 1);
  1151. if (defined($line)) {
  1152. # we are not guaranteed to get a full line
  1153. $full_line .= $line;
  1154. doprint $line;
  1155. if ($full_line =~ /call trace:/i) {
  1156. $bug = 1;
  1157. }
  1158. if ($full_line =~ /Kernel panic -/) {
  1159. $bug = 1;
  1160. }
  1161. if ($line =~ /\n/) {
  1162. $full_line = "";
  1163. }
  1164. }
  1165. } while (!$child_done && !$bug);
  1166. if ($bug) {
  1167. my $failure_start = time;
  1168. my $now;
  1169. do {
  1170. $line = wait_for_input($monitor_fp, 1);
  1171. if (defined($line)) {
  1172. doprint $line;
  1173. }
  1174. $now = time;
  1175. if ($now - $failure_start >= $stop_after_failure) {
  1176. last;
  1177. }
  1178. } while (defined($line));
  1179. doprint "Detected kernel crash!\n";
  1180. # kill the child with extreme prejudice
  1181. kill 9, $child_pid;
  1182. }
  1183. waitpid $child_pid, 0;
  1184. $child_exit = $?;
  1185. if ($bug || $child_exit) {
  1186. return 0 if $in_bisect;
  1187. fail "test failed" and return 0;
  1188. }
  1189. return 1;
  1190. }
  1191. sub run_git_bisect {
  1192. my ($command) = @_;
  1193. doprint "$command ... ";
  1194. my $output = `$command 2>&1`;
  1195. my $ret = $?;
  1196. logit $output;
  1197. if ($ret) {
  1198. doprint "FAILED\n";
  1199. dodie "Failed to git bisect";
  1200. }
  1201. doprint "SUCCESS\n";
  1202. if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
  1203. doprint "$1 [$2]\n";
  1204. } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
  1205. $bisect_bad = $1;
  1206. doprint "Found bad commit... $1\n";
  1207. return 0;
  1208. } else {
  1209. # we already logged it, just print it now.
  1210. print $output;
  1211. }
  1212. return 1;
  1213. }
  1214. sub bisect_reboot {
  1215. doprint "Reboot and sleep $bisect_sleep_time seconds\n";
  1216. reboot;
  1217. start_monitor;
  1218. wait_for_monitor $bisect_sleep_time;
  1219. end_monitor;
  1220. }
  1221. # returns 1 on success, 0 on failure, -1 on skip
  1222. sub run_bisect_test {
  1223. my ($type, $buildtype) = @_;
  1224. my $failed = 0;
  1225. my $result;
  1226. my $output;
  1227. my $ret;
  1228. $in_bisect = 1;
  1229. build $buildtype or $failed = 1;
  1230. if ($type ne "build") {
  1231. if ($failed && $bisect_skip) {
  1232. $in_bisect = 0;
  1233. return -1;
  1234. }
  1235. dodie "Failed on build" if $failed;
  1236. # Now boot the box
  1237. start_monitor_and_boot or $failed = 1;
  1238. if ($type ne "boot") {
  1239. if ($failed && $bisect_skip) {
  1240. end_monitor;
  1241. bisect_reboot;
  1242. $in_bisect = 0;
  1243. return -1;
  1244. }
  1245. dodie "Failed on boot" if $failed;
  1246. do_run_test or $failed = 1;
  1247. }
  1248. end_monitor;
  1249. }
  1250. if ($failed) {
  1251. $result = 0;
  1252. } else {
  1253. $result = 1;
  1254. }
  1255. # reboot the box to a kernel we can ssh to
  1256. if ($type ne "build") {
  1257. bisect_reboot;
  1258. }
  1259. $in_bisect = 0;
  1260. return $result;
  1261. }
  1262. sub run_bisect {
  1263. my ($type) = @_;
  1264. my $buildtype = "oldconfig";
  1265. # We should have a minconfig to use?
  1266. if (defined($minconfig)) {
  1267. $buildtype = "useconfig:$minconfig";
  1268. }
  1269. my $ret = run_bisect_test $type, $buildtype;
  1270. if ($bisect_manual) {
  1271. $ret = answer_bisect;
  1272. }
  1273. # Are we looking for where it worked, not failed?
  1274. if ($reverse_bisect) {
  1275. $ret = !$ret;
  1276. }
  1277. if ($ret > 0) {
  1278. return "good";
  1279. } elsif ($ret == 0) {
  1280. return "bad";
  1281. } elsif ($bisect_skip) {
  1282. doprint "HIT A BAD COMMIT ... SKIPPING\n";
  1283. return "skip";
  1284. }
  1285. }
  1286. sub bisect {
  1287. my ($i) = @_;
  1288. my $result;
  1289. die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
  1290. die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
  1291. die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
  1292. my $good = $opt{"BISECT_GOOD[$i]"};
  1293. my $bad = $opt{"BISECT_BAD[$i]"};
  1294. my $type = $opt{"BISECT_TYPE[$i]"};
  1295. my $start = $opt{"BISECT_START[$i]"};
  1296. my $replay = $opt{"BISECT_REPLAY[$i]"};
  1297. my $start_files = $opt{"BISECT_FILES[$i]"};
  1298. if (defined($start_files)) {
  1299. $start_files = " -- " . $start_files;
  1300. } else {
  1301. $start_files = "";
  1302. }
  1303. # convert to true sha1's
  1304. $good = get_sha1($good);
  1305. $bad = get_sha1($bad);
  1306. if (defined($opt{"BISECT_REVERSE[$i]"}) &&
  1307. $opt{"BISECT_REVERSE[$i]"} == 1) {
  1308. doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
  1309. $reverse_bisect = 1;
  1310. } else {
  1311. $reverse_bisect = 0;
  1312. }
  1313. # Can't have a test without having a test to run
  1314. if ($type eq "test" && !defined($run_test)) {
  1315. $type = "boot";
  1316. }
  1317. my $check = $opt{"BISECT_CHECK[$i]"};
  1318. if (defined($check) && $check ne "0") {
  1319. # get current HEAD
  1320. my $head = get_sha1("HEAD");
  1321. if ($check ne "good") {
  1322. doprint "TESTING BISECT BAD [$bad]\n";
  1323. run_command "git checkout $bad" or
  1324. die "Failed to checkout $bad";
  1325. $result = run_bisect $type;
  1326. if ($result ne "bad") {
  1327. fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
  1328. }
  1329. }
  1330. if ($check ne "bad") {
  1331. doprint "TESTING BISECT GOOD [$good]\n";
  1332. run_command "git checkout $good" or
  1333. die "Failed to checkout $good";
  1334. $result = run_bisect $type;
  1335. if ($result ne "good") {
  1336. fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
  1337. }
  1338. }
  1339. # checkout where we started
  1340. run_command "git checkout $head" or
  1341. die "Failed to checkout $head";
  1342. }
  1343. run_command "git bisect start$start_files" or
  1344. dodie "could not start bisect";
  1345. run_command "git bisect good $good" or
  1346. dodie "could not set bisect good to $good";
  1347. run_git_bisect "git bisect bad $bad" or
  1348. dodie "could not set bisect bad to $bad";
  1349. if (defined($replay)) {
  1350. run_command "git bisect replay $replay" or
  1351. dodie "failed to run replay";
  1352. }
  1353. if (defined($start)) {
  1354. run_command "git checkout $start" or
  1355. dodie "failed to checkout $start";
  1356. }
  1357. my $test;
  1358. do {
  1359. $result = run_bisect $type;
  1360. $test = run_git_bisect "git bisect $result";
  1361. } while ($test);
  1362. run_command "git bisect log" or
  1363. dodie "could not capture git bisect log";
  1364. run_command "git bisect reset" or
  1365. dodie "could not reset git bisect";
  1366. doprint "Bad commit was [$bisect_bad]\n";
  1367. success $i;
  1368. }
  1369. my %config_ignore;
  1370. my %config_set;
  1371. my %config_list;
  1372. my %null_config;
  1373. my %dependency;
  1374. sub assign_configs {
  1375. my ($hash, $config) = @_;
  1376. open (IN, $config)
  1377. or dodie "Failed to read $config";
  1378. while (<IN>) {
  1379. if (/^((CONFIG\S*)=.*)/) {
  1380. ${$hash}{$2} = $1;
  1381. }
  1382. }
  1383. close(IN);
  1384. }
  1385. sub process_config_ignore {
  1386. my ($config) = @_;
  1387. assign_configs \%config_ignore, $config;
  1388. }
  1389. sub read_current_config {
  1390. my ($config_ref) = @_;
  1391. %{$config_ref} = ();
  1392. undef %{$config_ref};
  1393. my @key = keys %{$config_ref};
  1394. if ($#key >= 0) {
  1395. print "did not delete!\n";
  1396. exit;
  1397. }
  1398. open (IN, "$output_config");
  1399. while (<IN>) {
  1400. if (/^(CONFIG\S+)=(.*)/) {
  1401. ${$config_ref}{$1} = $2;
  1402. }
  1403. }
  1404. close(IN);
  1405. }
  1406. sub get_dependencies {
  1407. my ($config) = @_;
  1408. my $arr = $dependency{$config};
  1409. if (!defined($arr)) {
  1410. return ();
  1411. }
  1412. my @deps = @{$arr};
  1413. foreach my $dep (@{$arr}) {
  1414. print "ADD DEP $dep\n";
  1415. @deps = (@deps, get_dependencies $dep);
  1416. }
  1417. return @deps;
  1418. }
  1419. sub create_config {
  1420. my @configs = @_;
  1421. open(OUT, ">$output_config") or dodie "Can not write to $output_config";
  1422. foreach my $config (@configs) {
  1423. print OUT "$config_set{$config}\n";
  1424. my @deps = get_dependencies $config;
  1425. foreach my $dep (@deps) {
  1426. print OUT "$config_set{$dep}\n";
  1427. }
  1428. }
  1429. foreach my $config (keys %config_ignore) {
  1430. print OUT "$config_ignore{$config}\n";
  1431. }
  1432. close(OUT);
  1433. # exit;
  1434. make_oldconfig;
  1435. }
  1436. sub compare_configs {
  1437. my (%a, %b) = @_;
  1438. foreach my $item (keys %a) {
  1439. if (!defined($b{$item})) {
  1440. print "diff $item\n";
  1441. return 1;
  1442. }
  1443. delete $b{$item};
  1444. }
  1445. my @keys = keys %b;
  1446. if ($#keys) {
  1447. print "diff2 $keys[0]\n";
  1448. }
  1449. return -1 if ($#keys >= 0);
  1450. return 0;
  1451. }
  1452. sub run_config_bisect_test {
  1453. my ($type) = @_;
  1454. return run_bisect_test $type, "oldconfig";
  1455. }
  1456. sub process_passed {
  1457. my (%configs) = @_;
  1458. doprint "These configs had no failure: (Enabling them for further compiles)\n";
  1459. # Passed! All these configs are part of a good compile.
  1460. # Add them to the min options.
  1461. foreach my $config (keys %configs) {
  1462. if (defined($config_list{$config})) {
  1463. doprint " removing $config\n";
  1464. $config_ignore{$config} = $config_list{$config};
  1465. delete $config_list{$config};
  1466. }
  1467. }
  1468. doprint "config copied to $outputdir/config_good\n";
  1469. run_command "cp -f $output_config $outputdir/config_good";
  1470. }
  1471. sub process_failed {
  1472. my ($config) = @_;
  1473. doprint "\n\n***************************************\n";
  1474. doprint "Found bad config: $config\n";
  1475. doprint "***************************************\n\n";
  1476. }
  1477. sub run_config_bisect {
  1478. my @start_list = keys %config_list;
  1479. if ($#start_list < 0) {
  1480. doprint "No more configs to test!!!\n";
  1481. return -1;
  1482. }
  1483. doprint "***** RUN TEST ***\n";
  1484. my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
  1485. my $ret;
  1486. my %current_config;
  1487. my $count = $#start_list + 1;
  1488. doprint " $count configs to test\n";
  1489. my $half = int($#start_list / 2);
  1490. do {
  1491. my @tophalf = @start_list[0 .. $half];
  1492. create_config @tophalf;
  1493. read_current_config \%current_config;
  1494. $count = $#tophalf + 1;
  1495. doprint "Testing $count configs\n";
  1496. my $found = 0;
  1497. # make sure we test something
  1498. foreach my $config (@tophalf) {
  1499. if (defined($current_config{$config})) {
  1500. logit " $config\n";
  1501. $found = 1;
  1502. }
  1503. }
  1504. if (!$found) {
  1505. # try the other half
  1506. doprint "Top half produced no set configs, trying bottom half\n";
  1507. @tophalf = @start_list[$half + 1 .. $#start_list];
  1508. create_config @tophalf;
  1509. read_current_config \%current_config;
  1510. foreach my $config (@tophalf) {
  1511. if (defined($current_config{$config})) {
  1512. logit " $config\n";
  1513. $found = 1;
  1514. }
  1515. }
  1516. if (!$found) {
  1517. doprint "Failed: Can't make new config with current configs\n";
  1518. foreach my $config (@start_list) {
  1519. doprint " CONFIG: $config\n";
  1520. }
  1521. return -1;
  1522. }
  1523. $count = $#tophalf + 1;
  1524. doprint "Testing $count configs\n";
  1525. }
  1526. $ret = run_config_bisect_test $type;
  1527. if ($bisect_manual) {
  1528. $ret = answer_bisect;
  1529. }
  1530. if ($ret) {
  1531. process_passed %current_config;
  1532. return 0;
  1533. }
  1534. doprint "This config had a failure.\n";
  1535. doprint "Removing these configs that were not set in this config:\n";
  1536. doprint "config copied to $outputdir/config_bad\n";
  1537. run_command "cp -f $output_config $outputdir/config_bad";
  1538. # A config exists in this group that was bad.
  1539. foreach my $config (keys %config_list) {
  1540. if (!defined($current_config{$config})) {
  1541. doprint " removing $config\n";
  1542. delete $config_list{$config};
  1543. }
  1544. }
  1545. @start_list = @tophalf;
  1546. if ($#start_list == 0) {
  1547. process_failed $start_list[0];
  1548. return 1;
  1549. }
  1550. # remove half the configs we are looking at and see if
  1551. # they are good.
  1552. $half = int($#start_list / 2);
  1553. } while ($#start_list > 0);
  1554. # we found a single config, try it again unless we are running manually
  1555. if ($bisect_manual) {
  1556. process_failed $start_list[0];
  1557. return 1;
  1558. }
  1559. my @tophalf = @start_list[0 .. 0];
  1560. $ret = run_config_bisect_test $type;
  1561. if ($ret) {
  1562. process_passed %current_config;
  1563. return 0;
  1564. }
  1565. process_failed $start_list[0];
  1566. return 1;
  1567. }
  1568. sub config_bisect {
  1569. my ($i) = @_;
  1570. my $start_config = $opt{"CONFIG_BISECT[$i]"};
  1571. my $tmpconfig = "$tmpdir/use_config";
  1572. if (defined($config_bisect_good)) {
  1573. process_config_ignore $config_bisect_good;
  1574. }
  1575. # Make the file with the bad config and the min config
  1576. if (defined($minconfig)) {
  1577. # read the min config for things to ignore
  1578. run_command "cp $minconfig $tmpconfig" or
  1579. dodie "failed to copy $minconfig to $tmpconfig";
  1580. } else {
  1581. unlink $tmpconfig;
  1582. }
  1583. if (-f $tmpconfig) {
  1584. load_force_config($tmpconfig);
  1585. process_config_ignore $tmpconfig;
  1586. }
  1587. # now process the start config
  1588. run_command "cp $start_config $output_config" or
  1589. dodie "failed to copy $start_config to $output_config";
  1590. # read directly what we want to check
  1591. my %config_check;
  1592. open (IN, $output_config)
  1593. or dodie "faied to open $output_config";
  1594. while (<IN>) {
  1595. if (/^((CONFIG\S*)=.*)/) {
  1596. $config_check{$2} = $1;
  1597. }
  1598. }
  1599. close(IN);
  1600. # Now run oldconfig with the minconfig
  1601. make_oldconfig;
  1602. # check to see what we lost (or gained)
  1603. open (IN, $output_config)
  1604. or dodie "Failed to read $start_config";
  1605. my %removed_configs;
  1606. my %added_configs;
  1607. while (<IN>) {
  1608. if (/^((CONFIG\S*)=.*)/) {
  1609. # save off all options
  1610. $config_set{$2} = $1;
  1611. if (defined($config_check{$2})) {
  1612. if (defined($config_ignore{$2})) {
  1613. $removed_configs{$2} = $1;
  1614. } else {
  1615. $config_list{$2} = $1;
  1616. }
  1617. } elsif (!defined($config_ignore{$2})) {
  1618. $added_configs{$2} = $1;
  1619. $config_list{$2} = $1;
  1620. }
  1621. }
  1622. }
  1623. close(IN);
  1624. my @confs = keys %removed_configs;
  1625. if ($#confs >= 0) {
  1626. doprint "Configs overridden by default configs and removed from check:\n";
  1627. foreach my $config (@confs) {
  1628. doprint " $config\n";
  1629. }
  1630. }
  1631. @confs = keys %added_configs;
  1632. if ($#confs >= 0) {
  1633. doprint "Configs appearing in make oldconfig and added:\n";
  1634. foreach my $config (@confs) {
  1635. doprint " $config\n";
  1636. }
  1637. }
  1638. my %config_test;
  1639. my $once = 0;
  1640. # Sometimes kconfig does weird things. We must make sure
  1641. # that the config we autocreate has everything we need
  1642. # to test, otherwise we may miss testing configs, or
  1643. # may not be able to create a new config.
  1644. # Here we create a config with everything set.
  1645. create_config (keys %config_list);
  1646. read_current_config \%config_test;
  1647. foreach my $config (keys %config_list) {
  1648. if (!defined($config_test{$config})) {
  1649. if (!$once) {
  1650. $once = 1;
  1651. doprint "Configs not produced by kconfig (will not be checked):\n";
  1652. }
  1653. doprint " $config\n";
  1654. delete $config_list{$config};
  1655. }
  1656. }
  1657. my $ret;
  1658. do {
  1659. $ret = run_config_bisect;
  1660. } while (!$ret);
  1661. return $ret if ($ret < 0);
  1662. success $i;
  1663. }
  1664. sub patchcheck_reboot {
  1665. doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
  1666. reboot;
  1667. start_monitor;
  1668. wait_for_monitor $patchcheck_sleep_time;
  1669. end_monitor;
  1670. }
  1671. sub patchcheck {
  1672. my ($i) = @_;
  1673. die "PATCHCHECK_START[$i] not defined\n"
  1674. if (!defined($opt{"PATCHCHECK_START[$i]"}));
  1675. die "PATCHCHECK_TYPE[$i] not defined\n"
  1676. if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
  1677. my $start = $opt{"PATCHCHECK_START[$i]"};
  1678. my $end = "HEAD";
  1679. if (defined($opt{"PATCHCHECK_END[$i]"})) {
  1680. $end = $opt{"PATCHCHECK_END[$i]"};
  1681. }
  1682. # Get the true sha1's since we can use things like HEAD~3
  1683. $start = get_sha1($start);
  1684. $end = get_sha1($end);
  1685. my $type = $opt{"PATCHCHECK_TYPE[$i]"};
  1686. # Can't have a test without having a test to run
  1687. if ($type eq "test" && !defined($run_test)) {
  1688. $type = "boot";
  1689. }
  1690. open (IN, "git log --pretty=oneline $end|") or
  1691. dodie "could not get git list";
  1692. my @list;
  1693. while (<IN>) {
  1694. chomp;
  1695. $list[$#list+1] = $_;
  1696. last if (/^$start/);
  1697. }
  1698. close(IN);
  1699. if ($list[$#list] !~ /^$start/) {
  1700. fail "SHA1 $start not found";
  1701. }
  1702. # go backwards in the list
  1703. @list = reverse @list;
  1704. my $save_clean = $noclean;
  1705. my %ignored_warnings;
  1706. if (defined($ignore_warnings)) {
  1707. foreach my $sha1 (split /\s+/, $ignore_warnings) {
  1708. $ignored_warnings{$sha1} = 1;
  1709. }
  1710. }
  1711. $in_patchcheck = 1;
  1712. foreach my $item (@list) {
  1713. my $sha1 = $item;
  1714. $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
  1715. doprint "\nProcessing commit $item\n\n";
  1716. run_command "git checkout $sha1" or
  1717. die "Failed to checkout $sha1";
  1718. # only clean on the first and last patch
  1719. if ($item eq $list[0] ||
  1720. $item eq $list[$#list]) {
  1721. $noclean = $save_clean;
  1722. } else {
  1723. $noclean = 1;
  1724. }
  1725. if (defined($minconfig)) {
  1726. build "useconfig:$minconfig" or return 0;
  1727. } else {
  1728. # ?? no config to use?
  1729. build "oldconfig" or return 0;
  1730. }
  1731. if (!defined($ignored_warnings{$sha1})) {
  1732. check_buildlog $sha1 or return 0;
  1733. }
  1734. next if ($type eq "build");
  1735. my $failed = 0;
  1736. start_monitor_and_boot or $failed = 1;
  1737. if (!$failed && $type ne "boot"){
  1738. do_run_test or $failed = 1;
  1739. }
  1740. end_monitor;
  1741. return 0 if ($failed);
  1742. patchcheck_reboot;
  1743. }
  1744. $in_patchcheck = 0;
  1745. success $i;
  1746. return 1;
  1747. }
  1748. my %depends;
  1749. my $iflevel = 0;
  1750. my @ifdeps;
  1751. # prevent recursion
  1752. my %read_kconfigs;
  1753. # taken from streamline_config.pl
  1754. sub read_kconfig {
  1755. my ($kconfig) = @_;
  1756. my $state = "NONE";
  1757. my $config;
  1758. my @kconfigs;
  1759. my $cont = 0;
  1760. my $line;
  1761. if (! -f $kconfig) {
  1762. doprint "file $kconfig does not exist, skipping\n";
  1763. return;
  1764. }
  1765. open(KIN, "$kconfig")
  1766. or die "Can't open $kconfig";
  1767. while (<KIN>) {
  1768. chomp;
  1769. # Make sure that lines ending with \ continue
  1770. if ($cont) {
  1771. $_ = $line . " " . $_;
  1772. }
  1773. if (s/\\$//) {
  1774. $cont = 1;
  1775. $line = $_;
  1776. next;
  1777. }
  1778. $cont = 0;
  1779. # collect any Kconfig sources
  1780. if (/^source\s*"(.*)"/) {
  1781. $kconfigs[$#kconfigs+1] = $1;
  1782. }
  1783. # configs found
  1784. if (/^\s*(menu)?config\s+(\S+)\s*$/) {
  1785. $state = "NEW";
  1786. $config = $2;
  1787. for (my $i = 0; $i < $iflevel; $i++) {
  1788. if ($i) {
  1789. $depends{$config} .= " " . $ifdeps[$i];
  1790. } else {
  1791. $depends{$config} = $ifdeps[$i];
  1792. }
  1793. $state = "DEP";
  1794. }
  1795. # collect the depends for the config
  1796. } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
  1797. if (defined($depends{$1})) {
  1798. $depends{$config} .= " " . $1;
  1799. } else {
  1800. $depends{$config} = $1;
  1801. }
  1802. # Get the configs that select this config
  1803. } elsif ($state ne "NONE" && /^\s*select\s+(\S+)/) {
  1804. if (defined($depends{$1})) {
  1805. $depends{$1} .= " " . $config;
  1806. } else {
  1807. $depends{$1} = $config;
  1808. }
  1809. # Check for if statements
  1810. } elsif (/^if\s+(.*\S)\s*$/) {
  1811. my $deps = $1;
  1812. # remove beginning and ending non text
  1813. $deps =~ s/^[^a-zA-Z0-9_]*//;
  1814. $deps =~ s/[^a-zA-Z0-9_]*$//;
  1815. my @deps = split /[^a-zA-Z0-9_]+/, $deps;
  1816. $ifdeps[$iflevel++] = join ':', @deps;
  1817. } elsif (/^endif/) {
  1818. $iflevel-- if ($iflevel);
  1819. # stop on "help"
  1820. } elsif (/^\s*help\s*$/) {
  1821. $state = "NONE";
  1822. }
  1823. }
  1824. close(KIN);
  1825. # read in any configs that were found.
  1826. foreach $kconfig (@kconfigs) {
  1827. if (!defined($read_kconfigs{$kconfig})) {
  1828. $read_kconfigs{$kconfig} = 1;
  1829. read_kconfig("$builddir/$kconfig");
  1830. }
  1831. }
  1832. }
  1833. sub read_depends {
  1834. # find out which arch this is by the kconfig file
  1835. open (IN, $output_config)
  1836. or dodie "Failed to read $output_config";
  1837. my $arch;
  1838. while (<IN>) {
  1839. if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
  1840. $arch = $1;
  1841. last;
  1842. }
  1843. }
  1844. close IN;
  1845. if (!defined($arch)) {
  1846. doprint "Could not find arch from config file\n";
  1847. doprint "no dependencies used\n";
  1848. return;
  1849. }
  1850. # arch is really the subarch, we need to know
  1851. # what directory to look at.
  1852. if ($arch eq "i386" || $arch eq "x86_64") {
  1853. $arch = "x86";
  1854. } elsif ($arch =~ /^tile/) {
  1855. $arch = "tile";
  1856. }
  1857. my $kconfig = "$builddir/arch/$arch/Kconfig";
  1858. if (! -f $kconfig && $arch =~ /\d$/) {
  1859. my $orig = $arch;
  1860. # some subarchs have numbers, truncate them
  1861. $arch =~ s/\d*$//;
  1862. $kconfig = "$builddir/arch/$arch/Kconfig";
  1863. if (! -f $kconfig) {
  1864. doprint "No idea what arch dir $orig is for\n";
  1865. doprint "no dependencies used\n";
  1866. return;
  1867. }
  1868. }
  1869. read_kconfig($kconfig);
  1870. }
  1871. sub read_config_list {
  1872. my ($config) = @_;
  1873. open (IN, $config)
  1874. or dodie "Failed to read $config";
  1875. while (<IN>) {
  1876. if (/^((CONFIG\S*)=.*)/) {
  1877. if (!defined($config_ignore{$2})) {
  1878. $config_list{$2} = $1;
  1879. }
  1880. }
  1881. }
  1882. close(IN);
  1883. }
  1884. sub read_output_config {
  1885. my ($config) = @_;
  1886. assign_configs \%config_ignore, $config;
  1887. }
  1888. sub make_new_config {
  1889. my @configs = @_;
  1890. open (OUT, ">$output_config")
  1891. or dodie "Failed to write $output_config";
  1892. foreach my $config (@configs) {
  1893. print OUT "$config\n";
  1894. }
  1895. close OUT;
  1896. }
  1897. sub get_depends {
  1898. my ($dep) = @_;
  1899. my $kconfig = $dep;
  1900. $kconfig =~ s/CONFIG_//;
  1901. $dep = $depends{"$kconfig"};
  1902. # the dep string we have saves the dependencies as they
  1903. # were found, including expressions like ! && ||. We
  1904. # want to split this out into just an array of configs.
  1905. my $valid = "A-Za-z_0-9";
  1906. my @configs;
  1907. while ($dep =~ /[$valid]/) {
  1908. if ($dep =~ /^[^$valid]*([$valid]+)/) {
  1909. my $conf = "CONFIG_" . $1;
  1910. $configs[$#configs + 1] = $conf;
  1911. $dep =~ s/^[^$valid]*[$valid]+//;
  1912. } else {
  1913. die "this should never happen";
  1914. }
  1915. }
  1916. return @configs;
  1917. }
  1918. my %min_configs;
  1919. my %keep_configs;
  1920. my %save_configs;
  1921. my %processed_configs;
  1922. my %nochange_config;
  1923. sub test_this_config {
  1924. my ($config) = @_;
  1925. my $found;
  1926. # if we already processed this config, skip it
  1927. if (defined($processed_configs{$config})) {
  1928. return undef;
  1929. }
  1930. $processed_configs{$config} = 1;
  1931. # if this config failed during this round, skip it
  1932. if (defined($nochange_config{$config})) {
  1933. return undef;
  1934. }
  1935. my $kconfig = $config;
  1936. $kconfig =~ s/CONFIG_//;
  1937. # Test dependencies first
  1938. if (defined($depends{"$kconfig"})) {
  1939. my @parents = get_depends $config;
  1940. foreach my $parent (@parents) {
  1941. # if the parent is in the min config, check it first
  1942. next if (!defined($min_configs{$parent}));
  1943. $found = test_this_config($parent);
  1944. if (defined($found)) {
  1945. return $found;
  1946. }
  1947. }
  1948. }
  1949. # Remove this config from the list of configs
  1950. # do a make oldnoconfig and then read the resulting
  1951. # .config to make sure it is missing the config that
  1952. # we had before
  1953. my %configs = %min_configs;
  1954. delete $configs{$config};
  1955. make_new_config ((values %configs), (values %keep_configs));
  1956. make_oldconfig;
  1957. undef %configs;
  1958. assign_configs \%configs, $output_config;
  1959. return $config if (!defined($configs{$config}));
  1960. doprint "disabling config $config did not change .config\n";
  1961. $nochange_config{$config} = 1;
  1962. return undef;
  1963. }
  1964. sub make_min_config {
  1965. my ($i) = @_;
  1966. if (!defined($output_minconfig)) {
  1967. fail "OUTPUT_MIN_CONFIG not defined" and return;
  1968. }
  1969. # If output_minconfig exists, and the start_minconfig
  1970. # came from min_config, than ask if we should use
  1971. # that instead.
  1972. if (-f $output_minconfig && !$start_minconfig_defined) {
  1973. print "$output_minconfig exists\n";
  1974. if (read_yn " Use it as minconfig?") {
  1975. $start_minconfig = $output_minconfig;
  1976. }
  1977. }
  1978. if (!defined($start_minconfig)) {
  1979. fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
  1980. }
  1981. my $temp_config = "$tmpdir/temp_config";
  1982. # First things first. We build an allnoconfig to find
  1983. # out what the defaults are that we can't touch.
  1984. # Some are selections, but we really can't handle selections.
  1985. my $save_minconfig = $minconfig;
  1986. undef $minconfig;
  1987. run_command "$make allnoconfig" or return 0;
  1988. read_depends;
  1989. process_config_ignore $output_config;
  1990. undef %save_configs;
  1991. undef %min_configs;
  1992. if (defined($ignore_config)) {
  1993. # make sure the file exists
  1994. `touch $ignore_config`;
  1995. assign_configs \%save_configs, $ignore_config;
  1996. }
  1997. %keep_configs = %save_configs;
  1998. doprint "Load initial configs from $start_minconfig\n";
  1999. # Look at the current min configs, and save off all the
  2000. # ones that were set via the allnoconfig
  2001. assign_configs \%min_configs, $start_minconfig;
  2002. my @config_keys = keys %min_configs;
  2003. # Remove anything that was set by the make allnoconfig
  2004. # we shouldn't need them as they get set for us anyway.
  2005. foreach my $config (@config_keys) {
  2006. # Remove anything in the ignore_config
  2007. if (defined($keep_configs{$config})) {
  2008. my $file = $ignore_config;
  2009. $file =~ s,.*/(.*?)$,$1,;
  2010. doprint "$config set by $file ... ignored\n";
  2011. delete $min_configs{$config};
  2012. next;
  2013. }
  2014. # But make sure the settings are the same. If a min config
  2015. # sets a selection, we do not want to get rid of it if
  2016. # it is not the same as what we have. Just move it into
  2017. # the keep configs.
  2018. if (defined($config_ignore{$config})) {
  2019. if ($config_ignore{$config} ne $min_configs{$config}) {
  2020. doprint "$config is in allnoconfig as '$config_ignore{$config}'";
  2021. doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
  2022. $keep_configs{$config} = $min_configs{$config};
  2023. } else {
  2024. doprint "$config set by allnoconfig ... ignored\n";
  2025. }
  2026. delete $min_configs{$config};
  2027. }
  2028. }
  2029. my $done = 0;
  2030. my $take_two = 0;
  2031. while (!$done) {
  2032. my $config;
  2033. my $found;
  2034. # Now disable each config one by one and do a make oldconfig
  2035. # till we find a config that changes our list.
  2036. # Put configs that did not modify the config at the end.
  2037. my @test_configs = keys %min_configs;
  2038. my $reset = 1;
  2039. for (my $i = 0; $i < $#test_configs; $i++) {
  2040. if (!defined($nochange_config{$test_configs[0]})) {
  2041. $reset = 0;
  2042. last;
  2043. }
  2044. # This config didn't change the .config last time.
  2045. # Place it at the end
  2046. my $config = shift @test_configs;
  2047. push @test_configs, $config;
  2048. }
  2049. # if every test config has failed to modify the .config file
  2050. # in the past, then reset and start over.
  2051. if ($reset) {
  2052. undef %nochange_config;
  2053. }
  2054. undef %processed_configs;
  2055. foreach my $config (@test_configs) {
  2056. $found = test_this_config $config;
  2057. last if (defined($found));
  2058. # oh well, try another config
  2059. }
  2060. if (!defined($found)) {
  2061. # we could have failed due to the nochange_config hash
  2062. # reset and try again
  2063. if (!$take_two) {
  2064. undef %nochange_config;
  2065. $take_two = 1;
  2066. next;
  2067. }
  2068. doprint "No more configs found that we can disable\n";
  2069. $done = 1;
  2070. last;
  2071. }
  2072. $take_two = 0;
  2073. $config = $found;
  2074. doprint "Test with $config disabled\n";
  2075. # set in_bisect to keep build and monitor from dieing
  2076. $in_bisect = 1;
  2077. my $failed = 0;
  2078. build "oldconfig";
  2079. start_monitor_and_boot or $failed = 1;
  2080. end_monitor;
  2081. $in_bisect = 0;
  2082. if ($failed) {
  2083. doprint "$min_configs{$config} is needed to boot the box... keeping\n";
  2084. # this config is needed, add it to the ignore list.
  2085. $keep_configs{$config} = $min_configs{$config};
  2086. $save_configs{$config} = $min_configs{$config};
  2087. delete $min_configs{$config};
  2088. # update new ignore configs
  2089. if (defined($ignore_config)) {
  2090. open (OUT, ">$temp_config")
  2091. or die "Can't write to $temp_config";
  2092. foreach my $config (keys %save_configs) {
  2093. print OUT "$save_configs{$config}\n";
  2094. }
  2095. close OUT;
  2096. run_command "mv $temp_config $ignore_config" or
  2097. dodie "failed to copy update to $ignore_config";
  2098. }
  2099. } else {
  2100. # We booted without this config, remove it from the minconfigs.
  2101. doprint "$config is not needed, disabling\n";
  2102. delete $min_configs{$config};
  2103. # Also disable anything that is not enabled in this config
  2104. my %configs;
  2105. assign_configs \%configs, $output_config;
  2106. my @config_keys = keys %min_configs;
  2107. foreach my $config (@config_keys) {
  2108. if (!defined($configs{$config})) {
  2109. doprint "$config is not set, disabling\n";
  2110. delete $min_configs{$config};
  2111. }
  2112. }
  2113. # Save off all the current mandidory configs
  2114. open (OUT, ">$temp_config")
  2115. or die "Can't write to $temp_config";
  2116. foreach my $config (keys %keep_configs) {
  2117. print OUT "$keep_configs{$config}\n";
  2118. }
  2119. foreach my $config (keys %min_configs) {
  2120. print OUT "$min_configs{$config}\n";
  2121. }
  2122. close OUT;
  2123. run_command "mv $temp_config $output_minconfig" or
  2124. dodie "failed to copy update to $output_minconfig";
  2125. }
  2126. doprint "Reboot and wait $sleep_time seconds\n";
  2127. reboot;
  2128. start_monitor;
  2129. wait_for_monitor $sleep_time;
  2130. end_monitor;
  2131. }
  2132. success $i;
  2133. return 1;
  2134. }
  2135. $#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
  2136. if ($#ARGV == 0) {
  2137. $ktest_config = $ARGV[0];
  2138. if (! -f $ktest_config) {
  2139. print "$ktest_config does not exist.\n";
  2140. if (!read_yn "Create it?") {
  2141. exit 0;
  2142. }
  2143. }
  2144. } else {
  2145. $ktest_config = "ktest.conf";
  2146. }
  2147. if (! -f $ktest_config) {
  2148. open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
  2149. print OUT << "EOF"
  2150. # Generated by ktest.pl
  2151. #
  2152. # Define each test with TEST_START
  2153. # The config options below it will override the defaults
  2154. TEST_START
  2155. DEFAULTS
  2156. EOF
  2157. ;
  2158. close(OUT);
  2159. }
  2160. read_config $ktest_config;
  2161. if (defined($opt{"LOG_FILE"})) {
  2162. $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
  2163. }
  2164. # Append any configs entered in manually to the config file.
  2165. my @new_configs = keys %entered_configs;
  2166. if ($#new_configs >= 0) {
  2167. print "\nAppending entered in configs to $ktest_config\n";
  2168. open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
  2169. foreach my $config (@new_configs) {
  2170. print OUT "$config = $entered_configs{$config}\n";
  2171. $opt{$config} = $entered_configs{$config};
  2172. }
  2173. }
  2174. if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
  2175. unlink $opt{"LOG_FILE"};
  2176. }
  2177. doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
  2178. for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
  2179. if (!$i) {
  2180. doprint "DEFAULT OPTIONS:\n";
  2181. } else {
  2182. doprint "\nTEST $i OPTIONS";
  2183. if (defined($repeat_tests{$i})) {
  2184. $repeat = $repeat_tests{$i};
  2185. doprint " ITERATE $repeat";
  2186. }
  2187. doprint "\n";
  2188. }
  2189. foreach my $option (sort keys %opt) {
  2190. if ($option =~ /\[(\d+)\]$/) {
  2191. next if ($i != $1);
  2192. } else {
  2193. next if ($i);
  2194. }
  2195. doprint "$option = $opt{$option}\n";
  2196. }
  2197. }
  2198. sub __set_test_option {
  2199. my ($name, $i) = @_;
  2200. my $option = "$name\[$i\]";
  2201. if (defined($opt{$option})) {
  2202. return $opt{$option};
  2203. }
  2204. foreach my $test (keys %repeat_tests) {
  2205. if ($i >= $test &&
  2206. $i < $test + $repeat_tests{$test}) {
  2207. $option = "$name\[$test\]";
  2208. if (defined($opt{$option})) {
  2209. return $opt{$option};
  2210. }
  2211. }
  2212. }
  2213. if (defined($opt{$name})) {
  2214. return $opt{$name};
  2215. }
  2216. return undef;
  2217. }
  2218. sub set_test_option {
  2219. my ($name, $i) = @_;
  2220. my $option = __set_test_option($name, $i);
  2221. return $option if (!defined($option));
  2222. return eval_option($option, $i);
  2223. }
  2224. # First we need to do is the builds
  2225. for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
  2226. $iteration = $i;
  2227. my $makecmd = set_test_option("MAKE_CMD", $i);
  2228. $machine = set_test_option("MACHINE", $i);
  2229. $ssh_user = set_test_option("SSH_USER", $i);
  2230. $tmpdir = set_test_option("TMP_DIR", $i);
  2231. $outputdir = set_test_option("OUTPUT_DIR", $i);
  2232. $builddir = set_test_option("BUILD_DIR", $i);
  2233. $test_type = set_test_option("TEST_TYPE", $i);
  2234. $build_type = set_test_option("BUILD_TYPE", $i);
  2235. $build_options = set_test_option("BUILD_OPTIONS", $i);
  2236. $pre_build = set_test_option("PRE_BUILD", $i);
  2237. $post_build = set_test_option("POST_BUILD", $i);
  2238. $pre_build_die = set_test_option("PRE_BUILD_DIE", $i);
  2239. $post_build_die = set_test_option("POST_BUILD_DIE", $i);
  2240. $power_cycle = set_test_option("POWER_CYCLE", $i);
  2241. $reboot = set_test_option("REBOOT", $i);
  2242. $noclean = set_test_option("BUILD_NOCLEAN", $i);
  2243. $minconfig = set_test_option("MIN_CONFIG", $i);
  2244. $output_minconfig = set_test_option("OUTPUT_MIN_CONFIG", $i);
  2245. $start_minconfig = set_test_option("START_MIN_CONFIG", $i);
  2246. $ignore_config = set_test_option("IGNORE_CONFIG", $i);
  2247. $run_test = set_test_option("TEST", $i);
  2248. $addconfig = set_test_option("ADD_CONFIG", $i);
  2249. $reboot_type = set_test_option("REBOOT_TYPE", $i);
  2250. $grub_menu = set_test_option("GRUB_MENU", $i);
  2251. $post_install = set_test_option("POST_INSTALL", $i);
  2252. $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
  2253. $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
  2254. $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
  2255. $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
  2256. $power_off = set_test_option("POWER_OFF", $i);
  2257. $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
  2258. $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
  2259. $sleep_time = set_test_option("SLEEP_TIME", $i);
  2260. $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
  2261. $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
  2262. $ignore_warnings = set_test_option("IGNORE_WARNINGS", $i);
  2263. $bisect_manual = set_test_option("BISECT_MANUAL", $i);
  2264. $bisect_skip = set_test_option("BISECT_SKIP", $i);
  2265. $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i);
  2266. $store_failures = set_test_option("STORE_FAILURES", $i);
  2267. $test_name = set_test_option("TEST_NAME", $i);
  2268. $timeout = set_test_option("TIMEOUT", $i);
  2269. $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
  2270. $console = set_test_option("CONSOLE", $i);
  2271. $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
  2272. $success_line = set_test_option("SUCCESS_LINE", $i);
  2273. $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
  2274. $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
  2275. $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
  2276. $build_target = set_test_option("BUILD_TARGET", $i);
  2277. $ssh_exec = set_test_option("SSH_EXEC", $i);
  2278. $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
  2279. $target_image = set_test_option("TARGET_IMAGE", $i);
  2280. $localversion = set_test_option("LOCALVERSION", $i);
  2281. $start_minconfig_defined = 1;
  2282. if (!defined($start_minconfig)) {
  2283. $start_minconfig_defined = 0;
  2284. $start_minconfig = $minconfig;
  2285. }
  2286. chdir $builddir || die "can't change directory to $builddir";
  2287. if (!-d $tmpdir) {
  2288. mkpath($tmpdir) or
  2289. die "can't create $tmpdir";
  2290. }
  2291. $ENV{"SSH_USER"} = $ssh_user;
  2292. $ENV{"MACHINE"} = $machine;
  2293. $target = "$ssh_user\@$machine";
  2294. $buildlog = "$tmpdir/buildlog-$machine";
  2295. $dmesg = "$tmpdir/dmesg-$machine";
  2296. $make = "$makecmd O=$outputdir";
  2297. $output_config = "$outputdir/.config";
  2298. if ($reboot_type eq "grub") {
  2299. dodie "GRUB_MENU not defined" if (!defined($grub_menu));
  2300. } elsif (!defined($reboot_script)) {
  2301. dodie "REBOOT_SCRIPT not defined"
  2302. }
  2303. my $run_type = $build_type;
  2304. if ($test_type eq "patchcheck") {
  2305. $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
  2306. } elsif ($test_type eq "bisect") {
  2307. $run_type = $opt{"BISECT_TYPE[$i]"};
  2308. } elsif ($test_type eq "config_bisect") {
  2309. $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
  2310. }
  2311. if ($test_type eq "make_min_config") {
  2312. $run_type = "";
  2313. }
  2314. # mistake in config file?
  2315. if (!defined($run_type)) {
  2316. $run_type = "ERROR";
  2317. }
  2318. doprint "\n\n";
  2319. doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type\n\n";
  2320. unlink $dmesg;
  2321. unlink $buildlog;
  2322. if (defined($addconfig)) {
  2323. my $min = $minconfig;
  2324. if (!defined($minconfig)) {
  2325. $min = "";
  2326. }
  2327. run_command "cat $addconfig $min > $tmpdir/add_config" or
  2328. dodie "Failed to create temp config";
  2329. $minconfig = "$tmpdir/add_config";
  2330. }
  2331. my $checkout = $opt{"CHECKOUT[$i]"};
  2332. if (defined($checkout)) {
  2333. run_command "git checkout $checkout" or
  2334. die "failed to checkout $checkout";
  2335. }
  2336. if ($test_type eq "bisect") {
  2337. bisect $i;
  2338. next;
  2339. } elsif ($test_type eq "config_bisect") {
  2340. config_bisect $i;
  2341. next;
  2342. } elsif ($test_type eq "patchcheck") {
  2343. patchcheck $i;
  2344. next;
  2345. } elsif ($test_type eq "make_min_config") {
  2346. make_min_config $i;
  2347. next;
  2348. }
  2349. if ($build_type ne "nobuild") {
  2350. build $build_type or next;
  2351. }
  2352. if ($test_type ne "build") {
  2353. my $failed = 0;
  2354. start_monitor_and_boot or $failed = 1;
  2355. if (!$failed && $test_type ne "boot" && defined($run_test)) {
  2356. do_run_test or $failed = 1;
  2357. }
  2358. end_monitor;
  2359. next if ($failed);
  2360. }
  2361. success $i;
  2362. }
  2363. if ($opt{"POWEROFF_ON_SUCCESS"}) {
  2364. halt;
  2365. } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
  2366. reboot;
  2367. }
  2368. doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
  2369. exit 0;