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