Home | History | Annotate | Download | only in enterprise_CFM_VolumeChange
      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 
      5 import datetime
      6 import logging
      7 import random
      8 import time
      9 
     10 from autotest_lib.client.common_lib import error
     11 from autotest_lib.server.cros.cfm import cfm_base_test
     12 
     13 _SHORT_TIMEOUT = 2
     14 
     15 
     16 class enterprise_CFM_VolumeChange(cfm_base_test.CfmBaseTest):
     17     """
     18     Volume changes made in the CFM / hotrod app should be accurately reflected
     19     in CrOS.
     20     """
     21     version = 1
     22 
     23 
     24     def _start_hangout_session(self):
     25         """
     26         Start a hangout session.
     27 
     28         Also unmutes the mic if it's muted after joining.
     29 
     30         @raises error.TestFail if any of the checks fail.
     31         """
     32         current_time = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
     33         hangout_name = 'auto-hangout-' + current_time
     34 
     35         self.cfm_facade.start_new_hangout_session(hangout_name)
     36 
     37         if self.cfm_facade.is_ready_to_start_hangout_session():
     38             raise error.TestFail('Is already in hangout session and should not '
     39                                  'be able to start another session.')
     40         time.sleep(_SHORT_TIMEOUT)
     41 
     42         if self.cfm_facade.is_mic_muted():
     43             self.cfm_facade.unmute_mic()
     44 
     45 
     46     def _change_volume(self, repeat, cmd):
     47         """
     48         Change volume using CFM api and cross check with cras_test_client
     49         output.
     50 
     51         @param repeat: Number of times the volume should be changed.
     52         @param cmd: cras_test_client command to run.
     53         @raises error.TestFail if cras volume does not match volume set by CFM.
     54         """
     55         # This is used to trigger crbug.com/614885
     56         for volume in range(55, 85):
     57             self.cfm_facade.set_speaker_volume(str(volume))
     58             time.sleep(random.uniform(0.01, 0.05))
     59 
     60         for _ in xrange(repeat):
     61             # There is a minimal volume threshold so we can't start at 0%.
     62             # See crbug.com/633809 for more info.
     63             cfm_volume = str(random.randrange(2, 100, 1))
     64             self.cfm_facade.set_speaker_volume(cfm_volume)
     65             time.sleep(_SHORT_TIMEOUT)
     66 
     67             cras_volume = [s.strip() for s in
     68                            self._host.run_output(cmd).splitlines()]
     69             for volume in cras_volume:
     70                 if volume != cfm_volume:
     71                     raise error.TestFail('Cras volume (%s) does not match '
     72                                          'volume set by CFM (%s).' %
     73                                          (volume, cfm_volume))
     74             logging.info('Cras volume (%s) matches volume set by CFM (%s)',
     75                          cras_volume, cfm_volume)
     76 
     77 
     78     def run_once(self, repeat, cmd):
     79         """Runs the test."""
     80         self.cfm_facade.wait_for_hangouts_telemetry_commands()
     81         self._start_hangout_session()
     82         self._change_volume(repeat, cmd)
     83         self.cfm_facade.end_hangout_session()
     84 
     85