Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

+230 -31
+230 -31
tools/testing/ktest/ktest.pl
··· 178 178 my $localversion; 179 179 my $iteration = 0; 180 180 my $successes = 0; 181 + my $stty_orig; 181 182 182 183 my $bisect_good; 183 184 my $bisect_bad; ··· 197 196 my $patchcheck_start; 198 197 my $patchcheck_cherry; 199 198 my $patchcheck_end; 199 + 200 + my $build_time; 201 + my $install_time; 202 + my $reboot_time; 203 + my $test_time; 200 204 201 205 # set when a test is something other that just building or install 202 206 # which would require more options. ··· 558 552 $entered_configs{$config} = ${ans}; 559 553 last; 560 554 } 555 + } 556 + 557 + sub show_time { 558 + my ($time) = @_; 559 + 560 + my $hours = 0; 561 + my $minutes = 0; 562 + 563 + if ($time > 3600) { 564 + $hours = int($time / 3600); 565 + $time -= $hours * 3600; 566 + } 567 + if ($time > 60) { 568 + $minutes = int($time / 60); 569 + $time -= $minutes * 60; 570 + } 571 + 572 + if ($hours > 0) { 573 + doprint "$hours hour"; 574 + doprint "s" if ($hours > 1); 575 + doprint " "; 576 + } 577 + 578 + if ($minutes > 0) { 579 + doprint "$minutes minute"; 580 + doprint "s" if ($minutes > 1); 581 + doprint " "; 582 + } 583 + 584 + doprint "$time second"; 585 + doprint "s" if ($time != 1); 586 + } 587 + 588 + sub print_times { 589 + doprint "\n"; 590 + if ($build_time) { 591 + doprint "Build time: "; 592 + show_time($build_time); 593 + doprint "\n"; 594 + } 595 + if ($install_time) { 596 + doprint "Install time: "; 597 + show_time($install_time); 598 + doprint "\n"; 599 + } 600 + if ($reboot_time) { 601 + doprint "Reboot time: "; 602 + show_time($reboot_time); 603 + doprint "\n"; 604 + } 605 + if ($test_time) { 606 + doprint "Test time: "; 607 + show_time($test_time); 608 + doprint "\n"; 609 + } 610 + # reset for iterations like bisect 611 + $build_time = 0; 612 + $install_time = 0; 613 + $reboot_time = 0; 614 + $test_time = 0; 561 615 } 562 616 563 617 sub get_mandatory_configs { ··· 1407 1341 print " See $opt{LOG_FILE} for more info.\n"; 1408 1342 } 1409 1343 1344 + if ($monitor_cnt) { 1345 + # restore terminal settings 1346 + system("stty $stty_orig"); 1347 + } 1348 + 1410 1349 die @_, "\n"; 1411 1350 } 1412 1351 1352 + sub create_pty { 1353 + my ($ptm, $pts) = @_; 1354 + my $tmp; 1355 + my $TIOCSPTLCK = 0x40045431; 1356 + my $TIOCGPTN = 0x80045430; 1357 + 1358 + sysopen($ptm, "/dev/ptmx", O_RDWR | O_NONBLOCK) or 1359 + dodie "Cant open /dev/ptmx"; 1360 + 1361 + # unlockpt() 1362 + $tmp = pack("i", 0); 1363 + ioctl($ptm, $TIOCSPTLCK, $tmp) or 1364 + dodie "ioctl TIOCSPTLCK for /dev/ptmx failed"; 1365 + 1366 + # ptsname() 1367 + ioctl($ptm, $TIOCGPTN, $tmp) or 1368 + dodie "ioctl TIOCGPTN for /dev/ptmx failed"; 1369 + $tmp = unpack("i", $tmp); 1370 + 1371 + sysopen($pts, "/dev/pts/$tmp", O_RDWR | O_NONBLOCK) or 1372 + dodie "Can't open /dev/pts/$tmp"; 1373 + } 1374 + 1375 + sub exec_console { 1376 + my ($ptm, $pts) = @_; 1377 + 1378 + close($ptm); 1379 + 1380 + close(\*STDIN); 1381 + close(\*STDOUT); 1382 + close(\*STDERR); 1383 + 1384 + open(\*STDIN, '<&', $pts); 1385 + open(\*STDOUT, '>&', $pts); 1386 + open(\*STDERR, '>&', $pts); 1387 + 1388 + close($pts); 1389 + 1390 + exec $console or 1391 + die "Can't open console $console"; 1392 + } 1393 + 1413 1394 sub open_console { 1414 - my ($fp) = @_; 1395 + my ($ptm) = @_; 1396 + my $pts = \*PTSFD; 1397 + my $pid; 1415 1398 1416 - my $flags; 1399 + # save terminal settings 1400 + $stty_orig = `stty -g`; 1417 1401 1418 - my $pid = open($fp, "$console|") or 1419 - dodie "Can't open console $console"; 1402 + # place terminal in cbreak mode so that stdin can be read one character at 1403 + # a time without having to wait for a newline 1404 + system("stty -icanon -echo -icrnl"); 1420 1405 1421 - $flags = fcntl($fp, F_GETFL, 0) or 1422 - dodie "Can't get flags for the socket: $!"; 1423 - $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or 1424 - dodie "Can't set flags for the socket: $!"; 1406 + create_pty($ptm, $pts); 1407 + 1408 + $pid = fork; 1409 + 1410 + if (!$pid) { 1411 + # child 1412 + exec_console($ptm, $pts) 1413 + } 1414 + 1415 + # parent 1416 + close($pts); 1425 1417 1426 1418 return $pid; 1419 + 1420 + open(PTSFD, "Stop perl from warning about single use of PTSFD"); 1427 1421 } 1428 1422 1429 1423 sub close_console { ··· 1494 1368 1495 1369 print "closing!\n"; 1496 1370 close($fp); 1371 + 1372 + # restore terminal settings 1373 + system("stty $stty_orig"); 1497 1374 } 1498 1375 1499 1376 sub start_monitor { ··· 1648 1519 $name = " ($test_name)"; 1649 1520 } 1650 1521 1522 + print_times; 1523 + 1651 1524 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; 1652 1525 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; 1653 1526 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n"; ··· 1665 1534 1666 1535 sub run_command { 1667 1536 my ($command, $redirect) = @_; 1537 + my $start_time; 1538 + my $end_time; 1668 1539 my $dolog = 0; 1669 1540 my $dord = 0; 1670 1541 my $pid; 1542 + 1543 + $start_time = time; 1671 1544 1672 1545 $command =~ s/\$SSH_USER/$ssh_user/g; 1673 1546 $command =~ s/\$MACHINE/$machine/g; ··· 1704 1569 close(CMD); 1705 1570 close(LOG) if ($dolog); 1706 1571 close(RD) if ($dord); 1572 + 1573 + $end_time = time; 1574 + my $delta = $end_time - $start_time; 1575 + 1576 + if ($delta == 1) { 1577 + doprint "[1 second] "; 1578 + } else { 1579 + doprint "[$delta seconds] "; 1580 + } 1707 1581 1708 1582 if ($failed) { 1709 1583 doprint "FAILED!\n"; ··· 1838 1694 { 1839 1695 my ($fp, $time) = @_; 1840 1696 my $rin; 1841 - my $ready; 1697 + my $rout; 1698 + my $nr; 1699 + my $buf; 1842 1700 my $line; 1843 1701 my $ch; 1844 1702 ··· 1850 1704 1851 1705 $rin = ''; 1852 1706 vec($rin, fileno($fp), 1) = 1; 1853 - ($ready, $time) = select($rin, undef, undef, $time); 1707 + vec($rin, fileno(\*STDIN), 1) = 1; 1854 1708 1855 - $line = ""; 1709 + while (1) { 1710 + $nr = select($rout=$rin, undef, undef, $time); 1856 1711 1857 - # try to read one char at a time 1858 - while (sysread $fp, $ch, 1) { 1859 - $line .= $ch; 1860 - last if ($ch eq "\n"); 1712 + if ($nr <= 0) { 1713 + return undef; 1714 + } 1715 + 1716 + # copy data from stdin to the console 1717 + if (vec($rout, fileno(\*STDIN), 1) == 1) { 1718 + sysread(\*STDIN, $buf, 1000); 1719 + syswrite($fp, $buf, 1000); 1720 + next; 1721 + } 1722 + 1723 + $line = ""; 1724 + 1725 + # try to read one char at a time 1726 + while (sysread $fp, $ch, 1) { 1727 + $line .= $ch; 1728 + last if ($ch eq "\n"); 1729 + } 1730 + 1731 + if (!length($line)) { 1732 + return undef; 1733 + } 1734 + 1735 + return $line; 1861 1736 } 1862 - 1863 - if (!length($line)) { 1864 - return undef; 1865 - } 1866 - 1867 - return $line; 1868 1737 } 1869 1738 1870 1739 sub reboot_to { ··· 1926 1765 my $bug_ignored = 0; 1927 1766 my $skip_call_trace = 0; 1928 1767 my $loops; 1768 + 1769 + my $start_time = time; 1929 1770 1930 1771 wait_for_monitor 5; 1931 1772 ··· 2053 1890 } 2054 1891 } 2055 1892 1893 + my $end_time = time; 1894 + $reboot_time = $end_time - $start_time; 1895 + 2056 1896 close(DMESG); 2057 1897 2058 1898 if ($bug) { ··· 2104 1938 2105 1939 return if ($no_install); 2106 1940 1941 + my $start_time = time; 1942 + 2107 1943 if (defined($pre_install)) { 2108 1944 my $cp_pre_install = eval_kernel_version $pre_install; 2109 1945 run_command "$cp_pre_install" or ··· 2137 1969 if (!$install_mods) { 2138 1970 do_post_install; 2139 1971 doprint "No modules needed\n"; 1972 + my $end_time = time; 1973 + $install_time = $end_time - $start_time; 2140 1974 return; 2141 1975 } 2142 1976 ··· 2166 1996 run_ssh "rm -f /tmp/$modtar"; 2167 1997 2168 1998 do_post_install; 1999 + 2000 + my $end_time = time; 2001 + $install_time = $end_time - $start_time; 2169 2002 } 2170 2003 2171 2004 sub get_version { ··· 2181 2008 $have_version = 1; 2182 2009 } 2183 2010 2184 - sub start_monitor_and_boot { 2011 + sub start_monitor_and_install { 2185 2012 # Make sure the stable kernel has finished booting 2186 2013 2187 2014 # Install bisects, don't need console ··· 2381 2208 2382 2209 unlink $buildlog; 2383 2210 2211 + my $start_time = time; 2212 + 2384 2213 # Failed builds should not reboot the target 2385 2214 my $save_no_reboot = $no_reboot; 2386 2215 $no_reboot = 1; ··· 2468 2293 2469 2294 $no_reboot = $save_no_reboot; 2470 2295 2296 + my $end_time = time; 2297 + $build_time = $end_time - $start_time; 2298 + 2471 2299 return 1; 2472 2300 } 2473 2301 ··· 2500 2322 if (defined($test_name)) { 2501 2323 $name = " ($test_name)"; 2502 2324 } 2325 + 2326 + print_times; 2503 2327 2504 2328 doprint "\n\n*******************************************\n"; 2505 2329 doprint "*******************************************\n"; ··· 2562 2382 my $full_line; 2563 2383 my $bug = 0; 2564 2384 my $bug_ignored = 0; 2385 + 2386 + my $start_time = time; 2565 2387 2566 2388 wait_for_monitor 1; 2567 2389 ··· 2630 2448 2631 2449 waitpid $child_pid, 0; 2632 2450 $child_exit = $?; 2451 + 2452 + my $end_time = time; 2453 + $test_time = $end_time - $start_time; 2633 2454 2634 2455 if (!$bug && $in_bisect) { 2635 2456 if (defined($bisect_ret_good)) { ··· 2734 2549 dodie "Failed on build" if $failed; 2735 2550 2736 2551 # Now boot the box 2737 - start_monitor_and_boot or $failed = 1; 2552 + start_monitor_and_install or $failed = 1; 2738 2553 2739 2554 if ($type ne "boot") { 2740 2555 if ($failed && $bisect_skip) { ··· 2940 2755 do { 2941 2756 $result = run_bisect $type; 2942 2757 $test = run_git_bisect "git bisect $result"; 2758 + print_times; 2943 2759 } while ($test); 2944 2760 2945 2761 run_command "git bisect log" or ··· 3354 3168 3355 3169 do { 3356 3170 $ret = run_config_bisect \%good_configs, \%bad_configs; 3171 + print_times; 3357 3172 } while (!$ret); 3358 3173 3359 3174 return $ret if ($ret < 0); ··· 3447 3260 my $sha1 = $item; 3448 3261 $sha1 =~ s/^([[:xdigit:]]+).*/$1/; 3449 3262 3450 - doprint "\nProcessing commit $item\n\n"; 3263 + doprint "\nProcessing commit \"$item\"\n\n"; 3451 3264 3452 3265 run_command "git checkout $sha1" or 3453 3266 die "Failed to checkout $sha1"; ··· 3478 3291 3479 3292 my $failed = 0; 3480 3293 3481 - start_monitor_and_boot or $failed = 1; 3294 + start_monitor_and_install or $failed = 1; 3482 3295 3483 3296 if (!$failed && $type ne "boot"){ 3484 3297 do_run_test or $failed = 1; 3485 3298 } 3486 3299 end_monitor; 3487 - return 0 if ($failed); 3488 - 3300 + if ($failed) { 3301 + print_times; 3302 + return 0; 3303 + } 3489 3304 patchcheck_reboot; 3490 - 3305 + print_times; 3491 3306 } 3492 3307 $in_patchcheck = 0; 3493 3308 success $i; ··· 3942 3753 my $failed = 0; 3943 3754 build "oldconfig" or $failed = 1; 3944 3755 if (!$failed) { 3945 - start_monitor_and_boot or $failed = 1; 3756 + start_monitor_and_install or $failed = 1; 3946 3757 3947 3758 if ($type eq "test" && !$failed) { 3948 3759 do_run_test or $failed = 1; ··· 4189 4000 4190 4001 $iteration = $i; 4191 4002 4003 + $build_time = 0; 4004 + $install_time = 0; 4005 + $reboot_time = 0; 4006 + $test_time = 0; 4007 + 4192 4008 undef %force_config; 4193 4009 4194 4010 my $makecmd = set_test_option("MAKE_CMD", $i); ··· 4351 4157 4352 4158 if ($test_type ne "build") { 4353 4159 my $failed = 0; 4354 - start_monitor_and_boot or $failed = 1; 4160 + start_monitor_and_install or $failed = 1; 4355 4161 4356 4162 if (!$failed && $test_type ne "boot" && defined($run_test)) { 4357 4163 do_run_test or $failed = 1; 4358 4164 } 4359 4165 end_monitor; 4360 - next if ($failed); 4166 + if ($failed) { 4167 + print_times; 4168 + next; 4169 + } 4361 4170 } 4171 + 4172 + print_times; 4362 4173 4363 4174 success $i; 4364 4175 }