Merge branch 'test-fixes20200806'

* test-fixes20200806:
  tests/extra: add vm.run(..., gui=) argument
  tests: collect detailed diagnostics on failure
  tests: workaround a race in qrexec test
  tests: fix audio recording test
  tests: make qvm-sync-clock test more reliable
This commit is contained in:
Marek Marczykowski-Górecki 2020-08-12 01:25:27 +02:00
commit 74725b584a
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
5 changed files with 55 additions and 5 deletions

View File

@ -80,7 +80,14 @@ class VMWrapper(object):
return self._loop.run_until_complete(self._vm.shutdown())
def run(self, command, wait=False, user=None, passio_popen=False,
passio_stderr=False, **kwargs):
passio_stderr=False, gui=False, **kwargs):
if gui:
try:
self._loop.run_until_complete(
self._vm.run_service_for_stdio('qubes.WaitForSession',
user=user))
except subprocess.CalledProcessError as err:
return err.returncode
if wait:
try:
self._loop.run_until_complete(

View File

@ -18,7 +18,7 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, see <https://www.gnu.org/licenses/>.
#
import contextlib
from distutils import spawn
import asyncio
@ -87,6 +87,32 @@ class VmNetworkingMixin(object):
self.configure_netvm()
def _run_cmd_and_log_output(self, vm, cmd):
"""Used in tearDown to collect more info"""
if not vm.is_running():
return
with contextlib.suppress(subprocess.CalledProcessError):
output = self.loop.run_until_complete(
self.testnetvm.run_for_stdio(cmd, user='root'))
self.log.error('{}: {}: {}'.format(vm.name, cmd, output))
def tearDown(self):
# collect more info on failure
if self._outcome and not self._outcome.success:
for vm in (self.testnetvm, self.testvm1, getattr(self, 'proxy', None)):
if vm is None:
continue
self._run_cmd_and_log_output(vm, 'ip a')
self._run_cmd_and_log_output(vm, 'ip r')
self._run_cmd_and_log_output(vm, 'iptables -vnL')
self._run_cmd_and_log_output(vm, 'iptables -vnL -t nat')
self._run_cmd_and_log_output(vm, 'nft list table qubes-firewall')
self._run_cmd_and_log_output(vm, 'systemctl --no-pager status qubes-firewall')
self._run_cmd_and_log_output(vm, 'systemctl --no-pager status qubes-iptables')
self._run_cmd_and_log_output(vm, 'systemctl --no-pager status xendriverdomain')
super(VmNetworkingMixin, self).tearDown()
def configure_netvm(self):
'''

View File

@ -43,6 +43,19 @@ class VmIPv6NetworkingMixin(VmNetworkingMixin):
self.ping6_ip = self.ping6_cmd.format(target=self.test_ip6)
self.ping6_name = self.ping6_cmd.format(target=self.test_name)
def tearDown(self):
# collect more info on failure (ipv4 info collected in parent)
if self._outcome and not self._outcome.success:
for vm in (self.testnetvm, self.testvm1, getattr(self, 'proxy', None)):
if vm is None:
continue
self._run_cmd_and_log_output(vm, 'ip -6 r')
self._run_cmd_and_log_output(vm, 'ip6tables -vnL')
self._run_cmd_and_log_output(vm, 'ip6tables -vnL -t nat')
self._run_cmd_and_log_output(vm, 'nft list table ip6 qubes-firewall')
super().tearDown()
def configure_netvm(self):
'''
:type self: qubes.tests.SystemTestCase | VmIPv6NetworkingMixin

View File

@ -201,6 +201,7 @@ class TC_00_QrexecMixin(object):
self.testvm1.run_for_stdio('''\
/usr/lib/qubes/qrexec-client-vm dom0 test.Abort \
/bin/sh -c 'cat /dev/zero; echo $? >/tmp/exit-code';
sleep 1;
e=$(cat /tmp/exit-code);
test $e -eq 141 -o $e -eq 1'''),
timeout=10))

View File

@ -399,10 +399,13 @@ class TC_00_AppVMMixin(object):
self.assertEqual(p.returncode, 0)
vm_time, _ = self.loop.run_until_complete(
self.testvm2.run_for_stdio('date -u +%s'))
self.assertAlmostEquals(int(vm_time), int(start_time), delta=30)
# get current time
current_time, _ = self.loop.run_until_complete(
self.testvm1.run_for_stdio('date -u +%s'))
self.assertAlmostEquals(int(vm_time), int(current_time), delta=30)
dom0_time = subprocess.check_output(['date', '-u', '+%s'])
self.assertAlmostEquals(int(dom0_time), int(start_time), delta=30)
self.assertAlmostEquals(int(dom0_time), int(current_time), delta=30)
except:
# reset time to some approximation of the real time
@ -455,7 +458,7 @@ class TC_00_AppVMMixin(object):
(rec[:-1] < -threshold))[0]
np.seterr('raise')
# compare against sine wave frequency
rec_freq = rec_size/np.mean(np.diff(crossings))
rec_freq = 44100/np.mean(np.diff(crossings))
if not sfreq*0.8 < rec_freq < sfreq*1.2:
self.fail('frequency {} not in specified range'
.format(rec_freq))