| 1 | #!/usr/bin/python |
|---|
| 2 | |
|---|
| 3 | # Copyright (C) International Business Machines Corp., 2005 |
|---|
| 4 | # Author: Dan Smith <danms@us.ibm.com> |
|---|
| 5 | |
|---|
| 6 | import random |
|---|
| 7 | import re |
|---|
| 8 | |
|---|
| 9 | from XmTestLib import * |
|---|
| 10 | |
|---|
| 11 | if ENABLE_HVM_SUPPORT: |
|---|
| 12 | SKIP("Mem-set not supported for HVM domains") |
|---|
| 13 | |
|---|
| 14 | domain = XmTestDomain() |
|---|
| 15 | |
|---|
| 16 | try: |
|---|
| 17 | console = domain.start() |
|---|
| 18 | except DomainError, e: |
|---|
| 19 | if verbose: |
|---|
| 20 | print "Failed to start domain:" |
|---|
| 21 | print e.extra |
|---|
| 22 | FAIL(str(e)) |
|---|
| 23 | |
|---|
| 24 | times = random.randint(10,50) |
|---|
| 25 | |
|---|
| 26 | try: |
|---|
| 27 | run = console.runCmd("cat /proc/xen/balloon | grep Current"); |
|---|
| 28 | except ConsoleError, e: |
|---|
| 29 | FAIL(str(e)) |
|---|
| 30 | |
|---|
| 31 | match = re.match("[^0-9]+([0-9]+)", run["output"]) |
|---|
| 32 | if not match: |
|---|
| 33 | FAIL("Invalid domU meminfo line") |
|---|
| 34 | |
|---|
| 35 | origmem = int(match.group(1)) / 1024 |
|---|
| 36 | currmem = origmem |
|---|
| 37 | |
|---|
| 38 | for 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 | |
|---|