xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Wei Liu <wei.liu2@citrix.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: andrew.cooper3@citrix.com, Wei Liu <wei.liu2@citrix.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>
Subject: [XTF PATCH] xtf-runner: fix two synchronisation issues
Date: Fri, 29 Jul 2016 13:07:03 +0100	[thread overview]
Message-ID: <1469794023-10594-1-git-send-email-wei.liu2@citrix.com> (raw)

There were two synchronisation issues for the old code:

1. There was no guarantee that guest console was ready before "xl
   console" invocation.
2. There was no guarantee that runner wouldn't not exit before all test
   guests were gone.

For xtf-runner to be suitable to run in an automatic testing system like
osstest, we need to eliminate those two issues, otherwise we risk seeing
failures that are caused by races.

To fix these two issues:

1. Use "xl create -F" to force the process that creates a guest to
   stay until the guest is dead. With this we can wait for that
   particular subprocess in runner to make sure the guest is gone.
2. Poll xenstore guest console node to make sure console is available
   before "xl console" invocation.

To avoid the runner loops forever in that console checking loop, use
SIGALRM to make it time out after 5 seconds.

Redirect output that we're not interested in to DEVNULL.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 xtf-runner | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 50 insertions(+), 7 deletions(-)

diff --git a/xtf-runner b/xtf-runner
index 66b2fb7..3296cdf 100755
--- a/xtf-runner
+++ b/xtf-runner
@@ -7,7 +7,7 @@ xtf-runner - A utility for enumerating and running XTF tests.
 Currently assumes the presence and availability of the `xl` toolstack.
 """
 
-import sys, os, os.path as path
+import sys, os, os.path as path, signal
 
 from optparse import OptionParser
 from subprocess import Popen, PIPE, call as subproc_call, check_output
@@ -17,6 +17,11 @@ try:
 except ImportError:
     import simplejson as json
 
+try:
+    from subprocess import DEVNULL
+except ImportError:
+    DEVNULL = open(os.devnull, 'wb')
+
 # All results of a test, keep in sync with C code report.h.
 # Note that warning is not a result on its own.
 all_results = ('SUCCESS', 'SKIP', 'ERROR', 'FAILURE')
@@ -41,6 +46,10 @@ all_environments = pv_environments + hvm_environments
 class RunnerError(Exception):
     """ Errors relating to xtf-runner itself """
 
+def sigalrm_handler(signum, frame):
+    """ Signal handler for SIGALRM """
+    raise RunnerError("Operation timed out")
+
 def open_test_info():
     """ Open and collate each test-info.json """
 
@@ -132,24 +141,53 @@ def list_tests(args):
 
         print name
 
+# A list of processes that we need to wait until they exits.
+wait_list = []
 
 def run_test(test):
     """ Run a specific test """
 
+    console_path = '/local/domain/0/backend/console'
+    # Setup watch for console
+    cmd = ['xenstore-watch', console_path]
+    print "Executing '%s'" % (" ".join(cmd), )
+    xs_watch = Popen(cmd, stdout = PIPE, stderr = PIPE)
+
     _, _, name = test.split('-', 2)
 
     cfg = path.join("tests", name, test + ".cfg")
 
-    cmd = ['xl', 'create', '-p', cfg]
+    cmd = ['xl', 'create', '-Fp', cfg]
 
     print "Executing '%s'" % (" ".join(cmd), )
-    rc = subproc_call(cmd)
-    if rc:
-        raise RunnerError("Failed to create VM")
+    wait = Popen(cmd, stdout = DEVNULL, stderr = DEVNULL)
+    wait_list.append(wait)
+
+    # Wait up to 5 seconds for console to show up
+    signal.alarm(5)
+    while True:
+        l = xs_watch.stdout.readline()
+        domid = l[len(console_path)+1:].split('/')[0]
+        if domid == '': continue
+
+        cmd = ['xenstore-read', '/local/domain/'+domid+'/name']
+        print "Executing '%s'" % (" ".join(cmd), )
+        gname = check_output(cmd).splitlines()[0]
+        if gname != test: continue
+
+        cmd = ['xenstore-read', '/local/domain/'+domid+'/console/tty']
+        print "Executing '%s'" % (" ".join(cmd), )
+        con = check_output(cmd).splitlines()[0]
+        if con != '': break
+
+    # Tear down watch and timer
+    signal.alarm(0)
+    xs_watch.kill()
 
     cmd = ['xl', 'console', test]
     print "Executing '%s'" % (" ".join(cmd), )
     console = Popen(cmd, stdout = PIPE)
+    wait_list.append(console)
 
     cmd = ['xl', 'unpause', test]
     print "Executing '%s'" % (" ".join(cmd), )
@@ -327,12 +365,17 @@ def main():
     opts, args = parser.parse_args()
 
     if opts.list_tests:
-        return list_tests(args)
+        ret = list_tests(args)
     else:
-        return run_tests(args)
+        ret = run_tests(args)
+
+    for child in wait_list: child.wait()
+
+    return ret
 
 
 if __name__ == "__main__":
+    signal.signal(signal.SIGALRM, sigalrm_handler)
     try:
         sys.exit(main())
     except RunnerError, e:
-- 
2.1.4


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

             reply	other threads:[~2016-07-29 12:07 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-29 12:07 Wei Liu [this message]
2016-07-29 12:43 ` [XTF PATCH] xtf-runner: fix two synchronisation issues Andrew Cooper
2016-07-29 12:58   ` Wei Liu
2016-07-29 13:06     ` Andrew Cooper
2016-07-29 13:12       ` Wei Liu
2016-07-29 13:23         ` Andrew Cooper
2016-07-29 13:26           ` Wei Liu
2016-07-29 14:31     ` Ian Jackson
2016-07-29 14:55       ` Wei Liu
2016-07-29 16:18         ` Ian Jackson
2016-07-29 16:35           ` Andrew Cooper
2016-07-29 16:41           ` Wei Liu
2016-07-29 15:05       ` Andrew Cooper
2016-08-01 13:16       ` [RFC PATCH 0/8] Fix console " Wei Liu
2016-08-01 13:16         ` [RFC PATCH 1/8] tools/console: fix help string in client Wei Liu
2016-08-05 15:40           ` Ian Jackson
2016-08-01 13:16         ` [RFC PATCH 2/8] tools/console: introduce --start-notify-fd option for console client Wei Liu
2016-08-05 15:43           ` Ian Jackson
2016-08-01 13:16         ` [RFC PATCH 3/8] libxl: factor out libxl__console_tty_path Wei Liu
2016-08-05 15:44           ` Ian Jackson
2016-08-01 13:16         ` [RFC PATCH 4/8] libxl: wait up to 5s in libxl_console_exec for xenconsoled Wei Liu
2016-08-05 15:48           ` Ian Jackson
2016-08-01 13:16         ` [RFC PATCH 5/8] libxl: libxl_{primary_, }console_exec now take notify_fd argument Wei Liu
2016-08-05 15:49           ` Ian Jackson
2016-08-05 15:50             ` Ian Jackson
2016-08-01 13:16         ` [RFC PATCH 6/8] docs: document xenconsole startup protocol Wei Liu
2016-08-05 15:52           ` Ian Jackson
2016-08-01 13:16         ` [RFC PATCH 7/8] xl: use " Wei Liu
2016-08-05 15:55           ` Ian Jackson
2016-08-01 13:16         ` [RFC PATCH 8/8] tools/console: remove 5s bodge in console client Wei Liu
2016-08-05 15:57           ` Ian Jackson
2016-08-05 16:16             ` Wei Liu
2016-08-05 16:18               ` Ian Jackson
2016-08-05 16:28                 ` Wei Liu
2016-08-05 16:32                   ` Ian Jackson
2016-08-05 16:36                     ` Wei Liu
2016-08-05 17:23                       ` Wei Liu
2016-08-08 10:07                         ` Ian Jackson
2016-08-01 14:04       ` [XTF PATCH] xtf-runner: use xl create -Fc directly Wei Liu
2016-07-29 13:27 ` [XTF PATCH] xtf-runner: fix two synchronisation issues Andrew Cooper
2016-07-29 14:21 ` Ian Jackson
2016-07-29 14:25   ` Wei Liu
2016-07-29 14:35     ` Ian Jackson
2016-07-29 14:46       ` Wei Liu
2016-07-29 14:26   ` Andrew Cooper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1469794023-10594-1-git-send-email-wei.liu2@citrix.com \
    --to=wei.liu2@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).