• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 USB playback audio test using the Chameleon board."""
6
7import logging
8import os
9import time
10
11from autotest_lib.client.bin import utils
12from autotest_lib.client.cros.audio import audio_test_data
13from autotest_lib.client.cros.chameleon import audio_test_utils
14from autotest_lib.client.cros.chameleon import chameleon_audio_ids
15from autotest_lib.client.cros.chameleon import chameleon_audio_helper
16from autotest_lib.server.cros.audio import audio_test
17from autotest_lib.server.cros.multimedia import remote_facade_factory
18
19
20class audio_AudioBasicUSBPlayback(audio_test.AudioTest):
21    """Server side USB playback audio test.
22
23    This test talks to a Chameleon board and a Cros device to verify
24    USB audio playback function of the Cros device.
25
26    """
27    version = 1
28    RECORD_SECONDS = 5
29    SUSPEND_SECONDS = 30
30    RPC_RECONNECT_TIMEOUT = 60
31
32    def run_once(self, host, suspend=False):
33        golden_file = audio_test_data.SWEEP_TEST_FILE
34
35        chameleon_board = host.chameleon
36        factory = remote_facade_factory.RemoteFacadeFactory(
37                host, results_dir=self.resultsdir)
38
39        chameleon_board.setup_and_reset(self.outputdir)
40
41        widget_factory = chameleon_audio_helper.AudioWidgetFactory(
42                factory, host)
43
44        source = widget_factory.create_widget(
45            chameleon_audio_ids.CrosIds.USBOUT)
46        recorder = widget_factory.create_widget(
47            chameleon_audio_ids.ChameleonIds.USBIN)
48        binder = widget_factory.create_binder(source, recorder)
49
50        with chameleon_audio_helper.bind_widgets(binder):
51            # Checks the node selected by cras is correct.
52            audio_facade = factory.create_audio_facade()
53
54            audio_test_utils.dump_cros_audio_logs(
55                    host, audio_facade, self.resultsdir, 'after_binding')
56
57            audio_test_utils.check_and_set_chrome_active_node_types(
58                    audio_facade, 'USB', None)
59            audio_test_utils.dump_cros_audio_logs(
60                    host, audio_facade, self.resultsdir, 'after_select')
61
62            audio_test_utils.check_audio_nodes(audio_facade, (['USB'], None))
63
64            logging.info('Setting playback data on Cros device')
65
66            audio_facade.set_selected_output_volume(70)
67
68            source.set_playback_data(golden_file)
69
70            if suspend:
71                audio_test_utils.suspend_resume(host, self.SUSPEND_SECONDS)
72                utils.poll_for_condition(condition=factory.ready,
73                                         timeout=self.RPC_RECONNECT_TIMEOUT,
74                                         desc='multimedia server reconnect')
75                audio_test_utils.check_audio_nodes(audio_facade,
76                                                   (['USB'], None))
77
78            # Starts recording from Chameleon, waits for some time, and then
79            # starts playing from Cros device.
80            logging.info('Start recording from Chameleon.')
81            recorder.start_recording()
82
83            logging.info('Start playing %s on Cros device',
84                         golden_file.path)
85            source.start_playback()
86
87            time.sleep(self.RECORD_SECONDS)
88
89            recorder.stop_recording()
90            logging.info('Stopped recording from Chameleon.')
91
92            audio_test_utils.dump_cros_audio_logs(
93                    host, audio_facade, self.resultsdir, 'after_recording')
94
95            recorder.read_recorded_binary()
96            logging.info('Read recorded binary from Chameleon.')
97
98        recorded_file = os.path.join(self.resultsdir, "recorded.raw")
99        logging.info('Saving recorded data to %s', recorded_file)
100        recorder.save_file(recorded_file)
101
102        audio_test_utils.compare_recorded_correlation(golden_file, recorder)
103