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

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



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 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
+#
+
+=pod
+
+=head1 NAME
+
+domain/310-memory-set-get.t: test set and get memory/max memory
+
+=head1 DESCRIPTION
+
+The test case validates that the set memory, set max memory and get
+max memory works well for domain.
+
+=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 $dom_name ="tck310memtest";
+
+my $dom = prepare_test_disk_and_vm($tck, $conn, $dom_name);
+
+diag "Set max memory for domain";
+lives_ok(sub { $dom->set_max_memory("1572864") }, "Set max memory succeed");
+
+diag "Get max memory for domain when domain is inactive";
+is($dom->get_max_memory(), 1572864, "Get max memory is same as set value 1572864");
+
+diag "Start inactive domain";
+$dom->create;
+ok($dom->get_id() > 0, "running domain has an ID > 0");
+sleep(30);
+
+diag "Set memory for current state";
+lives_ok(sub { $dom->set_memory("924288", Sys::Virt::Domain::MEM_CONFIG) }, "Set memory succeed in persistent config");
+
+diag "get memory of running domain";
+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");
-- 
1.7.1


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