From nobody Thu Nov 14 18:04:18 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=1708331792; cv=none; d=zohomail.com; s=zohoarc; b=ZLWx/N1vneiqJxmnjJxwnPTs48QjHLDelxWsPFvxxRq6MRyUIni62j/gZu5BFlQzJZ/ubOnFiziahGgPs85ZOYk3Nq8ZjW4E6HzIusK5xLgVNoUR/G//mJ3dunGc6HlXEbcx7wgTYZjyIwKRlL1fKQc0Qmd2bng62+JHG5WMVcQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708331792; 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=KKOi2D3+rzG/W2PQht+fyug8zMVL/3xQ5VSl096jp0w=; b=Or8M5UaQ/b2PnELJNqy1GH4d3JN5vLjW7sCXw7ChIsN++uvi3Jl+6a72d4VDU7Xvumxq0X443LgQuMgaEly6R/JYjmx+XvS8dMn8WjEypDke7gSvj87q1wiIRRTvwuH7mbGQ8TdZuFuBlUtF2ZHUGLI71gnM3xx1hlqbfXBLhAQ= 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 1708331792368524.1212351969517; Mon, 19 Feb 2024 00:36:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rbz33-0000KF-KU; Mon, 19 Feb 2024 03:30:56 -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 1rbz2o-0000JA-Nn; Mon, 19 Feb 2024 03:30:35 -0500 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rbz2k-0002AK-BG; Mon, 19 Feb 2024 03:30:32 -0500 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1da0cd9c0e5so37027325ad.0; Mon, 19 Feb 2024 00:30:29 -0800 (PST) Received: from wheely.local0.net ([1.146.38.93]) by smtp.gmail.com with ESMTPSA id mo7-20020a1709030a8700b001db5ecd115bsm3838348plb.276.2024.02.19.00.30.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 00:30:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708331428; x=1708936228; 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=KKOi2D3+rzG/W2PQht+fyug8zMVL/3xQ5VSl096jp0w=; b=D3SWkDAU9wtMz0TXMQC+8cvnQLSZspuUed3ME8+TA0iL5yU/I1/CAui97fz6xqWGMY pt9BcbhSEhq5A56blMaU2tcEGTuP001Ar6V04zy5xJNf4Mg/hoo+8N/KFBi08lGm8kn0 +7i8LODM1hoFbgidYrwwmP/RMbLjiIzHsOXmvt8Fd7C5pFyDMJCDVv4x8rZDzYln8NG0 fxsyChEUPTwsHWXEH4XJWHHSUtz0zagZKuPWzC9u8mrW9IAJyiKhNAHlIlgKrTzpg+T0 zJLWH/0lczI7c6712xQnCVpZCKLZ2eN9ozDjSj9908sso5RT8vRwG50wnkQFvpE05aid rmqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708331428; x=1708936228; 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=KKOi2D3+rzG/W2PQht+fyug8zMVL/3xQ5VSl096jp0w=; b=VU88MCdup5E39GjZbOMZzEGXtEUN+/1njcIkkvHgfZOM4j2WkPvi83qBXRaIEiZPT/ rRTQRcOEeuOUrlkexHWHvV4wfBl77uwC2GYhhfF0LKHnhjAVvRjVdnqaCZcoPHZuRW4B zxKIgVR/8IO3+d0uXyYHdCjgMszZUFnk+Hwxpdda93bFaIEgxfep2yM4J6hd1z1dt0rt cB83jphxwfCZVOi9jlFBdmoSSqb2+S6v3mJLwSai4Nnp0c3lSGMe0PCRWOJ2bQnHdM89 VD2dgxX/GvCW53O6tRAbR0EZFN/LzgbiV/1vicnTnLV6V1cgeSSct+2J4Ql7fpSHL2hT HXtQ== X-Forwarded-Encrypted: i=1; AJvYcCXw7zNy8UiuSDC+CSEbQRis8RsFY1iMlZ5t/+0ZGdM/e/Sd2OjokUjkzHGZiry43eH3DUY7hadzxegXc8xk8asFZ3tX X-Gm-Message-State: AOJu0YwwcTt+cPjr2LCQn0wJ+I2m12grfMSNjUsRVimeLDiUYAEMJ617 QCu8fSoC2YbT0NjHlI0FjQjyoXn9ZK+X9xdBSGds7uzBY1xNzRSLxRrBnjwT X-Google-Smtp-Source: AGHT+IEdTFRsblYKyyBRlQ/aO6+dTGep3RdTWDz6cnoD+7stx3Ls8PgLjB7wdjxBRcpfwfW/6frvJg== X-Received: by 2002:a17:903:11c7:b0:1d9:5563:431 with SMTP id q7-20020a17090311c700b001d955630431mr20717040plh.7.1708331428355; Mon, 19 Feb 2024 00:30:28 -0800 (PST) From: Nicholas Piggin To: qemu-devel@nongnu.org Cc: Nicholas Piggin , qemu-ppc@nongnu.org, Daniel Henrique Barboza , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Harsh Prateek Bora Subject: [PULL 08/49] tests/avocado: ppc add hypervisor tests Date: Mon, 19 Feb 2024 18:28:57 +1000 Message-ID: <20240219082938.238302-9-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240219082938.238302-1-npiggin@gmail.com> References: <20240219082938.238302-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::62c; envelope-from=npiggin@gmail.com; helo=mail-pl1-x62c.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: 1708331794059100003 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 7d61fb9319..c0f42e8d4a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1525,6 +1525,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