1# Copyright 2017 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 6import time 7import random 8 9from autotest_lib.client.common_lib import error 10from autotest_lib.server.cros.cfm import cfm_base_test 11from autotest_lib.client.common_lib.cros import power_cycle_usb_util 12from autotest_lib.client.common_lib.cros.cfm.usb import cfm_usb_devices 13from autotest_lib.client.common_lib.cros.cfm.usb import usb_device_collector 14 15 16LONG_TIMEOUT = 20 17SHORT_TIMEOUT = 5 18 19class enterprise_CFM_MimoSanity(cfm_base_test.CfmBaseTest): 20 """Tests the following fuctionality works on CFM enrolled devices: 21 1. Verify CfM has Camera, Speaker and Mimo connected. 22 2. Verify all peripherals have expected usb interfaces. 23 3. Verify after rebooting CfM Mimo is present. 24 4. Verify after powercycle Mimo Mimo comes back. 25 """ 26 version = 1 27 28 29 def _power_cycle_mimo_device(self): 30 """Power Cycle Mimo device""" 31 logging.info('Plan to power cycle Mimo') 32 try: 33 power_cycle_usb_util.power_cycle_usb_vidpid( 34 self._host, self._board, 35 self._mimo.vendor_id, self._mimo.product_id) 36 except KeyError: 37 raise error.TestFail('Could not find target device: %s', 38 self._mimo.product) 39 40 41 def _test_power_cycle_mimo(self): 42 """Power Cycle Mimo device for multiple times""" 43 self._power_cycle_mimo_device() 44 logging.info('Powercycle done for %s (%s)', 45 self._mimo.product, self._mimo.vid_pid) 46 time.sleep(LONG_TIMEOUT) 47 self._kernel_usb_sanity_test() 48 49 50 def _check_peripherals(self): 51 """ 52 Check CfM has camera, speaker and MiMO connected. 53 @returns list of peripherals found. 54 """ 55 atruses = self.device_collector.get_devices_by_spec( 56 cfm_usb_devices.ATRUS) 57 if not atruses: 58 raise error.TestFail('Expected to find connected speakers.') 59 self._atrus = atruses[0] 60 61 huddlys = self.device_collector.get_devices_by_spec( 62 cfm_usb_devices.HUDDLY_GO) 63 if not huddlys: 64 raise error.TestFail('Expected to find a connected camera.') 65 self._huddly = huddlys[0] 66 67 68 displays = self.device_collector.get_devices_by_spec( 69 *cfm_usb_devices.ALL_MIMO_DISPLAYS) 70 if not displays: 71 raise error.TestFail('Expected a MiMO display to be connected.') 72 if len(displays) != 1: 73 raise error.TestFail('Expected exactly one MiMO display to be ' 74 'connected. Found %d' % len(displays)) 75 self._mimo = displays[0] 76 77 78 controllers = self.device_collector.get_devices_by_spec( 79 cfm_usb_devices.MIMO_VUE_HID_TOUCH_CONTROLLER) 80 if not controllers: 81 raise error.TestFail('Expected a MiMO controller to be connected.') 82 if len(controllers) != 1: 83 raise error.TestFail('Expected exactly one MiMO controller to be ' 84 'connected. Found %d' % len(controllers)) 85 self._touch_controller = controllers[0] 86 87 def _check_device_interfaces_match_spec(self, spec): 88 for device in self.device_collector.get_devices_by_spec(spec): 89 if not device.interfaces_match_spec(spec): 90 raise error.TestFail( 91 'Device %s has unexpected interfaces.' 92 'Expected: %s. Actual: %s' % (device, spec.interfaces, 93 spec.interfaces)) 94 95 def _kernel_usb_sanity_test(self): 96 """ 97 Check connected camera, speaker and Mimo have expected usb interfaces. 98 """ 99 self._check_device_interfaces_match_spec(self._atrus) 100 self._check_device_interfaces_match_spec(self._huddly) 101 self._check_device_interfaces_match_spec(self._mimo) 102 self._check_device_interfaces_match_spec(self._touch_controller) 103 104 def _test_reboot(self): 105 """Reboot testing for Mimo.""" 106 107 boot_id = self._host.get_boot_id() 108 self._host.reboot() 109 self._host.wait_for_restart(old_boot_id=boot_id) 110 self.cfm_facade.restart_chrome_for_cfm() 111 time.sleep(SHORT_TIMEOUT) 112 self.cfm_facade.wait_for_telemetry_commands() 113 self._kernel_usb_sanity_test() 114 115 116 def _test_mimo_in_call(self) : 117 """ 118 Start a hangout session and end the session after random time. 119 120 @raises error.TestFail if any of the checks fail. 121 """ 122 logging.info('Joining meeting...') 123 if self._is_meeting: 124 self.cfm_facade.start_meeting_session() 125 else: 126 self.cfm_facade.start_new_hangout_session('mimo-sanity-test') 127 time.sleep(random.randrange(SHORT_TIMEOUT, LONG_TIMEOUT)) 128 129 # Verify USB data in-call. 130 self._kernel_usb_sanity_test() 131 132 if self._is_meeting: 133 self.cfm_facade.end_meeting_session() 134 else: 135 self.cfm_facade.end_hangout_session() 136 logging.info('Session has ended.') 137 138 # Verify USB devices after leaving the call. 139 self._kernel_usb_sanity_test() 140 time.sleep(SHORT_TIMEOUT) 141 142 143 def run_once(self, repetitions, is_meeting): 144 """ 145 Runs the test. 146 147 @param repetitions: amount of reboot cycles to perform. 148 """ 149 # Remove 'board:' prefix. 150 self._board = self._host.get_board().split(':')[1] 151 self._is_meeting = is_meeting 152 153 self.device_collector = usb_device_collector.UsbDeviceCollector( 154 self._host) 155 self._check_peripherals() 156 self._kernel_usb_sanity_test() 157 158 self.cfm_facade.wait_for_telemetry_commands() 159 160 for i in xrange(1, repetitions + 1): 161 logging.info('Running test cycle %d/%d', i, repetitions) 162 self._test_reboot() 163 self._test_mimo_in_call() 164 self._test_power_cycle_mimo() 165