From nobody Thu Nov 14 06:26:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1705500866; cv=none; d=zohomail.com; s=zohoarc; b=bLIjNP7rDYEqXCFpXTIjlzRz18kduW1P+8UBosFjfO8AGyYTYR6QmRhiz+ywxESsSMn3WCxwMz9v6B4FkCxG3tYd0eT8EU51Fcvxhh6PPlAoG0BKrX9s4zz+pI1mSX9jnZSumVo6/VjieT0oEQFj0ASt/c4hd69AW+Oc2nKA+mM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705500866; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=xiHHuj4kwhZGtwrNQLZcjOwLh7+4izxlGNDa/VHvDps=; b=BwGZCkA4FagoQnrSDDYZlvb8gkOPzDzkuSQc1BUKqE8m9a6T1s5vlVWdGBf21KYk+D7sbtVZ/vmv729W3e3lxjvyN/FxeE19h8YvPGuztkzL38vFVsuPLiETNsPMw37O3B12toUnbOqDlESmazkPTDgk0iov5iRv3ILeQP9qIys= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1705500866088164.77105956548723; Wed, 17 Jan 2024 06:14:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQ6fS-00062P-3T; Wed, 17 Jan 2024 09:13:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rQ6fQ-0005zj-Lx; Wed, 17 Jan 2024 09:13:20 -0500 Received: from mail-ot1-x333.google.com ([2607:f8b0:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rQ6fO-0002pr-5t; Wed, 17 Jan 2024 09:13:20 -0500 Received: by mail-ot1-x333.google.com with SMTP id 46e09a7af769-6e0af93fdaaso3158663a34.3; Wed, 17 Jan 2024 06:13:17 -0800 (PST) Received: from wheely.local0.net (124-171-76-150.tpgi.com.au. [124.171.76.150]) by smtp.gmail.com with ESMTPSA id i136-20020a636d8e000000b005cebb10e28fsm11812428pgc.69.2024.01.17.06.13.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 06:13:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705500796; x=1706105596; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xiHHuj4kwhZGtwrNQLZcjOwLh7+4izxlGNDa/VHvDps=; b=Nv0GKHDYhY7+VDX/8tuXDdcc4CUCoGaomBwGnJOd5NhbpVf5cjIDt8CSjOweifPIKH waE21w5yYSfVtWpMSwRRxRnMmcDFY3D/Fcy3X2fW8+bG3Riln1c8aY5dv4ggdRFi3Jc/ 9VK9V+S7DKhDFbEv4wc8vP1VruXFDPhd3Gw2/GNCR+qQTwyq/9P+yva3zFkj7T5Ju2Qu f5BXErENZ7ukJXdjsJZSuORzju4l1MmFd0dq7SZ1RGdEsPJg6ap4YSTh3P3wjnqc66tV odfreWneK5KHEww8dUVj9hJtN7MFG/OG4Dje4mjujP9ofS8vr5i+s2lLnsggoPIBBiCt PXeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705500796; x=1706105596; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xiHHuj4kwhZGtwrNQLZcjOwLh7+4izxlGNDa/VHvDps=; b=Q83msGDKOBaRMVxpAUYHEQ6xmghvQQF1FoMfI6gfDua7BpAxcuaCqOeqHI1gUI4aAF VzVcQZwhDfKgb92BLpC8TTm54z0WCFrW2RDdTMz3L9xtmhS/gsKRXN3zsRZWj39aDx99 TYa2q95p0reLzuavySA1V7nB8zPaQkpifJ/xXuJawWcV4NoVyAqnCcLQczysBiswPAXk dRs2VyiKhUt5rBaikDn4h+am1CQFx3LB790P/dorJmNuDYcijsllFWsBfM6yHSBKa6rm DN+bq56qTt0brVcV8yoPNeH9ACKflLYtuDTSktSQD7+4BZwav6TKCLrGm3+v5UFK2ppE ynJw== X-Gm-Message-State: AOJu0YyirSjeZ0pcR/3ww+EmOi9q3+J1z0Wgdq2Zj1uExoWy2RLz4EPt WFQx8OGsy2tQ6KviBQaX4lDpykXPyyg= X-Google-Smtp-Source: AGHT+IEE/8piKxp7XdazCM8iXlNqAm9OAW+cWQfj3PdX8oqgIuDJh3mg3NxZ8qvMbTafyQ0vf68k9w== X-Received: by 2002:a05:6358:70d:b0:176:18ee:4e8b with SMTP id e13-20020a056358070d00b0017618ee4e8bmr219758rwj.8.1705500795904; Wed, 17 Jan 2024 06:13:15 -0800 (PST) From: Nicholas Piggin To: qemu-devel@nongnu.org Cc: Nicholas Piggin , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Daniel Henrique Barboza , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Harsh Prateek Bora , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Wainer dos Santos Moschetta , Beraldo Leal , Cleber Rosa , qemu-ppc@nongnu.org Subject: [PATCH v2 7/8] tests/avocado: ppc add hypervisor tests Date: Thu, 18 Jan 2024 00:12:22 +1000 Message-ID: <20240117141224.90462-8-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240117141224.90462-1-npiggin@gmail.com> References: <20240117141224.90462-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::333; envelope-from=npiggin@gmail.com; helo=mail-ot1-x333.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1705500867373100001 The powernv and pseries machines both provide hypervisor facilities that are supported by KVM. This is a large and complicated set of features that don't get much system-level testing in ppc tests. Add a new test case for these which runs QEMU KVM inside the target. This downloads an Alpine VM image, boots it and downloads and installs the qemu package, then boots a virtual machine under it, re-using the original Alpine VM image. Signed-off-by: Nicholas Piggin --- MAINTAINERS | 1 + tests/avocado/ppc_hv_tests.py | 203 ++++++++++++++++++++++++++++++++++ 2 files changed, 204 insertions(+) create mode 100644 tests/avocado/ppc_hv_tests.py diff --git a/MAINTAINERS b/MAINTAINERS index b406fb20c0..bf41ac61c8 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1523,6 +1523,7 @@ F: tests/qtest/libqos/*spapr* F: tests/qtest/rtas* F: tests/qtest/libqos/rtas* F: tests/avocado/ppc_pseries.py +F: tests/avocado/ppc_hv_tests.py =20 PowerNV (Non-Virtualized) M: C=C3=A9dric Le Goater diff --git a/tests/avocado/ppc_hv_tests.py b/tests/avocado/ppc_hv_tests.py new file mode 100644 index 0000000000..2f80d0d176 --- /dev/null +++ b/tests/avocado/ppc_hv_tests.py @@ -0,0 +1,203 @@ +# Tests that specifically try to exercise hypervisor features of the +# target machines. powernv supports the Power hypervisor ISA, and +# pseries supports the nested-HV hypervisor spec. +# +# Copyright (c) 2023 IBM Corporation +# +# This work is licensed under the terms of the GNU GPL, version 2 or +# later. See the COPYING file in the top-level directory. + +from avocado import skipIf, skipUnless +from avocado.utils import archive +from avocado_qemu import QemuSystemTest +from avocado_qemu import wait_for_console_pattern, exec_command +import os +import time +import subprocess + +deps =3D ["xorriso"] # dependent tools needed in the test setup/box. + +def which(tool): + """ looks up the full path for @tool, returns None if not found + or if @tool does not have executable permissions. + """ + paths=3Dos.getenv('PATH') + for p in paths.split(os.path.pathsep): + p =3D os.path.join(p, tool) + if os.path.exists(p) and os.access(p, os.X_OK): + return p + return None + +def missing_deps(): + """ returns True if any of the test dependent tools are absent. + """ + for dep in deps: + if which(dep) is None: + return True + return False + +# Alpine is a light weight distro that supports QEMU. These tests boot +# that on the machine then run a QEMU guest inside it in KVM mode, +# that runs the same Alpine distro image. +# QEMU packages are downloaded and installed on each test. That's not a +# large download, but it may be more polite to create qcow2 image with +# QEMU already installed and use that. +@skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited') +@skipUnless(os.getenv('SPEED') =3D=3D 'slow', 'runtime limited') +@skipIf(missing_deps(), 'dependencies (%s) not installed' % ','.join(deps)) +class HypervisorTest(QemuSystemTest): + + timeout =3D 1000 + KERNEL_COMMON_COMMAND_LINE =3D 'printk.time=3D0 console=3Dhvc0 ' + panic_message =3D 'Kernel panic - not syncing' + good_message =3D 'VFS: Cannot open root device' + + def extract_from_iso(self, iso, path): + """ + Extracts a file from an iso file into the test workdir + + :param iso: path to the iso file + :param path: path within the iso file of the file to be extracted + :returns: path of the extracted file + """ + filename =3D os.path.basename(path) + + cwd =3D os.getcwd() + os.chdir(self.workdir) + + with open(filename, "w") as outfile: + cmd =3D "xorriso -osirrox on -indev %s -cpx %s %s" % (iso, pat= h, filename) + subprocess.run(cmd.split(), + stdout=3Dsubprocess.DEVNULL, stderr=3Dsubproces= s.DEVNULL) + + os.chdir(cwd) + + # Return complete path to extracted file. Because callers to + # extract_from_iso() specify 'path' with a leading slash, it is + # necessary to use os.path.relpath() as otherwise os.path.join() + # interprets it as an absolute path and drops the self.workdir par= t. + return os.path.normpath(os.path.join(self.workdir, filename)) + + def setUp(self): + super().setUp() + + iso_url =3D ('https://dl-cdn.alpinelinux.org/alpine/v3.18/releases= /ppc64le/alpine-standard-3.18.4-ppc64le.iso') + + # Alpine use sha256 so I recalculated this myself + iso_sha256 =3D 'c26b8d3e17c2f3f0fed02b4b1296589c2390e6d5548610099a= f75300edd7b3ff' + iso_path =3D self.fetch_asset(iso_url, asset_hash=3Diso_sha256, + algorithm =3D "sha256") + + self.iso_path =3D iso_path + self.vmlinuz =3D self.extract_from_iso(iso_path, '/boot/vmlinuz-lt= s') + self.initramfs =3D self.extract_from_iso(iso_path, '/boot/initramf= s-lts') + + def do_start_alpine(self): + self.vm.set_console() + kernel_command_line =3D self.KERNEL_COMMON_COMMAND_LINE + self.vm.add_args("-kernel", self.vmlinuz) + self.vm.add_args("-initrd", self.initramfs) + self.vm.add_args("-smp", "4", "-m", "2g") + self.vm.add_args("-drive", f"file=3D{self.iso_path},format=3Draw,i= f=3Dnone,id=3Ddrive0") + + self.vm.launch() + wait_for_console_pattern(self, 'Welcome to Alpine Linux 3.18') + exec_command(self, 'root') + wait_for_console_pattern(self, 'localhost login:') + wait_for_console_pattern(self, 'You may change this message by edi= ting /etc/motd.') + exec_command(self, 'setup-alpine -qe') + wait_for_console_pattern(self, 'localhost:~#') + + def do_stop_alpine(self): + exec_command(self, 'poweroff') + wait_for_console_pattern(self, 'alpine:~#') + self.vm.wait() + + def do_setup_kvm(self): + exec_command(self, 'echo http://dl-cdn.alpinelinux.org/alpine/v3.1= 8/main > /etc/apk/repositories') + wait_for_console_pattern(self, 'alpine:~#') + exec_command(self, 'echo http://dl-cdn.alpinelinux.org/alpine/v3.1= 8/community >> /etc/apk/repositories') + wait_for_console_pattern(self, 'alpine:~#') + exec_command(self, 'apk update') + wait_for_console_pattern(self, 'alpine:~#') + exec_command(self, 'apk add qemu-system-ppc64') + wait_for_console_pattern(self, 'alpine:~#') + exec_command(self, 'modprobe kvm-hv') + wait_for_console_pattern(self, 'alpine:~#') + + # 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 + # iso without having a passthrough filesystem configured. + def do_test_kvm(self, hpt=3DFalse): + if hpt: + append =3D 'disable_radix' + else: + append =3D '' + exec_command(self, 'qemu-system-ppc64 -nographic -smp 2 -m 1g ' + '-machine pseries,x-vof=3Don,accel=3Dkvm ' + '-machine cap-cfpc=3Dbroken,cap-sbbc=3Dbroken,' + 'cap-ibs=3Dbroken,cap-ccf-assist=3Doff= ' + '-drive file=3D/dev/nvme0n1,format=3Draw,readon= ly=3Don ' + '-initrd /media/nvme0n1/boot/initramfs-lts ' + '-kernel /media/nvme0n1/boot/vmlinuz-lts ' + '-append \'usbcore.nousb ' + append + '\'') + # Alpine 3.18 kernel seems to crash in XHCI USB driver. + wait_for_console_pattern(self, 'Welcome to Alpine Linux 3.18') + exec_command(self, 'root') + wait_for_console_pattern(self, 'localhost login:') + wait_for_console_pattern(self, 'You may change this message by edi= ting /etc/motd.') + exec_command(self, 'poweroff >& /dev/null') + wait_for_console_pattern(self, 'localhost:~#') + wait_for_console_pattern(self, 'reboot: Power down') + time.sleep(1) + exec_command(self, '') # console has strange issue after qemu exit + exec_command(self, 'reset') + exec_command(self, 'echo VM finished') + wait_for_console_pattern(self, 'VM finished') + + def test_hv_pseries(self): + """ + :avocado: tags=3Darch:ppc64 + :avocado: tags=3Dmachine:pseries + :avocado: tags=3Daccel:tcg + """ + self.require_accelerator("tcg") + self.vm.add_args("-accel", "tcg,thread=3Dmulti") + self.vm.add_args('-device', 'nvme,serial=3D1234,drive=3Ddrive0') + self.vm.add_args("-machine", "x-vof=3Don,cap-nested-hv=3Don") + self.do_start_alpine() + self.do_setup_kvm() + self.do_test_kvm() + self.do_stop_alpine() + + def test_hv_pseries_kvm(self): + """ + :avocado: tags=3Darch:ppc64 + :avocado: tags=3Dmachine:pseries + :avocado: tags=3Daccel:kvm + """ + self.require_accelerator("kvm") + self.vm.add_args("-accel", "kvm") + self.vm.add_args('-device', 'nvme,serial=3D1234,drive=3Ddrive0') + self.vm.add_args("-machine", "x-vof=3Don,cap-nested-hv=3Don") + self.do_start_alpine() + self.do_setup_kvm() + self.do_test_kvm() + self.do_stop_alpine() + + def test_hv_powernv(self): + """ + :avocado: tags=3Darch:ppc64 + :avocado: tags=3Dmachine:powernv + :avocado: tags=3Daccel:tcg + """ + self.require_accelerator("tcg") + self.vm.add_args("-accel", "tcg,thread=3Dmulti") + self.vm.add_args('-device', 'nvme,bus=3Dpcie.2,addr=3D0x0,serial= =3D1234,drive=3Ddrive0', + '-device', 'e1000e,netdev=3Dnet0,mac=3DC0:FF:EE:0= 0:00:02,bus=3Dpcie.0,addr=3D0x0', + '-netdev', 'user,id=3Dnet0,hostfwd=3D::20022-:22,= hostname=3Dalpine') + self.do_start_alpine() + self.do_setup_kvm() + self.do_test_kvm() + self.do_test_kvm(True) + self.do_stop_alpine() --=20 2.42.0