diff options
-rwxr-xr-x | tools/testing/ktest/ktest.pl | 81 |
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); | |||
11 | use File::Copy qw(cp); | 11 | use File::Copy qw(cp); |
12 | use FileHandle; | 12 | use FileHandle; |
13 | 13 | ||
14 | $#ARGV >= 0 || die "usage: ktest.pl config-file\n"; | 14 | my $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 | ||
44 | my $version; | 49 | my $version; |
45 | my $machine; | 50 | my $machine; |
51 | my $ssh_user; | ||
46 | my $tmpdir; | 52 | my $tmpdir; |
47 | my $builddir; | 53 | my $builddir; |
48 | my $outputdir; | 54 | my $outputdir; |
@@ -53,11 +59,14 @@ my $build_options; | |||
53 | my $reboot_type; | 59 | my $reboot_type; |
54 | my $reboot_script; | 60 | my $reboot_script; |
55 | my $power_cycle; | 61 | my $power_cycle; |
62 | my $reboot; | ||
56 | my $reboot_on_error; | 63 | my $reboot_on_error; |
57 | my $poweroff_on_error; | 64 | my $poweroff_on_error; |
58 | my $die_on_failure; | 65 | my $die_on_failure; |
59 | my $powercycle_after_reboot; | 66 | my $powercycle_after_reboot; |
60 | my $poweroff_after_halt; | 67 | my $poweroff_after_halt; |
68 | my $ssh_exec; | ||
69 | my $scp_to_target; | ||
61 | my $power_off; | 70 | my $power_off; |
62 | my $grub_menu; | 71 | my $grub_menu; |
63 | my $grub_number; | 72 | my $grub_number; |
@@ -89,6 +98,7 @@ my $build_target; | |||
89 | my $target_image; | 98 | my $target_image; |
90 | my $localversion; | 99 | my $localversion; |
91 | my $iteration = 0; | 100 | my $iteration = 0; |
101 | my $successes = 0; | ||
92 | 102 | ||
93 | sub set_value { | 103 | sub 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 | ||
262 | sub reboot { | 273 | sub 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 | ||
474 | sub 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 | |||
482 | sub 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 | |||
460 | sub get_grub_index { | 492 | sub 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 | ||
517 | sub reboot_to { | 554 | sub 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 | ||
619 | sub install { | 656 | sub 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 | ||
676 | sub check_buildlog { | 710 | sub check_buildlog { |
@@ -766,7 +800,7 @@ sub build { | |||
766 | } | 800 | } |
767 | 801 | ||
768 | sub halt { | 802 | sub 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 { | |||
780 | sub success { | 814 | sub 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 | ||
1422 | doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n"; | ||
1423 | |||
1379 | exit 0; | 1424 | exit 0; |