]> xenbits.xensource.com Git - people/aperard/osstest.git/commitdiff
TestSupport: target_cmd_output_root_status: New sub
authorKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Mon, 12 Dec 2016 18:48:37 +0000 (13:48 -0500)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Fri, 9 Jun 2017 14:34:24 +0000 (15:34 +0100)
Similar to target_cmd_root_status except it outputs both output _and_
status.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Osstest/TestSupport.pm

index f54962aa87bea619ded8750f03256f8842a7d4dc..fc1aa7db92a8165c6f602b71d4a0df6acfd84228 100644 (file)
@@ -52,7 +52,7 @@ BEGIN {
                       unique_incrementing_runvar next_unique_name
                       stashfilecontents
 
-                      target_cmd_root_status
+                      target_cmd_root_status target_cmd_output_root_status
                       target_cmd_root target_cmd target_cmd_build
                       target_cmd_output_root target_cmd_output
                       target_cmd_inputfh_root sshuho
@@ -708,19 +708,25 @@ sub target_cmd_root_status ($$;$$) { tcmd(undef,undef,1, 'root',@_); }
 
 sub tcmdout {
     my $stdout= IO::File::new_tmpfile();
-    tcmd(undef,$stdout,0,@_);
+    my $badstatusok = $_[1];
+    my $rc = tcmd(undef,$stdout,@_);
     $stdout->seek(0,0) or die "$stdout $!";
     my $r;
     { local ($/) = undef;
       $r= <$stdout>; }
     die "$stdout $!" if !defined $r or $stdout->error or !close $stdout;
     chomp($r);
+    return ($rc, $r) if $badstatusok;
     return $r;
 }
 
 # Like target_cmd[_root], but collect the stdout and return it as a string.
-sub target_cmd_output ($$;$) { tcmdout('osstest',@_); }
-sub target_cmd_output_root ($$;$) { tcmdout('root',@_); }
+# Like target_cmd[_root], but collects the stdout and returns it as a string.
+sub target_cmd_output ($$;$) { tcmdout(0, 'osstest',@_); }
+sub target_cmd_output_root ($$;$) { tcmdout(0, 'root',@_); }
+
+# Like target_cmd_root_status but returns a tuple ($?, $stdout_data).
+sub target_cmd_output_root_status ($$;$$) { tcmdout(1, 'root',@_); }
 
 sub target_cmd_inputfh_root ($$$;$$) {
     my ($tho,$stdinfh,$tcmd,@rest) = @_;