/usr/lib/2013.com.canonical.certification:checkbox/bin/window_test is in plainbox-provider-checkbox 0.4-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | #!/usr/bin/python3
# -*- coding: utf-8 -*-
#
# window_test
#
# This file is part of Checkbox.
#
# Copyright 2012 Canonical Ltd.
#
# Authors: Alberto Milone <alberto.milone@canonical.com>
#
# Checkbox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3,
# as published by the Free Software Foundation.
#
# Checkbox is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
import threading
import time
import os
import sys
from signal import SIGTSTP, SIGCONT, SIGTERM
from subprocess import check_call, check_output, Popen, PIPE
from argparse import ArgumentParser
class AppThread(threading.Thread):
def __init__(self, app_name):
self._appname = app_name
self.stdout = None
self.stderr = None
self.pid = None
threading.Thread.__init__(self)
def run(self):
proc = Popen(self._appname, stdout=PIPE, stderr=PIPE)
self.pid = proc.pid
print(' Starting "%s", PID: %d' %
(self._appname, self.pid))
self.stdout, self.stderr = proc.communicate()
def open_close_process(app, timeout):
'''Open and close a process after a timeout'''
status = 0
# Start the process in a separate thread
app_thread = AppThread(app)
app_thread.start()
# Wait until we have a pid
while app_thread.pid is None:
continue
pid = app_thread.pid
# Wait a bit and kill the process
time.sleep(timeout)
print(' Killing "%s", PID: %d' % (app, pid))
os.kill(pid, SIGTERM)
if app_thread.stderr:
print('Errors:\n%s' % app_thread.stderr, file=sys.stderr)
status = 1
time.sleep(timeout)
return status
def open_close_multi_process(app, timeout, apps_num):
'''Open and close multiple processes after a timeout'''
status = 0
threads = []
for thread in range(apps_num):
app_thread = AppThread(app)
app_thread.start()
threads.append(app_thread)
for thread in threads:
# Wait until we have a pid
while thread.pid is None:
continue
# Wait a bit and kill the process
time.sleep(timeout)
for thread in threads:
print(' Killing "%s", PID: %d' % (app, thread.pid))
os.kill(thread.pid, SIGTERM)
if thread.stderr:
print('Errors:\n%s' % thread.stderr, file=sys.stderr)
status = 1
time.sleep(timeout)
return status
def open_suspend_close_process(app, timeout):
'''Open, suspend and close a process after a timeout'''
status = 0
# Start the process in a separate thread
app_thread = AppThread(app)
app_thread.start()
# Wait until we have a pid
while app_thread.pid is None:
continue
pid = app_thread.pid
# Wait a bit and suspend the process
time.sleep(timeout)
print(' Suspending "%s", PID: %d' % (app, pid))
os.kill(pid, SIGTSTP)
# Wait a bit and resume the process
time.sleep(timeout)
print(' Resuming "%s", PID: %d' % (app, pid))
os.kill(pid, SIGCONT)
# Wait a bit and kill the process
time.sleep(timeout)
print(' Killing "%s", PID: %d' % (app, pid))
os.kill(pid, SIGTERM)
if app_thread.stderr:
print('Errors:\n%s' % app_thread.stderr, file=sys.stderr)
status = 1
time.sleep(timeout)
return status
def move_window(app, timeout):
status = 0
# Start the process in a separate thread
app_thread = AppThread(app)
app_thread.start()
while app_thread.pid is None:
continue
pid = app_thread.pid
time.sleep(3)
window_list = check_output(['wmctrl', '-l'], universal_newlines=True)
window_id = ''
for line in window_list.split('\n'):
if app in line:
window_id = line.split()[0]
if window_id:
# Get the screen information from GDK
from gi.repository import Gdk
screen = Gdk.Screen.get_default()
geom = screen.get_monitor_geometry(screen.get_primary_monitor())
# Find out the window information from xwininfo
win_x = ''
win_y = ''
win_width = ''
win_height = ''
for line in check_output(['xwininfo', '-name', app],
universal_newlines=True).split('\n'):
if 'Absolute upper-left X' in line:
win_x = line.split(': ')[-1].strip()
elif 'Absolute upper-left Y' in line:
win_y = line.split(': ')[-1].strip()
elif 'Width' in line:
win_width = line.split(': ')[-1].strip()
elif 'Height' in line:
win_height = line.split(': ')[-1].strip()
move_line = ["0", win_x, win_y, win_width, win_height]
directions = {'RIGHT': geom.width,
'DOWN': geom.height,
'LEFT': win_x,
'UP': win_y,
'STOP': None}
current = 'RIGHT'
while current != 'STOP':
if current == 'RIGHT':
# Check if top right corner of window reached top right point
if int(move_line[1]) + int(win_width) != directions[current]:
new_x = int(move_line[1]) + 1
move_line[1] = str(new_x)
else:
current = 'DOWN'
elif current == 'DOWN':
if int(move_line[2]) + int(win_height) != directions[current]:
new_y = int(move_line[2]) + 1
move_line[2] = str(new_y)
else:
current = 'LEFT'
elif current == 'LEFT':
if int(move_line[1]) != int(directions[current]):
new_x = int(move_line[1]) - 1
move_line[1] = str(new_x)
else:
current = 'UP'
elif current == 'UP':
if int(move_line[2]) != int(directions[current]):
new_y = int(move_line[2]) - 1
move_line[2] = str(new_y)
else:
current = 'STOP'
check_call(['wmctrl', '-i', '-r', window_id,
'-e', ','.join(move_line)])
os.kill(pid, SIGTERM)
else:
print("Could not get window handle for %s" % app, file=sys.stderr)
status = 1
return status
def print_open_close(iterations, timeout, *args):
status = 0
print('Opening and closing a 3D window')
for it in range(iterations):
print('Iteration %d of %d:' % (it + 1, iterations))
exit_status = open_close_process('glxgears', timeout)
if exit_status != 0:
status = 1
print('')
return status
def print_suspend_resume(iterations, timeout, *args):
status = 0
print('Opening, suspending, resuming and closing a 3D window')
for it in range(iterations):
print('Iteration %d of %d:' % (it + 1, iterations))
exit_status = open_suspend_close_process('glxgears', timeout)
if exit_status != 0:
status = 1
print('')
return status
def print_open_close_multi(iterations, timeout, windows_number):
status = 0
print('Opening and closing %d 3D windows at the same time'
% windows_number)
for it in range(iterations):
print('Iteration %d of %d:' % (it + 1, iterations))
exit_status = open_close_multi_process('glxgears',
timeout,
windows_number)
if exit_status != 0:
status = 1
print('')
return status
def print_move_window(iterations, timeout, *args):
status = 0
print('Moving a 3D window across the screen')
for it in range(iterations):
print('Iteration %d of %d:' % (it + 1, iterations))
exit_status = move_window('glxgears',
timeout)
print('')
return status
def main():
tests = {'open-close': print_open_close,
'suspend-resume': print_suspend_resume,
'open-close-multi': print_open_close_multi,
'move': print_move_window}
parser = ArgumentParser(description='Script that performs window operation')
parser.add_argument('-t', '--test',
default='all',
help='The name of the test to run. \
Available tests: \
%s, all. \
Default is all' % (', '.join(tests)))
parser.add_argument('-i', '--iterations',
type=int,
default=1,
help='The number of times to run the test. \
Default is 1')
parser.add_argument('-a', '--application',
default='glxgears',
help='The 3D application to launch. \
Default is "glxgears"')
parser.add_argument('-to', '--timeout',
type=int,
default=3,
help='The time in seconds between each test. \
Default is 3')
parser.add_argument('-w', '--windows-number',
type=int,
default=4,
help='The number of windows to open.')
args = parser.parse_args()
status = 0
test = tests.get(args.test)
if test:
status = test(args.iterations, args.timeout, args.windows_number)
else:
if args.test == 'all':
for test in tests:
exit_status = tests[test](args.iterations, args.timeout,
args.windows_number)
if exit_status != 0:
status = exit_status
else:
parser.error('-t or --test can only be used with one '
'of the following tests: '
'%s, all' % (', '.join(tests)))
return status
if __name__ == '__main__':
exit(main())
|