]> xenbits.xensource.com Git - osstest.git/commitdiff
TestSupport: Honour $stdin fh argument to cmd, tcmd and tcmdex
authorIan Jackson <ian.jackson@eu.citrix.com>
Mon, 28 Sep 2015 15:29:33 +0000 (16:29 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Tue, 29 Sep 2015 15:36:07 +0000 (16:36 +0100)
These are internal functions, so the change is entirely within
TestSupport.  All the call sites are adjusted to pass undef so there
is no functional change.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Osstest/TestSupport.pm

index 7b9d8159c113b6ae3031b6c55d235da39c39fe80..91829a0ac7b2da4af0a47f03316578cb9cc98ea8 100644 (file)
@@ -323,9 +323,13 @@ sub target_adjust_timeout ($$) {
 #---------- running commands eg on targets ----------
 
 sub cmd {
-    my ($timeout,$stdout,@cmd) = @_;
+    my ($timeout,$stdin,$stdout,@cmd) = @_;
     my $child= fork;  die $! unless defined $child;
     if (!$child) {
+        if (defined $stdin) {
+            open STDIN, '<&', $stdin
+                or die "STDIN $stdin $cmd[0] $!";
+        }
         if (defined $stdout) {
             open STDOUT, '>&', $stdout
                 or die "STDOUT $stdout $cmd[0] $!";
@@ -395,19 +399,20 @@ sub sshopts () {
 }
 
 sub tcmdex {
-    my ($timeout,$stdout,$cmd,$optsref,@args) = @_;
+    my ($timeout,$stdin,$stdout,$cmd,$optsref,@args) = @_;
     logm("executing $cmd ... @args");
     # We use timeout(1) as a backstop, in case $cmd doesn't die.  We
     # need $cmd to die because we won't release the resources we own
     # until all of our children are dead.
-    my $r= cmd($timeout,$stdout, 'timeout',$timeout+30, $cmd,@$optsref,@args);
+    my $r= cmd($timeout,$stdin,$stdout,
+              'timeout',$timeout+30, $cmd,@$optsref,@args);
     $r and die "status $r";
 }
 
 sub tgetfileex {
     my ($ruser, $ho,$timeout, $rsrc,$ldst) = @_;
     unlink $ldst or $!==&ENOENT or die "$ldst $!";
-    tcmdex($timeout,undef,
+    tcmdex($timeout,undef,undef,
            'scp', sshopts(),
            sshuho($ruser,$ho).":$rsrc", $ldst);
 } 
@@ -424,12 +429,12 @@ sub tputfileex {
     my ($ruser, $ho,$timeout, $lsrc,$rdst, $rsync) = @_;
     my @args= ($lsrc, sshuho($ruser,$ho).":$rdst");
     if (!defined $rsync) {
-        tcmdex($timeout,undef,
+        tcmdex($timeout,undef,undef,
                'scp', sshopts(),
                @args);
     } else {
         unshift @args, $rsync if length $rsync;
-        tcmdex($timeout,undef,
+        tcmdex($timeout,undef,undef,
                'rsync', [ '-e', 'ssh '.join(' ',@{ sshopts() }) ],
                @args);
     }
@@ -625,19 +630,19 @@ sub target_await_down ($$) {
 }    
 
 sub tcmd { # $tcmd will be put between '' but not escaped
-    my ($stdout,$user,$ho,$tcmd,$timeout,$extrasshopts) = @_;
+    my ($stdin,$stdout,$user,$ho,$tcmd,$timeout,$extrasshopts) = @_;
     $timeout=30 if !defined $timeout;
     target_adjust_timeout($ho,\$timeout);
-    tcmdex($timeout,$stdout,
+    tcmdex($timeout,$stdin,$stdout,
            'ssh', sshopts(), @{ $extrasshopts || [] },
            sshuho($user,$ho), $tcmd);
 }
-sub target_cmd ($$;$$) { tcmd(undef,'osstest',@_); }
-sub target_cmd_root ($$;$$) { tcmd(undef,'root',@_); }
+sub target_cmd ($$;$$) { tcmd(undef,undef,'osstest',@_); }
+sub target_cmd_root ($$;$$) { tcmd(undef,undef,'root',@_); }
 
 sub tcmdout {
     my $stdout= IO::File::new_tmpfile();
-    tcmd($stdout,@_);
+    tcmd(undef,$stdout,@_);
     $stdout->seek(0,0) or die "$stdout $!";
     my $r;
     { local ($/) = undef;