Skip to contentSkip to conversation

oeqa: Fix for QEMU_USE_KVM

PATCH Superseded Robert Yang 2 participants 5 messages Jan 3, 2019 – Jan 4, 2019

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover oeqa: Fix for QEMU_USE_KVM

The following changes since commit caa776bdcf8ea34c857f45970370bf771075f4bc:

testimage.bbclass: remove boot parameter systemd.log_target (2018-12-27 22:50:01 +0000)

are available in the git repository at:

git://git.openembedded.org/openembedded-core-contrib rbt/kvm
http://cgit.openembedded.org/openembedded-core-contrib/log/?h=rbt/kvm

Robert Yang (2):
oeqa: Fix for QEMU_USE_KVM oeqa/selftest/runqemu: enable kvm when QEMU_USE_KVM is set

 meta/classes/testimage.bbclass          |  8 +-------
 meta/lib/oe/types.py                    | 18 ++++++++++++++++++
 meta/lib/oeqa/selftest/cases/runqemu.py |  5 +++++
 meta/lib/oeqa/targetcontrol.py          |  8 +-------
 4 files changed, 25 insertions(+), 14 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/2 oeqa: Fix for QEMU_USE_KVM

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'

---
 meta/classes/testimage.bbclass |  8 +-------
 meta/lib/oe/types.py           | 18 ++++++++++++++++++
 meta/lib/oeqa/targetcontrol.py |  8 +-------
 3 files changed, 20 insertions(+), 14 deletions(-)
meta/classes/testimage.bbclass +1 -7
index e8fa4a3..82aef9f 100644
@@ -230,13 +230,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('MACHINE'))
 
     slirp = False
     if d.getVar("QEMU_USE_SLIRP"):
meta/lib/oe/types.py +18 -0
index f401713..a153f2c 100644
@@ -156,3 +156,21 @@ def path(value, relativeto='', normalize='true', mustexist='false'):
                 raise ValueError("{0}: {1}".format(value, os.strerror(errno.ENOENT)))
 
     return value
+
+def qemu_use_kvm(kvm, machine):
+    """
+    kvm can be:
+    - bool: 0, yes, ...
+    - MACHINEs: qemux86 qemux86-64 ...
+    """
+    use_kvm = False
+    if kvm:
+        kvm_boolean = False
+        try:
+            kvm_boolean = boolean(kvm)
+        except ValueError:
+            pass
+        if (kvm_boolean and "x86" in machine) or (machine in kvm.split()):
+            use_kvm = True
+    return use_kvm
+
meta/lib/oeqa/targetcontrol.py +1 -7
index 59a9c35..980d6a2 100644
@@ -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('MACHINE'))
 
         # Log QemuRunner log output to a file
         import oe.path
Signature · 1 line
2.7.4
#2 lore raw
Quoted 90 lines · Robert Yang

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'

---
 meta/classes/testimage.bbclass |  8 +-------
 meta/lib/oe/types.py           | 18 ++++++++++++++++++
 meta/lib/oeqa/targetcontrol.py |  8 +-------
 3 files changed, 20 insertions(+), 14 deletions(-)
meta/classes/testimage.bbclass +1 -7
index e8fa4a3..82aef9f 100644
@@ -230,13 +230,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('MACHINE'))
 
     slirp = False
     if d.getVar("QEMU_USE_SLIRP"):
meta/lib/oe/types.py +0 -0
index f401713..a153f2c 100644
@@ -156,3 +156,21 @@ def path(value, relativeto='', normalize='true',

mustexist='false'):

                 raise ValueError("{0}: {1}".format(value,

os.strerror(errno.ENOENT)))

return value

meta/lib/oe/types.py +15 -0
+
+def qemu_use_kvm(kvm, machine):
+    """
+    kvm can be:
+    - bool: 0, yes, ...
+    - MACHINEs: qemux86 qemux86-64 ...
+    """
+    use_kvm = False
+    if kvm:
+        kvm_boolean = False
+        try:
+            kvm_boolean = boolean(kvm)
+        except ValueError:
+            pass
+        if (kvm_boolean and "x86" in machine) or (machine in

kvm.split()):

meta/lib/oe/types.py +3 -0
+            use_kvm = True
+    return use_kvm
+
meta/lib/oeqa/targetcontrol.py +1 -7
index 59a9c35..980d6a2 100644
@@ -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('MACHINE'))
 
Quoted 2 lines

# Log QemuRunner log output to a file
import oe.path

There have been a few patches related to this floating around. I'd like to fix this once and for all but we don't have a patch which quite gets this to where it needs to be.

I'd suggest we:

a) drop the approach of having MACHINE in the variable and simply have it either set to enabled or disabled

b) only enable KVM if the target arch matches the host arch

For b) I'd like to cover the case where qemuarm64 is being run on an aarch64 server.

This way we'd automatically enable KVM where the arch matches rather than needing to code it for each MACHINE.

Does that make sense?

Cheers,

Richard

#3 lore raw
Quoted 107 lines · Richard Purdie
Quoted 90 lines · Robert Yang

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'

---
  meta/classes/testimage.bbclass |  8 +-------
  meta/lib/oe/types.py           | 18 ++++++++++++++++++
  meta/lib/oeqa/targetcontrol.py |  8 +-------
  3 files changed, 20 insertions(+), 14 deletions(-)
meta/classes/testimage.bbclass +1 -7
index e8fa4a3..82aef9f 100644
@@ -230,13 +230,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('MACHINE'))
 
      slirp = False
      if d.getVar("QEMU_USE_SLIRP"):
meta/lib/oe/types.py +0 -0
index f401713..a153f2c 100644
@@ -156,3 +156,21 @@ def path(value, relativeto='', normalize='true',

mustexist='false'):

                  raise ValueError("{0}: {1}".format(value,

os.strerror(errno.ENOENT)))

return value

meta/lib/oe/types.py +15 -0
+
+def qemu_use_kvm(kvm, machine):
+    """
+    kvm can be:
+    - bool: 0, yes, ...
+    - MACHINEs: qemux86 qemux86-64 ...
+    """
+    use_kvm = False
+    if kvm:
+        kvm_boolean = False
+        try:
+            kvm_boolean = boolean(kvm)
+        except ValueError:
+            pass
+        if (kvm_boolean and "x86" in machine) or (machine in

kvm.split()):

meta/lib/oe/types.py +3 -0
+            use_kvm = True
+    return use_kvm
+
meta/lib/oeqa/targetcontrol.py +1 -7
index 59a9c35..980d6a2 100644
@@ -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('MACHINE'))
 
Quoted 2 lines

# Log QemuRunner log output to a file
import oe.path

There have been a few patches related to this floating around. I'd like to fix this once and for all but we don't have a patch which quite gets this to where it needs to be.

I'd suggest we:

a) drop the approach of having MACHINE in the variable and simply have it either set to enabled or disabled

b) only enable KVM if the target arch matches the host arch

Quoted 7 lines

For b) I'd like to cover the case where qemuarm64 is being run on an aarch64 server.

This way we'd automatically enable KVM where the arch matches rather than needing to code it for each MACHINE.

Does that make sense?

Thanks, that make sense, I've sent a v2 for it:

[OE-core] [PATCH v2 0/3] oeqa: Fix for QEMU_USE_KVM

// Robert

Quoted 8 lines

Cheers,

Richard

#4 lore raw

PATCH 2/2 oeqa/selftest/runqemu: enable kvm when QEMU_USE_KVM is set

In reply to Robert Yang
---
 meta/lib/oeqa/selftest/cases/runqemu.py | 5 +++++
 1 file changed, 5 insertions(+)
meta/lib/oeqa/selftest/cases/runqemu.py +5 -0
index 4e35bb9..0b664b4 100644
@@ -5,6 +5,7 @@
 import re
 import tempfile
 import time
+import oe.types
 from oeqa.selftest.case import OESelftestTestCase
 from oeqa.utils.commands import bitbake, runqemu, get_bb_var, runCmd
 from oeqa.core.decorator.oeid import OETestID
@@ -22,6 +23,10 @@ class RunqemuTests(OESelftestTestCase):
         self.fstypes = "ext4 iso hddimg wic.vmdk wic.qcow2 wic.vdi"
         self.cmd_common = "runqemu nographic"
 
+        kvm = oe.types.qemu_use_kvm(get_bb_var('QEMU_USE_KVM'), self.machine)
+        if kvm:
+            self.cmd_common += " kvm"
+
         self.write_config(
 """
 MACHINE = "%s"
Signature · 1 line
2.7.4