xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [OSSTEST PATCH 1/2] Executive: Support substeps
@ 2016-07-07 18:47 Ian Jackson
  2016-07-07 18:47 ` [OSSTEST PATCH 2/2] DO NOT APPLY make-flight-substep-test Ian Jackson
  0 siblings, 1 reply; 2+ messages in thread
From: Ian Jackson @ 2016-07-07 18:47 UTC (permalink / raw)
  To: xen-devel; +Cc: Wei Liu, Ian Jackson

ts-* scripts can now create `substeps'.  For the purposes of
archaeology etc., a substep is just like a step.  But it does
correspond to a single specific ts-* invocation.

Instead, it is started and finished explicitly as required.

The whole job implementation code needs to explicitly assign a unique
stable testid to each substep.

The `script' parameter is stored in the `step' field in the database,
which is used only for reporting.  These do not need to be unique.

All substeps started are should also be finished, by the end of the
job.  If this is not done, the job will be regarded as broken (if it
is not already failed or aborted).  (But a substep might be finished
by a different ts-* script to the one that started it.)

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
CC: Wei Liu <wei.liu2@citrix.com>
---
 Osstest/JobDB/Executive.pm  | 51 +++++++++++++++++++++++++++++++++++++++++++++
 Osstest/JobDB/Standalone.pm | 10 +++++++++
 Osstest/TestSupport.pm      | 11 ++++++++++
 sg-run-job                  |  6 ++++++
 tcl/JobDB-Executive.tcl     | 32 ++++++++++++++++++++++++++++
 tcl/JobDB-Standalone.tcl    |  2 ++
 6 files changed, 112 insertions(+)

diff --git a/Osstest/JobDB/Executive.pm b/Osstest/JobDB/Executive.pm
index c0af21c..fdcb177 100644
--- a/Osstest/JobDB/Executive.pm
+++ b/Osstest/JobDB/Executive.pm
@@ -161,6 +161,57 @@ END
     logm("starting $flight started=$now") if $count>0;
 }
 
+sub step_start ($$) { #method
+    my ($jd,$testid,$script) = @_;
+    my $snq = $dbh_tests->prepare(<<END);
+        SELECT max(stepno) AS maxstep FROM steps
+            WHERE flight=? AND job=?
+END
+    my $createq = $dbh_tests->prepare(<<END);
+        INSERT INTO steps (flight,job,stepno, step,status, testid,started)
+            VALUES (?,?,?, ?,'running', ?,?)
+END
+    my $stepno;
+    db_retry($flight,[qw(running)], $dbh_tests,[qw(flights)],sub {
+	$snq->execute($flight,$job);
+	($stepno) = $snq->fetchrow_array();
+	$stepno //= 0;
+	$stepno++;
+	$createq->execute($flight,$job,$stepno, $script, $testid,time);
+    });
+    logm("---------- substep $stepno $testid running ----------");
+}
+
+sub step_finish ($$) { #method
+    my ($jd,$testid,$stepstatus) = @_;
+    die "$flight.$job $testid $stepstatus" unless grep { $stepstatus eq $_ }
+	qw(pass fail blocked broken);
+    my $checkq = $dbh_tests->prepare(<<END);
+        SELECT stepno, status
+          FROM steps
+         WHERE flight=?
+           AND job=?
+           AND testid=?
+END
+    my $setq = $dbh_tests->prepare(<<END);
+        UPDATE steps
+           SET status=?, finished=?
+         WHERE flight=?
+           AND job=?
+           AND testid=?
+           AND stepno=?
+END
+    my ($stepno,$oldstatus);
+    db_retry($flight,[qw(running)], $dbh_tests,[qw(flights)],sub {
+	$checkq->execute($flight,$job,$testid);
+	($stepno, $oldstatus) = $checkq->fetchrow_array();
+	die "$flight.$job $testid $stepno $oldstatus ?"
+	    unless $oldstatus eq 'running';
+	$setq->execute($stepstatus,time, $flight,$job,$testid, $stepno);
+    });
+    logm("---------- substep $stepno $testid $stepstatus ----------");
+}
+
 sub host_check_allocated ($$) { #method
     my ($jd, $ho) = @_;
 
diff --git a/Osstest/JobDB/Standalone.pm b/Osstest/JobDB/Standalone.pm
index 98d0173..21ea07b 100644
--- a/Osstest/JobDB/Standalone.pm
+++ b/Osstest/JobDB/Standalone.pm
@@ -87,6 +87,16 @@ sub current_flight ($) {
 
 sub job_ensure_started ($) { }
 
+sub step_start ($$) {
+    my ($jd,$testid,$script) = @_;
+    logm("========== $flight.$job step $testid running $script ==========");
+}
+
+sub step_finish ($$) { #method
+    my ($jd,$testid,$stepstatus) = @_;
+    logm("========== $flight.$job step $testid $stepstatus ==========");
+}
+
 sub host_check_allocated ($$) { #method
     my ($jd, $ho) = @_;
 
diff --git a/Osstest/TestSupport.pm b/Osstest/TestSupport.pm
index 9e6479a..76c3a57 100644
--- a/Osstest/TestSupport.pm
+++ b/Osstest/TestSupport.pm
@@ -42,6 +42,7 @@ BEGIN {
                       ts_get_host_guest
 
                       fail broken logm $logm_handle $logm_prefix
+                      substep_start substep_finish
                       get_filecontents
                       report_once
 
@@ -228,6 +229,16 @@ END
                          : "($flight.$job not marked $newst)");
 }
 
+sub substep_start ($$) {
+    my ($testid,$script) = @_;
+    $mjobdb->step_start($testid,$script);
+}
+
+sub substep_finish ($$) {
+    my ($testid,$stepstatus) = @_;
+    $mjobdb->step_finish($testid,$stepstatus);
+}
+
 sub get_filecontents ($;$) {
     my ($path, $ifnoent) = @_;  # $ifnoent=undef => is error
     my $data= get_filecontents_core_quiet($path);
diff --git a/sg-run-job b/sg-run-job
index 0847d2f..60855b4 100755
--- a/sg-run-job
+++ b/sg-run-job
@@ -88,6 +88,12 @@ proc run-job {job} {
 	run-ts  !broken capture-logs      ts-logs-capture + host
     }
 
+    if {$ok} {
+        if {[jobdb::job-check-escaped-steps $flight $job]} {
+            set ok 0
+        }
+    }
+
     if {$ok} { setstatus pass                                             }
 
     if {$need_build_host && $ok} { jobdb::preserve-task 90 }
diff --git a/tcl/JobDB-Executive.tcl b/tcl/JobDB-Executive.tcl
index 7dba497..8ba7d92 100644
--- a/tcl/JobDB-Executive.tcl
+++ b/tcl/JobDB-Executive.tcl
@@ -66,6 +66,38 @@ proc job-set-status {flight job st} {
     }
 }
 
+proc job-check-escaped-steps {flight job} {
+    global runstepinfo
+    transaction flights {
+	set any 0
+
+	db-execute-array runstepinfo "
+            SELECT stepno, testid
+              FROM steps
+             WHERE flight = [pg_quote $flight]
+               AND job = [pg_quote $job]
+               AND status = 'running'
+        " {
+	    logputs stderr \
+ "$flight.$job step #$runstepinfo(stepno) $runstepinfo(testid) still running!"
+	    set any 1
+	}
+
+	if {$any} {
+	    db-execute "
+                UPDATE jobs
+		   SET status='broken'
+		 WHERE flight = [pg_quote $flight]
+		   AND job = [pg_quote $job]
+		   AND status<>'aborted'
+		   AND status<>'broken'
+		   AND status<>'fail'
+            "
+	}
+    }
+    return $any
+}
+
 proc set-flight {} {
     global flight argv env
 
diff --git a/tcl/JobDB-Standalone.tcl b/tcl/JobDB-Standalone.tcl
index d7d8422..4ef0962 100644
--- a/tcl/JobDB-Standalone.tcl
+++ b/tcl/JobDB-Standalone.tcl
@@ -44,6 +44,8 @@ proc job-set-status {flight job st} {
     }
 }
 
+proc job-check-escaped-steps {flight job} { }
+
 proc ensure-db-open {} {
     global c
     if {![catch { osstestdb version }]} { return }
-- 
2.1.4


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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [OSSTEST PATCH 2/2] DO NOT APPLY make-flight-substep-test
  2016-07-07 18:47 [OSSTEST PATCH 1/2] Executive: Support substeps Ian Jackson
@ 2016-07-07 18:47 ` Ian Jackson
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Jackson @ 2016-07-07 18:47 UTC (permalink / raw)
  To: xen-devel; +Cc: Wei Liu, Ian Jackson

This is a simple test case for substeps.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
CC: Wei Liu <wei.liu2@citrix.com>
---
 make-flight-substep-test | 14 ++++++++++++++
 sg-run-job               |  7 +++++++
 2 files changed, 21 insertions(+)
 create mode 100755 make-flight-substep-test

diff --git a/make-flight-substep-test b/make-flight-substep-test
new file mode 100755
index 0000000..44b0451
--- /dev/null
+++ b/make-flight-substep-test
@@ -0,0 +1,14 @@
+#!/bin/sh
+set -e
+
+flight=`./cs-flight-create play xen-unstable`
+
+runvars=bogus=0
+
+for j in test-1 test-2; do
+    ./cs-job-create $flight $j test-substeps \
+	$runvars
+    runvars=bogus=1
+done
+
+echo $flight
diff --git a/sg-run-job b/sg-run-job
index 60855b4..05e7725 100755
--- a/sg-run-job
+++ b/sg-run-job
@@ -423,6 +423,13 @@ proc run-job/test-rumpuserxen {} {
                  ts-guest-destroy-hard            host   $g   +
 }
 
+proc need-hosts/test-substeps {} { }
+proc run-job/test-substeps {} {
+    run-ts . =   ts-substep-test suba:foo 1 subb:wombat suba=pass
+    run-ts . =.2 ts-substep-test subx:foo 1             subx=fail
+    run-ts . =.3 ts-substep-test ,bogus     subb=pass
+}
+
 if {[file exists sg-run-job-adhoc]} {
     source sg-run-job-adhoc
 }
-- 
2.1.4


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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-07-07 18:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-07 18:47 [OSSTEST PATCH 1/2] Executive: Support substeps Ian Jackson
2016-07-07 18:47 ` [OSSTEST PATCH 2/2] DO NOT APPLY make-flight-substep-test Ian Jackson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).