source: trunk/packages/xen-3.1/xen-3.1/tools/xm-test/tests/memset/03_memset_random_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: 1.9 KB
Line 
1#!/usr/bin/python
2
3# Copyright (C) International Business Machines Corp., 2005
4# Author: Dan Smith <danms@us.ibm.com>
5
6import random
7import re
8
9from XmTestLib import *
10
11if ENABLE_HVM_SUPPORT:
12    SKIP("Mem-set not supported for HVM domains")
13
14domain = XmTestDomain()
15
16try:
17    console = domain.start()
18except DomainError, e:
19    if verbose:
20        print "Failed to start domain:"
21        print e.extra
22    FAIL(str(e))
23
24times = random.randint(10,50)
25
26try:
27    run = console.runCmd("cat /proc/xen/balloon | grep Current");
28except ConsoleError, e:
29    FAIL(str(e))
30
31match = re.match("[^0-9]+([0-9]+)", run["output"])
32if not match:
33    FAIL("Invalid domU meminfo line")
34       
35origmem = int(match.group(1)) / 1024
36currmem = origmem
37
38for i in range(0,times):
39    amt = random.randint(-10,10)
40
41    target = currmem + amt
42
43    # Make sure we're not going over or under
44    if target < domain.minSafeMem():
45        continue
46    if target > origmem:
47        continue
48
49    if verbose:
50        print "[%i/%i] Current: %i Target: %i" % (i, times, currmem, target)
51
52    cmd = "xm mem-set %s %i" % (domain.getName(), target)
53    status, output = traceCommand(cmd)
54
55    if status != 0:
56        if verbose:
57            print "mem-set failed:"
58            print output
59        FAIL("mem-set from %i to %i failed" % (currmem, target))
60
61    try:
62        run = console.runCmd("cat /proc/xen/balloon | grep Current");
63    except ConsoleError, e:
64        FAIL(str(e))
65
66    match = re.match("[^0-9]+([0-9]+)", run["output"])
67    if not match:
68        FAIL("Invalid domU meminfo line")
69       
70    domUmem = int(match.group(1)) / 1024
71
72    currmem = target
73    actual = int(getDomInfo(domain.getName(), "Mem"))
74
75    if actual != currmem:
76        FAIL("Expected %i MB, xm reported %i MB" % (currmem, actual))
77    if domUmem != currmem:
78        FAIL("Expected %i MB, domU reported %i MB" % (currmem, domUmem))
79       
80
Note: See TracBrowser for help on using the repository browser.