ktest.pl (7a849cd93ad2cf7d32427f3dbf5f524d5f588d20) ktest.pl (e48c5293bde398e253f83fdd0247fb2bc71cc92f)
1#!/usr/bin/perl -w
2#
3# Copywrite 2010 - Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.
4# Licensed under the terms of the GNU GPL License version 2
5#
6
7use strict;
8use IPC::Open2;
9use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
10use File::Path qw(mkpath);
11use File::Copy qw(cp);
12use FileHandle;
13
1#!/usr/bin/perl -w
2#
3# Copywrite 2010 - Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.
4# Licensed under the terms of the GNU GPL License version 2
5#
6
7use strict;
8use IPC::Open2;
9use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
10use File::Path qw(mkpath);
11use File::Copy qw(cp);
12use FileHandle;
13
14$#ARGV >= 0 || die "usage: ktest.pl config-file\n";
14my $VERSION = "0.2";
15
15
16$#ARGV >= 0 || die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
17
16$| = 1;
17
18my %opt;
19my %repeat_tests;
20my %repeats;
21my %default;
22
23#default opts

--- 11 unchanged lines hidden (view full) ---

35$default{"REBOOT_ON_SUCCESS"} = 1;
36$default{"POWEROFF_ON_SUCCESS"} = 0;
37$default{"BUILD_OPTIONS"} = "";
38$default{"BISECT_SLEEP_TIME"} = 60; # sleep time between bisects
39$default{"CLEAR_LOG"} = 0;
40$default{"SUCCESS_LINE"} = "login:";
41$default{"BOOTED_TIMEOUT"} = 1;
42$default{"DIE_ON_FAILURE"} = 1;
18$| = 1;
19
20my %opt;
21my %repeat_tests;
22my %repeats;
23my %default;
24
25#default opts

--- 11 unchanged lines hidden (view full) ---

37$default{"REBOOT_ON_SUCCESS"} = 1;
38$default{"POWEROFF_ON_SUCCESS"} = 0;
39$default{"BUILD_OPTIONS"} = "";
40$default{"BISECT_SLEEP_TIME"} = 60; # sleep time between bisects
41$default{"CLEAR_LOG"} = 0;
42$default{"SUCCESS_LINE"} = "login:";
43$default{"BOOTED_TIMEOUT"} = 1;
44$default{"DIE_ON_FAILURE"} = 1;
45$default{"SSH_EXEC"} = "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND";
46$default{"SCP_TO_TARGET"} = "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE";
47$default{"REBOOT"} = "ssh \$SSH_USER\@\$MACHINE reboot";
43
44my $version;
45my $machine;
48
49my $version;
50my $machine;
51my $ssh_user;
46my $tmpdir;
47my $builddir;
48my $outputdir;
49my $output_config;
50my $test_type;
51my $build_type;
52my $build_options;
53my $reboot_type;
54my $reboot_script;
55my $power_cycle;
52my $tmpdir;
53my $builddir;
54my $outputdir;
55my $output_config;
56my $test_type;
57my $build_type;
58my $build_options;
59my $reboot_type;
60my $reboot_script;
61my $power_cycle;
62my $reboot;
56my $reboot_on_error;
57my $poweroff_on_error;
58my $die_on_failure;
59my $powercycle_after_reboot;
60my $poweroff_after_halt;
63my $reboot_on_error;
64my $poweroff_on_error;
65my $die_on_failure;
66my $powercycle_after_reboot;
67my $poweroff_after_halt;
68my $ssh_exec;
69my $scp_to_target;
61my $power_off;
62my $grub_menu;
63my $grub_number;
64my $target;
65my $make;
66my $post_install;
67my $noclean;
68my $minconfig;

--- 15 unchanged lines hidden (view full) ---

84my $timeout;
85my $booted_timeout;
86my $console;
87my $success_line;
88my $build_target;
89my $target_image;
90my $localversion;
91my $iteration = 0;
70my $power_off;
71my $grub_menu;
72my $grub_number;
73my $target;
74my $make;
75my $post_install;
76my $noclean;
77my $minconfig;

--- 15 unchanged lines hidden (view full) ---

93my $timeout;
94my $booted_timeout;
95my $console;
96my $success_line;
97my $build_target;
98my $target_image;
99my $localversion;
100my $iteration = 0;
101my $successes = 0;
92
93sub set_value {
94 my ($lvalue, $rvalue) = @_;
95
96 if (defined($opt{$lvalue})) {
97 die "Error: Option $lvalue defined more than once!\n";
98 }
99 $opt{$lvalue} = $rvalue;

--- 28 unchanged lines hidden (view full) ---

128
129 $rest = $1;
130
131 if ($num_tests_set) {
132 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
133 }
134
135 my $old_test_num = $test_num;
102
103sub set_value {
104 my ($lvalue, $rvalue) = @_;
105
106 if (defined($opt{$lvalue})) {
107 die "Error: Option $lvalue defined more than once!\n";
108 }
109 $opt{$lvalue} = $rvalue;

--- 28 unchanged lines hidden (view full) ---

138
139 $rest = $1;
140
141 if ($num_tests_set) {
142 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
143 }
144
145 my $old_test_num = $test_num;
146 my $old_repeat = $repeat;
136
137 $test_num += $repeat;
138 $default = 0;
139 $repeat = 1;
140
141 if ($rest =~ /\s+SKIP(.*)/) {
142 $rest = $1;
143 $skip = 1;

--- 13 unchanged lines hidden (view full) ---

157 }
158
159 if ($rest !~ /^\s*$/) {
160 die "$name: $.: Gargbage found after TEST_START\n$_";
161 }
162
163 if ($skip) {
164 $test_num = $old_test_num;
147
148 $test_num += $repeat;
149 $default = 0;
150 $repeat = 1;
151
152 if ($rest =~ /\s+SKIP(.*)/) {
153 $rest = $1;
154 $skip = 1;

--- 13 unchanged lines hidden (view full) ---

168 }
169
170 if ($rest !~ /^\s*$/) {
171 die "$name: $.: Gargbage found after TEST_START\n$_";
172 }
173
174 if ($skip) {
175 $test_num = $old_test_num;
165 $repeat = 1;
176 $repeat = $old_repeat;
166 }
167
168 } elsif (/^\s*DEFAULTS(.*)$/) {
169 $default = 1;
170
171 $rest = $1;
172
173 if ($rest =~ /\s+SKIP(.*)/) {

--- 82 unchanged lines hidden (view full) ---

256 print @_;
257 _logit @_;
258}
259
260sub run_command;
261
262sub reboot {
263 # try to reboot normally
177 }
178
179 } elsif (/^\s*DEFAULTS(.*)$/) {
180 $default = 1;
181
182 $rest = $1;
183
184 if ($rest =~ /\s+SKIP(.*)/) {

--- 82 unchanged lines hidden (view full) ---

267 print @_;
268 _logit @_;
269}
270
271sub run_command;
272
273sub reboot {
274 # try to reboot normally
264 if (run_command "ssh $target reboot") {
275 if (run_command $reboot) {
265 if (defined($powercycle_after_reboot)) {
266 sleep $powercycle_after_reboot;
267 run_command "$power_cycle";
268 }
269 } else {
270 # nope? power cycle it.
271 run_command "$power_cycle";
272 }

--- 141 unchanged lines hidden (view full) ---

414}
415
416sub run_command {
417 my ($command) = @_;
418 my $dolog = 0;
419 my $dord = 0;
420 my $pid;
421
276 if (defined($powercycle_after_reboot)) {
277 sleep $powercycle_after_reboot;
278 run_command "$power_cycle";
279 }
280 } else {
281 # nope? power cycle it.
282 run_command "$power_cycle";
283 }

--- 141 unchanged lines hidden (view full) ---

425}
426
427sub run_command {
428 my ($command) = @_;
429 my $dolog = 0;
430 my $dord = 0;
431 my $pid;
432
433 $command =~ s/\$SSH_USER/$ssh_user/g;
434 $command =~ s/\$MACHINE/$machine/g;
435
422 doprint("$command ... ");
423
424 $pid = open(CMD, "$command 2>&1 |") or
425 (fail "unable to exec $command" and return 0);
426
427 if (defined($opt{"LOG_FILE"})) {
428 open(LOG, ">>$opt{LOG_FILE}") or
429 dodie "failed to write to log";

--- 22 unchanged lines hidden (view full) ---

452 doprint "FAILED!\n";
453 } else {
454 doprint "SUCCESS\n";
455 }
456
457 return !$failed;
458}
459
436 doprint("$command ... ");
437
438 $pid = open(CMD, "$command 2>&1 |") or
439 (fail "unable to exec $command" and return 0);
440
441 if (defined($opt{"LOG_FILE"})) {
442 open(LOG, ">>$opt{LOG_FILE}") or
443 dodie "failed to write to log";

--- 22 unchanged lines hidden (view full) ---

466 doprint "FAILED!\n";
467 } else {
468 doprint "SUCCESS\n";
469 }
470
471 return !$failed;
472}
473
474sub run_ssh {
475 my ($cmd) = @_;
476 my $cp_exec = $ssh_exec;
477
478 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
479 return run_command "$cp_exec";
480}
481
482sub run_scp {
483 my ($src, $dst) = @_;
484 my $cp_scp = $scp_to_target;
485
486 $cp_scp =~ s/\$SRC_FILE/$src/g;
487 $cp_scp =~ s/\$DST_FILE/$dst/g;
488
489 return run_command "$cp_scp";
490}
491
460sub get_grub_index {
461
462 if ($reboot_type ne "grub") {
463 return;
464 }
465 return if (defined($grub_number));
466
467 doprint "Find grub menu ... ";
468 $grub_number = -1;
492sub get_grub_index {
493
494 if ($reboot_type ne "grub") {
495 return;
496 }
497 return if (defined($grub_number));
498
499 doprint "Find grub menu ... ";
500 $grub_number = -1;
469 open(IN, "ssh $target cat /boot/grub/menu.lst |")
501
502 my $ssh_grub = $ssh_exec;
503 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
504
505 open(IN, "$ssh_grub |")
470 or die "unable to get menu.lst";
506 or die "unable to get menu.lst";
507
471 while (<IN>) {
472 if (/^\s*title\s+$grub_menu\s*$/) {
473 $grub_number++;
474 last;
475 } elsif (/^\s*title\s/) {
476 $grub_number++;
477 }
478 }

--- 32 unchanged lines hidden (view full) ---

511 return undef;
512 }
513
514 return $line;
515}
516
517sub reboot_to {
518 if ($reboot_type eq "grub") {
508 while (<IN>) {
509 if (/^\s*title\s+$grub_menu\s*$/) {
510 $grub_number++;
511 last;
512 } elsif (/^\s*title\s/) {
513 $grub_number++;
514 }
515 }

--- 32 unchanged lines hidden (view full) ---

548 return undef;
549 }
550
551 return $line;
552}
553
554sub reboot_to {
555 if ($reboot_type eq "grub") {
519 run_command "ssh $target '(echo \"savedefault --default=$grub_number --once\" | grub --batch; reboot)'";
556 run_command "$ssh_exec '(echo \"savedefault --default=$grub_number --once\" | grub --batch; reboot)'";
520 return;
521 }
522
523 run_command "$reboot_script";
524}
525
526sub get_sha1 {
527 my ($commit) = @_;

--- 85 unchanged lines hidden (view full) ---

613 fail "failed - never got a boot prompt." and return 0;
614 }
615
616 return 1;
617}
618
619sub install {
620
557 return;
558 }
559
560 run_command "$reboot_script";
561}
562
563sub get_sha1 {
564 my ($commit) = @_;

--- 85 unchanged lines hidden (view full) ---

650 fail "failed - never got a boot prompt." and return 0;
651 }
652
653 return 1;
654}
655
656sub install {
657
621 run_command "scp $outputdir/$build_target $target:$target_image" or
658 run_scp "$outputdir/$build_target", "$target_image" or
622 dodie "failed to copy image";
623
624 my $install_mods = 0;
625
626 # should we process modules?
627 $install_mods = 0;
628 open(IN, "$output_config") or dodie("Can't read config file");
629 while (<IN>) {

--- 10 unchanged lines hidden (view full) ---

640 }
641
642 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
643 dodie "Failed to install modules";
644
645 my $modlib = "/lib/modules/$version";
646 my $modtar = "ktest-mods.tar.bz2";
647
659 dodie "failed to copy image";
660
661 my $install_mods = 0;
662
663 # should we process modules?
664 $install_mods = 0;
665 open(IN, "$output_config") or dodie("Can't read config file");
666 while (<IN>) {

--- 10 unchanged lines hidden (view full) ---

677 }
678
679 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
680 dodie "Failed to install modules";
681
682 my $modlib = "/lib/modules/$version";
683 my $modtar = "ktest-mods.tar.bz2";
684
648 run_command "ssh $target rm -rf $modlib" or
685 run_ssh "rm -rf $modlib" or
649 dodie "failed to remove old mods: $modlib";
650
651 # would be nice if scp -r did not follow symbolic links
652 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
653 dodie "making tarball";
654
686 dodie "failed to remove old mods: $modlib";
687
688 # would be nice if scp -r did not follow symbolic links
689 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
690 dodie "making tarball";
691
655 run_command "scp $tmpdir/$modtar $target:/tmp" or
692 run_scp "$tmpdir/$modtar", "/tmp" or
656 dodie "failed to copy modules";
657
658 unlink "$tmpdir/$modtar";
659
693 dodie "failed to copy modules";
694
695 unlink "$tmpdir/$modtar";
696
660 run_command "ssh $target '(cd / && tar xf /tmp/$modtar)'" or
697 run_ssh "'(cd / && tar xf /tmp/$modtar)'" or
661 dodie "failed to tar modules";
662
698 dodie "failed to tar modules";
699
663 run_command "ssh $target rm -f /tmp/$modtar";
700 run_ssh "rm -f /tmp/$modtar";
664
665 return if (!defined($post_install));
666
701
702 return if (!defined($post_install));
703
667 my $save_env = $ENV{KERNEL_VERSION};
668
669 $ENV{KERNEL_VERSION} = $version;
670 run_command "$post_install" or
704 my $cp_post_install = $post_install;
705 $cp_post_install = s/\$KERNEL_VERSION/$version/g;
706 run_command "$cp_post_install" or
671 dodie "Failed to run post install";
707 dodie "Failed to run post install";
672
673 $ENV{KERNEL_VERSION} = $save_env;
674}
675
676sub check_buildlog {
677 my ($patch) = @_;
678
679 my @files = `git show $patch | diffstat -l`;
680
681 open(IN, "git show $patch |") or

--- 79 unchanged lines hidden (view full) ---

761 fail "failed build" and return 0;
762 }
763 undef $redirect;
764
765 return 1;
766}
767
768sub halt {
708}
709
710sub check_buildlog {
711 my ($patch) = @_;
712
713 my @files = `git show $patch | diffstat -l`;
714
715 open(IN, "git show $patch |") or

--- 79 unchanged lines hidden (view full) ---

795 fail "failed build" and return 0;
796 }
797 undef $redirect;
798
799 return 1;
800}
801
802sub halt {
769 if (!run_command "ssh $target halt" or defined($power_off)) {
803 if (!run_ssh "halt" or defined($power_off)) {
770 if (defined($poweroff_after_halt)) {
771 sleep $poweroff_after_halt;
772 run_command "$power_off";
773 }
774 } else {
775 # nope? the zap it!
776 run_command "$power_off";
777 }
778}
779
780sub success {
781 my ($i) = @_;
782
804 if (defined($poweroff_after_halt)) {
805 sleep $poweroff_after_halt;
806 run_command "$power_off";
807 }
808 } else {
809 # nope? the zap it!
810 run_command "$power_off";
811 }
812}
813
814sub success {
815 my ($i) = @_;
816
817 $successes++;
818
783 doprint "\n\n*******************************************\n";
784 doprint "*******************************************\n";
785 doprint "KTEST RESULT: TEST $i SUCCESS!!!! **\n";
786 doprint "*******************************************\n";
787 doprint "*******************************************\n";
788
789 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
790 doprint "Reboot and wait $sleep_time seconds\n";

--- 454 unchanged lines hidden (view full) ---

1245 return undef;
1246}
1247
1248# First we need to do is the builds
1249for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
1250
1251 $iteration = $i;
1252
819 doprint "\n\n*******************************************\n";
820 doprint "*******************************************\n";
821 doprint "KTEST RESULT: TEST $i SUCCESS!!!! **\n";
822 doprint "*******************************************\n";
823 doprint "*******************************************\n";
824
825 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
826 doprint "Reboot and wait $sleep_time seconds\n";

--- 454 unchanged lines hidden (view full) ---

1281 return undef;
1282}
1283
1284# First we need to do is the builds
1285for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
1286
1287 $iteration = $i;
1288
1253 my $ssh_user = set_test_option("SSH_USER", $i);
1254 my $makecmd = set_test_option("MAKE_CMD", $i);
1255
1256 $machine = set_test_option("MACHINE", $i);
1289 my $makecmd = set_test_option("MAKE_CMD", $i);
1290
1291 $machine = set_test_option("MACHINE", $i);
1292 $ssh_user = set_test_option("SSH_USER", $i);
1257 $tmpdir = set_test_option("TMP_DIR", $i);
1258 $outputdir = set_test_option("OUTPUT_DIR", $i);
1259 $builddir = set_test_option("BUILD_DIR", $i);
1260 $test_type = set_test_option("TEST_TYPE", $i);
1261 $build_type = set_test_option("BUILD_TYPE", $i);
1262 $build_options = set_test_option("BUILD_OPTIONS", $i);
1263 $power_cycle = set_test_option("POWER_CYCLE", $i);
1293 $tmpdir = set_test_option("TMP_DIR", $i);
1294 $outputdir = set_test_option("OUTPUT_DIR", $i);
1295 $builddir = set_test_option("BUILD_DIR", $i);
1296 $test_type = set_test_option("TEST_TYPE", $i);
1297 $build_type = set_test_option("BUILD_TYPE", $i);
1298 $build_options = set_test_option("BUILD_OPTIONS", $i);
1299 $power_cycle = set_test_option("POWER_CYCLE", $i);
1300 $reboot = set_test_option("REBOOT", $i);
1264 $noclean = set_test_option("BUILD_NOCLEAN", $i);
1265 $minconfig = set_test_option("MIN_CONFIG", $i);
1266 $run_test = set_test_option("TEST", $i);
1267 $addconfig = set_test_option("ADD_CONFIG", $i);
1268 $reboot_type = set_test_option("REBOOT_TYPE", $i);
1269 $grub_menu = set_test_option("GRUB_MENU", $i);
1270 $post_install = set_test_option("POST_INSTALL", $i);
1271 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);

--- 6 unchanged lines hidden (view full) ---

1278 $sleep_time = set_test_option("SLEEP_TIME", $i);
1279 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
1280 $store_failures = set_test_option("STORE_FAILURES", $i);
1281 $timeout = set_test_option("TIMEOUT", $i);
1282 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
1283 $console = set_test_option("CONSOLE", $i);
1284 $success_line = set_test_option("SUCCESS_LINE", $i);
1285 $build_target = set_test_option("BUILD_TARGET", $i);
1301 $noclean = set_test_option("BUILD_NOCLEAN", $i);
1302 $minconfig = set_test_option("MIN_CONFIG", $i);
1303 $run_test = set_test_option("TEST", $i);
1304 $addconfig = set_test_option("ADD_CONFIG", $i);
1305 $reboot_type = set_test_option("REBOOT_TYPE", $i);
1306 $grub_menu = set_test_option("GRUB_MENU", $i);
1307 $post_install = set_test_option("POST_INSTALL", $i);
1308 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);

--- 6 unchanged lines hidden (view full) ---

1315 $sleep_time = set_test_option("SLEEP_TIME", $i);
1316 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
1317 $store_failures = set_test_option("STORE_FAILURES", $i);
1318 $timeout = set_test_option("TIMEOUT", $i);
1319 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
1320 $console = set_test_option("CONSOLE", $i);
1321 $success_line = set_test_option("SUCCESS_LINE", $i);
1322 $build_target = set_test_option("BUILD_TARGET", $i);
1323 $ssh_exec = set_test_option("SSH_EXEC", $i);
1324 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
1286 $target_image = set_test_option("TARGET_IMAGE", $i);
1287 $localversion = set_test_option("LOCALVERSION", $i);
1288
1289 chdir $builddir || die "can't change directory to $builddir";
1290
1291 if (!-d $tmpdir) {
1292 mkpath($tmpdir) or
1293 die "can't create $tmpdir";
1294 }
1295
1325 $target_image = set_test_option("TARGET_IMAGE", $i);
1326 $localversion = set_test_option("LOCALVERSION", $i);
1327
1328 chdir $builddir || die "can't change directory to $builddir";
1329
1330 if (!-d $tmpdir) {
1331 mkpath($tmpdir) or
1332 die "can't create $tmpdir";
1333 }
1334
1335 $ENV{"SSH_USER"} = $ssh_user;
1336 $ENV{"MACHINE"} = $machine;
1337
1296 $target = "$ssh_user\@$machine";
1297
1298 $buildlog = "$tmpdir/buildlog-$machine";
1299 $dmesg = "$tmpdir/dmesg-$machine";
1300 $make = "$makecmd O=$outputdir";
1301 $output_config = "$outputdir/.config";
1338 $target = "$ssh_user\@$machine";
1339
1340 $buildlog = "$tmpdir/buildlog-$machine";
1341 $dmesg = "$tmpdir/dmesg-$machine";
1342 $make = "$makecmd O=$outputdir";
1343 $output_config = "$outputdir/.config";
1344 $output_config = "$outputdir/.config";
1302
1303 if ($reboot_type eq "grub") {
1304 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
1305 } elsif (!defined($reboot_script)) {
1306 dodie "REBOOT_SCRIPT not defined"
1307 }
1308
1309 my $run_type = $build_type;

--- 61 unchanged lines hidden (view full) ---

1371}
1372
1373if ($opt{"POWEROFF_ON_SUCCESS"}) {
1374 halt;
1375} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
1376 reboot;
1377}
1378
1345
1346 if ($reboot_type eq "grub") {
1347 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
1348 } elsif (!defined($reboot_script)) {
1349 dodie "REBOOT_SCRIPT not defined"
1350 }
1351
1352 my $run_type = $build_type;

--- 61 unchanged lines hidden (view full) ---

1414}
1415
1416if ($opt{"POWEROFF_ON_SUCCESS"}) {
1417 halt;
1418} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
1419 reboot;
1420}
1421
1422doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
1423
1379exit 0;
1424exit 0;