From nobody Fri May 3 16:32:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1576659141; cv=none; d=zohomail.com; s=zohoarc; b=WDa6wxNEY/COTxbAhPCk+0ZbjpmkiAExkewqPNTO861wX7uzReM+uGf5TxoWwEnIT70bi/+HHsHA9YQY/rR8ixLKC6s9zIZzZ5Qbz+R80c4enulcihARsXAq+L68GEglGjQsC0mS8QK/Z+JjghV04DGVBFyuP9G1kzIN8cZjwZ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576659141; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=TIuMwtg9TqHOdFFICeKVSKrMW9UyrzHl8A/We47FPrM=; b=N258qL5G2EYN5vAVhEXyXCiRlJyom7H7/okrhyg8gVJBtveG88f5tmx1Y8jRaVw1/YmJiKoDBa6B6qZJ7QJYUgbtMCrdnhMJITeLx8P5VB1D3myI9+7Wf4v/MIuA8W0rDg7QsuMPrryy/2egryQRe6iDccJqMiSg4t3kE6zUP9I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1576659141538855.8770492885467; Wed, 18 Dec 2019 00:52:21 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-59-1ddX9JmiO5mUbFc7txsDKw-1; Wed, 18 Dec 2019 03:52:17 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 58842DB21; Wed, 18 Dec 2019 08:52:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 315A87D8FA; Wed, 18 Dec 2019 08:52:12 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D40A8827CA; Wed, 18 Dec 2019 08:52:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xBI8q9jd027518 for ; Wed, 18 Dec 2019 03:52:09 -0500 Received: by smtp.corp.redhat.com (Postfix) id C24F57D8CA; Wed, 18 Dec 2019 08:52:09 +0000 (UTC) Received: from tcktest.nay.redhat.com (unknown [10.66.85.225]) by smtp.corp.redhat.com (Postfix) with ESMTP id B3E697C839; Wed, 18 Dec 2019 08:52:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576659140; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=TIuMwtg9TqHOdFFICeKVSKrMW9UyrzHl8A/We47FPrM=; b=XaPqzkPYsyPKkIr6c7YQtkojVzZDbCDyFo67MSulOUOg2rZp9w59aEzUPE9dR9JNBKaWXy Bl35ZxAHz8/9c22+Sqn6tNBXodPvODRQqbydgG7yNwttQJwEzFWB0lyxnChfIktzqf2TRi 69TWFaduXeyYP5q783Xr2admpcOEG00= From: dzheng@redhat.com To: libvir-list@redhat.com Date: Wed, 18 Dec 2019 16:52:03 +0800 Message-Id: <20191218085203.2914-1-dzheng@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Dan Zheng Subject: [libvirt] [libvirt-tck PATCH v2] Add cases for nvram X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: 1ddX9JmiO5mUbFc7txsDKw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Dan Zheng This is to add the tests for below flags: - Sys::Virt::Domain::UNDEFINE_KEEP_NVRAM - Sys::Virt::Domain::UNDEFINE_NVRAM v1: https://www.redhat.com/archives/libvir-list/2019-December/msg00932.html Signed-off-by: Dan Zheng Reviewed-by: Daniel P. Berrang=C3=A9 --- scripts/domain/401-ovmf-nvram.t | 144 ++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 scripts/domain/401-ovmf-nvram.t diff --git a/scripts/domain/401-ovmf-nvram.t b/scripts/domain/401-ovmf-nvra= m.t new file mode 100644 index 0000000..4af2117 --- /dev/null +++ b/scripts/domain/401-ovmf-nvram.t @@ -0,0 +1,144 @@ +# -*- perl -*- +# +# Copyright (C) 2009 Red Hat, Inc. +# Copyright (C) 2018 Dan Zheng (dzheng@redhat.com) +# +# This program is free software; You can redistribute it and/or modify +# it under the GNU General Public License as published by the Free +# Software Foundation; either version 2, or (at your option) any +# later version +# +# The file "LICENSE" distributed along with this file provides full +# details of the terms and conditions +# + +=3Dpod + +=3Dhead1 NAME + +domain/401-ovmf-nvram.t - Test OVMF related functions and flags + +=3Dhead1 DESCRIPTION + +The test cases validates OVMF related APIs and flags + +Sys::Virt::Domain::UNDEFINE_KEEP_NVRAM +Sys::Virt::Domain::UNDEFINE_NVRAM + +=3Dcut + +use strict; +use warnings; + +use Test::More tests =3D> 6; + +use Sys::Virt::TCK; +use File::stat; +use File::Copy; + + +my $tck =3D Sys::Virt::TCK->new(); +my $conn =3D eval { $tck->setup(); }; +BAIL_OUT "failed to setup test harness: $@" if $@; +END { $tck->cleanup if $tck; } + + +sub setup_nvram { + + my $loader_path =3D shift; + my $nvram_template =3D shift; + my $nvram_path =3D shift; + + # Check below two files should exist + # - /usr/share/OVMF/OVMF_CODE.secboot.fd + # - /usr/share/OVMF/OVMF_VARS.fd + if (!stat($loader_path) or !stat($nvram_template)) { + return undef; + } + + # Ensure the sample nvram file exists + copy($nvram_template, $nvram_path) or die "Copy failed: $!"; + + # Use 'q35' as machine type and add below lines to guest xml + # /usr/sha= re/OVMF/OVMF_CODE.secboot.fd + # /var/lib/libvir= t/qemu/nvram/test_VARS.fd + + my $xml =3D $tck->generic_domain(name =3D> "tck")->as_xml; + my $xp =3D XML::XPath->new($xml); + + if ($xp->getNodeText("/domain/os/type/\@machine") ne 'q35') { + diag "Changing guest machine type to q35"; + $xp->setNodeText("/domain/os/type/\@machine", "q35"); + } + + my $loader_node =3D XML::XPath::Node::Element->new('loader'); + my $loader_text =3D XML::XPath::Node::Text->new($loader_path); + my $attr_ro =3D XML::XPath::Node::Attribute->new('readonly'); + my $attr_secure =3D XML::XPath::Node::Attribute->new('secure'); + my $attr_type =3D XML::XPath::Node::Attribute->new('type'); + + $attr_ro -> setNodeValue('yes'); + $attr_secure -> setNodeValue('yes'); + $attr_type -> setNodeValue('pflash'); + + $loader_node->appendChild($loader_text); + $loader_node->appendAttribute($attr_ro); + $loader_node->appendAttribute($attr_secure); + $loader_node->appendAttribute($attr_type); + + my $nvram_node =3D XML::XPath::Node::Element->new('nvram'); + my $nvram_text =3D XML::XPath::Node::Text->new($nvram_path); + my $attr_template =3D XML::XPath::Node::Attribute->new('template'); + + $attr_template -> setNodeValue($nvram_template); + + $nvram_node->appendChild($nvram_text); + $nvram_node->appendAttribute($attr_template); + + my $smm_node =3D XML::XPath::Node::Element->new('smm'); + my $attr_state =3D XML::XPath::Node::Attribute->new('state'); + $attr_state -> setNodeValue("on"); + $smm_node -> appendAttribute($attr_state); + + my ($root) =3D $xp->findnodes('/domain/os'); + $root->appendChild($loader_node); + $root->appendChild($nvram_node); + ($root) =3D $xp->findnodes('/domain/features'); + $root->appendChild($smm_node); + + $xml =3D $xp->findnodes_as_string('/'); + diag $xml; + return $xml; +} + +diag "Defining an inactive domain config with nvram"; +my $loader_file_path =3D '/usr/share/OVMF/OVMF_CODE.secboot.fd'; +my $nvram_file_template =3D '/usr/share/OVMF/OVMF_VARS.fd'; +my $nvram_file_path =3D '/var/lib/libvirt/qemu/nvram/test_VARS.fd'; + +my $xml =3D setup_nvram($loader_file_path, $nvram_file_template, $nvram_fi= le_path); + +SKIP: { + diag "Require files ($loader_file_path, $nvram_file_template) for test= ing"; + skip "Please install OVMF and ensure necessary files exist", 5 if !def= ined($xml); + my $dom; + + diag "Test Sys::Virt::Domain::UNDEFINE_KEEP_NVRAM"; + ok_domain(sub { $dom =3D $conn->define_domain($xml) }, "defined domain= with nvram configure"); + diag "Checking nvram file already exists"; + my $st =3D stat($nvram_file_path); + ok($st, "File '$nvram_file_path' exists as expected"); + $dom->undefine(Sys::Virt::Domain::UNDEFINE_KEEP_NVRAM); + diag "Checking nvram file still exists"; + $st =3D stat($nvram_file_path); + ok($st, "File '$nvram_file_path' still exists as expected"); + + diag "Test Sys::Virt::Domain::UNDEFINE_NVRAM"; + ok_domain(sub { $dom =3D $conn->define_domain($xml) }, "defined domain= with nvram configure"); + $dom->undefine(Sys::Virt::Domain::UNDEFINE_NVRAM); + diag "Checking nvram file removed"; + $st =3D stat($nvram_file_path); + ok(!$st, "File '$nvram_file_path' is removed"); +} +ok_error(sub { $conn->get_domain_by_name("tck") }, "NO_DOMAIN error raised= from missing domain", + Sys::Virt::Error::ERR_NO_DOMAIN); --=20 2.18.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list