ia64/xen-unstable

changeset 9351:e36f95b43bf1

Test suspend and resume cycles of the TPM front- and backend.
Now that sysfs is mounted in the RAM disk of the test environment, the
test code does not need to do this anymore. This patch also simplifies
previous tests and the APIs used there. If prerequisites are not met
(vtpm manager not running) the patch will 'skip'.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
author emellor@leeni.uk.xensource.com
date Tue Mar 21 01:28:29 2006 +0100 (2006-03-21)
parents b78cab886a1e
children 25e1c3b1a9f2
files tools/xm-test/tests/vtpm/01_vtpm-list_pos.py tools/xm-test/tests/vtpm/02_vtpm-cat_pcrs.py tools/xm-test/tests/vtpm/Makefile.am xen-unstable.hg/tools/xm-test/tests/vtpm/03_vtpm-susp_res.py
line diff
     1.1 --- a/tools/xm-test/tests/vtpm/01_vtpm-list_pos.py	Tue Mar 21 01:19:24 2006 +0100
     1.2 +++ b/tools/xm-test/tests/vtpm/01_vtpm-list_pos.py	Tue Mar 21 01:28:29 2006 +0100
     1.3 @@ -1,18 +1,20 @@
     1.4  #!/usr/bin/python
     1.5  
     1.6  # Copyright (C) International Business Machines Corp., 2006
     1.7 -# Author: Stefan Berger <stefanb@us.ibm.com)
     1.8 +# Author: Stefan Berger <stefanb@us.ibm.com>
     1.9  
    1.10  # Positive Test: create domain with virtual TPM attached at build time,
    1.11  #                verify list
    1.12  
    1.13  
    1.14  from XmTestLib import *
    1.15 +import commands
    1.16 +import os
    1.17  
    1.18  def vtpm_cleanup(domName):
    1.19 -	# Since this is only a temporary domain I clean up the domain from the
    1.20 -	# virtual TPM directory
    1.21 -	traceCommand("/etc/xen/scripts/vtpm-delete %s" % domName)
    1.22 +    # Since this is only a temporary domain I clean up the domain from the
    1.23 +    # virtual TPM directory
    1.24 +    os.system("/etc/xen/scripts/vtpm-delete %s" % domName)
    1.25  
    1.26  if ENABLE_HVM_SUPPORT:
    1.27      SKIP("vtpm-list not supported for HVM domains")
     2.1 --- a/tools/xm-test/tests/vtpm/02_vtpm-cat_pcrs.py	Tue Mar 21 01:19:24 2006 +0100
     2.2 +++ b/tools/xm-test/tests/vtpm/02_vtpm-cat_pcrs.py	Tue Mar 21 01:28:29 2006 +0100
     2.3 @@ -1,28 +1,30 @@
     2.4  #!/usr/bin/python
     2.5  
     2.6  # Copyright (C) International Business Machines Corp., 2006
     2.7 -# Author: Stefan Berger <stefanb@us.ibm.com)
     2.8 +# Author: Stefan Berger <stefanb@us.ibm.com>
     2.9  
    2.10  # Positive Test: create domain with virtual TPM attached at build time,
    2.11  #                check list of pcrs
    2.12  
    2.13  from XmTestLib import *
    2.14 +import commands
    2.15 +import os
    2.16 +import os.path
    2.17  
    2.18  def vtpm_cleanup(domName):
    2.19 -	# Since this is only a temporary domain I clean up the domain from the
    2.20 -	# virtual TPM directory
    2.21 -	traceCommand("/etc/xen/scripts/vtpm-delete %s" % domName)
    2.22 +    # Since this is only a temporary domain I clean up the domain from the
    2.23 +    # virtual TPM directory
    2.24 +    os.system("/etc/xen/scripts/vtpm-delete %s" % domName)
    2.25  
    2.26  if ENABLE_HVM_SUPPORT:
    2.27      SKIP("vtpm-list not supported for HVM domains")
    2.28  
    2.29 -status, output = traceCommand("ls /dev/tpm0")
    2.30 -if re.search("No such file or directory",output):
    2.31 +if os.path.exists("/dev/tpm0") == False:
    2.32      SKIP("This machine has no hardware TPM; cannot run this test")
    2.33  
    2.34 -status, output = traceCommand("ps aux | grep vtpm_manager | grep -v grep")
    2.35 +output = commands.getoutput("ps aux | grep vtpm_manager | grep -v grep")
    2.36  if output == "":
    2.37 -    FAIL("virtual TPM manager must be started to run this test")
    2.38 +    SKIP("virtual TPM manager must be started to run this test")
    2.39  
    2.40  # vtpm manager has been detected
    2.41  config = {"vtpm":"instance=1,backend=0"}
    2.42 @@ -46,21 +48,11 @@ except ConsoleError, e:
    2.43  
    2.44  try:
    2.45      console.sendInput("input")
    2.46 -    run = console.runCmd("ls /sys")
    2.47  except ConsoleError, e:
    2.48      saveLog(console.getHistory())
    2.49      vtpm_cleanup(domName)
    2.50      FAIL(str(e))
    2.51  
    2.52 -if re.search("No such file",run["output"]):
    2.53 -    try:
    2.54 -        run = console.runCmd("mkdir /sys")
    2.55 -        run = console.runCmd("mount -t sysfs /sys /sys")
    2.56 -    except ConsoleError, e:
    2.57 -        saveLog(console.getHistory())
    2.58 -        vtpm_cleanup(domName)
    2.59 -        FAIL(str(e))
    2.60 -
    2.61  try:
    2.62      run = console.runCmd("cat /sys/devices/platform/tpm_vtpm/pcrs")
    2.63  except ConsoleError, e:
     3.1 --- a/tools/xm-test/tests/vtpm/Makefile.am	Tue Mar 21 01:19:24 2006 +0100
     3.2 +++ b/tools/xm-test/tests/vtpm/Makefile.am	Tue Mar 21 01:28:29 2006 +0100
     3.3 @@ -2,7 +2,8 @@
     3.4  SUBDIRS =
     3.5  
     3.6  TESTS = 01_vtpm-list_pos.test \
     3.7 -        02_vtpm-cat_pcrs.test
     3.8 +        02_vtpm-cat_pcrs.test \
     3.9 +        03_vtpm-susp_res.test
    3.10  
    3.11  XFAIL_TESTS =
    3.12  
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/xen-unstable.hg/tools/xm-test/tests/vtpm/03_vtpm-susp_res.py	Tue Mar 21 01:28:29 2006 +0100
     4.3 @@ -0,0 +1,120 @@
     4.4 +#!/usr/bin/python
     4.5 +
     4.6 +# Copyright (C) International Business Machines Corp., 2006
     4.7 +# Author: Stefan Berger <stefanb@us.ibm.com>
     4.8 +
     4.9 +# Positive Test: create domain with virtual TPM attached at build time,
    4.10 +#                check list of pcrs; suspend and resume the domain and
    4.11 +#                check list of pcrs again
    4.12 +
    4.13 +from XmTestLib import *
    4.14 +import commands
    4.15 +import os
    4.16 +import os.path
    4.17 +
    4.18 +def vtpm_cleanup(domName):
    4.19 +    # Since this is only a temporary domain I clean up the domain from the
    4.20 +    # virtual TPM directory
    4.21 +    os.system("/etc/xen/scripts/vtpm-delete %s" % domName)
    4.22 +
    4.23 +if ENABLE_HVM_SUPPORT:
    4.24 +    SKIP("vtpm-list not supported for HVM domains")
    4.25 +
    4.26 +if os.path.exists("/dev/tpm0") == False:
    4.27 +    SKIP("This machine has no hardware TPM; cannot run this test")
    4.28 +
    4.29 +output = commands.getoutput("ps aux | grep vtpm_manager | grep -v grep")
    4.30 +if output == "":
    4.31 +    SKIP("virtual TPM manager must be started to run this test")
    4.32 +
    4.33 +# vtpm manager has been detected
    4.34 +config = {"vtpm":"instance=1,backend=0"}
    4.35 +domain = XmTestDomain(extraConfig=config)
    4.36 +
    4.37 +try:
    4.38 +    domain.start()
    4.39 +except DomainError, e:
    4.40 +    if verbose:
    4.41 +        print e.extra
    4.42 +    vtpm_cleanup(domain.getName())
    4.43 +    FAIL("Unable to create domain")
    4.44 +
    4.45 +domName = domain.getName()
    4.46 +
    4.47 +try:
    4.48 +    console = XmConsole(domain.getName())
    4.49 +except ConsoleError, e:
    4.50 +    vtpm_cleanup(domName)
    4.51 +    FAIL(str(e))
    4.52 +
    4.53 +try:
    4.54 +    console.sendInput("input")
    4.55 +except ConsoleError, e:
    4.56 +    saveLog(console.getHistory())
    4.57 +    vtpm_cleanup(domName)
    4.58 +    FAIL(str(e))
    4.59 +
    4.60 +try:
    4.61 +    run = console.runCmd("cat /sys/devices/platform/tpm_vtpm/pcrs")
    4.62 +except ConsoleError, e:
    4.63 +    saveLog(console.getHistory())
    4.64 +    vtpm_cleanup(domName)
    4.65 +    FAIL(str(e))
    4.66 +
    4.67 +if re.search("No such file",run["output"]):
    4.68 +    FAIL("TPM frontend support not compiled into (domU?) kernel")
    4.69 +
    4.70 +console.closeConsole()
    4.71 +
    4.72 +try:
    4.73 +    status, ouptut = traceCommand("xm save %s %s.save" %
    4.74 +                                  (domName, domName),
    4.75 +                                  timeout=30)
    4.76 +except TimeoutError, e:
    4.77 +    saveLog(console.getHistory())
    4.78 +    vtpm_cleanup(domName)
    4.79 +    FAIL(str(e))
    4.80 +
    4.81 +if status != 0:
    4.82 +    saveLog(console.getHistory())
    4.83 +    vtpm_cleanup(domName)
    4.84 +    FAIL("xm save did not succeed")
    4.85 +
    4.86 +try:
    4.87 +    status, ouptut = traceCommand("xm restore %s.save" %
    4.88 +                                  (domName),
    4.89 +                                  timeout=30)
    4.90 +except TimeoutError, e:
    4.91 +    os.remove("%s.save" % domName)
    4.92 +    saveLog(console.getHistory())
    4.93 +    vtpm_cleanup(domName)
    4.94 +    FAIL(str(e))
    4.95 +
    4.96 +os.remove("%s.save" % domName)
    4.97 +
    4.98 +if status != 0:
    4.99 +    saveLog(console.getHistory())
   4.100 +    vtpm_cleanup(domName)
   4.101 +    FAIL("xm restore did not succeed")
   4.102 +
   4.103 +try:
   4.104 +    console = XmConsole(domain.getName())
   4.105 +except ConsoleError, e:
   4.106 +    vtpm_cleanup(domName)
   4.107 +    FAIL(str(e))
   4.108 +
   4.109 +try:
   4.110 +    run = console.runCmd("cat /sys/devices/platform/tpm_vtpm/pcrs")
   4.111 +except ConsoleError, e:
   4.112 +    saveLog(console.getHistory())
   4.113 +    vtpm_cleanup(domName)
   4.114 +    FAIL(str(e))
   4.115 +
   4.116 +console.closeConsole()
   4.117 +
   4.118 +domain.stop()
   4.119 +
   4.120 +vtpm_cleanup(domName)
   4.121 +
   4.122 +if not re.search("PCR-00:",run["output"]):
   4.123 +	FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side")