Skip to content

Commit 4571c3f

Browse files
committed
tests: adjust audio tests for changed recording stream behavior
Now "muted" mic is not connected anymore, so don't expect it. QubesOS/qubes-issues#9999
1 parent 26ae94d commit 4571c3f

File tree

1 file changed

+35
-20
lines changed

1 file changed

+35
-20
lines changed

qubes/tests/integ/audio.py

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -285,28 +285,12 @@ def _find_pactl_entry_for_vm(self, pactl_data, vm_name):
285285
if s["properties"].get("application.name") == vm_name
286286
][0]
287287
except IndexError:
288-
self.fail("source-output for VM {} not found".format(vm.name))
289-
# self.fail never returns
290-
assert False
288+
return None
291289

292-
def _configure_audio_recording(self, vm):
290+
def _configure_audio_recording(self, vm, expect_stream=True):
293291
"""Connect VM's source-output to sink monitor instead of mic"""
294292
audiovm = vm.audiovm
295293

296-
source_outputs = json.loads(
297-
self._call_in_audiovm(
298-
audiovm, ["pactl", "-f", "json", "list", "source-outputs"]
299-
)
300-
)
301-
302-
if not source_outputs:
303-
self.fail("no source-output found in {}".format(audiovm.name))
304-
assert False
305-
306-
output_info = self._find_pactl_entry_for_vm(source_outputs, vm.name)
307-
output_index = output_info["index"]
308-
current_source = output_info["source"]
309-
310294
sources = json.loads(
311295
self._call_in_audiovm(
312296
audiovm, ["pactl", "-f", "json", "list", "sources"]
@@ -326,11 +310,42 @@ def _configure_audio_recording(self, vm):
326310
# self.fail never returns
327311
assert False
328312

313+
assert isinstance(source_index, int)
314+
315+
source_outputs = json.loads(
316+
self._call_in_audiovm(
317+
audiovm, ["pactl", "-f", "json", "list", "source-outputs"]
318+
)
319+
)
320+
321+
output_info = self._find_pactl_entry_for_vm(source_outputs, vm.name)
322+
if expect_stream and not output_info:
323+
self.fail("source-output for VM {} not found".format(vm.name))
324+
# self.fail never returns
325+
assert False
326+
elif not expect_stream and output_info:
327+
self.fail(
328+
"source-output for VM {} unexpecedly present".format(vm.name)
329+
)
330+
# self.fail never returns
331+
assert False
332+
333+
if not expect_stream:
334+
cmd = [
335+
"pactl",
336+
"set-default-source",
337+
str(source_index),
338+
]
339+
self._call_in_audiovm(audiovm, cmd)
340+
return
341+
342+
output_index = output_info["index"]
343+
current_source = output_info["source"]
344+
329345
attempts_left = 5
330346
# pactl seems to fail sometimes, still with exit code 0...
331347
while current_source != source_index and attempts_left:
332348
assert isinstance(output_index, int)
333-
assert isinstance(source_index, int)
334349
cmd = [
335350
"pactl",
336351
"move-source-output",
@@ -392,7 +407,7 @@ def detach_mic(self):
392407

393408
def common_audio_record_muted(self):
394409
# connect VM's recording source output monitor (instead of mic)
395-
self._configure_audio_recording(self.testvm1)
410+
self._configure_audio_recording(self.testvm1, expect_stream=False)
396411

397412
# generate some "audio" data
398413
audio_in = b"\x20" * 4 * 44100

0 commit comments

Comments
 (0)