ktest.pl 49 KB

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