aboutsummaryrefslogtreecommitdiffstats
path: root/tools/xm-test/tests/vtpm/06_vtpm-susp_res_pcrs.py
blob: c70691d8e7565332404f6732e2409f2537984b7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/python

# Copyright (C) International Business Machines Corp., 2006
# Author: Stefan Berger <stefanb@us.ibm.com>

# Positive Test: create domain with virtual TPM attached at build time,
#                extend a pcr
#                check list of pcrs; suspend and resume the domain and
#                check list of pcrs again and validate extended pcr

from XmTestLib import *
from vtpm_utils import *
import commands
import os
import os.path
import atexit

config = {"vtpm":"instance=1,backend=0"}
domain = XmTestDomain(extraConfig=config)
domName = domain.getName()
consoleHistory = ""

try:
    console = domain.start()
except DomainError, e:
    if verbose:
        print e.extra
    FAIL("Unable to create domain (%s)" % domName)

atexit.register(vtpm_cleanup, vtpm_get_uuid(domid(domName)))

try:
    console.sendInput("input")
except ConsoleError, e:
    saveLog(console.getHistory())
    FAIL(str(e))

try:
    run = console.runCmd("mknod /dev/tpm0 c 10 224")
except ConsoleError, e:
    saveLog(console.getHistory())
    FAIL("Error while creating /dev/tpm0")

try:
    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")
except ConsoleError, e:
    saveLog(console.getHistory())
    FAIL("Error while extending PCR 0")

try:
    run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
except ConsoleError, e:
    saveLog(console.getHistory())
    FAIL("No result from dumping the PCRs")


if re.search("No such file",run["output"]):
    FAIL("TPM frontend support not compiled into (domU?) kernel")

if not re.search("PCR-00:",run["output"]):
    saveLog(console.getHistory())
    FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side: \n%s" % run["output"])

if not re.search("PCR-00: 1E A7 BD",run["output"]):
    saveLog(console.getHistory())
    FAIL("Extend did not lead to expected result (1E A7 BD ...): \n%s" % run["output"])

consoleHistory = console.getHistory()
domain.closeConsole()

loop = 0
while loop < 3:
    try:
        status, ouptut = traceCommand("xm save %s %s.save" %
                                      (domName, domName),
                                      timeout=30)

    except TimeoutError, e:
        saveLog(consoleHistory)
        FAIL(str(e))

    if status != 0:
        saveLog(consoleHistory)
        FAIL("xm save did not succeed")

    try:
        status, ouptut = traceCommand("xm restore %s.save" %
                                      (domName),
                                      timeout=30)
    except TimeoutError, e:
        os.remove("%s.save" % domName)
        saveLog(consoleHistory)
        FAIL(str(e))

    os.remove("%s.save" % domName)

    if status != 0:
        saveLog(consoleHistory)
        FAIL("xm restore did not succeed")

    try:
        console = domain.getConsole()
    except ConsoleError, e:
        FAIL(str(e))

    try:
        run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs")
    except ConsoleError, e:
        saveLog(console.getHistory())
        FAIL(str(e))

    if not re.search("PCR-00:",run["output"]):
        saveLog(console.getHistory())
        FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side")

    if not re.search("PCR-00: 1E A7 BD",run["output"]):
        saveLog(console.getHistory())
        FAIL("Virtual TPM lost PCR 0 value: \n%s" % run["output"])

    loop += 1

domain.closeConsole()

domain.stop()