diff mbox

[OSSTEST,03/11] TestSupport: target_cmd_output_root_status: New sub

Message ID 1496857742-20191-4-git-send-email-ian.jackson@eu.citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Ian Jackson June 7, 2017, 5:48 p.m. UTC
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

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>
---
v2: Initial posting
v3: Sprinkle some comments.
v4: Move doc comments out of this patch (and rewrite them).
    Edit commit message.
---
 Osstest/TestSupport.pm | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/Osstest/TestSupport.pm b/Osstest/TestSupport.pm
index f54962a..fc1aa7d 100644
--- a/Osstest/TestSupport.pm
+++ b/Osstest/TestSupport.pm
@@ -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) = @_;