source: trunk/packages/xen-3.1/xen-3.1/tools/xm-test/tests/memset/01_memset_basic_pos.py @ 34

Last change on this file since 34 was 34, checked in by hartmans, 18 years ago

Add xen and xen-common

  • Property svn:mime-type set to text/script
File size: 2.4 KB
Line 
1#!/usr/bin/python
2
3# Copyright (C) International Business Machines Corp., 2005
4# Author: Woody Marvel <marvel@us.ibm.com>
5##
6## Description:
7## Tests that verify mem-set output and return code
8## 1) Test for xm mem-set
9##      create domain,
10##      verify domain and ls output,
11##      mem-set in dom0,
12##      verify with xm list memory change external,
13##      verify with xm list memory change internal,
14##
15## Author: Woody Marvel         marvel@us.ibm.com
16##
17
18import sys
19import re
20import time
21from XmTestLib import *
22
23if ENABLE_HVM_SUPPORT:
24    SKIP("Mem-set not supported for HVM domains")
25
26# Create a domain (default XmTestDomain, with our ramdisk)
27domain = XmTestDomain()
28
29# Start it
30try:
31    console = domain.start()
32except DomainError, e:
33    if verbose:
34        print "Failed to create test domain because:"
35        print e.extra
36    FAIL(str(e))
37
38try:
39    # Make sure it's up an running before we continue
40    console.runCmd("ls")
41except ConsoleError, e:
42    FAIL(str(e))
43   
44try:
45    run = console.runCmd("cat /proc/xen/balloon | grep Current");
46except ConsoleError, e:
47    FAIL(str(e))
48
49match = re.match("[^0-9]+([0-9]+)", run["output"])
50if not match:
51    FAIL("Invalid domU meminfo line")
52       
53origmem = int(match.group(1)) / 1024
54newmem = origmem - 1
55
56# set mem-set for less than default
57cmd = "xm mem-set %s %i" % (domain.getName(), newmem)
58status, output = traceCommand(cmd)
59if status != 0:
60    if verbose:
61        print "mem-set failed:"
62        print output
63    FAIL("cmd %s returned invalid %i != 0" % (cmd, status))
64
65for i in [1,2,3,4,5,6,7,8,9,10]:
66    mem = getDomMem(domain.getName())
67    if mem == newmem:
68        break
69    time.sleep(1)
70
71# verify memory set externally
72mem = getDomMem(domain.getName())
73if not mem:
74    FAIL("Failed to get memory amount for domain %s" % domain.getName())
75elif mem != newmem:
76    FAIL("Dom0 failed to verify %i MB; got %i MB" % newmem,mem)
77
78# verify memory set internally
79try:
80    run = console.runCmd("cat /proc/xen/balloon | grep Current")
81except ConsoleError, e:
82    FAIL(str(e))
83
84# Check the output of 'cat /proc/xen/balloon'
85m = re.match("^Current allocation:\s+(\d+)\skB", run["output"])
86if not m:
87    FAIL("The DomU command 'cat /proc/xen/balloon' failed.")
88
89domUmem = int(m.group(1)) / 1024
90
91if domUmem != newmem:
92    FAIL("DomU reported incorrect memory amount: %i MB" % (domUmem))
93
94# quiesce everything
95# Close the console
96domain.closeConsole()
97
98# Stop the domain (nice shutdown)
99domain.stop()
Note: See TracBrowser for help on using the repository browser.