[v2,1/3] oeqa: Fix for QEMU_USE_KVM

Submitted by Robert Yang on Jan. 4, 2019, 7:15 a.m. | Patch ID: 157567

Details

Message ID f20642eb8822150fa43d2c9fada6c5c36c1d08e7.1546585931.git.liezhi.yang@windriver.com
State New
Headers show

Commit Message

Robert Yang Jan. 4, 2019, 7:15 a.m.
Fixed:
MACHINE = "qemux86"
QEMU_USE_KVM = "qemux86"
IMAGE_CLASSES += "testimage"

$ oe-selftest -r runqemu.RunqemuTests.test_boot_rootfs

[snip]
  File "/buildarea1/lyang1/poky/meta/lib/oe/types.py", line 122, in boolean
    raise ValueError("Invalid boolean value '%s'" % value)
ValueError: Invalid boolean value 'qemux86'

Now QEMU_USE_KVM can only be boolean, can not contain MACHINE any more, kvm
will be enabled if target_arch == build_arch or both of them are x86 archs.

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
---
 meta/classes/testimage.bbclass |  8 +-------
 meta/lib/oe/types.py           | 24 ++++++++++++++++++++++++
 meta/lib/oeqa/targetcontrol.py |  8 +-------
 3 files changed, 26 insertions(+), 14 deletions(-)

Patch hide | download patch | download mbox

diff --git a/meta/classes/testimage.bbclass b/meta/classes/testimage.bbclass
index 3c2209a..73cd375 100644
--- a/meta/classes/testimage.bbclass
+++ b/meta/classes/testimage.bbclass
@@ -231,13 +231,7 @@  def testimage_main(d):
     boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT"))
 
     # Get use_kvm
-    qemu_use_kvm = d.getVar("QEMU_USE_KVM")
-    if qemu_use_kvm and \
-       (d.getVar('MACHINE') in qemu_use_kvm.split() or \
-        oe.types.boolean(qemu_use_kvm) and 'x86' in machine):
-        kvm = True
-    else:
-        kvm = False
+    kvm = oe.types.qemu_use_kvm(d.getVar('QEMU_USE_KVM'), d.getVar('TARGET_ARCH'))
 
     slirp = False
     if d.getVar("QEMU_USE_SLIRP"):
diff --git a/meta/lib/oe/types.py b/meta/lib/oe/types.py
index f401713..b9462e0 100644
--- a/meta/lib/oe/types.py
+++ b/meta/lib/oe/types.py
@@ -156,3 +156,27 @@  def path(value, relativeto='', normalize='true', mustexist='false'):
                 raise ValueError("{0}: {1}".format(value, os.strerror(errno.ENOENT)))
 
     return value
+
+def is_x86(arch):
+    """
+    Check whether arch is x86 or x86_64
+    """
+    if arch.startswith('x86_') or re.match('i.*86', arch) or arch == 'ia64':
+        return True
+    else:
+        return False
+
+def qemu_use_kvm(kvm, target_arch):
+    """
+    Enable kvm if target_arch == build_arch or both of them are x86 archs.
+    """
+
+    use_kvm = False
+    if kvm and boolean(kvm):
+        build_arch = os.uname()[4]
+        if is_x86(build_arch) and is_x86(target_arch):
+            use_kvm = True
+        elif build_arch == target_arch:
+            use_kvm = True
+    return use_kvm
+
diff --git a/meta/lib/oeqa/targetcontrol.py b/meta/lib/oeqa/targetcontrol.py
index 59a9c35..288e747 100644
--- a/meta/lib/oeqa/targetcontrol.py
+++ b/meta/lib/oeqa/targetcontrol.py
@@ -107,13 +107,7 @@  class QemuTarget(BaseTarget):
         dump_target_cmds = d.getVar("testimage_dump_target")
         dump_host_cmds = d.getVar("testimage_dump_host")
         dump_dir = d.getVar("TESTIMAGE_DUMP_DIR")
-        qemu_use_kvm = d.getVar("QEMU_USE_KVM")
-        if qemu_use_kvm and \
-           (oe.types.boolean(qemu_use_kvm) and "x86" in d.getVar("MACHINE") or \
-            d.getVar("MACHINE") in qemu_use_kvm.split()):
-            use_kvm = True
-        else:
-            use_kvm = False
+        use_kvm = oe.types.qemu_use_kvm(d.getVar('QEMU_USE_KVM'), d.getVar('TARGET_ARCH'))
 
         # Log QemuRunner log output to a file
         import oe.path

Comments

Richard Purdie Jan. 7, 2019, 3:24 p.m.
On Fri, 2019-01-04 at 15:15 +0800, Robert Yang wrote:
> Fixed:
> MACHINE = "qemux86"
> QEMU_USE_KVM = "qemux86"
> IMAGE_CLASSES += "testimage"
> 
> $ oe-selftest -r runqemu.RunqemuTests.test_boot_rootfs
> 
> [snip]
>   File "/buildarea1/lyang1/poky/meta/lib/oe/types.py", line 122, in
> boolean
>     raise ValueError("Invalid boolean value '%s'" % value)
> ValueError: Invalid boolean value 'qemux86'
> 
> Now QEMU_USE_KVM can only be boolean, can not contain MACHINE any
> more, kvm
> will be enabled if target_arch == build_arch or both of them are x86
> archs.
> 
[...]
> +def is_x86(arch):
> +    """
> +    Check whether arch is x86 or x86_64
> +    """
> +    if arch.startswith('x86_') or re.match('i.*86', arch) or arch ==
> 'ia64':
> +        return True

Thanks, I've queued this for testing. I did remove the ia64 test here
as ia64 is itanium which can't do x86 KVM from what I know.

We may also need to add something for arm == aarch64 comparisons, I'm
not 100% sure what is supproted. I've cc'd Jon on that...

Cheers,

Richard