Merge branch 'tests20200301'

* tests20200301:
  tests/salt: don't depend on initial tags set
  tests: make audio tests less racy
This commit is contained in:
Marek Marczykowski-Górecki 2020-03-09 01:45:58 +01:00
commit 36e9afe1ff
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 34 additions and 17 deletions

View File

@ -206,8 +206,10 @@ class TC_00_Dom0(SaltTestMixin, qubes.tests.SystemTestCase):
vm = self.app.add_new_vm('AppVM', label='red', vm = self.app.add_new_vm('AppVM', label='red',
name=vmname) name=vmname)
self.loop.run_until_complete(vm.create_on_disk()) self.loop.run_until_complete(vm.create_on_disk())
new_tags = list(sorted(list(vm.tags) + ['tag1', 'tag2']))
vm.tags.add('tag1') vm.tags.add('tag1')
vm.tags.add('tag3') vm.tags.add('tag3')
old_tags = list(sorted(vm.tags))
with open(os.path.join(self.salt_testdir, 'test_state.sls'), 'w') as f: with open(os.path.join(self.salt_testdir, 'test_state.sls'), 'w') as f:
f.write(vmname + ':\n') f.write(vmname + ':\n')
@ -224,13 +226,14 @@ class TC_00_Dom0(SaltTestMixin, qubes.tests.SystemTestCase):
state_out = list(cmd_output['local'].values())[0] state_out = list(cmd_output['local'].values())[0]
del state_out['start_time'] del state_out['start_time']
del state_out['duration'] del state_out['duration']
self.maxDiff = None
self.assertEqual(state_out, { self.assertEqual(state_out, {
'comment': '====== [\'tags\'] ======\n', 'comment': '====== [\'tags\'] ======\n',
'name': vmname, 'name': vmname,
'result': True, 'result': True,
'changes': { 'changes': {
'qvm.tags': {'qvm.tags': { 'qvm.tags': {'qvm.tags': {
'new': ['tag1', 'tag2'], 'old': ['tag1', 'tag3'], 'new': new_tags, 'old': old_tags,
} }
}, },
}, },
@ -241,7 +244,7 @@ class TC_00_Dom0(SaltTestMixin, qubes.tests.SystemTestCase):
self.assertIn(vmname, self.app.domains) self.assertIn(vmname, self.app.domains)
vm = self.app.domains[vmname] vm = self.app.domains[vmname]
self.assertEqual(set(vm.tags), {'tag1', 'tag2'}) self.assertEqual(set(vm.tags), set(new_tags))
def test_020_qubes_pillar(self): def test_020_qubes_pillar(self):
vmname = self.make_vm_name('appvm') vmname = self.make_vm_name('appvm')

View File

@ -805,6 +805,20 @@ class TC_00_AppVMMixin(object):
finally: finally:
self.app.clockvm = None self.app.clockvm = None
def wait_for_pulseaudio_startup(self, vm):
self.loop.run_until_complete(
self.wait_for_session(self.testvm1))
try:
self.loop.run_until_complete(vm.run_for_stdio(
"timeout 30s sh -c 'while ! pactl info; do sleep 1; done'"
))
except subprocess.CalledProcessError as e:
self.fail('Timeout waiting for pulseaudio start in {}: {}{}'.format(
vm.name, e.stdout, e.stderr))
# and some more...
self.loop.run_until_complete(asyncio.sleep(1))
@unittest.skipUnless(spawn.find_executable('parecord'), @unittest.skipUnless(spawn.find_executable('parecord'),
"pulseaudio-utils not installed in dom0") "pulseaudio-utils not installed in dom0")
def test_220_audio_playback(self): def test_220_audio_playback(self):
@ -817,10 +831,7 @@ class TC_00_AppVMMixin(object):
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
self.skipTest('pulseaudio-utils not installed in VM') self.skipTest('pulseaudio-utils not installed in VM')
self.loop.run_until_complete( self.wait_for_pulseaudio_startup(self.testvm1)
self.wait_for_session(self.testvm1))
# and some more...
self.loop.run_until_complete(asyncio.sleep(1))
# generate some "audio" data # generate some "audio" data
audio_in = b'\x20' * 44100 audio_in = b'\x20' * 44100
self.loop.run_until_complete( self.loop.run_until_complete(
@ -845,8 +856,13 @@ class TC_00_AppVMMixin(object):
p.wait() p.wait()
# allow few bytes missing, don't use assertIn, to avoid printing # allow few bytes missing, don't use assertIn, to avoid printing
# the whole data in error message # the whole data in error message
if audio_in[:-8] not in recorded_audio.file.read(): recorded_audio = recorded_audio.file.read()
self.fail('played sound not found in dom0') if audio_in[:-8] not in recorded_audio:
found_bytes = recorded_audio.count(audio_in[0])
all_bytes = len(audio_in)
self.fail('played sound not found in dom0, '
'missing {} bytes out of {}'.format(
all_bytes-found_bytes, all_bytes))
def _configure_audio_recording(self, vm): def _configure_audio_recording(self, vm):
'''Connect VM's output-source to sink monitor instead of mic''' '''Connect VM's output-source to sink monitor instead of mic'''
@ -883,10 +899,7 @@ class TC_00_AppVMMixin(object):
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
self.skipTest('pulseaudio-utils not installed in VM') self.skipTest('pulseaudio-utils not installed in VM')
self.loop.run_until_complete( self.wait_for_pulseaudio_startup(self.testvm1)
self.wait_for_session(self.testvm1))
# and some more...
self.loop.run_until_complete(asyncio.sleep(1))
# connect VM's recording source output monitor (instead of mic) # connect VM's recording source output monitor (instead of mic)
self._configure_audio_recording(self.testvm1) self._configure_audio_recording(self.testvm1)
@ -924,10 +937,7 @@ class TC_00_AppVMMixin(object):
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
self.skipTest('pulseaudio-utils not installed in VM') self.skipTest('pulseaudio-utils not installed in VM')
self.loop.run_until_complete( self.wait_for_pulseaudio_startup(self.testvm1)
self.wait_for_session(self.testvm1))
# and some more...
self.loop.run_until_complete(asyncio.sleep(1))
da = qubes.devices.DeviceAssignment(self.app.domains[0], 'mic') da = qubes.devices.DeviceAssignment(self.app.domains[0], 'mic')
self.loop.run_until_complete( self.loop.run_until_complete(
self.testvm1.devices['mic'].attach(da)) self.testvm1.devices['mic'].attach(da))
@ -954,7 +964,11 @@ class TC_00_AppVMMixin(object):
self.testvm1.run_for_stdio('cat audio_rec.raw')) self.testvm1.run_for_stdio('cat audio_rec.raw'))
# allow few bytes to be missing # allow few bytes to be missing
if audio_in[:-8] not in recorded_audio: if audio_in[:-8] not in recorded_audio:
self.fail('VM not recorded expected data') found_bytes = recorded_audio.count(audio_in[0])
all_bytes = len(audio_in)
self.fail('VM not recorded expected data, '
'missing {} bytes out of {}'.format(
all_bytes-found_bytes, all_bytes))
def test_250_resize_private_img(self): def test_250_resize_private_img(self):
""" """