Home | History | Annotate | Download | only in platform_CryptohomeTpmLiveTestServer
      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 
      5 from autotest_lib.client.common_lib import error
      6 from autotest_lib.client.common_lib.cros import tpm_utils
      7 from autotest_lib.server import autotest
      8 from autotest_lib.server import test
      9 
     10 
     11 class 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         self.client = host
     18 
     19         # Skip the test if the TPM is unavailable.
     20         tpm_status = tpm_utils.TPMStatus(self.client)
     21         if 'Enabled' not in tpm_status:
     22             raise error.TestError('Error obtaining TPM enabled state. Status '
     23                                   'returned by cryptohome: ' + str(tpm_status))
     24         if not tpm_status['Enabled']:
     25             return
     26 
     27         # Clear the TPM, so that the client test is able to obtain the TPM owner
     28         # password.
     29         tpm_utils.ClearTPMOwnerRequest(self.client, wait_for_ready=True)
     30 
     31         # Run the client test which executes the cryptohome's TPM live test.
     32         autotest.Autotest(self.client).run_test(
     33                 'platform_CryptohomeTpmLiveTest', check_client_result=True)
     34 
     35         # Clean the TPM up, so that the TPM state clobbered by the TPM live
     36         # tests doesn't affect subsequent tests.
     37         tpm_utils.ClearTPMOwnerRequest(self.client)
     38