~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Tools/Scripts/webkitpy/layout_tests/port/pulseaudio_sanitizer.py

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2010 Google Inc. All rights reserved.
 
2
# Copyrigth (C) 2012 Intel Corporation
 
3
#
 
4
# Redistribution and use in source and binary forms, with or without
 
5
# modification, are permitted provided that the following conditions are
 
6
# met:
 
7
#
 
8
#     * Redistributions of source code must retain the above copyright
 
9
# notice, this list of conditions and the following disclaimer.
 
10
#     * Redistributions in binary form must reproduce the above
 
11
# copyright notice, this list of conditions and the following disclaimer
 
12
# in the documentation and/or other materials provided with the
 
13
# distribution.
 
14
#     * Neither the Google name nor the names of its
 
15
# contributors may be used to endorse or promote products derived from
 
16
# this software without specific prior written permission.
 
17
#
 
18
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
19
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
20
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
21
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 
22
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
23
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
24
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
25
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
26
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
27
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
28
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
29
 
 
30
import logging
 
31
import os
 
32
import subprocess
 
33
 
 
34
 
 
35
_log = logging.getLogger(__name__)
 
36
 
 
37
 
 
38
# Shared by GTK and EFL for pulseaudio sanitizing before running tests.
 
39
class PulseAudioSanitizer:
 
40
    def _unload_pulseaudio_module(self):
 
41
        # Unload pulseaudio's module-stream-restore, since it remembers
 
42
        # volume settings from different runs, and could affect
 
43
        # multimedia tests results
 
44
        self._pa_module_index = -1
 
45
        with open(os.devnull, 'w') as devnull:
 
46
            try:
 
47
                pactl_process = subprocess.Popen(["pactl", "list", "short", "modules"], stdout=subprocess.PIPE, stderr=devnull)
 
48
                pactl_process.wait()
 
49
            except OSError:
 
50
                # pactl might not be available.
 
51
                _log.debug('pactl not found. Please install pulseaudio-utils to avoid some potential media test failures.')
 
52
                return
 
53
        modules_list = pactl_process.communicate()[0]
 
54
        for module in modules_list.splitlines():
 
55
            if module.find("module-stream-restore") >= 0:
 
56
                # Some pulseaudio-utils versions don't provide
 
57
                # the index, just an empty string
 
58
                self._pa_module_index = module.split('\t')[0] or -1
 
59
                try:
 
60
                    # Since they could provide other stuff (not an index
 
61
                    # nor an empty string, let's make sure this is an int.
 
62
                    if int(self._pa_module_index) != -1:
 
63
                        pactl_process = subprocess.Popen(["pactl", "unload-module", self._pa_module_index])
 
64
                        pactl_process.wait()
 
65
                        if pactl_process.returncode == 0:
 
66
                            _log.debug('Unloaded module-stream-restore successfully')
 
67
                        else:
 
68
                            _log.debug('Unloading module-stream-restore failed')
 
69
                except ValueError:
 
70
                        # pactl should have returned an index if the module is found
 
71
                        _log.debug('Unable to parse module index. Please check if your pulseaudio-utils version is too old.')
 
72
                return
 
73
 
 
74
    def _restore_pulseaudio_module(self):
 
75
        # If pulseaudio's module-stream-restore was previously unloaded,
 
76
        # restore it back. We shouldn't need extra checks here, since an
 
77
        # index != -1 here means we successfully unloaded it previously.
 
78
        if self._pa_module_index != -1:
 
79
            with open(os.devnull, 'w') as devnull:
 
80
                pactl_process = subprocess.Popen(["pactl", "load-module", "module-stream-restore"], stdout=devnull, stderr=devnull)
 
81
                pactl_process.wait()
 
82
                if pactl_process.returncode == 0:
 
83
                    _log.debug('Restored module-stream-restore successfully')
 
84
                else:
 
85
                    _log.debug('Restoring module-stream-restore failed')