• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 logging
6import random
7import time
8
9from autotest_lib.client.common_lib import error
10from autotest_lib.server.cros.cfm import cfm_base_test
11
12_SHORT_TIMEOUT = 2
13
14
15class enterprise_CFM_VolumeChange(cfm_base_test.CfmBaseTest):
16    """
17    Volume changes made in the CFM / hotrod app should be accurately reflected
18    in CrOS.
19    """
20    version = 1
21
22
23    def _change_volume(self, repeat, cmd):
24        """
25        Change volume using CFM api and cross check with cras_test_client
26        output.
27
28        @param repeat: Number of times the volume should be changed.
29        @param cmd: cras_test_client command to run.
30        @raises error.TestFail if cras volume does not match volume set by CFM.
31        """
32        # This is used to trigger crbug.com/614885
33        for volume in range(55, 85):
34            self.cfm_facade.set_speaker_volume(volume)
35            time.sleep(random.uniform(0.01, 0.05))
36
37        for _ in xrange(repeat):
38            # There is a minimal volume threshold so we can't start at 0%.
39            # See crbug.com/633809 for more info.
40            cfm_volume = random.randrange(2, 100, 1)
41            self.cfm_facade.set_speaker_volume(cfm_volume)
42            time.sleep(_SHORT_TIMEOUT)
43
44            # Get the volume report from cras_test_client
45            cras_volume = int(
46                self._host.run_output(cmd).splitlines()[0].strip())
47
48            if cras_volume != cfm_volume:
49                raise error.TestFail('Cras volume (%d) does not match '
50                                     'volume set by CFM (%d).' %
51                                     (cras_volume, cfm_volume))
52            else:
53                logging.info('Cras volume (%d) matches volume set by CFM (%d)',
54                             cras_volume, cfm_volume)
55
56    def run_once(self, repeat, cmd):
57        """Runs the test."""
58        self.cfm_facade.wait_for_meetings_telemetry_commands()
59        self.cfm_facade.start_meeting_session()
60        if self.cfm_facade.is_mic_muted():
61            self.cfm_facade.unmute_mic()
62        self._change_volume(repeat, cmd)
63        self.cfm_facade.end_meeting_session()
64