Re: [PATCH v2][TCK 2/2] Add test for memory set and get

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 08/01/2012 06:01 PM, Kyla Zhang wrote:
Add test for memory/maxmem set and get on domain running/shutdown
---
  scripts/domain/310-memory-set-get.t |   98 +++++++++++++++++++++++++++++++++++
  1 files changed, 98 insertions(+), 0 deletions(-)
  create mode 100644 scripts/domain/310-memory-set-get.t

diff --git a/scripts/domain/310-memory-set-get.t b/scripts/domain/310-memory-set-get.t
new file mode 100644
index 0000000..71886a6
--- /dev/null
+++ b/scripts/domain/310-memory-set-get.t
@@ -0,0 +1,98 @@
+# -*- perl -*-
+#
+# Copyright (C) 2012-2013 Red Hat, Inc.
+# Copyright (C) 2012-2013 Kyla Zhang <weizhan@xxxxxxxxxx>
+#
+# 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
+#
+
+=pod
+
+=head1 NAME
+
+domain/310-memory-set-get.t: test set and get memory/max memory

         Could we use small number rather than 310.

+
+=head1 DESCRIPTION
+
+The test case validates that the set memory, set max memory and get
+max memory works well for domain.

The testcase validates the basic function of domain memory balloon via
      setting its value of current memory, max memory.

+
+=cut
+
+use strict;
+use warnings;
+
+use Test::More tests => 15;
+
+use Sys::Virt::TCK;
+use Sys::Virt::TCK::NetworkHelpers;
+use Test::Exception;
+use File::Spec::Functions qw(catfile catdir rootdir);
+
+my $tck = Sys::Virt::TCK->new();
+my $conn = eval { $tck->setup(); };
+BAIL_OUT "failed to setup test harness: $@" if $@;
+END { $tck->cleanup if $tck; }
+
+diag "Define a new real domain, default memory is 1048576";

        my $current_mem = 1048576;
        my $max_mem = 1572864;
        my $config_mem = 924288;
        diag "Defing a guest with memory size $current_mem KiB";


+my $dom_name ="tck310memtest";

       $dom_name = "tckmemballoon"


+
+my $dom = prepare_test_disk_and_vm($tck, $conn, $dom_name);
+
+diag "Set max memory for domain";

        diag "Setting maximum memory for inactive domain"


+lives_ok(sub { $dom->set_max_memory("1572864") }, "Set max memory succeed");


lives_ok(sub { $dom->set_max_memory($max_mem) }, "Set max memory $max_mem");


+
+diag "Get max memory for domain when domain is inactive";

         diag "Get maximum memory from the inactive domain";


+is($dom->get_max_memory(), 1572864, "Get max memory is same as set value 1572864");

is($dom->get_max_memory(), $max_mem, "Got max memory $max_mem");


+
+diag "Start inactive domain";

        diag "Starting domain";


+$dom->create;
+ok($dom->get_id() > 0, "running domain has an ID > 0");
+sleep(30);
+
+diag "Set memory for current state";

       diag "Setting  memory with flag MEM_CONFIG";


+lives_ok(sub { $dom->set_memory("924288", Sys::Virt::Domain::MEM_CONFIG) }, "Set memory succeed in persistent config");

lives_ok(sub { $dom->set_memory($config_mem, Sys::Virt::Domain::MEM_CONFIG) }, "Set persistent memory value $config_mem");


+
+diag "get memory of running domain";

        diag "Get current memory";

+is($dom->get_info()->{memory}, 1048576, "Get current memory is 1048576");
+
+diag "Get max memory for domain when domain is active";
+is($dom->get_max_memory(), 1572864, "Get max memory is same as set value 1572864");
+
+diag "Set memory for current state";
+lives_ok(sub { $dom->set_memory("724288", Sys::Virt::Domain::MEM_CURRENT) }, "Set memory succeed in current state");
+sleep(3);
+
+diag "Check memory of running domain";
+is($dom->get_info()->{memory}, 724288, "Get current memory is same as set value 724288");
+
+diag "Set memory for live state";
+lives_ok(sub { $dom->set_memory("824288", Sys::Virt::Domain::MEM_LIVE) }, "Set memory succeed in live state");
+sleep(3);
+
+diag "Check memory of running domain";
+is($dom->get_info()->{memory}, 824288, "Get current memory is same as set value 824288");
+
+diag "Try setting max memory when domain is running";
+ok_error(sub { $dom->set_max_memory("1048576") }, "not allowed to set max memory when domain is running");
+
+diag "Destroying the transient domain";
+$dom->destroy;
+
+diag "Check memory of shutdown domain";
+is($dom->get_info()->{memory}, 924288, "Get memory is 624288 when domain is shutdown");
+
+diag "Set max memory with set_memory";
+lives_ok(sub { $dom->set_memory("1148576", Sys::Virt::Domain::MEM_MAXIMUM) }, "Set max memory succeed with set_memory");
+
+diag "Get max memory for domain";
+is($dom->get_info()->{maxMem}, 1148576, "Get max memory is same as set value 1148576");
+
+diag "Try setting live state memory when domain is shutdown";
+ok_error(sub { $dom->set_memory("824288", Sys::Virt::Domain::MEM_LIVE) }, "not allowed to set live state memory when domain is shutdown");


         Using variable make code maintain easier.
         Output more simple and concise log.

         Testing scenario is good. hope v3 version.

         Guannan Ren

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]