Skip to contentSkip to conversation

oeqa/selftest/sdk: add test_sdk_runqemu

RFC PATCH In review [email protected] 2 participants 6 messages Feb 7 – Feb 12

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 oeqa/selftest/sdk: add test_sdk_runqemu

From: Chen Qi <[email protected]>

Add test case to ensure runqemu works in SDK.

Using runqemu from SDK has been supported for many years. Add a test case to ensure we have no regression.

---
 meta/lib/oeqa/selftest/cases/sdk.py | 88 ++++++++++++++++++++++++++++-
 1 file changed, 87 insertions(+), 1 deletion(-)
meta/lib/oeqa/selftest/cases/sdk.py +87 -1
index 3971365029..ee1e4ca420 100644
@@ -4,7 +4,13 @@
 # SPDX-License-Identifier: MIT
 #
 
-import os.path
+import os
+import shutil
+import subprocess
+import glob
+import time
+import select
+from tempfile import TemporaryDirectory
 
 from oeqa.selftest.case import OESelftestTestCase
 from oeqa.utils.commands import bitbake, get_bb_vars
@@ -37,3 +43,83 @@ IMAGE_INSTALL:append = " selftest-hello"
         path = os.path.join(vars["SDK_DEPLOY"], vars["TOOLCHAIN_OUTPUTNAME"] + ".target.manifest")
         self.assertNotEqual(os.path.getsize(path), 0, msg="Target manifest is empty")
         self.assertIn("selftest-hello", self.load_manifest(path))
+
+    def test_sdk_runqemu(self):
+        """Test using runqemu from SDK which has no bitbake available"""
+
+        def path_with_no_bitbake():
+            orig_paths = os.environ["PATH"].split(":")
+            new_paths = []
+            for orig_path in orig_paths:
+                if not os.access(os.path.join(orig_path, "bitbake"), os.X_OK):
+                    new_paths.append(orig_path)
+            return ":".join(new_paths)
+
+        def runqemu_works_from_sdk(sdk_dir, sdk_env, machine, path, timeout=360):
+            env = os.environ.copy()
+            env["PATH"] = path
+
+            cmd = f'cd {sdk_dir}; . {sdk_env}; runqemu {machine} snapshot slirp nographic'
+            self.logger.info(f"Running {cmd}")
+            proc = subprocess.Popen(
+                ['bash', '-c', cmd],
+                stdout=subprocess.PIPE,
+                stderr=subprocess.STDOUT,
+                text=True,
+                bufsize=1,
+                env=env
+            )
+            buffer = ""
+            start = time.time()
+            while time.time() - start < timeout:
+                if proc.poll() is not None:
+                    chunk = proc.stdout.read()
+                    if chunk:
+                        buffer += chunk
+                    return ('Linux version' in buffer, "\n".join(buffer.split('\n')[-10:]))
+                ready, _, _ = select.select([proc.stdout], [], [], 0.1)
+                if ready:
+                    chunk = proc.stdout.read(4096)
+                    if chunk:
+                        buffer += chunk
+                        if "Linux version" in buffer:
+                            proc.terminate()
+                            return (True, "\n".join(buffer.split('\n')[-10:]))
+                time.sleep(0.1)
+            proc.terminate()
+            time.sleep(5)
+            if proc.poll() is None:
+                proc.kill()
+            return (False, "\n".join(buffer.split('\n')[-10:]))
+
+        image = "core-image-minimal"
+
+        self.write_config('QEMU_USE_KVM = "1"')
+
+        # generate image and SDK
+        bitbake(f"{image}")
+        bitbake(f"{image} -c populate_sdk")
+
+        # create a temporary destdir to test runqemu from SDK
+        with TemporaryDirectory() as tmpdir:
+            self.logger.debug(f"Created tempdir: {tmpdir}")
+            vars = get_bb_vars(["DEPLOY_DIR_IMAGE", "SDK_DEPLOY", "TOOLCHAIN_OUTPUTNAME", "MACHINE"], image)
+            machine = vars["MACHINE"]
+            image_dir = vars["DEPLOY_DIR_IMAGE"]
+            sdk_path = os.path.join(vars["SDK_DEPLOY"], vars["TOOLCHAIN_OUTPUTNAME"] + ".sh")
+            self.logger.debug(f"machine: {machine}")
+            self.logger.debug(f"image_dir: {image_dir}")
+            self.logger.debug(f"sdk_path: {sdk_path}")
+            dst_image_dir = os.path.join(tmpdir, os.path.basename(image_dir))
+            shutil.copytree(image_dir, dst_image_dir)
+            subprocess.check_call(f"{sdk_path} -d {tmpdir} -y", shell=True)
+            sdk_env = glob.glob(tmpdir + '/environment-setup-*')[0]
+            self.logger.debug(f"sdk_env: {sdk_env}")
+
+            path = path_with_no_bitbake()
+            self.logger.debug(f"path: {path}")
+
+            runqemu_works, output = runqemu_works_from_sdk(tmpdir, sdk_env, machine, path)
+            self.logger.debug(f"runqemu works in SDK: {runqemu_works}\n{output}")
+
+            self.assertTrue(runqemu_works, f"runqemu does not work in SDK\n{output}")
Signature · 1 line
2.43.0
#1 lore raw

Thanks for writing this up, I'll get to it once some more pressing issues are taken care of.

Alex

Quoted 119 lines · On Sat, 7 Feb 2026 at 06:13, <[email protected]> wrote:

From: Chen Qi <[email protected]>

Add test case to ensure runqemu works in SDK.

Using runqemu from SDK has been supported for many years. Add a test case to ensure we have no regression.

---
 meta/lib/oeqa/selftest/cases/sdk.py | 88 ++++++++++++++++++++++++++++-
 1 file changed, 87 insertions(+), 1 deletion(-)
meta/lib/oeqa/selftest/cases/sdk.py +87 -2
index 3971365029..ee1e4ca420 100644
@@ -4,7 +4,13 @@
 # SPDX-License-Identifier: MIT
 #
 
-import os.path
+import os
+import shutil
+import subprocess
+import glob
+import time
+import select
+from tempfile import TemporaryDirectory
 
 from oeqa.selftest.case import OESelftestTestCase
 from oeqa.utils.commands import bitbake, get_bb_vars
@@ -37,3 +43,83 @@ IMAGE_INSTALL:append = " selftest-hello"
         path = os.path.join(vars["SDK_DEPLOY"], vars["TOOLCHAIN_OUTPUTNAME"] + ".target.manifest")
         self.assertNotEqual(os.path.getsize(path), 0, msg="Target manifest is empty")
         self.assertIn("selftest-hello", self.load_manifest(path))
+
+    def test_sdk_runqemu(self):
+        """Test using runqemu from SDK which has no bitbake available"""
+
+        def path_with_no_bitbake():
+            orig_paths = os.environ["PATH"].split(":")
+            new_paths = []
+            for orig_path in orig_paths:
+                if not os.access(os.path.join(orig_path, "bitbake"), os.X_OK):
+                    new_paths.append(orig_path)
+            return ":".join(new_paths)
+
+        def runqemu_works_from_sdk(sdk_dir, sdk_env, machine, path, timeout=360):
+            env = os.environ.copy()
+            env["PATH"] = path
+
+            cmd = f'cd {sdk_dir}; . {sdk_env}; runqemu {machine} snapshot slirp nographic'
+            self.logger.info(f"Running {cmd}")
+            proc = subprocess.Popen(
+                ['bash', '-c', cmd],
+                stdout=subprocess.PIPE,
+                stderr=subprocess.STDOUT,
+                text=True,
+                bufsize=1,
+                env=env
+            )
+            buffer = ""
+            start = time.time()
+            while time.time() - start < timeout:
+                if proc.poll() is not None:
+                    chunk = proc.stdout.read()
+                    if chunk:
+                        buffer += chunk
+                    return ('Linux version' in buffer, "\n".join(buffer.split('\n')[-10:]))
+                ready, _, _ = select.select([proc.stdout], [], [], 0.1)
+                if ready:
+                    chunk = proc.stdout.read(4096)
+                    if chunk:
+                        buffer += chunk
+                        if "Linux version" in buffer:
+                            proc.terminate()
+                            return (True, "\n".join(buffer.split('\n')[-10:]))
+                time.sleep(0.1)
+            proc.terminate()
+            time.sleep(5)
+            if proc.poll() is None:
+                proc.kill()
+            return (False, "\n".join(buffer.split('\n')[-10:]))
+
+        image = "core-image-minimal"
+
+        self.write_config('QEMU_USE_KVM = "1"')
+
+        # generate image and SDK
+        bitbake(f"{image}")
+        bitbake(f"{image} -c populate_sdk")
+
+        # create a temporary destdir to test runqemu from SDK
+        with TemporaryDirectory() as tmpdir:
+            self.logger.debug(f"Created tempdir: {tmpdir}")
+            vars = get_bb_vars(["DEPLOY_DIR_IMAGE", "SDK_DEPLOY", "TOOLCHAIN_OUTPUTNAME", "MACHINE"], image)
+            machine = vars["MACHINE"]
+            image_dir = vars["DEPLOY_DIR_IMAGE"]
+            sdk_path = os.path.join(vars["SDK_DEPLOY"], vars["TOOLCHAIN_OUTPUTNAME"] + ".sh")
+            self.logger.debug(f"machine: {machine}")
+            self.logger.debug(f"image_dir: {image_dir}")
+            self.logger.debug(f"sdk_path: {sdk_path}")
+            dst_image_dir = os.path.join(tmpdir, os.path.basename(image_dir))
+            shutil.copytree(image_dir, dst_image_dir)
+            subprocess.check_call(f"{sdk_path} -d {tmpdir} -y", shell=True)
+            sdk_env = glob.glob(tmpdir + '/environment-setup-*')[0]
+            self.logger.debug(f"sdk_env: {sdk_env}")
+
+            path = path_with_no_bitbake()
+            self.logger.debug(f"path: {path}")
+
+            runqemu_works, output = runqemu_works_from_sdk(tmpdir, sdk_env, machine, path)
+            self.logger.debug(f"runqemu works in SDK: {runqemu_works}\n{output}")
+
+            self.assertTrue(runqemu_works, f"runqemu does not work in SDK\n{output}")
--

2.43.0

#2 lore raw
In reply to [email protected]
Quoted 4 lines · On Sat, 7 Feb 2026 at 06:13, <[email protected]> wrote:

Add test case to ensure runqemu works in SDK.

Using runqemu from SDK has been supported for many years. Add a test case to ensure we have no regression.

I set and ran this test. This indeed does not work:

====

alex@Zen2:~$ runqemu qemux86-64 kvm snapshot nographic
runqemu - ERROR - In order for this script to dynamically infer paths
 kernels or filesystem images, you either need bitbake in your PATH
 or to source oe-init-build-env before running this script.

Dynamic path inference can be avoided by passing a *.qemuboot.conf to runqemu, i.e. runqemu /path/to/my-image-name.qemuboot.conf

Bitbake is needed to run 'MACHINE=qemux86-64 bitbake -e', but it is
not found in PATH. Please source the bitbake build environment.
====

The error makes sense, doesn't it? How would runqemu be able to figure out where the image it needs to run is on the filesystem if all it has is MACHINE value? We can try to hardcode something relative to SDK installation, from some environment variable that SDK sets, but that would be limiting: in the context of an SDK, images can be downloaded and located anywhere.

On the other hand, if you pass the path to the image directory to runqemu, it works perfectly:

====

alex@Zen2:~$ runqemu kvm slirp snapshot
/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/
runqemu - INFO - Decompressing
/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.rootfs-20260210110409.ext4.zst
to /srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.rootfs-20260210110409.ext4
/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.rootfs-20260210110409.ext4.zst:
43323392 bytes
runqemu - INFO - Continuing with the following parameters:
KERNEL: [/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/bzImage]
MACHINE: [qemux86-64]
FSTYPE: [ext4]
ROOTFS: [/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.rootfs-20260210110409.ext4]
SNAPSHOT: [Enabled. Changes on rootfs won't be kept after QEMU shutdown.]
CONFFILE: [/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.rootfs-20260210110409.qemuboot.conf]
....
====

So would it be okay to set the path to the image directory explicitly? If you have several images in that directory, then you need to pass the path to a particular some-image.qemuboot.conf file, and it will still work:

alex@Zen2:~$ runqemu kvm slirp snapshot
/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.rootfs-20260210110409.qemuboot.conf

Alex

author
#3 lore raw

Hi Alex,

I guess you were still in a bitbake build environment when testing runqemu in SDK manually. That's why your command 'runqemu kvm slirp snapshot /path/to/images/qemux86-64' worked.

See commands and output below (Pure SDK, no bitbake environment):
"""
chenqi@HOST:/buildarea3/chenqi/SDK/Yocto [3][0] $ runqemu kvm snapshot slirp /buildarea3/chenqi/SDK/Yocto/qemux86-64/ runqemu - ERROR - In order for this script to dynamically infer paths
 kernels or filesystem images, you either need bitbake in your PATH
 or to source oe-init-build-env before running this script.

 Dynamic path inference can be avoided by passing a *.qemuboot.conf to runqemu, i.e. runqemu /path/to/my-image-name.qemuboot.conf

 Bitbake is needed to run 'MACHINE=qemux86-64 bitbake -e  None', but it is not found in PATH. Please source the bitbake build environment. runqemu - INFO - Cleaning up
runqemu - INFO - Host uptime: 16354810.08

chenqi@HOST:/buildarea3/chenqi/SDK/Yocto [3][0] $ runqemu kvm snapshot slirp /buildarea3/chenqi/SDK/Yocto/qemux86-64/core-image-minimal-qemux86-64.rootfs.qemuboot.conf

runqemu - ERROR - In order for this script to dynamically infer paths kernels or filesystem images, you either need bitbake in your PATH or to source oe-init-build-env before running this script.

 Dynamic path inference can be avoided by passing a *.qemuboot.conf to runqemu, i.e. runqemu /path/to/my-image-name.qemuboot.conf

 Bitbake is needed to run 'MACHINE=qemux86-64 bitbake -e  None', but it is not found in PATH. Please source the bitbake build environment. runqemu - INFO - Cleaning up
runqemu - INFO - Host uptime: 16354858.44

chenqi@HOST:/buildarea3/chenqi/SDK/Yocto [3][0] $ which bitbake chenqi@HOST:/buildarea3/chenqi/SDK/Yocto [3][0] $ echo $?
1
chenqi@HOST:/buildarea3/chenqi/SDK/Yocto [3][0] $ which runqemu /buildarea3/chenqi/SDK/Yocto/sysroots/x86_64-pokysdk-linux/usr/bin/runqemu """

Regards,
Qi

Quoted 57 lines · Alexander Kanavin
Quoted 4 lines · On Sat, 7 Feb 2026 at 06:13, <[email protected]> wrote:

Add test case to ensure runqemu works in SDK.

Using runqemu from SDK has been supported for many years. Add a test case to ensure we have no regression.

I set and ran this test. This indeed does not work:

====

alex@Zen2:~$ runqemu qemux86-64 kvm snapshot nographic
runqemu - ERROR - In order for this script to dynamically infer paths
  kernels or filesystem images, you either need bitbake in your PATH
  or to source oe-init-build-env before running this script.

Dynamic path inference can be avoided by passing a *.qemuboot.conf to runqemu, i.e. runqemu /path/to/my-image-name.qemuboot.conf

Bitbake is needed to run 'MACHINE=qemux86-64 bitbake -e', but it is
not found in PATH. Please source the bitbake build environment.
====

The error makes sense, doesn't it? How would runqemu be able to figure out where the image it needs to run is on the filesystem if all it has is MACHINE value? We can try to hardcode something relative to SDK installation, from some environment variable that SDK sets, but that would be limiting: in the context of an SDK, images can be downloaded and located anywhere.

On the other hand, if you pass the path to the image directory to runqemu, it works perfectly:

====

alex@Zen2:~$ runqemu kvm slirp snapshot
/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/
runqemu - INFO - Decompressing
/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.rootfs-20260210110409.ext4.zst
to /srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.rootfs-20260210110409.ext4
/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.rootfs-20260210110409.ext4.zst:
43323392 bytes
runqemu - INFO - Continuing with the following parameters:
KERNEL: [/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/bzImage]
MACHINE: [qemux86-64]
FSTYPE: [ext4]
ROOTFS: [/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.rootfs-20260210110409.ext4]
SNAPSHOT: [Enabled. Changes on rootfs won't be kept after QEMU shutdown.]
CONFFILE: [/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.rootfs-20260210110409.qemuboot.conf]
....
====

So would it be okay to set the path to the image directory explicitly? If you have several images in that directory, then you need to pass the path to a particular some-image.qemuboot.conf file, and it will still work:

alex@Zen2:~$ runqemu kvm slirp snapshot
/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.rootfs-20260210110409.qemuboot.conf

Alex

#4 lore raw
Quoted 4 lines · ChenQi

I guess you were still in a bitbake build environment when testing runqemu in SDK manually.
That's why your command 'runqemu kvm slirp snapshot /path/to/images/qemux86-64' worked.

Not quite. I provided the path to the original yocto build's deploy directory, which does work. It stops working if you copy the image directory to somewhere else.

The issue is that runqemu reads qemuboot.conf in that directory which hardcodes build-specific paths:

staging_bindir_native = ../../../work/x86_64-linux/qemu-helper-native/1.0/recipe-sysroot-native/usr/bin staging_dir_host = ../../../work/qemux86_64-poky-linux/core-image-minimal/1.0/recipe-sysroot staging_dir_native = ../../../work/qemux86_64-poky-linux/core-image-minimal/1.0/recipe-sysroot-native tune_arch = x86_64
uninative_loader = ../../../sysroots-uninative/x86_64-linux/lib/ld-linux-x86-64.so.2

Then the code checks them for existence, and tries to obtain them from bitbake if they don't exist:

# If the STAGING_*_NATIVE directories from the config file don't exist # and we're in a sourced OE build directory try to extract the paths # from bitbake -e
havenative = os.path.exists(self.get('STAGING_DIR_NATIVE')) and \
os.path.exists(self.get('STAGING_BINDIR_NATIVE'))

if not havenative:
if not self.bitbake_e:
self.load_bitbake_env()

native_vars = ['STAGING_DIR_NATIVE']
for nv in native_vars:
s = re.search('^%s="(.*)"' % nv, self.bitbake_e, re.M) if s and s.group(1) != self.get(nv):
logger.info('Overriding conf file setting of %s to
%s from Bitbake environment' % (nv, s.group(1)))

                    self.set(nv, s.group(1))

The above code indeed doesn't make sense: it gets STAGING_DIR_NATIVE from bitbake (if bitbake is present), but then STAGING_DIR_NATIVE is not used anywhere!

So going back to your proposed fix, is it possible to replace the above sequence with something like this?

if not os.path.exists(self.get('STAGING_BINDIR_NATIVE')):
logger.info('tell what is happening')
if OECORE_NATIVE_SYSROOT is set:
set STAGING_BINDIR_NATIVE from OECORE_NATIVE_SYSROOT + '/usr/bin' logger.info('tell what is happening')
else:
set STAGING_BINDIR_NATIVE from bitbake -e

This should cover all use cases:
- yocto or sdk environment or no environment at all, with image in deploy directory (qemuboot.conf paths are valid)
- sdk environment with image in any directory (will set paths from OECORE_NATIVE_SYSROOT)
- yocto environment with image in any directory (will ask bitbake -e for paths)

That way we can avoid reverting changes to run_bitbake_env: it should either succeed or raise an error, and not just return nothing, as that hides actual issues.

Alex

Quoted 102 lines

See commands and output below (Pure SDK, no bitbake environment):
"""
chenqi@HOST:/buildarea3/chenqi/SDK/Yocto [3][0] $ runqemu kvm snapshot slirp /buildarea3/chenqi/SDK/Yocto/qemux86-64/
runqemu - ERROR - In order for this script to dynamically infer paths
kernels or filesystem images, you either need bitbake in your PATH or to source oe-init-build-env before running this script.

Dynamic path inference can be avoided by passing a *.qemuboot.conf to runqemu, i.e. runqemu /path/to/my-image-name.qemuboot.conf

Bitbake is needed to run 'MACHINE=qemux86-64 bitbake -e None', but it
is not found in PATH. Please source the bitbake build environment. runqemu - INFO - Cleaning up
runqemu - INFO - Host uptime: 16354810.08

chenqi@HOST:/buildarea3/chenqi/SDK/Yocto [3][0] $ runqemu kvm snapshot slirp /buildarea3/chenqi/SDK/Yocto/qemux86-64/core-image-minimal-qemux86-64.rootfs.qemuboot.conf

runqemu - ERROR - In order for this script to dynamically infer paths
kernels or filesystem images, you either need bitbake in your PATH or to source oe-init-build-env before running this script.

Dynamic path inference can be avoided by passing a *.qemuboot.conf to runqemu, i.e. runqemu /path/to/my-image-name.qemuboot.conf

Bitbake is needed to run 'MACHINE=qemux86-64 bitbake -e None', but it
is not found in PATH. Please source the bitbake build environment. runqemu - INFO - Cleaning up
runqemu - INFO - Host uptime: 16354858.44

chenqi@HOST:/buildarea3/chenqi/SDK/Yocto [3][0] $ which bitbake chenqi@HOST:/buildarea3/chenqi/SDK/Yocto [3][0] $ echo $?
1
chenqi@HOST:/buildarea3/chenqi/SDK/Yocto [3][0] $ which runqemu /buildarea3/chenqi/SDK/Yocto/sysroots/x86_64-pokysdk-linux/usr/bin/runqemu """

Regards,
Qi

Quoted 57 lines · Alexander Kanavin
Quoted 4 lines · On Sat, 7 Feb 2026 at 06:13, <[email protected]> wrote:

Add test case to ensure runqemu works in SDK.

Using runqemu from SDK has been supported for many years. Add a test case to ensure we have no regression.

I set and ran this test. This indeed does not work:

====

alex@Zen2:~$ runqemu qemux86-64 kvm snapshot nographic
runqemu - ERROR - In order for this script to dynamically infer paths
  kernels or filesystem images, you either need bitbake in your PATH
  or to source oe-init-build-env before running this script.

Dynamic path inference can be avoided by passing a *.qemuboot.conf to runqemu, i.e. runqemu /path/to/my-image-name.qemuboot.conf

Bitbake is needed to run 'MACHINE=qemux86-64 bitbake -e', but it is
not found in PATH. Please source the bitbake build environment.
====

The error makes sense, doesn't it? How would runqemu be able to figure out where the image it needs to run is on the filesystem if all it has is MACHINE value? We can try to hardcode something relative to SDK installation, from some environment variable that SDK sets, but that would be limiting: in the context of an SDK, images can be downloaded and located anywhere.

On the other hand, if you pass the path to the image directory to runqemu, it works perfectly:

====

alex@Zen2:~$ runqemu kvm slirp snapshot
/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/
runqemu - INFO - Decompressing
/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.rootfs-20260210110409.ext4.zst
to /srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.rootfs-20260210110409.ext4
/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.rootfs-20260210110409.ext4.zst:
43323392 bytes
runqemu - INFO - Continuing with the following parameters:
KERNEL: [/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/bzImage]
MACHINE: [qemux86-64]
FSTYPE: [ext4]
ROOTFS: [/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.rootfs-20260210110409.ext4]
SNAPSHOT: [Enabled. Changes on rootfs won't be kept after QEMU shutdown.]
CONFFILE: [/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.rootfs-20260210110409.qemuboot.conf]
....
====

So would it be okay to set the path to the image directory explicitly? If you have several images in that directory, then you need to pass the path to a particular some-image.qemuboot.conf file, and it will still work:

alex@Zen2:~$ runqemu kvm slirp snapshot
/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.rootfs-20260210110409.qemuboot.conf

Alex

author
#5 lore raw

Hi Alex,

Thanks for checking the codes and providing advice. I think your solution will work. I'll try it out after Chinese New Year vacation.

Regards,
Qi

-----Original Message-----
From: Alexander Kanavin <[email protected]>
Sent: Wednesday, February 11, 2026 9:09 PM
To: Chen, Qi <[email protected]>
Cc: [email protected]
Subject: Re: [OE-core][RFC][PATCH] oeqa/selftest/sdk: add test_sdk_runqemu

Quoted 4 lines · ChenQi

I guess you were still in a bitbake build environment when testing runqemu in SDK manually.
That's why your command 'runqemu kvm slirp snapshot /path/to/images/qemux86-64' worked.

Not quite. I provided the path to the original yocto build's deploy directory, which does work. It stops working if you copy the image directory to somewhere else.

The issue is that runqemu reads qemuboot.conf in that directory which hardcodes build-specific paths:

staging_bindir_native = ../../../work/x86_64-linux/qemu-helper-native/1.0/recipe-sysroot-native/usr/bin staging_dir_host = ../../../work/qemux86_64-poky-linux/core-image-minimal/1.0/recipe-sysroot staging_dir_native = ../../../work/qemux86_64-poky-linux/core-image-minimal/1.0/recipe-sysroot-native tune_arch = x86_64
uninative_loader = ../../../sysroots-uninative/x86_64-linux/lib/ld-linux-x86-64.so.2

Then the code checks them for existence, and tries to obtain them from bitbake if they don't exist:

# If the STAGING_*_NATIVE directories from the config file don't exist # and we're in a sourced OE build directory try to extract the paths # from bitbake -e
havenative = os.path.exists(self.get('STAGING_DIR_NATIVE')) and \
os.path.exists(self.get('STAGING_BINDIR_NATIVE'))

if not havenative:
if not self.bitbake_e:
self.load_bitbake_env()

native_vars = ['STAGING_DIR_NATIVE']
for nv in native_vars:
s = re.search('^%s="(.*)"' % nv, self.bitbake_e, re.M)
if s and s.group(1) != self.get(nv):
logger.info('Overriding conf file setting of %s to %s from Bitbake environment' % (nv, s.group(1))) self.set(nv, s.group(1))

The above code indeed doesn't make sense: it gets STAGING_DIR_NATIVE from bitbake (if bitbake is present), but then STAGING_DIR_NATIVE is not used anywhere!

So going back to your proposed fix, is it possible to replace the above sequence with something like this?

if not os.path.exists(self.get('STAGING_BINDIR_NATIVE')):
logger.info('tell what is happening')
if OECORE_NATIVE_SYSROOT is set:
set STAGING_BINDIR_NATIVE from OECORE_NATIVE_SYSROOT + '/usr/bin' logger.info('tell what is happening')
else:
set STAGING_BINDIR_NATIVE from bitbake -e

This should cover all use cases:
- yocto or sdk environment or no environment at all, with image in deploy directory (qemuboot.conf paths are valid)
- sdk environment with image in any directory (will set paths from
OECORE_NATIVE_SYSROOT)
- yocto environment with image in any directory (will ask bitbake -e for paths)

That way we can avoid reverting changes to run_bitbake_env: it should either succeed or raise an error, and not just return nothing, as that hides actual issues.

Alex

Quoted 115 lines

See commands and output below (Pure SDK, no bitbake environment):
"""
chenqi@HOST:/buildarea3/chenqi/SDK/Yocto [3][0] $ runqemu kvm snapshot slirp /buildarea3/chenqi/SDK/Yocto/qemux86-64/
runqemu - ERROR - In order for this script to dynamically infer paths
kernels or filesystem images, you either need bitbake in your PATH or to source oe-init-build-env before running this script.

Dynamic path inference can be avoided by passing a *.qemuboot.conf to runqemu, i.e. runqemu /path/to/my-image-name.qemuboot.conf

Bitbake is needed to run 'MACHINE=qemux86-64 bitbake -e None', but
it is not found in PATH. Please source the bitbake build environment. runqemu - INFO - Cleaning up
runqemu - INFO - Host uptime: 16354810.08

chenqi@HOST:/buildarea3/chenqi/SDK/Yocto [3][0] $ runqemu kvm snapshot slirp /buildarea3/chenqi/SDK/Yocto/qemux86-64/core-image-minimal-qemux86-64. rootfs.qemuboot.conf

runqemu - ERROR - In order for this script to dynamically infer paths
kernels or filesystem images, you either need bitbake in your PATH or to source oe-init-build-env before running this script.

Dynamic path inference can be avoided by passing a *.qemuboot.conf to runqemu, i.e. runqemu /path/to/my-image-name.qemuboot.conf

Bitbake is needed to run 'MACHINE=qemux86-64 bitbake -e None', but
it is not found in PATH. Please source the bitbake build environment. runqemu - INFO - Cleaning up
runqemu - INFO - Host uptime: 16354858.44

chenqi@HOST:/buildarea3/chenqi/SDK/Yocto [3][0] $ which bitbake chenqi@HOST:/buildarea3/chenqi/SDK/Yocto [3][0] $ echo $?
1
chenqi@HOST:/buildarea3/chenqi/SDK/Yocto [3][0] $ which runqemu /buildarea3/chenqi/SDK/Yocto/sysroots/x86_64-pokysdk-linux/usr/bin/run qemu
"""

Regards,
Qi

Quoted 68 lines · Alexander Kanavin
Quoted 4 lines · On Sat, 7 Feb 2026 at 06:13, <[email protected]> wrote:

Add test case to ensure runqemu works in SDK.

Using runqemu from SDK has been supported for many years. Add a test case to ensure we have no regression.

I set and ran this test. This indeed does not work:

====

alex@Zen2:~$ runqemu qemux86-64 kvm snapshot nographic runqemu - 
ERROR - In order for this script to dynamically infer paths
  kernels or filesystem images, you either need bitbake in your PATH
  or to source oe-init-build-env before running this script.

Dynamic path inference can be avoided by passing a *.qemuboot.conf to runqemu, i.e. runqemu /path/to/my-image-name.qemuboot.conf

Bitbake is needed to run 'MACHINE=qemux86-64 bitbake -e', but it
is not found in PATH. Please source the bitbake build environment.
====

The error makes sense, doesn't it? How would runqemu be able to figure out where the image it needs to run is on the filesystem if all it has is MACHINE value? We can try to hardcode something relative to SDK installation, from some environment variable that SDK sets, but that would be limiting: in the context of an SDK, images can be downloaded and located anywhere.

On the other hand, if you pass the path to the image directory to runqemu, it works perfectly:

====

alex@Zen2:~$ runqemu kvm slirp snapshot 
/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/
runqemu - INFO - Decompressing
/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/core-i
mage-minimal-qemux86-64.rootfs-20260210110409.ext4.zst
to 
/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/core-i
mage-minimal-qemux86-64.rootfs-20260210110409.ext4
/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.rootfs-20260210110409.ext4.zst:
43323392 bytes
runqemu - INFO - Continuing with the following parameters:
KERNEL: 
[/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/bzIma
ge]
MACHINE: [qemux86-64]
FSTYPE: [ext4]
ROOTFS: 
[/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/core-
image-minimal-qemux86-64.rootfs-20260210110409.ext4]
SNAPSHOT: [Enabled. Changes on rootfs won't be kept after QEMU 
shutdown.]
CONFFILE: 
[/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/core-
image-minimal-qemux86-64.rootfs-20260210110409.qemuboot.conf]
....
====

So would it be okay to set the path to the image directory explicitly? If you have several images in that directory, then you need to pass the path to a particular some-image.qemuboot.conf file, and it will still work:

alex@Zen2:~$ runqemu kvm slirp snapshot 
/srv/storage/alex/yocto/build-64/tmp/deploy/images/qemux86-64/core-i
mage-minimal-qemux86-64.rootfs-20260210110409.qemuboot.conf

Alex