@@ -288,7 +288,7 @@ def testimage_main(d):
boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT"))
# Get use_kvm
- kvm = oe.types.qemu_use_kvm(d.getVar('QEMU_USE_KVM'), d.getVar('TARGET_ARCH'))
+ kvm = oe.qemu.qemu_use_kvm(d.getVar('QEMU_USE_KVM'), d.getVar('TARGET_ARCH'))
# Get OVMF
ovmf = d.getVar("QEMU_USE_OVMF")
@@ -4,6 +4,11 @@
# SPDX-License-Identifier: GPL-2.0-only
#
+import os
+import re
+
+import oe.types
+
def qemu_target_binary(d):
package_arch = d.getVar("PACKAGE_ARCH")
qemu_target_binary = (d.getVar("QEMU_TARGET_BINARY_%s" % package_arch) or "")
@@ -52,3 +57,27 @@ def qemu_run_binary(d, rootfs_path, binary):
base_libdir = rootfs_path + d.getVar("base_libdir", False)
return qemu_wrapper_cmdline(d, rootfs_path, [libdir, base_libdir]) + rootfs_path + binary
+
+def is_x86(arch):
+ """
+ Check whether ``arch`` is ``x86`` or ``x86_64``, return ``True`` if it is,
+ ``False`` otherwise.
+ """
+ if arch.startswith('x86_') or re.match('i.*86', arch):
+ 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 oe.types.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
@@ -163,26 +163,3 @@ 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):
- 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
@@ -8,7 +8,7 @@
from oeqa.selftest.case import OESelftestTestCase
from oeqa.utils.commands import bitbake, runqemu, get_bb_var
from oeqa.core.decorator.data import skipIfNotMachine
-import oe.types
+import oe.qemu
class GenericEFITest(OESelftestTestCase):
"""EFI booting test class"""
@@ -17,7 +17,7 @@ class GenericEFITest(OESelftestTestCase):
image = "core-image-minimal"
runqemu_params = get_bb_var('TEST_RUNQEMUPARAMS', image) or ""
cmd = "runqemu %s nographic serial wic ovmf" % (runqemu_params)
- if oe.types.qemu_use_kvm(self.td.get('QEMU_USE_KVM', 0), self.td["TARGET_ARCH"]):
+ if oe.qemu.qemu_use_kvm(self.td.get('QEMU_USE_KVM', 0), self.td["TARGET_ARCH"]):
cmd += " kvm"
self.write_config("""
@@ -7,7 +7,7 @@
import os
import re
import time
-import oe.types
+import oe.qemu
from oeqa.core.decorator import OETestTag
from oeqa.core.decorator.data import skipIfNotArch, skipIfNotMachine
from oeqa.selftest.case import OESelftestTestCase
@@ -34,7 +34,7 @@ class RunqemuTests(OESelftestTestCase):
self.fstypes += " wic.vmdk wic.qcow2 wic.vdi wic.zst"
self.cmd_common = "runqemu nographic snapshot"
- kvm = oe.types.qemu_use_kvm(get_bb_var('QEMU_USE_KVM'), self.td["TARGET_ARCH"])
+ kvm = oe.qemu.qemu_use_kvm(get_bb_var('QEMU_USE_KVM'), self.td["TARGET_ARCH"])
if kvm:
self.cmd_common += " kvm"
@@ -9,7 +9,7 @@ from oeqa.selftest.case import OESelftestTestCase
from oeqa.utils.commands import bitbake, runqemu, get_bb_var
from oeqa.core.decorator.data import skipIfNotArch
from oeqa.core.decorator import OETestTag
-import oe.types
+import oe.qemu
class UkiTest(OESelftestTestCase):
"""Boot Unified Kernel Image (UKI) generated with uki.bbclass on UEFI firmware (omvf/edk2)"""
@@ -21,7 +21,7 @@ class UkiTest(OESelftestTestCase):
image = "core-image-minimal"
runqemu_params = get_bb_var('TEST_RUNQEMUPARAMS', image) or ""
cmd = "runqemu %s nographic serial wic ovmf" % (runqemu_params)
- if oe.types.qemu_use_kvm(self.td.get('QEMU_USE_KVM', 0), self.td["TARGET_ARCH"]):
+ if oe.qemu.qemu_use_kvm(self.td.get('QEMU_USE_KVM', 0), self.td["TARGET_ARCH"]):
cmd += " kvm"
self.write_config("""
@@ -91,7 +91,7 @@ class QemuTarget(BaseTarget):
def __init__(self, d, logger, image_fstype=None, boot_patterns=None):
- import oe.types
+ import oe.qemu
super(QemuTarget, self).__init__(d, logger)
@@ -108,7 +108,7 @@ class QemuTarget(BaseTarget):
dump_dir = d.getVar("TESTIMAGE_DUMP_DIR")
if not dump_dir:
dump_dir = os.path.join(d.getVar('LOG_DIR'), 'runtime-hostdump')
- use_kvm = oe.types.qemu_use_kvm(d.getVar('QEMU_USE_KVM'), d.getVar('TARGET_ARCH'))
+ use_kvm = oe.qemu.qemu_use_kvm(d.getVar('QEMU_USE_KVM'), d.getVar('TARGET_ARCH'))
# Log QemuRunner log output to a file
import oe.path
The oe.types library represents OpenEmbedded types such as booleans, integers, etc. which is unrelated to what these two functions do: is_x86() checks if a given arch matches the x86 architecture, and qemu_use_kvm() is used to return True to enable KVM based on the current target architecture. Move these two functions to oe.qemu which is more appropriate. Adapt usage in OE-Core as a consequence. Signed-off-by: Antonin Godard <antonin.godard@bootlin.com> --- meta/classes-recipe/testimage.bbclass | 2 +- meta/lib/oe/qemu.py | 29 +++++++++++++++++++ meta/lib/oe/types.py | 23 --------------- .../oeqa/selftest/cases/efibootpartition.py | 4 +-- meta/lib/oeqa/selftest/cases/runqemu.py | 4 +-- meta/lib/oeqa/selftest/cases/uki.py | 4 +-- meta/lib/oeqa/targetcontrol.py | 4 +-- 7 files changed, 38 insertions(+), 32 deletions(-)