blob: f344fd0d4f28e4c0a538839c2189a9d24181885a [file] [log] [blame]
Steven Rostedt2545eb62010-11-02 15:01:32 -04001#!/usr/bin/perl -w
2
3use strict;
4use IPC::Open2;
5use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
6use FileHandle;
7
8$#ARGV >= 0 || die "usage: autotest.pl config-file\n";
9
10$| = 1;
11
12my %opt;
13
14#default opts
15$opt{"NUM_BUILDS"} = 5;
16$opt{"DEFAULT_BUILD_TYPE"} = "randconfig";
17$opt{"MAKE_CMD"} = "make";
18$opt{"TIMEOUT"} = 50;
19$opt{"TMP_DIR"} = "/tmp/autotest";
20$opt{"SLEEP_TIME"} = 60; # sleep time between tests
Steven Rostedt5c42fc52010-11-02 14:57:01 -040021$opt{"BUILD_NOCLEAN"} = 0;
Steven Rostedt75c3fda72010-11-02 14:57:21 -040022$opt{"REBOOT_ON_ERROR"} = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -040023$opt{"POWEROFF_ON_ERROR"} = 0;
Steven Rostedt1a5cfce2010-11-02 14:57:51 -040024$opt{"REBOOT_ON_SUCCESS"} = 1;
Steven Rostedt5c42fc52010-11-02 14:57:01 -040025$opt{"POWEROFF_ON_SUCCESS"} = 0;
Steven Rostedt75c3fda72010-11-02 14:57:21 -040026$opt{"BUILD_OPTIONS"} = "";
Steven Rostedt5a391fb2010-11-02 14:57:43 -040027$opt{"BISECT_SLEEP_TIME"} = 10; # sleep time between bisects
Steven Rostedt2545eb62010-11-02 15:01:32 -040028
29my $version;
Steven Rostedt2545eb62010-11-02 15:01:32 -040030my $grub_number;
31my $target;
32my $make;
Steven Rostedt5c42fc52010-11-02 14:57:01 -040033my $noclean;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -040034my $minconfig;
35my $in_bisect = 0;
36my $bisect_bad = "";
Steven Rostedt5a391fb2010-11-02 14:57:43 -040037my $run_test;
Steven Rostedt2545eb62010-11-02 15:01:32 -040038
39sub read_config {
40 my ($config) = @_;
41
42 open(IN, $config) || die "can't read file $config";
43
44 while (<IN>) {
45
46 # ignore blank lines and comments
47 next if (/^\s*$/ || /\s*\#/);
48
49 if (/^\s*(\S+)\s*=\s*(.*?)\s*$/) {
50 my $lvalue = $1;
51 my $rvalue = $2;
52
53 $opt{$lvalue} = $rvalue;
54 }
55 }
56
57 close(IN);
58}
59
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -040060sub logit {
Steven Rostedt2545eb62010-11-02 15:01:32 -040061 if (defined($opt{"LOG_FILE"})) {
62 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
63 print OUT @_;
64 close(OUT);
65 }
66}
67
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -040068sub doprint {
69 print @_;
70 logit @_;
71}
72
Steven Rostedt5c42fc52010-11-02 14:57:01 -040073sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -040074 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -040075
Steven Rostedt75c3fda72010-11-02 14:57:21 -040076 if ($opt{"REBOOT_ON_ERROR"}) {
77 doprint "REBOOTING\n";
78 `$opt{"POWER_CYCLE"}`;
79
80 } elsif ($opt{"POWEROFF_ON_ERROR"} && defined($opt{"POWER_OFF"})) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -040081 doprint "POWERING OFF\n";
82 `$opt{"POWER_OFF"}`;
83 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -040084
Steven Rostedt5c42fc52010-11-02 14:57:01 -040085 die @_;
86}
87
Steven Rostedt2545eb62010-11-02 15:01:32 -040088sub run_command {
89 my ($command) = @_;
Steven Rostedt5a391fb2010-11-02 14:57:43 -040090 my $redirect_log = "";
Steven Rostedt2545eb62010-11-02 15:01:32 -040091
92 if (defined($opt{"LOG_FILE"})) {
Steven Rostedt5a391fb2010-11-02 14:57:43 -040093 $redirect_log = " >> $opt{LOG_FILE} 2>&1";
Steven Rostedt2545eb62010-11-02 15:01:32 -040094 }
95
96 doprint "$command ... ";
Steven Rostedt5a391fb2010-11-02 14:57:43 -040097 `$command $redirect_log`;
Steven Rostedt2545eb62010-11-02 15:01:32 -040098
99 my $failed = $?;
100
101 if ($failed) {
102 doprint "FAILED!\n";
103 } else {
104 doprint "SUCCESS\n";
105 }
106
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400107 return !$failed;
108}
109
110sub get_grub_index {
111
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400112 return if (defined($grub_number));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400113
114 doprint "Find grub menu ... ";
115 $grub_number = -1;
116 open(IN, "ssh $target cat /boot/grub/menu.lst |")
117 or die "unable to get menu.lst";
118 while (<IN>) {
119 if (/^\s*title\s+$opt{GRUB_MENU}\s*$/) {
120 $grub_number++;
121 last;
122 } elsif (/^\s*title\s/) {
123 $grub_number++;
124 }
125 }
126 close(IN);
127
128 die "Could not find '$opt{GRUB_MENU}' in /boot/grub/menu on $opt{MACHINE}"
129 if ($grub_number < 0);
130 doprint "$grub_number\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400131}
132
133my $timeout = $opt{"TIMEOUT"};
134
135sub wait_for_input
136{
137 my ($fp, $time) = @_;
138 my $rin;
139 my $ready;
140 my $line;
141 my $ch;
142
143 if (!defined($time)) {
144 $time = $timeout;
145 }
146
147 $rin = '';
148 vec($rin, fileno($fp), 1) = 1;
149 $ready = select($rin, undef, undef, $time);
150
151 $line = "";
152
153 # try to read one char at a time
154 while (sysread $fp, $ch, 1) {
155 $line .= $ch;
156 last if ($ch eq "\n");
157 }
158
159 if (!length($line)) {
160 return undef;
161 }
162
163 return $line;
164}
165
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400166sub reboot_to {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400167 run_command "ssh $target '(echo \"savedefault --default=$grub_number --once\" | grub --batch; reboot)'";
168}
169
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400170sub open_console {
171 my ($fp) = @_;
172
Steven Rostedt2545eb62010-11-02 15:01:32 -0400173 my $flags;
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400174
175 my $pid = open($fp, "$opt{CONSOLE}|") or
176 dodie "Can't open console $opt{CONSOLE}";
177
178 $flags = fcntl($fp, F_GETFL, 0) or
179 dodie "Can't get flags for the socket: $!\n";
180 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
181 dodie "Can't set flags for the socket: $!\n";
182
183 return $pid;
184}
185
186sub close_console {
187 my ($fp, $pid) = @_;
188
189 doprint "kill child process $pid\n";
190 kill 2, $pid;
191
192 print "closing!\n";
193 close($fp);
194}
195
196sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400197 my $booted = 0;
198 my $bug = 0;
199 my $pid;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400200 my $skip_call_trace = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400201 my $fp = \*IN;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400202
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400203 $pid = open_console($fp);
Steven Rostedt2545eb62010-11-02 15:01:32 -0400204
205 my $line;
206 my $full_line = "";
207
208 doprint "Wait for monitor to settle down.\n";
209 # read the monitor and wait for the system to calm down
210 do {
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400211 $line = wait_for_input($fp, 5);
Steven Rostedt2545eb62010-11-02 15:01:32 -0400212 } while (defined($line));
213
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400214 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400215
216 for (;;) {
217
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400218 $line = wait_for_input($fp);
Steven Rostedt2545eb62010-11-02 15:01:32 -0400219
220 last if (!defined($line));
221
222 doprint $line;
223
224 # we are not guaranteed to get a full line
225 $full_line .= $line;
226
227 if ($full_line =~ /login:/) {
228 $booted = 1;
229 }
230
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400231 if ($full_line =~ /\[ backtrace testing \]/) {
232 $skip_call_trace = 1;
233 }
234
Steven Rostedt2545eb62010-11-02 15:01:32 -0400235 if ($full_line =~ /call trace:/i) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400236 $bug = 1 if (!$skip_call_trace);
237 }
238
239 if ($full_line =~ /\[ end of backtrace testing \]/) {
240 $skip_call_trace = 0;
241 }
242
243 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400244 $bug = 1;
245 }
246
247 if ($line =~ /\n/) {
248 $full_line = "";
249 }
250 }
251
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400252 close_console($fp, $pid);
Steven Rostedt2545eb62010-11-02 15:01:32 -0400253
254 if (!$booted) {
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400255 return 1 if ($in_bisect);
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400256 dodie "failed - never got a boot prompt.\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400257 }
258
259 if ($bug) {
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400260 return 1 if ($in_bisect);
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400261 dodie "failed - got a bug report\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400262 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400263
264 return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400265}
266
267sub install {
268
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400269 run_command "scp $opt{OUTPUT_DIR}/$opt{BUILD_TARGET} $target:$opt{TARGET_IMAGE}" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400270 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400271
272 my $install_mods = 0;
273
274 # should we process modules?
275 $install_mods = 0;
276 open(IN, "$opt{OUTPUT_DIR}/.config") or dodie("Can't read config file");
277 while (<IN>) {
278 if (/CONFIG_MODULES(=y)?/) {
279 $install_mods = 1 if (defined($1));
280 last;
281 }
282 }
283 close(IN);
284
285 if (!$install_mods) {
286 doprint "No modules needed\n";
287 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400288 }
289
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400290 run_command "$make INSTALL_MOD_PATH=$opt{TMP_DIR} modules_install" or
291 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400292
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400293 my $modlib = "/lib/modules/$version";
294 my $modtar = "autotest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400295
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400296 run_command "ssh $target rm -rf $modlib" or
297 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400298
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400299 # would be nice if scp -r did not follow symbolic links
300 run_command "cd $opt{TMP_DIR} && tar -cjf $modtar lib/modules/$version" or
301 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400302
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400303 run_command "scp $opt{TMP_DIR}/$modtar $target:/tmp" or
304 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400305
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400306 unlink "$opt{TMP_DIR}/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400307
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400308 run_command "ssh $target '(cd / && tar xf /tmp/$modtar)'" or
309 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400310
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400311 run_command "ssh $target rm -f /tmp/$modtar";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400312}
313
314sub build {
315 my ($type) = @_;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400316 my $defconfig = "";
317 my $append = "";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400318
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400319 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400320 run_command "cp $1 $opt{OUTPUT_DIR}/.config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400321 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400322
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400323 $type = "oldconfig";
324 }
325
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400326 # old config can ask questions
327 if ($type eq "oldconfig") {
328 $append = "yes ''|";
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400329
330 # allow for empty configs
331 run_command "touch $opt{OUTPUT_DIR}/.config";
332
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400333 run_command "mv $opt{OUTPUT_DIR}/.config $opt{OUTPUT_DIR}/config_temp" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400334 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400335
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400336 if (!$noclean && !run_command "$make mrproper") {
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400337 dodie "make mrproper";
338 }
339
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400340 run_command "mv $opt{OUTPUT_DIR}/config_temp $opt{OUTPUT_DIR}/.config" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400341 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400342
343 } elsif (!$noclean) {
344 unlink "$opt{OUTPUT_DIR}/.config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400345 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400346 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400347 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400348
349 # add something to distinguish this build
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400350 open(OUT, "> $opt{OUTPUT_DIR}/localversion") or dodie("Can't make localversion file");
Steven Rostedt2545eb62010-11-02 15:01:32 -0400351 print OUT "$opt{LOCALVERSION}\n";
352 close(OUT);
353
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400354 if (defined($minconfig)) {
355 $defconfig = "KCONFIG_ALLCONFIG=$minconfig";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400356 }
357
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400358 run_command "$defconfig $append $make $type" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400359 dodie "failed make config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400360
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400361 if (!run_command "$make $opt{BUILD_OPTIONS}") {
362 # bisect may need this to pass
363 return 1 if ($in_bisect);
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400364 dodie "failed build";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400365 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400366
367 return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400368}
369
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400370sub reboot {
371 # try to reboot normally
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400372 if (!run_command "ssh $target reboot") {
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400373 # nope? power cycle it.
374 run_command "$opt{POWER_CYCLE}";
375 }
376}
377
378sub halt {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400379 if (!run_command "ssh $target halt" or defined($opt{"POWER_OFF"})) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400380 # nope? the zap it!
381 run_command "$opt{POWER_OFF}";
382 }
383}
384
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400385sub success {
386 my ($i) = @_;
387
388 doprint "\n\n*******************************************\n";
389 doprint "*******************************************\n";
390 doprint "** SUCCESS!!!! **\n";
391 doprint "*******************************************\n";
392 doprint "*******************************************\n";
393
394 if ($i != $opt{"NUM_BUILDS"}) {
395 reboot;
396 doprint "Sleeping $opt{SLEEP_TIME} seconds\n";
397 sleep "$opt{SLEEP_TIME}";
398 }
399}
400
401sub get_version {
402 # get the release name
403 doprint "$make kernelrelease ... ";
404 $version = `$make kernelrelease | tail -1`;
405 chomp($version);
406 doprint "$version\n";
407}
408
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400409sub child_run_test {
410 my $failed;
411
412 $failed = !run_command $run_test;
413 exit $failed;
414}
415
416my $child_done;
417
418sub child_finished {
419 $child_done = 1;
420}
421
422sub do_run_test {
423 my $child_pid;
424 my $child_exit;
425 my $pid;
426 my $line;
427 my $full_line;
428 my $bug = 0;
429 my $fp = \*IN;
430
431 $pid = open_console($fp);
432
433 # read the monitor and wait for the system to calm down
434 do {
435 $line = wait_for_input($fp, 1);
436 } while (defined($line));
437
438 $child_done = 0;
439
440 $SIG{CHLD} = qw(child_finished);
441
442 $child_pid = fork;
443
444 child_run_test if (!$child_pid);
445
446 $full_line = "";
447
448 do {
449 $line = wait_for_input($fp, 1);
450 if (defined($line)) {
451
452 # we are not guaranteed to get a full line
453 $full_line .= $line;
454
455 if ($full_line =~ /call trace:/i) {
456 $bug = 1;
457 }
458
459 if ($full_line =~ /Kernel panic -/) {
460 $bug = 1;
461 }
462
463 if ($line =~ /\n/) {
464 $full_line = "";
465 }
466 }
467 } while (!$child_done && !$bug);
468
469 if ($bug) {
470 doprint "Detected kernel crash!\n";
471 # kill the child with extreme prejudice
472 kill 9, $child_pid;
473 }
474
475 waitpid $child_pid, 0;
476 $child_exit = $?;
477
478 close_console($fp, $pid);
479
480 if ($bug || $child_exit) {
481 return 1 if $in_bisect;
482 dodie "test failed";
483 }
484 return 0;
485}
486
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400487sub run_bisect {
488 my ($type) = @_;
489
490 my $failed;
491 my $result;
492 my $output;
493 my $ret;
494
495
496 if (defined($minconfig)) {
497 $failed = build "useconfig:$minconfig";
498 } else {
499 # ?? no config to use?
500 $failed = build "oldconfig";
501 }
502
503 if ($type ne "build") {
504 dodie "Failed on build" if $failed;
505
506 # Now boot the box
507 get_grub_index;
508 get_version;
509 install;
510 $failed = monitor;
511
512 if ($type ne "boot") {
513 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400514
515 $failed = do_run_test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400516 }
517 }
518
519 if ($failed) {
520 $result = "bad";
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400521
522 # reboot the box to a good kernel
523 if ($type eq "boot") {
524 reboot;
525 doprint "sleep a little for reboot\n";
526 sleep $opt{"BISECT_SLEEP_TIME"};
527 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400528 } else {
529 $result = "good";
530 }
531
532 doprint "git bisect $result ... ";
533 $output = `git bisect $result 2>&1`;
534 $ret = $?;
535
536 logit $output;
537
538 if ($ret) {
539 doprint "FAILED\n";
540 dodie "Failed to git bisect";
541 }
542
543 doprint "SUCCESS\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400544 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400545 doprint "$1 [$2]\n";
546 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
547 $bisect_bad = $1;
548 doprint "Found bad commit... $1\n";
549 return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400550 } else {
551 # we already logged it, just print it now.
552 print $output;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400553 }
554
555
556 return 1;
557}
558
559sub bisect {
560 my ($i) = @_;
561
562 my $result;
563
564 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
565 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
566 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
567
568 my $good = $opt{"BISECT_GOOD[$i]"};
569 my $bad = $opt{"BISECT_BAD[$i]"};
570 my $type = $opt{"BISECT_TYPE[$i]"};
571
572 $in_bisect = 1;
573
574 run_command "git bisect start" or
575 dodie "could not start bisect";
576
577 run_command "git bisect good $good" or
578 dodie "could not set bisect good to $good";
579
580 run_command "git bisect bad $bad" or
581 dodie "could not set bisect good to $bad";
582
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400583 # Can't have a test without having a test to run
584 if ($type eq "test" && !defined($run_test)) {
585 $type = "boot";
586 }
587
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400588 do {
589 $result = run_bisect $type;
590 } while ($result);
591
592 run_command "git bisect log" or
593 dodie "could not capture git bisect log";
594
595 run_command "git bisect reset" or
596 dodie "could not reset git bisect";
597
598 doprint "Bad commit was [$bisect_bad]\n";
599
600 $in_bisect = 0;
601
602 success $i;
603}
604
Steven Rostedt2545eb62010-11-02 15:01:32 -0400605read_config $ARGV[0];
606
607# mandatory configs
608die "MACHINE not defined\n" if (!defined($opt{"MACHINE"}));
609die "SSH_USER not defined\n" if (!defined($opt{"SSH_USER"}));
610die "BUILD_DIR not defined\n" if (!defined($opt{"BUILD_DIR"}));
611die "OUTPUT_DIR not defined\n" if (!defined($opt{"OUTPUT_DIR"}));
612die "BUILD_TARGET not defined\n" if (!defined($opt{"BUILD_TARGET"}));
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400613die "TARGET_IMAGE not defined\n" if (!defined($opt{"TARGET_IMAGE"}));
Steven Rostedt2545eb62010-11-02 15:01:32 -0400614die "POWER_CYCLE not defined\n" if (!defined($opt{"POWER_CYCLE"}));
615die "CONSOLE not defined\n" if (!defined($opt{"CONSOLE"}));
616die "LOCALVERSION not defined\n" if (!defined($opt{"LOCALVERSION"}));
617die "GRUB_MENU not defined\n" if (!defined($opt{"GRUB_MENU"}));
618
619chdir $opt{"BUILD_DIR"} || die "can't change directory to $opt{BUILD_DIR}";
620
621$target = "$opt{SSH_USER}\@$opt{MACHINE}";
622
623doprint "\n\nSTARTING AUTOMATED TESTS\n";
624
Steven Rostedt2545eb62010-11-02 15:01:32 -0400625
626$make = "$opt{MAKE_CMD} O=$opt{OUTPUT_DIR}";
627
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400628sub set_build_option {
629 my ($name, $i) = @_;
630
631 my $option = "$name\[$i\]";
632
633 if (defined($opt{$option})) {
634 return $opt{$option};
635 }
636
637 if (defined($opt{$name})) {
638 return $opt{$name};
639 }
640
641 return undef;
642}
643
Steven Rostedt2545eb62010-11-02 15:01:32 -0400644# First we need to do is the builds
645for (my $i = 1; $i <= $opt{"NUM_BUILDS"}; $i++) {
646 my $type = "BUILD_TYPE[$i]";
647
Steven Rostedt1a5cfce2010-11-02 14:57:51 -0400648 if (!defined($opt{$type})) {
649 $opt{$type} = $opt{"DEFAULT_BUILD_TYPE"};
650 }
651
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400652 $noclean = set_build_option("BUILD_NOCLEAN", $i);
653 $minconfig = set_build_option("MIN_CONFIG", $i);
654 $run_test = set_build_option("TEST", $i);
Steven Rostedt2545eb62010-11-02 15:01:32 -0400655
656 doprint "\n\n";
657 doprint "RUNNING TEST $i of $opt{NUM_BUILDS} with option $opt{$type}\n\n";
658
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400659 if ($opt{$type} eq "bisect") {
660 bisect $i;
661 next;
662 }
663
Steven Rostedt2545eb62010-11-02 15:01:32 -0400664 if ($opt{$type} ne "nobuild") {
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400665 build $opt{$type};
Steven Rostedt2545eb62010-11-02 15:01:32 -0400666 }
667
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400668 get_grub_index;
669 get_version;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400670 install;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400671 monitor;
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400672
673 if (defined($run_test)) {
674 do_run_test;
675 }
676
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400677 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400678}
679
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400680if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400681 halt;
Steven Rostedt1a5cfce2010-11-02 14:57:51 -0400682} elsif ($opt{"REBOOT_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400683 reboot;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400684}
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400685
Steven Rostedt2545eb62010-11-02 15:01:32 -0400686exit 0;