1# Copyright 2018 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 5from autotest_lib.client.common_lib import error 6from autotest_lib.client.common_lib.cros import tpm_utils 7from autotest_lib.server import autotest 8from autotest_lib.server import test 9 10 11class platform_CryptohomeTpmLiveTestServer(test.test): 12 """A test that runs platform_CryptohomeTpmLiveTest and clears the TPM as 13 necessary.""" 14 version = 1 15 16 def run_once(self, host=None): 17 """Runs a single iteration of the test.""" 18 self.client = host 19 20 # Skip the test if the TPM is unavailable. 21 tpm_status = tpm_utils.TPMStatus(self.client) 22 if 'is_enabled' not in tpm_status: 23 raise error.TestError('Error obtaining TPM enabled state. Status ' 24 'returned by cryptohome: ' + str(tpm_status)) 25 if not tpm_status['is_enabled']: 26 return 27 28 # Clear the TPM, so that the client test is able to obtain the TPM owner 29 # password. 30 tpm_utils.ClearTPMOwnerRequest(self.client, wait_for_ready=True) 31 32 # Run the client test which executes the cryptohome's TPM live test. 33 autotest.Autotest(self.client).run_test( 34 'platform_CryptohomeTpmLiveTest', check_client_result=True) 35 36 # Clean the TPM up, so that the TPM state clobbered by the TPM live 37 # tests doesn't affect subsequent tests. 38 tpm_utils.ClearTPMOwnerRequest(self.client) 39