| 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 os, re | 5 import logging, os, re |
| 6 from autotest_lib.client.bin import test, utils | 6 from autotest_lib.client.bin import test, utils |
| 7 from autotest_lib.client.common_lib import error | 7 from autotest_lib.client.common_lib import error |
| 8 | 8 |
| 9 def old_or_missing_firmware_version(): |
| 10 f = open("/sys/devices/platform/chromeos_acpi/FWID") |
| 11 if not f: |
| 12 return True |
| 13 version = f.readline().strip() |
| 14 logging.info("firmware version: %s", version) |
| 15 # Expect a dot-separated list of 6 elements. Discard 1st element. |
| 16 v = re.split("\.", version)[1:] |
| 17 w = re.split("\.", "any-nickname.03.60.1118.0036.")[1:] |
| 18 if len(v) != len(w): |
| 19 raise error.TestError("malformed firmware version %s" % version) |
| 20 return v < w |
| 21 |
| 9 def dict_from_command(command): | 22 def dict_from_command(command): |
| 10 dict = {} | 23 dict = {} |
| 11 out = os.popen(command) | 24 out = os.popen(command) |
| 12 for linecr in out.readlines(): | 25 for linecr in out.readlines(): |
| 13 line = linecr.strip() | 26 line = linecr.strip() |
| 14 match = re.match("([^ ]+) (.*)", line) | 27 match = re.match("([^ ]+) (.*)", line) |
| 15 k = match.group(1) | 28 k = match.group(1) |
| 16 v = match.group(2) | 29 v = match.group(2) |
| 17 dict[k] = v | 30 dict[k] = v |
| 18 return dict | 31 return dict |
| 19 | 32 |
| 20 def expect(d, key, value): | 33 def expect(d, key, value): |
| 21 if (d[key] != value): | 34 if (d[key] != value): |
| 22 utils.system("start tcsd", ignore_status=True) | 35 raise error.TestError("expecting %s = %s, observing %s = %s" % |
| 23 raise error.TestError("expecting %s = %s, receiving %s = %s" % | |
| 24 (key, value, key, d[key])) | 36 (key, value, key, d[key])) |
| 25 | 37 |
| 38 def checkp(space, permission): |
| 39 c = "tpmc getp %s" % space |
| 40 l = os.popen(c).readline() |
| 41 if (not re.match(".*%s" % permission, l)): |
| 42 raise error.TestError("invalid response to %s: %s" % (c, l)) |
| 43 |
| 26 class hardware_TPMCheck(test.test): | 44 class hardware_TPMCheck(test.test): |
| 27 version = 1 | 45 version = 1 |
| 28 | 46 |
| 29 def run_once(self): | 47 def run_once(self): |
| 30 utils.system("stop tcsd", ignore_status=True) | |
| 31 | 48 |
| 32 d = dict_from_command("tpmc getvf"); | 49 if old_or_missing_firmware_version(): |
| 33 expect(d, "deactivated", "0") | 50 logging.warning("skipping test because firmware " + |
| 34 expect(d, "physicalPresence", "0") | 51 "version missing or deemed too old") |
| 35 expect(d, "physicalPresenceLock", "1") | 52 return |
| 36 expect(d, "bGlobalLock", "1") | |
| 37 | 53 |
| 38 d = dict_from_command("tpmc getpf"); | 54 try: |
| 39 expect(d, "disable", "0") | 55 utils.system("stop tcsd", ignore_status=True) |
| 40 expect(d, "ownership", "1") | |
| 41 expect(d, "deactivated", "0") | |
| 42 expect(d, "physicalPresenceHWEnable", "0") | |
| 43 expect(d, "physicalPresenceCMDEnable", "1") | |
| 44 expect(d, "physicalPresenceLifetimeLock", "1") | |
| 45 expect(d, "nvLocked", "1") | |
| 46 | 56 |
| 47 utils.system("start tcsd", ignore_status=True) | 57 # Check volatile (ST_CLEAR) flags |
| 58 d = dict_from_command("tpmc getvf"); |
| 59 expect(d, "deactivated", "0") |
| 60 expect(d, "physicalPresence", "0") |
| 61 expect(d, "physicalPresenceLock", "1") |
| 62 expect(d, "bGlobalLock", "1") |
| 63 |
| 64 # Check permanent flags |
| 65 d = dict_from_command("tpmc getpf"); |
| 66 expect(d, "disable", "0") |
| 67 expect(d, "ownership", "1") |
| 68 expect(d, "deactivated", "0") |
| 69 expect(d, "physicalPresenceHWEnable", "0") |
| 70 expect(d, "physicalPresenceCMDEnable", "1") |
| 71 expect(d, "physicalPresenceLifetimeLock", "1") |
| 72 expect(d, "nvLocked", "1") |
| 73 |
| 74 # Check space permissions |
| 75 checkp("0x1007", "0x8001") |
| 76 checkp("0x1008", "0x1") |
| 77 |
| 78 # Check kernel space UID |
| 79 l = os.popen("tpmc read 0x1008 0x5").readline() |
| 80 if (not re.match(".* 4c 57 52 47$", l)): |
| 81 raise error.TestError("invalid kernel space UID: %s" % l) |
| 82 |
| 83 finally: |
| 84 utils.system("start tcsd", ignore_status=True) |
| OLD | NEW |