ktest.pl 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831
  1. #!/usr/bin/perl -w
  2. #
  3. # Copywrite 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. $#ARGV >= 0 || die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
  14. $| = 1;
  15. my %opt;
  16. my %repeat_tests;
  17. my %repeats;
  18. my %default;
  19. #default opts
  20. $default{"NUM_TESTS"} = 1;
  21. $default{"REBOOT_TYPE"} = "grub";
  22. $default{"TEST_TYPE"} = "test";
  23. $default{"BUILD_TYPE"} = "randconfig";
  24. $default{"MAKE_CMD"} = "make";
  25. $default{"TIMEOUT"} = 120;
  26. $default{"TMP_DIR"} = "/tmp/ktest";
  27. $default{"SLEEP_TIME"} = 60; # sleep time between tests
  28. $default{"BUILD_NOCLEAN"} = 0;
  29. $default{"REBOOT_ON_ERROR"} = 0;
  30. $default{"POWEROFF_ON_ERROR"} = 0;
  31. $default{"REBOOT_ON_SUCCESS"} = 1;
  32. $default{"POWEROFF_ON_SUCCESS"} = 0;
  33. $default{"BUILD_OPTIONS"} = "";
  34. $default{"BISECT_SLEEP_TIME"} = 60; # sleep time between bisects
  35. $default{"CLEAR_LOG"} = 0;
  36. $default{"SUCCESS_LINE"} = "login:";
  37. $default{"BOOTED_TIMEOUT"} = 1;
  38. $default{"DIE_ON_FAILURE"} = 1;
  39. $default{"SSH_EXEC"} = "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND";
  40. $default{"SCP_TO_TARGET"} = "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE";
  41. $default{"REBOOT"} = "ssh \$SSH_USER\@\$MACHINE reboot";
  42. $default{"STOP_AFTER_SUCCESS"} = 10;
  43. $default{"STOP_AFTER_FAILURE"} = 60;
  44. my $version;
  45. my $machine;
  46. my $ssh_user;
  47. my $tmpdir;
  48. my $builddir;
  49. my $outputdir;
  50. my $output_config;
  51. my $test_type;
  52. my $build_type;
  53. my $build_options;
  54. my $reboot_type;
  55. my $reboot_script;
  56. my $power_cycle;
  57. my $reboot;
  58. my $reboot_on_error;
  59. my $poweroff_on_error;
  60. my $die_on_failure;
  61. my $powercycle_after_reboot;
  62. my $poweroff_after_halt;
  63. my $ssh_exec;
  64. my $scp_to_target;
  65. my $power_off;
  66. my $grub_menu;
  67. my $grub_number;
  68. my $target;
  69. my $make;
  70. my $post_install;
  71. my $noclean;
  72. my $minconfig;
  73. my $addconfig;
  74. my $in_bisect = 0;
  75. my $bisect_bad = "";
  76. my $reverse_bisect;
  77. my $in_patchcheck = 0;
  78. my $run_test;
  79. my $redirect;
  80. my $buildlog;
  81. my $dmesg;
  82. my $monitor_fp;
  83. my $monitor_pid;
  84. my $monitor_cnt = 0;
  85. my $sleep_time;
  86. my $bisect_sleep_time;
  87. my $store_failures;
  88. my $timeout;
  89. my $booted_timeout;
  90. my $console;
  91. my $success_line;
  92. my $stop_after_success;
  93. my $stop_after_failure;
  94. my $build_target;
  95. my $target_image;
  96. my $localversion;
  97. my $iteration = 0;
  98. my $successes = 0;
  99. sub set_value {
  100. my ($lvalue, $rvalue) = @_;
  101. if (defined($opt{$lvalue})) {
  102. die "Error: Option $lvalue defined more than once!\n";
  103. }
  104. if ($rvalue =~ /^\s*$/) {
  105. delete $opt{$lvalue};
  106. } else {
  107. $opt{$lvalue} = $rvalue;
  108. }
  109. }
  110. sub read_config {
  111. my ($config) = @_;
  112. open(IN, $config) || die "can't read file $config";
  113. my $name = $config;
  114. $name =~ s,.*/(.*),$1,;
  115. my $test_num = 0;
  116. my $default = 1;
  117. my $repeat = 1;
  118. my $num_tests_set = 0;
  119. my $skip = 0;
  120. my $rest;
  121. while (<IN>) {
  122. # ignore blank lines and comments
  123. next if (/^\s*$/ || /\s*\#/);
  124. if (/^\s*TEST_START(.*)/) {
  125. $rest = $1;
  126. if ($num_tests_set) {
  127. die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
  128. }
  129. my $old_test_num = $test_num;
  130. my $old_repeat = $repeat;
  131. $test_num += $repeat;
  132. $default = 0;
  133. $repeat = 1;
  134. if ($rest =~ /\s+SKIP(.*)/) {
  135. $rest = $1;
  136. $skip = 1;
  137. } else {
  138. $skip = 0;
  139. }
  140. if ($rest =~ /\s+ITERATE\s+(\d+)(.*)$/) {
  141. $repeat = $1;
  142. $rest = $2;
  143. $repeat_tests{"$test_num"} = $repeat;
  144. }
  145. if ($rest =~ /\s+SKIP(.*)/) {
  146. $rest = $1;
  147. $skip = 1;
  148. }
  149. if ($rest !~ /^\s*$/) {
  150. die "$name: $.: Gargbage found after TEST_START\n$_";
  151. }
  152. if ($skip) {
  153. $test_num = $old_test_num;
  154. $repeat = $old_repeat;
  155. }
  156. } elsif (/^\s*DEFAULTS(.*)$/) {
  157. $default = 1;
  158. $rest = $1;
  159. if ($rest =~ /\s+SKIP(.*)/) {
  160. $rest = $1;
  161. $skip = 1;
  162. } else {
  163. $skip = 0;
  164. }
  165. if ($rest !~ /^\s*$/) {
  166. die "$name: $.: Gargbage found after DEFAULTS\n$_";
  167. }
  168. } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
  169. next if ($skip);
  170. my $lvalue = $1;
  171. my $rvalue = $2;
  172. if (!$default &&
  173. ($lvalue eq "NUM_TESTS" ||
  174. $lvalue eq "LOG_FILE" ||
  175. $lvalue eq "CLEAR_LOG")) {
  176. die "$name: $.: $lvalue must be set in DEFAULTS section\n";
  177. }
  178. if ($lvalue eq "NUM_TESTS") {
  179. if ($test_num) {
  180. die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
  181. }
  182. if (!$default) {
  183. die "$name: $.: NUM_TESTS must be set in default section\n";
  184. }
  185. $num_tests_set = 1;
  186. }
  187. if ($default || $lvalue =~ /\[\d+\]$/) {
  188. set_value($lvalue, $rvalue);
  189. } else {
  190. my $val = "$lvalue\[$test_num\]";
  191. set_value($val, $rvalue);
  192. if ($repeat > 1) {
  193. $repeats{$val} = $repeat;
  194. }
  195. }
  196. } else {
  197. die "$name: $.: Garbage found in config\n$_";
  198. }
  199. }
  200. close(IN);
  201. if ($test_num) {
  202. $test_num += $repeat - 1;
  203. $opt{"NUM_TESTS"} = $test_num;
  204. }
  205. # set any defaults
  206. foreach my $default (keys %default) {
  207. if (!defined($opt{$default})) {
  208. $opt{$default} = $default{$default};
  209. }
  210. }
  211. }
  212. sub _logit {
  213. if (defined($opt{"LOG_FILE"})) {
  214. open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
  215. print OUT @_;
  216. close(OUT);
  217. }
  218. }
  219. sub logit {
  220. if (defined($opt{"LOG_FILE"})) {
  221. _logit @_;
  222. } else {
  223. print @_;
  224. }
  225. }
  226. sub doprint {
  227. print @_;
  228. _logit @_;
  229. }
  230. sub run_command;
  231. sub reboot {
  232. # try to reboot normally
  233. if (run_command $reboot) {
  234. if (defined($powercycle_after_reboot)) {
  235. sleep $powercycle_after_reboot;
  236. run_command "$power_cycle";
  237. }
  238. } else {
  239. # nope? power cycle it.
  240. run_command "$power_cycle";
  241. }
  242. }
  243. sub do_not_reboot {
  244. my $i = $iteration;
  245. return $test_type eq "build" ||
  246. ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
  247. ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
  248. }
  249. sub dodie {
  250. doprint "CRITICAL FAILURE... ", @_, "\n";
  251. my $i = $iteration;
  252. if ($reboot_on_error && !do_not_reboot) {
  253. doprint "REBOOTING\n";
  254. reboot;
  255. } elsif ($poweroff_on_error && defined($power_off)) {
  256. doprint "POWERING OFF\n";
  257. `$power_off`;
  258. }
  259. die @_, "\n";
  260. }
  261. sub open_console {
  262. my ($fp) = @_;
  263. my $flags;
  264. my $pid = open($fp, "$console|") or
  265. dodie "Can't open console $console";
  266. $flags = fcntl($fp, F_GETFL, 0) or
  267. dodie "Can't get flags for the socket: $!";
  268. $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
  269. dodie "Can't set flags for the socket: $!";
  270. return $pid;
  271. }
  272. sub close_console {
  273. my ($fp, $pid) = @_;
  274. doprint "kill child process $pid\n";
  275. kill 2, $pid;
  276. print "closing!\n";
  277. close($fp);
  278. }
  279. sub start_monitor {
  280. if ($monitor_cnt++) {
  281. return;
  282. }
  283. $monitor_fp = \*MONFD;
  284. $monitor_pid = open_console $monitor_fp;
  285. return;
  286. open(MONFD, "Stop perl from warning about single use of MONFD");
  287. }
  288. sub end_monitor {
  289. if (--$monitor_cnt) {
  290. return;
  291. }
  292. close_console($monitor_fp, $monitor_pid);
  293. }
  294. sub wait_for_monitor {
  295. my ($time) = @_;
  296. my $line;
  297. doprint "** Wait for monitor to settle down **\n";
  298. # read the monitor and wait for the system to calm down
  299. do {
  300. $line = wait_for_input($monitor_fp, $time);
  301. print "$line" if (defined($line));
  302. } while (defined($line));
  303. print "** Monitor flushed **\n";
  304. }
  305. sub fail {
  306. if ($die_on_failure) {
  307. dodie @_;
  308. }
  309. doprint "FAILED\n";
  310. my $i = $iteration;
  311. # no need to reboot for just building.
  312. if (!do_not_reboot) {
  313. doprint "REBOOTING\n";
  314. reboot;
  315. start_monitor;
  316. wait_for_monitor $sleep_time;
  317. end_monitor;
  318. }
  319. doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
  320. doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
  321. doprint "KTEST RESULT: TEST $i Failed: ", @_, "\n";
  322. doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
  323. doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
  324. return 1 if (!defined($store_failures));
  325. my @t = localtime;
  326. my $date = sprintf "%04d%02d%02d%02d%02d%02d",
  327. 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
  328. my $type = $build_type;
  329. if ($type =~ /useconfig/) {
  330. $type = "useconfig";
  331. }
  332. my $dir = "$machine-$test_type-$type-fail-$date";
  333. my $faildir = "$store_failures/$dir";
  334. if (!-d $faildir) {
  335. mkpath($faildir) or
  336. die "can't create $faildir";
  337. }
  338. if (-f "$output_config") {
  339. cp "$output_config", "$faildir/config" or
  340. die "failed to copy .config";
  341. }
  342. if (-f $buildlog) {
  343. cp $buildlog, "$faildir/buildlog" or
  344. die "failed to move $buildlog";
  345. }
  346. if (-f $dmesg) {
  347. cp $dmesg, "$faildir/dmesg" or
  348. die "failed to move $dmesg";
  349. }
  350. doprint "*** Saved info to $faildir ***\n";
  351. return 1;
  352. }
  353. sub run_command {
  354. my ($command) = @_;
  355. my $dolog = 0;
  356. my $dord = 0;
  357. my $pid;
  358. $command =~ s/\$SSH_USER/$ssh_user/g;
  359. $command =~ s/\$MACHINE/$machine/g;
  360. doprint("$command ... ");
  361. $pid = open(CMD, "$command 2>&1 |") or
  362. (fail "unable to exec $command" and return 0);
  363. if (defined($opt{"LOG_FILE"})) {
  364. open(LOG, ">>$opt{LOG_FILE}") or
  365. dodie "failed to write to log";
  366. $dolog = 1;
  367. }
  368. if (defined($redirect)) {
  369. open (RD, ">$redirect") or
  370. dodie "failed to write to redirect $redirect";
  371. $dord = 1;
  372. }
  373. while (<CMD>) {
  374. print LOG if ($dolog);
  375. print RD if ($dord);
  376. }
  377. waitpid($pid, 0);
  378. my $failed = $?;
  379. close(CMD);
  380. close(LOG) if ($dolog);
  381. close(RD) if ($dord);
  382. if ($failed) {
  383. doprint "FAILED!\n";
  384. } else {
  385. doprint "SUCCESS\n";
  386. }
  387. return !$failed;
  388. }
  389. sub run_ssh {
  390. my ($cmd) = @_;
  391. my $cp_exec = $ssh_exec;
  392. $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
  393. return run_command "$cp_exec";
  394. }
  395. sub run_scp {
  396. my ($src, $dst) = @_;
  397. my $cp_scp = $scp_to_target;
  398. $cp_scp =~ s/\$SRC_FILE/$src/g;
  399. $cp_scp =~ s/\$DST_FILE/$dst/g;
  400. return run_command "$cp_scp";
  401. }
  402. sub get_grub_index {
  403. if ($reboot_type ne "grub") {
  404. return;
  405. }
  406. return if (defined($grub_number));
  407. doprint "Find grub menu ... ";
  408. $grub_number = -1;
  409. my $ssh_grub = $ssh_exec;
  410. $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
  411. open(IN, "$ssh_grub |")
  412. or die "unable to get menu.lst";
  413. while (<IN>) {
  414. if (/^\s*title\s+$grub_menu\s*$/) {
  415. $grub_number++;
  416. last;
  417. } elsif (/^\s*title\s/) {
  418. $grub_number++;
  419. }
  420. }
  421. close(IN);
  422. die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
  423. if ($grub_number < 0);
  424. doprint "$grub_number\n";
  425. }
  426. sub wait_for_input
  427. {
  428. my ($fp, $time) = @_;
  429. my $rin;
  430. my $ready;
  431. my $line;
  432. my $ch;
  433. if (!defined($time)) {
  434. $time = $timeout;
  435. }
  436. $rin = '';
  437. vec($rin, fileno($fp), 1) = 1;
  438. $ready = select($rin, undef, undef, $time);
  439. $line = "";
  440. # try to read one char at a time
  441. while (sysread $fp, $ch, 1) {
  442. $line .= $ch;
  443. last if ($ch eq "\n");
  444. }
  445. if (!length($line)) {
  446. return undef;
  447. }
  448. return $line;
  449. }
  450. sub reboot_to {
  451. if ($reboot_type eq "grub") {
  452. run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch; reboot)'";
  453. return;
  454. }
  455. run_command "$reboot_script";
  456. }
  457. sub get_sha1 {
  458. my ($commit) = @_;
  459. doprint "git rev-list --max-count=1 $commit ... ";
  460. my $sha1 = `git rev-list --max-count=1 $commit`;
  461. my $ret = $?;
  462. logit $sha1;
  463. if ($ret) {
  464. doprint "FAILED\n";
  465. dodie "Failed to get git $commit";
  466. }
  467. print "SUCCESS\n";
  468. chomp $sha1;
  469. return $sha1;
  470. }
  471. sub monitor {
  472. my $booted = 0;
  473. my $bug = 0;
  474. my $skip_call_trace = 0;
  475. my $loops;
  476. wait_for_monitor 5;
  477. my $line;
  478. my $full_line = "";
  479. open(DMESG, "> $dmesg") or
  480. die "unable to write to $dmesg";
  481. reboot_to;
  482. my $success_start;
  483. my $failure_start;
  484. for (;;) {
  485. if ($booted) {
  486. $line = wait_for_input($monitor_fp, $booted_timeout);
  487. } else {
  488. $line = wait_for_input($monitor_fp);
  489. }
  490. last if (!defined($line));
  491. doprint $line;
  492. print DMESG $line;
  493. # we are not guaranteed to get a full line
  494. $full_line .= $line;
  495. if ($full_line =~ /$success_line/) {
  496. $booted = 1;
  497. $success_start = time;
  498. }
  499. if ($booted && defined($stop_after_success) &&
  500. $stop_after_success >= 0) {
  501. my $now = time;
  502. if ($now - $success_start >= $stop_after_success) {
  503. doprint "Test forced to stop after $stop_after_success seconds after success\n";
  504. last;
  505. }
  506. }
  507. if ($full_line =~ /\[ backtrace testing \]/) {
  508. $skip_call_trace = 1;
  509. }
  510. if ($full_line =~ /call trace:/i) {
  511. if (!$skip_call_trace) {
  512. $bug = 1;
  513. $failure_start = time;
  514. }
  515. }
  516. if ($bug && defined($stop_after_failure) &&
  517. $stop_after_failure >= 0) {
  518. my $now = time;
  519. if ($now - $failure_start >= $stop_after_failure) {
  520. doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
  521. last;
  522. }
  523. }
  524. if ($full_line =~ /\[ end of backtrace testing \]/) {
  525. $skip_call_trace = 0;
  526. }
  527. if ($full_line =~ /Kernel panic -/) {
  528. $bug = 1;
  529. }
  530. if ($line =~ /\n/) {
  531. $full_line = "";
  532. }
  533. }
  534. close(DMESG);
  535. if ($bug) {
  536. return 0 if ($in_bisect);
  537. fail "failed - got a bug report" and return 0;
  538. }
  539. if (!$booted) {
  540. return 0 if ($in_bisect);
  541. fail "failed - never got a boot prompt." and return 0;
  542. }
  543. return 1;
  544. }
  545. sub install {
  546. run_scp "$outputdir/$build_target", "$target_image" or
  547. dodie "failed to copy image";
  548. my $install_mods = 0;
  549. # should we process modules?
  550. $install_mods = 0;
  551. open(IN, "$output_config") or dodie("Can't read config file");
  552. while (<IN>) {
  553. if (/CONFIG_MODULES(=y)?/) {
  554. $install_mods = 1 if (defined($1));
  555. last;
  556. }
  557. }
  558. close(IN);
  559. if (!$install_mods) {
  560. doprint "No modules needed\n";
  561. return;
  562. }
  563. run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
  564. dodie "Failed to install modules";
  565. my $modlib = "/lib/modules/$version";
  566. my $modtar = "ktest-mods.tar.bz2";
  567. run_ssh "rm -rf $modlib" or
  568. dodie "failed to remove old mods: $modlib";
  569. # would be nice if scp -r did not follow symbolic links
  570. run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
  571. dodie "making tarball";
  572. run_scp "$tmpdir/$modtar", "/tmp" or
  573. dodie "failed to copy modules";
  574. unlink "$tmpdir/$modtar";
  575. run_ssh "'(cd / && tar xf /tmp/$modtar)'" or
  576. dodie "failed to tar modules";
  577. run_ssh "rm -f /tmp/$modtar";
  578. return if (!defined($post_install));
  579. my $cp_post_install = $post_install;
  580. $cp_post_install = s/\$KERNEL_VERSION/$version/g;
  581. run_command "$cp_post_install" or
  582. dodie "Failed to run post install";
  583. }
  584. sub check_buildlog {
  585. my ($patch) = @_;
  586. my @files = `git show $patch | diffstat -l`;
  587. open(IN, "git show $patch |") or
  588. dodie "failed to show $patch";
  589. while (<IN>) {
  590. if (m,^--- a/(.*),) {
  591. chomp $1;
  592. $files[$#files] = $1;
  593. }
  594. }
  595. close(IN);
  596. open(IN, $buildlog) or dodie "Can't open $buildlog";
  597. while (<IN>) {
  598. if (/^\s*(.*?):.*(warning|error)/) {
  599. my $err = $1;
  600. foreach my $file (@files) {
  601. my $fullpath = "$builddir/$file";
  602. if ($file eq $err || $fullpath eq $err) {
  603. fail "$file built with warnings" and return 0;
  604. }
  605. }
  606. }
  607. }
  608. close(IN);
  609. return 1;
  610. }
  611. sub build {
  612. my ($type) = @_;
  613. my $defconfig = "";
  614. unlink $buildlog;
  615. if ($type =~ /^useconfig:(.*)/) {
  616. run_command "cp $1 $output_config" or
  617. dodie "could not copy $1 to .config";
  618. $type = "oldconfig";
  619. }
  620. # old config can ask questions
  621. if ($type eq "oldconfig") {
  622. $type = "oldnoconfig";
  623. # allow for empty configs
  624. run_command "touch $output_config";
  625. run_command "mv $output_config $outputdir/config_temp" or
  626. dodie "moving .config";
  627. if (!$noclean && !run_command "$make mrproper") {
  628. dodie "make mrproper";
  629. }
  630. run_command "mv $outputdir/config_temp $output_config" or
  631. dodie "moving config_temp";
  632. } elsif (!$noclean) {
  633. unlink "$output_config";
  634. run_command "$make mrproper" or
  635. dodie "make mrproper";
  636. }
  637. # add something to distinguish this build
  638. open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
  639. print OUT "$localversion\n";
  640. close(OUT);
  641. if (defined($minconfig)) {
  642. $defconfig = "KCONFIG_ALLCONFIG=$minconfig";
  643. }
  644. run_command "$defconfig $make $type" or
  645. dodie "failed make config";
  646. $redirect = "$buildlog";
  647. if (!run_command "$make $build_options") {
  648. undef $redirect;
  649. # bisect may need this to pass
  650. return 0 if ($in_bisect);
  651. fail "failed build" and return 0;
  652. }
  653. undef $redirect;
  654. return 1;
  655. }
  656. sub halt {
  657. if (!run_ssh "halt" or defined($power_off)) {
  658. if (defined($poweroff_after_halt)) {
  659. sleep $poweroff_after_halt;
  660. run_command "$power_off";
  661. }
  662. } else {
  663. # nope? the zap it!
  664. run_command "$power_off";
  665. }
  666. }
  667. sub success {
  668. my ($i) = @_;
  669. $successes++;
  670. doprint "\n\n*******************************************\n";
  671. doprint "*******************************************\n";
  672. doprint "KTEST RESULT: TEST $i SUCCESS!!!! **\n";
  673. doprint "*******************************************\n";
  674. doprint "*******************************************\n";
  675. if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
  676. doprint "Reboot and wait $sleep_time seconds\n";
  677. reboot;
  678. start_monitor;
  679. wait_for_monitor $sleep_time;
  680. end_monitor;
  681. }
  682. }
  683. sub get_version {
  684. # get the release name
  685. doprint "$make kernelrelease ... ";
  686. $version = `$make kernelrelease | tail -1`;
  687. chomp($version);
  688. doprint "$version\n";
  689. }
  690. sub child_run_test {
  691. my $failed = 0;
  692. # child should have no power
  693. $reboot_on_error = 0;
  694. $poweroff_on_error = 0;
  695. $die_on_failure = 1;
  696. run_command $run_test or $failed = 1;
  697. exit $failed;
  698. }
  699. my $child_done;
  700. sub child_finished {
  701. $child_done = 1;
  702. }
  703. sub do_run_test {
  704. my $child_pid;
  705. my $child_exit;
  706. my $line;
  707. my $full_line;
  708. my $bug = 0;
  709. wait_for_monitor 1;
  710. doprint "run test $run_test\n";
  711. $child_done = 0;
  712. $SIG{CHLD} = qw(child_finished);
  713. $child_pid = fork;
  714. child_run_test if (!$child_pid);
  715. $full_line = "";
  716. do {
  717. $line = wait_for_input($monitor_fp, 1);
  718. if (defined($line)) {
  719. # we are not guaranteed to get a full line
  720. $full_line .= $line;
  721. if ($full_line =~ /call trace:/i) {
  722. $bug = 1;
  723. }
  724. if ($full_line =~ /Kernel panic -/) {
  725. $bug = 1;
  726. }
  727. if ($line =~ /\n/) {
  728. $full_line = "";
  729. }
  730. }
  731. } while (!$child_done && !$bug);
  732. if ($bug) {
  733. doprint "Detected kernel crash!\n";
  734. # kill the child with extreme prejudice
  735. kill 9, $child_pid;
  736. }
  737. waitpid $child_pid, 0;
  738. $child_exit = $?;
  739. if ($bug || $child_exit) {
  740. return 0 if $in_bisect;
  741. fail "test failed" and return 0;
  742. }
  743. return 1;
  744. }
  745. sub run_git_bisect {
  746. my ($command) = @_;
  747. doprint "$command ... ";
  748. my $output = `$command 2>&1`;
  749. my $ret = $?;
  750. logit $output;
  751. if ($ret) {
  752. doprint "FAILED\n";
  753. dodie "Failed to git bisect";
  754. }
  755. doprint "SUCCESS\n";
  756. if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
  757. doprint "$1 [$2]\n";
  758. } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
  759. $bisect_bad = $1;
  760. doprint "Found bad commit... $1\n";
  761. return 0;
  762. } else {
  763. # we already logged it, just print it now.
  764. print $output;
  765. }
  766. return 1;
  767. }
  768. # returns 1 on success, 0 on failure
  769. sub run_bisect_test {
  770. my ($type, $buildtype) = @_;
  771. my $failed = 0;
  772. my $result;
  773. my $output;
  774. my $ret;
  775. $in_bisect = 1;
  776. build $buildtype or $failed = 1;
  777. if ($type ne "build") {
  778. dodie "Failed on build" if $failed;
  779. # Now boot the box
  780. get_grub_index;
  781. get_version;
  782. install;
  783. start_monitor;
  784. monitor or $failed = 1;
  785. if ($type ne "boot") {
  786. dodie "Failed on boot" if $failed;
  787. do_run_test or $failed = 1;
  788. }
  789. end_monitor;
  790. }
  791. if ($failed) {
  792. $result = 0;
  793. # reboot the box to a good kernel
  794. if ($type ne "build") {
  795. doprint "Reboot and sleep $bisect_sleep_time seconds\n";
  796. reboot;
  797. start_monitor;
  798. wait_for_monitor $bisect_sleep_time;
  799. end_monitor;
  800. }
  801. } else {
  802. $result = 1;
  803. }
  804. $in_bisect = 0;
  805. return $result;
  806. }
  807. sub run_bisect {
  808. my ($type) = @_;
  809. my $buildtype = "oldconfig";
  810. # We should have a minconfig to use?
  811. if (defined($minconfig)) {
  812. $buildtype = "useconfig:$minconfig";
  813. }
  814. my $ret = run_bisect_test $type, $buildtype;
  815. # Are we looking for where it worked, not failed?
  816. if ($reverse_bisect) {
  817. $ret = !$ret;
  818. }
  819. if ($ret) {
  820. return "good";
  821. } else {
  822. return "bad";
  823. }
  824. }
  825. sub bisect {
  826. my ($i) = @_;
  827. my $result;
  828. die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
  829. die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
  830. die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
  831. my $good = $opt{"BISECT_GOOD[$i]"};
  832. my $bad = $opt{"BISECT_BAD[$i]"};
  833. my $type = $opt{"BISECT_TYPE[$i]"};
  834. my $start = $opt{"BISECT_START[$i]"};
  835. my $replay = $opt{"BISECT_REPLAY[$i]"};
  836. # convert to true sha1's
  837. $good = get_sha1($good);
  838. $bad = get_sha1($bad);
  839. if (defined($opt{"BISECT_REVERSE[$i]"}) &&
  840. $opt{"BISECT_REVERSE[$i]"} == 1) {
  841. doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
  842. $reverse_bisect = 1;
  843. } else {
  844. $reverse_bisect = 0;
  845. }
  846. # Can't have a test without having a test to run
  847. if ($type eq "test" && !defined($run_test)) {
  848. $type = "boot";
  849. }
  850. my $check = $opt{"BISECT_CHECK[$i]"};
  851. if (defined($check) && $check ne "0") {
  852. # get current HEAD
  853. my $head = get_sha1("HEAD");
  854. if ($check ne "good") {
  855. doprint "TESTING BISECT BAD [$bad]\n";
  856. run_command "git checkout $bad" or
  857. die "Failed to checkout $bad";
  858. $result = run_bisect $type;
  859. if ($result ne "bad") {
  860. fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
  861. }
  862. }
  863. if ($check ne "bad") {
  864. doprint "TESTING BISECT GOOD [$good]\n";
  865. run_command "git checkout $good" or
  866. die "Failed to checkout $good";
  867. $result = run_bisect $type;
  868. if ($result ne "good") {
  869. fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
  870. }
  871. }
  872. # checkout where we started
  873. run_command "git checkout $head" or
  874. die "Failed to checkout $head";
  875. }
  876. run_command "git bisect start" or
  877. dodie "could not start bisect";
  878. run_command "git bisect good $good" or
  879. dodie "could not set bisect good to $good";
  880. run_git_bisect "git bisect bad $bad" or
  881. dodie "could not set bisect bad to $bad";
  882. if (defined($replay)) {
  883. run_command "git bisect replay $replay" or
  884. dodie "failed to run replay";
  885. }
  886. if (defined($start)) {
  887. run_command "git checkout $start" or
  888. dodie "failed to checkout $start";
  889. }
  890. my $test;
  891. do {
  892. $result = run_bisect $type;
  893. $test = run_git_bisect "git bisect $result";
  894. } while ($test);
  895. run_command "git bisect log" or
  896. dodie "could not capture git bisect log";
  897. run_command "git bisect reset" or
  898. dodie "could not reset git bisect";
  899. doprint "Bad commit was [$bisect_bad]\n";
  900. success $i;
  901. }
  902. my %config_ignore;
  903. my %config_set;
  904. my %config_list;
  905. my %null_config;
  906. my %dependency;
  907. sub process_config_ignore {
  908. my ($config) = @_;
  909. open (IN, $config)
  910. or dodie "Failed to read $config";
  911. while (<IN>) {
  912. if (/^(.*?(CONFIG\S*)(=.*| is not set))/) {
  913. $config_ignore{$2} = $1;
  914. }
  915. }
  916. close(IN);
  917. }
  918. sub read_current_config {
  919. my ($config_ref) = @_;
  920. %{$config_ref} = ();
  921. undef %{$config_ref};
  922. my @key = keys %{$config_ref};
  923. if ($#key >= 0) {
  924. print "did not delete!\n";
  925. exit;
  926. }
  927. open (IN, "$output_config");
  928. while (<IN>) {
  929. if (/^(CONFIG\S+)=(.*)/) {
  930. ${$config_ref}{$1} = $2;
  931. }
  932. }
  933. close(IN);
  934. }
  935. sub get_dependencies {
  936. my ($config) = @_;
  937. my $arr = $dependency{$config};
  938. if (!defined($arr)) {
  939. return ();
  940. }
  941. my @deps = @{$arr};
  942. foreach my $dep (@{$arr}) {
  943. print "ADD DEP $dep\n";
  944. @deps = (@deps, get_dependencies $dep);
  945. }
  946. return @deps;
  947. }
  948. sub create_config {
  949. my @configs = @_;
  950. open(OUT, ">$output_config") or dodie "Can not write to $output_config";
  951. foreach my $config (@configs) {
  952. print OUT "$config_set{$config}\n";
  953. my @deps = get_dependencies $config;
  954. foreach my $dep (@deps) {
  955. print OUT "$config_set{$dep}\n";
  956. }
  957. }
  958. foreach my $config (keys %config_ignore) {
  959. print OUT "$config_ignore{$config}\n";
  960. }
  961. close(OUT);
  962. # exit;
  963. run_command "$make oldnoconfig" or
  964. dodie "failed make config oldconfig";
  965. }
  966. sub compare_configs {
  967. my (%a, %b) = @_;
  968. foreach my $item (keys %a) {
  969. if (!defined($b{$item})) {
  970. print "diff $item\n";
  971. return 1;
  972. }
  973. delete $b{$item};
  974. }
  975. my @keys = keys %b;
  976. if ($#keys) {
  977. print "diff2 $keys[0]\n";
  978. }
  979. return -1 if ($#keys >= 0);
  980. return 0;
  981. }
  982. sub run_config_bisect_test {
  983. my ($type) = @_;
  984. return run_bisect_test $type, "oldconfig";
  985. }
  986. sub process_passed {
  987. my (%configs) = @_;
  988. doprint "These configs had no failure: (Enabling them for further compiles)\n";
  989. # Passed! All these configs are part of a good compile.
  990. # Add them to the min options.
  991. foreach my $config (keys %configs) {
  992. if (defined($config_list{$config})) {
  993. doprint " removing $config\n";
  994. $config_ignore{$config} = $config_list{$config};
  995. delete $config_list{$config};
  996. }
  997. }
  998. doprint "config copied to $outputdir/config_good\n";
  999. run_command "cp -f $output_config $outputdir/config_good";
  1000. }
  1001. sub process_failed {
  1002. my ($config) = @_;
  1003. doprint "\n\n***************************************\n";
  1004. doprint "Found bad config: $config\n";
  1005. doprint "***************************************\n\n";
  1006. }
  1007. sub run_config_bisect {
  1008. my @start_list = keys %config_list;
  1009. if ($#start_list < 0) {
  1010. doprint "No more configs to test!!!\n";
  1011. return -1;
  1012. }
  1013. doprint "***** RUN TEST ***\n";
  1014. my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
  1015. my $ret;
  1016. my %current_config;
  1017. my $count = $#start_list + 1;
  1018. doprint " $count configs to test\n";
  1019. my $half = int($#start_list / 2);
  1020. do {
  1021. my @tophalf = @start_list[0 .. $half];
  1022. create_config @tophalf;
  1023. read_current_config \%current_config;
  1024. $count = $#tophalf + 1;
  1025. doprint "Testing $count configs\n";
  1026. my $found = 0;
  1027. # make sure we test something
  1028. foreach my $config (@tophalf) {
  1029. if (defined($current_config{$config})) {
  1030. logit " $config\n";
  1031. $found = 1;
  1032. }
  1033. }
  1034. if (!$found) {
  1035. # try the other half
  1036. doprint "Top half produced no set configs, trying bottom half\n";
  1037. @tophalf = @start_list[$half .. $#start_list];
  1038. create_config @tophalf;
  1039. read_current_config \%current_config;
  1040. foreach my $config (@tophalf) {
  1041. if (defined($current_config{$config})) {
  1042. logit " $config\n";
  1043. $found = 1;
  1044. }
  1045. }
  1046. if (!$found) {
  1047. doprint "Failed: Can't make new config with current configs\n";
  1048. foreach my $config (@start_list) {
  1049. doprint " CONFIG: $config\n";
  1050. }
  1051. return -1;
  1052. }
  1053. $count = $#tophalf + 1;
  1054. doprint "Testing $count configs\n";
  1055. }
  1056. $ret = run_config_bisect_test $type;
  1057. if ($ret) {
  1058. process_passed %current_config;
  1059. return 0;
  1060. }
  1061. doprint "This config had a failure.\n";
  1062. doprint "Removing these configs that were not set in this config:\n";
  1063. doprint "config copied to $outputdir/config_bad\n";
  1064. run_command "cp -f $output_config $outputdir/config_bad";
  1065. # A config exists in this group that was bad.
  1066. foreach my $config (keys %config_list) {
  1067. if (!defined($current_config{$config})) {
  1068. doprint " removing $config\n";
  1069. delete $config_list{$config};
  1070. }
  1071. }
  1072. @start_list = @tophalf;
  1073. if ($#start_list == 0) {
  1074. process_failed $start_list[0];
  1075. return 1;
  1076. }
  1077. # remove half the configs we are looking at and see if
  1078. # they are good.
  1079. $half = int($#start_list / 2);
  1080. } while ($half > 0);
  1081. # we found a single config, try it again
  1082. my @tophalf = @start_list[0 .. 0];
  1083. $ret = run_config_bisect_test $type;
  1084. if ($ret) {
  1085. process_passed %current_config;
  1086. return 0;
  1087. }
  1088. process_failed $start_list[0];
  1089. return 1;
  1090. }
  1091. sub config_bisect {
  1092. my ($i) = @_;
  1093. my $start_config = $opt{"CONFIG_BISECT[$i]"};
  1094. my $tmpconfig = "$tmpdir/use_config";
  1095. # Make the file with the bad config and the min config
  1096. if (defined($minconfig)) {
  1097. # read the min config for things to ignore
  1098. run_command "cp $minconfig $tmpconfig" or
  1099. dodie "failed to copy $minconfig to $tmpconfig";
  1100. } else {
  1101. unlink $tmpconfig;
  1102. }
  1103. # Add other configs
  1104. if (defined($addconfig)) {
  1105. run_command "cat $addconfig >> $tmpconfig" or
  1106. dodie "failed to append $addconfig";
  1107. }
  1108. my $defconfig = "";
  1109. if (-f $tmpconfig) {
  1110. $defconfig = "KCONFIG_ALLCONFIG=$tmpconfig";
  1111. process_config_ignore $tmpconfig;
  1112. }
  1113. # now process the start config
  1114. run_command "cp $start_config $output_config" or
  1115. dodie "failed to copy $start_config to $output_config";
  1116. # read directly what we want to check
  1117. my %config_check;
  1118. open (IN, $output_config)
  1119. or dodie "faied to open $output_config";
  1120. while (<IN>) {
  1121. if (/^((CONFIG\S*)=.*)/) {
  1122. $config_check{$2} = $1;
  1123. }
  1124. }
  1125. close(IN);
  1126. # Now run oldconfig with the minconfig (and addconfigs)
  1127. run_command "$defconfig $make oldnoconfig" or
  1128. dodie "failed make config oldconfig";
  1129. # check to see what we lost (or gained)
  1130. open (IN, $output_config)
  1131. or dodie "Failed to read $start_config";
  1132. my %removed_configs;
  1133. my %added_configs;
  1134. while (<IN>) {
  1135. if (/^((CONFIG\S*)=.*)/) {
  1136. # save off all options
  1137. $config_set{$2} = $1;
  1138. if (defined($config_check{$2})) {
  1139. if (defined($config_ignore{$2})) {
  1140. $removed_configs{$2} = $1;
  1141. } else {
  1142. $config_list{$2} = $1;
  1143. }
  1144. } elsif (!defined($config_ignore{$2})) {
  1145. $added_configs{$2} = $1;
  1146. $config_list{$2} = $1;
  1147. }
  1148. }
  1149. }
  1150. close(IN);
  1151. my @confs = keys %removed_configs;
  1152. if ($#confs >= 0) {
  1153. doprint "Configs overridden by default configs and removed from check:\n";
  1154. foreach my $config (@confs) {
  1155. doprint " $config\n";
  1156. }
  1157. }
  1158. @confs = keys %added_configs;
  1159. if ($#confs >= 0) {
  1160. doprint "Configs appearing in make oldconfig and added:\n";
  1161. foreach my $config (@confs) {
  1162. doprint " $config\n";
  1163. }
  1164. }
  1165. my %config_test;
  1166. my $once = 0;
  1167. # Sometimes kconfig does weird things. We must make sure
  1168. # that the config we autocreate has everything we need
  1169. # to test, otherwise we may miss testing configs, or
  1170. # may not be able to create a new config.
  1171. # Here we create a config with everything set.
  1172. create_config (keys %config_list);
  1173. read_current_config \%config_test;
  1174. foreach my $config (keys %config_list) {
  1175. if (!defined($config_test{$config})) {
  1176. if (!$once) {
  1177. $once = 1;
  1178. doprint "Configs not produced by kconfig (will not be checked):\n";
  1179. }
  1180. doprint " $config\n";
  1181. delete $config_list{$config};
  1182. }
  1183. }
  1184. my $ret;
  1185. do {
  1186. $ret = run_config_bisect;
  1187. } while (!$ret);
  1188. return $ret if ($ret < 0);
  1189. success $i;
  1190. }
  1191. sub patchcheck {
  1192. my ($i) = @_;
  1193. die "PATCHCHECK_START[$i] not defined\n"
  1194. if (!defined($opt{"PATCHCHECK_START[$i]"}));
  1195. die "PATCHCHECK_TYPE[$i] not defined\n"
  1196. if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
  1197. my $start = $opt{"PATCHCHECK_START[$i]"};
  1198. my $end = "HEAD";
  1199. if (defined($opt{"PATCHCHECK_END[$i]"})) {
  1200. $end = $opt{"PATCHCHECK_END[$i]"};
  1201. }
  1202. # Get the true sha1's since we can use things like HEAD~3
  1203. $start = get_sha1($start);
  1204. $end = get_sha1($end);
  1205. my $type = $opt{"PATCHCHECK_TYPE[$i]"};
  1206. # Can't have a test without having a test to run
  1207. if ($type eq "test" && !defined($run_test)) {
  1208. $type = "boot";
  1209. }
  1210. open (IN, "git log --pretty=oneline $end|") or
  1211. dodie "could not get git list";
  1212. my @list;
  1213. while (<IN>) {
  1214. chomp;
  1215. $list[$#list+1] = $_;
  1216. last if (/^$start/);
  1217. }
  1218. close(IN);
  1219. if ($list[$#list] !~ /^$start/) {
  1220. fail "SHA1 $start not found";
  1221. }
  1222. # go backwards in the list
  1223. @list = reverse @list;
  1224. my $save_clean = $noclean;
  1225. $in_patchcheck = 1;
  1226. foreach my $item (@list) {
  1227. my $sha1 = $item;
  1228. $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
  1229. doprint "\nProcessing commit $item\n\n";
  1230. run_command "git checkout $sha1" or
  1231. die "Failed to checkout $sha1";
  1232. # only clean on the first and last patch
  1233. if ($item eq $list[0] ||
  1234. $item eq $list[$#list]) {
  1235. $noclean = $save_clean;
  1236. } else {
  1237. $noclean = 1;
  1238. }
  1239. if (defined($minconfig)) {
  1240. build "useconfig:$minconfig" or return 0;
  1241. } else {
  1242. # ?? no config to use?
  1243. build "oldconfig" or return 0;
  1244. }
  1245. check_buildlog $sha1 or return 0;
  1246. next if ($type eq "build");
  1247. get_grub_index;
  1248. get_version;
  1249. install;
  1250. my $failed = 0;
  1251. start_monitor;
  1252. monitor or $failed = 1;
  1253. if (!$failed && $type ne "boot"){
  1254. do_run_test or $failed = 1;
  1255. }
  1256. end_monitor;
  1257. return 0 if ($failed);
  1258. }
  1259. $in_patchcheck = 0;
  1260. success $i;
  1261. return 1;
  1262. }
  1263. read_config $ARGV[0];
  1264. # mandatory configs
  1265. die "MACHINE not defined\n" if (!defined($opt{"MACHINE"}));
  1266. die "SSH_USER not defined\n" if (!defined($opt{"SSH_USER"}));
  1267. die "BUILD_DIR not defined\n" if (!defined($opt{"BUILD_DIR"}));
  1268. die "OUTPUT_DIR not defined\n" if (!defined($opt{"OUTPUT_DIR"}));
  1269. die "BUILD_TARGET not defined\n" if (!defined($opt{"BUILD_TARGET"}));
  1270. die "TARGET_IMAGE not defined\n" if (!defined($opt{"TARGET_IMAGE"}));
  1271. die "POWER_CYCLE not defined\n" if (!defined($opt{"POWER_CYCLE"}));
  1272. die "CONSOLE not defined\n" if (!defined($opt{"CONSOLE"}));
  1273. die "LOCALVERSION not defined\n" if (!defined($opt{"LOCALVERSION"}));
  1274. if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
  1275. unlink $opt{"LOG_FILE"};
  1276. }
  1277. doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
  1278. for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
  1279. if (!$i) {
  1280. doprint "DEFAULT OPTIONS:\n";
  1281. } else {
  1282. doprint "\nTEST $i OPTIONS";
  1283. if (defined($repeat_tests{$i})) {
  1284. $repeat = $repeat_tests{$i};
  1285. doprint " ITERATE $repeat";
  1286. }
  1287. doprint "\n";
  1288. }
  1289. foreach my $option (sort keys %opt) {
  1290. if ($option =~ /\[(\d+)\]$/) {
  1291. next if ($i != $1);
  1292. } else {
  1293. next if ($i);
  1294. }
  1295. doprint "$option = $opt{$option}\n";
  1296. }
  1297. }
  1298. sub set_test_option {
  1299. my ($name, $i) = @_;
  1300. my $option = "$name\[$i\]";
  1301. if (defined($opt{$option})) {
  1302. return $opt{$option};
  1303. }
  1304. foreach my $test (keys %repeat_tests) {
  1305. if ($i >= $test &&
  1306. $i < $test + $repeat_tests{$test}) {
  1307. $option = "$name\[$test\]";
  1308. if (defined($opt{$option})) {
  1309. return $opt{$option};
  1310. }
  1311. }
  1312. }
  1313. if (defined($opt{$name})) {
  1314. return $opt{$name};
  1315. }
  1316. return undef;
  1317. }
  1318. # First we need to do is the builds
  1319. for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
  1320. $iteration = $i;
  1321. my $makecmd = set_test_option("MAKE_CMD", $i);
  1322. $machine = set_test_option("MACHINE", $i);
  1323. $ssh_user = set_test_option("SSH_USER", $i);
  1324. $tmpdir = set_test_option("TMP_DIR", $i);
  1325. $outputdir = set_test_option("OUTPUT_DIR", $i);
  1326. $builddir = set_test_option("BUILD_DIR", $i);
  1327. $test_type = set_test_option("TEST_TYPE", $i);
  1328. $build_type = set_test_option("BUILD_TYPE", $i);
  1329. $build_options = set_test_option("BUILD_OPTIONS", $i);
  1330. $power_cycle = set_test_option("POWER_CYCLE", $i);
  1331. $reboot = set_test_option("REBOOT", $i);
  1332. $noclean = set_test_option("BUILD_NOCLEAN", $i);
  1333. $minconfig = set_test_option("MIN_CONFIG", $i);
  1334. $run_test = set_test_option("TEST", $i);
  1335. $addconfig = set_test_option("ADD_CONFIG", $i);
  1336. $reboot_type = set_test_option("REBOOT_TYPE", $i);
  1337. $grub_menu = set_test_option("GRUB_MENU", $i);
  1338. $post_install = set_test_option("POST_INSTALL", $i);
  1339. $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
  1340. $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
  1341. $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
  1342. $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
  1343. $power_off = set_test_option("POWER_OFF", $i);
  1344. $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
  1345. $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
  1346. $sleep_time = set_test_option("SLEEP_TIME", $i);
  1347. $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
  1348. $store_failures = set_test_option("STORE_FAILURES", $i);
  1349. $timeout = set_test_option("TIMEOUT", $i);
  1350. $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
  1351. $console = set_test_option("CONSOLE", $i);
  1352. $success_line = set_test_option("SUCCESS_LINE", $i);
  1353. $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
  1354. $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
  1355. $build_target = set_test_option("BUILD_TARGET", $i);
  1356. $ssh_exec = set_test_option("SSH_EXEC", $i);
  1357. $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
  1358. $target_image = set_test_option("TARGET_IMAGE", $i);
  1359. $localversion = set_test_option("LOCALVERSION", $i);
  1360. chdir $builddir || die "can't change directory to $builddir";
  1361. if (!-d $tmpdir) {
  1362. mkpath($tmpdir) or
  1363. die "can't create $tmpdir";
  1364. }
  1365. $ENV{"SSH_USER"} = $ssh_user;
  1366. $ENV{"MACHINE"} = $machine;
  1367. $target = "$ssh_user\@$machine";
  1368. $buildlog = "$tmpdir/buildlog-$machine";
  1369. $dmesg = "$tmpdir/dmesg-$machine";
  1370. $make = "$makecmd O=$outputdir";
  1371. $output_config = "$outputdir/.config";
  1372. if ($reboot_type eq "grub") {
  1373. dodie "GRUB_MENU not defined" if (!defined($grub_menu));
  1374. } elsif (!defined($reboot_script)) {
  1375. dodie "REBOOT_SCRIPT not defined"
  1376. }
  1377. my $run_type = $build_type;
  1378. if ($test_type eq "patchcheck") {
  1379. $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
  1380. } elsif ($test_type eq "bisect") {
  1381. $run_type = $opt{"BISECT_TYPE[$i]"};
  1382. } elsif ($test_type eq "config_bisect") {
  1383. $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
  1384. }
  1385. # mistake in config file?
  1386. if (!defined($run_type)) {
  1387. $run_type = "ERROR";
  1388. }
  1389. doprint "\n\n";
  1390. doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type\n\n";
  1391. unlink $dmesg;
  1392. unlink $buildlog;
  1393. if (!defined($minconfig)) {
  1394. $minconfig = $addconfig;
  1395. } elsif (defined($addconfig)) {
  1396. run_command "cat $addconfig $minconfig > $tmpdir/add_config" or
  1397. dodie "Failed to create temp config";
  1398. $minconfig = "$tmpdir/add_config";
  1399. }
  1400. my $checkout = $opt{"CHECKOUT[$i]"};
  1401. if (defined($checkout)) {
  1402. run_command "git checkout $checkout" or
  1403. die "failed to checkout $checkout";
  1404. }
  1405. if ($test_type eq "bisect") {
  1406. bisect $i;
  1407. next;
  1408. } elsif ($test_type eq "config_bisect") {
  1409. config_bisect $i;
  1410. next;
  1411. } elsif ($test_type eq "patchcheck") {
  1412. patchcheck $i;
  1413. next;
  1414. }
  1415. if ($build_type ne "nobuild") {
  1416. build $build_type or next;
  1417. }
  1418. if ($test_type ne "build") {
  1419. get_grub_index;
  1420. get_version;
  1421. install;
  1422. my $failed = 0;
  1423. start_monitor;
  1424. monitor or $failed = 1;;
  1425. if (!$failed && $test_type ne "boot" && defined($run_test)) {
  1426. do_run_test or $failed = 1;
  1427. }
  1428. end_monitor;
  1429. next if ($failed);
  1430. }
  1431. success $i;
  1432. }
  1433. if ($opt{"POWEROFF_ON_SUCCESS"}) {
  1434. halt;
  1435. } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
  1436. reboot;
  1437. }
  1438. doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
  1439. exit 0;