ktest.pl 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077
  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. #default opts
  18. my %default = (
  19. "NUM_TESTS" => 1,
  20. "TEST_TYPE" => "build",
  21. "BUILD_TYPE" => "randconfig",
  22. "MAKE_CMD" => "make",
  23. "TIMEOUT" => 120,
  24. "TMP_DIR" => "/tmp/ktest/\${MACHINE}",
  25. "SLEEP_TIME" => 60, # sleep time between tests
  26. "BUILD_NOCLEAN" => 0,
  27. "REBOOT_ON_ERROR" => 0,
  28. "POWEROFF_ON_ERROR" => 0,
  29. "REBOOT_ON_SUCCESS" => 1,
  30. "POWEROFF_ON_SUCCESS" => 0,
  31. "BUILD_OPTIONS" => "",
  32. "BISECT_SLEEP_TIME" => 60, # sleep time between bisects
  33. "PATCHCHECK_SLEEP_TIME" => 60, # sleep time between patch checks
  34. "CLEAR_LOG" => 0,
  35. "BISECT_MANUAL" => 0,
  36. "BISECT_SKIP" => 1,
  37. "MIN_CONFIG_TYPE" => "boot",
  38. "SUCCESS_LINE" => "login:",
  39. "DETECT_TRIPLE_FAULT" => 1,
  40. "NO_INSTALL" => 0,
  41. "BOOTED_TIMEOUT" => 1,
  42. "DIE_ON_FAILURE" => 1,
  43. "SSH_EXEC" => "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND",
  44. "SCP_TO_TARGET" => "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE",
  45. "SCP_TO_TARGET_INSTALL" => "\${SCP_TO_TARGET}",
  46. "REBOOT" => "ssh \$SSH_USER\@\$MACHINE reboot",
  47. "STOP_AFTER_SUCCESS" => 10,
  48. "STOP_AFTER_FAILURE" => 60,
  49. "STOP_TEST_AFTER" => 600,
  50. "MAX_MONITOR_WAIT" => 1800,
  51. "GRUB_REBOOT" => "grub2-reboot",
  52. "SYSLINUX" => "extlinux",
  53. "SYSLINUX_PATH" => "/boot/extlinux",
  54. # required, and we will ask users if they don't have them but we keep the default
  55. # value something that is common.
  56. "REBOOT_TYPE" => "grub",
  57. "LOCALVERSION" => "-test",
  58. "SSH_USER" => "root",
  59. "BUILD_TARGET" => "arch/x86/boot/bzImage",
  60. "TARGET_IMAGE" => "/boot/vmlinuz-test",
  61. "LOG_FILE" => undef,
  62. "IGNORE_UNUSED" => 0,
  63. );
  64. my $ktest_config;
  65. my $version;
  66. my $have_version = 0;
  67. my $machine;
  68. my $ssh_user;
  69. my $tmpdir;
  70. my $builddir;
  71. my $outputdir;
  72. my $output_config;
  73. my $test_type;
  74. my $build_type;
  75. my $build_options;
  76. my $final_post_ktest;
  77. my $pre_ktest;
  78. my $post_ktest;
  79. my $pre_test;
  80. my $post_test;
  81. my $pre_build;
  82. my $post_build;
  83. my $pre_build_die;
  84. my $post_build_die;
  85. my $reboot_type;
  86. my $reboot_script;
  87. my $power_cycle;
  88. my $reboot;
  89. my $reboot_on_error;
  90. my $switch_to_good;
  91. my $switch_to_test;
  92. my $poweroff_on_error;
  93. my $reboot_on_success;
  94. my $die_on_failure;
  95. my $powercycle_after_reboot;
  96. my $poweroff_after_halt;
  97. my $max_monitor_wait;
  98. my $ssh_exec;
  99. my $scp_to_target;
  100. my $scp_to_target_install;
  101. my $power_off;
  102. my $grub_menu;
  103. my $grub_file;
  104. my $grub_number;
  105. my $grub_reboot;
  106. my $syslinux;
  107. my $syslinux_path;
  108. my $syslinux_label;
  109. my $target;
  110. my $make;
  111. my $pre_install;
  112. my $post_install;
  113. my $no_install;
  114. my $noclean;
  115. my $minconfig;
  116. my $start_minconfig;
  117. my $start_minconfig_defined;
  118. my $output_minconfig;
  119. my $minconfig_type;
  120. my $use_output_minconfig;
  121. my $warnings_file;
  122. my $ignore_config;
  123. my $ignore_errors;
  124. my $addconfig;
  125. my $in_bisect = 0;
  126. my $bisect_bad_commit = "";
  127. my $reverse_bisect;
  128. my $bisect_manual;
  129. my $bisect_skip;
  130. my $config_bisect_good;
  131. my $bisect_ret_good;
  132. my $bisect_ret_bad;
  133. my $bisect_ret_skip;
  134. my $bisect_ret_abort;
  135. my $bisect_ret_default;
  136. my $in_patchcheck = 0;
  137. my $run_test;
  138. my $redirect;
  139. my $buildlog;
  140. my $testlog;
  141. my $dmesg;
  142. my $monitor_fp;
  143. my $monitor_pid;
  144. my $monitor_cnt = 0;
  145. my $sleep_time;
  146. my $bisect_sleep_time;
  147. my $patchcheck_sleep_time;
  148. my $ignore_warnings;
  149. my $store_failures;
  150. my $store_successes;
  151. my $test_name;
  152. my $timeout;
  153. my $booted_timeout;
  154. my $detect_triplefault;
  155. my $console;
  156. my $reboot_success_line;
  157. my $success_line;
  158. my $stop_after_success;
  159. my $stop_after_failure;
  160. my $stop_test_after;
  161. my $build_target;
  162. my $target_image;
  163. my $checkout;
  164. my $localversion;
  165. my $iteration = 0;
  166. my $successes = 0;
  167. my $bisect_good;
  168. my $bisect_bad;
  169. my $bisect_type;
  170. my $bisect_start;
  171. my $bisect_replay;
  172. my $bisect_files;
  173. my $bisect_reverse;
  174. my $bisect_check;
  175. my $config_bisect;
  176. my $config_bisect_type;
  177. my $config_bisect_check;
  178. my $patchcheck_type;
  179. my $patchcheck_start;
  180. my $patchcheck_end;
  181. # set when a test is something other that just building or install
  182. # which would require more options.
  183. my $buildonly = 1;
  184. # tell build not to worry about warnings, even when WARNINGS_FILE is set
  185. my $warnings_ok = 0;
  186. # set when creating a new config
  187. my $newconfig = 0;
  188. my %entered_configs;
  189. my %config_help;
  190. my %variable;
  191. # force_config is the list of configs that we force enabled (or disabled)
  192. # in a .config file. The MIN_CONFIG and ADD_CONFIG configs.
  193. my %force_config;
  194. # do not force reboots on config problems
  195. my $no_reboot = 1;
  196. # reboot on success
  197. my $reboot_success = 0;
  198. my %option_map = (
  199. "MACHINE" => \$machine,
  200. "SSH_USER" => \$ssh_user,
  201. "TMP_DIR" => \$tmpdir,
  202. "OUTPUT_DIR" => \$outputdir,
  203. "BUILD_DIR" => \$builddir,
  204. "TEST_TYPE" => \$test_type,
  205. "PRE_KTEST" => \$pre_ktest,
  206. "POST_KTEST" => \$post_ktest,
  207. "PRE_TEST" => \$pre_test,
  208. "POST_TEST" => \$post_test,
  209. "BUILD_TYPE" => \$build_type,
  210. "BUILD_OPTIONS" => \$build_options,
  211. "PRE_BUILD" => \$pre_build,
  212. "POST_BUILD" => \$post_build,
  213. "PRE_BUILD_DIE" => \$pre_build_die,
  214. "POST_BUILD_DIE" => \$post_build_die,
  215. "POWER_CYCLE" => \$power_cycle,
  216. "REBOOT" => \$reboot,
  217. "BUILD_NOCLEAN" => \$noclean,
  218. "MIN_CONFIG" => \$minconfig,
  219. "OUTPUT_MIN_CONFIG" => \$output_minconfig,
  220. "START_MIN_CONFIG" => \$start_minconfig,
  221. "MIN_CONFIG_TYPE" => \$minconfig_type,
  222. "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig,
  223. "WARNINGS_FILE" => \$warnings_file,
  224. "IGNORE_CONFIG" => \$ignore_config,
  225. "TEST" => \$run_test,
  226. "ADD_CONFIG" => \$addconfig,
  227. "REBOOT_TYPE" => \$reboot_type,
  228. "GRUB_MENU" => \$grub_menu,
  229. "GRUB_FILE" => \$grub_file,
  230. "GRUB_REBOOT" => \$grub_reboot,
  231. "SYSLINUX" => \$syslinux,
  232. "SYSLINUX_PATH" => \$syslinux_path,
  233. "SYSLINUX_LABEL" => \$syslinux_label,
  234. "PRE_INSTALL" => \$pre_install,
  235. "POST_INSTALL" => \$post_install,
  236. "NO_INSTALL" => \$no_install,
  237. "REBOOT_SCRIPT" => \$reboot_script,
  238. "REBOOT_ON_ERROR" => \$reboot_on_error,
  239. "SWITCH_TO_GOOD" => \$switch_to_good,
  240. "SWITCH_TO_TEST" => \$switch_to_test,
  241. "POWEROFF_ON_ERROR" => \$poweroff_on_error,
  242. "REBOOT_ON_SUCCESS" => \$reboot_on_success,
  243. "DIE_ON_FAILURE" => \$die_on_failure,
  244. "POWER_OFF" => \$power_off,
  245. "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot,
  246. "POWEROFF_AFTER_HALT" => \$poweroff_after_halt,
  247. "MAX_MONITOR_WAIT" => \$max_monitor_wait,
  248. "SLEEP_TIME" => \$sleep_time,
  249. "BISECT_SLEEP_TIME" => \$bisect_sleep_time,
  250. "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time,
  251. "IGNORE_WARNINGS" => \$ignore_warnings,
  252. "IGNORE_ERRORS" => \$ignore_errors,
  253. "BISECT_MANUAL" => \$bisect_manual,
  254. "BISECT_SKIP" => \$bisect_skip,
  255. "CONFIG_BISECT_GOOD" => \$config_bisect_good,
  256. "BISECT_RET_GOOD" => \$bisect_ret_good,
  257. "BISECT_RET_BAD" => \$bisect_ret_bad,
  258. "BISECT_RET_SKIP" => \$bisect_ret_skip,
  259. "BISECT_RET_ABORT" => \$bisect_ret_abort,
  260. "BISECT_RET_DEFAULT" => \$bisect_ret_default,
  261. "STORE_FAILURES" => \$store_failures,
  262. "STORE_SUCCESSES" => \$store_successes,
  263. "TEST_NAME" => \$test_name,
  264. "TIMEOUT" => \$timeout,
  265. "BOOTED_TIMEOUT" => \$booted_timeout,
  266. "CONSOLE" => \$console,
  267. "DETECT_TRIPLE_FAULT" => \$detect_triplefault,
  268. "SUCCESS_LINE" => \$success_line,
  269. "REBOOT_SUCCESS_LINE" => \$reboot_success_line,
  270. "STOP_AFTER_SUCCESS" => \$stop_after_success,
  271. "STOP_AFTER_FAILURE" => \$stop_after_failure,
  272. "STOP_TEST_AFTER" => \$stop_test_after,
  273. "BUILD_TARGET" => \$build_target,
  274. "SSH_EXEC" => \$ssh_exec,
  275. "SCP_TO_TARGET" => \$scp_to_target,
  276. "SCP_TO_TARGET_INSTALL" => \$scp_to_target_install,
  277. "CHECKOUT" => \$checkout,
  278. "TARGET_IMAGE" => \$target_image,
  279. "LOCALVERSION" => \$localversion,
  280. "BISECT_GOOD" => \$bisect_good,
  281. "BISECT_BAD" => \$bisect_bad,
  282. "BISECT_TYPE" => \$bisect_type,
  283. "BISECT_START" => \$bisect_start,
  284. "BISECT_REPLAY" => \$bisect_replay,
  285. "BISECT_FILES" => \$bisect_files,
  286. "BISECT_REVERSE" => \$bisect_reverse,
  287. "BISECT_CHECK" => \$bisect_check,
  288. "CONFIG_BISECT" => \$config_bisect,
  289. "CONFIG_BISECT_TYPE" => \$config_bisect_type,
  290. "CONFIG_BISECT_CHECK" => \$config_bisect_check,
  291. "PATCHCHECK_TYPE" => \$patchcheck_type,
  292. "PATCHCHECK_START" => \$patchcheck_start,
  293. "PATCHCHECK_END" => \$patchcheck_end,
  294. );
  295. # Options may be used by other options, record them.
  296. my %used_options;
  297. # default variables that can be used
  298. chomp ($variable{"PWD"} = `pwd`);
  299. $config_help{"MACHINE"} = << "EOF"
  300. The machine hostname that you will test.
  301. For build only tests, it is still needed to differentiate log files.
  302. EOF
  303. ;
  304. $config_help{"SSH_USER"} = << "EOF"
  305. The box is expected to have ssh on normal bootup, provide the user
  306. (most likely root, since you need privileged operations)
  307. EOF
  308. ;
  309. $config_help{"BUILD_DIR"} = << "EOF"
  310. The directory that contains the Linux source code (full path).
  311. You can use \${PWD} that will be the path where ktest.pl is run, or use
  312. \${THIS_DIR} which is assigned \${PWD} but may be changed later.
  313. EOF
  314. ;
  315. $config_help{"OUTPUT_DIR"} = << "EOF"
  316. The directory that the objects will be built (full path).
  317. (can not be same as BUILD_DIR)
  318. You can use \${PWD} that will be the path where ktest.pl is run, or use
  319. \${THIS_DIR} which is assigned \${PWD} but may be changed later.
  320. EOF
  321. ;
  322. $config_help{"BUILD_TARGET"} = << "EOF"
  323. The location of the compiled file to copy to the target.
  324. (relative to OUTPUT_DIR)
  325. EOF
  326. ;
  327. $config_help{"BUILD_OPTIONS"} = << "EOF"
  328. Options to add to \"make\" when building.
  329. i.e. -j20
  330. EOF
  331. ;
  332. $config_help{"TARGET_IMAGE"} = << "EOF"
  333. The place to put your image on the test machine.
  334. EOF
  335. ;
  336. $config_help{"POWER_CYCLE"} = << "EOF"
  337. A script or command to reboot the box.
  338. Here is a digital loggers power switch example
  339. POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
  340. Here is an example to reboot a virtual box on the current host
  341. with the name "Guest".
  342. POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
  343. EOF
  344. ;
  345. $config_help{"CONSOLE"} = << "EOF"
  346. The script or command that reads the console
  347. If you use ttywatch server, something like the following would work.
  348. CONSOLE = nc -d localhost 3001
  349. For a virtual machine with guest name "Guest".
  350. CONSOLE = virsh console Guest
  351. EOF
  352. ;
  353. $config_help{"LOCALVERSION"} = << "EOF"
  354. Required version ending to differentiate the test
  355. from other linux builds on the system.
  356. EOF
  357. ;
  358. $config_help{"REBOOT_TYPE"} = << "EOF"
  359. Way to reboot the box to the test kernel.
  360. Only valid options so far are "grub", "grub2", "syslinux", and "script".
  361. If you specify grub, it will assume grub version 1
  362. and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
  363. and select that target to reboot to the kernel. If this is not
  364. your setup, then specify "script" and have a command or script
  365. specified in REBOOT_SCRIPT to boot to the target.
  366. The entry in /boot/grub/menu.lst must be entered in manually.
  367. The test will not modify that file.
  368. If you specify grub2, then you also need to specify both \$GRUB_MENU
  369. and \$GRUB_FILE.
  370. If you specify syslinux, then you may use SYSLINUX to define the syslinux
  371. command (defaults to extlinux), and SYSLINUX_PATH to specify the path to
  372. the syslinux install (defaults to /boot/extlinux). But you have to specify
  373. SYSLINUX_LABEL to define the label to boot to for the test kernel.
  374. EOF
  375. ;
  376. $config_help{"GRUB_MENU"} = << "EOF"
  377. The grub title name for the test kernel to boot
  378. (Only mandatory if REBOOT_TYPE = grub or grub2)
  379. Note, ktest.pl will not update the grub menu.lst, you need to
  380. manually add an option for the test. ktest.pl will search
  381. the grub menu.lst for this option to find what kernel to
  382. reboot into.
  383. For example, if in the /boot/grub/menu.lst the test kernel title has:
  384. title Test Kernel
  385. kernel vmlinuz-test
  386. GRUB_MENU = Test Kernel
  387. For grub2, a search of \$GRUB_FILE is performed for the lines
  388. that begin with "menuentry". It will not detect submenus. The
  389. menu must be a non-nested menu. Add the quotes used in the menu
  390. to guarantee your selection, as the first menuentry with the content
  391. of \$GRUB_MENU that is found will be used.
  392. EOF
  393. ;
  394. $config_help{"GRUB_FILE"} = << "EOF"
  395. If grub2 is used, the full path for the grub.cfg file is placed
  396. here. Use something like /boot/grub2/grub.cfg to search.
  397. EOF
  398. ;
  399. $config_help{"SYSLINUX_LABEL"} = << "EOF"
  400. If syslinux is used, the label that boots the target kernel must
  401. be specified with SYSLINUX_LABEL.
  402. EOF
  403. ;
  404. $config_help{"REBOOT_SCRIPT"} = << "EOF"
  405. A script to reboot the target into the test kernel
  406. (Only mandatory if REBOOT_TYPE = script)
  407. EOF
  408. ;
  409. sub read_prompt {
  410. my ($cancel, $prompt) = @_;
  411. my $ans;
  412. for (;;) {
  413. if ($cancel) {
  414. print "$prompt [y/n/C] ";
  415. } else {
  416. print "$prompt [Y/n] ";
  417. }
  418. $ans = <STDIN>;
  419. chomp $ans;
  420. if ($ans =~ /^\s*$/) {
  421. if ($cancel) {
  422. $ans = "c";
  423. } else {
  424. $ans = "y";
  425. }
  426. }
  427. last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
  428. if ($cancel) {
  429. last if ($ans =~ /^c$/i);
  430. print "Please answer either 'y', 'n' or 'c'.\n";
  431. } else {
  432. print "Please answer either 'y' or 'n'.\n";
  433. }
  434. }
  435. if ($ans =~ /^c/i) {
  436. exit;
  437. }
  438. if ($ans !~ /^y$/i) {
  439. return 0;
  440. }
  441. return 1;
  442. }
  443. sub read_yn {
  444. my ($prompt) = @_;
  445. return read_prompt 0, $prompt;
  446. }
  447. sub read_ync {
  448. my ($prompt) = @_;
  449. return read_prompt 1, $prompt;
  450. }
  451. sub get_ktest_config {
  452. my ($config) = @_;
  453. my $ans;
  454. return if (defined($opt{$config}));
  455. if (defined($config_help{$config})) {
  456. print "\n";
  457. print $config_help{$config};
  458. }
  459. for (;;) {
  460. print "$config = ";
  461. if (defined($default{$config}) && length($default{$config})) {
  462. print "\[$default{$config}\] ";
  463. }
  464. $ans = <STDIN>;
  465. $ans =~ s/^\s*(.*\S)\s*$/$1/;
  466. if ($ans =~ /^\s*$/) {
  467. if ($default{$config}) {
  468. $ans = $default{$config};
  469. } else {
  470. print "Your answer can not be blank\n";
  471. next;
  472. }
  473. }
  474. $entered_configs{$config} = ${ans};
  475. last;
  476. }
  477. }
  478. sub get_ktest_configs {
  479. get_ktest_config("MACHINE");
  480. get_ktest_config("BUILD_DIR");
  481. get_ktest_config("OUTPUT_DIR");
  482. if ($newconfig) {
  483. get_ktest_config("BUILD_OPTIONS");
  484. }
  485. # options required for other than just building a kernel
  486. if (!$buildonly) {
  487. get_ktest_config("POWER_CYCLE");
  488. get_ktest_config("CONSOLE");
  489. }
  490. # options required for install and more
  491. if ($buildonly != 1) {
  492. get_ktest_config("SSH_USER");
  493. get_ktest_config("BUILD_TARGET");
  494. get_ktest_config("TARGET_IMAGE");
  495. }
  496. get_ktest_config("LOCALVERSION");
  497. return if ($buildonly);
  498. my $rtype = $opt{"REBOOT_TYPE"};
  499. if (!defined($rtype)) {
  500. if (!defined($opt{"GRUB_MENU"})) {
  501. get_ktest_config("REBOOT_TYPE");
  502. $rtype = $entered_configs{"REBOOT_TYPE"};
  503. } else {
  504. $rtype = "grub";
  505. }
  506. }
  507. if ($rtype eq "grub") {
  508. get_ktest_config("GRUB_MENU");
  509. }
  510. if ($rtype eq "grub2") {
  511. get_ktest_config("GRUB_MENU");
  512. get_ktest_config("GRUB_FILE");
  513. }
  514. if ($rtype eq "syslinux") {
  515. get_ktest_config("SYSLINUX_LABEL");
  516. }
  517. }
  518. sub process_variables {
  519. my ($value, $remove_undef) = @_;
  520. my $retval = "";
  521. # We want to check for '\', and it is just easier
  522. # to check the previous characet of '$' and not need
  523. # to worry if '$' is the first character. By adding
  524. # a space to $value, we can just check [^\\]\$ and
  525. # it will still work.
  526. $value = " $value";
  527. while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
  528. my $begin = $1;
  529. my $var = $2;
  530. my $end = $3;
  531. # append beginning of value to retval
  532. $retval = "$retval$begin";
  533. if (defined($variable{$var})) {
  534. $retval = "$retval$variable{$var}";
  535. } elsif (defined($remove_undef) && $remove_undef) {
  536. # for if statements, any variable that is not defined,
  537. # we simple convert to 0
  538. $retval = "${retval}0";
  539. } else {
  540. # put back the origin piece.
  541. $retval = "$retval\$\{$var\}";
  542. # This could be an option that is used later, save
  543. # it so we don't warn if this option is not one of
  544. # ktests options.
  545. $used_options{$var} = 1;
  546. }
  547. $value = $end;
  548. }
  549. $retval = "$retval$value";
  550. # remove the space added in the beginning
  551. $retval =~ s/ //;
  552. return "$retval"
  553. }
  554. sub set_value {
  555. my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
  556. my $prvalue = process_variables($rvalue);
  557. if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
  558. # Note if a test is something other than build, then we
  559. # will need other manditory options.
  560. if ($prvalue ne "install") {
  561. # for bisect, we need to check BISECT_TYPE
  562. if ($prvalue ne "bisect") {
  563. $buildonly = 0;
  564. }
  565. } else {
  566. # install still limits some manditory options.
  567. $buildonly = 2;
  568. }
  569. }
  570. if ($buildonly && $lvalue =~ /^BISECT_TYPE(\[.*\])?$/ && $prvalue ne "build") {
  571. if ($prvalue ne "install") {
  572. $buildonly = 0;
  573. } else {
  574. # install still limits some manditory options.
  575. $buildonly = 2;
  576. }
  577. }
  578. if (defined($opt{$lvalue})) {
  579. if (!$override || defined(${$overrides}{$lvalue})) {
  580. my $extra = "";
  581. if ($override) {
  582. $extra = "In the same override section!\n";
  583. }
  584. die "$name: $.: Option $lvalue defined more than once!\n$extra";
  585. }
  586. ${$overrides}{$lvalue} = $prvalue;
  587. }
  588. if ($rvalue =~ /^\s*$/) {
  589. delete $opt{$lvalue};
  590. } else {
  591. $opt{$lvalue} = $prvalue;
  592. }
  593. }
  594. sub set_variable {
  595. my ($lvalue, $rvalue) = @_;
  596. if ($rvalue =~ /^\s*$/) {
  597. delete $variable{$lvalue};
  598. } else {
  599. $rvalue = process_variables($rvalue);
  600. $variable{$lvalue} = $rvalue;
  601. }
  602. }
  603. sub process_compare {
  604. my ($lval, $cmp, $rval) = @_;
  605. # remove whitespace
  606. $lval =~ s/^\s*//;
  607. $lval =~ s/\s*$//;
  608. $rval =~ s/^\s*//;
  609. $rval =~ s/\s*$//;
  610. if ($cmp eq "==") {
  611. return $lval eq $rval;
  612. } elsif ($cmp eq "!=") {
  613. return $lval ne $rval;
  614. } elsif ($cmp eq "=~") {
  615. return $lval =~ m/$rval/;
  616. } elsif ($cmp eq "!~") {
  617. return $lval !~ m/$rval/;
  618. }
  619. my $statement = "$lval $cmp $rval";
  620. my $ret = eval $statement;
  621. # $@ stores error of eval
  622. if ($@) {
  623. return -1;
  624. }
  625. return $ret;
  626. }
  627. sub value_defined {
  628. my ($val) = @_;
  629. return defined($variable{$2}) ||
  630. defined($opt{$2});
  631. }
  632. my $d = 0;
  633. sub process_expression {
  634. my ($name, $val) = @_;
  635. my $c = $d++;
  636. while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
  637. my $express = $1;
  638. if (process_expression($name, $express)) {
  639. $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
  640. } else {
  641. $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
  642. }
  643. }
  644. $d--;
  645. my $OR = "\\|\\|";
  646. my $AND = "\\&\\&";
  647. while ($val =~ s/^(.*?)($OR|$AND)//) {
  648. my $express = $1;
  649. my $op = $2;
  650. if (process_expression($name, $express)) {
  651. if ($op eq "||") {
  652. return 1;
  653. }
  654. } else {
  655. if ($op eq "&&") {
  656. return 0;
  657. }
  658. }
  659. }
  660. if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) {
  661. my $ret = process_compare($1, $2, $3);
  662. if ($ret < 0) {
  663. die "$name: $.: Unable to process comparison\n";
  664. }
  665. return $ret;
  666. }
  667. if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
  668. if (defined $1) {
  669. return !value_defined($2);
  670. } else {
  671. return value_defined($2);
  672. }
  673. }
  674. if ($val =~ /^\s*0\s*$/) {
  675. return 0;
  676. } elsif ($val =~ /^\s*\d+\s*$/) {
  677. return 1;
  678. }
  679. die ("$name: $.: Undefined content $val in if statement\n");
  680. }
  681. sub process_if {
  682. my ($name, $value) = @_;
  683. # Convert variables and replace undefined ones with 0
  684. my $val = process_variables($value, 1);
  685. my $ret = process_expression $name, $val;
  686. return $ret;
  687. }
  688. sub __read_config {
  689. my ($config, $current_test_num) = @_;
  690. my $in;
  691. open($in, $config) || die "can't read file $config";
  692. my $name = $config;
  693. $name =~ s,.*/(.*),$1,;
  694. my $test_num = $$current_test_num;
  695. my $default = 1;
  696. my $repeat = 1;
  697. my $num_tests_set = 0;
  698. my $skip = 0;
  699. my $rest;
  700. my $line;
  701. my $test_case = 0;
  702. my $if = 0;
  703. my $if_set = 0;
  704. my $override = 0;
  705. my %overrides;
  706. while (<$in>) {
  707. # ignore blank lines and comments
  708. next if (/^\s*$/ || /\s*\#/);
  709. if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
  710. my $type = $1;
  711. $rest = $2;
  712. $line = $2;
  713. my $old_test_num;
  714. my $old_repeat;
  715. $override = 0;
  716. if ($type eq "TEST_START") {
  717. if ($num_tests_set) {
  718. die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
  719. }
  720. $old_test_num = $test_num;
  721. $old_repeat = $repeat;
  722. $test_num += $repeat;
  723. $default = 0;
  724. $repeat = 1;
  725. } else {
  726. $default = 1;
  727. }
  728. # If SKIP is anywhere in the line, the command will be skipped
  729. if ($rest =~ s/\s+SKIP\b//) {
  730. $skip = 1;
  731. } else {
  732. $test_case = 1;
  733. $skip = 0;
  734. }
  735. if ($rest =~ s/\sELSE\b//) {
  736. if (!$if) {
  737. die "$name: $.: ELSE found with out matching IF section\n$_";
  738. }
  739. $if = 0;
  740. if ($if_set) {
  741. $skip = 1;
  742. } else {
  743. $skip = 0;
  744. }
  745. }
  746. if ($rest =~ s/\sIF\s+(.*)//) {
  747. if (process_if($name, $1)) {
  748. $if_set = 1;
  749. } else {
  750. $skip = 1;
  751. }
  752. $if = 1;
  753. } else {
  754. $if = 0;
  755. $if_set = 0;
  756. }
  757. if (!$skip) {
  758. if ($type eq "TEST_START") {
  759. if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
  760. $repeat = $1;
  761. $repeat_tests{"$test_num"} = $repeat;
  762. }
  763. } elsif ($rest =~ s/\sOVERRIDE\b//) {
  764. # DEFAULT only
  765. $override = 1;
  766. # Clear previous overrides
  767. %overrides = ();
  768. }
  769. }
  770. if (!$skip && $rest !~ /^\s*$/) {
  771. die "$name: $.: Gargbage found after $type\n$_";
  772. }
  773. if ($skip && $type eq "TEST_START") {
  774. $test_num = $old_test_num;
  775. $repeat = $old_repeat;
  776. }
  777. } elsif (/^\s*ELSE\b(.*)$/) {
  778. if (!$if) {
  779. die "$name: $.: ELSE found with out matching IF section\n$_";
  780. }
  781. $rest = $1;
  782. if ($if_set) {
  783. $skip = 1;
  784. $rest = "";
  785. } else {
  786. $skip = 0;
  787. if ($rest =~ /\sIF\s+(.*)/) {
  788. # May be a ELSE IF section.
  789. if (process_if($name, $1)) {
  790. $if_set = 1;
  791. } else {
  792. $skip = 1;
  793. }
  794. $rest = "";
  795. } else {
  796. $if = 0;
  797. }
  798. }
  799. if ($rest !~ /^\s*$/) {
  800. die "$name: $.: Gargbage found after DEFAULTS\n$_";
  801. }
  802. } elsif (/^\s*INCLUDE\s+(\S+)/) {
  803. next if ($skip);
  804. if (!$default) {
  805. die "$name: $.: INCLUDE can only be done in default sections\n$_";
  806. }
  807. my $file = process_variables($1);
  808. if ($file !~ m,^/,) {
  809. # check the path of the config file first
  810. if ($config =~ m,(.*)/,) {
  811. if (-f "$1/$file") {
  812. $file = "$1/$file";
  813. }
  814. }
  815. }
  816. if ( ! -r $file ) {
  817. die "$name: $.: Can't read file $file\n$_";
  818. }
  819. if (__read_config($file, \$test_num)) {
  820. $test_case = 1;
  821. }
  822. } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
  823. next if ($skip);
  824. my $lvalue = $1;
  825. my $rvalue = $2;
  826. if (!$default &&
  827. ($lvalue eq "NUM_TESTS" ||
  828. $lvalue eq "LOG_FILE" ||
  829. $lvalue eq "CLEAR_LOG")) {
  830. die "$name: $.: $lvalue must be set in DEFAULTS section\n";
  831. }
  832. if ($lvalue eq "NUM_TESTS") {
  833. if ($test_num) {
  834. die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
  835. }
  836. if (!$default) {
  837. die "$name: $.: NUM_TESTS must be set in default section\n";
  838. }
  839. $num_tests_set = 1;
  840. }
  841. if ($default || $lvalue =~ /\[\d+\]$/) {
  842. set_value($lvalue, $rvalue, $override, \%overrides, $name);
  843. } else {
  844. my $val = "$lvalue\[$test_num\]";
  845. set_value($val, $rvalue, $override, \%overrides, $name);
  846. if ($repeat > 1) {
  847. $repeats{$val} = $repeat;
  848. }
  849. }
  850. } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
  851. next if ($skip);
  852. my $lvalue = $1;
  853. my $rvalue = $2;
  854. # process config variables.
  855. # Config variables are only active while reading the
  856. # config and can be defined anywhere. They also ignore
  857. # TEST_START and DEFAULTS, but are skipped if they are in
  858. # on of these sections that have SKIP defined.
  859. # The save variable can be
  860. # defined multiple times and the new one simply overrides
  861. # the prevous one.
  862. set_variable($lvalue, $rvalue);
  863. } else {
  864. die "$name: $.: Garbage found in config\n$_";
  865. }
  866. }
  867. if ($test_num) {
  868. $test_num += $repeat - 1;
  869. $opt{"NUM_TESTS"} = $test_num;
  870. }
  871. close($in);
  872. $$current_test_num = $test_num;
  873. return $test_case;
  874. }
  875. sub get_test_case {
  876. print "What test case would you like to run?\n";
  877. print " (build, install or boot)\n";
  878. print " Other tests are available but require editing the config file\n";
  879. my $ans = <STDIN>;
  880. chomp $ans;
  881. $default{"TEST_TYPE"} = $ans;
  882. }
  883. sub read_config {
  884. my ($config) = @_;
  885. my $test_case;
  886. my $test_num = 0;
  887. $test_case = __read_config $config, \$test_num;
  888. # make sure we have all mandatory configs
  889. get_ktest_configs;
  890. # was a test specified?
  891. if (!$test_case) {
  892. print "No test case specified.\n";
  893. get_test_case;
  894. }
  895. # set any defaults
  896. foreach my $default (keys %default) {
  897. if (!defined($opt{$default})) {
  898. $opt{$default} = $default{$default};
  899. }
  900. }
  901. if ($opt{"IGNORE_UNUSED"} == 1) {
  902. return;
  903. }
  904. my %not_used;
  905. # check if there are any stragglers (typos?)
  906. foreach my $option (keys %opt) {
  907. my $op = $option;
  908. # remove per test labels.
  909. $op =~ s/\[.*\]//;
  910. if (!exists($option_map{$op}) &&
  911. !exists($default{$op}) &&
  912. !exists($used_options{$op})) {
  913. $not_used{$op} = 1;
  914. }
  915. }
  916. if (%not_used) {
  917. my $s = "s are";
  918. $s = " is" if (keys %not_used == 1);
  919. print "The following option$s not used; could be a typo:\n";
  920. foreach my $option (keys %not_used) {
  921. print "$option\n";
  922. }
  923. print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
  924. if (!read_yn "Do you want to continue?") {
  925. exit -1;
  926. }
  927. }
  928. }
  929. sub __eval_option {
  930. my ($name, $option, $i) = @_;
  931. # Add space to evaluate the character before $
  932. $option = " $option";
  933. my $retval = "";
  934. my $repeated = 0;
  935. my $parent = 0;
  936. foreach my $test (keys %repeat_tests) {
  937. if ($i >= $test &&
  938. $i < $test + $repeat_tests{$test}) {
  939. $repeated = 1;
  940. $parent = $test;
  941. last;
  942. }
  943. }
  944. while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
  945. my $start = $1;
  946. my $var = $2;
  947. my $end = $3;
  948. # Append beginning of line
  949. $retval = "$retval$start";
  950. # If the iteration option OPT[$i] exists, then use that.
  951. # otherwise see if the default OPT (without [$i]) exists.
  952. my $o = "$var\[$i\]";
  953. my $parento = "$var\[$parent\]";
  954. # If a variable contains itself, use the default var
  955. if (($var eq $name) && defined($opt{$var})) {
  956. $o = $opt{$var};
  957. $retval = "$retval$o";
  958. } elsif (defined($opt{$o})) {
  959. $o = $opt{$o};
  960. $retval = "$retval$o";
  961. } elsif ($repeated && defined($opt{$parento})) {
  962. $o = $opt{$parento};
  963. $retval = "$retval$o";
  964. } elsif (defined($opt{$var})) {
  965. $o = $opt{$var};
  966. $retval = "$retval$o";
  967. } else {
  968. $retval = "$retval\$\{$var\}";
  969. }
  970. $option = $end;
  971. }
  972. $retval = "$retval$option";
  973. $retval =~ s/^ //;
  974. return $retval;
  975. }
  976. sub eval_option {
  977. my ($name, $option, $i) = @_;
  978. my $prev = "";
  979. # Since an option can evaluate to another option,
  980. # keep iterating until we do not evaluate any more
  981. # options.
  982. my $r = 0;
  983. while ($prev ne $option) {
  984. # Check for recursive evaluations.
  985. # 100 deep should be more than enough.
  986. if ($r++ > 100) {
  987. die "Over 100 evaluations accurred with $option\n" .
  988. "Check for recursive variables\n";
  989. }
  990. $prev = $option;
  991. $option = __eval_option($name, $option, $i);
  992. }
  993. return $option;
  994. }
  995. sub _logit {
  996. if (defined($opt{"LOG_FILE"})) {
  997. open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
  998. print OUT @_;
  999. close(OUT);
  1000. }
  1001. }
  1002. sub logit {
  1003. if (defined($opt{"LOG_FILE"})) {
  1004. _logit @_;
  1005. } else {
  1006. print @_;
  1007. }
  1008. }
  1009. sub doprint {
  1010. print @_;
  1011. _logit @_;
  1012. }
  1013. sub run_command;
  1014. sub start_monitor;
  1015. sub end_monitor;
  1016. sub wait_for_monitor;
  1017. sub reboot {
  1018. my ($time) = @_;
  1019. # Make sure everything has been written to disk
  1020. run_ssh("sync");
  1021. if (defined($time)) {
  1022. start_monitor;
  1023. # flush out current monitor
  1024. # May contain the reboot success line
  1025. wait_for_monitor 1;
  1026. }
  1027. # try to reboot normally
  1028. if (run_command $reboot) {
  1029. if (defined($powercycle_after_reboot)) {
  1030. sleep $powercycle_after_reboot;
  1031. run_command "$power_cycle";
  1032. }
  1033. } else {
  1034. # nope? power cycle it.
  1035. run_command "$power_cycle";
  1036. }
  1037. if (defined($time)) {
  1038. # We only want to get to the new kernel, don't fail
  1039. # if we stumble over a call trace.
  1040. my $save_ignore_errors = $ignore_errors;
  1041. $ignore_errors = 1;
  1042. # Look for the good kernel to boot
  1043. if (wait_for_monitor($time, "Linux version")) {
  1044. # reboot got stuck?
  1045. doprint "Reboot did not finish. Forcing power cycle\n";
  1046. run_command "$power_cycle";
  1047. }
  1048. $ignore_errors = $save_ignore_errors;
  1049. # Still need to wait for the reboot to finish
  1050. wait_for_monitor($time, $reboot_success_line);
  1051. end_monitor;
  1052. }
  1053. }
  1054. sub reboot_to_good {
  1055. my ($time) = @_;
  1056. if (defined($switch_to_good)) {
  1057. run_command $switch_to_good;
  1058. }
  1059. reboot $time;
  1060. }
  1061. sub do_not_reboot {
  1062. my $i = $iteration;
  1063. return $test_type eq "build" || $no_reboot ||
  1064. ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
  1065. ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
  1066. }
  1067. sub dodie {
  1068. doprint "CRITICAL FAILURE... ", @_, "\n";
  1069. my $i = $iteration;
  1070. if ($reboot_on_error && !do_not_reboot) {
  1071. doprint "REBOOTING\n";
  1072. reboot_to_good;
  1073. } elsif ($poweroff_on_error && defined($power_off)) {
  1074. doprint "POWERING OFF\n";
  1075. `$power_off`;
  1076. }
  1077. if (defined($opt{"LOG_FILE"})) {
  1078. print " See $opt{LOG_FILE} for more info.\n";
  1079. }
  1080. die @_, "\n";
  1081. }
  1082. sub open_console {
  1083. my ($fp) = @_;
  1084. my $flags;
  1085. my $pid = open($fp, "$console|") or
  1086. dodie "Can't open console $console";
  1087. $flags = fcntl($fp, F_GETFL, 0) or
  1088. dodie "Can't get flags for the socket: $!";
  1089. $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
  1090. dodie "Can't set flags for the socket: $!";
  1091. return $pid;
  1092. }
  1093. sub close_console {
  1094. my ($fp, $pid) = @_;
  1095. doprint "kill child process $pid\n";
  1096. kill 2, $pid;
  1097. print "closing!\n";
  1098. close($fp);
  1099. }
  1100. sub start_monitor {
  1101. if ($monitor_cnt++) {
  1102. return;
  1103. }
  1104. $monitor_fp = \*MONFD;
  1105. $monitor_pid = open_console $monitor_fp;
  1106. return;
  1107. open(MONFD, "Stop perl from warning about single use of MONFD");
  1108. }
  1109. sub end_monitor {
  1110. return if (!defined $console);
  1111. if (--$monitor_cnt) {
  1112. return;
  1113. }
  1114. close_console($monitor_fp, $monitor_pid);
  1115. }
  1116. sub wait_for_monitor {
  1117. my ($time, $stop) = @_;
  1118. my $full_line = "";
  1119. my $line;
  1120. my $booted = 0;
  1121. my $start_time = time;
  1122. my $skip_call_trace = 0;
  1123. my $bug = 0;
  1124. my $bug_ignored = 0;
  1125. my $now;
  1126. doprint "** Wait for monitor to settle down **\n";
  1127. # read the monitor and wait for the system to calm down
  1128. while (!$booted) {
  1129. $line = wait_for_input($monitor_fp, $time);
  1130. last if (!defined($line));
  1131. print "$line";
  1132. $full_line .= $line;
  1133. if (defined($stop) && $full_line =~ /$stop/) {
  1134. doprint "wait for monitor detected $stop\n";
  1135. $booted = 1;
  1136. }
  1137. if ($full_line =~ /\[ backtrace testing \]/) {
  1138. $skip_call_trace = 1;
  1139. }
  1140. if ($full_line =~ /call trace:/i) {
  1141. if (!$bug && !$skip_call_trace) {
  1142. if ($ignore_errors) {
  1143. $bug_ignored = 1;
  1144. } else {
  1145. $bug = 1;
  1146. }
  1147. }
  1148. }
  1149. if ($full_line =~ /\[ end of backtrace testing \]/) {
  1150. $skip_call_trace = 0;
  1151. }
  1152. if ($full_line =~ /Kernel panic -/) {
  1153. $bug = 1;
  1154. }
  1155. if ($line =~ /\n/) {
  1156. $full_line = "";
  1157. }
  1158. $now = time;
  1159. if ($now - $start_time >= $max_monitor_wait) {
  1160. doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
  1161. return 1;
  1162. }
  1163. }
  1164. print "** Monitor flushed **\n";
  1165. return $bug;
  1166. }
  1167. sub save_logs {
  1168. my ($result, $basedir) = @_;
  1169. my @t = localtime;
  1170. my $date = sprintf "%04d%02d%02d%02d%02d%02d",
  1171. 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
  1172. my $type = $build_type;
  1173. if ($type =~ /useconfig/) {
  1174. $type = "useconfig";
  1175. }
  1176. my $dir = "$machine-$test_type-$type-$result-$date";
  1177. $dir = "$basedir/$dir";
  1178. if (!-d $dir) {
  1179. mkpath($dir) or
  1180. die "can't create $dir";
  1181. }
  1182. my %files = (
  1183. "config" => $output_config,
  1184. "buildlog" => $buildlog,
  1185. "dmesg" => $dmesg,
  1186. "testlog" => $testlog,
  1187. );
  1188. while (my ($name, $source) = each(%files)) {
  1189. if (-f "$source") {
  1190. cp "$source", "$dir/$name" or
  1191. die "failed to copy $source";
  1192. }
  1193. }
  1194. doprint "*** Saved info to $dir ***\n";
  1195. }
  1196. sub fail {
  1197. if (defined($post_test)) {
  1198. run_command $post_test;
  1199. }
  1200. if ($die_on_failure) {
  1201. dodie @_;
  1202. }
  1203. doprint "FAILED\n";
  1204. my $i = $iteration;
  1205. # no need to reboot for just building.
  1206. if (!do_not_reboot) {
  1207. doprint "REBOOTING\n";
  1208. reboot_to_good $sleep_time;
  1209. }
  1210. my $name = "";
  1211. if (defined($test_name)) {
  1212. $name = " ($test_name)";
  1213. }
  1214. doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
  1215. doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
  1216. doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
  1217. doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
  1218. doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
  1219. if (defined($store_failures)) {
  1220. save_logs "fail", $store_failures;
  1221. }
  1222. return 1;
  1223. }
  1224. sub run_command {
  1225. my ($command) = @_;
  1226. my $dolog = 0;
  1227. my $dord = 0;
  1228. my $pid;
  1229. $command =~ s/\$SSH_USER/$ssh_user/g;
  1230. $command =~ s/\$MACHINE/$machine/g;
  1231. doprint("$command ... ");
  1232. $pid = open(CMD, "$command 2>&1 |") or
  1233. (fail "unable to exec $command" and return 0);
  1234. if (defined($opt{"LOG_FILE"})) {
  1235. open(LOG, ">>$opt{LOG_FILE}") or
  1236. dodie "failed to write to log";
  1237. $dolog = 1;
  1238. }
  1239. if (defined($redirect)) {
  1240. open (RD, ">$redirect") or
  1241. dodie "failed to write to redirect $redirect";
  1242. $dord = 1;
  1243. }
  1244. while (<CMD>) {
  1245. print LOG if ($dolog);
  1246. print RD if ($dord);
  1247. }
  1248. waitpid($pid, 0);
  1249. my $failed = $?;
  1250. close(CMD);
  1251. close(LOG) if ($dolog);
  1252. close(RD) if ($dord);
  1253. if ($failed) {
  1254. doprint "FAILED!\n";
  1255. } else {
  1256. doprint "SUCCESS\n";
  1257. }
  1258. return !$failed;
  1259. }
  1260. sub run_ssh {
  1261. my ($cmd) = @_;
  1262. my $cp_exec = $ssh_exec;
  1263. $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
  1264. return run_command "$cp_exec";
  1265. }
  1266. sub run_scp {
  1267. my ($src, $dst, $cp_scp) = @_;
  1268. $cp_scp =~ s/\$SRC_FILE/$src/g;
  1269. $cp_scp =~ s/\$DST_FILE/$dst/g;
  1270. return run_command "$cp_scp";
  1271. }
  1272. sub run_scp_install {
  1273. my ($src, $dst) = @_;
  1274. my $cp_scp = $scp_to_target_install;
  1275. return run_scp($src, $dst, $cp_scp);
  1276. }
  1277. sub run_scp_mod {
  1278. my ($src, $dst) = @_;
  1279. my $cp_scp = $scp_to_target;
  1280. return run_scp($src, $dst, $cp_scp);
  1281. }
  1282. sub get_grub2_index {
  1283. return if (defined($grub_number));
  1284. doprint "Find grub2 menu ... ";
  1285. $grub_number = -1;
  1286. my $ssh_grub = $ssh_exec;
  1287. $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
  1288. open(IN, "$ssh_grub |")
  1289. or die "unable to get $grub_file";
  1290. my $found = 0;
  1291. while (<IN>) {
  1292. if (/^menuentry.*$grub_menu/) {
  1293. $grub_number++;
  1294. $found = 1;
  1295. last;
  1296. } elsif (/^menuentry\s/) {
  1297. $grub_number++;
  1298. }
  1299. }
  1300. close(IN);
  1301. die "Could not find '$grub_menu' in $grub_file on $machine"
  1302. if (!$found);
  1303. doprint "$grub_number\n";
  1304. }
  1305. sub get_grub_index {
  1306. if ($reboot_type eq "grub2") {
  1307. get_grub2_index;
  1308. return;
  1309. }
  1310. if ($reboot_type ne "grub") {
  1311. return;
  1312. }
  1313. return if (defined($grub_number));
  1314. doprint "Find grub menu ... ";
  1315. $grub_number = -1;
  1316. my $ssh_grub = $ssh_exec;
  1317. $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
  1318. open(IN, "$ssh_grub |")
  1319. or die "unable to get menu.lst";
  1320. my $found = 0;
  1321. while (<IN>) {
  1322. if (/^\s*title\s+$grub_menu\s*$/) {
  1323. $grub_number++;
  1324. $found = 1;
  1325. last;
  1326. } elsif (/^\s*title\s/) {
  1327. $grub_number++;
  1328. }
  1329. }
  1330. close(IN);
  1331. die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
  1332. if (!$found);
  1333. doprint "$grub_number\n";
  1334. }
  1335. sub wait_for_input
  1336. {
  1337. my ($fp, $time) = @_;
  1338. my $rin;
  1339. my $ready;
  1340. my $line;
  1341. my $ch;
  1342. if (!defined($time)) {
  1343. $time = $timeout;
  1344. }
  1345. $rin = '';
  1346. vec($rin, fileno($fp), 1) = 1;
  1347. ($ready, $time) = select($rin, undef, undef, $time);
  1348. $line = "";
  1349. # try to read one char at a time
  1350. while (sysread $fp, $ch, 1) {
  1351. $line .= $ch;
  1352. last if ($ch eq "\n");
  1353. }
  1354. if (!length($line)) {
  1355. return undef;
  1356. }
  1357. return $line;
  1358. }
  1359. sub reboot_to {
  1360. if (defined($switch_to_test)) {
  1361. run_command $switch_to_test;
  1362. }
  1363. if ($reboot_type eq "grub") {
  1364. run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
  1365. } elsif ($reboot_type eq "grub2") {
  1366. run_ssh "$grub_reboot $grub_number";
  1367. } elsif ($reboot_type eq "syslinux") {
  1368. run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
  1369. } elsif (defined $reboot_script) {
  1370. run_command "$reboot_script";
  1371. }
  1372. reboot;
  1373. }
  1374. sub get_sha1 {
  1375. my ($commit) = @_;
  1376. doprint "git rev-list --max-count=1 $commit ... ";
  1377. my $sha1 = `git rev-list --max-count=1 $commit`;
  1378. my $ret = $?;
  1379. logit $sha1;
  1380. if ($ret) {
  1381. doprint "FAILED\n";
  1382. dodie "Failed to get git $commit";
  1383. }
  1384. print "SUCCESS\n";
  1385. chomp $sha1;
  1386. return $sha1;
  1387. }
  1388. sub monitor {
  1389. my $booted = 0;
  1390. my $bug = 0;
  1391. my $bug_ignored = 0;
  1392. my $skip_call_trace = 0;
  1393. my $loops;
  1394. wait_for_monitor 5;
  1395. my $line;
  1396. my $full_line = "";
  1397. open(DMESG, "> $dmesg") or
  1398. die "unable to write to $dmesg";
  1399. reboot_to;
  1400. my $success_start;
  1401. my $failure_start;
  1402. my $monitor_start = time;
  1403. my $done = 0;
  1404. my $version_found = 0;
  1405. while (!$done) {
  1406. if ($bug && defined($stop_after_failure) &&
  1407. $stop_after_failure >= 0) {
  1408. my $time = $stop_after_failure - (time - $failure_start);
  1409. $line = wait_for_input($monitor_fp, $time);
  1410. if (!defined($line)) {
  1411. doprint "bug timed out after $booted_timeout seconds\n";
  1412. doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
  1413. last;
  1414. }
  1415. } elsif ($booted) {
  1416. $line = wait_for_input($monitor_fp, $booted_timeout);
  1417. if (!defined($line)) {
  1418. my $s = $booted_timeout == 1 ? "" : "s";
  1419. doprint "Successful boot found: break after $booted_timeout second$s\n";
  1420. last;
  1421. }
  1422. } else {
  1423. $line = wait_for_input($monitor_fp);
  1424. if (!defined($line)) {
  1425. my $s = $timeout == 1 ? "" : "s";
  1426. doprint "Timed out after $timeout second$s\n";
  1427. last;
  1428. }
  1429. }
  1430. doprint $line;
  1431. print DMESG $line;
  1432. # we are not guaranteed to get a full line
  1433. $full_line .= $line;
  1434. if ($full_line =~ /$success_line/) {
  1435. $booted = 1;
  1436. $success_start = time;
  1437. }
  1438. if ($booted && defined($stop_after_success) &&
  1439. $stop_after_success >= 0) {
  1440. my $now = time;
  1441. if ($now - $success_start >= $stop_after_success) {
  1442. doprint "Test forced to stop after $stop_after_success seconds after success\n";
  1443. last;
  1444. }
  1445. }
  1446. if ($full_line =~ /\[ backtrace testing \]/) {
  1447. $skip_call_trace = 1;
  1448. }
  1449. if ($full_line =~ /call trace:/i) {
  1450. if (!$bug && !$skip_call_trace) {
  1451. if ($ignore_errors) {
  1452. $bug_ignored = 1;
  1453. } else {
  1454. $bug = 1;
  1455. $failure_start = time;
  1456. }
  1457. }
  1458. }
  1459. if ($bug && defined($stop_after_failure) &&
  1460. $stop_after_failure >= 0) {
  1461. my $now = time;
  1462. if ($now - $failure_start >= $stop_after_failure) {
  1463. doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
  1464. last;
  1465. }
  1466. }
  1467. if ($full_line =~ /\[ end of backtrace testing \]/) {
  1468. $skip_call_trace = 0;
  1469. }
  1470. if ($full_line =~ /Kernel panic -/) {
  1471. $failure_start = time;
  1472. $bug = 1;
  1473. }
  1474. # Detect triple faults by testing the banner
  1475. if ($full_line =~ /\bLinux version (\S+).*\n/) {
  1476. if ($1 eq $version) {
  1477. $version_found = 1;
  1478. } elsif ($version_found && $detect_triplefault) {
  1479. # We already booted into the kernel we are testing,
  1480. # but now we booted into another kernel?
  1481. # Consider this a triple fault.
  1482. doprint "Aleady booted in Linux kernel $version, but now\n";
  1483. doprint "we booted into Linux kernel $1.\n";
  1484. doprint "Assuming that this is a triple fault.\n";
  1485. doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
  1486. last;
  1487. }
  1488. }
  1489. if ($line =~ /\n/) {
  1490. $full_line = "";
  1491. }
  1492. if ($stop_test_after > 0 && !$booted && !$bug) {
  1493. if (time - $monitor_start > $stop_test_after) {
  1494. doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
  1495. $done = 1;
  1496. }
  1497. }
  1498. }
  1499. close(DMESG);
  1500. if ($bug) {
  1501. return 0 if ($in_bisect);
  1502. fail "failed - got a bug report" and return 0;
  1503. }
  1504. if (!$booted) {
  1505. return 0 if ($in_bisect);
  1506. fail "failed - never got a boot prompt." and return 0;
  1507. }
  1508. if ($bug_ignored) {
  1509. doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
  1510. }
  1511. return 1;
  1512. }
  1513. sub eval_kernel_version {
  1514. my ($option) = @_;
  1515. $option =~ s/\$KERNEL_VERSION/$version/g;
  1516. return $option;
  1517. }
  1518. sub do_post_install {
  1519. return if (!defined($post_install));
  1520. my $cp_post_install = eval_kernel_version $post_install;
  1521. run_command "$cp_post_install" or
  1522. dodie "Failed to run post install";
  1523. }
  1524. # Sometimes the reboot fails, and will hang. We try to ssh to the box
  1525. # and if we fail, we force another reboot, that should powercycle it.
  1526. sub test_booted {
  1527. if (!run_ssh "echo testing connection") {
  1528. reboot $sleep_time;
  1529. }
  1530. }
  1531. sub install {
  1532. return if ($no_install);
  1533. if (defined($pre_install)) {
  1534. my $cp_pre_install = eval_kernel_version $pre_install;
  1535. run_command "$cp_pre_install" or
  1536. dodie "Failed to run pre install";
  1537. }
  1538. my $cp_target = eval_kernel_version $target_image;
  1539. test_booted;
  1540. run_scp_install "$outputdir/$build_target", "$cp_target" or
  1541. dodie "failed to copy image";
  1542. my $install_mods = 0;
  1543. # should we process modules?
  1544. $install_mods = 0;
  1545. open(IN, "$output_config") or dodie("Can't read config file");
  1546. while (<IN>) {
  1547. if (/CONFIG_MODULES(=y)?/) {
  1548. if (defined($1)) {
  1549. $install_mods = 1;
  1550. last;
  1551. }
  1552. }
  1553. }
  1554. close(IN);
  1555. if (!$install_mods) {
  1556. do_post_install;
  1557. doprint "No modules needed\n";
  1558. return;
  1559. }
  1560. run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
  1561. dodie "Failed to install modules";
  1562. my $modlib = "/lib/modules/$version";
  1563. my $modtar = "ktest-mods.tar.bz2";
  1564. run_ssh "rm -rf $modlib" or
  1565. dodie "failed to remove old mods: $modlib";
  1566. # would be nice if scp -r did not follow symbolic links
  1567. run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
  1568. dodie "making tarball";
  1569. run_scp_mod "$tmpdir/$modtar", "/tmp" or
  1570. dodie "failed to copy modules";
  1571. unlink "$tmpdir/$modtar";
  1572. run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
  1573. dodie "failed to tar modules";
  1574. run_ssh "rm -f /tmp/$modtar";
  1575. do_post_install;
  1576. }
  1577. sub get_version {
  1578. # get the release name
  1579. return if ($have_version);
  1580. doprint "$make kernelrelease ... ";
  1581. $version = `$make kernelrelease | tail -1`;
  1582. chomp($version);
  1583. doprint "$version\n";
  1584. $have_version = 1;
  1585. }
  1586. sub start_monitor_and_boot {
  1587. # Make sure the stable kernel has finished booting
  1588. # Install bisects, don't need console
  1589. if (defined $console) {
  1590. start_monitor;
  1591. wait_for_monitor 5;
  1592. end_monitor;
  1593. }
  1594. get_grub_index;
  1595. get_version;
  1596. install;
  1597. start_monitor if (defined $console);
  1598. return monitor;
  1599. }
  1600. my $check_build_re = ".*:.*(warning|error|Error):.*";
  1601. my $utf8_quote = "\\x{e2}\\x{80}(\\x{98}|\\x{99})";
  1602. sub process_warning_line {
  1603. my ($line) = @_;
  1604. chomp $line;
  1605. # for distcc heterogeneous systems, some compilers
  1606. # do things differently causing warning lines
  1607. # to be slightly different. This makes an attempt
  1608. # to fixe those issues.
  1609. # chop off the index into the line
  1610. # using distcc, some compilers give different indexes
  1611. # depending on white space
  1612. $line =~ s/^(\s*\S+:\d+:)\d+/$1/;
  1613. # Some compilers use UTF-8 extended for quotes and some don't.
  1614. $line =~ s/$utf8_quote/'/g;
  1615. return $line;
  1616. }
  1617. # Read buildlog and check against warnings file for any
  1618. # new warnings.
  1619. #
  1620. # Returns 1 if OK
  1621. # 0 otherwise
  1622. sub check_buildlog {
  1623. return 1 if (!defined $warnings_file);
  1624. my %warnings_list;
  1625. # Failed builds should not reboot the target
  1626. my $save_no_reboot = $no_reboot;
  1627. $no_reboot = 1;
  1628. if (-f $warnings_file) {
  1629. open(IN, $warnings_file) or
  1630. dodie "Error opening $warnings_file";
  1631. while (<IN>) {
  1632. if (/$check_build_re/) {
  1633. my $warning = process_warning_line $_;
  1634. $warnings_list{$warning} = 1;
  1635. }
  1636. }
  1637. close(IN);
  1638. }
  1639. # If warnings file didn't exist, and WARNINGS_FILE exist,
  1640. # then we fail on any warning!
  1641. open(IN, $buildlog) or dodie "Can't open $buildlog";
  1642. while (<IN>) {
  1643. if (/$check_build_re/) {
  1644. my $warning = process_warning_line $_;
  1645. if (!defined $warnings_list{$warning}) {
  1646. fail "New warning found (not in $warnings_file)\n$_\n";
  1647. $no_reboot = $save_no_reboot;
  1648. return 0;
  1649. }
  1650. }
  1651. }
  1652. $no_reboot = $save_no_reboot;
  1653. close(IN);
  1654. }
  1655. sub check_patch_buildlog {
  1656. my ($patch) = @_;
  1657. my @files = `git show $patch | diffstat -l`;
  1658. foreach my $file (@files) {
  1659. chomp $file;
  1660. }
  1661. open(IN, "git show $patch |") or
  1662. dodie "failed to show $patch";
  1663. while (<IN>) {
  1664. if (m,^--- a/(.*),) {
  1665. chomp $1;
  1666. $files[$#files] = $1;
  1667. }
  1668. }
  1669. close(IN);
  1670. open(IN, $buildlog) or dodie "Can't open $buildlog";
  1671. while (<IN>) {
  1672. if (/^\s*(.*?):.*(warning|error)/) {
  1673. my $err = $1;
  1674. foreach my $file (@files) {
  1675. my $fullpath = "$builddir/$file";
  1676. if ($file eq $err || $fullpath eq $err) {
  1677. fail "$file built with warnings" and return 0;
  1678. }
  1679. }
  1680. }
  1681. }
  1682. close(IN);
  1683. return 1;
  1684. }
  1685. sub apply_min_config {
  1686. my $outconfig = "$output_config.new";
  1687. # Read the config file and remove anything that
  1688. # is in the force_config hash (from minconfig and others)
  1689. # then add the force config back.
  1690. doprint "Applying minimum configurations into $output_config.new\n";
  1691. open (OUT, ">$outconfig") or
  1692. dodie "Can't create $outconfig";
  1693. if (-f $output_config) {
  1694. open (IN, $output_config) or
  1695. dodie "Failed to open $output_config";
  1696. while (<IN>) {
  1697. if (/^(# )?(CONFIG_[^\s=]*)/) {
  1698. next if (defined($force_config{$2}));
  1699. }
  1700. print OUT;
  1701. }
  1702. close IN;
  1703. }
  1704. foreach my $config (keys %force_config) {
  1705. print OUT "$force_config{$config}\n";
  1706. }
  1707. close OUT;
  1708. run_command "mv $outconfig $output_config";
  1709. }
  1710. sub make_oldconfig {
  1711. my @force_list = keys %force_config;
  1712. if ($#force_list >= 0) {
  1713. apply_min_config;
  1714. }
  1715. if (!run_command "$make olddefconfig") {
  1716. # Perhaps olddefconfig doesn't exist in this version of the kernel
  1717. # try oldnoconfig
  1718. doprint "olddefconfig failed, trying make oldnoconfig\n";
  1719. if (!run_command "$make oldnoconfig") {
  1720. doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
  1721. # try a yes '' | oldconfig
  1722. run_command "yes '' | $make oldconfig" or
  1723. dodie "failed make config oldconfig";
  1724. }
  1725. }
  1726. }
  1727. # read a config file and use this to force new configs.
  1728. sub load_force_config {
  1729. my ($config) = @_;
  1730. doprint "Loading force configs from $config\n";
  1731. open(IN, $config) or
  1732. dodie "failed to read $config";
  1733. while (<IN>) {
  1734. chomp;
  1735. if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
  1736. $force_config{$1} = $_;
  1737. } elsif (/^# (CONFIG_\S*) is not set/) {
  1738. $force_config{$1} = $_;
  1739. }
  1740. }
  1741. close IN;
  1742. }
  1743. sub build {
  1744. my ($type) = @_;
  1745. unlink $buildlog;
  1746. # Failed builds should not reboot the target
  1747. my $save_no_reboot = $no_reboot;
  1748. $no_reboot = 1;
  1749. # Calculate a new version from here.
  1750. $have_version = 0;
  1751. if (defined($pre_build)) {
  1752. my $ret = run_command $pre_build;
  1753. if (!$ret && defined($pre_build_die) &&
  1754. $pre_build_die) {
  1755. dodie "failed to pre_build\n";
  1756. }
  1757. }
  1758. if ($type =~ /^useconfig:(.*)/) {
  1759. run_command "cp $1 $output_config" or
  1760. dodie "could not copy $1 to .config";
  1761. $type = "oldconfig";
  1762. }
  1763. # old config can ask questions
  1764. if ($type eq "oldconfig") {
  1765. $type = "olddefconfig";
  1766. # allow for empty configs
  1767. run_command "touch $output_config";
  1768. if (!$noclean) {
  1769. run_command "mv $output_config $outputdir/config_temp" or
  1770. dodie "moving .config";
  1771. run_command "$make mrproper" or dodie "make mrproper";
  1772. run_command "mv $outputdir/config_temp $output_config" or
  1773. dodie "moving config_temp";
  1774. }
  1775. } elsif (!$noclean) {
  1776. unlink "$output_config";
  1777. run_command "$make mrproper" or
  1778. dodie "make mrproper";
  1779. }
  1780. # add something to distinguish this build
  1781. open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
  1782. print OUT "$localversion\n";
  1783. close(OUT);
  1784. if (defined($minconfig)) {
  1785. load_force_config($minconfig);
  1786. }
  1787. if ($type ne "olddefconfig") {
  1788. run_command "$make $type" or
  1789. dodie "failed make config";
  1790. }
  1791. # Run old config regardless, to enforce min configurations
  1792. make_oldconfig;
  1793. $redirect = "$buildlog";
  1794. my $build_ret = run_command "$make $build_options";
  1795. undef $redirect;
  1796. if (defined($post_build)) {
  1797. # Because a post build may change the kernel version
  1798. # do it now.
  1799. get_version;
  1800. my $ret = run_command $post_build;
  1801. if (!$ret && defined($post_build_die) &&
  1802. $post_build_die) {
  1803. dodie "failed to post_build\n";
  1804. }
  1805. }
  1806. if (!$build_ret) {
  1807. # bisect may need this to pass
  1808. if ($in_bisect) {
  1809. $no_reboot = $save_no_reboot;
  1810. return 0;
  1811. }
  1812. fail "failed build" and return 0;
  1813. }
  1814. $no_reboot = $save_no_reboot;
  1815. return 1;
  1816. }
  1817. sub halt {
  1818. if (!run_ssh "halt" or defined($power_off)) {
  1819. if (defined($poweroff_after_halt)) {
  1820. sleep $poweroff_after_halt;
  1821. run_command "$power_off";
  1822. }
  1823. } else {
  1824. # nope? the zap it!
  1825. run_command "$power_off";
  1826. }
  1827. }
  1828. sub success {
  1829. my ($i) = @_;
  1830. if (defined($post_test)) {
  1831. run_command $post_test;
  1832. }
  1833. $successes++;
  1834. my $name = "";
  1835. if (defined($test_name)) {
  1836. $name = " ($test_name)";
  1837. }
  1838. doprint "\n\n*******************************************\n";
  1839. doprint "*******************************************\n";
  1840. doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
  1841. doprint "*******************************************\n";
  1842. doprint "*******************************************\n";
  1843. if (defined($store_successes)) {
  1844. save_logs "success", $store_successes;
  1845. }
  1846. if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
  1847. doprint "Reboot and wait $sleep_time seconds\n";
  1848. reboot_to_good $sleep_time;
  1849. }
  1850. }
  1851. sub answer_bisect {
  1852. for (;;) {
  1853. doprint "Pass or fail? [p/f]";
  1854. my $ans = <STDIN>;
  1855. chomp $ans;
  1856. if ($ans eq "p" || $ans eq "P") {
  1857. return 1;
  1858. } elsif ($ans eq "f" || $ans eq "F") {
  1859. return 0;
  1860. } else {
  1861. print "Please answer 'P' or 'F'\n";
  1862. }
  1863. }
  1864. }
  1865. sub child_run_test {
  1866. my $failed = 0;
  1867. # child should have no power
  1868. $reboot_on_error = 0;
  1869. $poweroff_on_error = 0;
  1870. $die_on_failure = 1;
  1871. $redirect = "$testlog";
  1872. run_command $run_test or $failed = 1;
  1873. undef $redirect;
  1874. exit $failed;
  1875. }
  1876. my $child_done;
  1877. sub child_finished {
  1878. $child_done = 1;
  1879. }
  1880. sub do_run_test {
  1881. my $child_pid;
  1882. my $child_exit;
  1883. my $line;
  1884. my $full_line;
  1885. my $bug = 0;
  1886. my $bug_ignored = 0;
  1887. wait_for_monitor 1;
  1888. doprint "run test $run_test\n";
  1889. $child_done = 0;
  1890. $SIG{CHLD} = qw(child_finished);
  1891. $child_pid = fork;
  1892. child_run_test if (!$child_pid);
  1893. $full_line = "";
  1894. do {
  1895. $line = wait_for_input($monitor_fp, 1);
  1896. if (defined($line)) {
  1897. # we are not guaranteed to get a full line
  1898. $full_line .= $line;
  1899. doprint $line;
  1900. if ($full_line =~ /call trace:/i) {
  1901. if ($ignore_errors) {
  1902. $bug_ignored = 1;
  1903. } else {
  1904. $bug = 1;
  1905. }
  1906. }
  1907. if ($full_line =~ /Kernel panic -/) {
  1908. $bug = 1;
  1909. }
  1910. if ($line =~ /\n/) {
  1911. $full_line = "";
  1912. }
  1913. }
  1914. } while (!$child_done && !$bug);
  1915. if (!$bug && $bug_ignored) {
  1916. doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
  1917. }
  1918. if ($bug) {
  1919. my $failure_start = time;
  1920. my $now;
  1921. do {
  1922. $line = wait_for_input($monitor_fp, 1);
  1923. if (defined($line)) {
  1924. doprint $line;
  1925. }
  1926. $now = time;
  1927. if ($now - $failure_start >= $stop_after_failure) {
  1928. last;
  1929. }
  1930. } while (defined($line));
  1931. doprint "Detected kernel crash!\n";
  1932. # kill the child with extreme prejudice
  1933. kill 9, $child_pid;
  1934. }
  1935. waitpid $child_pid, 0;
  1936. $child_exit = $?;
  1937. if (!$bug && $in_bisect) {
  1938. if (defined($bisect_ret_good)) {
  1939. if ($child_exit == $bisect_ret_good) {
  1940. return 1;
  1941. }
  1942. }
  1943. if (defined($bisect_ret_skip)) {
  1944. if ($child_exit == $bisect_ret_skip) {
  1945. return -1;
  1946. }
  1947. }
  1948. if (defined($bisect_ret_abort)) {
  1949. if ($child_exit == $bisect_ret_abort) {
  1950. fail "test abort" and return -2;
  1951. }
  1952. }
  1953. if (defined($bisect_ret_bad)) {
  1954. if ($child_exit == $bisect_ret_skip) {
  1955. return 0;
  1956. }
  1957. }
  1958. if (defined($bisect_ret_default)) {
  1959. if ($bisect_ret_default eq "good") {
  1960. return 1;
  1961. } elsif ($bisect_ret_default eq "bad") {
  1962. return 0;
  1963. } elsif ($bisect_ret_default eq "skip") {
  1964. return -1;
  1965. } elsif ($bisect_ret_default eq "abort") {
  1966. return -2;
  1967. } else {
  1968. fail "unknown default action: $bisect_ret_default"
  1969. and return -2;
  1970. }
  1971. }
  1972. }
  1973. if ($bug || $child_exit) {
  1974. return 0 if $in_bisect;
  1975. fail "test failed" and return 0;
  1976. }
  1977. return 1;
  1978. }
  1979. sub run_git_bisect {
  1980. my ($command) = @_;
  1981. doprint "$command ... ";
  1982. my $output = `$command 2>&1`;
  1983. my $ret = $?;
  1984. logit $output;
  1985. if ($ret) {
  1986. doprint "FAILED\n";
  1987. dodie "Failed to git bisect";
  1988. }
  1989. doprint "SUCCESS\n";
  1990. if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
  1991. doprint "$1 [$2]\n";
  1992. } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
  1993. $bisect_bad_commit = $1;
  1994. doprint "Found bad commit... $1\n";
  1995. return 0;
  1996. } else {
  1997. # we already logged it, just print it now.
  1998. print $output;
  1999. }
  2000. return 1;
  2001. }
  2002. sub bisect_reboot {
  2003. doprint "Reboot and sleep $bisect_sleep_time seconds\n";
  2004. reboot_to_good $bisect_sleep_time;
  2005. }
  2006. # returns 1 on success, 0 on failure, -1 on skip
  2007. sub run_bisect_test {
  2008. my ($type, $buildtype) = @_;
  2009. my $failed = 0;
  2010. my $result;
  2011. my $output;
  2012. my $ret;
  2013. $in_bisect = 1;
  2014. build $buildtype or $failed = 1;
  2015. if ($type ne "build") {
  2016. if ($failed && $bisect_skip) {
  2017. $in_bisect = 0;
  2018. return -1;
  2019. }
  2020. dodie "Failed on build" if $failed;
  2021. # Now boot the box
  2022. start_monitor_and_boot or $failed = 1;
  2023. if ($type ne "boot") {
  2024. if ($failed && $bisect_skip) {
  2025. end_monitor;
  2026. bisect_reboot;
  2027. $in_bisect = 0;
  2028. return -1;
  2029. }
  2030. dodie "Failed on boot" if $failed;
  2031. do_run_test or $failed = 1;
  2032. }
  2033. end_monitor;
  2034. }
  2035. if ($failed) {
  2036. $result = 0;
  2037. } else {
  2038. $result = 1;
  2039. }
  2040. # reboot the box to a kernel we can ssh to
  2041. if ($type ne "build") {
  2042. bisect_reboot;
  2043. }
  2044. $in_bisect = 0;
  2045. return $result;
  2046. }
  2047. sub run_bisect {
  2048. my ($type) = @_;
  2049. my $buildtype = "oldconfig";
  2050. # We should have a minconfig to use?
  2051. if (defined($minconfig)) {
  2052. $buildtype = "useconfig:$minconfig";
  2053. }
  2054. my $ret = run_bisect_test $type, $buildtype;
  2055. if ($bisect_manual) {
  2056. $ret = answer_bisect;
  2057. }
  2058. # Are we looking for where it worked, not failed?
  2059. if ($reverse_bisect && $ret >= 0) {
  2060. $ret = !$ret;
  2061. }
  2062. if ($ret > 0) {
  2063. return "good";
  2064. } elsif ($ret == 0) {
  2065. return "bad";
  2066. } elsif ($bisect_skip) {
  2067. doprint "HIT A BAD COMMIT ... SKIPPING\n";
  2068. return "skip";
  2069. }
  2070. }
  2071. sub update_bisect_replay {
  2072. my $tmp_log = "$tmpdir/ktest_bisect_log";
  2073. run_command "git bisect log > $tmp_log" or
  2074. die "can't create bisect log";
  2075. return $tmp_log;
  2076. }
  2077. sub bisect {
  2078. my ($i) = @_;
  2079. my $result;
  2080. die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
  2081. die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
  2082. die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
  2083. my $good = $bisect_good;
  2084. my $bad = $bisect_bad;
  2085. my $type = $bisect_type;
  2086. my $start = $bisect_start;
  2087. my $replay = $bisect_replay;
  2088. my $start_files = $bisect_files;
  2089. if (defined($start_files)) {
  2090. $start_files = " -- " . $start_files;
  2091. } else {
  2092. $start_files = "";
  2093. }
  2094. # convert to true sha1's
  2095. $good = get_sha1($good);
  2096. $bad = get_sha1($bad);
  2097. if (defined($bisect_reverse) && $bisect_reverse == 1) {
  2098. doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
  2099. $reverse_bisect = 1;
  2100. } else {
  2101. $reverse_bisect = 0;
  2102. }
  2103. # Can't have a test without having a test to run
  2104. if ($type eq "test" && !defined($run_test)) {
  2105. $type = "boot";
  2106. }
  2107. # Check if a bisect was running
  2108. my $bisect_start_file = "$builddir/.git/BISECT_START";
  2109. my $check = $bisect_check;
  2110. my $do_check = defined($check) && $check ne "0";
  2111. if ( -f $bisect_start_file ) {
  2112. print "Bisect in progress found\n";
  2113. if ($do_check) {
  2114. print " If you say yes, then no checks of good or bad will be done\n";
  2115. }
  2116. if (defined($replay)) {
  2117. print "** BISECT_REPLAY is defined in config file **";
  2118. print " Ignore config option and perform new git bisect log?\n";
  2119. if (read_ync " (yes, no, or cancel) ") {
  2120. $replay = update_bisect_replay;
  2121. $do_check = 0;
  2122. }
  2123. } elsif (read_yn "read git log and continue?") {
  2124. $replay = update_bisect_replay;
  2125. $do_check = 0;
  2126. }
  2127. }
  2128. if ($do_check) {
  2129. # get current HEAD
  2130. my $head = get_sha1("HEAD");
  2131. if ($check ne "good") {
  2132. doprint "TESTING BISECT BAD [$bad]\n";
  2133. run_command "git checkout $bad" or
  2134. die "Failed to checkout $bad";
  2135. $result = run_bisect $type;
  2136. if ($result ne "bad") {
  2137. fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
  2138. }
  2139. }
  2140. if ($check ne "bad") {
  2141. doprint "TESTING BISECT GOOD [$good]\n";
  2142. run_command "git checkout $good" or
  2143. die "Failed to checkout $good";
  2144. $result = run_bisect $type;
  2145. if ($result ne "good") {
  2146. fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
  2147. }
  2148. }
  2149. # checkout where we started
  2150. run_command "git checkout $head" or
  2151. die "Failed to checkout $head";
  2152. }
  2153. run_command "git bisect start$start_files" or
  2154. dodie "could not start bisect";
  2155. run_command "git bisect good $good" or
  2156. dodie "could not set bisect good to $good";
  2157. run_git_bisect "git bisect bad $bad" or
  2158. dodie "could not set bisect bad to $bad";
  2159. if (defined($replay)) {
  2160. run_command "git bisect replay $replay" or
  2161. dodie "failed to run replay";
  2162. }
  2163. if (defined($start)) {
  2164. run_command "git checkout $start" or
  2165. dodie "failed to checkout $start";
  2166. }
  2167. my $test;
  2168. do {
  2169. $result = run_bisect $type;
  2170. $test = run_git_bisect "git bisect $result";
  2171. } while ($test);
  2172. run_command "git bisect log" or
  2173. dodie "could not capture git bisect log";
  2174. run_command "git bisect reset" or
  2175. dodie "could not reset git bisect";
  2176. doprint "Bad commit was [$bisect_bad_commit]\n";
  2177. success $i;
  2178. }
  2179. # config_ignore holds the configs that were set (or unset) for
  2180. # a good config and we will ignore these configs for the rest
  2181. # of a config bisect. These configs stay as they were.
  2182. my %config_ignore;
  2183. # config_set holds what all configs were set as.
  2184. my %config_set;
  2185. # config_off holds the set of configs that the bad config had disabled.
  2186. # We need to record them and set them in the .config when running
  2187. # olddefconfig, because olddefconfig keeps the defaults.
  2188. my %config_off;
  2189. # config_off_tmp holds a set of configs to turn off for now
  2190. my @config_off_tmp;
  2191. # config_list is the set of configs that are being tested
  2192. my %config_list;
  2193. my %null_config;
  2194. my %dependency;
  2195. sub assign_configs {
  2196. my ($hash, $config) = @_;
  2197. open (IN, $config)
  2198. or dodie "Failed to read $config";
  2199. while (<IN>) {
  2200. if (/^((CONFIG\S*)=.*)/) {
  2201. ${$hash}{$2} = $1;
  2202. }
  2203. }
  2204. close(IN);
  2205. }
  2206. sub process_config_ignore {
  2207. my ($config) = @_;
  2208. assign_configs \%config_ignore, $config;
  2209. }
  2210. sub read_current_config {
  2211. my ($config_ref) = @_;
  2212. %{$config_ref} = ();
  2213. undef %{$config_ref};
  2214. my @key = keys %{$config_ref};
  2215. if ($#key >= 0) {
  2216. print "did not delete!\n";
  2217. exit;
  2218. }
  2219. open (IN, "$output_config");
  2220. while (<IN>) {
  2221. if (/^(CONFIG\S+)=(.*)/) {
  2222. ${$config_ref}{$1} = $2;
  2223. }
  2224. }
  2225. close(IN);
  2226. }
  2227. sub get_dependencies {
  2228. my ($config) = @_;
  2229. my $arr = $dependency{$config};
  2230. if (!defined($arr)) {
  2231. return ();
  2232. }
  2233. my @deps = @{$arr};
  2234. foreach my $dep (@{$arr}) {
  2235. print "ADD DEP $dep\n";
  2236. @deps = (@deps, get_dependencies $dep);
  2237. }
  2238. return @deps;
  2239. }
  2240. sub create_config {
  2241. my @configs = @_;
  2242. open(OUT, ">$output_config") or dodie "Can not write to $output_config";
  2243. foreach my $config (@configs) {
  2244. print OUT "$config_set{$config}\n";
  2245. my @deps = get_dependencies $config;
  2246. foreach my $dep (@deps) {
  2247. print OUT "$config_set{$dep}\n";
  2248. }
  2249. }
  2250. # turn off configs to keep off
  2251. foreach my $config (keys %config_off) {
  2252. print OUT "# $config is not set\n";
  2253. }
  2254. # turn off configs that should be off for now
  2255. foreach my $config (@config_off_tmp) {
  2256. print OUT "# $config is not set\n";
  2257. }
  2258. foreach my $config (keys %config_ignore) {
  2259. print OUT "$config_ignore{$config}\n";
  2260. }
  2261. close(OUT);
  2262. make_oldconfig;
  2263. }
  2264. sub compare_configs {
  2265. my (%a, %b) = @_;
  2266. foreach my $item (keys %a) {
  2267. if (!defined($b{$item})) {
  2268. print "diff $item\n";
  2269. return 1;
  2270. }
  2271. delete $b{$item};
  2272. }
  2273. my @keys = keys %b;
  2274. if ($#keys) {
  2275. print "diff2 $keys[0]\n";
  2276. }
  2277. return -1 if ($#keys >= 0);
  2278. return 0;
  2279. }
  2280. sub run_config_bisect_test {
  2281. my ($type) = @_;
  2282. return run_bisect_test $type, "oldconfig";
  2283. }
  2284. sub process_passed {
  2285. my (%configs) = @_;
  2286. doprint "These configs had no failure: (Enabling them for further compiles)\n";
  2287. # Passed! All these configs are part of a good compile.
  2288. # Add them to the min options.
  2289. foreach my $config (keys %configs) {
  2290. if (defined($config_list{$config})) {
  2291. doprint " removing $config\n";
  2292. $config_ignore{$config} = $config_list{$config};
  2293. delete $config_list{$config};
  2294. }
  2295. }
  2296. doprint "config copied to $outputdir/config_good\n";
  2297. run_command "cp -f $output_config $outputdir/config_good";
  2298. }
  2299. sub process_failed {
  2300. my ($config) = @_;
  2301. doprint "\n\n***************************************\n";
  2302. doprint "Found bad config: $config\n";
  2303. doprint "***************************************\n\n";
  2304. }
  2305. sub run_config_bisect {
  2306. my @start_list = keys %config_list;
  2307. if ($#start_list < 0) {
  2308. doprint "No more configs to test!!!\n";
  2309. return -1;
  2310. }
  2311. doprint "***** RUN TEST ***\n";
  2312. my $type = $config_bisect_type;
  2313. my $ret;
  2314. my %current_config;
  2315. my $count = $#start_list + 1;
  2316. doprint " $count configs to test\n";
  2317. my $half = int($#start_list / 2);
  2318. do {
  2319. my @tophalf = @start_list[0 .. $half];
  2320. # keep the bottom half off
  2321. if ($half < $#start_list) {
  2322. @config_off_tmp = @start_list[$half + 1 .. $#start_list];
  2323. } else {
  2324. @config_off_tmp = ();
  2325. }
  2326. create_config @tophalf;
  2327. read_current_config \%current_config;
  2328. $count = $#tophalf + 1;
  2329. doprint "Testing $count configs\n";
  2330. my $found = 0;
  2331. # make sure we test something
  2332. foreach my $config (@tophalf) {
  2333. if (defined($current_config{$config})) {
  2334. logit " $config\n";
  2335. $found = 1;
  2336. }
  2337. }
  2338. if (!$found) {
  2339. # try the other half
  2340. doprint "Top half produced no set configs, trying bottom half\n";
  2341. # keep the top half off
  2342. @config_off_tmp = @tophalf;
  2343. @tophalf = @start_list[$half + 1 .. $#start_list];
  2344. create_config @tophalf;
  2345. read_current_config \%current_config;
  2346. foreach my $config (@tophalf) {
  2347. if (defined($current_config{$config})) {
  2348. logit " $config\n";
  2349. $found = 1;
  2350. }
  2351. }
  2352. if (!$found) {
  2353. doprint "Failed: Can't make new config with current configs\n";
  2354. foreach my $config (@start_list) {
  2355. doprint " CONFIG: $config\n";
  2356. }
  2357. return -1;
  2358. }
  2359. $count = $#tophalf + 1;
  2360. doprint "Testing $count configs\n";
  2361. }
  2362. $ret = run_config_bisect_test $type;
  2363. if ($bisect_manual) {
  2364. $ret = answer_bisect;
  2365. }
  2366. if ($ret) {
  2367. process_passed %current_config;
  2368. return 0;
  2369. }
  2370. doprint "This config had a failure.\n";
  2371. doprint "Removing these configs that were not set in this config:\n";
  2372. doprint "config copied to $outputdir/config_bad\n";
  2373. run_command "cp -f $output_config $outputdir/config_bad";
  2374. # A config exists in this group that was bad.
  2375. foreach my $config (keys %config_list) {
  2376. if (!defined($current_config{$config})) {
  2377. doprint " removing $config\n";
  2378. delete $config_list{$config};
  2379. }
  2380. }
  2381. @start_list = @tophalf;
  2382. if ($#start_list == 0) {
  2383. process_failed $start_list[0];
  2384. return 1;
  2385. }
  2386. # remove half the configs we are looking at and see if
  2387. # they are good.
  2388. $half = int($#start_list / 2);
  2389. } while ($#start_list > 0);
  2390. # we found a single config, try it again unless we are running manually
  2391. if ($bisect_manual) {
  2392. process_failed $start_list[0];
  2393. return 1;
  2394. }
  2395. my @tophalf = @start_list[0 .. 0];
  2396. $ret = run_config_bisect_test $type;
  2397. if ($ret) {
  2398. process_passed %current_config;
  2399. return 0;
  2400. }
  2401. process_failed $start_list[0];
  2402. return 1;
  2403. }
  2404. sub config_bisect {
  2405. my ($i) = @_;
  2406. my $start_config = $config_bisect;
  2407. my $tmpconfig = "$tmpdir/use_config";
  2408. if (defined($config_bisect_good)) {
  2409. process_config_ignore $config_bisect_good;
  2410. }
  2411. # Make the file with the bad config and the min config
  2412. if (defined($minconfig)) {
  2413. # read the min config for things to ignore
  2414. run_command "cp $minconfig $tmpconfig" or
  2415. dodie "failed to copy $minconfig to $tmpconfig";
  2416. } else {
  2417. unlink $tmpconfig;
  2418. }
  2419. if (-f $tmpconfig) {
  2420. load_force_config($tmpconfig);
  2421. process_config_ignore $tmpconfig;
  2422. }
  2423. # now process the start config
  2424. run_command "cp $start_config $output_config" or
  2425. dodie "failed to copy $start_config to $output_config";
  2426. # read directly what we want to check
  2427. my %config_check;
  2428. open (IN, $output_config)
  2429. or dodie "failed to open $output_config";
  2430. while (<IN>) {
  2431. if (/^((CONFIG\S*)=.*)/) {
  2432. $config_check{$2} = $1;
  2433. }
  2434. }
  2435. close(IN);
  2436. # Now run oldconfig with the minconfig
  2437. make_oldconfig;
  2438. # check to see what we lost (or gained)
  2439. open (IN, $output_config)
  2440. or dodie "Failed to read $start_config";
  2441. my %removed_configs;
  2442. my %added_configs;
  2443. while (<IN>) {
  2444. if (/^((CONFIG\S*)=.*)/) {
  2445. # save off all options
  2446. $config_set{$2} = $1;
  2447. if (defined($config_check{$2})) {
  2448. if (defined($config_ignore{$2})) {
  2449. $removed_configs{$2} = $1;
  2450. } else {
  2451. $config_list{$2} = $1;
  2452. }
  2453. } elsif (!defined($config_ignore{$2})) {
  2454. $added_configs{$2} = $1;
  2455. $config_list{$2} = $1;
  2456. }
  2457. } elsif (/^# ((CONFIG\S*).*)/) {
  2458. # Keep these configs disabled
  2459. $config_set{$2} = $1;
  2460. $config_off{$2} = $1;
  2461. }
  2462. }
  2463. close(IN);
  2464. my @confs = keys %removed_configs;
  2465. if ($#confs >= 0) {
  2466. doprint "Configs overridden by default configs and removed from check:\n";
  2467. foreach my $config (@confs) {
  2468. doprint " $config\n";
  2469. }
  2470. }
  2471. @confs = keys %added_configs;
  2472. if ($#confs >= 0) {
  2473. doprint "Configs appearing in make oldconfig and added:\n";
  2474. foreach my $config (@confs) {
  2475. doprint " $config\n";
  2476. }
  2477. }
  2478. my %config_test;
  2479. my $once = 0;
  2480. @config_off_tmp = ();
  2481. # Sometimes kconfig does weird things. We must make sure
  2482. # that the config we autocreate has everything we need
  2483. # to test, otherwise we may miss testing configs, or
  2484. # may not be able to create a new config.
  2485. # Here we create a config with everything set.
  2486. create_config (keys %config_list);
  2487. read_current_config \%config_test;
  2488. foreach my $config (keys %config_list) {
  2489. if (!defined($config_test{$config})) {
  2490. if (!$once) {
  2491. $once = 1;
  2492. doprint "Configs not produced by kconfig (will not be checked):\n";
  2493. }
  2494. doprint " $config\n";
  2495. delete $config_list{$config};
  2496. }
  2497. }
  2498. my $ret;
  2499. if (defined($config_bisect_check) && $config_bisect_check) {
  2500. doprint " Checking to make sure bad config with min config fails\n";
  2501. create_config keys %config_list;
  2502. $ret = run_config_bisect_test $config_bisect_type;
  2503. if ($ret) {
  2504. doprint " FAILED! Bad config with min config boots fine\n";
  2505. return -1;
  2506. }
  2507. doprint " Bad config with min config fails as expected\n";
  2508. }
  2509. do {
  2510. $ret = run_config_bisect;
  2511. } while (!$ret);
  2512. return $ret if ($ret < 0);
  2513. success $i;
  2514. }
  2515. sub patchcheck_reboot {
  2516. doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
  2517. reboot_to_good $patchcheck_sleep_time;
  2518. }
  2519. sub patchcheck {
  2520. my ($i) = @_;
  2521. die "PATCHCHECK_START[$i] not defined\n"
  2522. if (!defined($patchcheck_start));
  2523. die "PATCHCHECK_TYPE[$i] not defined\n"
  2524. if (!defined($patchcheck_type));
  2525. my $start = $patchcheck_start;
  2526. my $end = "HEAD";
  2527. if (defined($patchcheck_end)) {
  2528. $end = $patchcheck_end;
  2529. }
  2530. # Get the true sha1's since we can use things like HEAD~3
  2531. $start = get_sha1($start);
  2532. $end = get_sha1($end);
  2533. my $type = $patchcheck_type;
  2534. # Can't have a test without having a test to run
  2535. if ($type eq "test" && !defined($run_test)) {
  2536. $type = "boot";
  2537. }
  2538. open (IN, "git log --pretty=oneline $end|") or
  2539. dodie "could not get git list";
  2540. my @list;
  2541. while (<IN>) {
  2542. chomp;
  2543. $list[$#list+1] = $_;
  2544. last if (/^$start/);
  2545. }
  2546. close(IN);
  2547. if ($list[$#list] !~ /^$start/) {
  2548. fail "SHA1 $start not found";
  2549. }
  2550. # go backwards in the list
  2551. @list = reverse @list;
  2552. my $save_clean = $noclean;
  2553. my %ignored_warnings;
  2554. if (defined($ignore_warnings)) {
  2555. foreach my $sha1 (split /\s+/, $ignore_warnings) {
  2556. $ignored_warnings{$sha1} = 1;
  2557. }
  2558. }
  2559. $in_patchcheck = 1;
  2560. foreach my $item (@list) {
  2561. my $sha1 = $item;
  2562. $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
  2563. doprint "\nProcessing commit $item\n\n";
  2564. run_command "git checkout $sha1" or
  2565. die "Failed to checkout $sha1";
  2566. # only clean on the first and last patch
  2567. if ($item eq $list[0] ||
  2568. $item eq $list[$#list]) {
  2569. $noclean = $save_clean;
  2570. } else {
  2571. $noclean = 1;
  2572. }
  2573. if (defined($minconfig)) {
  2574. build "useconfig:$minconfig" or return 0;
  2575. } else {
  2576. # ?? no config to use?
  2577. build "oldconfig" or return 0;
  2578. }
  2579. # No need to do per patch checking if warnings file exists
  2580. if (!defined($warnings_file) && !defined($ignored_warnings{$sha1})) {
  2581. check_patch_buildlog $sha1 or return 0;
  2582. }
  2583. check_buildlog or return 0;
  2584. next if ($type eq "build");
  2585. my $failed = 0;
  2586. start_monitor_and_boot or $failed = 1;
  2587. if (!$failed && $type ne "boot"){
  2588. do_run_test or $failed = 1;
  2589. }
  2590. end_monitor;
  2591. return 0 if ($failed);
  2592. patchcheck_reboot;
  2593. }
  2594. $in_patchcheck = 0;
  2595. success $i;
  2596. return 1;
  2597. }
  2598. my %depends;
  2599. my %depcount;
  2600. my $iflevel = 0;
  2601. my @ifdeps;
  2602. # prevent recursion
  2603. my %read_kconfigs;
  2604. sub add_dep {
  2605. # $config depends on $dep
  2606. my ($config, $dep) = @_;
  2607. if (defined($depends{$config})) {
  2608. $depends{$config} .= " " . $dep;
  2609. } else {
  2610. $depends{$config} = $dep;
  2611. }
  2612. # record the number of configs depending on $dep
  2613. if (defined $depcount{$dep}) {
  2614. $depcount{$dep}++;
  2615. } else {
  2616. $depcount{$dep} = 1;
  2617. }
  2618. }
  2619. # taken from streamline_config.pl
  2620. sub read_kconfig {
  2621. my ($kconfig) = @_;
  2622. my $state = "NONE";
  2623. my $config;
  2624. my @kconfigs;
  2625. my $cont = 0;
  2626. my $line;
  2627. if (! -f $kconfig) {
  2628. doprint "file $kconfig does not exist, skipping\n";
  2629. return;
  2630. }
  2631. open(KIN, "$kconfig")
  2632. or die "Can't open $kconfig";
  2633. while (<KIN>) {
  2634. chomp;
  2635. # Make sure that lines ending with \ continue
  2636. if ($cont) {
  2637. $_ = $line . " " . $_;
  2638. }
  2639. if (s/\\$//) {
  2640. $cont = 1;
  2641. $line = $_;
  2642. next;
  2643. }
  2644. $cont = 0;
  2645. # collect any Kconfig sources
  2646. if (/^source\s*"(.*)"/) {
  2647. $kconfigs[$#kconfigs+1] = $1;
  2648. }
  2649. # configs found
  2650. if (/^\s*(menu)?config\s+(\S+)\s*$/) {
  2651. $state = "NEW";
  2652. $config = $2;
  2653. for (my $i = 0; $i < $iflevel; $i++) {
  2654. add_dep $config, $ifdeps[$i];
  2655. }
  2656. # collect the depends for the config
  2657. } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
  2658. add_dep $config, $1;
  2659. # Get the configs that select this config
  2660. } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
  2661. # selected by depends on config
  2662. add_dep $1, $config;
  2663. # Check for if statements
  2664. } elsif (/^if\s+(.*\S)\s*$/) {
  2665. my $deps = $1;
  2666. # remove beginning and ending non text
  2667. $deps =~ s/^[^a-zA-Z0-9_]*//;
  2668. $deps =~ s/[^a-zA-Z0-9_]*$//;
  2669. my @deps = split /[^a-zA-Z0-9_]+/, $deps;
  2670. $ifdeps[$iflevel++] = join ':', @deps;
  2671. } elsif (/^endif/) {
  2672. $iflevel-- if ($iflevel);
  2673. # stop on "help"
  2674. } elsif (/^\s*help\s*$/) {
  2675. $state = "NONE";
  2676. }
  2677. }
  2678. close(KIN);
  2679. # read in any configs that were found.
  2680. foreach $kconfig (@kconfigs) {
  2681. if (!defined($read_kconfigs{$kconfig})) {
  2682. $read_kconfigs{$kconfig} = 1;
  2683. read_kconfig("$builddir/$kconfig");
  2684. }
  2685. }
  2686. }
  2687. sub read_depends {
  2688. # find out which arch this is by the kconfig file
  2689. open (IN, $output_config)
  2690. or dodie "Failed to read $output_config";
  2691. my $arch;
  2692. while (<IN>) {
  2693. if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
  2694. $arch = $1;
  2695. last;
  2696. }
  2697. }
  2698. close IN;
  2699. if (!defined($arch)) {
  2700. doprint "Could not find arch from config file\n";
  2701. doprint "no dependencies used\n";
  2702. return;
  2703. }
  2704. # arch is really the subarch, we need to know
  2705. # what directory to look at.
  2706. if ($arch eq "i386" || $arch eq "x86_64") {
  2707. $arch = "x86";
  2708. } elsif ($arch =~ /^tile/) {
  2709. $arch = "tile";
  2710. }
  2711. my $kconfig = "$builddir/arch/$arch/Kconfig";
  2712. if (! -f $kconfig && $arch =~ /\d$/) {
  2713. my $orig = $arch;
  2714. # some subarchs have numbers, truncate them
  2715. $arch =~ s/\d*$//;
  2716. $kconfig = "$builddir/arch/$arch/Kconfig";
  2717. if (! -f $kconfig) {
  2718. doprint "No idea what arch dir $orig is for\n";
  2719. doprint "no dependencies used\n";
  2720. return;
  2721. }
  2722. }
  2723. read_kconfig($kconfig);
  2724. }
  2725. sub read_config_list {
  2726. my ($config) = @_;
  2727. open (IN, $config)
  2728. or dodie "Failed to read $config";
  2729. while (<IN>) {
  2730. if (/^((CONFIG\S*)=.*)/) {
  2731. if (!defined($config_ignore{$2})) {
  2732. $config_list{$2} = $1;
  2733. }
  2734. }
  2735. }
  2736. close(IN);
  2737. }
  2738. sub read_output_config {
  2739. my ($config) = @_;
  2740. assign_configs \%config_ignore, $config;
  2741. }
  2742. sub make_new_config {
  2743. my @configs = @_;
  2744. open (OUT, ">$output_config")
  2745. or dodie "Failed to write $output_config";
  2746. foreach my $config (@configs) {
  2747. print OUT "$config\n";
  2748. }
  2749. close OUT;
  2750. }
  2751. sub chomp_config {
  2752. my ($config) = @_;
  2753. $config =~ s/CONFIG_//;
  2754. return $config;
  2755. }
  2756. sub get_depends {
  2757. my ($dep) = @_;
  2758. my $kconfig = chomp_config $dep;
  2759. $dep = $depends{"$kconfig"};
  2760. # the dep string we have saves the dependencies as they
  2761. # were found, including expressions like ! && ||. We
  2762. # want to split this out into just an array of configs.
  2763. my $valid = "A-Za-z_0-9";
  2764. my @configs;
  2765. while ($dep =~ /[$valid]/) {
  2766. if ($dep =~ /^[^$valid]*([$valid]+)/) {
  2767. my $conf = "CONFIG_" . $1;
  2768. $configs[$#configs + 1] = $conf;
  2769. $dep =~ s/^[^$valid]*[$valid]+//;
  2770. } else {
  2771. die "this should never happen";
  2772. }
  2773. }
  2774. return @configs;
  2775. }
  2776. my %min_configs;
  2777. my %keep_configs;
  2778. my %save_configs;
  2779. my %processed_configs;
  2780. my %nochange_config;
  2781. sub test_this_config {
  2782. my ($config) = @_;
  2783. my $found;
  2784. # if we already processed this config, skip it
  2785. if (defined($processed_configs{$config})) {
  2786. return undef;
  2787. }
  2788. $processed_configs{$config} = 1;
  2789. # if this config failed during this round, skip it
  2790. if (defined($nochange_config{$config})) {
  2791. return undef;
  2792. }
  2793. my $kconfig = chomp_config $config;
  2794. # Test dependencies first
  2795. if (defined($depends{"$kconfig"})) {
  2796. my @parents = get_depends $config;
  2797. foreach my $parent (@parents) {
  2798. # if the parent is in the min config, check it first
  2799. next if (!defined($min_configs{$parent}));
  2800. $found = test_this_config($parent);
  2801. if (defined($found)) {
  2802. return $found;
  2803. }
  2804. }
  2805. }
  2806. # Remove this config from the list of configs
  2807. # do a make olddefconfig and then read the resulting
  2808. # .config to make sure it is missing the config that
  2809. # we had before
  2810. my %configs = %min_configs;
  2811. delete $configs{$config};
  2812. make_new_config ((values %configs), (values %keep_configs));
  2813. make_oldconfig;
  2814. undef %configs;
  2815. assign_configs \%configs, $output_config;
  2816. return $config if (!defined($configs{$config}));
  2817. doprint "disabling config $config did not change .config\n";
  2818. $nochange_config{$config} = 1;
  2819. return undef;
  2820. }
  2821. sub make_min_config {
  2822. my ($i) = @_;
  2823. my $type = $minconfig_type;
  2824. if ($type ne "boot" && $type ne "test") {
  2825. fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
  2826. " make_min_config works only with 'boot' and 'test'\n" and return;
  2827. }
  2828. if (!defined($output_minconfig)) {
  2829. fail "OUTPUT_MIN_CONFIG not defined" and return;
  2830. }
  2831. # If output_minconfig exists, and the start_minconfig
  2832. # came from min_config, than ask if we should use
  2833. # that instead.
  2834. if (-f $output_minconfig && !$start_minconfig_defined) {
  2835. print "$output_minconfig exists\n";
  2836. if (!defined($use_output_minconfig)) {
  2837. if (read_yn " Use it as minconfig?") {
  2838. $start_minconfig = $output_minconfig;
  2839. }
  2840. } elsif ($use_output_minconfig > 0) {
  2841. doprint "Using $output_minconfig as MIN_CONFIG\n";
  2842. $start_minconfig = $output_minconfig;
  2843. } else {
  2844. doprint "Set to still use MIN_CONFIG as starting point\n";
  2845. }
  2846. }
  2847. if (!defined($start_minconfig)) {
  2848. fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
  2849. }
  2850. my $temp_config = "$tmpdir/temp_config";
  2851. # First things first. We build an allnoconfig to find
  2852. # out what the defaults are that we can't touch.
  2853. # Some are selections, but we really can't handle selections.
  2854. my $save_minconfig = $minconfig;
  2855. undef $minconfig;
  2856. run_command "$make allnoconfig" or return 0;
  2857. read_depends;
  2858. process_config_ignore $output_config;
  2859. undef %save_configs;
  2860. undef %min_configs;
  2861. if (defined($ignore_config)) {
  2862. # make sure the file exists
  2863. `touch $ignore_config`;
  2864. assign_configs \%save_configs, $ignore_config;
  2865. }
  2866. %keep_configs = %save_configs;
  2867. doprint "Load initial configs from $start_minconfig\n";
  2868. # Look at the current min configs, and save off all the
  2869. # ones that were set via the allnoconfig
  2870. assign_configs \%min_configs, $start_minconfig;
  2871. my @config_keys = keys %min_configs;
  2872. # All configs need a depcount
  2873. foreach my $config (@config_keys) {
  2874. my $kconfig = chomp_config $config;
  2875. if (!defined $depcount{$kconfig}) {
  2876. $depcount{$kconfig} = 0;
  2877. }
  2878. }
  2879. # Remove anything that was set by the make allnoconfig
  2880. # we shouldn't need them as they get set for us anyway.
  2881. foreach my $config (@config_keys) {
  2882. # Remove anything in the ignore_config
  2883. if (defined($keep_configs{$config})) {
  2884. my $file = $ignore_config;
  2885. $file =~ s,.*/(.*?)$,$1,;
  2886. doprint "$config set by $file ... ignored\n";
  2887. delete $min_configs{$config};
  2888. next;
  2889. }
  2890. # But make sure the settings are the same. If a min config
  2891. # sets a selection, we do not want to get rid of it if
  2892. # it is not the same as what we have. Just move it into
  2893. # the keep configs.
  2894. if (defined($config_ignore{$config})) {
  2895. if ($config_ignore{$config} ne $min_configs{$config}) {
  2896. doprint "$config is in allnoconfig as '$config_ignore{$config}'";
  2897. doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
  2898. $keep_configs{$config} = $min_configs{$config};
  2899. } else {
  2900. doprint "$config set by allnoconfig ... ignored\n";
  2901. }
  2902. delete $min_configs{$config};
  2903. }
  2904. }
  2905. my $done = 0;
  2906. my $take_two = 0;
  2907. while (!$done) {
  2908. my $config;
  2909. my $found;
  2910. # Now disable each config one by one and do a make oldconfig
  2911. # till we find a config that changes our list.
  2912. my @test_configs = keys %min_configs;
  2913. # Sort keys by who is most dependent on
  2914. @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
  2915. @test_configs ;
  2916. # Put configs that did not modify the config at the end.
  2917. my $reset = 1;
  2918. for (my $i = 0; $i < $#test_configs; $i++) {
  2919. if (!defined($nochange_config{$test_configs[0]})) {
  2920. $reset = 0;
  2921. last;
  2922. }
  2923. # This config didn't change the .config last time.
  2924. # Place it at the end
  2925. my $config = shift @test_configs;
  2926. push @test_configs, $config;
  2927. }
  2928. # if every test config has failed to modify the .config file
  2929. # in the past, then reset and start over.
  2930. if ($reset) {
  2931. undef %nochange_config;
  2932. }
  2933. undef %processed_configs;
  2934. foreach my $config (@test_configs) {
  2935. $found = test_this_config $config;
  2936. last if (defined($found));
  2937. # oh well, try another config
  2938. }
  2939. if (!defined($found)) {
  2940. # we could have failed due to the nochange_config hash
  2941. # reset and try again
  2942. if (!$take_two) {
  2943. undef %nochange_config;
  2944. $take_two = 1;
  2945. next;
  2946. }
  2947. doprint "No more configs found that we can disable\n";
  2948. $done = 1;
  2949. last;
  2950. }
  2951. $take_two = 0;
  2952. $config = $found;
  2953. doprint "Test with $config disabled\n";
  2954. # set in_bisect to keep build and monitor from dieing
  2955. $in_bisect = 1;
  2956. my $failed = 0;
  2957. build "oldconfig" or $failed = 1;
  2958. if (!$failed) {
  2959. start_monitor_and_boot or $failed = 1;
  2960. if ($type eq "test" && !$failed) {
  2961. do_run_test or $failed = 1;
  2962. }
  2963. end_monitor;
  2964. }
  2965. $in_bisect = 0;
  2966. if ($failed) {
  2967. doprint "$min_configs{$config} is needed to boot the box... keeping\n";
  2968. # this config is needed, add it to the ignore list.
  2969. $keep_configs{$config} = $min_configs{$config};
  2970. $save_configs{$config} = $min_configs{$config};
  2971. delete $min_configs{$config};
  2972. # update new ignore configs
  2973. if (defined($ignore_config)) {
  2974. open (OUT, ">$temp_config")
  2975. or die "Can't write to $temp_config";
  2976. foreach my $config (keys %save_configs) {
  2977. print OUT "$save_configs{$config}\n";
  2978. }
  2979. close OUT;
  2980. run_command "mv $temp_config $ignore_config" or
  2981. dodie "failed to copy update to $ignore_config";
  2982. }
  2983. } else {
  2984. # We booted without this config, remove it from the minconfigs.
  2985. doprint "$config is not needed, disabling\n";
  2986. delete $min_configs{$config};
  2987. # Also disable anything that is not enabled in this config
  2988. my %configs;
  2989. assign_configs \%configs, $output_config;
  2990. my @config_keys = keys %min_configs;
  2991. foreach my $config (@config_keys) {
  2992. if (!defined($configs{$config})) {
  2993. doprint "$config is not set, disabling\n";
  2994. delete $min_configs{$config};
  2995. }
  2996. }
  2997. # Save off all the current mandidory configs
  2998. open (OUT, ">$temp_config")
  2999. or die "Can't write to $temp_config";
  3000. foreach my $config (keys %keep_configs) {
  3001. print OUT "$keep_configs{$config}\n";
  3002. }
  3003. foreach my $config (keys %min_configs) {
  3004. print OUT "$min_configs{$config}\n";
  3005. }
  3006. close OUT;
  3007. run_command "mv $temp_config $output_minconfig" or
  3008. dodie "failed to copy update to $output_minconfig";
  3009. }
  3010. doprint "Reboot and wait $sleep_time seconds\n";
  3011. reboot_to_good $sleep_time;
  3012. }
  3013. success $i;
  3014. return 1;
  3015. }
  3016. sub make_warnings_file {
  3017. my ($i) = @_;
  3018. if (!defined($warnings_file)) {
  3019. dodie "Must define WARNINGS_FILE for make_warnings_file test";
  3020. }
  3021. if ($build_type eq "nobuild") {
  3022. dodie "BUILD_TYPE can not be 'nobuild' for make_warnings_file test";
  3023. }
  3024. build $build_type or dodie "Failed to build";
  3025. open(OUT, ">$warnings_file") or dodie "Can't create $warnings_file";
  3026. open(IN, $buildlog) or dodie "Can't open $buildlog";
  3027. while (<IN>) {
  3028. # Some compilers use UTF-8 extended for quotes
  3029. # for distcc heterogeneous systems, this causes issues
  3030. s/$utf8_quote/'/g;
  3031. if (/$check_build_re/) {
  3032. print OUT;
  3033. }
  3034. }
  3035. close(IN);
  3036. close(OUT);
  3037. success $i;
  3038. }
  3039. $#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
  3040. if ($#ARGV == 0) {
  3041. $ktest_config = $ARGV[0];
  3042. if (! -f $ktest_config) {
  3043. print "$ktest_config does not exist.\n";
  3044. if (!read_yn "Create it?") {
  3045. exit 0;
  3046. }
  3047. }
  3048. } else {
  3049. $ktest_config = "ktest.conf";
  3050. }
  3051. if (! -f $ktest_config) {
  3052. $newconfig = 1;
  3053. get_test_case;
  3054. open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
  3055. print OUT << "EOF"
  3056. # Generated by ktest.pl
  3057. #
  3058. # PWD is a ktest.pl variable that will result in the process working
  3059. # directory that ktest.pl is executed in.
  3060. # THIS_DIR is automatically assigned the PWD of the path that generated
  3061. # the config file. It is best to use this variable when assigning other
  3062. # directory paths within this directory. This allows you to easily
  3063. # move the test cases to other locations or to other machines.
  3064. #
  3065. THIS_DIR := $variable{"PWD"}
  3066. # Define each test with TEST_START
  3067. # The config options below it will override the defaults
  3068. TEST_START
  3069. TEST_TYPE = $default{"TEST_TYPE"}
  3070. DEFAULTS
  3071. EOF
  3072. ;
  3073. close(OUT);
  3074. }
  3075. read_config $ktest_config;
  3076. if (defined($opt{"LOG_FILE"})) {
  3077. $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1);
  3078. }
  3079. # Append any configs entered in manually to the config file.
  3080. my @new_configs = keys %entered_configs;
  3081. if ($#new_configs >= 0) {
  3082. print "\nAppending entered in configs to $ktest_config\n";
  3083. open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
  3084. foreach my $config (@new_configs) {
  3085. print OUT "$config = $entered_configs{$config}\n";
  3086. $opt{$config} = process_variables($entered_configs{$config});
  3087. }
  3088. }
  3089. if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
  3090. unlink $opt{"LOG_FILE"};
  3091. }
  3092. doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
  3093. for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
  3094. if (!$i) {
  3095. doprint "DEFAULT OPTIONS:\n";
  3096. } else {
  3097. doprint "\nTEST $i OPTIONS";
  3098. if (defined($repeat_tests{$i})) {
  3099. $repeat = $repeat_tests{$i};
  3100. doprint " ITERATE $repeat";
  3101. }
  3102. doprint "\n";
  3103. }
  3104. foreach my $option (sort keys %opt) {
  3105. if ($option =~ /\[(\d+)\]$/) {
  3106. next if ($i != $1);
  3107. } else {
  3108. next if ($i);
  3109. }
  3110. doprint "$option = $opt{$option}\n";
  3111. }
  3112. }
  3113. sub __set_test_option {
  3114. my ($name, $i) = @_;
  3115. my $option = "$name\[$i\]";
  3116. if (defined($opt{$option})) {
  3117. return $opt{$option};
  3118. }
  3119. foreach my $test (keys %repeat_tests) {
  3120. if ($i >= $test &&
  3121. $i < $test + $repeat_tests{$test}) {
  3122. $option = "$name\[$test\]";
  3123. if (defined($opt{$option})) {
  3124. return $opt{$option};
  3125. }
  3126. }
  3127. }
  3128. if (defined($opt{$name})) {
  3129. return $opt{$name};
  3130. }
  3131. return undef;
  3132. }
  3133. sub set_test_option {
  3134. my ($name, $i) = @_;
  3135. my $option = __set_test_option($name, $i);
  3136. return $option if (!defined($option));
  3137. return eval_option($name, $option, $i);
  3138. }
  3139. # First we need to do is the builds
  3140. for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
  3141. # Do not reboot on failing test options
  3142. $no_reboot = 1;
  3143. $reboot_success = 0;
  3144. $have_version = 0;
  3145. $iteration = $i;
  3146. undef %force_config;
  3147. my $makecmd = set_test_option("MAKE_CMD", $i);
  3148. # Load all the options into their mapped variable names
  3149. foreach my $opt (keys %option_map) {
  3150. ${$option_map{$opt}} = set_test_option($opt, $i);
  3151. }
  3152. $start_minconfig_defined = 1;
  3153. # The first test may override the PRE_KTEST option
  3154. if (defined($pre_ktest) && $i == 1) {
  3155. doprint "\n";
  3156. run_command $pre_ktest;
  3157. }
  3158. # Any test can override the POST_KTEST option
  3159. # The last test takes precedence.
  3160. if (defined($post_ktest)) {
  3161. $final_post_ktest = $post_ktest;
  3162. }
  3163. if (!defined($start_minconfig)) {
  3164. $start_minconfig_defined = 0;
  3165. $start_minconfig = $minconfig;
  3166. }
  3167. chdir $builddir || die "can't change directory to $builddir";
  3168. foreach my $dir ($tmpdir, $outputdir) {
  3169. if (!-d $dir) {
  3170. mkpath($dir) or
  3171. die "can't create $dir";
  3172. }
  3173. }
  3174. $ENV{"SSH_USER"} = $ssh_user;
  3175. $ENV{"MACHINE"} = $machine;
  3176. $buildlog = "$tmpdir/buildlog-$machine";
  3177. $testlog = "$tmpdir/testlog-$machine";
  3178. $dmesg = "$tmpdir/dmesg-$machine";
  3179. $make = "$makecmd O=$outputdir";
  3180. $output_config = "$outputdir/.config";
  3181. if (!$buildonly) {
  3182. $target = "$ssh_user\@$machine";
  3183. if ($reboot_type eq "grub") {
  3184. dodie "GRUB_MENU not defined" if (!defined($grub_menu));
  3185. } elsif ($reboot_type eq "grub2") {
  3186. dodie "GRUB_MENU not defined" if (!defined($grub_menu));
  3187. dodie "GRUB_FILE not defined" if (!defined($grub_file));
  3188. } elsif ($reboot_type eq "syslinux") {
  3189. dodie "SYSLINUX_LABEL not defined" if (!defined($syslinux_label));
  3190. }
  3191. }
  3192. my $run_type = $build_type;
  3193. if ($test_type eq "patchcheck") {
  3194. $run_type = $patchcheck_type;
  3195. } elsif ($test_type eq "bisect") {
  3196. $run_type = $bisect_type;
  3197. } elsif ($test_type eq "config_bisect") {
  3198. $run_type = $config_bisect_type;
  3199. } elsif ($test_type eq "make_min_config") {
  3200. $run_type = "";
  3201. } elsif ($test_type eq "make_warnings_file") {
  3202. $run_type = "";
  3203. }
  3204. # mistake in config file?
  3205. if (!defined($run_type)) {
  3206. $run_type = "ERROR";
  3207. }
  3208. my $installme = "";
  3209. $installme = " no_install" if ($no_install);
  3210. doprint "\n\n";
  3211. doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
  3212. if (defined($pre_test)) {
  3213. run_command $pre_test;
  3214. }
  3215. unlink $dmesg;
  3216. unlink $buildlog;
  3217. unlink $testlog;
  3218. if (defined($addconfig)) {
  3219. my $min = $minconfig;
  3220. if (!defined($minconfig)) {
  3221. $min = "";
  3222. }
  3223. run_command "cat $addconfig $min > $tmpdir/add_config" or
  3224. dodie "Failed to create temp config";
  3225. $minconfig = "$tmpdir/add_config";
  3226. }
  3227. if (defined($checkout)) {
  3228. run_command "git checkout $checkout" or
  3229. die "failed to checkout $checkout";
  3230. }
  3231. $no_reboot = 0;
  3232. # A test may opt to not reboot the box
  3233. if ($reboot_on_success) {
  3234. $reboot_success = 1;
  3235. }
  3236. if ($test_type eq "bisect") {
  3237. bisect $i;
  3238. next;
  3239. } elsif ($test_type eq "config_bisect") {
  3240. config_bisect $i;
  3241. next;
  3242. } elsif ($test_type eq "patchcheck") {
  3243. patchcheck $i;
  3244. next;
  3245. } elsif ($test_type eq "make_min_config") {
  3246. make_min_config $i;
  3247. next;
  3248. } elsif ($test_type eq "make_warnings_file") {
  3249. $no_reboot = 1;
  3250. make_warnings_file $i;
  3251. next;
  3252. }
  3253. if ($build_type ne "nobuild") {
  3254. build $build_type or next;
  3255. check_buildlog or next;
  3256. }
  3257. if ($test_type eq "install") {
  3258. get_version;
  3259. install;
  3260. success $i;
  3261. next;
  3262. }
  3263. if ($test_type ne "build") {
  3264. my $failed = 0;
  3265. start_monitor_and_boot or $failed = 1;
  3266. if (!$failed && $test_type ne "boot" && defined($run_test)) {
  3267. do_run_test or $failed = 1;
  3268. }
  3269. end_monitor;
  3270. next if ($failed);
  3271. }
  3272. success $i;
  3273. }
  3274. if (defined($final_post_ktest)) {
  3275. run_command $final_post_ktest;
  3276. }
  3277. if ($opt{"POWEROFF_ON_SUCCESS"}) {
  3278. halt;
  3279. } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
  3280. reboot_to_good;
  3281. } elsif (defined($switch_to_good)) {
  3282. # still need to get to the good kernel
  3283. run_command $switch_to_good;
  3284. }
  3285. doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
  3286. exit 0;