Skip to content

Commit

Permalink
tests: use improved wait_for_window in various tests
Browse files Browse the repository at this point in the history
Replace manual `xdotool search calls` with wait_for_window(), where
compatible.
  • Loading branch information
marmarek committed Oct 15, 2018
1 parent f1621c0 commit 9e81087
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 77 deletions.
46 changes: 19 additions & 27 deletions qubes/tests/integ/dispvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,34 +255,26 @@ def test_030_edit_file(self):
p = self.loop.run_until_complete(
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
while True:
search = self.loop.run_until_complete(
asyncio.create_subprocess_exec(
'xdotool', 'search', '--onlyvisible', '--class',
'disp[0-9]*',
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL))
stdout, _ = self.loop.run_until_complete(search.communicate())
if search.returncode == 0:
winid = stdout.strip()
# get window title
(window_title, _) = subprocess.Popen(
['xdotool', 'getwindowname', winid], stdout=subprocess.PIPE). \
communicate()
window_title = window_title.decode().strip()
# ignore LibreOffice splash screen and window with no title
# set yet
if window_title and not window_title.startswith("LibreOffice")\
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))
for _ in range(5):
winid = self.wait_for_window('disp[0-9]*', search_class=True)
# get window title
(window_title, _) = subprocess.Popen(
['xdotool', 'getwindowname', winid], stdout=subprocess.PIPE). \
communicate()
window_title = window_title.decode().strip()
# ignore LibreOffice splash screen and window with no title
# set yet
if window_title and not window_title.startswith("LibreOffice")\
and not window_title == 'VMapp command' \
and 'whonixcheck' not in window_title \
and not window_title == 'NetworkManager Applet':
break
self.loop.run_until_complete(asyncio.sleep(1))
winid = None
if winid is None:
self.fail('Timeout waiting for editor window')

time.sleep(0.5)
self._handle_editor(winid)
Expand Down
58 changes: 8 additions & 50 deletions qubes/tests/integ/vm_qrexec_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,32 +76,17 @@ def test_010_run_xterm(self):
self.loop.run_until_complete(self.wait_for_session(self.testvm1))
p = self.loop.run_until_complete(self.testvm1.run('xterm'))
try:
wait_count = 0
title = 'user@{}'.format(self.testvm1.name)
if self.template.count("whonix"):
title = 'user@host'
while subprocess.call(
['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.wait_for_window(title)

self.loop.run_until_complete(asyncio.sleep(0.5))
subprocess.check_call(
['xdotool', 'search', '--name', title,
'windowactivate', 'type', 'exit\n'])

wait_count = 0
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))
self.wait_for_window(title, show=False)
finally:
try:
p.terminate()
Expand All @@ -124,15 +109,7 @@ def test_011_run_gnome_terminal(self):
title = 'user@{}'.format(self.testvm1.name)
if self.template.count("whonix"):
title = 'user@host'
wait_count = 0
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.wait_for_window(title)

self.loop.run_until_complete(asyncio.sleep(0.5))
subprocess.check_call(
Expand Down Expand Up @@ -178,30 +155,14 @@ def test_012_qubes_desktop_run(self):
title = 'user@{}'.format(self.testvm1.name)
if self.template.count("whonix"):
title = 'user@host'
wait_count = 0
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.wait_for_window(title)

self.loop.run_until_complete(asyncio.sleep(0.5))
subprocess.check_call(
['xdotool', 'search', '--name', title,
'windowactivate', '--sync', 'type', 'exit\n'])

wait_count = 0
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))
self.wait_for_window(title, show=False)

def test_050_qrexec_simple_eof(self):
"""Test for data and EOF transmission dom0->VM"""
Expand Down Expand Up @@ -1111,15 +1072,12 @@ def _test_300_bug_1028_gui_memory_pinning(self):
proc = yield from self.testvm1.run(
'xterm -maximized -e top')

# help xdotool a little...
yield from asyncio.sleep(2)
if proc.returncode is not None:
self.fail('xterm failed to start')
# get window ID
winid = (yield from asyncio.get_event_loop().run_in_executor(None,
subprocess.check_output,
['xdotool', 'search', '--sync', '--onlyvisible', '--class',
self.testvm1.name + ':xterm'])).decode()
winid = yield from self.wait_for_window_coro(
self.testvm1.name + ':xterm',
search_class=True)
xprop = yield from asyncio.get_event_loop().run_in_executor(None,
subprocess.check_output,
['xprop', '-notype', '-id', winid, '_QUBES_VMWINDOWID'])
Expand Down

0 comments on commit 9e81087

Please sign in to comment.