All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wei Liu <wei.liu2@citrix.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Ian Jackson <Ian.Jackson@eu.citrix.com>,
	Wei Liu <wei.liu2@citrix.com>
Subject: [XTF PATCH 3/3] xtf-runner: support two modes for getting output
Date: Wed, 10 Aug 2016 16:07:30 +0100	[thread overview]
Message-ID: <1470841650-30850-4-git-send-email-wei.liu2@citrix.com> (raw)
In-Reply-To: <1470841650-30850-1-git-send-email-wei.liu2@citrix.com>

We need two modes for getting output:

1. Use console directly with newer (>=4.8) Xen
2. Use log files for older Xen

This patch implements both. The default behaviour is to choose mode
automatically based on Xen version. User can also explicitly specify
which mode to use.

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

diff --git a/xtf-runner b/xtf-runner
index 73a4e0d..2d4d6db 100755
--- a/xtf-runner
+++ b/xtf-runner
@@ -11,6 +11,8 @@
 
 from optparse import OptionParser
 from subprocess import Popen, PIPE, call as subproc_call, check_output
+from distutils.version import LooseVersion
+import time
 
 try:
     import json
@@ -438,30 +440,19 @@ def list_tests(opts):
     for sel in opts.selection:
         print sel
 
+def run_test_console(opts, test):
+    """ Run a specific test via xenconsole"""
 
-def run_test(test):
-    """ Run a specific test """
-
-    cmd = ['xl', 'create', '-p', test.cfg_path()]
-    print "Executing '%s'" % (" ".join(cmd), )
-    rc = subproc_call(cmd)
-    if rc:
-        raise RunnerError("Failed to create VM")
-
-    cmd = ['xl', 'console', test.vm_name()]
+    cmd = ['xl', 'create', '-Fc', test.cfg_path()]
     print "Executing '%s'" % (" ".join(cmd), )
-    console = Popen(cmd, stdout = PIPE)
+    guest = Popen(cmd, stdout = PIPE, stderr = PIPE)
 
-    cmd = ['xl', 'unpause', test.vm_name()]
-    print "Executing '%s'" % (" ".join(cmd), )
-    rc = subproc_call(cmd)
-    if rc:
-        raise RunnerError("Failed to unpause VM")
+    # stdout is console output, stderr is xl output
+    stdout, stderr = guest.communicate()
 
-    stdout, _ = console.communicate()
-
-    if console.returncode:
-        raise RunnerError("Failed to obtain VM console")
+    if guest.returncode:
+        print stderr
+        raise RunnerError("Failed to communicate with guest")
 
     lines = stdout.splitlines()
 
@@ -483,6 +474,64 @@ def run_test(test):
     return "ERROR"
 
 
+def run_test_logfile(opts, test):
+    """ Run a specific test via grepping log file"""
+
+    fn = opts.logfile_dir + (opts.logfile_pattern % test)
+    local_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
+
+    # Use time to generate unique stamps
+    start_stamp = "===== XTF TEST START %s =====" % local_time
+    end_stamp = "===== XTF TEST END %s =====" % local_time
+
+    print "Using %s" % fn
+
+    f = open(fn, "ab")
+    f.write(start_stamp + "\n")
+    f.close()
+
+    cmd = ['xl', 'create', '-F', test.cfg_path()]
+    print "Executing '%s'" % (" ".join(cmd), )
+    rc = subproc_call(cmd)
+    if rc:
+        raise RunnerError("Failed to run test")
+
+    f = open(fn, "ab")
+    f.write(end_stamp + "\n")
+    f.close()
+
+    f = open(fn, "rb")
+    output = f.readlines()
+    f.close()
+    lines = []
+    found = False
+    for line in output:
+        if end_stamp in line:
+            break
+        if start_stamp in line:
+            found = True
+            continue
+        if not found:
+            continue
+        lines.append(line)
+
+    print "".join(lines)
+
+    if len(lines) == 0:
+        raise RunnerError("Log file output empty")
+
+    test_result = lines[-1]
+    if not "Test result:" in test_result:
+        return "ERROR"
+
+    for res in all_results:
+
+        if res in test_result:
+            return res
+
+    return "ERROR"
+
+
 def run_tests(opts):
     """ Run tests """
 
@@ -490,12 +539,25 @@ def run_tests(opts):
     if not len(tests):
         raise RunnerError("No tests to run")
 
+    if opts.mode == "auto":
+        xen_version = LooseVersion(get_xen_version())
+        if xen_version < LooseVersion("4.8"):
+            run_test = run_test_logfile
+        else:
+            run_test = run_test_console
+    elif opts.mode == "console":
+        run_test = run_test_console
+    elif opts.mode == "logfile":
+        run_test = run_test_logfile
+    else:
+        raise RunnerError("Unrecognised mode")
+
     rc = all_results.index('SUCCESS')
     results = []
 
     for test in tests:
 
-        res = run_test(test)
+        res = run_test(opts, test)
         res_idx = all_results.index(res)
         if res_idx > rc:
             rc = res_idx
-- 
2.1.4


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

  parent reply	other threads:[~2016-08-10 15:07 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-10 15:07 [XTF PATCH 0/3] Support getting output from either console or log file Wei Liu
2016-08-10 15:07 ` [XTF PATCH 1/3] xtf-runner: introduce get_xen_version Wei Liu
2016-08-11 10:10   ` Andrew Cooper
2016-08-11 10:12     ` Wei Liu
2016-08-11 10:14       ` Andrew Cooper
2016-08-10 15:07 ` [XTF PATCH 2/3] xtf-runner: options for different modes to get output Wei Liu
2016-08-10 15:07 ` Wei Liu [this message]
2016-08-11  8:33   ` [XTF PATCH 3/3] xtf-runner: support two modes for getting output Wei Liu
2016-08-11  9:44     ` Wei Liu
2016-08-11  9:56       ` Andrew Cooper
2016-08-11 10:05         ` Wei Liu
2016-08-11 11:08         ` Ian Jackson
2016-08-11 11:19           ` Wei Liu
2016-08-11 11:41             ` Andrew Cooper
2016-08-11 10:49   ` Ian Jackson
2016-08-11 11:03     ` Wei Liu

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=1470841650-30850-4-git-send-email-wei.liu2@citrix.com \
    --to=wei.liu2@citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=andrew.cooper3@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.