| OLD | NEW |
| 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import logging, os, re, sys, shutil | 5 import logging, os, re, sys, shutil |
| 6 from autotest_lib.client.bin import test, utils | 6 from autotest_lib.client.bin import test, utils |
| 7 | 7 |
| 8 class hardware_TPMFirmware(test.test): | 8 class hardware_TPMFirmware(test.test): |
| 9 """ | 9 """ |
| 10 Test of TPM functionality needed in firmware (client side of the test). | 10 Test of TPM functionality needed in firmware (client side of the test). |
| 11 See also server/site_tests/hardware_TPMFirmwareServer. | 11 See also server/site_tests/hardware_TPMFirmwareServer. |
| 12 """ | 12 """ |
| 13 version = 1 | 13 version = 1 |
| 14 preserve_srcdir = True | 14 preserve_srcdir = True |
| 15 | 15 |
| 16 # Cross-compiles TLCL test suite and other needed code. | |
| 17 # TODO(semenzato): tpm_takeownership is currently available by making | |
| 18 # tpm-tools an RDEPEND in the autotest ebuild. See that file for a | |
| 19 # better way. | |
| 20 def setup(self): | 16 def setup(self): |
| 21 sysroot = os.environ['SYSROOT'] | |
| 22 bin_path = os.path.join(sysroot, 'usr/sbin/tpm_takeownership') | |
| 23 shutil.copy(bin_path, self.bindir) | |
| 24 utils.make('-C %s' % self.srcdir) | 17 utils.make('-C %s' % self.srcdir) |
| 25 | 18 |
| 26 | |
| 27 # Runs a command, logs the output, and returns the exit status. | 19 # Runs a command, logs the output, and returns the exit status. |
| 28 def tpm_run(self, cmd, ignore_status=False): | 20 def tpm_run(self, cmd, ignore_status=False): |
| 29 output = utils.run(cmd, ignore_status=ignore_status) | 21 output = utils.run(cmd, ignore_status=ignore_status) |
| 30 logging.info(output) | 22 logging.info(output) |
| 31 self.job.set_state("client_status", output.exit_status) | 23 self.job.set_state("client_status", output.exit_status) |
| 32 | 24 |
| 33 | 25 |
| 34 # Sets up the system (if it isn't already) to run the tpm binaries. This | |
| 35 # is mostly needed after a reboot. We don't rely on the system booting in | |
| 36 # any particular state. | |
| 37 def tpm_setup(self, with_tcsd=False): | |
| 38 utils.run('mknod /dev/tpm c 10 224', ignore_status=True) | |
| 39 utils.run('mknod /dev/tpm0 c 10 224', ignore_status=True) | |
| 40 utils.run('modprobe tpm_tis force=1 interrupts=0', ignore_status=True) | |
| 41 | |
| 42 if (with_tcsd): | |
| 43 utils.run('/usr/sbin/tcsd') | |
| 44 else: | |
| 45 # It will be a problem if upstart automatically restarts tcsd. | |
| 46 utils.run('pkill tcsd', ignore_status=True) | |
| 47 | |
| 48 | |
| 49 def run_once(self, subtest='None'): | 26 def run_once(self, subtest='None'): |
| 50 logging.info("Running TPM firmware client subtest %s", subtest) | 27 logging.info("Running TPM firmware client subtest %s", subtest) |
| 51 if (subtest == 'setup'): | 28 if (subtest == 'takeownership'): |
| 52 self.tpm_setup() | 29 output = utils.run("start tcsd", ignore_status=False) |
| 53 self.tpm_write_status(0) | 30 # When TCSD is running, the system might try to take ownership as |
| 54 elif (subtest == 'takeownership'): | 31 # well. We don't care. |
| 55 self.tpm_setup(with_tcsd=True) | 32 logging.info(output) |
| 56 own_cmd = os.path.join(self.bindir, "tpm_takeownership -y -z") | 33 own_cmd = "tpm_takeownership -y -z" |
| 57 self.tpm_run(own_cmd) | 34 self.tpm_run(own_cmd, ignore_status=True) |
| 58 » else: | 35 else: |
| 59 self.tpm_setup() | |
| 60 cmd = os.path.join(self.srcdir, subtest) | 36 cmd = os.path.join(self.srcdir, subtest) |
| 61 self.tpm_run(cmd, ignore_status=True) | 37 self.tpm_run(cmd, ignore_status=True) |
| OLD | NEW |