aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/ktest/ktest.pl
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2010-11-02 14:35:37 -0400
committerSteven Rostedt <rostedt@goodmis.org>2010-11-18 11:23:11 -0500
commite48c5293bde398e253f83fdd0247fb2bc71cc92f (patch)
treed0b3fa90b5632e589b52ae0f7e59585b6c7aa515 /tools/testing/ktest/ktest.pl
parent7a849cd93ad2cf7d32427f3dbf5f524d5f588d20 (diff)
ktest/cleanups: Added version 0.2, ssh as options
Updated to version 0.2. Now have SSH_EXEC options. Also added some cleanups for keeping track of success and reading the config file. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'tools/testing/ktest/ktest.pl')
-rwxr-xr-xtools/testing/ktest/ktest.pl81
1 files changed, 63 insertions, 18 deletions
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index e0e5935e94c8..7b6f8e1a82a4 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -11,7 +11,9 @@ use File::Path qw(mkpath);
11use File::Copy qw(cp); 11use File::Copy qw(cp);
12use FileHandle; 12use FileHandle;
13 13
14$#ARGV >= 0 || die "usage: ktest.pl config-file\n"; 14my $VERSION = "0.2";
15
16$#ARGV >= 0 || die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
15 17
16$| = 1; 18$| = 1;
17 19
@@ -40,9 +42,13 @@ $default{"CLEAR_LOG"} = 0;
40$default{"SUCCESS_LINE"} = "login:"; 42$default{"SUCCESS_LINE"} = "login:";
41$default{"BOOTED_TIMEOUT"} = 1; 43$default{"BOOTED_TIMEOUT"} = 1;
42$default{"DIE_ON_FAILURE"} = 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 48
44my $version; 49my $version;
45my $machine; 50my $machine;
51my $ssh_user;
46my $tmpdir; 52my $tmpdir;
47my $builddir; 53my $builddir;
48my $outputdir; 54my $outputdir;
@@ -53,11 +59,14 @@ my $build_options;
53my $reboot_type; 59my $reboot_type;
54my $reboot_script; 60my $reboot_script;
55my $power_cycle; 61my $power_cycle;
62my $reboot;
56my $reboot_on_error; 63my $reboot_on_error;
57my $poweroff_on_error; 64my $poweroff_on_error;
58my $die_on_failure; 65my $die_on_failure;
59my $powercycle_after_reboot; 66my $powercycle_after_reboot;
60my $poweroff_after_halt; 67my $poweroff_after_halt;
68my $ssh_exec;
69my $scp_to_target;
61my $power_off; 70my $power_off;
62my $grub_menu; 71my $grub_menu;
63my $grub_number; 72my $grub_number;
@@ -89,6 +98,7 @@ my $build_target;
89my $target_image; 98my $target_image;
90my $localversion; 99my $localversion;
91my $iteration = 0; 100my $iteration = 0;
101my $successes = 0;
92 102
93sub set_value { 103sub set_value {
94 my ($lvalue, $rvalue) = @_; 104 my ($lvalue, $rvalue) = @_;
@@ -133,6 +143,7 @@ sub read_config {
133 } 143 }
134 144
135 my $old_test_num = $test_num; 145 my $old_test_num = $test_num;
146 my $old_repeat = $repeat;
136 147
137 $test_num += $repeat; 148 $test_num += $repeat;
138 $default = 0; 149 $default = 0;
@@ -162,7 +173,7 @@ sub read_config {
162 173
163 if ($skip) { 174 if ($skip) {
164 $test_num = $old_test_num; 175 $test_num = $old_test_num;
165 $repeat = 1; 176 $repeat = $old_repeat;
166 } 177 }
167 178
168 } elsif (/^\s*DEFAULTS(.*)$/) { 179 } elsif (/^\s*DEFAULTS(.*)$/) {
@@ -261,7 +272,7 @@ sub run_command;
261 272
262sub reboot { 273sub reboot {
263 # try to reboot normally 274 # try to reboot normally
264 if (run_command "ssh $target reboot") { 275 if (run_command $reboot) {
265 if (defined($powercycle_after_reboot)) { 276 if (defined($powercycle_after_reboot)) {
266 sleep $powercycle_after_reboot; 277 sleep $powercycle_after_reboot;
267 run_command "$power_cycle"; 278 run_command "$power_cycle";
@@ -419,6 +430,9 @@ sub run_command {
419 my $dord = 0; 430 my $dord = 0;
420 my $pid; 431 my $pid;
421 432
433 $command =~ s/\$SSH_USER/$ssh_user/g;
434 $command =~ s/\$MACHINE/$machine/g;
435
422 doprint("$command ... "); 436 doprint("$command ... ");
423 437
424 $pid = open(CMD, "$command 2>&1 |") or 438 $pid = open(CMD, "$command 2>&1 |") or
@@ -457,6 +471,24 @@ sub run_command {
457 return !$failed; 471 return !$failed;
458} 472}
459 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 { 492sub get_grub_index {
461 493
462 if ($reboot_type ne "grub") { 494 if ($reboot_type ne "grub") {
@@ -466,8 +498,13 @@ sub get_grub_index {
466 498
467 doprint "Find grub menu ... "; 499 doprint "Find grub menu ... ";
468 $grub_number = -1; 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>) { 508 while (<IN>) {
472 if (/^\s*title\s+$grub_menu\s*$/) { 509 if (/^\s*title\s+$grub_menu\s*$/) {
473 $grub_number++; 510 $grub_number++;
@@ -516,7 +553,7 @@ sub wait_for_input
516 553
517sub reboot_to { 554sub reboot_to {
518 if ($reboot_type eq "grub") { 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; 557 return;
521 } 558 }
522 559
@@ -618,7 +655,7 @@ sub monitor {
618 655
619sub install { 656sub install {
620 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"; 659 dodie "failed to copy image";
623 660
624 my $install_mods = 0; 661 my $install_mods = 0;
@@ -645,32 +682,29 @@ sub install {
645 my $modlib = "/lib/modules/$version"; 682 my $modlib = "/lib/modules/$version";
646 my $modtar = "ktest-mods.tar.bz2"; 683 my $modtar = "ktest-mods.tar.bz2";
647 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"; 686 dodie "failed to remove old mods: $modlib";
650 687
651 # would be nice if scp -r did not follow symbolic links 688 # would be nice if scp -r did not follow symbolic links
652 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or 689 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
653 dodie "making tarball"; 690 dodie "making tarball";
654 691
655 run_command "scp $tmpdir/$modtar $target:/tmp" or 692 run_scp "$tmpdir/$modtar", "/tmp" or
656 dodie "failed to copy modules"; 693 dodie "failed to copy modules";
657 694
658 unlink "$tmpdir/$modtar"; 695 unlink "$tmpdir/$modtar";
659 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"; 698 dodie "failed to tar modules";
662 699
663 run_command "ssh $target rm -f /tmp/$modtar"; 700 run_ssh "rm -f /tmp/$modtar";
664 701
665 return if (!defined($post_install)); 702 return if (!defined($post_install));
666 703
667 my $save_env = $ENV{KERNEL_VERSION}; 704 my $cp_post_install = $post_install;
668 705 $cp_post_install = s/\$KERNEL_VERSION/$version/g;
669 $ENV{KERNEL_VERSION} = $version; 706 run_command "$cp_post_install" or
670 run_command "$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} 708}
675 709
676sub check_buildlog { 710sub check_buildlog {
@@ -766,7 +800,7 @@ sub build {
766} 800}
767 801
768sub halt { 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)) { 804 if (defined($poweroff_after_halt)) {
771 sleep $poweroff_after_halt; 805 sleep $poweroff_after_halt;
772 run_command "$power_off"; 806 run_command "$power_off";
@@ -780,6 +814,8 @@ sub halt {
780sub success { 814sub success {
781 my ($i) = @_; 815 my ($i) = @_;
782 816
817 $successes++;
818
783 doprint "\n\n*******************************************\n"; 819 doprint "\n\n*******************************************\n";
784 doprint "*******************************************\n"; 820 doprint "*******************************************\n";
785 doprint "KTEST RESULT: TEST $i SUCCESS!!!! **\n"; 821 doprint "KTEST RESULT: TEST $i SUCCESS!!!! **\n";
@@ -1250,10 +1286,10 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
1250 1286
1251 $iteration = $i; 1287 $iteration = $i;
1252 1288
1253 my $ssh_user = set_test_option("SSH_USER", $i);
1254 my $makecmd = set_test_option("MAKE_CMD", $i); 1289 my $makecmd = set_test_option("MAKE_CMD", $i);
1255 1290
1256 $machine = set_test_option("MACHINE", $i); 1291 $machine = set_test_option("MACHINE", $i);
1292 $ssh_user = set_test_option("SSH_USER", $i);
1257 $tmpdir = set_test_option("TMP_DIR", $i); 1293 $tmpdir = set_test_option("TMP_DIR", $i);
1258 $outputdir = set_test_option("OUTPUT_DIR", $i); 1294 $outputdir = set_test_option("OUTPUT_DIR", $i);
1259 $builddir = set_test_option("BUILD_DIR", $i); 1295 $builddir = set_test_option("BUILD_DIR", $i);
@@ -1261,6 +1297,7 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
1261 $build_type = set_test_option("BUILD_TYPE", $i); 1297 $build_type = set_test_option("BUILD_TYPE", $i);
1262 $build_options = set_test_option("BUILD_OPTIONS", $i); 1298 $build_options = set_test_option("BUILD_OPTIONS", $i);
1263 $power_cycle = set_test_option("POWER_CYCLE", $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); 1301 $noclean = set_test_option("BUILD_NOCLEAN", $i);
1265 $minconfig = set_test_option("MIN_CONFIG", $i); 1302 $minconfig = set_test_option("MIN_CONFIG", $i);
1266 $run_test = set_test_option("TEST", $i); 1303 $run_test = set_test_option("TEST", $i);
@@ -1283,6 +1320,8 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
1283 $console = set_test_option("CONSOLE", $i); 1320 $console = set_test_option("CONSOLE", $i);
1284 $success_line = set_test_option("SUCCESS_LINE", $i); 1321 $success_line = set_test_option("SUCCESS_LINE", $i);
1285 $build_target = set_test_option("BUILD_TARGET", $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); 1325 $target_image = set_test_option("TARGET_IMAGE", $i);
1287 $localversion = set_test_option("LOCALVERSION", $i); 1326 $localversion = set_test_option("LOCALVERSION", $i);
1288 1327
@@ -1293,12 +1332,16 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
1293 die "can't create $tmpdir"; 1332 die "can't create $tmpdir";
1294 } 1333 }
1295 1334
1335 $ENV{"SSH_USER"} = $ssh_user;
1336 $ENV{"MACHINE"} = $machine;
1337
1296 $target = "$ssh_user\@$machine"; 1338 $target = "$ssh_user\@$machine";
1297 1339
1298 $buildlog = "$tmpdir/buildlog-$machine"; 1340 $buildlog = "$tmpdir/buildlog-$machine";
1299 $dmesg = "$tmpdir/dmesg-$machine"; 1341 $dmesg = "$tmpdir/dmesg-$machine";
1300 $make = "$makecmd O=$outputdir"; 1342 $make = "$makecmd O=$outputdir";
1301 $output_config = "$outputdir/.config"; 1343 $output_config = "$outputdir/.config";
1344 $output_config = "$outputdir/.config";
1302 1345
1303 if ($reboot_type eq "grub") { 1346 if ($reboot_type eq "grub") {
1304 dodie "GRUB_MENU not defined" if (!defined($grub_menu)); 1347 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
@@ -1376,4 +1419,6 @@ if ($opt{"POWEROFF_ON_SUCCESS"}) {
1376 reboot; 1419 reboot;
1377} 1420}
1378 1421
1422doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
1423
1379exit 0; 1424exit 0;