From cbc5dbb9b154ceadf8bd1ed86c3c1f15c668a687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Mon, 2 Oct 2017 18:26:18 +0200 Subject: [PATCH] tests: various fixes - Use proper features/services names (updates proxy test). - Fix logic error in wait_for_window. - Fix test for qvm-sync-clock (first sync clockvm, then dom0), also fix cleanup (unset clockvm before removing it) - More fixes for asyncio usage --- qubes/tests/__init__.py | 2 +- qubes/tests/integ/network.py | 8 ++++---- qubes/tests/integ/vm_qrexec_gui.py | 21 ++++++++++++--------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/qubes/tests/__init__.py b/qubes/tests/__init__.py index 2be9b220..77f4f63a 100644 --- a/qubes/tests/__init__.py +++ b/qubes/tests/__init__.py @@ -939,7 +939,7 @@ class SystemTestCase(QubesTestCase): wait_count = 0 while subprocess.call(['xdotool', 'search', '--name', title], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) \ - == int(show): + == int(not show): wait_count += 1 if wait_count > timeout*10: self.fail("Timeout while waiting for {} window to {}".format( diff --git a/qubes/tests/integ/network.py b/qubes/tests/integ/network.py index 985eb434..7f4f01bf 100644 --- a/qubes/tests/integ/network.py +++ b/qubes/tests/integ/network.py @@ -899,10 +899,9 @@ SHA256: self.netvm_repo.provides_network = True self.loop.run_until_complete(self.netvm_repo.create_on_disk()) self.testvm1.netvm = self.netvm_repo - # NetVM should have qubes-updates-proxy enabled by default - #self.netvm_repo.features['qubes-updates-proxy'] = True + self.netvm_repo.features['service.qubes-updates-proxy'] = True # TODO: consider also adding a test for the template itself - self.testvm1.features['updates-proxy-setup'] = True + self.testvm1.features['service.updates-proxy-setup'] = True self.app.save() # Setup test repo @@ -915,7 +914,8 @@ SHA256: # update repository metadata p = self.loop.run_until_complete(self.testvm1.run( - self.update_cmd, user='root')) + self.update_cmd, user='root', stdout=subprocess.PIPE, + stderr=subprocess.PIPE)) (stdout, stderr) = self.loop.run_until_complete(p.communicate()) self.assertIn(self.loop.run_until_complete(p.wait()), self.exit_code_ok, '{}: {}\n{}'.format(self.update_cmd, stdout, stderr)) diff --git a/qubes/tests/integ/vm_qrexec_gui.py b/qubes/tests/integ/vm_qrexec_gui.py index f8863ad3..492aa61b 100644 --- a/qubes/tests/integ/vm_qrexec_gui.py +++ b/qubes/tests/integ/vm_qrexec_gui.py @@ -751,15 +751,15 @@ class TC_00_AppVMMixin(object): self.testvm1.run_for_stdio('date -s 2001-01-01T12:34:56', user='root')) + self.loop.run_until_complete( + self.testvm1.run_for_stdio('qvm-sync-clock', + user='root')) + p = self.loop.run_until_complete( asyncio.create_subprocess_exec('sudo', 'qvm-sync-clock', stdout=asyncio.subprocess.DEVNULL)) self.loop.run_until_complete(p.wait()) self.assertEqual(p.returncode, 0) - self.loop.run_until_complete( - self.testvm1.run_for_stdio('qvm-sync-clock', - user='root')) - vm_time, _ = self.loop.run_until_complete( self.testvm1.run_for_stdio('date -u +%s')) self.assertAlmostEquals(int(vm_time), int(start_time), delta=30) @@ -772,6 +772,8 @@ class TC_00_AppVMMixin(object): subprocess.Popen( ["sudo", "date", "-u", "-s", "@" + start_time.decode()]) raise + finally: + self.app.clockvm = None @unittest.expectedFailure def test_250_resize_private_img(self): @@ -894,12 +896,13 @@ int main(int argc, char **argv) { 'ulimit -l unlimited; exec /home/user/allocator {}'.format( memory_pages), user="root", - stdin=subprocess.PIPE, stdout=subprocess.PIPE) + stdin=subprocess.PIPE, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) # wait for memory being allocated; can't use just .read(), because EOF # passing is unreliable while the process is still running - yield from alloc1.stdin.write(b'\n') - yield from alloc1.stdin.flush() + alloc1.stdin.write(b'\n') + yield from alloc1.stdin.drain() alloc_out = yield from alloc1.stdout.read( len('Stage1\nStage2\nStage3\n')) @@ -931,8 +934,8 @@ int main(int argc, char **argv) { vm_winid = xprop.decode().strip().split(' ')[4] # now free the fragmented memory and trigger compaction - yield from alloc1.stdin.write(b'\n') - yield from alloc1.stdin.flush() + alloc1.stdin.write(b'\n') + yield from alloc1.stdin.drain() yield from alloc1.wait() yield from self.testvm1.run_for_stdio( 'echo 1 > /proc/sys/vm/compact_memory', user='root')