All of lore.kernel.org
 help / color / mirror / Atom feed
From: sshang <sshang@redhat.com>
To: lmr@redhat.com
Cc: autotest@test.kernel.org, kvm@vger.kernel.org,
	sshang <sshang@redhat.com>
Subject: [PATCH] KVM test: Add a subtest cpuflags
Date: Thu,  4 Mar 2010 15:20:33 +0800	[thread overview]
Message-ID: <1267687233-26740-1-git-send-email-sshang@redhat.com> (raw)

 This test mainly tests whether all guest cpu flags are supported by host machine.

Signed-off-by: sshang <sshang@redhat.com>
---
 client/tests/kvm/tests/cpuflags.py     |   80 ++++++++++++++++++++++++++++++++
 client/tests/kvm/tests_base.cfg.sample |    9 +++-
 2 files changed, 88 insertions(+), 1 deletions(-)
 create mode 100644 client/tests/kvm/tests/cpuflags.py

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
 
 
-- 
1.5.5.6


             reply	other threads:[~2010-03-04  7:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-04  7:20 sshang [this message]
2011-07-29  5:27 ` [PATCH] KVM test: Add a subtest cpuflags Amos Kong

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=1267687233-26740-1-git-send-email-sshang@redhat.com \
    --to=sshang@redhat.com \
    --cc=autotest@test.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=lmr@redhat.com \
    /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.