1
# Copyright (C) 2010 Google Inc. All rights reserved.
2
# Copyrigth (C) 2012 Intel Corporation
4
# Redistribution and use in source and binary forms, with or without
5
# modification, are permitted provided that the following conditions are
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
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.
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.
35
_log = logging.getLogger(__name__)
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:
47
pactl_process = subprocess.Popen(["pactl", "list", "short", "modules"], stdout=subprocess.PIPE, stderr=devnull)
50
# pactl might not be available.
51
_log.debug('pactl not found. Please install pulseaudio-utils to avoid some potential media test failures.')
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
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])
65
if pactl_process.returncode == 0:
66
_log.debug('Unloaded module-stream-restore successfully')
68
_log.debug('Unloading module-stream-restore failed')
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.')
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)
82
if pactl_process.returncode == 0:
83
_log.debug('Restored module-stream-restore successfully')
85
_log.debug('Restoring module-stream-restore failed')