From: Feng Yang <fyang@redhat.com>
To: autotest@test.kernel.org
Cc: kvm@vger.kernel.org, Feng Yang <fyang@redhat.com>
Subject: [PATCH 2/3] KVM Test: Add function run_autotest_background and wait_autotest_background.
Date: Wed, 7 Apr 2010 16:49:15 +0800 [thread overview]
Message-ID: <1270630156-9904-2-git-send-email-fyang@redhat.com> (raw)
In-Reply-To: <1270630156-9904-1-git-send-email-fyang@redhat.com>
Add function run_autotest_background and wait_autotest_background to
kvm_test_utils.py. This two functions is used in ioquit test script.
Signed-off-by: Feng Yang <fyang@redhat.com>
---
client/tests/kvm/kvm_test_utils.py | 68 +++++++++++++++++++++++++++++++++++-
1 files changed, 67 insertions(+), 1 deletions(-)
diff --git a/client/tests/kvm/kvm_test_utils.py b/client/tests/kvm/kvm_test_utils.py
index f512044..2a1054e 100644
--- a/client/tests/kvm/kvm_test_utils.py
+++ b/client/tests/kvm/kvm_test_utils.py
@@ -21,7 +21,7 @@ More specifically:
@copyright: 2008-2009 Red Hat Inc.
"""
-import time, os, logging, re, commands
+import time, os, logging, re, commands, sys
from autotest_lib.client.common_lib import error
from autotest_lib.client.bin import utils
import kvm_utils, kvm_vm, kvm_subprocess, scan_results
@@ -402,3 +402,69 @@ def run_autotest(vm, session, control_path, timeout, test_name, outputdir):
result = bad_results[0]
raise error.TestFail("Test '%s' ended with %s (reason: '%s')"
% (result[0], result[1], result[3]))
+
+
+def run_autotest_background(vm, session, control_path, timeout, test_name,
+ outputdir):
+ """
+ Wrapper of run_autotest() and make it run in the background through fork()
+ and let it run in the child process.
+ 1) Flush the stdio.
+ 2) Build test params which is recevied from arguments and used by
+ run_autotest()
+ 3) Fork the process and let the run_autotest() run in the child
+ 4) Catch the exception raise by run_autotest() and exit the child with
+ non-zero return code.
+ 5) If no exception catched, reutrn 0
+
+ @param vm: VM object.
+ @param session: A shell session on the VM provided.
+ @param control: An autotest control file.
+ @param timeout: Timeout under which the autotest test must complete.
+ @param test_name: Autotest client test name.
+ @param outputdir: Path on host where we should copy the guest autotest
+ results to.
+ """
+
+ def flush():
+ sys.stdout.flush()
+ sys.stderr.flush()
+
+ logging.info("Running autotest background ...")
+ flush()
+ pid = os.fork()
+ if pid:
+ # Parent process
+ return pid
+
+ try:
+ # Launch autotest
+ logging.info("child process of run_autotest_background")
+ run_autotest(vm, session, control_path, timeout, test_name, outputdir)
+ except error.TestFail, message_fail:
+ logging.info("[Autotest Background FAIL] %s" % message_fail)
+ os._exit(1)
+ except error.TestError, message_error:
+ logging.info("[Autotest Background ERROR] %s" % message_error)
+ os._exit(2)
+ except:
+ os._exit(3)
+
+ logging.info("[Auototest Background GOOD]")
+ os._exit(0)
+
+
+def wait_autotest_background(pid):
+ """
+ Wait for background autotest finish.
+
+ @param pid: Pid of the child process executing background autotest
+ """
+ logging.info("Waiting for background autotest to finish ...")
+
+ (pid, s) = os.waitpid(pid,0)
+ status = os.WEXITSTATUS(s)
+ if status != 0:
+ return False
+ return True
+
--
1.5.5.6
next prev parent reply other threads:[~2010-04-07 8:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-07 8:49 [PATCH 1/3] KVM Test: Add control file dbench.control.200 for dbench Feng Yang
2010-04-07 8:49 ` Feng Yang [this message]
2010-04-07 8:49 ` [PATCH 3/3] KVM Test: Add ioquit test case Feng Yang
2010-04-08 14:36 ` Michael Goldish
2010-05-06 23:27 ` Lucas Meneghel Rodrigues
2010-05-06 23:32 ` Lucas Meneghel Rodrigues
2010-04-08 14:18 ` [PATCH 2/3] KVM Test: Add function run_autotest_background and wait_autotest_background Michael Goldish
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=1270630156-9904-2-git-send-email-fyang@redhat.com \
--to=fyang@redhat.com \
--cc=autotest@test.kernel.org \
--cc=kvm@vger.kernel.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).