ktest.pl 50 KB

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