From nobody Tue Nov 26 09:29:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.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 205.139.110.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=1576227643; cv=none; d=zohomail.com; s=zohoarc; b=hgN7n6kXsgosh3wTZYBkEv7WscJloPpWXj10WuTHjn337eYENwSQk5NOIcsVmnZ8P4/oOlPb97vUT/trzmOLY6gZYgirgWlRVNyNEqqj7qFHpl+2fWaGDaVlfxW1/h64cXDe9HbmKpwjoF0nkGbaozBTdOiH2iiIOToITYJBiR0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576227643; 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=ILTP8wG8h9WcU6jg6JL8zfdus4CVYcGfpwcr+LrTCZTxe3PicBPUAqVMuTiQUmCVuxd/pjnsarvs5FvXu++bGwS4f88wyKfWmrgqV9YFImyRNI/Wh2aYY6sxbL3OiJHvBStjisYWyu4/6rPFrcZUESepKBc9g2w1i0fhrlJ5E8c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.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 [205.139.110.120]) by mx.zohomail.com with SMTPS id 1576227643694671.4055511604715; Fri, 13 Dec 2019 01:00:43 -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-42-X8Bnd8QOM5W19FjB8ZYerA-1; Fri, 13 Dec 2019 04:00:40 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2C576593A1; Fri, 13 Dec 2019 09:00:34 +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 7232A5D9C9; Fri, 13 Dec 2019 09:00:33 +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 D0B6218095FF; Fri, 13 Dec 2019 09:00:30 +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 xBD8xsjI014456 for ; Fri, 13 Dec 2019 03:59:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id C96C146E9B; Fri, 13 Dec 2019 08:59:54 +0000 (UTC) Received: from tcktest.nay.redhat.com (unknown [10.66.85.225]) by smtp.corp.redhat.com (Postfix) with ESMTP id C642446E9F; Fri, 13 Dec 2019 08:59:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576227642; 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=ejjEe2x01r/r9oOHwF30fI3fbv/UK83h2vUxcYgAHWwDlpor8mUAJsV0euoKUkyZG3SbGB FhDBsmJ9GP78xbexEQhb96htZhG6LJaSkQrky73UbK5nwc2NrjsShj36gNYJpyXL3wPHab JRW3dT3n/hv1En4g/4pB9/ci/X47pmo= From: Dan Zheng To: libvir-list@redhat.com Date: Fri, 13 Dec 2019 16:59:24 +0800 Message-Id: <20191213085923.31112-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.14 X-MC-Unique: X8Bnd8QOM5W19FjB8ZYerA-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