All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aniket Sahu <asahu1x@linux.ibm.com>
To: qemu-devel@nongnu.org
Cc: qemu-ppc@nongnu.org, peterx@redhat.com, farosas@suse.de,
	npiggin@gmail.com, adityag@linux.ibm.com, milesg@linux.ibm.com,
	harshpb@linux.ibm.com, rathc@linux.ibm.com,
	anushree.mathur@linux.ibm.com, misanjum@linux.ibm.com,
	gautam@linux.ibm.com, thuth@redhat.com, amachhiw@linux.ibm.com,
	asahu1x@linux.ibm.com
Subject: [PATCH 4/5] tests/functional/ppc64: dynamically resolve NVMe device path
Date: Fri, 20 Nov 2026 15:28:57 +0530	[thread overview]
Message-ID: <20261120095854.35941-11-asahu1x@linux.ibm.com> (raw)
In-Reply-To: <20261120095854.35941-7-asahu1x@linux.ibm.com>

Do not hardcode the NVMe device name in L1 as it depends on the PCIe
topology of the machine type (e.g., pseries may enumerate it as nvme0n1
or nvme1n1).

Add _resolve_nvme_dev() method to query the kernel for the actual device
path, and write the L2 launch command to a script (/tmp/run-l2.sh) to
avoid terminal line-wrap breaking shell argument parsing.

Also add '-cpu POWER9' to the L2 QEMU command line to match what
kvm-hv.ko in L1 sees, and add comprehensive debug logging throughout
do_test_kvm() and do_setup_kvm().

Signed-off-by: Aniket Sahu <asahu1x@linux.ibm.com>
---
 tests/functional/ppc64/test_hv.py | 87 +++++++++++++++++++++++++++----
 1 file changed, 78 insertions(+), 9 deletions(-)

diff --git a/tests/functional/ppc64/test_hv.py b/tests/functional/ppc64/test_hv.py
index d983e5229c..567313fb6c 100755
--- a/tests/functional/ppc64/test_hv.py
+++ b/tests/functional/ppc64/test_hv.py
@@ -10,6 +10,7 @@
 # later.  See the COPYING file in the top-level directory.
 
 import os
+import re
 import subprocess
 
 from datetime import datetime, timezone
@@ -100,9 +101,51 @@ def do_stop_alpine(self):
         self.vm.wait()
 
     def do_setup_kvm(self):
-        ps1='alpine:~#'
+        self.log.debug("do_setup_kvm: installing qemu-system-ppc64 in L1")
+        ps1 = 'alpine:~#'
         exec_command_and_wait_for_pattern(self, 'apk add qemu-system-ppc64', ps1)
+        self.log.debug("do_setup_kvm: qemu-system-ppc64 installed, loading kvm-hv")
         exec_command_and_wait_for_pattern(self, 'modprobe kvm-hv', ps1)
+        self.log.debug("do_setup_kvm: kvm-hv module loaded")
+
+    def _resolve_nvme_dev(self):
+        """
+        Determine the NVMe block device path that the ISO is attached as
+        inside the L1 Alpine guest.  The device name is not stable across
+        machine types (e.g. pseries may enumerate it as nvme0n1 or nvme1n1
+        depending on the PCIe bus topology), so we ask the kernel directly.
+
+        Returns the literal device path string, e.g. '/dev/nvme0n1', so
+        callers can bake it directly into shell scripts without any shell
+        variable scoping issues.
+        """
+        self.log.debug("_resolve_nvme_dev: probing NVMe device path in L1")
+        ps1 = 'alpine:~#'
+        # Print a clearly delimited marker and wait for the shell prompt so
+        # we accumulate all console bytes in one call — including any bytes
+        # that the terminal wraps across line boundaries.
+        out = exec_command_and_wait_for_pattern(
+            self,
+            'echo "NVME_PATH:$(ls /dev/nvme?n1 | head -1)"',
+            ps1,
+        )
+        # Decode, strip ANSI escape sequences and newlines, then extract the
+        # path.  Terminal line-wrap can split the token mid-string so we join
+        # all non-whitespace characters before matching.
+        text = out.decode('utf-8', errors='replace')
+        text = re.sub(r'\x1b\[[0-9;]*[A-Za-z]', '', text)
+        joined = ''.join(text.split())
+        # The joined string looks like: ...NVME_PATH:/dev/nvme0n1alpine:~#
+        m = re.search(r'NVME_PATH:(/dev/nvme\S+?)alpine', joined)
+        if not m:
+            m = re.search(r'NVME_PATH:(/dev/nvme\S+)', joined)
+        if m:
+            dev = m.group(1).rstrip('#~:').strip()
+        else:
+            dev = '/dev/nvme0n1'
+            self.log.debug("_resolve_nvme_dev: marker not found, using fallback")
+        self.log.debug("_resolve_nvme_dev: resolved device=%s", dev)
+        return dev
 
     # This uses the host's block device as the source file for guest block
     # device for install media. This is a bit hacky but allows reuse of the
@@ -110,16 +153,40 @@ def do_setup_kvm(self):
     def do_test_kvm(self, hpt=False):
         if hpt:
             append = 'disable_radix'
+            self.log.debug("do_test_kvm: launching L2 in HPT mode")
         else:
             append = ''
-        exec_command(self, 'qemu-system-ppc64 -nographic -smp 2 -m 1g '
-                           '-machine pseries,x-vof=on,accel=kvm '
-                           '-machine cap-cfpc=broken,cap-sbbc=broken,'
-                                    'cap-ibs=broken,cap-ccf-assist=off '
-                           '-drive file=/dev/nvme0n1,format=raw,readonly=on '
-                           '-initrd /media/nvme0n1/boot/initramfs-lts '
-                           '-kernel /media/nvme0n1/boot/vmlinuz-lts '
-                           '-append \'usbcore.nousb ' + append + '\'')
+            self.log.debug("do_test_kvm: launching L2 in Radix mode (default)")
+
+        # Resolve the NVMe device path inside the L1 guest first so we do
+        # not hardcode a path that may differ by machine type.
+        nvme_dev = self._resolve_nvme_dev()
+
+        # Write the L2 launch command to a script to avoid terminal line-wrap
+        # breaking shell argument parsing, and to keep individual lines short.
+        # nvme_dev is the literal path, e.g. /dev/nvme0n1 — bake it in.
+        mnt = f'/media/$(basename {nvme_dev})'
+        ps1 = 'alpine:~#'
+        l2_script = [
+            ("cat > /tmp/run-l2.sh << 'EOF'", '>'),
+            ('#!/bin/sh', '>'),
+            ('qemu-system-ppc64 -nographic \\', '>'),
+            ('  -smp 2 -m 1g \\', '>'),
+            ('  -cpu POWER9 \\', '>'),
+            ('  -machine pseries,x-vof=on,accel=kvm \\', '>'),
+            ('  -machine cap-cfpc=broken,cap-sbbc=broken,cap-ibs=broken,cap-ccf-assist=off \\', '>'),
+            (f'  -drive file={nvme_dev},format=raw,readonly=on \\', '>'),
+            (f'  -initrd {mnt}/boot/initramfs-lts \\', '>'),
+            (f'  -kernel {mnt}/boot/vmlinuz-lts \\', '>'),
+            (f'  -append "usbcore.nousb {append}"', '>'),
+            ('EOF', ps1),
+            ('chmod +x /tmp/run-l2.sh', ps1),
+        ]
+        for cmd, expected_pattern in l2_script:
+            exec_command_and_wait_for_pattern(self, cmd, expected_pattern)
+        self.log.debug("do_test_kvm: L2 launch script written, executing")
+        exec_command(self, '/tmp/run-l2.sh')
+        self.log.debug("do_test_kvm: L2 QEMU launched, waiting for L2 login prompt")
         # Alpine 3.21 kernel seems to crash in XHCI USB driver.
         ps1 = 'localhost:~#'
         wait_for_console_pattern(self, 'localhost login:',
@@ -129,8 +196,10 @@ def do_test_kvm(self, hpt=False):
         self.log.debug("do_test_kvm: logged into L2, issuing poweroff")
         exec_command(self, 'poweroff')
         wait_for_console_pattern(self, 'reboot: Power down')
+        self.log.debug("do_test_kvm: L2 powered down, waiting for L1 prompt")
         # Now wait for the host's prompt to come back
         wait_for_console_pattern(self, 'alpine:~#')
+        self.log.debug("do_test_kvm: L1 prompt restored")
 
     def test_hv_pseries(self):
         self.require_accelerator("tcg")
-- 
2.52.0



  parent reply	other threads:[~2026-11-20  9:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  9:58 [PATCH 0/5] tests/functional/ppc64: Fixes and improvements for hypervisor tests Aniket Sahu
2026-11-20  9:58 ` [PATCH 1/5] tests/functional/ppc64: replace deprecated datetime.utcnow() Aniket Sahu
2026-11-20  9:58 ` [PATCH 2/5] tests/functional/ppc64: pin machine types for hypervisor tests Aniket Sahu
2026-11-20 10:06   ` Daniel P. Berrangé
2026-11-20 10:29     ` Aniket Sahu
2026-11-20  9:58 ` [PATCH 3/5] tests/functional/ppc64: add kernel params and early panic detection Aniket Sahu
2026-11-20  9:58 ` Aniket Sahu [this message]
2026-11-20  9:58 ` [PATCH 5/5] tests/functional/ppc64: increase timeout for hypervisor tests Aniket Sahu
2026-11-20 16:06 ` [PATCH 0/5] tests/functional/ppc64: Fixes and improvements " Alex Bennée

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=20261120095854.35941-11-asahu1x@linux.ibm.com \
    --to=asahu1x@linux.ibm.com \
    --cc=adityag@linux.ibm.com \
    --cc=amachhiw@linux.ibm.com \
    --cc=anushree.mathur@linux.ibm.com \
    --cc=farosas@suse.de \
    --cc=gautam@linux.ibm.com \
    --cc=harshpb@linux.ibm.com \
    --cc=milesg@linux.ibm.com \
    --cc=misanjum@linux.ibm.com \
    --cc=npiggin@gmail.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=rathc@linux.ibm.com \
    --cc=thuth@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.