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 __future__ import print_function 6 7import logging 8import time 9 10from autotest_lib.client.common_lib import error 11from autotest_lib.client.common_lib.cros import cr50_utils 12from autotest_lib.server.cros.faft.cr50_test import Cr50Test 13 14 15class firmware_Cr50Open(Cr50Test): 16 """Verify cr50 open.""" 17 version = 1 18 19 def initialize(self, host, cmdline_args, ccd_open_restricted, full_args): 20 """Initialize the test""" 21 super(firmware_Cr50Open, self).initialize(host, cmdline_args, 22 full_args) 23 24 if not self.faft_config.has_powerbutton: 25 raise error.TestNAError('No power button. Unable to test ccd open') 26 27 self.ccd_open_restricted = ccd_open_restricted 28 self.fast_ccd_open(enable_testlab=True) 29 self.cr50.ccd_reset() 30 self.cr50.set_ccd_level('lock') 31 32 33 def check_cr50_open(self, dev_mode, batt_pres): 34 """Verify you can't open ccd unless dev mode is enabled. 35 36 Make sure the ability to open ccd corresponds with the device being in 37 dev mode. When the device is in dev mode, open should be accessible from 38 the AP. When the device is in normal mode it shouldn't be accessible. 39 Open will never work from the console. 40 41 Args: 42 dev_mode: bool reflecting whether the device is in dev mode. If 43 True, the device is in dev mode. If False, the device is in 44 normal mode. 45 batt_pres: True if the battery is connected 46 """ 47 self.cr50.set_ccd_level('lock') 48 self.cr50.get_ccd_info() 49 50 #Make sure open doesn't work from the console. 51 try: 52 self.cr50.set_ccd_level('open') 53 except error.TestFail as e: 54 self.cr50.check_for_console_errors('ccd open from console') 55 if not batt_pres: 56 raise error.TestFail('Unable to open cr50 from console with ' 57 'batt disconnected: %s' % str(e)) 58 # If ccd open is limited, open should fail with access denied 59 # 60 # TODO: move logic to set_ccd_level. 61 if 'Access Denied' in str(e) and self.ccd_open_restricted: 62 logging.info('console ccd open successfully rejected') 63 else: 64 raise 65 else: 66 if self.ccd_open_restricted and batt_pres: 67 raise error.TestFail('Open should not be accessible from the ' 68 'console') 69 self.cr50.set_ccd_level('lock') 70 71 if not batt_pres: 72 cr50_utils.GSCTool(self.host, ['-a', '-o'], 73 expect_reboot=not batt_pres) 74 # Wait long enough for cr50 to open ccd and wipe the tpm. 75 time.sleep(10) 76 if self.cr50.OPEN != self.cr50.get_ccd_level(): 77 raise error.TestFail('Unable to open cr50 from AP with batt ' 78 'disconnected') 79 return 80 #Make sure open only works from the AP when the device is in dev mode. 81 try: 82 self.ccd_open_from_ap() 83 except error.TestFail as e: 84 logging.info(e) 85 self.cr50.check_for_console_errors('ccd open from ap') 86 # ccd open should work if the device is in dev mode or ccd open 87 # isn't restricted. If open failed for some reason raise the error. 88 if dev_mode or not self.ccd_open_restricted: 89 raise 90 91 92 def run_once(self): 93 """Check open only works when the device is in dev mode.""" 94 self.cr50.send_command('ccd testlab open') 95 self.cr50.set_batt_pres_state('connected', True) 96 self.switcher.reboot_to_mode(to_mode='dev') 97 self.check_cr50_open(True, True) 98 self.switcher.reboot_to_mode(to_mode='normal') 99 self.check_cr50_open(False, True) 100 101 self.cr50.send_command('ccd testlab open') 102 self.cr50.set_batt_pres_state('disconnected', True) 103 self.check_cr50_open(False, False) 104