From patchwork Tue Aug 11 12:10:42 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 40589 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n7BCFWmu031169 for ; Tue, 11 Aug 2009 12:15:33 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753429AbZHKMIH (ORCPT ); Tue, 11 Aug 2009 08:08:07 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753075AbZHKMIE (ORCPT ); Tue, 11 Aug 2009 08:08:04 -0400 Received: from mx2.redhat.com ([66.187.237.31]:38881 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752882AbZHKMIB (ORCPT ); Tue, 11 Aug 2009 08:08:01 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n7BC82Jf023959; Tue, 11 Aug 2009 08:08:02 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n7BC81kt016186; Tue, 11 Aug 2009 08:08:01 -0400 Received: from localhost.localdomain (dhcp-1-31.tlv.redhat.com [10.35.1.31]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n7BC7wF9028452; Tue, 11 Aug 2009 08:08:00 -0400 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH v2 1/3] KVM test: add AutoIt test Date: Tue, 11 Aug 2009 15:10:42 +0300 Message-Id: <35538aadbfdd5edaafca8b46f1d1c2b4e10c0420.1249992282.git.mgoldish@redhat.com> In-Reply-To: <1249992644-5111-1-git-send-email-mgoldish@redhat.com> References: <1249992644-5111-1-git-send-email-mgoldish@redhat.com> X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Currently the test only logs in, runs a given script and fails if the script takes too long to exit or if its exit status is nonzero. The test expects these parameters: autoit_binary: Path to AutoIt binary in the guest. autoit_script: Path to script in the host. autoit_script_params: Command line parameters to send to the script. autoit_script_timeout: The time duration (in seconds) to wait for the script to exit. The test code can be extended later to add more features. Signed-off-by: Michael Goldish --- client/tests/kvm/kvm.py | 1 + client/tests/kvm/kvm_tests.py | 66 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 0 deletions(-) diff --git a/client/tests/kvm/kvm.py b/client/tests/kvm/kvm.py index 070e463..4930e80 100644 --- a/client/tests/kvm/kvm.py +++ b/client/tests/kvm/kvm.py @@ -56,6 +56,7 @@ class kvm(test.test): "linux_s3": test_routine("kvm_tests", "run_linux_s3"), "stress_boot": test_routine("kvm_tests", "run_stress_boot"), "timedrift": test_routine("kvm_tests", "run_timedrift"), + "autoit": test_routine("kvm_tests", "run_autoit"), } # Make it possible to import modules from the test's bindir diff --git a/client/tests/kvm/kvm_tests.py b/client/tests/kvm/kvm_tests.py index 9cd01e2..749c1fd 100644 --- a/client/tests/kvm/kvm_tests.py +++ b/client/tests/kvm/kvm_tests.py @@ -776,3 +776,69 @@ def run_timedrift(test, params, env): if drift > drift_threshold_after_rest: raise error.TestFail("Time drift too large after rest period: %.2f%%" % drift_total) + + +def run_autoit(test, params, env): + """ + A wrapper for AutoIt scripts. + + 1) Log into a guest. + 2) Run AutoIt script. + 3) Wait for script execution to complete. + 4) Pass/fail according to exit status of script. + + @param test: KVM test object. + @param params: Dictionary with test parameters. + @param env: Dictionary with the test environment. + """ + vm = kvm_utils.env_get_vm(env, params.get("main_vm")) + if not vm: + raise error.TestError("VM object not found in environment") + if not vm.is_alive(): + raise error.TestError("VM seems to be dead; Test requires a living VM") + + logging.info("Waiting for guest to be up...") + + session = kvm_utils.wait_for(vm.remote_login, 240, 0, 2) + if not session: + raise error.TestFail("Could not log into guest") + + try: + logging.info("Logged in; starting script...") + + # Collect test parameters + binary = params.get("autoit_binary") + script = params.get("autoit_script") + script_params = params.get("autoit_script_params", "") + timeout = float(params.get("autoit_script_timeout", 600)) + + # Send AutoIt script to guest (this code will be replaced once we + # support sending files to Windows guests) + session.sendline("del script.au3") + file = open(kvm_utils.get_path(test.bindir, script)) + for line in file.readlines(): + # Insert a '^' before each character + line = "".join("^" + c for c in line.rstrip()) + if line: + # Append line to the file + session.sendline("echo %s>>script.au3" % line) + file.close() + + session.read_up_to_prompt() + + command = "cmd /c %s script.au3 %s" % (binary, script_params) + + logging.info("---------------- Script output ----------------") + status = session.get_command_status(command, + print_func=logging.info, + timeout=timeout) + logging.info("---------------- End of script output ----------------") + + if status is None: + raise error.TestFail("Timeout expired before script execution " + "completed (or something weird happened)") + if status != 0: + raise error.TestFail("Script execution failed") + + finally: + session.close()