- leaf 0x40000000 idx 0x00 ebx,ecx,edx
     - kvm and hyperv variants
  - leaf 0x40000001 idx 0x00 eax

Signed-off-by: Igor Mammedov <[email protected]>
---
 qemu/tests/cfg/qemu_cpu.cfg |   21 +++++++++++++++++++++
 qemu/tests/cpuid.py         |   43 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 63 insertions(+), 1 deletions(-)

diff --git a/qemu/tests/cfg/qemu_cpu.cfg b/qemu/tests/cfg/qemu_cpu.cfg
index 07e7b2b..f13c380 100644
--- a/qemu/tests/cfg/qemu_cpu.cfg
+++ b/qemu/tests/cfg/qemu_cpu.cfg
@@ -122,6 +122,27 @@
                                 vendor = "GenuineIntel"
                         cpu.amd:
                                 vendor = "AuthenticAMD"
+                - signature:
+                    only kvm
+                    only cpu.unset
+                    test_type = "cpuid_signature"
+                    variants:
+                        KVM:
+                            signature = "KVMKVMKVM\x00\x00\x00"
+                        hv_relaxed:
+                            signature = "Microsoft Hv"
+                            flags = "hv_relaxed"
+                        hv_vapic:
+                            signature = "Microsoft Hv"
+                            flags = "hv_vapic"
+                        hv_spinlocks:
+                            signature = "Microsoft Hv"
+                            flags = "hv_spinlocks=4095"
+                        0x40000001:
+                            signature = "Hv#1"
+                            leaf = "0x40000001"
+                            flags = "hv_relaxed"
+                            regs = "eax"
                 - custom:
                     # the checks below will be run without setting the CPU 
model
                     # explicitly. they can be repeated for each known CPU model
diff --git a/qemu/tests/cpuid.py b/qemu/tests/cpuid.py
index 5065c6a..99f70a0 100644
--- a/qemu/tests/cpuid.py
+++ b/qemu/tests/cpuid.py
@@ -1,7 +1,7 @@
 """
 Group of cpuid tests for X86 CPU
 """
-import logging, re, sys, traceback, os
+import logging, re, sys, traceback, os, string
 from autotest.client.shared import error, utils
 from autotest.client.shared import test as test_module
 from virttest import utils_misc, env_process
@@ -446,6 +446,47 @@ def run_cpuid(test, params, env):
             if (has_error is False) and (xfail is True):
                 raise error.TestFail("Test was expected to fail, but it 
didn't")
 
+    def cpuid_regs_to_string(cpuid_dump, leaf, idx, regs):
+        r = cpuid_regs_to_dic('%s %s' % (leaf, idx), cpuid_dump)
+        signature = ""
+        for i in regs:
+            for shift in range(0, 4):
+                c = chr((r[i] >> (shift * 8)) & 0xFF)
+                if c in string.printable:
+                    signature = signature + c
+                else:
+                    signature = "%s\\x%02x" % (signature, ord(c))
+        logging.debug("(%s.%s:%s: signature: %s" % (leaf, idx, str(regs),
+                                                    signature))
+        return signature
+
+    class cpuid_signature(MiniSubtest):
+        """
+        test signature in specified leaf:index:regs
+        """
+        def test(self):
+            has_error = False
+            flags = params.get("flags","")
+            leaf = params.get("leaf","0x40000000")
+            idx = params.get("index","0x00")
+            regs = params.get("regs","ebx ecx edx").split()
+            if params.get("signature") is None:
+                raise error.TestNAError("'signature' must be specified in"
+                                        "config for this test")
+            try:
+                out = get_guest_cpuid(self, cpu_model, flags)
+                signature = cpuid_regs_to_string(out, leaf, idx, regs)
+                if signature != params.get("signature"):
+                    raise error.TestFail("Guest's signature [%s], doesn't"
+                                         "match required signature [%s]" %
+                                         (signature, params.get("signature")))
+            except:
+                has_error = True
+                if xfail is False:
+                    raise
+            if (has_error is False) and (xfail is True):
+                raise error.TestFail("Test was expected to fail, but it 
didn't")
+
 
     # subtests runner
     test_type = params.get("test_type")
-- 
1.7.1

_______________________________________________
Virt-test-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virt-test-devel

Reply via email to