From patchwork Thu Mar 4 07:20:33 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sshang X-Patchwork-Id: 83543 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o247FTIu022547 for ; Thu, 4 Mar 2010 07:15:29 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753477Ab0CDHP1 (ORCPT ); Thu, 4 Mar 2010 02:15:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47331 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752884Ab0CDHP0 (ORCPT ); Thu, 4 Mar 2010 02:15:26 -0500 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o247FPUX025295 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 4 Mar 2010 02:15:25 -0500 Received: from localhost.localdomain ([10.66.91.194]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o247FMnH009109; Thu, 4 Mar 2010 02:15:23 -0500 From: sshang To: lmr@redhat.com Cc: autotest@test.kernel.org, kvm@vger.kernel.org, sshang Subject: [PATCH] KVM test: Add a subtest cpuflags Date: Thu, 4 Mar 2010 15:20:33 +0800 Message-Id: <1267687233-26740-1-git-send-email-sshang@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Thu, 04 Mar 2010 07:15:29 +0000 (UTC) diff --git a/client/tests/kvm/tests/cpuflags.py b/client/tests/kvm/tests/cpuflags.py new file mode 100644 index 0000000..5f51d65 --- /dev/null +++ b/client/tests/kvm/tests/cpuflags.py @@ -0,0 +1,80 @@ +import logging,os,commands +from autotest_lib.client.common_lib import error +import kvm_test_utils + +def run_cpuflags(test,params,env): + """ + Check guest cpu extension flags supported by host + 1) Log into guest + 2) Get guest cpu information and host cpu information + 3) Compare with each other make sure host cpu extension flags + bits contain guest + + @param test: kvm test object + @param params: Dictionary with the test parameters + @param env: Dictionary with test environment. + """ + vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + session = kvm_test_utils.wait_for_login(vm, + timeout=int(params.get("login_timeout", 360))) + + get_cpuflags_cmd = params.get("getcpuflags") + s, o = session.get_command_status_output(get_cpuflags_cmd) + if s != 0: + raise error.TestFail, "Could not read guest cpu flags" + guest_cpuflags_list = o.splitlines()[0].split(':')[1].split() + host_cpuflags_list = commands.getoutput(get_cpuflags_cmd).\ + splitlines()[0].split(':')[1].split() + + logging.debug("Host flags %s" % host_cpuflags_list) + logging.debug("Guest flags %s" % guest_cpuflags_list) + + # There are some special flags, for example 'hypervisor', 'sep', + # present in guests but not in the hosts, exclude these flags from + # comparison. + ban_flags_list = params.get("ban_flags").split() + + guest_cpuflags_set = set(guest_cpuflags_list) + host_cpuflags_set = set(host_cpuflags_list) + + # If the excluded flags provided by the config file that exist in the + # host, remove them from the ban_flags_list, because we require kvm + # virtualize/simulate the host. + if params.get("strict_check") == "yes": + for flag in ban_flags_list: + if flag in host_cpuflags_list: + ban_flags_list.remove(flag) + + # exclude the banned flags from guest flags set. + for flag in ban_flags_list: + if flag in guest_cpuflags_set: + guest_cpuflags_set.remove(flag) + + if guest_cpuflags_set.issubset(host_cpuflags_set): + logging.info("Guest cpu flags all supported by host") + else: + invalidflags_set = guest_cpuflags_set - host_cpuflags_set + host_cpuflags_str = str(host_cpuflags_set)[4:-1] + invalidflags_str = '' + for i in invalidflags_set: + if host_cpuflags_str.find(i.strip()) == -1: + invalidflags_str = invalidflags_str + i + ',' + + if invalidflags_str.strip() != '': + raise error.TestFail("Unsupported cpu flags by host: %s" % \ + invalidflags_str[0:-1]) + + # check the extra cpuflags in guest. + extra_flags_set = set(params.get("extra_flags").split()) + if extra_flags_set.issubset(guest_cpuflags_set): + logging.info("All extra flags are found in guest.") + else: + invalidflags_set = extra_flags_set - guest_cpuflags_set + invalidflags_str = '' + for i in invalidflags_set: + invalidflags_str = invalidflags_str + i + ',' + raise error.TestFail("Unsupported extra flags by guest: %s" % \ + invalidflags_str[0:-1]) + + session.close() + diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample index 040d0c3..f7dcbb6 100644 --- a/client/tests/kvm/tests_base.cfg.sample +++ b/client/tests/kvm/tests_base.cfg.sample @@ -300,6 +300,13 @@ variants: shutdown_method = shell kill_vm = yes kill_vm_gracefully = no + + - cpuflags: + type = cpuflags + getcpuflags = grep 'flags' /proc/cpuinfo + ban_flags = "up sep hypervisor sep_good" + extra_flags = "" + strict_check = yes # Do not define test variants below shutdown @@ -1001,7 +1008,7 @@ variants: md5sum = 9fae22f2666369968a76ef59e9a81ced -linux_s3: +linux_s3|cpuflags: only Linux