blob: 6f82629b3bd4c01c540b42203fa1a94f6e1e7089 [file] [log] [blame]
# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import commands, logging, os, re, time
from autotest_lib.client.bin import test, utils
from autotest_lib.client.common_lib import error
from autotest_lib.client.cros import rtc, sys_power
# It may be useful in the future to combine the following three functions
# into a separate library for use across multiple AutoTest files.
# At present, the AutoTest files listed below use these common functions:
# * hardware_TPMCheckS3 (this test), and
# * hardware_TPMCheck
def dict_from_command(command):
dict = {}
out = os.popen(command)
for linecr in out.readlines():
line = linecr.strip()
match = re.match("([^ ]+) (.*)", line)
k =
v =
dict[k] = v
return dict
def expect(d, key, value):
if (d[key] != value):
raise error.TestError("expecting %s = %s, observing %s = %s" %
(key, value, key, d[key]))
logging.debug("TPM: found %s = %s" % (key, value))
def check_tpm_volatile_states( ):
# Check TPM state values expected during normal operation, prior to
# and after a suspend/resume to/from RAM.
# Must stop the TCSD process to be able to collect TPM status,
# then restart TCSD process to leave system in a known good state.
# Stop tcsd daemon to have access to tpmc commands
utils.system("stop tcsd", ignore_status=True)
# Check TPM volatile (ST_CLEAR) flags
d = dict_from_command("tpmc getvf");
expect(d, "deactivated", "0")
expect(d, "physicalPresence", "0")
expect(d, "physicalPresenceLock", "1")
expect(d, "bGlobalLock", "1")
utils.system("start tcsd")
class hardware_TPMCheckS3(test.test):
# This test checks for the TPM to be able to Suspend and Resume from
# RAM and maintain previous state.
# The test sequence follows the steps below:
# 1. Read current TPM values
# 2. Cause suspend to RAM for 15 seconds
# 3. Read TPM values after resume from RAM
# 4. Error if TPM values after resume are not as expected.
version = 1
def run_once(self):
# Some idle time before initiating suspend-to-ram
# Can tweak idle_time if necessary. Minimum of zero.
idle_time = 3
# Check for current state of the TPM prior to Suspend to RAM.
# Can tweek time_to_sleep if necessary, but should
# be at least 10 seconds or more.
time_to_sleep = 10
# Set the alarm
alarm_time = rtc.get_seconds() + time_to_sleep
logging.debug('alarm_time = %d', alarm_time)
# Suspend the system to RAM
# Check for current state of the TPM after Resume from RAM.