]> xenbits.xensource.com Git - people/aperard/osstest.git/commitdiff
substep handling improvements
authorIan Jackson <ian.jackson@eu.citrix.com>
Mon, 12 Jun 2017 11:14:04 +0000 (12:14 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Mon, 12 Jun 2017 13:29:47 +0000 (14:29 +0100)
* 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@eu.citrix.com>
Osstest/TestSupport.pm
sg-run-job

index fc1aa7db92a8165c6f602b71d4a0df6acfd84228..ce9ffaadc186d595eb32d18daa695eece10f281c 100644 (file)
@@ -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;
index 0af86fa2d1501cb36f54ae3fa830e3d99b4090c6..4b98e2bb0ef7506336b08106d7662e2588a0b40e 100755 (executable)
@@ -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]