aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2015-02-12 11:36:38 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2015-02-12 11:36:38 -0500
commit12df4289ee8e4dccf932b7186b391bb6d2b915fa (patch)
treecef475ddac505eb140ebe3ff55610aef2734c6d7 /tools/testing
parent8cc748aa76c921d8834ef00f762f31acd2c93aa8 (diff)
parent7c2c49eceb79eb4738f38a00270830057b5bfb76 (diff)
Merge tag 'ktest-v3.20' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-ktest
Pull ktest updates from Steven Rostedt: "The following ktest updates were done: o Added timings to various parts of the test (build, install, boot, tests) and report them so that the users can keep track of changes. o Josh Poimboeuf fixed the console output to work better with virtual machine targets. o Various clean ups and fixes" * tag 'ktest-v3.20' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-ktest: ktest: Place quotes around item variable ktest: Cleanup terminal on dodie() failure ktest: Print build,install,boot,test times at success and failure ktest: Enable user input to the console ktest: Give console process a dedicated tty ktest: Rename start_monitor_and_boot to start_monitor_and_install ktest: Show times for build, install, boot and test ktest: Restore tty settings after closing console ktest: Add timings for commands
Diffstat (limited to 'tools/testing')
-rwxr-xr-xtools/testing/ktest/ktest.pl259
1 files changed, 229 insertions, 30 deletions
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index b9cd036f0442..d08e214ec6e7 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -178,6 +178,7 @@ my $checkout;
178my $localversion; 178my $localversion;
179my $iteration = 0; 179my $iteration = 0;
180my $successes = 0; 180my $successes = 0;
181my $stty_orig;
181 182
182my $bisect_good; 183my $bisect_good;
183my $bisect_bad; 184my $bisect_bad;
@@ -197,6 +198,11 @@ my $patchcheck_start;
197my $patchcheck_cherry; 198my $patchcheck_cherry;
198my $patchcheck_end; 199my $patchcheck_end;
199 200
201my $build_time;
202my $install_time;
203my $reboot_time;
204my $test_time;
205
200# set when a test is something other that just building or install 206# set when a test is something other that just building or install
201# which would require more options. 207# which would require more options.
202my $buildonly = 1; 208my $buildonly = 1;
@@ -554,6 +560,66 @@ sub get_mandatory_config {
554 } 560 }
555} 561}
556 562
563sub show_time {
564 my ($time) = @_;
565
566 my $hours = 0;
567 my $minutes = 0;
568
569 if ($time > 3600) {
570 $hours = int($time / 3600);
571 $time -= $hours * 3600;
572 }
573 if ($time > 60) {
574 $minutes = int($time / 60);
575 $time -= $minutes * 60;
576 }
577
578 if ($hours > 0) {
579 doprint "$hours hour";
580 doprint "s" if ($hours > 1);
581 doprint " ";
582 }
583
584 if ($minutes > 0) {
585 doprint "$minutes minute";
586 doprint "s" if ($minutes > 1);
587 doprint " ";
588 }
589
590 doprint "$time second";
591 doprint "s" if ($time != 1);
592}
593
594sub print_times {
595 doprint "\n";
596 if ($build_time) {
597 doprint "Build time: ";
598 show_time($build_time);
599 doprint "\n";
600 }
601 if ($install_time) {
602 doprint "Install time: ";
603 show_time($install_time);
604 doprint "\n";
605 }
606 if ($reboot_time) {
607 doprint "Reboot time: ";
608 show_time($reboot_time);
609 doprint "\n";
610 }
611 if ($test_time) {
612 doprint "Test time: ";
613 show_time($test_time);
614 doprint "\n";
615 }
616 # reset for iterations like bisect
617 $build_time = 0;
618 $install_time = 0;
619 $reboot_time = 0;
620 $test_time = 0;
621}
622
557sub get_mandatory_configs { 623sub get_mandatory_configs {
558 get_mandatory_config("MACHINE"); 624 get_mandatory_config("MACHINE");
559 get_mandatory_config("BUILD_DIR"); 625 get_mandatory_config("BUILD_DIR");
@@ -1341,23 +1407,83 @@ sub dodie {
1341 print " See $opt{LOG_FILE} for more info.\n"; 1407 print " See $opt{LOG_FILE} for more info.\n";
1342 } 1408 }
1343 1409
1410 if ($monitor_cnt) {
1411 # restore terminal settings
1412 system("stty $stty_orig");
1413 }
1414
1344 die @_, "\n"; 1415 die @_, "\n";
1345} 1416}
1346 1417
1418sub create_pty {
1419 my ($ptm, $pts) = @_;
1420 my $tmp;
1421 my $TIOCSPTLCK = 0x40045431;
1422 my $TIOCGPTN = 0x80045430;
1423
1424 sysopen($ptm, "/dev/ptmx", O_RDWR | O_NONBLOCK) or
1425 dodie "Cant open /dev/ptmx";
1426
1427 # unlockpt()
1428 $tmp = pack("i", 0);
1429 ioctl($ptm, $TIOCSPTLCK, $tmp) or
1430 dodie "ioctl TIOCSPTLCK for /dev/ptmx failed";
1431
1432 # ptsname()
1433 ioctl($ptm, $TIOCGPTN, $tmp) or
1434 dodie "ioctl TIOCGPTN for /dev/ptmx failed";
1435 $tmp = unpack("i", $tmp);
1436
1437 sysopen($pts, "/dev/pts/$tmp", O_RDWR | O_NONBLOCK) or
1438 dodie "Can't open /dev/pts/$tmp";
1439}
1440
1441sub exec_console {
1442 my ($ptm, $pts) = @_;
1443
1444 close($ptm);
1445
1446 close(\*STDIN);
1447 close(\*STDOUT);
1448 close(\*STDERR);
1449
1450 open(\*STDIN, '<&', $pts);
1451 open(\*STDOUT, '>&', $pts);
1452 open(\*STDERR, '>&', $pts);
1453
1454 close($pts);
1455
1456 exec $console or
1457 die "Can't open console $console";
1458}
1459
1347sub open_console { 1460sub open_console {
1348 my ($fp) = @_; 1461 my ($ptm) = @_;
1462 my $pts = \*PTSFD;
1463 my $pid;
1349 1464
1350 my $flags; 1465 # save terminal settings
1466 $stty_orig = `stty -g`;
1351 1467
1352 my $pid = open($fp, "$console|") or 1468 # place terminal in cbreak mode so that stdin can be read one character at
1353 dodie "Can't open console $console"; 1469 # a time without having to wait for a newline
1470 system("stty -icanon -echo -icrnl");
1354 1471
1355 $flags = fcntl($fp, F_GETFL, 0) or 1472 create_pty($ptm, $pts);
1356 dodie "Can't get flags for the socket: $!"; 1473
1357 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or 1474 $pid = fork;
1358 dodie "Can't set flags for the socket: $!"; 1475
1476 if (!$pid) {
1477 # child
1478 exec_console($ptm, $pts)
1479 }
1480
1481 # parent
1482 close($pts);
1359 1483
1360 return $pid; 1484 return $pid;
1485
1486 open(PTSFD, "Stop perl from warning about single use of PTSFD");
1361} 1487}
1362 1488
1363sub close_console { 1489sub close_console {
@@ -1368,6 +1494,9 @@ sub close_console {
1368 1494
1369 print "closing!\n"; 1495 print "closing!\n";
1370 close($fp); 1496 close($fp);
1497
1498 # restore terminal settings
1499 system("stty $stty_orig");
1371} 1500}
1372 1501
1373sub start_monitor { 1502sub start_monitor {
@@ -1519,6 +1648,8 @@ sub fail {
1519 $name = " ($test_name)"; 1648 $name = " ($test_name)";
1520 } 1649 }
1521 1650
1651 print_times;
1652
1522 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; 1653 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1523 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; 1654 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1524 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n"; 1655 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
@@ -1534,10 +1665,14 @@ sub fail {
1534 1665
1535sub run_command { 1666sub run_command {
1536 my ($command, $redirect) = @_; 1667 my ($command, $redirect) = @_;
1668 my $start_time;
1669 my $end_time;
1537 my $dolog = 0; 1670 my $dolog = 0;
1538 my $dord = 0; 1671 my $dord = 0;
1539 my $pid; 1672 my $pid;
1540 1673
1674 $start_time = time;
1675
1541 $command =~ s/\$SSH_USER/$ssh_user/g; 1676 $command =~ s/\$SSH_USER/$ssh_user/g;
1542 $command =~ s/\$MACHINE/$machine/g; 1677 $command =~ s/\$MACHINE/$machine/g;
1543 1678
@@ -1570,6 +1705,15 @@ sub run_command {
1570 close(LOG) if ($dolog); 1705 close(LOG) if ($dolog);
1571 close(RD) if ($dord); 1706 close(RD) if ($dord);
1572 1707
1708 $end_time = time;
1709 my $delta = $end_time - $start_time;
1710
1711 if ($delta == 1) {
1712 doprint "[1 second] ";
1713 } else {
1714 doprint "[$delta seconds] ";
1715 }
1716
1573 if ($failed) { 1717 if ($failed) {
1574 doprint "FAILED!\n"; 1718 doprint "FAILED!\n";
1575 } else { 1719 } else {
@@ -1694,7 +1838,9 @@ sub wait_for_input
1694{ 1838{
1695 my ($fp, $time) = @_; 1839 my ($fp, $time) = @_;
1696 my $rin; 1840 my $rin;
1697 my $ready; 1841 my $rout;
1842 my $nr;
1843 my $buf;
1698 my $line; 1844 my $line;
1699 my $ch; 1845 my $ch;
1700 1846
@@ -1704,21 +1850,36 @@ sub wait_for_input
1704 1850
1705 $rin = ''; 1851 $rin = '';
1706 vec($rin, fileno($fp), 1) = 1; 1852 vec($rin, fileno($fp), 1) = 1;
1707 ($ready, $time) = select($rin, undef, undef, $time); 1853 vec($rin, fileno(\*STDIN), 1) = 1;
1708 1854
1709 $line = ""; 1855 while (1) {
1856 $nr = select($rout=$rin, undef, undef, $time);
1710 1857
1711 # try to read one char at a time 1858 if ($nr <= 0) {
1712 while (sysread $fp, $ch, 1) { 1859 return undef;
1713 $line .= $ch; 1860 }
1714 last if ($ch eq "\n");
1715 }
1716 1861
1717 if (!length($line)) { 1862 # copy data from stdin to the console
1718 return undef; 1863 if (vec($rout, fileno(\*STDIN), 1) == 1) {
1719 } 1864 sysread(\*STDIN, $buf, 1000);
1865 syswrite($fp, $buf, 1000);
1866 next;
1867 }
1720 1868
1721 return $line; 1869 $line = "";
1870
1871 # try to read one char at a time
1872 while (sysread $fp, $ch, 1) {
1873 $line .= $ch;
1874 last if ($ch eq "\n");
1875 }
1876
1877 if (!length($line)) {
1878 return undef;
1879 }
1880
1881 return $line;
1882 }
1722} 1883}
1723 1884
1724sub reboot_to { 1885sub reboot_to {
@@ -1766,6 +1927,8 @@ sub monitor {
1766 my $skip_call_trace = 0; 1927 my $skip_call_trace = 0;
1767 my $loops; 1928 my $loops;
1768 1929
1930 my $start_time = time;
1931
1769 wait_for_monitor 5; 1932 wait_for_monitor 5;
1770 1933
1771 my $line; 1934 my $line;
@@ -1890,6 +2053,9 @@ sub monitor {
1890 } 2053 }
1891 } 2054 }
1892 2055
2056 my $end_time = time;
2057 $reboot_time = $end_time - $start_time;
2058
1893 close(DMESG); 2059 close(DMESG);
1894 2060
1895 if ($bug) { 2061 if ($bug) {
@@ -1938,6 +2104,8 @@ sub install {
1938 2104
1939 return if ($no_install); 2105 return if ($no_install);
1940 2106
2107 my $start_time = time;
2108
1941 if (defined($pre_install)) { 2109 if (defined($pre_install)) {
1942 my $cp_pre_install = eval_kernel_version $pre_install; 2110 my $cp_pre_install = eval_kernel_version $pre_install;
1943 run_command "$cp_pre_install" or 2111 run_command "$cp_pre_install" or
@@ -1969,6 +2137,8 @@ sub install {
1969 if (!$install_mods) { 2137 if (!$install_mods) {
1970 do_post_install; 2138 do_post_install;
1971 doprint "No modules needed\n"; 2139 doprint "No modules needed\n";
2140 my $end_time = time;
2141 $install_time = $end_time - $start_time;
1972 return; 2142 return;
1973 } 2143 }
1974 2144
@@ -1996,6 +2166,9 @@ sub install {
1996 run_ssh "rm -f /tmp/$modtar"; 2166 run_ssh "rm -f /tmp/$modtar";
1997 2167
1998 do_post_install; 2168 do_post_install;
2169
2170 my $end_time = time;
2171 $install_time = $end_time - $start_time;
1999} 2172}
2000 2173
2001sub get_version { 2174sub get_version {
@@ -2008,7 +2181,7 @@ sub get_version {
2008 $have_version = 1; 2181 $have_version = 1;
2009} 2182}
2010 2183
2011sub start_monitor_and_boot { 2184sub start_monitor_and_install {
2012 # Make sure the stable kernel has finished booting 2185 # Make sure the stable kernel has finished booting
2013 2186
2014 # Install bisects, don't need console 2187 # Install bisects, don't need console
@@ -2208,6 +2381,8 @@ sub build {
2208 2381
2209 unlink $buildlog; 2382 unlink $buildlog;
2210 2383
2384 my $start_time = time;
2385
2211 # Failed builds should not reboot the target 2386 # Failed builds should not reboot the target
2212 my $save_no_reboot = $no_reboot; 2387 my $save_no_reboot = $no_reboot;
2213 $no_reboot = 1; 2388 $no_reboot = 1;
@@ -2293,6 +2468,9 @@ sub build {
2293 2468
2294 $no_reboot = $save_no_reboot; 2469 $no_reboot = $save_no_reboot;
2295 2470
2471 my $end_time = time;
2472 $build_time = $end_time - $start_time;
2473
2296 return 1; 2474 return 1;
2297} 2475}
2298 2476
@@ -2323,6 +2501,8 @@ sub success {
2323 $name = " ($test_name)"; 2501 $name = " ($test_name)";
2324 } 2502 }
2325 2503
2504 print_times;
2505
2326 doprint "\n\n*******************************************\n"; 2506 doprint "\n\n*******************************************\n";
2327 doprint "*******************************************\n"; 2507 doprint "*******************************************\n";
2328 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n"; 2508 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
@@ -2383,6 +2563,8 @@ sub do_run_test {
2383 my $bug = 0; 2563 my $bug = 0;
2384 my $bug_ignored = 0; 2564 my $bug_ignored = 0;
2385 2565
2566 my $start_time = time;
2567
2386 wait_for_monitor 1; 2568 wait_for_monitor 1;
2387 2569
2388 doprint "run test $run_test\n"; 2570 doprint "run test $run_test\n";
@@ -2449,6 +2631,9 @@ sub do_run_test {
2449 waitpid $child_pid, 0; 2631 waitpid $child_pid, 0;
2450 $child_exit = $?; 2632 $child_exit = $?;
2451 2633
2634 my $end_time = time;
2635 $test_time = $end_time - $start_time;
2636
2452 if (!$bug && $in_bisect) { 2637 if (!$bug && $in_bisect) {
2453 if (defined($bisect_ret_good)) { 2638 if (defined($bisect_ret_good)) {
2454 if ($child_exit == $bisect_ret_good) { 2639 if ($child_exit == $bisect_ret_good) {
@@ -2549,7 +2734,7 @@ sub run_bisect_test {
2549 dodie "Failed on build" if $failed; 2734 dodie "Failed on build" if $failed;
2550 2735
2551 # Now boot the box 2736 # Now boot the box
2552 start_monitor_and_boot or $failed = 1; 2737 start_monitor_and_install or $failed = 1;
2553 2738
2554 if ($type ne "boot") { 2739 if ($type ne "boot") {
2555 if ($failed && $bisect_skip) { 2740 if ($failed && $bisect_skip) {
@@ -2755,6 +2940,7 @@ sub bisect {
2755 do { 2940 do {
2756 $result = run_bisect $type; 2941 $result = run_bisect $type;
2757 $test = run_git_bisect "git bisect $result"; 2942 $test = run_git_bisect "git bisect $result";
2943 print_times;
2758 } while ($test); 2944 } while ($test);
2759 2945
2760 run_command "git bisect log" or 2946 run_command "git bisect log" or
@@ -3168,6 +3354,7 @@ sub config_bisect {
3168 3354
3169 do { 3355 do {
3170 $ret = run_config_bisect \%good_configs, \%bad_configs; 3356 $ret = run_config_bisect \%good_configs, \%bad_configs;
3357 print_times;
3171 } while (!$ret); 3358 } while (!$ret);
3172 3359
3173 return $ret if ($ret < 0); 3360 return $ret if ($ret < 0);
@@ -3260,7 +3447,7 @@ sub patchcheck {
3260 my $sha1 = $item; 3447 my $sha1 = $item;
3261 $sha1 =~ s/^([[:xdigit:]]+).*/$1/; 3448 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
3262 3449
3263 doprint "\nProcessing commit $item\n\n"; 3450 doprint "\nProcessing commit \"$item\"\n\n";
3264 3451
3265 run_command "git checkout $sha1" or 3452 run_command "git checkout $sha1" or
3266 die "Failed to checkout $sha1"; 3453 die "Failed to checkout $sha1";
@@ -3291,16 +3478,18 @@ sub patchcheck {
3291 3478
3292 my $failed = 0; 3479 my $failed = 0;
3293 3480
3294 start_monitor_and_boot or $failed = 1; 3481 start_monitor_and_install or $failed = 1;
3295 3482
3296 if (!$failed && $type ne "boot"){ 3483 if (!$failed && $type ne "boot"){
3297 do_run_test or $failed = 1; 3484 do_run_test or $failed = 1;
3298 } 3485 }
3299 end_monitor; 3486 end_monitor;
3300 return 0 if ($failed); 3487 if ($failed) {
3301 3488 print_times;
3489 return 0;
3490 }
3302 patchcheck_reboot; 3491 patchcheck_reboot;
3303 3492 print_times;
3304 } 3493 }
3305 $in_patchcheck = 0; 3494 $in_patchcheck = 0;
3306 success $i; 3495 success $i;
@@ -3753,7 +3942,7 @@ sub make_min_config {
3753 my $failed = 0; 3942 my $failed = 0;
3754 build "oldconfig" or $failed = 1; 3943 build "oldconfig" or $failed = 1;
3755 if (!$failed) { 3944 if (!$failed) {
3756 start_monitor_and_boot or $failed = 1; 3945 start_monitor_and_install or $failed = 1;
3757 3946
3758 if ($type eq "test" && !$failed) { 3947 if ($type eq "test" && !$failed) {
3759 do_run_test or $failed = 1; 3948 do_run_test or $failed = 1;
@@ -4000,6 +4189,11 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
4000 4189
4001 $iteration = $i; 4190 $iteration = $i;
4002 4191
4192 $build_time = 0;
4193 $install_time = 0;
4194 $reboot_time = 0;
4195 $test_time = 0;
4196
4003 undef %force_config; 4197 undef %force_config;
4004 4198
4005 my $makecmd = set_test_option("MAKE_CMD", $i); 4199 my $makecmd = set_test_option("MAKE_CMD", $i);
@@ -4157,15 +4351,20 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
4157 4351
4158 if ($test_type ne "build") { 4352 if ($test_type ne "build") {
4159 my $failed = 0; 4353 my $failed = 0;
4160 start_monitor_and_boot or $failed = 1; 4354 start_monitor_and_install or $failed = 1;
4161 4355
4162 if (!$failed && $test_type ne "boot" && defined($run_test)) { 4356 if (!$failed && $test_type ne "boot" && defined($run_test)) {
4163 do_run_test or $failed = 1; 4357 do_run_test or $failed = 1;
4164 } 4358 }
4165 end_monitor; 4359 end_monitor;
4166 next if ($failed); 4360 if ($failed) {
4361 print_times;
4362 next;
4363 }
4167 } 4364 }
4168 4365
4366 print_times;
4367
4169 success $i; 4368 success $i;
4170} 4369}
4171 4370