From: Michael Goldish <mgoldish@redhat.com>
To: Feng Yang <fyang@redhat.com>
Cc: autotest@test.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH 2/3] KVM Test: Add function run_autotest_background and wait_autotest_background.
Date: Thu, 08 Apr 2010 17:18:13 +0300 [thread overview]
Message-ID: <4BBDE5A5.206@redhat.com> (raw)
In-Reply-To: <1270630156-9904-2-git-send-email-fyang@redhat.com>
On 04/07/2010 11:49 AM, Feng Yang wrote:
> 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
> +
I think these functions are unnecessary. IMO forking is not the clean
way of running autotest in the background. The kvm_shell_session
object, used to run autotest in the guest, by default runs things in the
background (e.g. session.sendline() returns immediately).
run_autotest(), which uses kvm_shell_session, blocks until the autotest
test is done. So in order to run autotest in the background, we should
modify run_autotest(), or break it up into smaller parts, to make it
nonblocking. There's no need to implement yet another wrapper.
prev parent reply other threads:[~2010-04-08 14:18 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 ` [PATCH 2/3] KVM Test: Add function run_autotest_background and wait_autotest_background Feng Yang
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 ` Michael Goldish [this message]
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=4BBDE5A5.206@redhat.com \
--to=mgoldish@redhat.com \
--cc=autotest@test.kernel.org \
--cc=fyang@redhat.com \
--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 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.