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

[Xen-devel] [OSSTEST PATCH 1/2] substep handling improvements



* Change sg-run-job to pass OSSTEST_TESTID to ts-* scripts

* If the specified $testid starts with /, prepend OSSTEST_TESTID
  (with a fallback for ad-hoc by-hand invocations).

* Default $script to the leafname from $0.

* Provide substep_eval, which does the obvious thing with eval and $@.

Signed-off-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
---
 Osstest/TestSupport.pm | 33 +++++++++++++++++++++++++++++++--
 sg-run-job             |  3 ++-
 2 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/Osstest/TestSupport.pm b/Osstest/TestSupport.pm
index fc1aa7d..ce9ffaa 100644
--- a/Osstest/TestSupport.pm
+++ b/Osstest/TestSupport.pm
@@ -43,7 +43,8 @@ BEGIN {
                       ts_get_host_guest ts_check_done
 
                       fail broken logm $logm_handle $logm_prefix
-                      substep_start substep_finish intended_blessing
+                      substep_start substep_finish substep_eval
+                      intended_blessing
                       get_filecontents
                       report_once
 
@@ -236,16 +237,44 @@ END
                          : "($flight.$job not marked $newst)");
 }
 
-sub substep_start ($$) {
+sub complete_testid ($) {
+    my ($testidr) = @_;
+    $$testidr =~ s{^(?=/)}{
+       $ENV{OSSTEST_TESTID} // sprintf('SUBSTEP-%s-%s', time, $$)
+    }e;
+}
+
+sub substep_start ($;$) {
     my ($testid,$script) = @_;
+    complete_testid(\$testid);
+    if (!defined $script) {
+       $script = $0;
+       $script =~ s{^.*/}{};
+    }
     $mjobdb->step_start($testid,$script);
 }
 
 sub substep_finish ($$) {
     my ($testid,$stepstatus) = @_;
+    complete_testid(\$testid);
     $mjobdb->step_finish($testid,$stepstatus);
 }
 
+sub substep_eval ($$;$) {
+    # substep_eval(TESTID, [SCRIPTNAME], sub { ... });
+    my $fn = pop @_;
+    my ($testid,$script) = @_;
+    substep_start($testid,$script);
+    eval { $fn->(); };
+    if (length $@) {
+       logm("substep ($testid) failed: $@");
+       substep_finish($testid,'fail');
+    } else {
+       substep_finish($testid,'pass');
+    }
+}
+    
+
 sub intended_blessing () {
     # must be run outside transaction
     my $intended;
diff --git a/sg-run-job b/sg-run-job
index 0af86fa..4b98e2b 100755
--- a/sg-run-job
+++ b/sg-run-job
@@ -253,11 +253,12 @@ proc spawn-ts {iffail testid args} {
                  [list sh -xc "
                      OSSTEST_JOB=$jobinfo(job)
                      export OSSTEST_JOB
+                     OSSTEST_TESTID=\$1; shift; export OSSTEST_TESTID
                      $xprefix \"$@\" >&2
                      rc=\$?
                      date -u +\"%Y-%m-%d %H:%M:%S Z exit status \$rc\" >&2
                      exit \$rc
-                 " x ./$ts] \
+                 " x $testid ./$ts] \
                  $real_args $redirects]
     set fh [open |$cmd r]
     return [list fh $fh $details]
-- 
2.1.4


_______________________________________________
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®.