Home | History | Annotate | Download | only in audio_AudioBluetoothConnectionStability
      1 # Copyright 2015 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 """This is a server side bluetooth connection test using the Chameleon board."""
      6 
      7 import logging
      8 import os
      9 import time, threading
     10 
     11 from autotest_lib.client.bin import utils
     12 from autotest_lib.client.cros.chameleon import audio_test_utils
     13 from autotest_lib.client.cros.chameleon import chameleon_audio_helper
     14 from autotest_lib.client.cros.chameleon import chameleon_audio_ids
     15 from autotest_lib.server.cros.audio import audio_test
     16 
     17 
     18 class audio_AudioBluetoothConnectionStability(audio_test.AudioTest):
     19     """Server side bluetooth connection audio test.
     20 
     21     This test talks to a Chameleon board and a Cros device to verify
     22     bluetooth connection between Cros device and bluetooth module is stable.
     23 
     24     """
     25     version = 1
     26     CONNECTION_TEST_TIME_SECS = 300
     27 
     28     def dump_logs_after_nodes_changed(self):
     29         """Dumps the log after unexpected NodesChanged signal happens."""
     30         audio_test_utils.dump_cros_audio_logs(
     31                 self.host, self.audio_facade, self.resultsdir,
     32                 'after_nodes_changed')
     33 
     34 
     35     def run_once(self, host, suspend=False,
     36                  disable=False, disconnect=False):
     37         """Runs bluetooth audio connection test."""
     38         self.host = host
     39 
     40         factory = self.create_remote_facade_factory(host)
     41         self.audio_facade = factory.create_audio_facade()
     42 
     43         chameleon_board = host.chameleon
     44         chameleon_board.reset()
     45 
     46         widget_factory = chameleon_audio_helper.AudioWidgetFactory(
     47                 factory, host)
     48 
     49         source = widget_factory.create_widget(
     50             chameleon_audio_ids.CrosIds.BLUETOOTH_HEADPHONE)
     51         bluetooth_widget = widget_factory.create_widget(
     52             chameleon_audio_ids.PeripheralIds.BLUETOOTH_DATA_RX)
     53         recorder = widget_factory.create_widget(
     54             chameleon_audio_ids.ChameleonIds.LINEIN)
     55 
     56         binder = widget_factory.create_binder(
     57                 source, bluetooth_widget, recorder)
     58 
     59         with chameleon_audio_helper.bind_widgets(binder):
     60 
     61             audio_test_utils.dump_cros_audio_logs(
     62                     host, self.audio_facade, self.resultsdir, 'after_binding')
     63 
     64             if audio_test_utils.has_internal_microphone(host):
     65                 self.audio_facade.set_chrome_active_node_type(None, 'BLUETOOTH')
     66 
     67             audio_test_utils.check_audio_nodes(self.audio_facade,
     68                                                (['BLUETOOTH'], ['BLUETOOTH']))
     69 
     70             # Monitors there is no node change in this time period.
     71             with audio_test_utils.monitor_no_nodes_changed(
     72                     self.audio_facade, self.dump_logs_after_nodes_changed):
     73                 logging.debug('Monitoring NodesChanged signal for %s seconds',
     74                               self.CONNECTION_TEST_TIME_SECS)
     75                 time.sleep(self.CONNECTION_TEST_TIME_SECS)
     76