[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [OSSTEST PATCH v12 18/21] TestSupport: Implement target_cmd_subunit a subunit stream parser into substeps



target_cmd_subunit can be used like target_cmd, but the command would
needs to output a subunit v1 stream, which will be parsed and turned
into osstest substeps. The command can be `| subunit-2to1` in order to
turn a subunit v2 stream into v1.

Currently, time is not taken into account, and all substeps will have
bogus timestamp as the output of the command is parsed after it has
runned.

Signed-off-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
---
 Osstest/TestSupport.pm | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/Osstest/TestSupport.pm b/Osstest/TestSupport.pm
index 7215156..f3174d2 100644
--- a/Osstest/TestSupport.pm
+++ b/Osstest/TestSupport.pm
@@ -55,6 +55,7 @@ BEGIN {
 
                       target_cmd_root_status target_cmd_output_root_status
                       target_cmd_root target_cmd target_cmd_build
+                      target_cmd_subunit
                       target_cmd_output_root target_cmd_output
                       target_cmd_inputfh_root sshuho
                       target_getfile target_getfile_root
@@ -737,6 +738,48 @@ sub target_cmd_root ($$;$$) { tcmd(undef,undef,0, 
'root',@_); }
 # Instead, returns the wait status (ie, what came in $?)
 sub target_cmd_root_status ($$;$$) { tcmd(undef,undef,1, 'root',@_); }
 
+sub subunit_result_to_osstest_result ($) {
+    my ($ret) = @_;
+    return "pass" if $ret eq "success" or $ret eq "successful";
+    return "fail" if $ret eq "failure";
+    return "skip" if $ret eq "skip";
+    return "fail" if $ret eq "error";
+}
+sub subunit_sanitize ($) {
+    my ($testname) = @_;
+    $testname =~ s/ /_/g;
+    return $testname;
+}
+
+sub target_cmd_subunit ($$;$$) {
+    my $stdout = IO::File::new_tmpfile();
+    my $rc = tcmd(undef,$stdout,0, 'osstest', @_);
+    $stdout->seek(0,0) or die "$stdout $!";
+    my $logfilename = undef;
+    my $fh = undef;
+
+    while (<$stdout>) {
+        if (/^time: (\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)(\.\d+)?Z$/) {
+            # This is the timestamp for the next events
+        } elsif (/^test: (.+)\n/) {
+            $logfilename = subunit_sanitize($1) . '.log';
+            $fh = open_unique_stashfile(\$logfilename);
+            substep_start(subunit_sanitize($1), $logfilename);
+        } elsif (/^(success(ful)?|failure|skip|error): (.+?)( \[( 
multipart)?)?$/) {
+            if ($4) {
+                my $test_output = "";
+                while (<$stdout>) {
+                    last if (/^\]$/);
+                    $test_output .= $_;
+                }
+                print $fh $test_output or die $!;
+            }
+            close $fh or die $!;
+            substep_finish(subunit_sanitize($3), 
subunit_result_to_osstest_result($1));
+        }
+    }
+}
+
 sub tcmdout {
     my $stdout= IO::File::new_tmpfile();
     my $badstatusok = $_[1];
-- 
Anthony PERARD


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.