blob: 9eaf8d05c749875c048589fe02f893c5497545d2 [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;
24$opt{"POWEROFF_ON_SUCCESS"} = 0;
Steven Rostedt75c3fda72010-11-02 14:57:21 -040025$opt{"BUILD_OPTIONS"} = "";
Steven Rostedt5a391fb2010-11-02 14:57:43 -040026$opt{"BISECT_SLEEP_TIME"} = 10; # sleep time between bisects
Steven Rostedt2545eb62010-11-02 15:01:32 -040027
28my $version;
Steven Rostedt2545eb62010-11-02 15:01:32 -040029my $grub_number;
30my $target;
31my $make;
Steven Rostedt5c42fc52010-11-02 14:57:01 -040032my $noclean;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -040033my $minconfig;
34my $in_bisect = 0;
35my $bisect_bad = "";
Steven Rostedt5a391fb2010-11-02 14:57:43 -040036my $run_test;
Steven Rostedt2545eb62010-11-02 15:01:32 -040037
38sub read_config {
39 my ($config) = @_;
40
41 open(IN, $config) || die "can't read file $config";
42
43 while (<IN>) {
44
45 # ignore blank lines and comments
46 next if (/^\s*$/ || /\s*\#/);
47
48 if (/^\s*(\S+)\s*=\s*(.*?)\s*$/) {
49 my $lvalue = $1;
50 my $rvalue = $2;
51
52 $opt{$lvalue} = $rvalue;
53 }
54 }
55
56 close(IN);
57}
58
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -040059sub logit {
Steven Rostedt2545eb62010-11-02 15:01:32 -040060 if (defined($opt{"LOG_FILE"})) {
61 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
62 print OUT @_;
63 close(OUT);
64 }
65}
66
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -040067sub doprint {
68 print @_;
69 logit @_;
70}
71
Steven Rostedt5c42fc52010-11-02 14:57:01 -040072sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -040073 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -040074
Steven Rostedt75c3fda72010-11-02 14:57:21 -040075 if ($opt{"REBOOT_ON_ERROR"}) {
76 doprint "REBOOTING\n";
77 `$opt{"POWER_CYCLE"}`;
78
79 } elsif ($opt{"POWEROFF_ON_ERROR"} && defined($opt{"POWER_OFF"})) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -040080 doprint "POWERING OFF\n";
81 `$opt{"POWER_OFF"}`;
82 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -040083
Steven Rostedt5c42fc52010-11-02 14:57:01 -040084 die @_;
85}
86
Steven Rostedt2545eb62010-11-02 15:01:32 -040087sub run_command {
88 my ($command) = @_;
Steven Rostedt5a391fb2010-11-02 14:57:43 -040089 my $redirect_log = "";
Steven Rostedt2545eb62010-11-02 15:01:32 -040090
91 if (defined($opt{"LOG_FILE"})) {
Steven Rostedt5a391fb2010-11-02 14:57:43 -040092 $redirect_log = " >> $opt{LOG_FILE} 2>&1";
Steven Rostedt2545eb62010-11-02 15:01:32 -040093 }
94
95 doprint "$command ... ";
Steven Rostedt5a391fb2010-11-02 14:57:43 -040096 `$command $redirect_log`;
Steven Rostedt2545eb62010-11-02 15:01:32 -040097
98 my $failed = $?;
99
100 if ($failed) {
101 doprint "FAILED!\n";
102 } else {
103 doprint "SUCCESS\n";
104 }
105
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400106 return !$failed;
107}
108
109sub get_grub_index {
110
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400111 return if (defined($grub_number));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400112
113 doprint "Find grub menu ... ";
114 $grub_number = -1;
115 open(IN, "ssh $target cat /boot/grub/menu.lst |")
116 or die "unable to get menu.lst";
117 while (<IN>) {
118 if (/^\s*title\s+$opt{GRUB_MENU}\s*$/) {
119 $grub_number++;
120 last;
121 } elsif (/^\s*title\s/) {
122 $grub_number++;
123 }
124 }
125 close(IN);
126
127 die "Could not find '$opt{GRUB_MENU}' in /boot/grub/menu on $opt{MACHINE}"
128 if ($grub_number < 0);
129 doprint "$grub_number\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400130}
131
132my $timeout = $opt{"TIMEOUT"};
133
134sub wait_for_input
135{
136 my ($fp, $time) = @_;
137 my $rin;
138 my $ready;
139 my $line;
140 my $ch;
141
142 if (!defined($time)) {
143 $time = $timeout;
144 }
145
146 $rin = '';
147 vec($rin, fileno($fp), 1) = 1;
148 $ready = select($rin, undef, undef, $time);
149
150 $line = "";
151
152 # try to read one char at a time
153 while (sysread $fp, $ch, 1) {
154 $line .= $ch;
155 last if ($ch eq "\n");
156 }
157
158 if (!length($line)) {
159 return undef;
160 }
161
162 return $line;
163}
164
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400165sub reboot_to {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400166 run_command "ssh $target '(echo \"savedefault --default=$grub_number --once\" | grub --batch; reboot)'";
167}
168
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400169sub open_console {
170 my ($fp) = @_;
171
Steven Rostedt2545eb62010-11-02 15:01:32 -0400172 my $flags;
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400173
174 my $pid = open($fp, "$opt{CONSOLE}|") or
175 dodie "Can't open console $opt{CONSOLE}";
176
177 $flags = fcntl($fp, F_GETFL, 0) or
178 dodie "Can't get flags for the socket: $!\n";
179 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
180 dodie "Can't set flags for the socket: $!\n";
181
182 return $pid;
183}
184
185sub close_console {
186 my ($fp, $pid) = @_;
187
188 doprint "kill child process $pid\n";
189 kill 2, $pid;
190
191 print "closing!\n";
192 close($fp);
193}
194
195sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400196 my $booted = 0;
197 my $bug = 0;
198 my $pid;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400199 my $skip_call_trace = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400200 my $fp = \*IN;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400201
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400202 $pid = open_console($fp);
Steven Rostedt2545eb62010-11-02 15:01:32 -0400203
204 my $line;
205 my $full_line = "";
206
207 doprint "Wait for monitor to settle down.\n";
208 # read the monitor and wait for the system to calm down
209 do {
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400210 $line = wait_for_input($fp, 5);
Steven Rostedt2545eb62010-11-02 15:01:32 -0400211 } while (defined($line));
212
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400213 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400214
215 for (;;) {
216
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400217 $line = wait_for_input($fp);
Steven Rostedt2545eb62010-11-02 15:01:32 -0400218
219 last if (!defined($line));
220
221 doprint $line;
222
223 # we are not guaranteed to get a full line
224 $full_line .= $line;
225
226 if ($full_line =~ /login:/) {
227 $booted = 1;
228 }
229
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400230 if ($full_line =~ /\[ backtrace testing \]/) {
231 $skip_call_trace = 1;
232 }
233
Steven Rostedt2545eb62010-11-02 15:01:32 -0400234 if ($full_line =~ /call trace:/i) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400235 $bug = 1 if (!$skip_call_trace);
236 }
237
238 if ($full_line =~ /\[ end of backtrace testing \]/) {
239 $skip_call_trace = 0;
240 }
241
242 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400243 $bug = 1;
244 }
245
246 if ($line =~ /\n/) {
247 $full_line = "";
248 }
249 }
250
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400251 close_console($fp, $pid);
Steven Rostedt2545eb62010-11-02 15:01:32 -0400252
253 if (!$booted) {
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400254 return 1 if ($in_bisect);
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400255 dodie "failed - never got a boot prompt.\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400256 }
257
258 if ($bug) {
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400259 return 1 if ($in_bisect);
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400260 dodie "failed - got a bug report\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400261 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400262
263 return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400264}
265
266sub install {
267
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400268 run_command "scp $opt{OUTPUT_DIR}/$opt{BUILD_TARGET} $target:$opt{TARGET_IMAGE}" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400269 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400270
271 my $install_mods = 0;
272
273 # should we process modules?
274 $install_mods = 0;
275 open(IN, "$opt{OUTPUT_DIR}/.config") or dodie("Can't read config file");
276 while (<IN>) {
277 if (/CONFIG_MODULES(=y)?/) {
278 $install_mods = 1 if (defined($1));
279 last;
280 }
281 }
282 close(IN);
283
284 if (!$install_mods) {
285 doprint "No modules needed\n";
286 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400287 }
288
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400289 run_command "$make INSTALL_MOD_PATH=$opt{TMP_DIR} modules_install" or
290 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400291
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400292 my $modlib = "/lib/modules/$version";
293 my $modtar = "autotest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400294
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400295 run_command "ssh $target rm -rf $modlib" or
296 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400297
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400298 # would be nice if scp -r did not follow symbolic links
299 run_command "cd $opt{TMP_DIR} && tar -cjf $modtar lib/modules/$version" or
300 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400301
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400302 run_command "scp $opt{TMP_DIR}/$modtar $target:/tmp" or
303 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400304
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400305 unlink "$opt{TMP_DIR}/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400306
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400307 run_command "ssh $target '(cd / && tar xf /tmp/$modtar)'" or
308 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400309
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400310 run_command "ssh $target rm -f /tmp/$modtar";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400311}
312
313sub build {
314 my ($type) = @_;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400315 my $defconfig = "";
316 my $append = "";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400317
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400318 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400319 run_command "cp $1 $opt{OUTPUT_DIR}/.config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400320 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400321
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400322 $type = "oldconfig";
323 }
324
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400325 # old config can ask questions
326 if ($type eq "oldconfig") {
327 $append = "yes ''|";
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400328
329 # allow for empty configs
330 run_command "touch $opt{OUTPUT_DIR}/.config";
331
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400332 run_command "mv $opt{OUTPUT_DIR}/.config $opt{OUTPUT_DIR}/config_temp" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400333 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400334
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400335 if (!$noclean && !run_command "$make mrproper") {
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400336 dodie "make mrproper";
337 }
338
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400339 run_command "mv $opt{OUTPUT_DIR}/config_temp $opt{OUTPUT_DIR}/.config" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400340 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400341
342 } elsif (!$noclean) {
343 unlink "$opt{OUTPUT_DIR}/.config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400344 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400345 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400346 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400347
348 # add something to distinguish this build
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400349 open(OUT, "> $opt{OUTPUT_DIR}/localversion") or dodie("Can't make localversion file");
Steven Rostedt2545eb62010-11-02 15:01:32 -0400350 print OUT "$opt{LOCALVERSION}\n";
351 close(OUT);
352
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400353 if (defined($minconfig)) {
354 $defconfig = "KCONFIG_ALLCONFIG=$minconfig";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400355 }
356
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400357 run_command "$defconfig $append $make $type" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400358 dodie "failed make config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400359
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400360 if (!run_command "$make $opt{BUILD_OPTIONS}") {
361 # bisect may need this to pass
362 return 1 if ($in_bisect);
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400363 dodie "failed build";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400364 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400365
366 return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400367}
368
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400369sub reboot {
370 # try to reboot normally
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400371 if (!run_command "ssh $target reboot") {
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400372 # nope? power cycle it.
373 run_command "$opt{POWER_CYCLE}";
374 }
375}
376
377sub halt {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400378 if (!run_command "ssh $target halt" or defined($opt{"POWER_OFF"})) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400379 # nope? the zap it!
380 run_command "$opt{POWER_OFF}";
381 }
382}
383
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400384sub success {
385 my ($i) = @_;
386
387 doprint "\n\n*******************************************\n";
388 doprint "*******************************************\n";
389 doprint "** SUCCESS!!!! **\n";
390 doprint "*******************************************\n";
391 doprint "*******************************************\n";
392
393 if ($i != $opt{"NUM_BUILDS"}) {
394 reboot;
395 doprint "Sleeping $opt{SLEEP_TIME} seconds\n";
396 sleep "$opt{SLEEP_TIME}";
397 }
398}
399
400sub get_version {
401 # get the release name
402 doprint "$make kernelrelease ... ";
403 $version = `$make kernelrelease | tail -1`;
404 chomp($version);
405 doprint "$version\n";
406}
407
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400408sub child_run_test {
409 my $failed;
410
411 $failed = !run_command $run_test;
412 exit $failed;
413}
414
415my $child_done;
416
417sub child_finished {
418 $child_done = 1;
419}
420
421sub do_run_test {
422 my $child_pid;
423 my $child_exit;
424 my $pid;
425 my $line;
426 my $full_line;
427 my $bug = 0;
428 my $fp = \*IN;
429
430 $pid = open_console($fp);
431
432 # read the monitor and wait for the system to calm down
433 do {
434 $line = wait_for_input($fp, 1);
435 } while (defined($line));
436
437 $child_done = 0;
438
439 $SIG{CHLD} = qw(child_finished);
440
441 $child_pid = fork;
442
443 child_run_test if (!$child_pid);
444
445 $full_line = "";
446
447 do {
448 $line = wait_for_input($fp, 1);
449 if (defined($line)) {
450
451 # we are not guaranteed to get a full line
452 $full_line .= $line;
453
454 if ($full_line =~ /call trace:/i) {
455 $bug = 1;
456 }
457
458 if ($full_line =~ /Kernel panic -/) {
459 $bug = 1;
460 }
461
462 if ($line =~ /\n/) {
463 $full_line = "";
464 }
465 }
466 } while (!$child_done && !$bug);
467
468 if ($bug) {
469 doprint "Detected kernel crash!\n";
470 # kill the child with extreme prejudice
471 kill 9, $child_pid;
472 }
473
474 waitpid $child_pid, 0;
475 $child_exit = $?;
476
477 close_console($fp, $pid);
478
479 if ($bug || $child_exit) {
480 return 1 if $in_bisect;
481 dodie "test failed";
482 }
483 return 0;
484}
485
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400486sub run_bisect {
487 my ($type) = @_;
488
489 my $failed;
490 my $result;
491 my $output;
492 my $ret;
493
494
495 if (defined($minconfig)) {
496 $failed = build "useconfig:$minconfig";
497 } else {
498 # ?? no config to use?
499 $failed = build "oldconfig";
500 }
501
502 if ($type ne "build") {
503 dodie "Failed on build" if $failed;
504
505 # Now boot the box
506 get_grub_index;
507 get_version;
508 install;
509 $failed = monitor;
510
511 if ($type ne "boot") {
512 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400513
514 $failed = do_run_test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400515 }
516 }
517
518 if ($failed) {
519 $result = "bad";
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400520
521 # reboot the box to a good kernel
522 if ($type eq "boot") {
523 reboot;
524 doprint "sleep a little for reboot\n";
525 sleep $opt{"BISECT_SLEEP_TIME"};
526 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400527 } else {
528 $result = "good";
529 }
530
531 doprint "git bisect $result ... ";
532 $output = `git bisect $result 2>&1`;
533 $ret = $?;
534
535 logit $output;
536
537 if ($ret) {
538 doprint "FAILED\n";
539 dodie "Failed to git bisect";
540 }
541
542 doprint "SUCCESS\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400543 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400544 doprint "$1 [$2]\n";
545 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
546 $bisect_bad = $1;
547 doprint "Found bad commit... $1\n";
548 return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400549 } else {
550 # we already logged it, just print it now.
551 print $output;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400552 }
553
554
555 return 1;
556}
557
558sub bisect {
559 my ($i) = @_;
560
561 my $result;
562
563 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
564 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
565 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
566
567 my $good = $opt{"BISECT_GOOD[$i]"};
568 my $bad = $opt{"BISECT_BAD[$i]"};
569 my $type = $opt{"BISECT_TYPE[$i]"};
570
571 $in_bisect = 1;
572
573 run_command "git bisect start" or
574 dodie "could not start bisect";
575
576 run_command "git bisect good $good" or
577 dodie "could not set bisect good to $good";
578
579 run_command "git bisect bad $bad" or
580 dodie "could not set bisect good to $bad";
581
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400582 # Can't have a test without having a test to run
583 if ($type eq "test" && !defined($run_test)) {
584 $type = "boot";
585 }
586
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400587 do {
588 $result = run_bisect $type;
589 } while ($result);
590
591 run_command "git bisect log" or
592 dodie "could not capture git bisect log";
593
594 run_command "git bisect reset" or
595 dodie "could not reset git bisect";
596
597 doprint "Bad commit was [$bisect_bad]\n";
598
599 $in_bisect = 0;
600
601 success $i;
602}
603
Steven Rostedt2545eb62010-11-02 15:01:32 -0400604read_config $ARGV[0];
605
606# mandatory configs
607die "MACHINE not defined\n" if (!defined($opt{"MACHINE"}));
608die "SSH_USER not defined\n" if (!defined($opt{"SSH_USER"}));
609die "BUILD_DIR not defined\n" if (!defined($opt{"BUILD_DIR"}));
610die "OUTPUT_DIR not defined\n" if (!defined($opt{"OUTPUT_DIR"}));
611die "BUILD_TARGET not defined\n" if (!defined($opt{"BUILD_TARGET"}));
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400612die "TARGET_IMAGE not defined\n" if (!defined($opt{"TARGET_IMAGE"}));
Steven Rostedt2545eb62010-11-02 15:01:32 -0400613die "POWER_CYCLE not defined\n" if (!defined($opt{"POWER_CYCLE"}));
614die "CONSOLE not defined\n" if (!defined($opt{"CONSOLE"}));
615die "LOCALVERSION not defined\n" if (!defined($opt{"LOCALVERSION"}));
616die "GRUB_MENU not defined\n" if (!defined($opt{"GRUB_MENU"}));
617
618chdir $opt{"BUILD_DIR"} || die "can't change directory to $opt{BUILD_DIR}";
619
620$target = "$opt{SSH_USER}\@$opt{MACHINE}";
621
622doprint "\n\nSTARTING AUTOMATED TESTS\n";
623
Steven Rostedt2545eb62010-11-02 15:01:32 -0400624
625$make = "$opt{MAKE_CMD} O=$opt{OUTPUT_DIR}";
626
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400627sub set_build_option {
628 my ($name, $i) = @_;
629
630 my $option = "$name\[$i\]";
631
632 if (defined($opt{$option})) {
633 return $opt{$option};
634 }
635
636 if (defined($opt{$name})) {
637 return $opt{$name};
638 }
639
640 return undef;
641}
642
Steven Rostedt2545eb62010-11-02 15:01:32 -0400643# First we need to do is the builds
644for (my $i = 1; $i <= $opt{"NUM_BUILDS"}; $i++) {
645 my $type = "BUILD_TYPE[$i]";
646
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400647 $noclean = set_build_option("BUILD_NOCLEAN", $i);
648 $minconfig = set_build_option("MIN_CONFIG", $i);
649 $run_test = set_build_option("TEST", $i);
Steven Rostedt2545eb62010-11-02 15:01:32 -0400650
651 doprint "\n\n";
652 doprint "RUNNING TEST $i of $opt{NUM_BUILDS} with option $opt{$type}\n\n";
653
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400654 if ($opt{$type} eq "bisect") {
655 bisect $i;
656 next;
657 }
658
Steven Rostedt2545eb62010-11-02 15:01:32 -0400659 if ($opt{$type} ne "nobuild") {
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400660 build $opt{$type};
Steven Rostedt2545eb62010-11-02 15:01:32 -0400661 }
662
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400663 get_grub_index;
664 get_version;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400665 install;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400666 monitor;
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400667
668 if (defined($run_test)) {
669 do_run_test;
670 }
671
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400672 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400673}
674
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400675if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400676 halt;
677} else {
678 reboot;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400679}
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400680
Steven Rostedt2545eb62010-11-02 15:01:32 -0400681exit 0;