public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Anton Mikanovich <amikan@ilbers.de>
To: isar-users@googlegroups.com
Cc: Anton Mikanovich <amikan@ilbers.de>
Subject: [PATCH 5/5] start_vm: Reuse getVars API
Date: Fri, 14 Jun 2024 14:23:20 +0300	[thread overview]
Message-ID: <20240614112320.122428-6-amikan@ilbers.de> (raw)
In-Reply-To: <20240614112320.122428-1-amikan@ilbers.de>

We already have an API to get Bitbake variable values without manual
handling of bitbake execution. This will speedup und simplify start_vm.

Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
---
 testsuite/start_vm.py | 47 ++++++++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 23 deletions(-)

diff --git a/testsuite/start_vm.py b/testsuite/start_vm.py
index 45e509a7..ada13121 100755
--- a/testsuite/start_vm.py
+++ b/testsuite/start_vm.py
@@ -11,43 +11,49 @@ import sys
 import shutil
 import time
 
+from utils import CIUtils
+
 OVMF_VARS_PATH = '/usr/share/OVMF/OVMF_VARS_4M.ms.fd'
 
-def get_bitbake_env(arch, distro, image):
+def format_qemu_cmdline(arch, build, distro, image, out, pid, enforce_pcbios=False):
     multiconfig = 'mc:qemu' + arch + '-' + distro + ':' + image
-    output = subprocess.check_output(['bitbake', '-e', str(multiconfig)])
-    return output
 
-def get_bitbake_var(output, var):
-    ret = ''
-    for line in output.splitlines():
-        if line.startswith(var + '='):
-            ret = line.split('"')[1]
-    return ret
-
-def format_qemu_cmdline(arch, build, distro, image, out, pid, enforce_pcbios=False):
-    bb_output = get_bitbake_env(arch, distro, image).decode()
+    image_type, \
+    deploy_dir_image, \
+    kernel_image, \
+    initrd_image, \
+    serial, \
+    root_dev, \
+    qemu_arch, \
+    qemu_machine, \
+    qemu_cpu, \
+    qemu_disk_args = CIUtils.getVars('IMAGE_FSTYPES', \
+                                     'DEPLOY_DIR_IMAGE', \
+                                     'KERNEL_IMAGE', \
+                                     'INITRD_DEPLOY_FILE', \
+                                     'MACHINE_SERIAL', \
+                                     'QEMU_ROOTFS_DEV', \
+                                     'QEMU_ARCH', \
+                                     'QEMU_MACHINE', \
+                                     'QEMU_CPU', \
+                                     'QEMU_DISK_ARGS', \
+                                     target=multiconfig)
 
     extra_args = ''
     cpu = ['']
 
-    image_type = get_bitbake_var(bb_output, 'IMAGE_FSTYPES').split()[0]
-    deploy_dir_image = get_bitbake_var(bb_output, 'DEPLOY_DIR_IMAGE')
     base = 'ubuntu' if distro in ['jammy', 'focal'] else 'debian'
 
     rootfs_image = image + '-' + base + '-' + distro + '-qemu' + arch + '.' + image_type
 
     if image_type == 'ext4':
-        kernel_image = deploy_dir_image + '/' + get_bitbake_var(bb_output, 'KERNEL_IMAGE')
-        initrd_image = get_bitbake_var(bb_output, 'INITRD_DEPLOY_FILE')
+        kernel_image = deploy_dir_image + '/' + kernel_image
 
         if not initrd_image:
             initrd_image = '/dev/null'
         else:
             initrd_image = deploy_dir_image + '/' + initrd_image
 
-        serial = get_bitbake_var(bb_output, 'MACHINE_SERIAL')
-        root_dev = get_bitbake_var(bb_output, 'QEMU_ROOTFS_DEV')
         kargs = ['-append', '"console=' + serial + ' root=/dev/' + root_dev + ' rw"']
 
         extra_args = ['-kernel', kernel_image, '-initrd', initrd_image]
@@ -57,11 +63,6 @@ def format_qemu_cmdline(arch, build, distro, image, out, pid, enforce_pcbios=Fal
     else:
         raise ValueError('Invalid image type: ' + str(image_type))
 
-    qemu_arch = get_bitbake_var(bb_output, 'QEMU_ARCH')
-    qemu_machine = get_bitbake_var(bb_output, 'QEMU_MACHINE')
-    qemu_cpu = get_bitbake_var(bb_output, 'QEMU_CPU')
-    qemu_disk_args = get_bitbake_var(bb_output, 'QEMU_DISK_ARGS')
-
     if out:
         extra_args.extend(['-chardev','stdio,id=ch0,logfile=' + out])
         extra_args.extend(['-serial','chardev:ch0'])
-- 
2.34.1


      parent reply	other threads:[~2024-06-14 11:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-14 11:23 [PATCH 0/5] Remove code duplications for start_vm Anton Mikanovich
2024-06-14 11:23 ` [PATCH 1/5] start_vm: Switch to python version Anton Mikanovich
2024-06-14 11:23 ` [PATCH 2/5] start_vm: Add secureboot support Anton Mikanovich
2024-06-14 11:23 ` [PATCH 3/5] scripts: Remove vm_smoke_test Anton Mikanovich
2024-06-14 11:23 ` [PATCH 4/5] CI: Allow external usage for some APIs Anton Mikanovich
2024-06-14 11:23 ` Anton Mikanovich [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240614112320.122428-6-amikan@ilbers.de \
    --to=amikan@ilbers.de \
    --cc=isar-users@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox