1 | #!/usr/bin/python |
---|
2 | |
---|
3 | # Copyright (C) International Business Machines Corp., 2006 |
---|
4 | # Author: Harry Butterworth <butterwo@uk.ibm.com> |
---|
5 | |
---|
6 | # This test initialises a ram disk in dom0 with data from /dev/urandom and |
---|
7 | # then imports the ram disk device as a physical device into a domU. The md5 |
---|
8 | # checksum of the data in the ramdisk is calculated in dom0 and also |
---|
9 | # calculated by the domU reading the data through the blk frontend and |
---|
10 | # backend drivers. The test succeeds if the checksums match indicating that |
---|
11 | # the domU successfully read all the correct data from the device. |
---|
12 | |
---|
13 | import re |
---|
14 | |
---|
15 | from XmTestLib import * |
---|
16 | from XmTestLib.block_utils import * |
---|
17 | |
---|
18 | if ENABLE_HVM_SUPPORT: |
---|
19 | SKIP("Block-attach not supported for HVM domains") |
---|
20 | |
---|
21 | domain = XmTestDomain() |
---|
22 | |
---|
23 | try: |
---|
24 | console = domain.start() |
---|
25 | except DomainError, e: |
---|
26 | FAIL(str(e)) |
---|
27 | |
---|
28 | console.setHistorySaveCmds(value=True) |
---|
29 | |
---|
30 | traceCommand("cat /dev/urandom > /dev/ram1") |
---|
31 | |
---|
32 | s, o = traceCommand("md5sum /dev/ram1") |
---|
33 | |
---|
34 | dom0_md5sum_match = re.search(r"^[\dA-Fa-f]{32}", o, re.M) |
---|
35 | |
---|
36 | block_attach(domain, "phy:ram1", "xvda1") |
---|
37 | |
---|
38 | try: |
---|
39 | run = console.runCmd("md5sum /dev/xvda1") |
---|
40 | except ConsoleError, e: |
---|
41 | FAIL(str(e)) |
---|
42 | |
---|
43 | domU_md5sum_match = re.search(r"^[\dA-Fa-f]{32}", run["output"], re.M) |
---|
44 | |
---|
45 | domain.closeConsole() |
---|
46 | |
---|
47 | domain.stop() |
---|
48 | |
---|
49 | if dom0_md5sum_match == None: |
---|
50 | FAIL("Failed to get md5sum of test ram disk in dom0.") |
---|
51 | |
---|
52 | if domU_md5sum_match == None: |
---|
53 | FAIL("Failed to get md5sum of test ram disk in domU.") |
---|
54 | |
---|
55 | if verbose: |
---|
56 | print "md5sum dom0:" |
---|
57 | print dom0_md5sum_match.group() |
---|
58 | print "md5sum domU:" |
---|
59 | print domU_md5sum_match.group() |
---|
60 | |
---|
61 | if dom0_md5sum_match.group() != domU_md5sum_match.group(): |
---|
62 | FAIL("MISCOMPARE: data read in domU did not match data provided by domO.") |
---|