source: trunk/packages/xen-3.1/xen-3.1/tools/xm-test/tests/vtpm/06_vtpm-susp_res_pcrs.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: 3.8 KB
Line 
1#!/usr/bin/python
2
3# Copyright (C) International Business Machines Corp., 2006
4# Author: Stefan Berger <stefanb@us.ibm.com>
5
6# Positive Test: create domain with virtual TPM attached at build time,
7#                extend a pcr
8#                check list of pcrs; suspend and resume the domain and
9#                check list of pcrs again and validate extended pcr
10
11from XmTestLib import *
12from vtpm_utils import *
13import commands
14import os
15import os.path
16
17config = {"vtpm":"instance=1,backend=0"}
18domain = XmTestDomain(extraConfig=config)
19domName = domain.getName()
20consoleHistory = ""
21
22try:
23    console = domain.start()
24except DomainError, e:
25    if verbose:
26        print e.extra
27    vtpm_cleanup(domName)
28    FAIL("Unable to create domain (%s)" % domName)
29
30try:
31    console.sendInput("input")
32except ConsoleError, e:
33    saveLog(console.getHistory())
34    vtpm_cleanup(domName)
35    FAIL(str(e))
36
37try:
38    run = console.runCmd("mknod /dev/tpm0 c 10 224")
39except ConsoleError, e:
40    saveLog(console.getHistory())
41    vtpm_cleanup(domName)
42    FAIL("Error while creating /dev/tpm0")
43
44try:
45    run = console.runCmd("echo -ne \"\\x00\\xc1\\x00\\x00\\x00\\x22\\x00\\x00\\x00\\x14\\x00\\x00\\x00\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\x09\\x0a\\x0b\\x0c\\x0d\\x0e\\0xf\\x10\\x11\\x12\\x13\\x14\" > seq; cat seq > /dev/tpm0")
46except ConsoleError, e:
47    saveLog(console.getHistory())
48    vtpm_cleanup(domName)
49    FAIL("Error while extending PCR 0")
50
51try:
52    run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
53except ConsoleError, e:
54    saveLog(console.getHistory())
55    vtpm_cleanup(domName)
56    FAIL("No result from dumping the PCRs")
57
58
59if re.search("No such file",run["output"]):
60    vtpm_cleanup(domName)
61    FAIL("TPM frontend support not compiled into (domU?) kernel")
62
63if not re.search("PCR-00:",run["output"]):
64    saveLog(console.getHistory())
65    vtpm_cleanup(domName)
66    FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side: \n%s" % run["output"])
67
68if not re.search("PCR-00: 1E A7 BD",run["output"]):
69    saveLog(console.getHistory())
70    FAIL("Extend did not lead to expected result (1E A7 BD ...): \n%s" % run["output"])
71
72consoleHistory = console.getHistory()
73domain.closeConsole()
74
75loop = 0
76while loop < 3:
77    try:
78        status, ouptut = traceCommand("xm save %s %s.save" %
79                                      (domName, domName),
80                                      timeout=30)
81
82    except TimeoutError, e:
83        saveLog(consoleHistory)
84        vtpm_cleanup(domName)
85        FAIL(str(e))
86
87    if status != 0:
88        saveLog(consoleHistory)
89        vtpm_cleanup(domName)
90        FAIL("xm save did not succeed")
91
92    try:
93        status, ouptut = traceCommand("xm restore %s.save" %
94                                      (domName),
95                                      timeout=30)
96    except TimeoutError, e:
97        os.remove("%s.save" % domName)
98        saveLog(consoleHistory)
99        vtpm_cleanup(domName)
100        FAIL(str(e))
101
102    os.remove("%s.save" % domName)
103
104    if status != 0:
105        saveLog(consoleHistory)
106        vtpm_cleanup(domName)
107        FAIL("xm restore did not succeed")
108
109    try:
110        console = domain.getConsole()
111    except ConsoleError, e:
112        vtpm_cleanup(domName)
113        FAIL(str(e))
114
115    try:
116        run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
117    except ConsoleError, e:
118        saveLog(console.getHistory())
119        vtpm_cleanup(domName)
120        FAIL(str(e))
121
122    if not re.search("PCR-00:",run["output"]):
123        saveLog(console.getHistory())
124        vtpm_cleanup(domName)
125        FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side")
126
127    if not re.search("PCR-00: 1E A7 BD",run["output"]):
128        saveLog(console.getHistory())
129        vtpm_cleanup(domName)
130        FAIL("Virtual TPM lost PCR 0 value: \n%s" % run["output"])
131
132    loop += 1
133
134domain.closeConsole()
135
136domain.stop()
137
138vtpm_cleanup(domName)
139
Note: See TracBrowser for help on using the repository browser.