Test for tpm driver suspend resume cycle
PATCH 1/1 Test for tpm driver suspend resume cycle
The attached patch adds a test for the suspend/resume cycle of the TPM front- and backend driver pair to the testsuite.
xen-unstable.hg/tools/xm-test/tests/vtpm/03_vtpm-susp_res.py new file +131 -0
@@ -0,0 +1,131 @@ +#!/usr/bin/python + +# Copyright (C) International Business Machines Corp., 2006 +# Author: Stefan Berger <[email protected]) + +# Positive Test: create domain with virtual TPM attached at build time, +# check list of pcrs + +from XmTestLib import * +import commands + +def vtpm_cleanup(domName): + # Since this is only a temporary domain I clean up the domain from the + # virtual TPM directory + traceCommand("/etc/xen/scripts/vtpm-delete %s" % domName) + +if ENABLE_HVM_SUPPORT: + SKIP("vtpm-list not supported for HVM domains") + +status, output = traceCommand("ls /dev/tpm0") +if re.search("No such file or directory",output): + SKIP("This machine has no hardware TPM; cannot run this test") + +status, output = traceCommand("ps aux | grep vtpm_manager | grep -v grep") +if output == "": + FAIL("virtual TPM manager must be started to run this test") + +# vtpm manager has been detected +config = {"vtpm":"instance=1,backend=0"} +domain = XmTestDomain(extraConfig=config) + +try: + domain.start() +except DomainError, e: + if verbose: + print e.extra + vtpm_cleanup(domain.getName()) + FAIL("Unable to create domain") + +domName = domain.getName() + +try: + console = XmConsole(domain.getName()) +except ConsoleError, e: + vtpm_cleanup(domName) + FAIL(str(e)) + +try: + console.sendInput("input") + run = console.runCmd("ls /sys") +except ConsoleError, e: + saveLog(console.getHistory()) + vtpm_cleanup(domName) + FAIL(str(e)) + +if re.search("No such file",run["output"]): + try: + run = console.runCmd("mkdir /sys") + run = console.runCmd("mount -t sysfs /sys /sys") + except ConsoleError, e: + saveLog(console.getHistory()) + vtpm_cleanup(domName) + FAIL(str(e)) + +try: + run = console.runCmd("cat /sys/devices/platform/tpm_vtpm/pcrs") +except ConsoleError, e: + saveLog(console.getHistory()) + vtpm_cleanup(domName) + FAIL(str(e)) + +if re.search("No such file",run["output"]): + FAIL("TPM frontend support not compiled into (domU?) kernel") + +console.closeConsole() + + +try: + status, ouptut = traceCommand("xm save %s %s.save" % + (domName, domName), + timeout=30) +except TimeoutError, e: + saveLog(console.getHistory()) + vtpm_cleanup(domName) + FAIL(str(e)) + +if status != 0: + saveLog(console.getHistory()) + vtpm_cleanup(domName) + FAIL("xm save did not succeed") + +try: + status, ouptut = traceCommand("xm restore %s.save" % + (domName), + timeout=30) +except TimeoutError, e: + commands.getoutput("rm -rf %s.save" % domName) + saveLog(console.getHistory()) + vtpm_cleanup(domName) + FAIL(str(e)) + +commands.getoutput("rm -rf %s.save" % domName) + +if status != 0: + saveLog(console.getHistory()) + vtpm_cleanup(domName) + FAIL("xm save did not succeed") + +try: + console = XmConsole(domain.getName()) +except ConsoleError, e: + vtpm_cleanup(domName) + FAIL(str(e)) + +try: + run = console.runCmd("cat /sys/devices/platform/tpm_vtpm/pcrs") +except ConsoleError, e: + saveLog(console.getHistory()) + vtpm_cleanup(domName) + FAIL(str(e)) + +console.closeConsole() + + + +domain.stop() + +vtpm_cleanup(domName) + +if not re.search("PCR-00:",run["output"]): + FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side")
xen-unstable.hg/tools/xm-test/tests/vtpm/Makefile.am +2 -1
@@ -2,7 +2,8 @@ SUBDIRS = TESTS = 01_vtpm-list_pos.test \ - 02_vtpm-cat_pcrs.test + 02_vtpm-cat_pcrs.test \ + 03_vtpm-susp_res.test XFAIL_TESTS =
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
SB> status, output = traceCommand("ls /dev/tpm0") SB> if re.search("No such file or directory",output):
SB> SKIP("This machine has no hardware TPM; cannot run this test")
Why all that when you can just do:
os.path.isfile("/dev/tmp0")
??
SB> try:
SB> console.sendInput("input")
SB> run = console.runCmd("ls /sys")
SB> except ConsoleError, e:
SB> saveLog(console.getHistory()) SB> vtpm_cleanup(domName) SB> FAIL(str(e))
SB>
SB> if re.search("No such file",run["output"]):
SB> try:
SB> run = console.runCmd("mkdir /sys")
SB> run = console.runCmd("mount -t sysfs /sys /sys")
SB> except ConsoleError, e:
SB> saveLog(console.getHistory()) SB> vtpm_cleanup(domName) SB> FAIL(str(e))
SB>
IIRC, /sys will never be mounted inside the ramdisk by default. So the initial check is pointless. Further, I think it would be better to put /sys in the fstab of the ramdisk instead of having every test mount it manually. This makes the tests longer and is something that probably needs to be on by default. I can cook up a quick patch if nobody else volunteers to do it ;)
Thanks Stefan!
Signature · 4 lines
Dan Smith IBM Linux Technology Center Open Hypervisor Team email: [email protected]
[email protected] wrote on 03/10/2006 10:13:44 AM:
Quoted 9 lines
SB> status, output =
traceCommand("ls /dev/tpm0")SB> ifre.search("No such file or directory",output):
SB>SKIP("This machine has no hardware TPM; cannot run this test")Why all that when you can just do:
os.path.isfile("/dev/tmp0")??
I will fix it.
Quoted 17 lines
SB> try:
SB>console.sendInput("input")
SB> run =console.runCmd("ls /sys")
SB> except ConsoleError, e:SB> saveLog(console.getHistory()) SB> vtpm_cleanup(domName) SB> FAIL(str(e))SB>
SB> ifre.search("No such file",run["output"]):
SB> try:
SB> run =console.runCmd("mkdir /sys")
SB> run =console.runCmd("mount -t sysfs /sys /sys")
SB> except ConsoleError, e:SB> saveLog(console.getHistory()) SB> vtpm_cleanup(domName) SB> FAIL(str(e))
Quoted 8 lines
SB>
IIRC, /sys will never be mounted inside the ramdisk by default. So the initial check is pointless. Further, I think it would be better to put /sys in the fstab of the ramdisk instead of having every test mount it manually. This makes the tests longer and is something that probably needs to be on by default. I can cook up a quick patch if nobody else volunteers to do it ;)
I will remove the check for '/sys', but would prefer if you provided the patch for the fstab. Are you going to provide a '/sys' mountpoint in the ramdisk as well or should I just keep the 'mkdir /sys'?
Quoted 2 lines
Thanks Stefan!
Welcome :-)
Stefan
Quoted 12 lines
Signature · 11 lines
-- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: [email protected] _______________________________________________ Xen-devel mailing list [email protected] http://lists.xensource.com/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
SB> I will remove the check for '/sys', but would prefer if you SB> provided the patch for the fstab. Are you going to provide a SB> '/sys' mountpoint in the ramdisk as well or should I just keep the SB> 'mkdir /sys'?
Yea, since /sys will be mounted at boot, the mount point will need to be there ahead of time. Once it's integrated, I think it's a safe for tests to assume it's there, just like they assume /proc is there.
Signature · 4 lines
Dan Smith IBM Linux Technology Center Open Hypervisor Team email: [email protected]