tests: use improved wait_for_window in various tests

Replace manual `xdotool search calls` with wait_for_window(), where
compatible.
This commit is contained in:
Marek Marczykowski-Górecki 2018-10-15 05:16:29 +02:00
parent f1621c01e9
commit 9e81087b25
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 27 additions and 77 deletions

View File

@ -255,34 +255,26 @@ class TC_20_DispVMMixin(object):
p = self.loop.run_until_complete( p = self.loop.run_until_complete(
self.testvm1.run("qvm-open-in-dvm /home/user/test.txt")) self.testvm1.run("qvm-open-in-dvm /home/user/test.txt"))
wait_count = 0 # if first 5 windows isn't expected editor, there is no hope
winid = None winid = None
while True: for _ in range(5):
search = self.loop.run_until_complete( winid = self.wait_for_window('disp[0-9]*', search_class=True)
asyncio.create_subprocess_exec( # get window title
'xdotool', 'search', '--onlyvisible', '--class', (window_title, _) = subprocess.Popen(
'disp[0-9]*', ['xdotool', 'getwindowname', winid], stdout=subprocess.PIPE). \
stdout=subprocess.PIPE, communicate()
stderr=subprocess.DEVNULL)) window_title = window_title.decode().strip()
stdout, _ = self.loop.run_until_complete(search.communicate()) # ignore LibreOffice splash screen and window with no title
if search.returncode == 0: # set yet
winid = stdout.strip() if window_title and not window_title.startswith("LibreOffice")\
# get window title and not window_title == 'VMapp command' \
(window_title, _) = subprocess.Popen( and 'whonixcheck' not in window_title \
['xdotool', 'getwindowname', winid], stdout=subprocess.PIPE). \ and not window_title == 'NetworkManager Applet':
communicate() break
window_title = window_title.decode().strip() self.loop.run_until_complete(asyncio.sleep(1))
# ignore LibreOffice splash screen and window with no title winid = None
# set yet if winid is None:
if window_title and not window_title.startswith("LibreOffice")\ self.fail('Timeout waiting for editor window')
and not window_title == 'VMapp command' \
and 'whonixcheck' not in window_title \
and not window_title == 'NetworkManager Applet':
break
wait_count += 1
if wait_count > 100:
self.fail("Timeout while waiting for editor window")
self.loop.run_until_complete(asyncio.sleep(0.3))
time.sleep(0.5) time.sleep(0.5)
self._handle_editor(winid) self._handle_editor(winid)

View File

@ -76,32 +76,17 @@ class TC_00_AppVMMixin(object):
self.loop.run_until_complete(self.wait_for_session(self.testvm1)) self.loop.run_until_complete(self.wait_for_session(self.testvm1))
p = self.loop.run_until_complete(self.testvm1.run('xterm')) p = self.loop.run_until_complete(self.testvm1.run('xterm'))
try: try:
wait_count = 0
title = 'user@{}'.format(self.testvm1.name) title = 'user@{}'.format(self.testvm1.name)
if self.template.count("whonix"): if self.template.count("whonix"):
title = 'user@host' title = 'user@host'
while subprocess.call( self.wait_for_window(title)
['xdotool', 'search', '--name', title],
stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) > 0:
wait_count += 1
if wait_count > 100:
self.fail("Timeout while waiting for xterm window")
self.loop.run_until_complete(asyncio.sleep(0.1))
self.loop.run_until_complete(asyncio.sleep(0.5)) self.loop.run_until_complete(asyncio.sleep(0.5))
subprocess.check_call( subprocess.check_call(
['xdotool', 'search', '--name', title, ['xdotool', 'search', '--name', title,
'windowactivate', 'type', 'exit\n']) 'windowactivate', 'type', 'exit\n'])
wait_count = 0 self.wait_for_window(title, show=False)
while subprocess.call(['xdotool', 'search', '--name', title],
stdout=open(os.path.devnull, 'w'),
stderr=subprocess.STDOUT) == 0:
wait_count += 1
if wait_count > 100:
self.fail("Timeout while waiting for xterm "
"termination")
self.loop.run_until_complete(asyncio.sleep(0.1))
finally: finally:
try: try:
p.terminate() p.terminate()
@ -124,15 +109,7 @@ class TC_00_AppVMMixin(object):
title = 'user@{}'.format(self.testvm1.name) title = 'user@{}'.format(self.testvm1.name)
if self.template.count("whonix"): if self.template.count("whonix"):
title = 'user@host' title = 'user@host'
wait_count = 0 self.wait_for_window(title)
while subprocess.call(
['xdotool', 'search', '--name', title],
stdout=open(os.path.devnull, 'w'),
stderr=subprocess.STDOUT) > 0:
wait_count += 1
if wait_count > 100:
self.fail("Timeout while waiting for gnome-terminal window")
self.loop.run_until_complete(asyncio.sleep(0.1))
self.loop.run_until_complete(asyncio.sleep(0.5)) self.loop.run_until_complete(asyncio.sleep(0.5))
subprocess.check_call( subprocess.check_call(
@ -178,30 +155,14 @@ class TC_00_AppVMMixin(object):
title = 'user@{}'.format(self.testvm1.name) title = 'user@{}'.format(self.testvm1.name)
if self.template.count("whonix"): if self.template.count("whonix"):
title = 'user@host' title = 'user@host'
wait_count = 0 self.wait_for_window(title)
while subprocess.call(
['xdotool', 'search', '--name', title],
stdout=open(os.path.devnull, 'w'),
stderr=subprocess.STDOUT) > 0:
wait_count += 1
if wait_count > 100:
self.fail("Timeout while waiting for xterm window")
self.loop.run_until_complete(asyncio.sleep(0.1))
self.loop.run_until_complete(asyncio.sleep(0.5)) self.loop.run_until_complete(asyncio.sleep(0.5))
subprocess.check_call( subprocess.check_call(
['xdotool', 'search', '--name', title, ['xdotool', 'search', '--name', title,
'windowactivate', '--sync', 'type', 'exit\n']) 'windowactivate', '--sync', 'type', 'exit\n'])
wait_count = 0 self.wait_for_window(title, show=False)
while subprocess.call(['xdotool', 'search', '--name', title],
stdout=open(os.path.devnull, 'w'),
stderr=subprocess.STDOUT) == 0:
wait_count += 1
if wait_count > 100:
self.fail("Timeout while waiting for xterm "
"termination")
self.loop.run_until_complete(asyncio.sleep(0.1))
def test_050_qrexec_simple_eof(self): def test_050_qrexec_simple_eof(self):
"""Test for data and EOF transmission dom0->VM""" """Test for data and EOF transmission dom0->VM"""
@ -1111,15 +1072,12 @@ int main(int argc, char **argv) {
proc = yield from self.testvm1.run( proc = yield from self.testvm1.run(
'xterm -maximized -e top') 'xterm -maximized -e top')
# help xdotool a little...
yield from asyncio.sleep(2)
if proc.returncode is not None: if proc.returncode is not None:
self.fail('xterm failed to start') self.fail('xterm failed to start')
# get window ID # get window ID
winid = (yield from asyncio.get_event_loop().run_in_executor(None, winid = yield from self.wait_for_window_coro(
subprocess.check_output, self.testvm1.name + ':xterm',
['xdotool', 'search', '--sync', '--onlyvisible', '--class', search_class=True)
self.testvm1.name + ':xterm'])).decode()
xprop = yield from asyncio.get_event_loop().run_in_executor(None, xprop = yield from asyncio.get_event_loop().run_in_executor(None,
subprocess.check_output, subprocess.check_output,
['xprop', '-notype', '-id', winid, '_QUBES_VMWINDOWID']) ['xprop', '-notype', '-id', winid, '_QUBES_VMWINDOWID'])