ktest.pl 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369
  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";
  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 $reboot_type;
  61. my $reboot_script;
  62. my $power_cycle;
  63. my $reboot;
  64. my $reboot_on_error;
  65. my $poweroff_on_error;
  66. my $die_on_failure;
  67. my $powercycle_after_reboot;
  68. my $poweroff_after_halt;
  69. my $ssh_exec;
  70. my $scp_to_target;
  71. my $power_off;
  72. my $grub_menu;
  73. my $grub_number;
  74. my $target;
  75. my $make;
  76. my $post_install;
  77. my $noclean;
  78. my $minconfig;
  79. my $addconfig;
  80. my $in_bisect = 0;
  81. my $bisect_bad = "";
  82. my $reverse_bisect;
  83. my $bisect_manual;
  84. my $bisect_skip;
  85. my $config_bisect_good;
  86. my $in_patchcheck = 0;
  87. my $run_test;
  88. my $redirect;
  89. my $buildlog;
  90. my $dmesg;
  91. my $monitor_fp;
  92. my $monitor_pid;
  93. my $monitor_cnt = 0;
  94. my $sleep_time;
  95. my $bisect_sleep_time;
  96. my $patchcheck_sleep_time;
  97. my $store_failures;
  98. my $test_name;
  99. my $timeout;
  100. my $booted_timeout;
  101. my $detect_triplefault;
  102. my $console;
  103. my $success_line;
  104. my $stop_after_success;
  105. my $stop_after_failure;
  106. my $stop_test_after;
  107. my $build_target;
  108. my $target_image;
  109. my $localversion;
  110. my $iteration = 0;
  111. my $successes = 0;
  112. my %entered_configs;
  113. my %config_help;
  114. my %variable;
  115. my %force_config;
  116. $config_help{"MACHINE"} = << "EOF"
  117. The machine hostname that you will test.
  118. EOF
  119. ;
  120. $config_help{"SSH_USER"} = << "EOF"
  121. The box is expected to have ssh on normal bootup, provide the user
  122. (most likely root, since you need privileged operations)
  123. EOF
  124. ;
  125. $config_help{"BUILD_DIR"} = << "EOF"
  126. The directory that contains the Linux source code (full path).
  127. EOF
  128. ;
  129. $config_help{"OUTPUT_DIR"} = << "EOF"
  130. The directory that the objects will be built (full path).
  131. (can not be same as BUILD_DIR)
  132. EOF
  133. ;
  134. $config_help{"BUILD_TARGET"} = << "EOF"
  135. The location of the compiled file to copy to the target.
  136. (relative to OUTPUT_DIR)
  137. EOF
  138. ;
  139. $config_help{"TARGET_IMAGE"} = << "EOF"
  140. The place to put your image on the test machine.
  141. EOF
  142. ;
  143. $config_help{"POWER_CYCLE"} = << "EOF"
  144. A script or command to reboot the box.
  145. Here is a digital loggers power switch example
  146. POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
  147. Here is an example to reboot a virtual box on the current host
  148. with the name "Guest".
  149. POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
  150. EOF
  151. ;
  152. $config_help{"CONSOLE"} = << "EOF"
  153. The script or command that reads the console
  154. If you use ttywatch server, something like the following would work.
  155. CONSOLE = nc -d localhost 3001
  156. For a virtual machine with guest name "Guest".
  157. CONSOLE = virsh console Guest
  158. EOF
  159. ;
  160. $config_help{"LOCALVERSION"} = << "EOF"
  161. Required version ending to differentiate the test
  162. from other linux builds on the system.
  163. EOF
  164. ;
  165. $config_help{"REBOOT_TYPE"} = << "EOF"
  166. Way to reboot the box to the test kernel.
  167. Only valid options so far are "grub" and "script".
  168. If you specify grub, it will assume grub version 1
  169. and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
  170. and select that target to reboot to the kernel. If this is not
  171. your setup, then specify "script" and have a command or script
  172. specified in REBOOT_SCRIPT to boot to the target.
  173. The entry in /boot/grub/menu.lst must be entered in manually.
  174. The test will not modify that file.
  175. EOF
  176. ;
  177. $config_help{"GRUB_MENU"} = << "EOF"
  178. The grub title name for the test kernel to boot
  179. (Only mandatory if REBOOT_TYPE = grub)
  180. Note, ktest.pl will not update the grub menu.lst, you need to
  181. manually add an option for the test. ktest.pl will search
  182. the grub menu.lst for this option to find what kernel to
  183. reboot into.
  184. For example, if in the /boot/grub/menu.lst the test kernel title has:
  185. title Test Kernel
  186. kernel vmlinuz-test
  187. GRUB_MENU = Test Kernel
  188. EOF
  189. ;
  190. $config_help{"REBOOT_SCRIPT"} = << "EOF"
  191. A script to reboot the target into the test kernel
  192. (Only mandatory if REBOOT_TYPE = script)
  193. EOF
  194. ;
  195. sub get_ktest_config {
  196. my ($config) = @_;
  197. return if (defined($opt{$config}));
  198. if (defined($config_help{$config})) {
  199. print "\n";
  200. print $config_help{$config};
  201. }
  202. for (;;) {
  203. print "$config = ";
  204. if (defined($default{$config})) {
  205. print "\[$default{$config}\] ";
  206. }
  207. $entered_configs{$config} = <STDIN>;
  208. $entered_configs{$config} =~ s/^\s*(.*\S)\s*$/$1/;
  209. if ($entered_configs{$config} =~ /^\s*$/) {
  210. if ($default{$config}) {
  211. $entered_configs{$config} = $default{$config};
  212. } else {
  213. print "Your answer can not be blank\n";
  214. next;
  215. }
  216. }
  217. last;
  218. }
  219. }
  220. sub get_ktest_configs {
  221. get_ktest_config("MACHINE");
  222. get_ktest_config("SSH_USER");
  223. get_ktest_config("BUILD_DIR");
  224. get_ktest_config("OUTPUT_DIR");
  225. get_ktest_config("BUILD_TARGET");
  226. get_ktest_config("TARGET_IMAGE");
  227. get_ktest_config("POWER_CYCLE");
  228. get_ktest_config("CONSOLE");
  229. get_ktest_config("LOCALVERSION");
  230. my $rtype = $opt{"REBOOT_TYPE"};
  231. if (!defined($rtype)) {
  232. if (!defined($opt{"GRUB_MENU"})) {
  233. get_ktest_config("REBOOT_TYPE");
  234. $rtype = $entered_configs{"REBOOT_TYPE"};
  235. } else {
  236. $rtype = "grub";
  237. }
  238. }
  239. if ($rtype eq "grub") {
  240. get_ktest_config("GRUB_MENU");
  241. } else {
  242. get_ktest_config("REBOOT_SCRIPT");
  243. }
  244. }
  245. sub process_variables {
  246. my ($value) = @_;
  247. my $retval = "";
  248. # We want to check for '\', and it is just easier
  249. # to check the previous characet of '$' and not need
  250. # to worry if '$' is the first character. By adding
  251. # a space to $value, we can just check [^\\]\$ and
  252. # it will still work.
  253. $value = " $value";
  254. while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
  255. my $begin = $1;
  256. my $var = $2;
  257. my $end = $3;
  258. # append beginning of value to retval
  259. $retval = "$retval$begin";
  260. if (defined($variable{$var})) {
  261. $retval = "$retval$variable{$var}";
  262. } else {
  263. # put back the origin piece.
  264. $retval = "$retval\$\{$var\}";
  265. }
  266. $value = $end;
  267. }
  268. $retval = "$retval$value";
  269. # remove the space added in the beginning
  270. $retval =~ s/ //;
  271. return "$retval"
  272. }
  273. sub set_value {
  274. my ($lvalue, $rvalue) = @_;
  275. if (defined($opt{$lvalue})) {
  276. die "Error: Option $lvalue defined more than once!\n";
  277. }
  278. if ($rvalue =~ /^\s*$/) {
  279. delete $opt{$lvalue};
  280. } else {
  281. $rvalue = process_variables($rvalue);
  282. $opt{$lvalue} = $rvalue;
  283. }
  284. }
  285. sub set_variable {
  286. my ($lvalue, $rvalue) = @_;
  287. if ($rvalue =~ /^\s*$/) {
  288. delete $variable{$lvalue};
  289. } else {
  290. $rvalue = process_variables($rvalue);
  291. $variable{$lvalue} = $rvalue;
  292. }
  293. }
  294. sub read_config {
  295. my ($config) = @_;
  296. open(IN, $config) || die "can't read file $config";
  297. my $name = $config;
  298. $name =~ s,.*/(.*),$1,;
  299. my $test_num = 0;
  300. my $default = 1;
  301. my $repeat = 1;
  302. my $num_tests_set = 0;
  303. my $skip = 0;
  304. my $rest;
  305. while (<IN>) {
  306. # ignore blank lines and comments
  307. next if (/^\s*$/ || /\s*\#/);
  308. if (/^\s*TEST_START(.*)/) {
  309. $rest = $1;
  310. if ($num_tests_set) {
  311. die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
  312. }
  313. my $old_test_num = $test_num;
  314. my $old_repeat = $repeat;
  315. $test_num += $repeat;
  316. $default = 0;
  317. $repeat = 1;
  318. if ($rest =~ /\s+SKIP(.*)/) {
  319. $rest = $1;
  320. $skip = 1;
  321. } else {
  322. $skip = 0;
  323. }
  324. if ($rest =~ /\s+ITERATE\s+(\d+)(.*)$/) {
  325. $repeat = $1;
  326. $rest = $2;
  327. $repeat_tests{"$test_num"} = $repeat;
  328. }
  329. if ($rest =~ /\s+SKIP(.*)/) {
  330. $rest = $1;
  331. $skip = 1;
  332. }
  333. if ($rest !~ /^\s*$/) {
  334. die "$name: $.: Gargbage found after TEST_START\n$_";
  335. }
  336. if ($skip) {
  337. $test_num = $old_test_num;
  338. $repeat = $old_repeat;
  339. }
  340. } elsif (/^\s*DEFAULTS(.*)$/) {
  341. $default = 1;
  342. $rest = $1;
  343. if ($rest =~ /\s+SKIP(.*)/) {
  344. $rest = $1;
  345. $skip = 1;
  346. } else {
  347. $skip = 0;
  348. }
  349. if ($rest !~ /^\s*$/) {
  350. die "$name: $.: Gargbage found after DEFAULTS\n$_";
  351. }
  352. } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
  353. next if ($skip);
  354. my $lvalue = $1;
  355. my $rvalue = $2;
  356. if (!$default &&
  357. ($lvalue eq "NUM_TESTS" ||
  358. $lvalue eq "LOG_FILE" ||
  359. $lvalue eq "CLEAR_LOG")) {
  360. die "$name: $.: $lvalue must be set in DEFAULTS section\n";
  361. }
  362. if ($lvalue eq "NUM_TESTS") {
  363. if ($test_num) {
  364. die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
  365. }
  366. if (!$default) {
  367. die "$name: $.: NUM_TESTS must be set in default section\n";
  368. }
  369. $num_tests_set = 1;
  370. }
  371. if ($default || $lvalue =~ /\[\d+\]$/) {
  372. set_value($lvalue, $rvalue);
  373. } else {
  374. my $val = "$lvalue\[$test_num\]";
  375. set_value($val, $rvalue);
  376. if ($repeat > 1) {
  377. $repeats{$val} = $repeat;
  378. }
  379. }
  380. } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
  381. next if ($skip);
  382. my $lvalue = $1;
  383. my $rvalue = $2;
  384. # process config variables.
  385. # Config variables are only active while reading the
  386. # config and can be defined anywhere. They also ignore
  387. # TEST_START and DEFAULTS, but are skipped if they are in
  388. # on of these sections that have SKIP defined.
  389. # The save variable can be
  390. # defined multiple times and the new one simply overrides
  391. # the prevous one.
  392. set_variable($lvalue, $rvalue);
  393. } else {
  394. die "$name: $.: Garbage found in config\n$_";
  395. }
  396. }
  397. close(IN);
  398. if ($test_num) {
  399. $test_num += $repeat - 1;
  400. $opt{"NUM_TESTS"} = $test_num;
  401. }
  402. # make sure we have all mandatory configs
  403. get_ktest_configs;
  404. # set any defaults
  405. foreach my $default (keys %default) {
  406. if (!defined($opt{$default})) {
  407. $opt{$default} = $default{$default};
  408. }
  409. }
  410. }
  411. sub _logit {
  412. if (defined($opt{"LOG_FILE"})) {
  413. open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
  414. print OUT @_;
  415. close(OUT);
  416. }
  417. }
  418. sub logit {
  419. if (defined($opt{"LOG_FILE"})) {
  420. _logit @_;
  421. } else {
  422. print @_;
  423. }
  424. }
  425. sub doprint {
  426. print @_;
  427. _logit @_;
  428. }
  429. sub run_command;
  430. sub reboot {
  431. # try to reboot normally
  432. if (run_command $reboot) {
  433. if (defined($powercycle_after_reboot)) {
  434. sleep $powercycle_after_reboot;
  435. run_command "$power_cycle";
  436. }
  437. } else {
  438. # nope? power cycle it.
  439. run_command "$power_cycle";
  440. }
  441. }
  442. sub do_not_reboot {
  443. my $i = $iteration;
  444. return $test_type eq "build" ||
  445. ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
  446. ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
  447. }
  448. sub dodie {
  449. doprint "CRITICAL FAILURE... ", @_, "\n";
  450. my $i = $iteration;
  451. if ($reboot_on_error && !do_not_reboot) {
  452. doprint "REBOOTING\n";
  453. reboot;
  454. } elsif ($poweroff_on_error && defined($power_off)) {
  455. doprint "POWERING OFF\n";
  456. `$power_off`;
  457. }
  458. if (defined($opt{"LOG_FILE"})) {
  459. print " See $opt{LOG_FILE} for more info.\n";
  460. }
  461. die @_, "\n";
  462. }
  463. sub open_console {
  464. my ($fp) = @_;
  465. my $flags;
  466. my $pid = open($fp, "$console|") or
  467. dodie "Can't open console $console";
  468. $flags = fcntl($fp, F_GETFL, 0) or
  469. dodie "Can't get flags for the socket: $!";
  470. $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
  471. dodie "Can't set flags for the socket: $!";
  472. return $pid;
  473. }
  474. sub close_console {
  475. my ($fp, $pid) = @_;
  476. doprint "kill child process $pid\n";
  477. kill 2, $pid;
  478. print "closing!\n";
  479. close($fp);
  480. }
  481. sub start_monitor {
  482. if ($monitor_cnt++) {
  483. return;
  484. }
  485. $monitor_fp = \*MONFD;
  486. $monitor_pid = open_console $monitor_fp;
  487. return;
  488. open(MONFD, "Stop perl from warning about single use of MONFD");
  489. }
  490. sub end_monitor {
  491. if (--$monitor_cnt) {
  492. return;
  493. }
  494. close_console($monitor_fp, $monitor_pid);
  495. }
  496. sub wait_for_monitor {
  497. my ($time) = @_;
  498. my $line;
  499. doprint "** Wait for monitor to settle down **\n";
  500. # read the monitor and wait for the system to calm down
  501. do {
  502. $line = wait_for_input($monitor_fp, $time);
  503. print "$line" if (defined($line));
  504. } while (defined($line));
  505. print "** Monitor flushed **\n";
  506. }
  507. sub fail {
  508. if ($die_on_failure) {
  509. dodie @_;
  510. }
  511. doprint "FAILED\n";
  512. my $i = $iteration;
  513. # no need to reboot for just building.
  514. if (!do_not_reboot) {
  515. doprint "REBOOTING\n";
  516. reboot;
  517. start_monitor;
  518. wait_for_monitor $sleep_time;
  519. end_monitor;
  520. }
  521. my $name = "";
  522. if (defined($test_name)) {
  523. $name = " ($test_name)";
  524. }
  525. doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
  526. doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
  527. doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
  528. doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
  529. doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
  530. return 1 if (!defined($store_failures));
  531. my @t = localtime;
  532. my $date = sprintf "%04d%02d%02d%02d%02d%02d",
  533. 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
  534. my $type = $build_type;
  535. if ($type =~ /useconfig/) {
  536. $type = "useconfig";
  537. }
  538. my $dir = "$machine-$test_type-$type-fail-$date";
  539. my $faildir = "$store_failures/$dir";
  540. if (!-d $faildir) {
  541. mkpath($faildir) or
  542. die "can't create $faildir";
  543. }
  544. if (-f "$output_config") {
  545. cp "$output_config", "$faildir/config" or
  546. die "failed to copy .config";
  547. }
  548. if (-f $buildlog) {
  549. cp $buildlog, "$faildir/buildlog" or
  550. die "failed to move $buildlog";
  551. }
  552. if (-f $dmesg) {
  553. cp $dmesg, "$faildir/dmesg" or
  554. die "failed to move $dmesg";
  555. }
  556. doprint "*** Saved info to $faildir ***\n";
  557. return 1;
  558. }
  559. sub run_command {
  560. my ($command) = @_;
  561. my $dolog = 0;
  562. my $dord = 0;
  563. my $pid;
  564. $command =~ s/\$SSH_USER/$ssh_user/g;
  565. $command =~ s/\$MACHINE/$machine/g;
  566. doprint("$command ... ");
  567. $pid = open(CMD, "$command 2>&1 |") or
  568. (fail "unable to exec $command" and return 0);
  569. if (defined($opt{"LOG_FILE"})) {
  570. open(LOG, ">>$opt{LOG_FILE}") or
  571. dodie "failed to write to log";
  572. $dolog = 1;
  573. }
  574. if (defined($redirect)) {
  575. open (RD, ">$redirect") or
  576. dodie "failed to write to redirect $redirect";
  577. $dord = 1;
  578. }
  579. while (<CMD>) {
  580. print LOG if ($dolog);
  581. print RD if ($dord);
  582. }
  583. waitpid($pid, 0);
  584. my $failed = $?;
  585. close(CMD);
  586. close(LOG) if ($dolog);
  587. close(RD) if ($dord);
  588. if ($failed) {
  589. doprint "FAILED!\n";
  590. } else {
  591. doprint "SUCCESS\n";
  592. }
  593. return !$failed;
  594. }
  595. sub run_ssh {
  596. my ($cmd) = @_;
  597. my $cp_exec = $ssh_exec;
  598. $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
  599. return run_command "$cp_exec";
  600. }
  601. sub run_scp {
  602. my ($src, $dst) = @_;
  603. my $cp_scp = $scp_to_target;
  604. $cp_scp =~ s/\$SRC_FILE/$src/g;
  605. $cp_scp =~ s/\$DST_FILE/$dst/g;
  606. return run_command "$cp_scp";
  607. }
  608. sub get_grub_index {
  609. if ($reboot_type ne "grub") {
  610. return;
  611. }
  612. return if (defined($grub_number));
  613. doprint "Find grub menu ... ";
  614. $grub_number = -1;
  615. my $ssh_grub = $ssh_exec;
  616. $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
  617. open(IN, "$ssh_grub |")
  618. or die "unable to get menu.lst";
  619. while (<IN>) {
  620. if (/^\s*title\s+$grub_menu\s*$/) {
  621. $grub_number++;
  622. last;
  623. } elsif (/^\s*title\s/) {
  624. $grub_number++;
  625. }
  626. }
  627. close(IN);
  628. die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
  629. if ($grub_number < 0);
  630. doprint "$grub_number\n";
  631. }
  632. sub wait_for_input
  633. {
  634. my ($fp, $time) = @_;
  635. my $rin;
  636. my $ready;
  637. my $line;
  638. my $ch;
  639. if (!defined($time)) {
  640. $time = $timeout;
  641. }
  642. $rin = '';
  643. vec($rin, fileno($fp), 1) = 1;
  644. $ready = select($rin, undef, undef, $time);
  645. $line = "";
  646. # try to read one char at a time
  647. while (sysread $fp, $ch, 1) {
  648. $line .= $ch;
  649. last if ($ch eq "\n");
  650. }
  651. if (!length($line)) {
  652. return undef;
  653. }
  654. return $line;
  655. }
  656. sub reboot_to {
  657. if ($reboot_type eq "grub") {
  658. run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch && reboot)'";
  659. return;
  660. }
  661. run_command "$reboot_script";
  662. }
  663. sub get_sha1 {
  664. my ($commit) = @_;
  665. doprint "git rev-list --max-count=1 $commit ... ";
  666. my $sha1 = `git rev-list --max-count=1 $commit`;
  667. my $ret = $?;
  668. logit $sha1;
  669. if ($ret) {
  670. doprint "FAILED\n";
  671. dodie "Failed to get git $commit";
  672. }
  673. print "SUCCESS\n";
  674. chomp $sha1;
  675. return $sha1;
  676. }
  677. sub monitor {
  678. my $booted = 0;
  679. my $bug = 0;
  680. my $skip_call_trace = 0;
  681. my $loops;
  682. wait_for_monitor 5;
  683. my $line;
  684. my $full_line = "";
  685. open(DMESG, "> $dmesg") or
  686. die "unable to write to $dmesg";
  687. reboot_to;
  688. my $success_start;
  689. my $failure_start;
  690. my $monitor_start = time;
  691. my $done = 0;
  692. my $version_found = 0;
  693. while (!$done) {
  694. if ($bug && defined($stop_after_failure) &&
  695. $stop_after_failure >= 0) {
  696. my $time = $stop_after_failure - (time - $failure_start);
  697. $line = wait_for_input($monitor_fp, $time);
  698. if (!defined($line)) {
  699. doprint "bug timed out after $booted_timeout seconds\n";
  700. doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
  701. last;
  702. }
  703. } elsif ($booted) {
  704. $line = wait_for_input($monitor_fp, $booted_timeout);
  705. if (!defined($line)) {
  706. my $s = $booted_timeout == 1 ? "" : "s";
  707. doprint "Successful boot found: break after $booted_timeout second$s\n";
  708. last;
  709. }
  710. } else {
  711. $line = wait_for_input($monitor_fp);
  712. if (!defined($line)) {
  713. my $s = $timeout == 1 ? "" : "s";
  714. doprint "Timed out after $timeout second$s\n";
  715. last;
  716. }
  717. }
  718. doprint $line;
  719. print DMESG $line;
  720. # we are not guaranteed to get a full line
  721. $full_line .= $line;
  722. if ($full_line =~ /$success_line/) {
  723. $booted = 1;
  724. $success_start = time;
  725. }
  726. if ($booted && defined($stop_after_success) &&
  727. $stop_after_success >= 0) {
  728. my $now = time;
  729. if ($now - $success_start >= $stop_after_success) {
  730. doprint "Test forced to stop after $stop_after_success seconds after success\n";
  731. last;
  732. }
  733. }
  734. if ($full_line =~ /\[ backtrace testing \]/) {
  735. $skip_call_trace = 1;
  736. }
  737. if ($full_line =~ /call trace:/i) {
  738. if (!$bug && !$skip_call_trace) {
  739. $bug = 1;
  740. $failure_start = time;
  741. }
  742. }
  743. if ($bug && defined($stop_after_failure) &&
  744. $stop_after_failure >= 0) {
  745. my $now = time;
  746. if ($now - $failure_start >= $stop_after_failure) {
  747. doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
  748. last;
  749. }
  750. }
  751. if ($full_line =~ /\[ end of backtrace testing \]/) {
  752. $skip_call_trace = 0;
  753. }
  754. if ($full_line =~ /Kernel panic -/) {
  755. $failure_start = time;
  756. $bug = 1;
  757. }
  758. # Detect triple faults by testing the banner
  759. if ($full_line =~ /\bLinux version (\S+).*\n/) {
  760. if ($1 eq $version) {
  761. $version_found = 1;
  762. } elsif ($version_found && $detect_triplefault) {
  763. # We already booted into the kernel we are testing,
  764. # but now we booted into another kernel?
  765. # Consider this a triple fault.
  766. doprint "Aleady booted in Linux kernel $version, but now\n";
  767. doprint "we booted into Linux kernel $1.\n";
  768. doprint "Assuming that this is a triple fault.\n";
  769. doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
  770. last;
  771. }
  772. }
  773. if ($line =~ /\n/) {
  774. $full_line = "";
  775. }
  776. if ($stop_test_after > 0 && !$booted && !$bug) {
  777. if (time - $monitor_start > $stop_test_after) {
  778. doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
  779. $done = 1;
  780. }
  781. }
  782. }
  783. close(DMESG);
  784. if ($bug) {
  785. return 0 if ($in_bisect);
  786. fail "failed - got a bug report" and return 0;
  787. }
  788. if (!$booted) {
  789. return 0 if ($in_bisect);
  790. fail "failed - never got a boot prompt." and return 0;
  791. }
  792. return 1;
  793. }
  794. sub install {
  795. run_scp "$outputdir/$build_target", "$target_image" or
  796. dodie "failed to copy image";
  797. my $install_mods = 0;
  798. # should we process modules?
  799. $install_mods = 0;
  800. open(IN, "$output_config") or dodie("Can't read config file");
  801. while (<IN>) {
  802. if (/CONFIG_MODULES(=y)?/) {
  803. $install_mods = 1 if (defined($1));
  804. last;
  805. }
  806. }
  807. close(IN);
  808. if (!$install_mods) {
  809. doprint "No modules needed\n";
  810. return;
  811. }
  812. run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
  813. dodie "Failed to install modules";
  814. my $modlib = "/lib/modules/$version";
  815. my $modtar = "ktest-mods.tar.bz2";
  816. run_ssh "rm -rf $modlib" or
  817. dodie "failed to remove old mods: $modlib";
  818. # would be nice if scp -r did not follow symbolic links
  819. run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
  820. dodie "making tarball";
  821. run_scp "$tmpdir/$modtar", "/tmp" or
  822. dodie "failed to copy modules";
  823. unlink "$tmpdir/$modtar";
  824. run_ssh "'(cd / && tar xf /tmp/$modtar)'" or
  825. dodie "failed to tar modules";
  826. run_ssh "rm -f /tmp/$modtar";
  827. return if (!defined($post_install));
  828. my $cp_post_install = $post_install;
  829. $cp_post_install =~ s/\$KERNEL_VERSION/$version/g;
  830. run_command "$cp_post_install" or
  831. dodie "Failed to run post install";
  832. }
  833. sub check_buildlog {
  834. my ($patch) = @_;
  835. my @files = `git show $patch | diffstat -l`;
  836. open(IN, "git show $patch |") or
  837. dodie "failed to show $patch";
  838. while (<IN>) {
  839. if (m,^--- a/(.*),) {
  840. chomp $1;
  841. $files[$#files] = $1;
  842. }
  843. }
  844. close(IN);
  845. open(IN, $buildlog) or dodie "Can't open $buildlog";
  846. while (<IN>) {
  847. if (/^\s*(.*?):.*(warning|error)/) {
  848. my $err = $1;
  849. foreach my $file (@files) {
  850. my $fullpath = "$builddir/$file";
  851. if ($file eq $err || $fullpath eq $err) {
  852. fail "$file built with warnings" and return 0;
  853. }
  854. }
  855. }
  856. }
  857. close(IN);
  858. return 1;
  859. }
  860. sub apply_min_config {
  861. my $outconfig = "$output_config.new";
  862. # Read the config file and remove anything that
  863. # is in the force_config hash (from minconfig and others)
  864. # then add the force config back.
  865. doprint "Applying minimum configurations into $output_config.new\n";
  866. open (OUT, ">$outconfig") or
  867. dodie "Can't create $outconfig";
  868. if (-f $output_config) {
  869. open (IN, $output_config) or
  870. dodie "Failed to open $output_config";
  871. while (<IN>) {
  872. if (/^(# )?(CONFIG_[^\s=]*)/) {
  873. next if (defined($force_config{$2}));
  874. }
  875. print OUT;
  876. }
  877. close IN;
  878. }
  879. foreach my $config (keys %force_config) {
  880. print OUT "$force_config{$config}\n";
  881. }
  882. close OUT;
  883. run_command "mv $outconfig $output_config";
  884. }
  885. sub make_oldconfig {
  886. apply_min_config;
  887. if (!run_command "$make oldnoconfig") {
  888. # Perhaps oldnoconfig doesn't exist in this version of the kernel
  889. # try a yes '' | oldconfig
  890. doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
  891. run_command "yes '' | $make oldconfig" or
  892. dodie "failed make config oldconfig";
  893. }
  894. }
  895. # read a config file and use this to force new configs.
  896. sub load_force_config {
  897. my ($config) = @_;
  898. open(IN, $config) or
  899. dodie "failed to read $config";
  900. while (<IN>) {
  901. chomp;
  902. if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
  903. $force_config{$1} = $_;
  904. } elsif (/^# (CONFIG_\S*) is not set/) {
  905. $force_config{$1} = $_;
  906. }
  907. }
  908. close IN;
  909. }
  910. sub build {
  911. my ($type) = @_;
  912. unlink $buildlog;
  913. if ($type =~ /^useconfig:(.*)/) {
  914. run_command "cp $1 $output_config" or
  915. dodie "could not copy $1 to .config";
  916. $type = "oldconfig";
  917. }
  918. # old config can ask questions
  919. if ($type eq "oldconfig") {
  920. $type = "oldnoconfig";
  921. # allow for empty configs
  922. run_command "touch $output_config";
  923. run_command "mv $output_config $outputdir/config_temp" or
  924. dodie "moving .config";
  925. if (!$noclean && !run_command "$make mrproper") {
  926. dodie "make mrproper";
  927. }
  928. run_command "mv $outputdir/config_temp $output_config" or
  929. dodie "moving config_temp";
  930. } elsif (!$noclean) {
  931. unlink "$output_config";
  932. run_command "$make mrproper" or
  933. dodie "make mrproper";
  934. }
  935. # add something to distinguish this build
  936. open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
  937. print OUT "$localversion\n";
  938. close(OUT);
  939. if (defined($minconfig)) {
  940. load_force_config($minconfig);
  941. }
  942. if ($type ne "oldnoconfig") {
  943. run_command "$make $type" or
  944. dodie "failed make config";
  945. }
  946. # Run old config regardless, to enforce min configurations
  947. make_oldconfig;
  948. $redirect = "$buildlog";
  949. if (!run_command "$make $build_options") {
  950. undef $redirect;
  951. # bisect may need this to pass
  952. return 0 if ($in_bisect);
  953. fail "failed build" and return 0;
  954. }
  955. undef $redirect;
  956. return 1;
  957. }
  958. sub halt {
  959. if (!run_ssh "halt" or defined($power_off)) {
  960. if (defined($poweroff_after_halt)) {
  961. sleep $poweroff_after_halt;
  962. run_command "$power_off";
  963. }
  964. } else {
  965. # nope? the zap it!
  966. run_command "$power_off";
  967. }
  968. }
  969. sub success {
  970. my ($i) = @_;
  971. $successes++;
  972. my $name = "";
  973. if (defined($test_name)) {
  974. $name = " ($test_name)";
  975. }
  976. doprint "\n\n*******************************************\n";
  977. doprint "*******************************************\n";
  978. doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
  979. doprint "*******************************************\n";
  980. doprint "*******************************************\n";
  981. if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
  982. doprint "Reboot and wait $sleep_time seconds\n";
  983. reboot;
  984. start_monitor;
  985. wait_for_monitor $sleep_time;
  986. end_monitor;
  987. }
  988. }
  989. sub get_version {
  990. # get the release name
  991. doprint "$make kernelrelease ... ";
  992. $version = `$make kernelrelease | tail -1`;
  993. chomp($version);
  994. doprint "$version\n";
  995. }
  996. sub answer_bisect {
  997. for (;;) {
  998. doprint "Pass or fail? [p/f]";
  999. my $ans = <STDIN>;
  1000. chomp $ans;
  1001. if ($ans eq "p" || $ans eq "P") {
  1002. return 1;
  1003. } elsif ($ans eq "f" || $ans eq "F") {
  1004. return 0;
  1005. } else {
  1006. print "Please answer 'P' or 'F'\n";
  1007. }
  1008. }
  1009. }
  1010. sub child_run_test {
  1011. my $failed = 0;
  1012. # child should have no power
  1013. $reboot_on_error = 0;
  1014. $poweroff_on_error = 0;
  1015. $die_on_failure = 1;
  1016. run_command $run_test or $failed = 1;
  1017. exit $failed;
  1018. }
  1019. my $child_done;
  1020. sub child_finished {
  1021. $child_done = 1;
  1022. }
  1023. sub do_run_test {
  1024. my $child_pid;
  1025. my $child_exit;
  1026. my $line;
  1027. my $full_line;
  1028. my $bug = 0;
  1029. wait_for_monitor 1;
  1030. doprint "run test $run_test\n";
  1031. $child_done = 0;
  1032. $SIG{CHLD} = qw(child_finished);
  1033. $child_pid = fork;
  1034. child_run_test if (!$child_pid);
  1035. $full_line = "";
  1036. do {
  1037. $line = wait_for_input($monitor_fp, 1);
  1038. if (defined($line)) {
  1039. # we are not guaranteed to get a full line
  1040. $full_line .= $line;
  1041. doprint $line;
  1042. if ($full_line =~ /call trace:/i) {
  1043. $bug = 1;
  1044. }
  1045. if ($full_line =~ /Kernel panic -/) {
  1046. $bug = 1;
  1047. }
  1048. if ($line =~ /\n/) {
  1049. $full_line = "";
  1050. }
  1051. }
  1052. } while (!$child_done && !$bug);
  1053. if ($bug) {
  1054. my $failure_start = time;
  1055. my $now;
  1056. do {
  1057. $line = wait_for_input($monitor_fp, 1);
  1058. if (defined($line)) {
  1059. doprint $line;
  1060. }
  1061. $now = time;
  1062. if ($now - $failure_start >= $stop_after_failure) {
  1063. last;
  1064. }
  1065. } while (defined($line));
  1066. doprint "Detected kernel crash!\n";
  1067. # kill the child with extreme prejudice
  1068. kill 9, $child_pid;
  1069. }
  1070. waitpid $child_pid, 0;
  1071. $child_exit = $?;
  1072. if ($bug || $child_exit) {
  1073. return 0 if $in_bisect;
  1074. fail "test failed" and return 0;
  1075. }
  1076. return 1;
  1077. }
  1078. sub run_git_bisect {
  1079. my ($command) = @_;
  1080. doprint "$command ... ";
  1081. my $output = `$command 2>&1`;
  1082. my $ret = $?;
  1083. logit $output;
  1084. if ($ret) {
  1085. doprint "FAILED\n";
  1086. dodie "Failed to git bisect";
  1087. }
  1088. doprint "SUCCESS\n";
  1089. if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
  1090. doprint "$1 [$2]\n";
  1091. } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
  1092. $bisect_bad = $1;
  1093. doprint "Found bad commit... $1\n";
  1094. return 0;
  1095. } else {
  1096. # we already logged it, just print it now.
  1097. print $output;
  1098. }
  1099. return 1;
  1100. }
  1101. sub bisect_reboot {
  1102. doprint "Reboot and sleep $bisect_sleep_time seconds\n";
  1103. reboot;
  1104. start_monitor;
  1105. wait_for_monitor $bisect_sleep_time;
  1106. end_monitor;
  1107. }
  1108. # returns 1 on success, 0 on failure, -1 on skip
  1109. sub run_bisect_test {
  1110. my ($type, $buildtype) = @_;
  1111. my $failed = 0;
  1112. my $result;
  1113. my $output;
  1114. my $ret;
  1115. $in_bisect = 1;
  1116. build $buildtype or $failed = 1;
  1117. if ($type ne "build") {
  1118. if ($failed && $bisect_skip) {
  1119. $in_bisect = 0;
  1120. return -1;
  1121. }
  1122. dodie "Failed on build" if $failed;
  1123. # Now boot the box
  1124. get_grub_index;
  1125. get_version;
  1126. install;
  1127. start_monitor;
  1128. monitor or $failed = 1;
  1129. if ($type ne "boot") {
  1130. if ($failed && $bisect_skip) {
  1131. end_monitor;
  1132. bisect_reboot;
  1133. $in_bisect = 0;
  1134. return -1;
  1135. }
  1136. dodie "Failed on boot" if $failed;
  1137. do_run_test or $failed = 1;
  1138. }
  1139. end_monitor;
  1140. }
  1141. if ($failed) {
  1142. $result = 0;
  1143. } else {
  1144. $result = 1;
  1145. }
  1146. # reboot the box to a kernel we can ssh to
  1147. if ($type ne "build") {
  1148. bisect_reboot;
  1149. }
  1150. $in_bisect = 0;
  1151. return $result;
  1152. }
  1153. sub run_bisect {
  1154. my ($type) = @_;
  1155. my $buildtype = "oldconfig";
  1156. # We should have a minconfig to use?
  1157. if (defined($minconfig)) {
  1158. $buildtype = "useconfig:$minconfig";
  1159. }
  1160. my $ret = run_bisect_test $type, $buildtype;
  1161. if ($bisect_manual) {
  1162. $ret = answer_bisect;
  1163. }
  1164. # Are we looking for where it worked, not failed?
  1165. if ($reverse_bisect) {
  1166. $ret = !$ret;
  1167. }
  1168. if ($ret > 0) {
  1169. return "good";
  1170. } elsif ($ret == 0) {
  1171. return "bad";
  1172. } elsif ($bisect_skip) {
  1173. doprint "HIT A BAD COMMIT ... SKIPPING\n";
  1174. return "skip";
  1175. }
  1176. }
  1177. sub bisect {
  1178. my ($i) = @_;
  1179. my $result;
  1180. die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
  1181. die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
  1182. die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
  1183. my $good = $opt{"BISECT_GOOD[$i]"};
  1184. my $bad = $opt{"BISECT_BAD[$i]"};
  1185. my $type = $opt{"BISECT_TYPE[$i]"};
  1186. my $start = $opt{"BISECT_START[$i]"};
  1187. my $replay = $opt{"BISECT_REPLAY[$i]"};
  1188. my $start_files = $opt{"BISECT_FILES[$i]"};
  1189. if (defined($start_files)) {
  1190. $start_files = " -- " . $start_files;
  1191. } else {
  1192. $start_files = "";
  1193. }
  1194. # convert to true sha1's
  1195. $good = get_sha1($good);
  1196. $bad = get_sha1($bad);
  1197. if (defined($opt{"BISECT_REVERSE[$i]"}) &&
  1198. $opt{"BISECT_REVERSE[$i]"} == 1) {
  1199. doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
  1200. $reverse_bisect = 1;
  1201. } else {
  1202. $reverse_bisect = 0;
  1203. }
  1204. # Can't have a test without having a test to run
  1205. if ($type eq "test" && !defined($run_test)) {
  1206. $type = "boot";
  1207. }
  1208. my $check = $opt{"BISECT_CHECK[$i]"};
  1209. if (defined($check) && $check ne "0") {
  1210. # get current HEAD
  1211. my $head = get_sha1("HEAD");
  1212. if ($check ne "good") {
  1213. doprint "TESTING BISECT BAD [$bad]\n";
  1214. run_command "git checkout $bad" or
  1215. die "Failed to checkout $bad";
  1216. $result = run_bisect $type;
  1217. if ($result ne "bad") {
  1218. fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
  1219. }
  1220. }
  1221. if ($check ne "bad") {
  1222. doprint "TESTING BISECT GOOD [$good]\n";
  1223. run_command "git checkout $good" or
  1224. die "Failed to checkout $good";
  1225. $result = run_bisect $type;
  1226. if ($result ne "good") {
  1227. fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
  1228. }
  1229. }
  1230. # checkout where we started
  1231. run_command "git checkout $head" or
  1232. die "Failed to checkout $head";
  1233. }
  1234. run_command "git bisect start$start_files" or
  1235. dodie "could not start bisect";
  1236. run_command "git bisect good $good" or
  1237. dodie "could not set bisect good to $good";
  1238. run_git_bisect "git bisect bad $bad" or
  1239. dodie "could not set bisect bad to $bad";
  1240. if (defined($replay)) {
  1241. run_command "git bisect replay $replay" or
  1242. dodie "failed to run replay";
  1243. }
  1244. if (defined($start)) {
  1245. run_command "git checkout $start" or
  1246. dodie "failed to checkout $start";
  1247. }
  1248. my $test;
  1249. do {
  1250. $result = run_bisect $type;
  1251. $test = run_git_bisect "git bisect $result";
  1252. } while ($test);
  1253. run_command "git bisect log" or
  1254. dodie "could not capture git bisect log";
  1255. run_command "git bisect reset" or
  1256. dodie "could not reset git bisect";
  1257. doprint "Bad commit was [$bisect_bad]\n";
  1258. success $i;
  1259. }
  1260. my %config_ignore;
  1261. my %config_set;
  1262. my %config_list;
  1263. my %null_config;
  1264. my %dependency;
  1265. sub process_config_ignore {
  1266. my ($config) = @_;
  1267. open (IN, $config)
  1268. or dodie "Failed to read $config";
  1269. while (<IN>) {
  1270. if (/^((CONFIG\S*)=.*)/) {
  1271. $config_ignore{$2} = $1;
  1272. }
  1273. }
  1274. close(IN);
  1275. }
  1276. sub read_current_config {
  1277. my ($config_ref) = @_;
  1278. %{$config_ref} = ();
  1279. undef %{$config_ref};
  1280. my @key = keys %{$config_ref};
  1281. if ($#key >= 0) {
  1282. print "did not delete!\n";
  1283. exit;
  1284. }
  1285. open (IN, "$output_config");
  1286. while (<IN>) {
  1287. if (/^(CONFIG\S+)=(.*)/) {
  1288. ${$config_ref}{$1} = $2;
  1289. }
  1290. }
  1291. close(IN);
  1292. }
  1293. sub get_dependencies {
  1294. my ($config) = @_;
  1295. my $arr = $dependency{$config};
  1296. if (!defined($arr)) {
  1297. return ();
  1298. }
  1299. my @deps = @{$arr};
  1300. foreach my $dep (@{$arr}) {
  1301. print "ADD DEP $dep\n";
  1302. @deps = (@deps, get_dependencies $dep);
  1303. }
  1304. return @deps;
  1305. }
  1306. sub create_config {
  1307. my @configs = @_;
  1308. open(OUT, ">$output_config") or dodie "Can not write to $output_config";
  1309. foreach my $config (@configs) {
  1310. print OUT "$config_set{$config}\n";
  1311. my @deps = get_dependencies $config;
  1312. foreach my $dep (@deps) {
  1313. print OUT "$config_set{$dep}\n";
  1314. }
  1315. }
  1316. foreach my $config (keys %config_ignore) {
  1317. print OUT "$config_ignore{$config}\n";
  1318. }
  1319. close(OUT);
  1320. # exit;
  1321. make_oldconfig;
  1322. }
  1323. sub compare_configs {
  1324. my (%a, %b) = @_;
  1325. foreach my $item (keys %a) {
  1326. if (!defined($b{$item})) {
  1327. print "diff $item\n";
  1328. return 1;
  1329. }
  1330. delete $b{$item};
  1331. }
  1332. my @keys = keys %b;
  1333. if ($#keys) {
  1334. print "diff2 $keys[0]\n";
  1335. }
  1336. return -1 if ($#keys >= 0);
  1337. return 0;
  1338. }
  1339. sub run_config_bisect_test {
  1340. my ($type) = @_;
  1341. return run_bisect_test $type, "oldconfig";
  1342. }
  1343. sub process_passed {
  1344. my (%configs) = @_;
  1345. doprint "These configs had no failure: (Enabling them for further compiles)\n";
  1346. # Passed! All these configs are part of a good compile.
  1347. # Add them to the min options.
  1348. foreach my $config (keys %configs) {
  1349. if (defined($config_list{$config})) {
  1350. doprint " removing $config\n";
  1351. $config_ignore{$config} = $config_list{$config};
  1352. delete $config_list{$config};
  1353. }
  1354. }
  1355. doprint "config copied to $outputdir/config_good\n";
  1356. run_command "cp -f $output_config $outputdir/config_good";
  1357. }
  1358. sub process_failed {
  1359. my ($config) = @_;
  1360. doprint "\n\n***************************************\n";
  1361. doprint "Found bad config: $config\n";
  1362. doprint "***************************************\n\n";
  1363. }
  1364. sub run_config_bisect {
  1365. my @start_list = keys %config_list;
  1366. if ($#start_list < 0) {
  1367. doprint "No more configs to test!!!\n";
  1368. return -1;
  1369. }
  1370. doprint "***** RUN TEST ***\n";
  1371. my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
  1372. my $ret;
  1373. my %current_config;
  1374. my $count = $#start_list + 1;
  1375. doprint " $count configs to test\n";
  1376. my $half = int($#start_list / 2);
  1377. do {
  1378. my @tophalf = @start_list[0 .. $half];
  1379. create_config @tophalf;
  1380. read_current_config \%current_config;
  1381. $count = $#tophalf + 1;
  1382. doprint "Testing $count configs\n";
  1383. my $found = 0;
  1384. # make sure we test something
  1385. foreach my $config (@tophalf) {
  1386. if (defined($current_config{$config})) {
  1387. logit " $config\n";
  1388. $found = 1;
  1389. }
  1390. }
  1391. if (!$found) {
  1392. # try the other half
  1393. doprint "Top half produced no set configs, trying bottom half\n";
  1394. @tophalf = @start_list[$half + 1 .. $#start_list];
  1395. create_config @tophalf;
  1396. read_current_config \%current_config;
  1397. foreach my $config (@tophalf) {
  1398. if (defined($current_config{$config})) {
  1399. logit " $config\n";
  1400. $found = 1;
  1401. }
  1402. }
  1403. if (!$found) {
  1404. doprint "Failed: Can't make new config with current configs\n";
  1405. foreach my $config (@start_list) {
  1406. doprint " CONFIG: $config\n";
  1407. }
  1408. return -1;
  1409. }
  1410. $count = $#tophalf + 1;
  1411. doprint "Testing $count configs\n";
  1412. }
  1413. $ret = run_config_bisect_test $type;
  1414. if ($bisect_manual) {
  1415. $ret = answer_bisect;
  1416. }
  1417. if ($ret) {
  1418. process_passed %current_config;
  1419. return 0;
  1420. }
  1421. doprint "This config had a failure.\n";
  1422. doprint "Removing these configs that were not set in this config:\n";
  1423. doprint "config copied to $outputdir/config_bad\n";
  1424. run_command "cp -f $output_config $outputdir/config_bad";
  1425. # A config exists in this group that was bad.
  1426. foreach my $config (keys %config_list) {
  1427. if (!defined($current_config{$config})) {
  1428. doprint " removing $config\n";
  1429. delete $config_list{$config};
  1430. }
  1431. }
  1432. @start_list = @tophalf;
  1433. if ($#start_list == 0) {
  1434. process_failed $start_list[0];
  1435. return 1;
  1436. }
  1437. # remove half the configs we are looking at and see if
  1438. # they are good.
  1439. $half = int($#start_list / 2);
  1440. } while ($#start_list > 0);
  1441. # we found a single config, try it again unless we are running manually
  1442. if ($bisect_manual) {
  1443. process_failed $start_list[0];
  1444. return 1;
  1445. }
  1446. my @tophalf = @start_list[0 .. 0];
  1447. $ret = run_config_bisect_test $type;
  1448. if ($ret) {
  1449. process_passed %current_config;
  1450. return 0;
  1451. }
  1452. process_failed $start_list[0];
  1453. return 1;
  1454. }
  1455. sub config_bisect {
  1456. my ($i) = @_;
  1457. my $start_config = $opt{"CONFIG_BISECT[$i]"};
  1458. my $tmpconfig = "$tmpdir/use_config";
  1459. if (defined($config_bisect_good)) {
  1460. process_config_ignore $config_bisect_good;
  1461. }
  1462. # Make the file with the bad config and the min config
  1463. if (defined($minconfig)) {
  1464. # read the min config for things to ignore
  1465. run_command "cp $minconfig $tmpconfig" or
  1466. dodie "failed to copy $minconfig to $tmpconfig";
  1467. } else {
  1468. unlink $tmpconfig;
  1469. }
  1470. # Add other configs
  1471. if (defined($addconfig)) {
  1472. run_command "cat $addconfig >> $tmpconfig" or
  1473. dodie "failed to append $addconfig";
  1474. }
  1475. if (-f $tmpconfig) {
  1476. load_force_config($tmpconfig);
  1477. process_config_ignore $tmpconfig;
  1478. }
  1479. # now process the start config
  1480. run_command "cp $start_config $output_config" or
  1481. dodie "failed to copy $start_config to $output_config";
  1482. # read directly what we want to check
  1483. my %config_check;
  1484. open (IN, $output_config)
  1485. or dodie "faied to open $output_config";
  1486. while (<IN>) {
  1487. if (/^((CONFIG\S*)=.*)/) {
  1488. $config_check{$2} = $1;
  1489. }
  1490. }
  1491. close(IN);
  1492. # Now run oldconfig with the minconfig (and addconfigs)
  1493. make_oldconfig;
  1494. # check to see what we lost (or gained)
  1495. open (IN, $output_config)
  1496. or dodie "Failed to read $start_config";
  1497. my %removed_configs;
  1498. my %added_configs;
  1499. while (<IN>) {
  1500. if (/^((CONFIG\S*)=.*)/) {
  1501. # save off all options
  1502. $config_set{$2} = $1;
  1503. if (defined($config_check{$2})) {
  1504. if (defined($config_ignore{$2})) {
  1505. $removed_configs{$2} = $1;
  1506. } else {
  1507. $config_list{$2} = $1;
  1508. }
  1509. } elsif (!defined($config_ignore{$2})) {
  1510. $added_configs{$2} = $1;
  1511. $config_list{$2} = $1;
  1512. }
  1513. }
  1514. }
  1515. close(IN);
  1516. my @confs = keys %removed_configs;
  1517. if ($#confs >= 0) {
  1518. doprint "Configs overridden by default configs and removed from check:\n";
  1519. foreach my $config (@confs) {
  1520. doprint " $config\n";
  1521. }
  1522. }
  1523. @confs = keys %added_configs;
  1524. if ($#confs >= 0) {
  1525. doprint "Configs appearing in make oldconfig and added:\n";
  1526. foreach my $config (@confs) {
  1527. doprint " $config\n";
  1528. }
  1529. }
  1530. my %config_test;
  1531. my $once = 0;
  1532. # Sometimes kconfig does weird things. We must make sure
  1533. # that the config we autocreate has everything we need
  1534. # to test, otherwise we may miss testing configs, or
  1535. # may not be able to create a new config.
  1536. # Here we create a config with everything set.
  1537. create_config (keys %config_list);
  1538. read_current_config \%config_test;
  1539. foreach my $config (keys %config_list) {
  1540. if (!defined($config_test{$config})) {
  1541. if (!$once) {
  1542. $once = 1;
  1543. doprint "Configs not produced by kconfig (will not be checked):\n";
  1544. }
  1545. doprint " $config\n";
  1546. delete $config_list{$config};
  1547. }
  1548. }
  1549. my $ret;
  1550. do {
  1551. $ret = run_config_bisect;
  1552. } while (!$ret);
  1553. return $ret if ($ret < 0);
  1554. success $i;
  1555. }
  1556. sub patchcheck_reboot {
  1557. doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
  1558. reboot;
  1559. start_monitor;
  1560. wait_for_monitor $patchcheck_sleep_time;
  1561. end_monitor;
  1562. }
  1563. sub patchcheck {
  1564. my ($i) = @_;
  1565. die "PATCHCHECK_START[$i] not defined\n"
  1566. if (!defined($opt{"PATCHCHECK_START[$i]"}));
  1567. die "PATCHCHECK_TYPE[$i] not defined\n"
  1568. if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
  1569. my $start = $opt{"PATCHCHECK_START[$i]"};
  1570. my $end = "HEAD";
  1571. if (defined($opt{"PATCHCHECK_END[$i]"})) {
  1572. $end = $opt{"PATCHCHECK_END[$i]"};
  1573. }
  1574. # Get the true sha1's since we can use things like HEAD~3
  1575. $start = get_sha1($start);
  1576. $end = get_sha1($end);
  1577. my $type = $opt{"PATCHCHECK_TYPE[$i]"};
  1578. # Can't have a test without having a test to run
  1579. if ($type eq "test" && !defined($run_test)) {
  1580. $type = "boot";
  1581. }
  1582. open (IN, "git log --pretty=oneline $end|") or
  1583. dodie "could not get git list";
  1584. my @list;
  1585. while (<IN>) {
  1586. chomp;
  1587. $list[$#list+1] = $_;
  1588. last if (/^$start/);
  1589. }
  1590. close(IN);
  1591. if ($list[$#list] !~ /^$start/) {
  1592. fail "SHA1 $start not found";
  1593. }
  1594. # go backwards in the list
  1595. @list = reverse @list;
  1596. my $save_clean = $noclean;
  1597. $in_patchcheck = 1;
  1598. foreach my $item (@list) {
  1599. my $sha1 = $item;
  1600. $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
  1601. doprint "\nProcessing commit $item\n\n";
  1602. run_command "git checkout $sha1" or
  1603. die "Failed to checkout $sha1";
  1604. # only clean on the first and last patch
  1605. if ($item eq $list[0] ||
  1606. $item eq $list[$#list]) {
  1607. $noclean = $save_clean;
  1608. } else {
  1609. $noclean = 1;
  1610. }
  1611. if (defined($minconfig)) {
  1612. build "useconfig:$minconfig" or return 0;
  1613. } else {
  1614. # ?? no config to use?
  1615. build "oldconfig" or return 0;
  1616. }
  1617. check_buildlog $sha1 or return 0;
  1618. next if ($type eq "build");
  1619. get_grub_index;
  1620. get_version;
  1621. install;
  1622. my $failed = 0;
  1623. start_monitor;
  1624. monitor or $failed = 1;
  1625. if (!$failed && $type ne "boot"){
  1626. do_run_test or $failed = 1;
  1627. }
  1628. end_monitor;
  1629. return 0 if ($failed);
  1630. patchcheck_reboot;
  1631. }
  1632. $in_patchcheck = 0;
  1633. success $i;
  1634. return 1;
  1635. }
  1636. $#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
  1637. if ($#ARGV == 0) {
  1638. $ktest_config = $ARGV[0];
  1639. if (! -f $ktest_config) {
  1640. print "$ktest_config does not exist.\n";
  1641. my $ans;
  1642. for (;;) {
  1643. print "Create it? [Y/n] ";
  1644. $ans = <STDIN>;
  1645. chomp $ans;
  1646. if ($ans =~ /^\s*$/) {
  1647. $ans = "y";
  1648. }
  1649. last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
  1650. print "Please answer either 'y' or 'n'.\n";
  1651. }
  1652. if ($ans !~ /^y$/i) {
  1653. exit 0;
  1654. }
  1655. }
  1656. } else {
  1657. $ktest_config = "ktest.conf";
  1658. }
  1659. if (! -f $ktest_config) {
  1660. open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
  1661. print OUT << "EOF"
  1662. # Generated by ktest.pl
  1663. #
  1664. # Define each test with TEST_START
  1665. # The config options below it will override the defaults
  1666. TEST_START
  1667. DEFAULTS
  1668. EOF
  1669. ;
  1670. close(OUT);
  1671. }
  1672. read_config $ktest_config;
  1673. # Append any configs entered in manually to the config file.
  1674. my @new_configs = keys %entered_configs;
  1675. if ($#new_configs >= 0) {
  1676. print "\nAppending entered in configs to $ktest_config\n";
  1677. open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
  1678. foreach my $config (@new_configs) {
  1679. print OUT "$config = $entered_configs{$config}\n";
  1680. $opt{$config} = $entered_configs{$config};
  1681. }
  1682. }
  1683. if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
  1684. unlink $opt{"LOG_FILE"};
  1685. }
  1686. doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
  1687. for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
  1688. if (!$i) {
  1689. doprint "DEFAULT OPTIONS:\n";
  1690. } else {
  1691. doprint "\nTEST $i OPTIONS";
  1692. if (defined($repeat_tests{$i})) {
  1693. $repeat = $repeat_tests{$i};
  1694. doprint " ITERATE $repeat";
  1695. }
  1696. doprint "\n";
  1697. }
  1698. foreach my $option (sort keys %opt) {
  1699. if ($option =~ /\[(\d+)\]$/) {
  1700. next if ($i != $1);
  1701. } else {
  1702. next if ($i);
  1703. }
  1704. doprint "$option = $opt{$option}\n";
  1705. }
  1706. }
  1707. sub __set_test_option {
  1708. my ($name, $i) = @_;
  1709. my $option = "$name\[$i\]";
  1710. if (defined($opt{$option})) {
  1711. return $opt{$option};
  1712. }
  1713. foreach my $test (keys %repeat_tests) {
  1714. if ($i >= $test &&
  1715. $i < $test + $repeat_tests{$test}) {
  1716. $option = "$name\[$test\]";
  1717. if (defined($opt{$option})) {
  1718. return $opt{$option};
  1719. }
  1720. }
  1721. }
  1722. if (defined($opt{$name})) {
  1723. return $opt{$name};
  1724. }
  1725. return undef;
  1726. }
  1727. sub eval_option {
  1728. my ($option, $i) = @_;
  1729. # Add space to evaluate the character before $
  1730. $option = " $option";
  1731. my $retval = "";
  1732. while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
  1733. my $start = $1;
  1734. my $var = $2;
  1735. my $end = $3;
  1736. # Append beginning of line
  1737. $retval = "$retval$start";
  1738. # If the iteration option OPT[$i] exists, then use that.
  1739. # otherwise see if the default OPT (without [$i]) exists.
  1740. my $o = "$var\[$i\]";
  1741. if (defined($opt{$o})) {
  1742. $o = $opt{$o};
  1743. $retval = "$retval$o";
  1744. } elsif (defined($opt{$var})) {
  1745. $o = $opt{$var};
  1746. $retval = "$retval$o";
  1747. } else {
  1748. $retval = "$retval\$\{$var\}";
  1749. }
  1750. $option = $end;
  1751. }
  1752. $retval = "$retval$option";
  1753. $retval =~ s/^ //;
  1754. return $retval;
  1755. }
  1756. sub set_test_option {
  1757. my ($name, $i) = @_;
  1758. my $option = __set_test_option($name, $i);
  1759. return $option if (!defined($option));
  1760. my $prev = "";
  1761. # Since an option can evaluate to another option,
  1762. # keep iterating until we do not evaluate any more
  1763. # options.
  1764. my $r = 0;
  1765. while ($prev ne $option) {
  1766. # Check for recursive evaluations.
  1767. # 100 deep should be more than enough.
  1768. if ($r++ > 100) {
  1769. die "Over 100 evaluations accurred with $name\n" .
  1770. "Check for recursive variables\n";
  1771. }
  1772. $prev = $option;
  1773. $option = eval_option($option, $i);
  1774. }
  1775. return $option;
  1776. }
  1777. # First we need to do is the builds
  1778. for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
  1779. $iteration = $i;
  1780. my $makecmd = set_test_option("MAKE_CMD", $i);
  1781. $machine = set_test_option("MACHINE", $i);
  1782. $ssh_user = set_test_option("SSH_USER", $i);
  1783. $tmpdir = set_test_option("TMP_DIR", $i);
  1784. $outputdir = set_test_option("OUTPUT_DIR", $i);
  1785. $builddir = set_test_option("BUILD_DIR", $i);
  1786. $test_type = set_test_option("TEST_TYPE", $i);
  1787. $build_type = set_test_option("BUILD_TYPE", $i);
  1788. $build_options = set_test_option("BUILD_OPTIONS", $i);
  1789. $power_cycle = set_test_option("POWER_CYCLE", $i);
  1790. $reboot = set_test_option("REBOOT", $i);
  1791. $noclean = set_test_option("BUILD_NOCLEAN", $i);
  1792. $minconfig = set_test_option("MIN_CONFIG", $i);
  1793. $run_test = set_test_option("TEST", $i);
  1794. $addconfig = set_test_option("ADD_CONFIG", $i);
  1795. $reboot_type = set_test_option("REBOOT_TYPE", $i);
  1796. $grub_menu = set_test_option("GRUB_MENU", $i);
  1797. $post_install = set_test_option("POST_INSTALL", $i);
  1798. $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
  1799. $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
  1800. $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
  1801. $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
  1802. $power_off = set_test_option("POWER_OFF", $i);
  1803. $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
  1804. $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
  1805. $sleep_time = set_test_option("SLEEP_TIME", $i);
  1806. $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
  1807. $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
  1808. $bisect_manual = set_test_option("BISECT_MANUAL", $i);
  1809. $bisect_skip = set_test_option("BISECT_SKIP", $i);
  1810. $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i);
  1811. $store_failures = set_test_option("STORE_FAILURES", $i);
  1812. $test_name = set_test_option("TEST_NAME", $i);
  1813. $timeout = set_test_option("TIMEOUT", $i);
  1814. $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
  1815. $console = set_test_option("CONSOLE", $i);
  1816. $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
  1817. $success_line = set_test_option("SUCCESS_LINE", $i);
  1818. $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
  1819. $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
  1820. $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
  1821. $build_target = set_test_option("BUILD_TARGET", $i);
  1822. $ssh_exec = set_test_option("SSH_EXEC", $i);
  1823. $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
  1824. $target_image = set_test_option("TARGET_IMAGE", $i);
  1825. $localversion = set_test_option("LOCALVERSION", $i);
  1826. chdir $builddir || die "can't change directory to $builddir";
  1827. if (!-d $tmpdir) {
  1828. mkpath($tmpdir) or
  1829. die "can't create $tmpdir";
  1830. }
  1831. $ENV{"SSH_USER"} = $ssh_user;
  1832. $ENV{"MACHINE"} = $machine;
  1833. $target = "$ssh_user\@$machine";
  1834. $buildlog = "$tmpdir/buildlog-$machine";
  1835. $dmesg = "$tmpdir/dmesg-$machine";
  1836. $make = "$makecmd O=$outputdir";
  1837. $output_config = "$outputdir/.config";
  1838. if ($reboot_type eq "grub") {
  1839. dodie "GRUB_MENU not defined" if (!defined($grub_menu));
  1840. } elsif (!defined($reboot_script)) {
  1841. dodie "REBOOT_SCRIPT not defined"
  1842. }
  1843. my $run_type = $build_type;
  1844. if ($test_type eq "patchcheck") {
  1845. $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
  1846. } elsif ($test_type eq "bisect") {
  1847. $run_type = $opt{"BISECT_TYPE[$i]"};
  1848. } elsif ($test_type eq "config_bisect") {
  1849. $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
  1850. }
  1851. # mistake in config file?
  1852. if (!defined($run_type)) {
  1853. $run_type = "ERROR";
  1854. }
  1855. doprint "\n\n";
  1856. doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type\n\n";
  1857. unlink $dmesg;
  1858. unlink $buildlog;
  1859. if (!defined($minconfig)) {
  1860. $minconfig = $addconfig;
  1861. } elsif (defined($addconfig)) {
  1862. run_command "cat $addconfig $minconfig > $tmpdir/add_config" or
  1863. dodie "Failed to create temp config";
  1864. $minconfig = "$tmpdir/add_config";
  1865. }
  1866. my $checkout = $opt{"CHECKOUT[$i]"};
  1867. if (defined($checkout)) {
  1868. run_command "git checkout $checkout" or
  1869. die "failed to checkout $checkout";
  1870. }
  1871. if ($test_type eq "bisect") {
  1872. bisect $i;
  1873. next;
  1874. } elsif ($test_type eq "config_bisect") {
  1875. config_bisect $i;
  1876. next;
  1877. } elsif ($test_type eq "patchcheck") {
  1878. patchcheck $i;
  1879. next;
  1880. }
  1881. if ($build_type ne "nobuild") {
  1882. build $build_type or next;
  1883. }
  1884. if ($test_type ne "build") {
  1885. get_grub_index;
  1886. get_version;
  1887. install;
  1888. my $failed = 0;
  1889. start_monitor;
  1890. monitor or $failed = 1;;
  1891. if (!$failed && $test_type ne "boot" && defined($run_test)) {
  1892. do_run_test or $failed = 1;
  1893. }
  1894. end_monitor;
  1895. next if ($failed);
  1896. }
  1897. success $i;
  1898. }
  1899. if ($opt{"POWEROFF_ON_SUCCESS"}) {
  1900. halt;
  1901. } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
  1902. reboot;
  1903. }
  1904. doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
  1905. exit 0;