ktest.pl (32677207dcc5e594254b7fb4fb2352b1755b1d5b) | ktest.pl (6e98d1b4415fe681ceb245e1374ed5e1942a332b) |
---|---|
1#!/usr/bin/perl -w 2# 3# Copyright 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; --- 1654 unchanged lines hidden (view full) --- 1663 if (defined($post_test)) { 1664 run_command $post_test; 1665 } 1666 1667 return 1; 1668} 1669 1670sub run_command { | 1#!/usr/bin/perl -w 2# 3# Copyright 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; --- 1654 unchanged lines hidden (view full) --- 1663 if (defined($post_test)) { 1664 run_command $post_test; 1665 } 1666 1667 return 1; 1668} 1669 1670sub run_command { |
1671 my ($command, $redirect) = @_; | 1671 my ($command, $redirect, $timeout) = @_; |
1672 my $start_time; 1673 my $end_time; 1674 my $dolog = 0; 1675 my $dord = 0; 1676 my $pid; 1677 | 1672 my $start_time; 1673 my $end_time; 1674 my $dolog = 0; 1675 my $dord = 0; 1676 my $pid; 1677 |
1678 $start_time = time; 1679 | |
1680 $command =~ s/\$SSH_USER/$ssh_user/g; 1681 $command =~ s/\$MACHINE/$machine/g; 1682 1683 doprint("$command ... "); | 1678 $command =~ s/\$SSH_USER/$ssh_user/g; 1679 $command =~ s/\$MACHINE/$machine/g; 1680 1681 doprint("$command ... "); |
1682 $start_time = time; |
|
1684 1685 $pid = open(CMD, "$command 2>&1 |") or 1686 (fail "unable to exec $command" and return 0); 1687 1688 if (defined($opt{"LOG_FILE"})) { 1689 open(LOG, ">>$opt{LOG_FILE}") or 1690 dodie "failed to write to log"; 1691 $dolog = 1; 1692 } 1693 1694 if (defined($redirect)) { 1695 open (RD, ">$redirect") or 1696 dodie "failed to write to redirect $redirect"; 1697 $dord = 1; 1698 } 1699 | 1683 1684 $pid = open(CMD, "$command 2>&1 |") or 1685 (fail "unable to exec $command" and return 0); 1686 1687 if (defined($opt{"LOG_FILE"})) { 1688 open(LOG, ">>$opt{LOG_FILE}") or 1689 dodie "failed to write to log"; 1690 $dolog = 1; 1691 } 1692 1693 if (defined($redirect)) { 1694 open (RD, ">$redirect") or 1695 dodie "failed to write to redirect $redirect"; 1696 $dord = 1; 1697 } 1698 |
1700 while (<CMD>) { 1701 print LOG if ($dolog); 1702 print RD if ($dord); | 1699 my $hit_timeout = 0; 1700 1701 while (1) { 1702 my $fp = \*CMD; 1703 if (defined($timeout)) { 1704 doprint "timeout = $timeout\n"; 1705 } 1706 my $line = wait_for_input($fp, $timeout); 1707 if (!defined($line)) { 1708 my $now = time; 1709 if (defined($timeout) && (($now - $start_time) >= $timeout)) { 1710 doprint "Hit timeout of $timeout, killing process\n"; 1711 $hit_timeout = 1; 1712 kill 9, $pid; 1713 } 1714 last; 1715 } 1716 print LOG $line if ($dolog); 1717 print RD $line if ($dord); |
1703 } 1704 1705 waitpid($pid, 0); 1706 my $failed = $?; 1707 | 1718 } 1719 1720 waitpid($pid, 0); 1721 my $failed = $?; 1722 |
1723 if ($hit_timeout) { 1724 $failed = 1; 1725 } 1726 |
|
1708 close(CMD); 1709 close(LOG) if ($dolog); 1710 close(RD) if ($dord); 1711 1712 $end_time = time; 1713 my $delta = $end_time - $start_time; 1714 1715 if ($delta == 1) { --- 7 unchanged lines hidden (view full) --- 1723 } else { 1724 doprint "SUCCESS\n"; 1725 } 1726 1727 return !$failed; 1728} 1729 1730sub run_ssh { | 1727 close(CMD); 1728 close(LOG) if ($dolog); 1729 close(RD) if ($dord); 1730 1731 $end_time = time; 1732 my $delta = $end_time - $start_time; 1733 1734 if ($delta == 1) { --- 7 unchanged lines hidden (view full) --- 1742 } else { 1743 doprint "SUCCESS\n"; 1744 } 1745 1746 return !$failed; 1747} 1748 1749sub run_ssh { |
1731 my ($cmd) = @_; | 1750 my ($cmd, $timeout) = @_; |
1732 my $cp_exec = $ssh_exec; 1733 1734 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g; | 1751 my $cp_exec = $ssh_exec; 1752 1753 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g; |
1735 return run_command "$cp_exec"; | 1754 return run_command "$cp_exec", undef , $timeout; |
1736} 1737 1738sub run_scp { 1739 my ($src, $dst, $cp_scp) = @_; 1740 1741 $cp_scp =~ s/\$SRC_FILE/$src/g; 1742 $cp_scp =~ s/\$DST_FILE/$dst/g; 1743 --- 2648 unchanged lines hidden --- | 1755} 1756 1757sub run_scp { 1758 my ($src, $dst, $cp_scp) = @_; 1759 1760 $cp_scp =~ s/\$SRC_FILE/$src/g; 1761 $cp_scp =~ s/\$DST_FILE/$dst/g; 1762 --- 2648 unchanged lines hidden --- |