From nobody Fri May 3 06:03:51 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=1576146471; cv=none; d=zohomail.com; s=zohoarc; b=ECSOZTuGiXaI6EJp43Sroe2gGibm9WBpHM5CjZwKge1w/AOv9A2OXLn9sZ2UzEK6g6mCBdyRbGulb5p0DVa/1xItllx9sfSw9XEn6GBNdggMpefsn1uTsPlcr0XUH/EAqqRNXezxKW5zyVcYWQdvToTpSVGGTnYvT3GM14NoxB8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576146471; 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=7Sjcv2uj2QVKlOlLst0/dZ2g6ahuJJN029DIuHm+Rxc=; b=gki37ugH1edLLsNudVjJ6tU8wyvuc7lZTP0qdy2AUoIP95gJpDy3WQXgSp3QC0r8Lll2cVUkVYd+4Y5DM89PTRCabJS07QrYfqVz22byO749GwClfAN5h7APJphBhn+5yHWlTqG7rC3BQONjXy+7re3FH/mevO+sf1H26M7pxWM= 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 1576146471169572.470053064185; Thu, 12 Dec 2019 02:27:51 -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-391-fw3IsZVuPTmLJcvmuaJK_w-1; Thu, 12 Dec 2019 05:27:48 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DB412157296A; Thu, 12 Dec 2019 10:27:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B494363BCD; Thu, 12 Dec 2019 10:27:42 +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 6032D18089CD; Thu, 12 Dec 2019 10:27:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xBCARf4A030109 for ; Thu, 12 Dec 2019 05:27:41 -0500 Received: by smtp.corp.redhat.com (Postfix) id 002D318779; Thu, 12 Dec 2019 10:27:41 +0000 (UTC) Received: from tcktest.nay.redhat.com (unknown [10.66.85.225]) by smtp.corp.redhat.com (Postfix) with ESMTP id F2737669E5; Thu, 12 Dec 2019 10:27:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576146469; 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=7Sjcv2uj2QVKlOlLst0/dZ2g6ahuJJN029DIuHm+Rxc=; b=GoiSRdiaw3kVrU2Bm4tPC1atQyxJC1jWUF5TEKmxSx28uOxidrH9JCjRA6eebAT7VS+93g +vgoEWI1+re0RbVNj45pa18mPHE1SHzGiNZxsQsEXrEGhewjyumX1rZmtRv3EN3cc2KghC t9Pui8HbV0tggf8UYAN110jIa/alSjI= From: Dan Zheng To: libvir-list@redhat.com Date: Thu, 12 Dec 2019 18:27:33 +0800 Message-Id: <20191212102733.18739-1-dzheng@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Dan Zheng Subject: [libvirt] [libvirt-tck PATCH] 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.15 X-MC-Unique: fw3IsZVuPTmLJcvmuaJK_w-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" This is to add the tests for below flags: - Sys::Virt::Domain::UNDEFINE_KEEP_NVRAM - Sys::Virt::Domain::UNDEFINE_NVRAM Signed-off-by: Dan Zheng --- scripts/domain/401-ovmf-nvram.t | 143 ++++++++++++++++++++++++++++++++ 1 file changed, 143 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..5310dd0 --- /dev/null +++ b/scripts/domain/401-ovmf-nvram.t @@ -0,0 +1,143 @@ +# -*- 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> 8; + +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; + +# Install OVMF and check the two files should exist +# - /usr/share/OVMF/OVMF_CODE.secboot.fd +# - /usr/share/OVMF/OVMF_VARS.fd + +my $ret =3D `yum install -y OVMF`; +diag "yum install OVMF: $ret"; +my $st =3D stat($loader_path); +ok($st, "path $loader_path exists after OVMF is installed"); +$st =3D stat($nvram_template); +ok($st, "path $nvram_template exists after OVMF is installed"); + +# 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/share/O= VMF/OVMF_CODE.secboot.fd +# /var/lib/libvirt/qe= mu/nvram/test_VARS.fd + +my $xml =3D $tck->generic_domain(name =3D> "tck")->as_xml; +my $xp =3D XML::XPath->new($xml); +diag $xp->getNodeText("/domain/os/type/\@machine"); + +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); +my $dom; + +diag "Test Sys::Virt::Domain::UNDEFINE_KEEP_NVRAM"; +ok_domain(sub { $dom =3D $conn->define_domain($xml) }, "defined domain wit= h 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 wit= h 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