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, logging, random, time
      6 
      7 from autotest_lib.client.common_lib import error
      8 from autotest_lib.client.common_lib.cros import tpm_utils
      9 from autotest_lib.server import test
     10 from autotest_lib.server.cros.multimedia import remote_facade_factory
     11 
     12 
     13 _SHORT_TIMEOUT = 2
     14 _LONG_TIMEOUT = 5
     15 
     16 
     17 class 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 = self.client.run_output(cmd)
     89             if cras_volume != cfm_volume:
     90                 raise error.TestFail('Cras volume (%s) does not match volume '
     91                                      'set by CFM (%s).' %
     92                                      (cras_volume, cfm_volume))
     93             logging.info('Cras volume (%s) matches volume set by CFM (%s)',
     94                          cras_volume, cfm_volume)
     95 
     96             repeat -= 1
     97 
     98 
     99     def run_once(self, host, repeat, cmd):
    100         """Runs the test."""
    101         self.client = host
    102 
    103         factory = remote_facade_factory.RemoteFacadeFactory(
    104                 host, no_chrome=True)
    105         self.cfm_facade = factory.create_cfm_facade()
    106 
    107         tpm_utils.ClearTPMOwnerRequest(self.client)
    108 
    109         if self.client.servo:
    110             self.client.servo.switch_usbkey('dut')
    111             self.client.servo.set('usb_mux_sel3', 'dut_sees_usbkey')
    112             time.sleep(_LONG_TIMEOUT)
    113             self.client.servo.set('dut_hub1_rst1', 'off')
    114             time.sleep(_LONG_TIMEOUT)
    115 
    116         try:
    117             self._enroll_device()
    118             self._start_hangout_session()
    119             self._change_volume(repeat, cmd)
    120             self._end_hangout_session()
    121         except Exception as e:
    122             raise error.TestFail(str(e))
    123 
    124         tpm_utils.ClearTPMOwnerRequest(self.client)
    125