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 5 from autotest_lib.client.common_lib import error 6 from autotest_lib.client.common_lib.cros.cfm import cras_node_collector 7 from autotest_lib.client.cros.chameleon import motor_board 8 from autotest_lib.server.cros.cfm import cfm_base_test 9 10 11 class enterprise_CFM_USBSpeakerEndToEndSanity(cfm_base_test.CfmBaseTest): 12 """Tests the USB speaker buttons work properly.""" 13 version = 1 14 15 def initialize(self, host, usb_speaker): 16 """ 17 Initializes common test properties. 18 19 @param host: a host object representing the DUT. 20 @param usb_speaker: The speaker to test. 21 """ 22 super(enterprise_CFM_USBSpeakerEndToEndSanity, self).initialize(host) 23 self.motor = self._host.chameleon.get_motor_board() 24 self.cras_collector = cras_node_collector.CrasNodeCollector(self._host) 25 self.usb_speaker = usb_speaker 26 27 def _get_cras_output_node_volumes(self, speaker_name): 28 """ 29 Gets the volume values for all output nodes with the specified name. 30 31 @param speaker_name: The name of the speaker output node. 32 @returns A list volume values. 33 """ 34 nodes = self.cras_collector.get_output_nodes() 35 return [n.volume for n in nodes if speaker_name in n.device_name] 36 37 def test_increase_volume_button_on_speaker(self): 38 """Tests that pressing the VOL_UP button increases the volume.""" 39 old_cras_volumes = self._get_cras_output_node_volumes( 40 self.usb_speaker.product) 41 42 self.motor.Touch(motor_board.ButtonFunction.VOL_UP) 43 self.motor.Release(motor_board.ButtonFunction.VOL_UP) 44 45 new_cras_volumes = self._get_cras_output_node_volumes( 46 self.usb_speaker.product) 47 48 # List comparison is done elemenet by element. 49 if not new_cras_volumes > old_cras_volumes: 50 raise error.TestFail('Speaker volume increase not reflected in ' 51 'cras volume output. Volume before button ' 52 'press: %s; volume after button press: %s.' 53 % (old_cras_volumes, new_cras_volumes)) 54 55 def test_decrease_volume_button_on_speaker(self): 56 """Tests that pressing the VOL_DOWN button decreases the volume.""" 57 old_cras_volumes = self._get_cras_output_node_volumes( 58 self.usb_speaker.product) 59 60 self.motor.Touch(motor_board.ButtonFunction.VOL_DOWN) 61 self.motor.Release(motor_board.ButtonFunction.VOL_DOWN) 62 63 new_cras_volumes = self._get_cras_output_node_volumes( 64 self.usb_speaker.product) 65 66 # List comparison is done elemenet by element. 67 if not new_cras_volumes < old_cras_volumes: 68 raise error.TestFail('Speaker volume decrease not reflected in ' 69 'cras volume output. Volume before button ' 70 'press: %s; volume after button press: %s.' 71 % (old_cras_volumes, new_cras_volumes)) 72 73 def test_call_hangup_button_on_speaker(self): 74 """Tests the HANG_UP button works.""" 75 self.motor.Touch(motor_board.ButtonFunction.HANG_UP) 76 self.motor.Release(motor_board.ButtonFunction.HANG_UP) 77 78 def test_call_button_on_speaker(self): 79 """Tests the CALL button works.""" 80 self.motor.Touch(motor_board.ButtonFunction.CALL) 81 self.motor.Release(motor_board.ButtonFunction.CALL) 82 83 def test_mute_button_on_speaker(self): 84 """Tests the MUTE button works.""" 85 self.motor.Touch(motor_board.ButtonFunction.MUTE) 86 self.motor.Release(motor_board.ButtonFunction.MUTE) 87 88 def run_once(self): 89 """Runs the test.""" 90 self.test_increase_volume_button_on_speaker() 91 self.test_decrease_volume_button_on_speaker() 92 self.test_call_hangup_button_on_speaker() 93 self.test_call_button_on_speaker() 94 self.test_mute_button_on_speaker() 95