OLD | NEW |
| (Empty) |
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 | |
3 # found in the LICENSE file. | |
4 | |
5 import logging, os, re | |
6 from autotest_lib.client.bin import test, utils | |
7 from autotest_lib.client.common_lib import error | |
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 | |
22 def dict_from_command(command): | |
23 dict = {} | |
24 out = os.popen(command) | |
25 for linecr in out.readlines(): | |
26 line = linecr.strip() | |
27 match = re.match("([^ ]+) (.*)", line) | |
28 k = match.group(1) | |
29 v = match.group(2) | |
30 dict[k] = v | |
31 return dict | |
32 | |
33 def expect(d, key, value): | |
34 if (d[key] != value): | |
35 raise error.TestError("expecting %s = %s, observing %s = %s" % | |
36 (key, value, key, d[key])) | |
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 | |
44 class hardware_TPMCheck(test.test): | |
45 version = 1 | |
46 | |
47 def run_once(self): | |
48 | |
49 if old_or_missing_firmware_version(): | |
50 logging.warning("skipping test because firmware " + | |
51 "version missing or deemed too old") | |
52 return | |
53 | |
54 try: | |
55 utils.system("stop tcsd", ignore_status=True) | |
56 | |
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 |