ktest.pl 52 KB

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