ktest.pl 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129
  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{"NO_INSTALL"} = 0;
  41. $default{"BOOTED_TIMEOUT"} = 1;
  42. $default{"DIE_ON_FAILURE"} = 1;
  43. $default{"SSH_EXEC"} = "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND";
  44. $default{"SCP_TO_TARGET"} = "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE";
  45. $default{"REBOOT"} = "ssh \$SSH_USER\@\$MACHINE reboot";
  46. $default{"STOP_AFTER_SUCCESS"} = 10;
  47. $default{"STOP_AFTER_FAILURE"} = 60;
  48. $default{"STOP_TEST_AFTER"} = 600;
  49. $default{"LOCALVERSION"} = "-test";
  50. my $ktest_config;
  51. my $version;
  52. my $machine;
  53. my $ssh_user;
  54. my $tmpdir;
  55. my $builddir;
  56. my $outputdir;
  57. my $output_config;
  58. my $test_type;
  59. my $build_type;
  60. my $build_options;
  61. my $pre_build;
  62. my $post_build;
  63. my $pre_build_die;
  64. my $post_build_die;
  65. my $reboot_type;
  66. my $reboot_script;
  67. my $power_cycle;
  68. my $reboot;
  69. my $reboot_on_error;
  70. my $poweroff_on_error;
  71. my $die_on_failure;
  72. my $powercycle_after_reboot;
  73. my $poweroff_after_halt;
  74. my $ssh_exec;
  75. my $scp_to_target;
  76. my $power_off;
  77. my $grub_menu;
  78. my $grub_number;
  79. my $target;
  80. my $make;
  81. my $post_install;
  82. my $no_install;
  83. my $noclean;
  84. my $minconfig;
  85. my $start_minconfig;
  86. my $start_minconfig_defined;
  87. my $output_minconfig;
  88. my $ignore_config;
  89. my $addconfig;
  90. my $in_bisect = 0;
  91. my $bisect_bad = "";
  92. my $reverse_bisect;
  93. my $bisect_manual;
  94. my $bisect_skip;
  95. my $config_bisect_good;
  96. my $in_patchcheck = 0;
  97. my $run_test;
  98. my $redirect;
  99. my $buildlog;
  100. my $dmesg;
  101. my $monitor_fp;
  102. my $monitor_pid;
  103. my $monitor_cnt = 0;
  104. my $sleep_time;
  105. my $bisect_sleep_time;
  106. my $patchcheck_sleep_time;
  107. my $ignore_warnings;
  108. my $store_failures;
  109. my $test_name;
  110. my $timeout;
  111. my $booted_timeout;
  112. my $detect_triplefault;
  113. my $console;
  114. my $reboot_success_line;
  115. my $success_line;
  116. my $stop_after_success;
  117. my $stop_after_failure;
  118. my $stop_test_after;
  119. my $build_target;
  120. my $target_image;
  121. my $localversion;
  122. my $iteration = 0;
  123. my $successes = 0;
  124. my %entered_configs;
  125. my %config_help;
  126. my %variable;
  127. my %force_config;
  128. # do not force reboots on config problems
  129. my $no_reboot = 1;
  130. $config_help{"MACHINE"} = << "EOF"
  131. The machine hostname that you will test.
  132. EOF
  133. ;
  134. $config_help{"SSH_USER"} = << "EOF"
  135. The box is expected to have ssh on normal bootup, provide the user
  136. (most likely root, since you need privileged operations)
  137. EOF
  138. ;
  139. $config_help{"BUILD_DIR"} = << "EOF"
  140. The directory that contains the Linux source code (full path).
  141. EOF
  142. ;
  143. $config_help{"OUTPUT_DIR"} = << "EOF"
  144. The directory that the objects will be built (full path).
  145. (can not be same as BUILD_DIR)
  146. EOF
  147. ;
  148. $config_help{"BUILD_TARGET"} = << "EOF"
  149. The location of the compiled file to copy to the target.
  150. (relative to OUTPUT_DIR)
  151. EOF
  152. ;
  153. $config_help{"TARGET_IMAGE"} = << "EOF"
  154. The place to put your image on the test machine.
  155. EOF
  156. ;
  157. $config_help{"POWER_CYCLE"} = << "EOF"
  158. A script or command to reboot the box.
  159. Here is a digital loggers power switch example
  160. POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
  161. Here is an example to reboot a virtual box on the current host
  162. with the name "Guest".
  163. POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
  164. EOF
  165. ;
  166. $config_help{"CONSOLE"} = << "EOF"
  167. The script or command that reads the console
  168. If you use ttywatch server, something like the following would work.
  169. CONSOLE = nc -d localhost 3001
  170. For a virtual machine with guest name "Guest".
  171. CONSOLE = virsh console Guest
  172. EOF
  173. ;
  174. $config_help{"LOCALVERSION"} = << "EOF"
  175. Required version ending to differentiate the test
  176. from other linux builds on the system.
  177. EOF
  178. ;
  179. $config_help{"REBOOT_TYPE"} = << "EOF"
  180. Way to reboot the box to the test kernel.
  181. Only valid options so far are "grub" and "script".
  182. If you specify grub, it will assume grub version 1
  183. and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
  184. and select that target to reboot to the kernel. If this is not
  185. your setup, then specify "script" and have a command or script
  186. specified in REBOOT_SCRIPT to boot to the target.
  187. The entry in /boot/grub/menu.lst must be entered in manually.
  188. The test will not modify that file.
  189. EOF
  190. ;
  191. $config_help{"GRUB_MENU"} = << "EOF"
  192. The grub title name for the test kernel to boot
  193. (Only mandatory if REBOOT_TYPE = grub)
  194. Note, ktest.pl will not update the grub menu.lst, you need to
  195. manually add an option for the test. ktest.pl will search
  196. the grub menu.lst for this option to find what kernel to
  197. reboot into.
  198. For example, if in the /boot/grub/menu.lst the test kernel title has:
  199. title Test Kernel
  200. kernel vmlinuz-test
  201. GRUB_MENU = Test Kernel
  202. EOF
  203. ;
  204. $config_help{"REBOOT_SCRIPT"} = << "EOF"
  205. A script to reboot the target into the test kernel
  206. (Only mandatory if REBOOT_TYPE = script)
  207. EOF
  208. ;
  209. sub read_yn {
  210. my ($prompt) = @_;
  211. my $ans;
  212. for (;;) {
  213. print "$prompt [Y/n] ";
  214. $ans = <STDIN>;
  215. chomp $ans;
  216. if ($ans =~ /^\s*$/) {
  217. $ans = "y";
  218. }
  219. last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
  220. print "Please answer either 'y' or 'n'.\n";
  221. }
  222. if ($ans !~ /^y$/i) {
  223. return 0;
  224. }
  225. return 1;
  226. }
  227. sub get_ktest_config {
  228. my ($config) = @_;
  229. return if (defined($opt{$config}));
  230. if (defined($config_help{$config})) {
  231. print "\n";
  232. print $config_help{$config};
  233. }
  234. for (;;) {
  235. print "$config = ";
  236. if (defined($default{$config})) {
  237. print "\[$default{$config}\] ";
  238. }
  239. $entered_configs{$config} = <STDIN>;
  240. $entered_configs{$config} =~ s/^\s*(.*\S)\s*$/$1/;
  241. if ($entered_configs{$config} =~ /^\s*$/) {
  242. if ($default{$config}) {
  243. $entered_configs{$config} = $default{$config};
  244. } else {
  245. print "Your answer can not be blank\n";
  246. next;
  247. }
  248. }
  249. last;
  250. }
  251. }
  252. sub get_ktest_configs {
  253. get_ktest_config("MACHINE");
  254. get_ktest_config("SSH_USER");
  255. get_ktest_config("BUILD_DIR");
  256. get_ktest_config("OUTPUT_DIR");
  257. get_ktest_config("BUILD_TARGET");
  258. get_ktest_config("TARGET_IMAGE");
  259. get_ktest_config("POWER_CYCLE");
  260. get_ktest_config("CONSOLE");
  261. get_ktest_config("LOCALVERSION");
  262. my $rtype = $opt{"REBOOT_TYPE"};
  263. if (!defined($rtype)) {
  264. if (!defined($opt{"GRUB_MENU"})) {
  265. get_ktest_config("REBOOT_TYPE");
  266. $rtype = $entered_configs{"REBOOT_TYPE"};
  267. } else {
  268. $rtype = "grub";
  269. }
  270. }
  271. if ($rtype eq "grub") {
  272. get_ktest_config("GRUB_MENU");
  273. } else {
  274. get_ktest_config("REBOOT_SCRIPT");
  275. }
  276. }
  277. sub process_variables {
  278. my ($value) = @_;
  279. my $retval = "";
  280. # We want to check for '\', and it is just easier
  281. # to check the previous characet of '$' and not need
  282. # to worry if '$' is the first character. By adding
  283. # a space to $value, we can just check [^\\]\$ and
  284. # it will still work.
  285. $value = " $value";
  286. while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
  287. my $begin = $1;
  288. my $var = $2;
  289. my $end = $3;
  290. # append beginning of value to retval
  291. $retval = "$retval$begin";
  292. if (defined($variable{$var})) {
  293. $retval = "$retval$variable{$var}";
  294. } else {
  295. # put back the origin piece.
  296. $retval = "$retval\$\{$var\}";
  297. }
  298. $value = $end;
  299. }
  300. $retval = "$retval$value";
  301. # remove the space added in the beginning
  302. $retval =~ s/ //;
  303. return "$retval"
  304. }
  305. sub set_value {
  306. my ($lvalue, $rvalue) = @_;
  307. if (defined($opt{$lvalue})) {
  308. die "Error: Option $lvalue defined more than once!\n";
  309. }
  310. if ($rvalue =~ /^\s*$/) {
  311. delete $opt{$lvalue};
  312. } else {
  313. $rvalue = process_variables($rvalue);
  314. $opt{$lvalue} = $rvalue;
  315. }
  316. }
  317. sub set_variable {
  318. my ($lvalue, $rvalue) = @_;
  319. if ($rvalue =~ /^\s*$/) {
  320. delete $variable{$lvalue};
  321. } else {
  322. $rvalue = process_variables($rvalue);
  323. $variable{$lvalue} = $rvalue;
  324. }
  325. }
  326. sub process_compare {
  327. my ($lval, $cmp, $rval) = @_;
  328. # remove whitespace
  329. $lval =~ s/^\s*//;
  330. $lval =~ s/\s*$//;
  331. $rval =~ s/^\s*//;
  332. $rval =~ s/\s*$//;
  333. if ($cmp eq "==") {
  334. return $lval eq $rval;
  335. } elsif ($cmp eq "!=") {
  336. return $lval ne $rval;
  337. }
  338. my $statement = "$lval $cmp $rval";
  339. my $ret = eval $statement;
  340. # $@ stores error of eval
  341. if ($@) {
  342. return -1;
  343. }
  344. return $ret;
  345. }
  346. sub process_if {
  347. my ($name, $value) = @_;
  348. my $val = process_variables($value);
  349. if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) {
  350. my $ret = process_compare($1, $2, $3);
  351. if ($ret < 0) {
  352. die "$name: $.: Unable to process comparison\n";
  353. }
  354. return $ret;
  355. }
  356. if ($val =~ /^\s*0\s*$/) {
  357. return 0;
  358. } elsif ($val =~ /^\s*\d+\s*$/) {
  359. return 1;
  360. }
  361. die ("$name: $.: Undefined variable $val in if statement\n");
  362. return 1;
  363. }
  364. sub __read_config {
  365. my ($config, $current_test_num) = @_;
  366. my $in;
  367. open($in, $config) || die "can't read file $config";
  368. my $name = $config;
  369. $name =~ s,.*/(.*),$1,;
  370. my $test_num = $$current_test_num;
  371. my $default = 1;
  372. my $repeat = 1;
  373. my $num_tests_set = 0;
  374. my $skip = 0;
  375. my $rest;
  376. my $test_case = 0;
  377. my $if = 0;
  378. my $if_set = 0;
  379. while (<$in>) {
  380. # ignore blank lines and comments
  381. next if (/^\s*$/ || /\s*\#/);
  382. if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
  383. my $type = $1;
  384. $rest = $2;
  385. my $old_test_num;
  386. my $old_repeat;
  387. if ($type eq "TEST_START") {
  388. if ($num_tests_set) {
  389. die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
  390. }
  391. $old_test_num = $test_num;
  392. $old_repeat = $repeat;
  393. $test_num += $repeat;
  394. $default = 0;
  395. $repeat = 1;
  396. } else {
  397. $default = 1;
  398. }
  399. if ($rest =~ /\s+SKIP\b(.*)/) {
  400. $rest = $1;
  401. $skip = 1;
  402. } else {
  403. $test_case = 1;
  404. $skip = 0;
  405. }
  406. if ($rest =~ /\s+ITERATE\s+(\d+)(.*)$/) {
  407. $repeat = $1;
  408. $rest = $2;
  409. $repeat_tests{"$test_num"} = $repeat;
  410. }
  411. if ($rest =~ /\sIF\s+(.*)/) {
  412. $rest = "";
  413. if (process_if($name, $1)) {
  414. $if_set = 1;
  415. } else {
  416. $skip = 1;
  417. }
  418. $if = 1;
  419. } else {
  420. $if = 0;
  421. }
  422. if ($rest !~ /^\s*$/) {
  423. die "$name: $.: Gargbage found after $type\n$_";
  424. }
  425. if ($skip && $type eq "TEST_START") {
  426. $test_num = $old_test_num;
  427. $repeat = $old_repeat;
  428. }
  429. } elsif (/^\s*ELSE\b(.*)$/) {
  430. if (!$if) {
  431. die "$name: $.: ELSE found with out matching IF section\n$_";
  432. }
  433. $rest = $1;
  434. if ($if_set) {
  435. $skip = 1;
  436. $rest = "";
  437. } else {
  438. $skip = 0;
  439. if ($rest =~ /\sIF\s+(.*)/) {
  440. # May be a ELSE IF section.
  441. if (!process_if($name, $1)) {
  442. $skip = 1;
  443. }
  444. $rest = "";
  445. } else {
  446. $if = 0;
  447. }
  448. }
  449. if ($rest !~ /^\s*$/) {
  450. die "$name: $.: Gargbage found after DEFAULTS\n$_";
  451. }
  452. } elsif (/^\s*INCLUDE\s+(\S+)/) {
  453. next if ($skip);
  454. if (!$default) {
  455. die "$name: $.: INCLUDE can only be done in default sections\n$_";
  456. }
  457. my $file = process_variables($1);
  458. if ($file !~ m,^/,) {
  459. # check the path of the config file first
  460. if ($config =~ m,(.*)/,) {
  461. if (-f "$1/$file") {
  462. $file = "$1/$file";
  463. }
  464. }
  465. }
  466. if ( ! -r $file ) {
  467. die "$name: $.: Can't read file $file\n$_";
  468. }
  469. if (__read_config($file, \$test_num)) {
  470. $test_case = 1;
  471. }
  472. } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
  473. next if ($skip);
  474. my $lvalue = $1;
  475. my $rvalue = $2;
  476. if (!$default &&
  477. ($lvalue eq "NUM_TESTS" ||
  478. $lvalue eq "LOG_FILE" ||
  479. $lvalue eq "CLEAR_LOG")) {
  480. die "$name: $.: $lvalue must be set in DEFAULTS section\n";
  481. }
  482. if ($lvalue eq "NUM_TESTS") {
  483. if ($test_num) {
  484. die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
  485. }
  486. if (!$default) {
  487. die "$name: $.: NUM_TESTS must be set in default section\n";
  488. }
  489. $num_tests_set = 1;
  490. }
  491. if ($default || $lvalue =~ /\[\d+\]$/) {
  492. set_value($lvalue, $rvalue);
  493. } else {
  494. my $val = "$lvalue\[$test_num\]";
  495. set_value($val, $rvalue);
  496. if ($repeat > 1) {
  497. $repeats{$val} = $repeat;
  498. }
  499. }
  500. } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
  501. next if ($skip);
  502. my $lvalue = $1;
  503. my $rvalue = $2;
  504. # process config variables.
  505. # Config variables are only active while reading the
  506. # config and can be defined anywhere. They also ignore
  507. # TEST_START and DEFAULTS, but are skipped if they are in
  508. # on of these sections that have SKIP defined.
  509. # The save variable can be
  510. # defined multiple times and the new one simply overrides
  511. # the prevous one.
  512. set_variable($lvalue, $rvalue);
  513. } else {
  514. die "$name: $.: Garbage found in config\n$_";
  515. }
  516. }
  517. if ($test_num) {
  518. $test_num += $repeat - 1;
  519. $opt{"NUM_TESTS"} = $test_num;
  520. }
  521. close($in);
  522. $$current_test_num = $test_num;
  523. return $test_case;
  524. }
  525. sub read_config {
  526. my ($config) = @_;
  527. my $test_case;
  528. my $test_num = 0;
  529. $test_case = __read_config $config, \$test_num;
  530. # make sure we have all mandatory configs
  531. get_ktest_configs;
  532. # was a test specified?
  533. if (!$test_case) {
  534. print "No test case specified.\n";
  535. print "What test case would you like to run?\n";
  536. my $ans = <STDIN>;
  537. chomp $ans;
  538. $default{"TEST_TYPE"} = $ans;
  539. }
  540. # set any defaults
  541. foreach my $default (keys %default) {
  542. if (!defined($opt{$default})) {
  543. $opt{$default} = $default{$default};
  544. }
  545. }
  546. }
  547. sub __eval_option {
  548. my ($option, $i) = @_;
  549. # Add space to evaluate the character before $
  550. $option = " $option";
  551. my $retval = "";
  552. while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
  553. my $start = $1;
  554. my $var = $2;
  555. my $end = $3;
  556. # Append beginning of line
  557. $retval = "$retval$start";
  558. # If the iteration option OPT[$i] exists, then use that.
  559. # otherwise see if the default OPT (without [$i]) exists.
  560. my $o = "$var\[$i\]";
  561. if (defined($opt{$o})) {
  562. $o = $opt{$o};
  563. $retval = "$retval$o";
  564. } elsif (defined($opt{$var})) {
  565. $o = $opt{$var};
  566. $retval = "$retval$o";
  567. } else {
  568. $retval = "$retval\$\{$var\}";
  569. }
  570. $option = $end;
  571. }
  572. $retval = "$retval$option";
  573. $retval =~ s/^ //;
  574. return $retval;
  575. }
  576. sub eval_option {
  577. my ($option, $i) = @_;
  578. my $prev = "";
  579. # Since an option can evaluate to another option,
  580. # keep iterating until we do not evaluate any more
  581. # options.
  582. my $r = 0;
  583. while ($prev ne $option) {
  584. # Check for recursive evaluations.
  585. # 100 deep should be more than enough.
  586. if ($r++ > 100) {
  587. die "Over 100 evaluations accurred with $option\n" .
  588. "Check for recursive variables\n";
  589. }
  590. $prev = $option;
  591. $option = __eval_option($option, $i);
  592. }
  593. return $option;
  594. }
  595. sub _logit {
  596. if (defined($opt{"LOG_FILE"})) {
  597. open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
  598. print OUT @_;
  599. close(OUT);
  600. }
  601. }
  602. sub logit {
  603. if (defined($opt{"LOG_FILE"})) {
  604. _logit @_;
  605. } else {
  606. print @_;
  607. }
  608. }
  609. sub doprint {
  610. print @_;
  611. _logit @_;
  612. }
  613. sub run_command;
  614. sub start_monitor;
  615. sub end_monitor;
  616. sub wait_for_monitor;
  617. sub reboot {
  618. my ($time) = @_;
  619. if (defined($time)) {
  620. start_monitor;
  621. # flush out current monitor
  622. # May contain the reboot success line
  623. wait_for_monitor 1;
  624. }
  625. # try to reboot normally
  626. if (run_command $reboot) {
  627. if (defined($powercycle_after_reboot)) {
  628. sleep $powercycle_after_reboot;
  629. run_command "$power_cycle";
  630. }
  631. } else {
  632. # nope? power cycle it.
  633. run_command "$power_cycle";
  634. }
  635. if (defined($time)) {
  636. wait_for_monitor($time, $reboot_success_line);
  637. end_monitor;
  638. }
  639. }
  640. sub do_not_reboot {
  641. my $i = $iteration;
  642. return $test_type eq "build" || $no_reboot ||
  643. ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
  644. ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
  645. }
  646. sub dodie {
  647. doprint "CRITICAL FAILURE... ", @_, "\n";
  648. my $i = $iteration;
  649. if ($reboot_on_error && !do_not_reboot) {
  650. doprint "REBOOTING\n";
  651. reboot;
  652. } elsif ($poweroff_on_error && defined($power_off)) {
  653. doprint "POWERING OFF\n";
  654. `$power_off`;
  655. }
  656. if (defined($opt{"LOG_FILE"})) {
  657. print " See $opt{LOG_FILE} for more info.\n";
  658. }
  659. die @_, "\n";
  660. }
  661. sub open_console {
  662. my ($fp) = @_;
  663. my $flags;
  664. my $pid = open($fp, "$console|") or
  665. dodie "Can't open console $console";
  666. $flags = fcntl($fp, F_GETFL, 0) or
  667. dodie "Can't get flags for the socket: $!";
  668. $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
  669. dodie "Can't set flags for the socket: $!";
  670. return $pid;
  671. }
  672. sub close_console {
  673. my ($fp, $pid) = @_;
  674. doprint "kill child process $pid\n";
  675. kill 2, $pid;
  676. print "closing!\n";
  677. close($fp);
  678. }
  679. sub start_monitor {
  680. if ($monitor_cnt++) {
  681. return;
  682. }
  683. $monitor_fp = \*MONFD;
  684. $monitor_pid = open_console $monitor_fp;
  685. return;
  686. open(MONFD, "Stop perl from warning about single use of MONFD");
  687. }
  688. sub end_monitor {
  689. if (--$monitor_cnt) {
  690. return;
  691. }
  692. close_console($monitor_fp, $monitor_pid);
  693. }
  694. sub wait_for_monitor {
  695. my ($time, $stop) = @_;
  696. my $full_line = "";
  697. my $line;
  698. my $booted = 0;
  699. doprint "** Wait for monitor to settle down **\n";
  700. # read the monitor and wait for the system to calm down
  701. while (!$booted) {
  702. $line = wait_for_input($monitor_fp, $time);
  703. last if (!defined($line));
  704. print "$line";
  705. $full_line .= $line;
  706. if (defined($stop) && $full_line =~ /$stop/) {
  707. doprint "wait for monitor detected $stop\n";
  708. $booted = 1;
  709. }
  710. if ($line =~ /\n/) {
  711. $full_line = "";
  712. }
  713. }
  714. print "** Monitor flushed **\n";
  715. }
  716. sub fail {
  717. if ($die_on_failure) {
  718. dodie @_;
  719. }
  720. doprint "FAILED\n";
  721. my $i = $iteration;
  722. # no need to reboot for just building.
  723. if (!do_not_reboot) {
  724. doprint "REBOOTING\n";
  725. reboot $sleep_time;
  726. }
  727. my $name = "";
  728. if (defined($test_name)) {
  729. $name = " ($test_name)";
  730. }
  731. doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
  732. doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
  733. doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
  734. doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
  735. doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
  736. return 1 if (!defined($store_failures));
  737. my @t = localtime;
  738. my $date = sprintf "%04d%02d%02d%02d%02d%02d",
  739. 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
  740. my $type = $build_type;
  741. if ($type =~ /useconfig/) {
  742. $type = "useconfig";
  743. }
  744. my $dir = "$machine-$test_type-$type-fail-$date";
  745. my $faildir = "$store_failures/$dir";
  746. if (!-d $faildir) {
  747. mkpath($faildir) or
  748. die "can't create $faildir";
  749. }
  750. if (-f "$output_config") {
  751. cp "$output_config", "$faildir/config" or
  752. die "failed to copy .config";
  753. }
  754. if (-f $buildlog) {
  755. cp $buildlog, "$faildir/buildlog" or
  756. die "failed to move $buildlog";
  757. }
  758. if (-f $dmesg) {
  759. cp $dmesg, "$faildir/dmesg" or
  760. die "failed to move $dmesg";
  761. }
  762. doprint "*** Saved info to $faildir ***\n";
  763. return 1;
  764. }
  765. sub run_command {
  766. my ($command) = @_;
  767. my $dolog = 0;
  768. my $dord = 0;
  769. my $pid;
  770. $command =~ s/\$SSH_USER/$ssh_user/g;
  771. $command =~ s/\$MACHINE/$machine/g;
  772. doprint("$command ... ");
  773. $pid = open(CMD, "$command 2>&1 |") or
  774. (fail "unable to exec $command" and return 0);
  775. if (defined($opt{"LOG_FILE"})) {
  776. open(LOG, ">>$opt{LOG_FILE}") or
  777. dodie "failed to write to log";
  778. $dolog = 1;
  779. }
  780. if (defined($redirect)) {
  781. open (RD, ">$redirect") or
  782. dodie "failed to write to redirect $redirect";
  783. $dord = 1;
  784. }
  785. while (<CMD>) {
  786. print LOG if ($dolog);
  787. print RD if ($dord);
  788. }
  789. waitpid($pid, 0);
  790. my $failed = $?;
  791. close(CMD);
  792. close(LOG) if ($dolog);
  793. close(RD) if ($dord);
  794. if ($failed) {
  795. doprint "FAILED!\n";
  796. } else {
  797. doprint "SUCCESS\n";
  798. }
  799. return !$failed;
  800. }
  801. sub run_ssh {
  802. my ($cmd) = @_;
  803. my $cp_exec = $ssh_exec;
  804. $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
  805. return run_command "$cp_exec";
  806. }
  807. sub run_scp {
  808. my ($src, $dst) = @_;
  809. my $cp_scp = $scp_to_target;
  810. $cp_scp =~ s/\$SRC_FILE/$src/g;
  811. $cp_scp =~ s/\$DST_FILE/$dst/g;
  812. return run_command "$cp_scp";
  813. }
  814. sub get_grub_index {
  815. if ($reboot_type ne "grub") {
  816. return;
  817. }
  818. return if (defined($grub_number));
  819. doprint "Find grub menu ... ";
  820. $grub_number = -1;
  821. my $ssh_grub = $ssh_exec;
  822. $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
  823. open(IN, "$ssh_grub |")
  824. or die "unable to get menu.lst";
  825. my $found = 0;
  826. while (<IN>) {
  827. if (/^\s*title\s+$grub_menu\s*$/) {
  828. $grub_number++;
  829. $found = 1;
  830. last;
  831. } elsif (/^\s*title\s/) {
  832. $grub_number++;
  833. }
  834. }
  835. close(IN);
  836. die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
  837. if (!$found);
  838. doprint "$grub_number\n";
  839. }
  840. sub wait_for_input
  841. {
  842. my ($fp, $time) = @_;
  843. my $rin;
  844. my $ready;
  845. my $line;
  846. my $ch;
  847. if (!defined($time)) {
  848. $time = $timeout;
  849. }
  850. $rin = '';
  851. vec($rin, fileno($fp), 1) = 1;
  852. $ready = select($rin, undef, undef, $time);
  853. $line = "";
  854. # try to read one char at a time
  855. while (sysread $fp, $ch, 1) {
  856. $line .= $ch;
  857. last if ($ch eq "\n");
  858. }
  859. if (!length($line)) {
  860. return undef;
  861. }
  862. return $line;
  863. }
  864. sub reboot_to {
  865. if ($reboot_type eq "grub") {
  866. run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch && reboot)'";
  867. return;
  868. }
  869. run_command "$reboot_script";
  870. }
  871. sub get_sha1 {
  872. my ($commit) = @_;
  873. doprint "git rev-list --max-count=1 $commit ... ";
  874. my $sha1 = `git rev-list --max-count=1 $commit`;
  875. my $ret = $?;
  876. logit $sha1;
  877. if ($ret) {
  878. doprint "FAILED\n";
  879. dodie "Failed to get git $commit";
  880. }
  881. print "SUCCESS\n";
  882. chomp $sha1;
  883. return $sha1;
  884. }
  885. sub monitor {
  886. my $booted = 0;
  887. my $bug = 0;
  888. my $skip_call_trace = 0;
  889. my $loops;
  890. wait_for_monitor 5;
  891. my $line;
  892. my $full_line = "";
  893. open(DMESG, "> $dmesg") or
  894. die "unable to write to $dmesg";
  895. reboot_to;
  896. my $success_start;
  897. my $failure_start;
  898. my $monitor_start = time;
  899. my $done = 0;
  900. my $version_found = 0;
  901. while (!$done) {
  902. if ($bug && defined($stop_after_failure) &&
  903. $stop_after_failure >= 0) {
  904. my $time = $stop_after_failure - (time - $failure_start);
  905. $line = wait_for_input($monitor_fp, $time);
  906. if (!defined($line)) {
  907. doprint "bug timed out after $booted_timeout seconds\n";
  908. doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
  909. last;
  910. }
  911. } elsif ($booted) {
  912. $line = wait_for_input($monitor_fp, $booted_timeout);
  913. if (!defined($line)) {
  914. my $s = $booted_timeout == 1 ? "" : "s";
  915. doprint "Successful boot found: break after $booted_timeout second$s\n";
  916. last;
  917. }
  918. } else {
  919. $line = wait_for_input($monitor_fp);
  920. if (!defined($line)) {
  921. my $s = $timeout == 1 ? "" : "s";
  922. doprint "Timed out after $timeout second$s\n";
  923. last;
  924. }
  925. }
  926. doprint $line;
  927. print DMESG $line;
  928. # we are not guaranteed to get a full line
  929. $full_line .= $line;
  930. if ($full_line =~ /$success_line/) {
  931. $booted = 1;
  932. $success_start = time;
  933. }
  934. if ($booted && defined($stop_after_success) &&
  935. $stop_after_success >= 0) {
  936. my $now = time;
  937. if ($now - $success_start >= $stop_after_success) {
  938. doprint "Test forced to stop after $stop_after_success seconds after success\n";
  939. last;
  940. }
  941. }
  942. if ($full_line =~ /\[ backtrace testing \]/) {
  943. $skip_call_trace = 1;
  944. }
  945. if ($full_line =~ /call trace:/i) {
  946. if (!$bug && !$skip_call_trace) {
  947. $bug = 1;
  948. $failure_start = time;
  949. }
  950. }
  951. if ($bug && defined($stop_after_failure) &&
  952. $stop_after_failure >= 0) {
  953. my $now = time;
  954. if ($now - $failure_start >= $stop_after_failure) {
  955. doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
  956. last;
  957. }
  958. }
  959. if ($full_line =~ /\[ end of backtrace testing \]/) {
  960. $skip_call_trace = 0;
  961. }
  962. if ($full_line =~ /Kernel panic -/) {
  963. $failure_start = time;
  964. $bug = 1;
  965. }
  966. # Detect triple faults by testing the banner
  967. if ($full_line =~ /\bLinux version (\S+).*\n/) {
  968. if ($1 eq $version) {
  969. $version_found = 1;
  970. } elsif ($version_found && $detect_triplefault) {
  971. # We already booted into the kernel we are testing,
  972. # but now we booted into another kernel?
  973. # Consider this a triple fault.
  974. doprint "Aleady booted in Linux kernel $version, but now\n";
  975. doprint "we booted into Linux kernel $1.\n";
  976. doprint "Assuming that this is a triple fault.\n";
  977. doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
  978. last;
  979. }
  980. }
  981. if ($line =~ /\n/) {
  982. $full_line = "";
  983. }
  984. if ($stop_test_after > 0 && !$booted && !$bug) {
  985. if (time - $monitor_start > $stop_test_after) {
  986. doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
  987. $done = 1;
  988. }
  989. }
  990. }
  991. close(DMESG);
  992. if ($bug) {
  993. return 0 if ($in_bisect);
  994. fail "failed - got a bug report" and return 0;
  995. }
  996. if (!$booted) {
  997. return 0 if ($in_bisect);
  998. fail "failed - never got a boot prompt." and return 0;
  999. }
  1000. return 1;
  1001. }
  1002. sub do_post_install {
  1003. return if (!defined($post_install));
  1004. my $cp_post_install = $post_install;
  1005. $cp_post_install =~ s/\$KERNEL_VERSION/$version/g;
  1006. run_command "$cp_post_install" or
  1007. dodie "Failed to run post install";
  1008. }
  1009. sub install {
  1010. return if ($no_install);
  1011. run_scp "$outputdir/$build_target", "$target_image" or
  1012. dodie "failed to copy image";
  1013. my $install_mods = 0;
  1014. # should we process modules?
  1015. $install_mods = 0;
  1016. open(IN, "$output_config") or dodie("Can't read config file");
  1017. while (<IN>) {
  1018. if (/CONFIG_MODULES(=y)?/) {
  1019. $install_mods = 1 if (defined($1));
  1020. last;
  1021. }
  1022. }
  1023. close(IN);
  1024. if (!$install_mods) {
  1025. do_post_install;
  1026. doprint "No modules needed\n";
  1027. return;
  1028. }
  1029. run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
  1030. dodie "Failed to install modules";
  1031. my $modlib = "/lib/modules/$version";
  1032. my $modtar = "ktest-mods.tar.bz2";
  1033. run_ssh "rm -rf $modlib" or
  1034. dodie "failed to remove old mods: $modlib";
  1035. # would be nice if scp -r did not follow symbolic links
  1036. run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
  1037. dodie "making tarball";
  1038. run_scp "$tmpdir/$modtar", "/tmp" or
  1039. dodie "failed to copy modules";
  1040. unlink "$tmpdir/$modtar";
  1041. run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
  1042. dodie "failed to tar modules";
  1043. run_ssh "rm -f /tmp/$modtar";
  1044. do_post_install;
  1045. }
  1046. sub get_version {
  1047. # get the release name
  1048. doprint "$make kernelrelease ... ";
  1049. $version = `$make kernelrelease | tail -1`;
  1050. chomp($version);
  1051. doprint "$version\n";
  1052. }
  1053. sub start_monitor_and_boot {
  1054. get_grub_index;
  1055. get_version;
  1056. install;
  1057. start_monitor;
  1058. return monitor;
  1059. }
  1060. sub check_buildlog {
  1061. my ($patch) = @_;
  1062. my @files = `git show $patch | diffstat -l`;
  1063. open(IN, "git show $patch |") or
  1064. dodie "failed to show $patch";
  1065. while (<IN>) {
  1066. if (m,^--- a/(.*),) {
  1067. chomp $1;
  1068. $files[$#files] = $1;
  1069. }
  1070. }
  1071. close(IN);
  1072. open(IN, $buildlog) or dodie "Can't open $buildlog";
  1073. while (<IN>) {
  1074. if (/^\s*(.*?):.*(warning|error)/) {
  1075. my $err = $1;
  1076. foreach my $file (@files) {
  1077. my $fullpath = "$builddir/$file";
  1078. if ($file eq $err || $fullpath eq $err) {
  1079. fail "$file built with warnings" and return 0;
  1080. }
  1081. }
  1082. }
  1083. }
  1084. close(IN);
  1085. return 1;
  1086. }
  1087. sub apply_min_config {
  1088. my $outconfig = "$output_config.new";
  1089. # Read the config file and remove anything that
  1090. # is in the force_config hash (from minconfig and others)
  1091. # then add the force config back.
  1092. doprint "Applying minimum configurations into $output_config.new\n";
  1093. open (OUT, ">$outconfig") or
  1094. dodie "Can't create $outconfig";
  1095. if (-f $output_config) {
  1096. open (IN, $output_config) or
  1097. dodie "Failed to open $output_config";
  1098. while (<IN>) {
  1099. if (/^(# )?(CONFIG_[^\s=]*)/) {
  1100. next if (defined($force_config{$2}));
  1101. }
  1102. print OUT;
  1103. }
  1104. close IN;
  1105. }
  1106. foreach my $config (keys %force_config) {
  1107. print OUT "$force_config{$config}\n";
  1108. }
  1109. close OUT;
  1110. run_command "mv $outconfig $output_config";
  1111. }
  1112. sub make_oldconfig {
  1113. my @force_list = keys %force_config;
  1114. if ($#force_list >= 0) {
  1115. apply_min_config;
  1116. }
  1117. if (!run_command "$make oldnoconfig") {
  1118. # Perhaps oldnoconfig doesn't exist in this version of the kernel
  1119. # try a yes '' | oldconfig
  1120. doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
  1121. run_command "yes '' | $make oldconfig" or
  1122. dodie "failed make config oldconfig";
  1123. }
  1124. }
  1125. # read a config file and use this to force new configs.
  1126. sub load_force_config {
  1127. my ($config) = @_;
  1128. open(IN, $config) or
  1129. dodie "failed to read $config";
  1130. while (<IN>) {
  1131. chomp;
  1132. if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
  1133. $force_config{$1} = $_;
  1134. } elsif (/^# (CONFIG_\S*) is not set/) {
  1135. $force_config{$1} = $_;
  1136. }
  1137. }
  1138. close IN;
  1139. }
  1140. sub build {
  1141. my ($type) = @_;
  1142. unlink $buildlog;
  1143. # Failed builds should not reboot the target
  1144. my $save_no_reboot = $no_reboot;
  1145. $no_reboot = 1;
  1146. if (defined($pre_build)) {
  1147. my $ret = run_command $pre_build;
  1148. if (!$ret && defined($pre_build_die) &&
  1149. $pre_build_die) {
  1150. dodie "failed to pre_build\n";
  1151. }
  1152. }
  1153. if ($type =~ /^useconfig:(.*)/) {
  1154. run_command "cp $1 $output_config" or
  1155. dodie "could not copy $1 to .config";
  1156. $type = "oldconfig";
  1157. }
  1158. # old config can ask questions
  1159. if ($type eq "oldconfig") {
  1160. $type = "oldnoconfig";
  1161. # allow for empty configs
  1162. run_command "touch $output_config";
  1163. if (!$noclean) {
  1164. run_command "mv $output_config $outputdir/config_temp" or
  1165. dodie "moving .config";
  1166. run_command "$make mrproper" or dodie "make mrproper";
  1167. run_command "mv $outputdir/config_temp $output_config" or
  1168. dodie "moving config_temp";
  1169. }
  1170. } elsif (!$noclean) {
  1171. unlink "$output_config";
  1172. run_command "$make mrproper" or
  1173. dodie "make mrproper";
  1174. }
  1175. # add something to distinguish this build
  1176. open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
  1177. print OUT "$localversion\n";
  1178. close(OUT);
  1179. if (defined($minconfig)) {
  1180. load_force_config($minconfig);
  1181. }
  1182. if ($type ne "oldnoconfig") {
  1183. run_command "$make $type" or
  1184. dodie "failed make config";
  1185. }
  1186. # Run old config regardless, to enforce min configurations
  1187. make_oldconfig;
  1188. $redirect = "$buildlog";
  1189. my $build_ret = run_command "$make $build_options";
  1190. undef $redirect;
  1191. if (defined($post_build)) {
  1192. my $ret = run_command $post_build;
  1193. if (!$ret && defined($post_build_die) &&
  1194. $post_build_die) {
  1195. dodie "failed to post_build\n";
  1196. }
  1197. }
  1198. if (!$build_ret) {
  1199. # bisect may need this to pass
  1200. if ($in_bisect) {
  1201. $no_reboot = $save_no_reboot;
  1202. return 0;
  1203. }
  1204. fail "failed build" and return 0;
  1205. }
  1206. $no_reboot = $save_no_reboot;
  1207. return 1;
  1208. }
  1209. sub halt {
  1210. if (!run_ssh "halt" or defined($power_off)) {
  1211. if (defined($poweroff_after_halt)) {
  1212. sleep $poweroff_after_halt;
  1213. run_command "$power_off";
  1214. }
  1215. } else {
  1216. # nope? the zap it!
  1217. run_command "$power_off";
  1218. }
  1219. }
  1220. sub success {
  1221. my ($i) = @_;
  1222. $successes++;
  1223. my $name = "";
  1224. if (defined($test_name)) {
  1225. $name = " ($test_name)";
  1226. }
  1227. doprint "\n\n*******************************************\n";
  1228. doprint "*******************************************\n";
  1229. doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
  1230. doprint "*******************************************\n";
  1231. doprint "*******************************************\n";
  1232. if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
  1233. doprint "Reboot and wait $sleep_time seconds\n";
  1234. reboot $sleep_time;
  1235. }
  1236. }
  1237. sub answer_bisect {
  1238. for (;;) {
  1239. doprint "Pass or fail? [p/f]";
  1240. my $ans = <STDIN>;
  1241. chomp $ans;
  1242. if ($ans eq "p" || $ans eq "P") {
  1243. return 1;
  1244. } elsif ($ans eq "f" || $ans eq "F") {
  1245. return 0;
  1246. } else {
  1247. print "Please answer 'P' or 'F'\n";
  1248. }
  1249. }
  1250. }
  1251. sub child_run_test {
  1252. my $failed = 0;
  1253. # child should have no power
  1254. $reboot_on_error = 0;
  1255. $poweroff_on_error = 0;
  1256. $die_on_failure = 1;
  1257. run_command $run_test or $failed = 1;
  1258. exit $failed;
  1259. }
  1260. my $child_done;
  1261. sub child_finished {
  1262. $child_done = 1;
  1263. }
  1264. sub do_run_test {
  1265. my $child_pid;
  1266. my $child_exit;
  1267. my $line;
  1268. my $full_line;
  1269. my $bug = 0;
  1270. wait_for_monitor 1;
  1271. doprint "run test $run_test\n";
  1272. $child_done = 0;
  1273. $SIG{CHLD} = qw(child_finished);
  1274. $child_pid = fork;
  1275. child_run_test if (!$child_pid);
  1276. $full_line = "";
  1277. do {
  1278. $line = wait_for_input($monitor_fp, 1);
  1279. if (defined($line)) {
  1280. # we are not guaranteed to get a full line
  1281. $full_line .= $line;
  1282. doprint $line;
  1283. if ($full_line =~ /call trace:/i) {
  1284. $bug = 1;
  1285. }
  1286. if ($full_line =~ /Kernel panic -/) {
  1287. $bug = 1;
  1288. }
  1289. if ($line =~ /\n/) {
  1290. $full_line = "";
  1291. }
  1292. }
  1293. } while (!$child_done && !$bug);
  1294. if ($bug) {
  1295. my $failure_start = time;
  1296. my $now;
  1297. do {
  1298. $line = wait_for_input($monitor_fp, 1);
  1299. if (defined($line)) {
  1300. doprint $line;
  1301. }
  1302. $now = time;
  1303. if ($now - $failure_start >= $stop_after_failure) {
  1304. last;
  1305. }
  1306. } while (defined($line));
  1307. doprint "Detected kernel crash!\n";
  1308. # kill the child with extreme prejudice
  1309. kill 9, $child_pid;
  1310. }
  1311. waitpid $child_pid, 0;
  1312. $child_exit = $?;
  1313. if ($bug || $child_exit) {
  1314. return 0 if $in_bisect;
  1315. fail "test failed" and return 0;
  1316. }
  1317. return 1;
  1318. }
  1319. sub run_git_bisect {
  1320. my ($command) = @_;
  1321. doprint "$command ... ";
  1322. my $output = `$command 2>&1`;
  1323. my $ret = $?;
  1324. logit $output;
  1325. if ($ret) {
  1326. doprint "FAILED\n";
  1327. dodie "Failed to git bisect";
  1328. }
  1329. doprint "SUCCESS\n";
  1330. if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
  1331. doprint "$1 [$2]\n";
  1332. } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
  1333. $bisect_bad = $1;
  1334. doprint "Found bad commit... $1\n";
  1335. return 0;
  1336. } else {
  1337. # we already logged it, just print it now.
  1338. print $output;
  1339. }
  1340. return 1;
  1341. }
  1342. sub bisect_reboot {
  1343. doprint "Reboot and sleep $bisect_sleep_time seconds\n";
  1344. reboot $bisect_sleep_time;
  1345. }
  1346. # returns 1 on success, 0 on failure, -1 on skip
  1347. sub run_bisect_test {
  1348. my ($type, $buildtype) = @_;
  1349. my $failed = 0;
  1350. my $result;
  1351. my $output;
  1352. my $ret;
  1353. $in_bisect = 1;
  1354. build $buildtype or $failed = 1;
  1355. if ($type ne "build") {
  1356. if ($failed && $bisect_skip) {
  1357. $in_bisect = 0;
  1358. return -1;
  1359. }
  1360. dodie "Failed on build" if $failed;
  1361. # Now boot the box
  1362. start_monitor_and_boot or $failed = 1;
  1363. if ($type ne "boot") {
  1364. if ($failed && $bisect_skip) {
  1365. end_monitor;
  1366. bisect_reboot;
  1367. $in_bisect = 0;
  1368. return -1;
  1369. }
  1370. dodie "Failed on boot" if $failed;
  1371. do_run_test or $failed = 1;
  1372. }
  1373. end_monitor;
  1374. }
  1375. if ($failed) {
  1376. $result = 0;
  1377. } else {
  1378. $result = 1;
  1379. }
  1380. # reboot the box to a kernel we can ssh to
  1381. if ($type ne "build") {
  1382. bisect_reboot;
  1383. }
  1384. $in_bisect = 0;
  1385. return $result;
  1386. }
  1387. sub run_bisect {
  1388. my ($type) = @_;
  1389. my $buildtype = "oldconfig";
  1390. # We should have a minconfig to use?
  1391. if (defined($minconfig)) {
  1392. $buildtype = "useconfig:$minconfig";
  1393. }
  1394. my $ret = run_bisect_test $type, $buildtype;
  1395. if ($bisect_manual) {
  1396. $ret = answer_bisect;
  1397. }
  1398. # Are we looking for where it worked, not failed?
  1399. if ($reverse_bisect) {
  1400. $ret = !$ret;
  1401. }
  1402. if ($ret > 0) {
  1403. return "good";
  1404. } elsif ($ret == 0) {
  1405. return "bad";
  1406. } elsif ($bisect_skip) {
  1407. doprint "HIT A BAD COMMIT ... SKIPPING\n";
  1408. return "skip";
  1409. }
  1410. }
  1411. sub bisect {
  1412. my ($i) = @_;
  1413. my $result;
  1414. die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
  1415. die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
  1416. die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
  1417. my $good = $opt{"BISECT_GOOD[$i]"};
  1418. my $bad = $opt{"BISECT_BAD[$i]"};
  1419. my $type = $opt{"BISECT_TYPE[$i]"};
  1420. my $start = $opt{"BISECT_START[$i]"};
  1421. my $replay = $opt{"BISECT_REPLAY[$i]"};
  1422. my $start_files = $opt{"BISECT_FILES[$i]"};
  1423. if (defined($start_files)) {
  1424. $start_files = " -- " . $start_files;
  1425. } else {
  1426. $start_files = "";
  1427. }
  1428. # convert to true sha1's
  1429. $good = get_sha1($good);
  1430. $bad = get_sha1($bad);
  1431. if (defined($opt{"BISECT_REVERSE[$i]"}) &&
  1432. $opt{"BISECT_REVERSE[$i]"} == 1) {
  1433. doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
  1434. $reverse_bisect = 1;
  1435. } else {
  1436. $reverse_bisect = 0;
  1437. }
  1438. # Can't have a test without having a test to run
  1439. if ($type eq "test" && !defined($run_test)) {
  1440. $type = "boot";
  1441. }
  1442. my $check = $opt{"BISECT_CHECK[$i]"};
  1443. if (defined($check) && $check ne "0") {
  1444. # get current HEAD
  1445. my $head = get_sha1("HEAD");
  1446. if ($check ne "good") {
  1447. doprint "TESTING BISECT BAD [$bad]\n";
  1448. run_command "git checkout $bad" or
  1449. die "Failed to checkout $bad";
  1450. $result = run_bisect $type;
  1451. if ($result ne "bad") {
  1452. fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
  1453. }
  1454. }
  1455. if ($check ne "bad") {
  1456. doprint "TESTING BISECT GOOD [$good]\n";
  1457. run_command "git checkout $good" or
  1458. die "Failed to checkout $good";
  1459. $result = run_bisect $type;
  1460. if ($result ne "good") {
  1461. fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
  1462. }
  1463. }
  1464. # checkout where we started
  1465. run_command "git checkout $head" or
  1466. die "Failed to checkout $head";
  1467. }
  1468. run_command "git bisect start$start_files" or
  1469. dodie "could not start bisect";
  1470. run_command "git bisect good $good" or
  1471. dodie "could not set bisect good to $good";
  1472. run_git_bisect "git bisect bad $bad" or
  1473. dodie "could not set bisect bad to $bad";
  1474. if (defined($replay)) {
  1475. run_command "git bisect replay $replay" or
  1476. dodie "failed to run replay";
  1477. }
  1478. if (defined($start)) {
  1479. run_command "git checkout $start" or
  1480. dodie "failed to checkout $start";
  1481. }
  1482. my $test;
  1483. do {
  1484. $result = run_bisect $type;
  1485. $test = run_git_bisect "git bisect $result";
  1486. } while ($test);
  1487. run_command "git bisect log" or
  1488. dodie "could not capture git bisect log";
  1489. run_command "git bisect reset" or
  1490. dodie "could not reset git bisect";
  1491. doprint "Bad commit was [$bisect_bad]\n";
  1492. success $i;
  1493. }
  1494. my %config_ignore;
  1495. my %config_set;
  1496. my %config_list;
  1497. my %null_config;
  1498. my %dependency;
  1499. sub assign_configs {
  1500. my ($hash, $config) = @_;
  1501. open (IN, $config)
  1502. or dodie "Failed to read $config";
  1503. while (<IN>) {
  1504. if (/^((CONFIG\S*)=.*)/) {
  1505. ${$hash}{$2} = $1;
  1506. }
  1507. }
  1508. close(IN);
  1509. }
  1510. sub process_config_ignore {
  1511. my ($config) = @_;
  1512. assign_configs \%config_ignore, $config;
  1513. }
  1514. sub read_current_config {
  1515. my ($config_ref) = @_;
  1516. %{$config_ref} = ();
  1517. undef %{$config_ref};
  1518. my @key = keys %{$config_ref};
  1519. if ($#key >= 0) {
  1520. print "did not delete!\n";
  1521. exit;
  1522. }
  1523. open (IN, "$output_config");
  1524. while (<IN>) {
  1525. if (/^(CONFIG\S+)=(.*)/) {
  1526. ${$config_ref}{$1} = $2;
  1527. }
  1528. }
  1529. close(IN);
  1530. }
  1531. sub get_dependencies {
  1532. my ($config) = @_;
  1533. my $arr = $dependency{$config};
  1534. if (!defined($arr)) {
  1535. return ();
  1536. }
  1537. my @deps = @{$arr};
  1538. foreach my $dep (@{$arr}) {
  1539. print "ADD DEP $dep\n";
  1540. @deps = (@deps, get_dependencies $dep);
  1541. }
  1542. return @deps;
  1543. }
  1544. sub create_config {
  1545. my @configs = @_;
  1546. open(OUT, ">$output_config") or dodie "Can not write to $output_config";
  1547. foreach my $config (@configs) {
  1548. print OUT "$config_set{$config}\n";
  1549. my @deps = get_dependencies $config;
  1550. foreach my $dep (@deps) {
  1551. print OUT "$config_set{$dep}\n";
  1552. }
  1553. }
  1554. foreach my $config (keys %config_ignore) {
  1555. print OUT "$config_ignore{$config}\n";
  1556. }
  1557. close(OUT);
  1558. # exit;
  1559. make_oldconfig;
  1560. }
  1561. sub compare_configs {
  1562. my (%a, %b) = @_;
  1563. foreach my $item (keys %a) {
  1564. if (!defined($b{$item})) {
  1565. print "diff $item\n";
  1566. return 1;
  1567. }
  1568. delete $b{$item};
  1569. }
  1570. my @keys = keys %b;
  1571. if ($#keys) {
  1572. print "diff2 $keys[0]\n";
  1573. }
  1574. return -1 if ($#keys >= 0);
  1575. return 0;
  1576. }
  1577. sub run_config_bisect_test {
  1578. my ($type) = @_;
  1579. return run_bisect_test $type, "oldconfig";
  1580. }
  1581. sub process_passed {
  1582. my (%configs) = @_;
  1583. doprint "These configs had no failure: (Enabling them for further compiles)\n";
  1584. # Passed! All these configs are part of a good compile.
  1585. # Add them to the min options.
  1586. foreach my $config (keys %configs) {
  1587. if (defined($config_list{$config})) {
  1588. doprint " removing $config\n";
  1589. $config_ignore{$config} = $config_list{$config};
  1590. delete $config_list{$config};
  1591. }
  1592. }
  1593. doprint "config copied to $outputdir/config_good\n";
  1594. run_command "cp -f $output_config $outputdir/config_good";
  1595. }
  1596. sub process_failed {
  1597. my ($config) = @_;
  1598. doprint "\n\n***************************************\n";
  1599. doprint "Found bad config: $config\n";
  1600. doprint "***************************************\n\n";
  1601. }
  1602. sub run_config_bisect {
  1603. my @start_list = keys %config_list;
  1604. if ($#start_list < 0) {
  1605. doprint "No more configs to test!!!\n";
  1606. return -1;
  1607. }
  1608. doprint "***** RUN TEST ***\n";
  1609. my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
  1610. my $ret;
  1611. my %current_config;
  1612. my $count = $#start_list + 1;
  1613. doprint " $count configs to test\n";
  1614. my $half = int($#start_list / 2);
  1615. do {
  1616. my @tophalf = @start_list[0 .. $half];
  1617. create_config @tophalf;
  1618. read_current_config \%current_config;
  1619. $count = $#tophalf + 1;
  1620. doprint "Testing $count configs\n";
  1621. my $found = 0;
  1622. # make sure we test something
  1623. foreach my $config (@tophalf) {
  1624. if (defined($current_config{$config})) {
  1625. logit " $config\n";
  1626. $found = 1;
  1627. }
  1628. }
  1629. if (!$found) {
  1630. # try the other half
  1631. doprint "Top half produced no set configs, trying bottom half\n";
  1632. @tophalf = @start_list[$half + 1 .. $#start_list];
  1633. create_config @tophalf;
  1634. read_current_config \%current_config;
  1635. foreach my $config (@tophalf) {
  1636. if (defined($current_config{$config})) {
  1637. logit " $config\n";
  1638. $found = 1;
  1639. }
  1640. }
  1641. if (!$found) {
  1642. doprint "Failed: Can't make new config with current configs\n";
  1643. foreach my $config (@start_list) {
  1644. doprint " CONFIG: $config\n";
  1645. }
  1646. return -1;
  1647. }
  1648. $count = $#tophalf + 1;
  1649. doprint "Testing $count configs\n";
  1650. }
  1651. $ret = run_config_bisect_test $type;
  1652. if ($bisect_manual) {
  1653. $ret = answer_bisect;
  1654. }
  1655. if ($ret) {
  1656. process_passed %current_config;
  1657. return 0;
  1658. }
  1659. doprint "This config had a failure.\n";
  1660. doprint "Removing these configs that were not set in this config:\n";
  1661. doprint "config copied to $outputdir/config_bad\n";
  1662. run_command "cp -f $output_config $outputdir/config_bad";
  1663. # A config exists in this group that was bad.
  1664. foreach my $config (keys %config_list) {
  1665. if (!defined($current_config{$config})) {
  1666. doprint " removing $config\n";
  1667. delete $config_list{$config};
  1668. }
  1669. }
  1670. @start_list = @tophalf;
  1671. if ($#start_list == 0) {
  1672. process_failed $start_list[0];
  1673. return 1;
  1674. }
  1675. # remove half the configs we are looking at and see if
  1676. # they are good.
  1677. $half = int($#start_list / 2);
  1678. } while ($#start_list > 0);
  1679. # we found a single config, try it again unless we are running manually
  1680. if ($bisect_manual) {
  1681. process_failed $start_list[0];
  1682. return 1;
  1683. }
  1684. my @tophalf = @start_list[0 .. 0];
  1685. $ret = run_config_bisect_test $type;
  1686. if ($ret) {
  1687. process_passed %current_config;
  1688. return 0;
  1689. }
  1690. process_failed $start_list[0];
  1691. return 1;
  1692. }
  1693. sub config_bisect {
  1694. my ($i) = @_;
  1695. my $start_config = $opt{"CONFIG_BISECT[$i]"};
  1696. my $tmpconfig = "$tmpdir/use_config";
  1697. if (defined($config_bisect_good)) {
  1698. process_config_ignore $config_bisect_good;
  1699. }
  1700. # Make the file with the bad config and the min config
  1701. if (defined($minconfig)) {
  1702. # read the min config for things to ignore
  1703. run_command "cp $minconfig $tmpconfig" or
  1704. dodie "failed to copy $minconfig to $tmpconfig";
  1705. } else {
  1706. unlink $tmpconfig;
  1707. }
  1708. if (-f $tmpconfig) {
  1709. load_force_config($tmpconfig);
  1710. process_config_ignore $tmpconfig;
  1711. }
  1712. # now process the start config
  1713. run_command "cp $start_config $output_config" or
  1714. dodie "failed to copy $start_config to $output_config";
  1715. # read directly what we want to check
  1716. my %config_check;
  1717. open (IN, $output_config)
  1718. or dodie "faied to open $output_config";
  1719. while (<IN>) {
  1720. if (/^((CONFIG\S*)=.*)/) {
  1721. $config_check{$2} = $1;
  1722. }
  1723. }
  1724. close(IN);
  1725. # Now run oldconfig with the minconfig
  1726. make_oldconfig;
  1727. # check to see what we lost (or gained)
  1728. open (IN, $output_config)
  1729. or dodie "Failed to read $start_config";
  1730. my %removed_configs;
  1731. my %added_configs;
  1732. while (<IN>) {
  1733. if (/^((CONFIG\S*)=.*)/) {
  1734. # save off all options
  1735. $config_set{$2} = $1;
  1736. if (defined($config_check{$2})) {
  1737. if (defined($config_ignore{$2})) {
  1738. $removed_configs{$2} = $1;
  1739. } else {
  1740. $config_list{$2} = $1;
  1741. }
  1742. } elsif (!defined($config_ignore{$2})) {
  1743. $added_configs{$2} = $1;
  1744. $config_list{$2} = $1;
  1745. }
  1746. }
  1747. }
  1748. close(IN);
  1749. my @confs = keys %removed_configs;
  1750. if ($#confs >= 0) {
  1751. doprint "Configs overridden by default configs and removed from check:\n";
  1752. foreach my $config (@confs) {
  1753. doprint " $config\n";
  1754. }
  1755. }
  1756. @confs = keys %added_configs;
  1757. if ($#confs >= 0) {
  1758. doprint "Configs appearing in make oldconfig and added:\n";
  1759. foreach my $config (@confs) {
  1760. doprint " $config\n";
  1761. }
  1762. }
  1763. my %config_test;
  1764. my $once = 0;
  1765. # Sometimes kconfig does weird things. We must make sure
  1766. # that the config we autocreate has everything we need
  1767. # to test, otherwise we may miss testing configs, or
  1768. # may not be able to create a new config.
  1769. # Here we create a config with everything set.
  1770. create_config (keys %config_list);
  1771. read_current_config \%config_test;
  1772. foreach my $config (keys %config_list) {
  1773. if (!defined($config_test{$config})) {
  1774. if (!$once) {
  1775. $once = 1;
  1776. doprint "Configs not produced by kconfig (will not be checked):\n";
  1777. }
  1778. doprint " $config\n";
  1779. delete $config_list{$config};
  1780. }
  1781. }
  1782. my $ret;
  1783. do {
  1784. $ret = run_config_bisect;
  1785. } while (!$ret);
  1786. return $ret if ($ret < 0);
  1787. success $i;
  1788. }
  1789. sub patchcheck_reboot {
  1790. doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
  1791. reboot $patchcheck_sleep_time;
  1792. }
  1793. sub patchcheck {
  1794. my ($i) = @_;
  1795. die "PATCHCHECK_START[$i] not defined\n"
  1796. if (!defined($opt{"PATCHCHECK_START[$i]"}));
  1797. die "PATCHCHECK_TYPE[$i] not defined\n"
  1798. if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
  1799. my $start = $opt{"PATCHCHECK_START[$i]"};
  1800. my $end = "HEAD";
  1801. if (defined($opt{"PATCHCHECK_END[$i]"})) {
  1802. $end = $opt{"PATCHCHECK_END[$i]"};
  1803. }
  1804. # Get the true sha1's since we can use things like HEAD~3
  1805. $start = get_sha1($start);
  1806. $end = get_sha1($end);
  1807. my $type = $opt{"PATCHCHECK_TYPE[$i]"};
  1808. # Can't have a test without having a test to run
  1809. if ($type eq "test" && !defined($run_test)) {
  1810. $type = "boot";
  1811. }
  1812. open (IN, "git log --pretty=oneline $end|") or
  1813. dodie "could not get git list";
  1814. my @list;
  1815. while (<IN>) {
  1816. chomp;
  1817. $list[$#list+1] = $_;
  1818. last if (/^$start/);
  1819. }
  1820. close(IN);
  1821. if ($list[$#list] !~ /^$start/) {
  1822. fail "SHA1 $start not found";
  1823. }
  1824. # go backwards in the list
  1825. @list = reverse @list;
  1826. my $save_clean = $noclean;
  1827. my %ignored_warnings;
  1828. if (defined($ignore_warnings)) {
  1829. foreach my $sha1 (split /\s+/, $ignore_warnings) {
  1830. $ignored_warnings{$sha1} = 1;
  1831. }
  1832. }
  1833. $in_patchcheck = 1;
  1834. foreach my $item (@list) {
  1835. my $sha1 = $item;
  1836. $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
  1837. doprint "\nProcessing commit $item\n\n";
  1838. run_command "git checkout $sha1" or
  1839. die "Failed to checkout $sha1";
  1840. # only clean on the first and last patch
  1841. if ($item eq $list[0] ||
  1842. $item eq $list[$#list]) {
  1843. $noclean = $save_clean;
  1844. } else {
  1845. $noclean = 1;
  1846. }
  1847. if (defined($minconfig)) {
  1848. build "useconfig:$minconfig" or return 0;
  1849. } else {
  1850. # ?? no config to use?
  1851. build "oldconfig" or return 0;
  1852. }
  1853. if (!defined($ignored_warnings{$sha1})) {
  1854. check_buildlog $sha1 or return 0;
  1855. }
  1856. next if ($type eq "build");
  1857. my $failed = 0;
  1858. start_monitor_and_boot or $failed = 1;
  1859. if (!$failed && $type ne "boot"){
  1860. do_run_test or $failed = 1;
  1861. }
  1862. end_monitor;
  1863. return 0 if ($failed);
  1864. patchcheck_reboot;
  1865. }
  1866. $in_patchcheck = 0;
  1867. success $i;
  1868. return 1;
  1869. }
  1870. my %depends;
  1871. my $iflevel = 0;
  1872. my @ifdeps;
  1873. # prevent recursion
  1874. my %read_kconfigs;
  1875. # taken from streamline_config.pl
  1876. sub read_kconfig {
  1877. my ($kconfig) = @_;
  1878. my $state = "NONE";
  1879. my $config;
  1880. my @kconfigs;
  1881. my $cont = 0;
  1882. my $line;
  1883. if (! -f $kconfig) {
  1884. doprint "file $kconfig does not exist, skipping\n";
  1885. return;
  1886. }
  1887. open(KIN, "$kconfig")
  1888. or die "Can't open $kconfig";
  1889. while (<KIN>) {
  1890. chomp;
  1891. # Make sure that lines ending with \ continue
  1892. if ($cont) {
  1893. $_ = $line . " " . $_;
  1894. }
  1895. if (s/\\$//) {
  1896. $cont = 1;
  1897. $line = $_;
  1898. next;
  1899. }
  1900. $cont = 0;
  1901. # collect any Kconfig sources
  1902. if (/^source\s*"(.*)"/) {
  1903. $kconfigs[$#kconfigs+1] = $1;
  1904. }
  1905. # configs found
  1906. if (/^\s*(menu)?config\s+(\S+)\s*$/) {
  1907. $state = "NEW";
  1908. $config = $2;
  1909. for (my $i = 0; $i < $iflevel; $i++) {
  1910. if ($i) {
  1911. $depends{$config} .= " " . $ifdeps[$i];
  1912. } else {
  1913. $depends{$config} = $ifdeps[$i];
  1914. }
  1915. $state = "DEP";
  1916. }
  1917. # collect the depends for the config
  1918. } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
  1919. if (defined($depends{$1})) {
  1920. $depends{$config} .= " " . $1;
  1921. } else {
  1922. $depends{$config} = $1;
  1923. }
  1924. # Get the configs that select this config
  1925. } elsif ($state ne "NONE" && /^\s*select\s+(\S+)/) {
  1926. if (defined($depends{$1})) {
  1927. $depends{$1} .= " " . $config;
  1928. } else {
  1929. $depends{$1} = $config;
  1930. }
  1931. # Check for if statements
  1932. } elsif (/^if\s+(.*\S)\s*$/) {
  1933. my $deps = $1;
  1934. # remove beginning and ending non text
  1935. $deps =~ s/^[^a-zA-Z0-9_]*//;
  1936. $deps =~ s/[^a-zA-Z0-9_]*$//;
  1937. my @deps = split /[^a-zA-Z0-9_]+/, $deps;
  1938. $ifdeps[$iflevel++] = join ':', @deps;
  1939. } elsif (/^endif/) {
  1940. $iflevel-- if ($iflevel);
  1941. # stop on "help"
  1942. } elsif (/^\s*help\s*$/) {
  1943. $state = "NONE";
  1944. }
  1945. }
  1946. close(KIN);
  1947. # read in any configs that were found.
  1948. foreach $kconfig (@kconfigs) {
  1949. if (!defined($read_kconfigs{$kconfig})) {
  1950. $read_kconfigs{$kconfig} = 1;
  1951. read_kconfig("$builddir/$kconfig");
  1952. }
  1953. }
  1954. }
  1955. sub read_depends {
  1956. # find out which arch this is by the kconfig file
  1957. open (IN, $output_config)
  1958. or dodie "Failed to read $output_config";
  1959. my $arch;
  1960. while (<IN>) {
  1961. if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
  1962. $arch = $1;
  1963. last;
  1964. }
  1965. }
  1966. close IN;
  1967. if (!defined($arch)) {
  1968. doprint "Could not find arch from config file\n";
  1969. doprint "no dependencies used\n";
  1970. return;
  1971. }
  1972. # arch is really the subarch, we need to know
  1973. # what directory to look at.
  1974. if ($arch eq "i386" || $arch eq "x86_64") {
  1975. $arch = "x86";
  1976. } elsif ($arch =~ /^tile/) {
  1977. $arch = "tile";
  1978. }
  1979. my $kconfig = "$builddir/arch/$arch/Kconfig";
  1980. if (! -f $kconfig && $arch =~ /\d$/) {
  1981. my $orig = $arch;
  1982. # some subarchs have numbers, truncate them
  1983. $arch =~ s/\d*$//;
  1984. $kconfig = "$builddir/arch/$arch/Kconfig";
  1985. if (! -f $kconfig) {
  1986. doprint "No idea what arch dir $orig is for\n";
  1987. doprint "no dependencies used\n";
  1988. return;
  1989. }
  1990. }
  1991. read_kconfig($kconfig);
  1992. }
  1993. sub read_config_list {
  1994. my ($config) = @_;
  1995. open (IN, $config)
  1996. or dodie "Failed to read $config";
  1997. while (<IN>) {
  1998. if (/^((CONFIG\S*)=.*)/) {
  1999. if (!defined($config_ignore{$2})) {
  2000. $config_list{$2} = $1;
  2001. }
  2002. }
  2003. }
  2004. close(IN);
  2005. }
  2006. sub read_output_config {
  2007. my ($config) = @_;
  2008. assign_configs \%config_ignore, $config;
  2009. }
  2010. sub make_new_config {
  2011. my @configs = @_;
  2012. open (OUT, ">$output_config")
  2013. or dodie "Failed to write $output_config";
  2014. foreach my $config (@configs) {
  2015. print OUT "$config\n";
  2016. }
  2017. close OUT;
  2018. }
  2019. sub get_depends {
  2020. my ($dep) = @_;
  2021. my $kconfig = $dep;
  2022. $kconfig =~ s/CONFIG_//;
  2023. $dep = $depends{"$kconfig"};
  2024. # the dep string we have saves the dependencies as they
  2025. # were found, including expressions like ! && ||. We
  2026. # want to split this out into just an array of configs.
  2027. my $valid = "A-Za-z_0-9";
  2028. my @configs;
  2029. while ($dep =~ /[$valid]/) {
  2030. if ($dep =~ /^[^$valid]*([$valid]+)/) {
  2031. my $conf = "CONFIG_" . $1;
  2032. $configs[$#configs + 1] = $conf;
  2033. $dep =~ s/^[^$valid]*[$valid]+//;
  2034. } else {
  2035. die "this should never happen";
  2036. }
  2037. }
  2038. return @configs;
  2039. }
  2040. my %min_configs;
  2041. my %keep_configs;
  2042. my %save_configs;
  2043. my %processed_configs;
  2044. my %nochange_config;
  2045. sub test_this_config {
  2046. my ($config) = @_;
  2047. my $found;
  2048. # if we already processed this config, skip it
  2049. if (defined($processed_configs{$config})) {
  2050. return undef;
  2051. }
  2052. $processed_configs{$config} = 1;
  2053. # if this config failed during this round, skip it
  2054. if (defined($nochange_config{$config})) {
  2055. return undef;
  2056. }
  2057. my $kconfig = $config;
  2058. $kconfig =~ s/CONFIG_//;
  2059. # Test dependencies first
  2060. if (defined($depends{"$kconfig"})) {
  2061. my @parents = get_depends $config;
  2062. foreach my $parent (@parents) {
  2063. # if the parent is in the min config, check it first
  2064. next if (!defined($min_configs{$parent}));
  2065. $found = test_this_config($parent);
  2066. if (defined($found)) {
  2067. return $found;
  2068. }
  2069. }
  2070. }
  2071. # Remove this config from the list of configs
  2072. # do a make oldnoconfig and then read the resulting
  2073. # .config to make sure it is missing the config that
  2074. # we had before
  2075. my %configs = %min_configs;
  2076. delete $configs{$config};
  2077. make_new_config ((values %configs), (values %keep_configs));
  2078. make_oldconfig;
  2079. undef %configs;
  2080. assign_configs \%configs, $output_config;
  2081. return $config if (!defined($configs{$config}));
  2082. doprint "disabling config $config did not change .config\n";
  2083. $nochange_config{$config} = 1;
  2084. return undef;
  2085. }
  2086. sub make_min_config {
  2087. my ($i) = @_;
  2088. if (!defined($output_minconfig)) {
  2089. fail "OUTPUT_MIN_CONFIG not defined" and return;
  2090. }
  2091. # If output_minconfig exists, and the start_minconfig
  2092. # came from min_config, than ask if we should use
  2093. # that instead.
  2094. if (-f $output_minconfig && !$start_minconfig_defined) {
  2095. print "$output_minconfig exists\n";
  2096. if (read_yn " Use it as minconfig?") {
  2097. $start_minconfig = $output_minconfig;
  2098. }
  2099. }
  2100. if (!defined($start_minconfig)) {
  2101. fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
  2102. }
  2103. my $temp_config = "$tmpdir/temp_config";
  2104. # First things first. We build an allnoconfig to find
  2105. # out what the defaults are that we can't touch.
  2106. # Some are selections, but we really can't handle selections.
  2107. my $save_minconfig = $minconfig;
  2108. undef $minconfig;
  2109. run_command "$make allnoconfig" or return 0;
  2110. read_depends;
  2111. process_config_ignore $output_config;
  2112. undef %save_configs;
  2113. undef %min_configs;
  2114. if (defined($ignore_config)) {
  2115. # make sure the file exists
  2116. `touch $ignore_config`;
  2117. assign_configs \%save_configs, $ignore_config;
  2118. }
  2119. %keep_configs = %save_configs;
  2120. doprint "Load initial configs from $start_minconfig\n";
  2121. # Look at the current min configs, and save off all the
  2122. # ones that were set via the allnoconfig
  2123. assign_configs \%min_configs, $start_minconfig;
  2124. my @config_keys = keys %min_configs;
  2125. # Remove anything that was set by the make allnoconfig
  2126. # we shouldn't need them as they get set for us anyway.
  2127. foreach my $config (@config_keys) {
  2128. # Remove anything in the ignore_config
  2129. if (defined($keep_configs{$config})) {
  2130. my $file = $ignore_config;
  2131. $file =~ s,.*/(.*?)$,$1,;
  2132. doprint "$config set by $file ... ignored\n";
  2133. delete $min_configs{$config};
  2134. next;
  2135. }
  2136. # But make sure the settings are the same. If a min config
  2137. # sets a selection, we do not want to get rid of it if
  2138. # it is not the same as what we have. Just move it into
  2139. # the keep configs.
  2140. if (defined($config_ignore{$config})) {
  2141. if ($config_ignore{$config} ne $min_configs{$config}) {
  2142. doprint "$config is in allnoconfig as '$config_ignore{$config}'";
  2143. doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
  2144. $keep_configs{$config} = $min_configs{$config};
  2145. } else {
  2146. doprint "$config set by allnoconfig ... ignored\n";
  2147. }
  2148. delete $min_configs{$config};
  2149. }
  2150. }
  2151. my $done = 0;
  2152. my $take_two = 0;
  2153. while (!$done) {
  2154. my $config;
  2155. my $found;
  2156. # Now disable each config one by one and do a make oldconfig
  2157. # till we find a config that changes our list.
  2158. # Put configs that did not modify the config at the end.
  2159. my @test_configs = keys %min_configs;
  2160. my $reset = 1;
  2161. for (my $i = 0; $i < $#test_configs; $i++) {
  2162. if (!defined($nochange_config{$test_configs[0]})) {
  2163. $reset = 0;
  2164. last;
  2165. }
  2166. # This config didn't change the .config last time.
  2167. # Place it at the end
  2168. my $config = shift @test_configs;
  2169. push @test_configs, $config;
  2170. }
  2171. # if every test config has failed to modify the .config file
  2172. # in the past, then reset and start over.
  2173. if ($reset) {
  2174. undef %nochange_config;
  2175. }
  2176. undef %processed_configs;
  2177. foreach my $config (@test_configs) {
  2178. $found = test_this_config $config;
  2179. last if (defined($found));
  2180. # oh well, try another config
  2181. }
  2182. if (!defined($found)) {
  2183. # we could have failed due to the nochange_config hash
  2184. # reset and try again
  2185. if (!$take_two) {
  2186. undef %nochange_config;
  2187. $take_two = 1;
  2188. next;
  2189. }
  2190. doprint "No more configs found that we can disable\n";
  2191. $done = 1;
  2192. last;
  2193. }
  2194. $take_two = 0;
  2195. $config = $found;
  2196. doprint "Test with $config disabled\n";
  2197. # set in_bisect to keep build and monitor from dieing
  2198. $in_bisect = 1;
  2199. my $failed = 0;
  2200. build "oldconfig";
  2201. start_monitor_and_boot or $failed = 1;
  2202. end_monitor;
  2203. $in_bisect = 0;
  2204. if ($failed) {
  2205. doprint "$min_configs{$config} is needed to boot the box... keeping\n";
  2206. # this config is needed, add it to the ignore list.
  2207. $keep_configs{$config} = $min_configs{$config};
  2208. $save_configs{$config} = $min_configs{$config};
  2209. delete $min_configs{$config};
  2210. # update new ignore configs
  2211. if (defined($ignore_config)) {
  2212. open (OUT, ">$temp_config")
  2213. or die "Can't write to $temp_config";
  2214. foreach my $config (keys %save_configs) {
  2215. print OUT "$save_configs{$config}\n";
  2216. }
  2217. close OUT;
  2218. run_command "mv $temp_config $ignore_config" or
  2219. dodie "failed to copy update to $ignore_config";
  2220. }
  2221. } else {
  2222. # We booted without this config, remove it from the minconfigs.
  2223. doprint "$config is not needed, disabling\n";
  2224. delete $min_configs{$config};
  2225. # Also disable anything that is not enabled in this config
  2226. my %configs;
  2227. assign_configs \%configs, $output_config;
  2228. my @config_keys = keys %min_configs;
  2229. foreach my $config (@config_keys) {
  2230. if (!defined($configs{$config})) {
  2231. doprint "$config is not set, disabling\n";
  2232. delete $min_configs{$config};
  2233. }
  2234. }
  2235. # Save off all the current mandidory configs
  2236. open (OUT, ">$temp_config")
  2237. or die "Can't write to $temp_config";
  2238. foreach my $config (keys %keep_configs) {
  2239. print OUT "$keep_configs{$config}\n";
  2240. }
  2241. foreach my $config (keys %min_configs) {
  2242. print OUT "$min_configs{$config}\n";
  2243. }
  2244. close OUT;
  2245. run_command "mv $temp_config $output_minconfig" or
  2246. dodie "failed to copy update to $output_minconfig";
  2247. }
  2248. doprint "Reboot and wait $sleep_time seconds\n";
  2249. reboot $sleep_time;
  2250. }
  2251. success $i;
  2252. return 1;
  2253. }
  2254. $#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
  2255. if ($#ARGV == 0) {
  2256. $ktest_config = $ARGV[0];
  2257. if (! -f $ktest_config) {
  2258. print "$ktest_config does not exist.\n";
  2259. if (!read_yn "Create it?") {
  2260. exit 0;
  2261. }
  2262. }
  2263. } else {
  2264. $ktest_config = "ktest.conf";
  2265. }
  2266. if (! -f $ktest_config) {
  2267. open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
  2268. print OUT << "EOF"
  2269. # Generated by ktest.pl
  2270. #
  2271. # Define each test with TEST_START
  2272. # The config options below it will override the defaults
  2273. TEST_START
  2274. DEFAULTS
  2275. EOF
  2276. ;
  2277. close(OUT);
  2278. }
  2279. read_config $ktest_config;
  2280. if (defined($opt{"LOG_FILE"})) {
  2281. $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
  2282. }
  2283. # Append any configs entered in manually to the config file.
  2284. my @new_configs = keys %entered_configs;
  2285. if ($#new_configs >= 0) {
  2286. print "\nAppending entered in configs to $ktest_config\n";
  2287. open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
  2288. foreach my $config (@new_configs) {
  2289. print OUT "$config = $entered_configs{$config}\n";
  2290. $opt{$config} = $entered_configs{$config};
  2291. }
  2292. }
  2293. if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
  2294. unlink $opt{"LOG_FILE"};
  2295. }
  2296. doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
  2297. for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
  2298. if (!$i) {
  2299. doprint "DEFAULT OPTIONS:\n";
  2300. } else {
  2301. doprint "\nTEST $i OPTIONS";
  2302. if (defined($repeat_tests{$i})) {
  2303. $repeat = $repeat_tests{$i};
  2304. doprint " ITERATE $repeat";
  2305. }
  2306. doprint "\n";
  2307. }
  2308. foreach my $option (sort keys %opt) {
  2309. if ($option =~ /\[(\d+)\]$/) {
  2310. next if ($i != $1);
  2311. } else {
  2312. next if ($i);
  2313. }
  2314. doprint "$option = $opt{$option}\n";
  2315. }
  2316. }
  2317. sub __set_test_option {
  2318. my ($name, $i) = @_;
  2319. my $option = "$name\[$i\]";
  2320. if (defined($opt{$option})) {
  2321. return $opt{$option};
  2322. }
  2323. foreach my $test (keys %repeat_tests) {
  2324. if ($i >= $test &&
  2325. $i < $test + $repeat_tests{$test}) {
  2326. $option = "$name\[$test\]";
  2327. if (defined($opt{$option})) {
  2328. return $opt{$option};
  2329. }
  2330. }
  2331. }
  2332. if (defined($opt{$name})) {
  2333. return $opt{$name};
  2334. }
  2335. return undef;
  2336. }
  2337. sub set_test_option {
  2338. my ($name, $i) = @_;
  2339. my $option = __set_test_option($name, $i);
  2340. return $option if (!defined($option));
  2341. return eval_option($option, $i);
  2342. }
  2343. # First we need to do is the builds
  2344. for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
  2345. # Do not reboot on failing test options
  2346. $no_reboot = 1;
  2347. $iteration = $i;
  2348. my $makecmd = set_test_option("MAKE_CMD", $i);
  2349. $machine = set_test_option("MACHINE", $i);
  2350. $ssh_user = set_test_option("SSH_USER", $i);
  2351. $tmpdir = set_test_option("TMP_DIR", $i);
  2352. $outputdir = set_test_option("OUTPUT_DIR", $i);
  2353. $builddir = set_test_option("BUILD_DIR", $i);
  2354. $test_type = set_test_option("TEST_TYPE", $i);
  2355. $build_type = set_test_option("BUILD_TYPE", $i);
  2356. $build_options = set_test_option("BUILD_OPTIONS", $i);
  2357. $pre_build = set_test_option("PRE_BUILD", $i);
  2358. $post_build = set_test_option("POST_BUILD", $i);
  2359. $pre_build_die = set_test_option("PRE_BUILD_DIE", $i);
  2360. $post_build_die = set_test_option("POST_BUILD_DIE", $i);
  2361. $power_cycle = set_test_option("POWER_CYCLE", $i);
  2362. $reboot = set_test_option("REBOOT", $i);
  2363. $noclean = set_test_option("BUILD_NOCLEAN", $i);
  2364. $minconfig = set_test_option("MIN_CONFIG", $i);
  2365. $output_minconfig = set_test_option("OUTPUT_MIN_CONFIG", $i);
  2366. $start_minconfig = set_test_option("START_MIN_CONFIG", $i);
  2367. $ignore_config = set_test_option("IGNORE_CONFIG", $i);
  2368. $run_test = set_test_option("TEST", $i);
  2369. $addconfig = set_test_option("ADD_CONFIG", $i);
  2370. $reboot_type = set_test_option("REBOOT_TYPE", $i);
  2371. $grub_menu = set_test_option("GRUB_MENU", $i);
  2372. $post_install = set_test_option("POST_INSTALL", $i);
  2373. $no_install = set_test_option("NO_INSTALL", $i);
  2374. $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
  2375. $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
  2376. $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
  2377. $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
  2378. $power_off = set_test_option("POWER_OFF", $i);
  2379. $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
  2380. $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
  2381. $sleep_time = set_test_option("SLEEP_TIME", $i);
  2382. $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
  2383. $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
  2384. $ignore_warnings = set_test_option("IGNORE_WARNINGS", $i);
  2385. $bisect_manual = set_test_option("BISECT_MANUAL", $i);
  2386. $bisect_skip = set_test_option("BISECT_SKIP", $i);
  2387. $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i);
  2388. $store_failures = set_test_option("STORE_FAILURES", $i);
  2389. $test_name = set_test_option("TEST_NAME", $i);
  2390. $timeout = set_test_option("TIMEOUT", $i);
  2391. $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
  2392. $console = set_test_option("CONSOLE", $i);
  2393. $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
  2394. $success_line = set_test_option("SUCCESS_LINE", $i);
  2395. $reboot_success_line = set_test_option("REBOOT_SUCCESS_LINE", $i);
  2396. $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
  2397. $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
  2398. $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
  2399. $build_target = set_test_option("BUILD_TARGET", $i);
  2400. $ssh_exec = set_test_option("SSH_EXEC", $i);
  2401. $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
  2402. $target_image = set_test_option("TARGET_IMAGE", $i);
  2403. $localversion = set_test_option("LOCALVERSION", $i);
  2404. $start_minconfig_defined = 1;
  2405. if (!defined($start_minconfig)) {
  2406. $start_minconfig_defined = 0;
  2407. $start_minconfig = $minconfig;
  2408. }
  2409. chdir $builddir || die "can't change directory to $builddir";
  2410. foreach my $dir ($tmpdir, $outputdir) {
  2411. if (!-d $dir) {
  2412. mkpath($dir) or
  2413. die "can't create $dir";
  2414. }
  2415. }
  2416. $ENV{"SSH_USER"} = $ssh_user;
  2417. $ENV{"MACHINE"} = $machine;
  2418. $target = "$ssh_user\@$machine";
  2419. $buildlog = "$tmpdir/buildlog-$machine";
  2420. $dmesg = "$tmpdir/dmesg-$machine";
  2421. $make = "$makecmd O=$outputdir";
  2422. $output_config = "$outputdir/.config";
  2423. if ($reboot_type eq "grub") {
  2424. dodie "GRUB_MENU not defined" if (!defined($grub_menu));
  2425. } elsif (!defined($reboot_script)) {
  2426. dodie "REBOOT_SCRIPT not defined"
  2427. }
  2428. my $run_type = $build_type;
  2429. if ($test_type eq "patchcheck") {
  2430. $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
  2431. } elsif ($test_type eq "bisect") {
  2432. $run_type = $opt{"BISECT_TYPE[$i]"};
  2433. } elsif ($test_type eq "config_bisect") {
  2434. $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
  2435. }
  2436. if ($test_type eq "make_min_config") {
  2437. $run_type = "";
  2438. }
  2439. # mistake in config file?
  2440. if (!defined($run_type)) {
  2441. $run_type = "ERROR";
  2442. }
  2443. my $installme = "";
  2444. $installme = " no_install" if ($no_install);
  2445. doprint "\n\n";
  2446. doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
  2447. unlink $dmesg;
  2448. unlink $buildlog;
  2449. if (defined($addconfig)) {
  2450. my $min = $minconfig;
  2451. if (!defined($minconfig)) {
  2452. $min = "";
  2453. }
  2454. run_command "cat $addconfig $min > $tmpdir/add_config" or
  2455. dodie "Failed to create temp config";
  2456. $minconfig = "$tmpdir/add_config";
  2457. }
  2458. my $checkout = $opt{"CHECKOUT[$i]"};
  2459. if (defined($checkout)) {
  2460. run_command "git checkout $checkout" or
  2461. die "failed to checkout $checkout";
  2462. }
  2463. $no_reboot = 0;
  2464. if ($test_type eq "bisect") {
  2465. bisect $i;
  2466. next;
  2467. } elsif ($test_type eq "config_bisect") {
  2468. config_bisect $i;
  2469. next;
  2470. } elsif ($test_type eq "patchcheck") {
  2471. patchcheck $i;
  2472. next;
  2473. } elsif ($test_type eq "make_min_config") {
  2474. make_min_config $i;
  2475. next;
  2476. }
  2477. if ($build_type ne "nobuild") {
  2478. build $build_type or next;
  2479. }
  2480. if ($test_type eq "install") {
  2481. get_version;
  2482. install;
  2483. success $i;
  2484. next;
  2485. }
  2486. if ($test_type ne "build") {
  2487. my $failed = 0;
  2488. start_monitor_and_boot or $failed = 1;
  2489. if (!$failed && $test_type ne "boot" && defined($run_test)) {
  2490. do_run_test or $failed = 1;
  2491. }
  2492. end_monitor;
  2493. next if ($failed);
  2494. }
  2495. success $i;
  2496. }
  2497. if ($opt{"POWEROFF_ON_SUCCESS"}) {
  2498. halt;
  2499. } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
  2500. reboot;
  2501. }
  2502. doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
  2503. exit 0;