1# Copyright 2016 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 datetime, logging, random, time 6 7from autotest_lib.client.common_lib import error 8from autotest_lib.client.common_lib.cros import tpm_utils 9from autotest_lib.server import test 10from autotest_lib.server.cros.multimedia import remote_facade_factory 11 12 13_SHORT_TIMEOUT = 2 14_LONG_TIMEOUT = 5 15 16 17class enterprise_CFM_VolumeChange(test.test): 18 """Volume changes made in the CFM / hotrod app should be accurately 19 reflected in CrOS. 20 """ 21 version = 1 22 23 24 def _enroll_device(self): 25 """Enroll device into CFM.""" 26 self.cfm_facade.enroll_device() 27 self.cfm_facade.restart_chrome_for_cfm() 28 self.cfm_facade.wait_for_telemetry_commands() 29 self.cfm_facade.wait_for_oobe_start_page() 30 31 if not self.cfm_facade.is_oobe_start_page(): 32 raise error.TestFail('CFM did not reach oobe screen.') 33 34 self.cfm_facade.skip_oobe_screen() 35 36 37 def _start_hangout_session(self): 38 """Start a hangout session. 39 40 @param webview_context: Context for hangouts webview. 41 @raises error.TestFail if any of the checks fail. 42 """ 43 current_time = datetime.datetime.now().strftime("%Y%m%d-%H%M%S") 44 hangout_name = 'auto-hangout-' + current_time 45 46 self.cfm_facade.start_new_hangout_session(hangout_name) 47 48 if self.cfm_facade.is_ready_to_start_hangout_session(): 49 raise error.TestFail('Is already in hangout session and should not ' 50 'be able to start another session.') 51 52 time.sleep(_SHORT_TIMEOUT) 53 54 if self.cfm_facade.is_mic_muted(): 55 self.cfm_facade.unmute_mic() 56 57 58 def _end_hangout_session(self): 59 """End hangout session. 60 61 @param webview_context: Context for hangouts window. 62 """ 63 self.cfm_facade.end_hangout_session() 64 65 if self.cfm_facade.is_in_hangout_session(): 66 raise error.TestFail('CFM should not be in hangout session.') 67 68 69 def _change_volume(self, repeat, cmd): 70 """Change volume using CFM api and cross check with cras_test_client 71 output. 72 73 @param repeat: Number of times the volume should be changed. 74 @param cmd: cras_test_client command to run. 75 @raises error.TestFail if cras volume does not match volume set by CFM. 76 """ 77 # This is used to trigger crbug.com/614885 78 for volume in range(55, 85): 79 self.cfm_facade.set_speaker_volume(str(volume)) 80 time.sleep(random.uniform(0.01, 0.05)) 81 82 while repeat: 83 # TODO: Change range back to 0, 100 once crbug.com/633809 is fixed. 84 cfm_volume = str(random.randrange(2, 100, 1)) 85 self.cfm_facade.set_speaker_volume(cfm_volume) 86 time.sleep(_SHORT_TIMEOUT) 87 88 cras_volume = [s.strip() for s in 89 self.client.run_output(cmd).splitlines()] 90 for volume in cras_volume: 91 if volume != cfm_volume: 92 raise error.TestFail('Cras volume (%s) does not match ' 93 'volume set by CFM (%s).' % 94 (volume, cfm_volume)) 95 logging.info('Cras volume (%s) matches volume set by CFM (%s)', 96 cras_volume, cfm_volume) 97 98 repeat -= 1 99 100 101 def run_once(self, host, repeat, cmd): 102 """Runs the test.""" 103 self.client = host 104 105 factory = remote_facade_factory.RemoteFacadeFactory( 106 host, no_chrome=True) 107 self.cfm_facade = factory.create_cfm_facade() 108 109 tpm_utils.ClearTPMOwnerRequest(self.client) 110 111 if self.client.servo: 112 self.client.servo.switch_usbkey('dut') 113 self.client.servo.set('usb_mux_sel3', 'dut_sees_usbkey') 114 time.sleep(_LONG_TIMEOUT) 115 self.client.servo.set('dut_hub1_rst1', 'off') 116 time.sleep(_LONG_TIMEOUT) 117 118 try: 119 self._enroll_device() 120 self._start_hangout_session() 121 self._change_volume(repeat, cmd) 122 self._end_hangout_session() 123 except Exception as e: 124 raise error.TestFail(str(e)) 125 126 tpm_utils.ClearTPMOwnerRequest(self.client) 127