8c1f01916d8a82a181cd48146c8eb33be60014ce
4 * python main.py --functional-test 1 --functional-ref
5 * python main.py --functional-test 2 --functional-ref
6 * M-x fla-unset-fun-test'''
8 from os
import getcwd
, system
9 from logging
import debug
, info
10 from pathlib
import Path
11 from shutil
import rmtree
12 from os
import makedirs
13 from os
.path
import join
, exists
16 from panda3d
.core
import Filename
17 from direct
.gui
.OnscreenText
import OnscreenText
18 from lib
.gameobject
import GameObject
19 from lib
.build
.build
import _branch
22 class FunctionalTest(GameObject
):
28 def __init__(self
, idx
, ref
):
30 self
.txt
= OnscreenText('', fg
=(1, 0, 0, 1), scale
=.16)
32 #if self.eng.is_appimage:
33 self
._path
= str(Filename().get_user_appdata_directory())
34 self
._path
+= '/pmachines/'
35 self
._path
+= 'tests/functional%s/' % ('_ref' if ref
else '')
36 home
= '/home/flavio' # we must force this for wine
37 # if self._path.startswith('/c/users/') and exists(str(Path.home()) + '/.local/share/flatpak-wine601/default/'):
38 # self._path = str(Path.home()) + '/.local/share/flatpak-wine601/default/drive_' + self._path[1:]
39 if self
._path
.startswith('/c/users/') and exists(home
+ '/.wine/'):
40 self
._path
= home
+ '/.wine/drive_' + self
._path
[1:]
43 Filename().get_user_appdata_directory(),
44 'pmachines/tests/functional_ref_%s/' % _branch())
47 rmtree(self
._path
, ignore_errors
=True)
48 info('creating dir: %s' % self
._path
)
49 makedirs(self
._path
, exist_ok
=True)
53 #self.eng.attach_obs(self.on_frame_unpausable)
54 taskMgr
.add(self
.on_frame_unpausable
, 'on-frame-unpausable')
55 self
._do
_screenshots
(idx
)
57 def _do_screenshot(self
, path
=None):
58 time
= datetime
.datetime
.now().strftime('%y%m%d%H%M%S')
59 #res = base.win.save_screenshot(Filename(path or ("yocto%s.png" % time)))
60 #debug('screenshot %s (%s)' % (path or ("yocto%s.png" % time), res))
61 res
= base
.screenshot(path
or ("pmachines%s.png" % time
), False)
62 info('screenshot %s (%s; %s)' % (path
or ("pmachines%s.png" % time
), res
, getcwd()))
64 def _screenshot(self
, time
, name
):
65 self
._fnames
+= [self
._path
+ name
+ '.png']
67 self
._curr
_time
+ time
,
68 lambda: self
._do
_screenshot
(self
._path
+ name
+ '.png'),
69 'screenshot: %s' % name
)]
71 self
.txt
['text'] = name
72 (self
.txt
.show
if show_hide
else self
.txt
.hide
)()
74 self
._curr
_time
+ time
+ .1,
76 'screenshot: %s (show)' % name
)]
78 self
._curr
_time
+ time
+ FunctionalTest
.evt_time
- .1,
80 'screenshot: %s (hide)' % name
)]
81 self
._curr
_time
+= time
83 def __keypress(self
, key
):
84 '''Emulates a keypress'''
85 dev
= base
.win
.getInputDevice(0)
89 def __char_entered(self
, char
):
90 '''Emulates a character being entered.'''
91 dev
= base
.win
.getInputDevice(0)
92 dev
.keystroke(ord(char
))
94 def __mouse_click(self
, pos
, btn
):
95 center
= base
.pipe
.get_display_width() / 2, base
.pipe
.get_display_height() / 2
96 tgt
= pos
[0] + center
[0], pos
[1] + center
[1]
97 btn
= 3 if btn
== 'right' else 1
98 system('xdotool mousemove %s %s click %s' % (tgt
[0], tgt
[1], btn
))
100 def __mouse_move(self
, pos
):
101 center
= base
.pipe
.get_display_width() / 2, base
.pipe
.get_display_height() / 2
102 tgt
= pos
[0] + center
[0], pos
[1] + center
[1]
103 system('xdotool mousemove %s %s' % tgt
)
105 def __mouse_drag(self
, start
, end
, btn
):
106 center
= base
.pipe
.get_display_width() / 2, base
.pipe
.get_display_height() / 2
107 start
= start
[0] + center
[0], start
[1] + center
[1]
108 end
= end
[0] + center
[0], end
[1] + center
[1]
109 btn
= 3 if btn
== 'right' else 1
110 system('xdotool mousemove %s %s mousedown %s mousemove %s %s mouseup %s' % (
111 start
[0], start
[1], btn
, end
[0], end
[1], btn
))
113 def _event(self
, time
, evt
, messenger_evt
=False, append_up
=True, mouse_args
=None):
114 def _append_up(evt_name
):
115 return evt
+ ('' if evt
.endswith('-up') or not append_up
else '-up')
116 def cback_char(_evt
):
117 self
.__char
_entered
(_evt
)
118 def cback_keyp(_evt
):
119 self
.__keypress
(_evt
)
120 self
.__keypress
('raw-' + _evt
)
121 cback
= lambda: (cback_char(evt
) if len(evt
) == 1 else cback_keyp(evt
))
122 if evt
in ['mousemove', 'mouseclick', 'mousedrag']:
123 if evt
== 'mousemove':
124 cback
= lambda: self
.__mouse
_move
(*mouse_args
)
125 elif evt
== 'mouseclick':
126 cback
= lambda: self
.__mouse
_click
(*mouse_args
)
127 elif evt
== 'mousedrag':
128 cback
= lambda: self
.__mouse
_drag
(*mouse_args
)
130 cback
= lambda: messenger
.send(_append_up(evt
))
132 self
._curr
_time
+ time
,
136 self
.txt
['text'] = evt
137 (self
.txt
.show
if show_hide
else self
.txt
.hide
)()
139 self
._curr
_time
+ time
+ .2,
141 'event: %s (show)' % evt
)]
143 self
._curr
_time
+ time
+ .8,
145 'event: %s (hide)' % evt
)]
146 self
._curr
_time
+= time
150 files
= glob(self
._path
+ '*')
151 for fname
in self
._fnames
:
152 info('verifying %s' % fname
)
166 def on_frame_unpausable(self
, task
):
167 for tsk
in self
._tasks
:
168 #if self._prev_time <= tsk[0] < self.eng.event.unpaused_time:
169 if self
._prev
_time
<= tsk
[0] < globalClock
.getFrameTime():
170 debug('%s %s' % (tsk
[0], tsk
[2]))
172 self
._prev
_time
= globalClock
.getFrameTime() # self.eng.event.unpaused_time
175 def _do_screenshots_1(self
):
176 info('_do_screenshots_1')
177 self
._screenshot
(FunctionalTest
.start_time
, 'main_menu')
178 self
._do
_screenshots
_credits
()
179 # self._do_screenshots_options()
180 self
._do
_screenshots
_exit
()
182 def _do_screenshots_credits(self
):
183 self
._event
(FunctionalTest
.evt_time
, 'mouseclick', False, False, [(0, 50), 'left'])
184 self
._screenshot
(FunctionalTest
.screenshot_time
, 'credits_menu')
185 self
._event
(FunctionalTest
.evt_time
, 'mouseclick', False, False, [(0, 280), 'left'])
186 self
._screenshot
(FunctionalTest
.screenshot_time
, 'main_menu_back_from_credits')
188 # self._event(FunctionalTest.evt_time, 'joypad0-dpad_down', True)
189 # self._event(FunctionalTest.evt_time, 'arrow_down')
190 # self._event(FunctionalTest.evt_time, 'joypad0-dpad_down', True)
191 # self._event(FunctionalTest.evt_time, 'arrow_down')
192 # self._screenshot(FunctionalTest.screenshot_time, 'main_menu_highlight')
193 # self._event(FunctionalTest.evt_time, 'rcontrol')
194 # self._screenshot(FunctionalTest.screenshot_time, 'credits_menu')
196 # self._event(FunctionalTest.evt_time, 'joypad0-face_a', True)
197 # self._screenshot(FunctionalTest.screenshot_time, 'supporters_menu')
199 # self._event(FunctionalTest.evt_time, 'rcontrol')
200 # self._event(FunctionalTest.evt_time, 'joypad0-face_b', True)
201 # self._event(FunctionalTest.evt_time, 'arrow_up')
202 # self._event(FunctionalTest.evt_time, 'arrow_up')
203 # self._event(FunctionalTest.evt_time, 'arrow_up')
204 # self._event(FunctionalTest.evt_time, 'arrow_up')
206 # def _do_screenshots_options(self):
208 # self._event(FunctionalTest.evt_time, 'arrow_down')
209 # self._event(FunctionalTest.evt_time, 'arrow_down')
210 # self._event(FunctionalTest.evt_time, 'rcontrol')
211 # self._screenshot(FunctionalTest.screenshot_time, 'options_menu')
213 # self._event(FunctionalTest.evt_time, 'rcontrol')
214 # self._screenshot(FunctionalTest.screenshot_time, 'language_open')
215 # self._event(FunctionalTest.evt_time, 'arrow_down')
216 # self._screenshot(FunctionalTest.screenshot_time, 'language_highlight')
217 # self._event(FunctionalTest.evt_time, 'rcontrol')
218 # self._screenshot(FunctionalTest.screenshot_time, 'language_it')
220 # self._event(FunctionalTest.evt_time, 'arrow_down')
221 # self._event(FunctionalTest.evt_time, 'arrow_right')
222 # self._event(FunctionalTest.evt_time, 'arrow_right')
223 # self._screenshot(FunctionalTest.screenshot_time, 'volume')
225 # self._event(FunctionalTest.evt_time, 'arrow_down')
226 # self._event(FunctionalTest.evt_time, 'rcontrol')
227 # self._screenshot(FunctionalTest.screenshot_time, 'cars_open')
228 # self._event(FunctionalTest.evt_time, 'rcontrol')
229 # self._screenshot(FunctionalTest.screenshot_time, 'cars_changed')
231 # self._event(FunctionalTest.evt_time, 'arrow_down')
232 # self._event(FunctionalTest.evt_time, 'arrow_down')
233 # self._event(FunctionalTest.evt_time, 'arrow_down')
234 # self._event(FunctionalTest.evt_time, 'rcontrol')
235 # self._event(FunctionalTest.evt_time, 'arrow_up')
236 # self._event(FunctionalTest.evt_time, 'arrow_up')
238 def _do_screenshots_exit(self
):
239 # self._event(FunctionalTest.evt_time, 'arrow_down')
240 # self._event(FunctionalTest.evt_time, 'arrow_down')
241 # self._event(FunctionalTest.evt_time, 'arrow_down')
242 # self._event(FunctionalTest.evt_time, 'arrow_down')
243 # self._event(FunctionalTest.evt_time, 'arrow_down')
244 # self._event(FunctionalTest.evt_time, 'rcontrol')
245 # self._event(FunctionalTest.evt_time, 'arrow_down')
247 # self._event(FunctionalTest.evt_time, 'rcontrol')
249 self
._event
(FunctionalTest
.evt_time
, 'mouseclick', False, False, [(0, 200), 'left'])
252 def _do_screenshots_2(self
):
253 info('_do_screenshots_2')
254 # self._do_screenshots_restore_options()
255 # self._do_screenshots_game()
256 # self._do_screenshots_end()
258 # def _do_screenshots_restore_options(self):
260 # self._event(FunctionalTest.evt_time, 'joypad0-dpad_down', True)
261 # self._event(FunctionalTest.evt_time, 'arrow_down')
262 # self._event(FunctionalTest.evt_time, 'rcontrol')
263 # self._screenshot(FunctionalTest.screenshot_time, 'options_menu_restored')
265 # self._event(FunctionalTest.evt_time, 'rcontrol')
266 # self._event(FunctionalTest.evt_time, 'arrow_up')
267 # self._event(FunctionalTest.evt_time, 'rcontrol')
268 # self._screenshot(FunctionalTest.screenshot_time, 'language_en_restored')
270 # self._event(FunctionalTest.evt_time, 'arrow_down')
271 # self._event(FunctionalTest.evt_time, 'arrow_left')
272 # self._event(FunctionalTest.evt_time, 'arrow_left')
273 # self._screenshot(FunctionalTest.screenshot_time, 'volume_restored')
275 # self._event(FunctionalTest.evt_time, 'arrow_down')
276 # self._event(FunctionalTest.evt_time, 'rcontrol')
277 # self._event(FunctionalTest.evt_time, 'arrow_down')
278 # self._event(FunctionalTest.evt_time, 'arrow_down')
279 # self._event(FunctionalTest.evt_time, 'arrow_down')
280 # self._event(FunctionalTest.evt_time, 'arrow_down')
281 # self._event(FunctionalTest.evt_time, 'rcontrol')
282 # self._screenshot(FunctionalTest.screenshot_time, 'cars_restored')
283 # # graphics settings
284 # self._event(FunctionalTest.evt_time, 'arrow_down')
285 # self._event(FunctionalTest.evt_time, 'rcontrol')
286 # self._screenshot(FunctionalTest.screenshot_time, 'graphics_settings')
287 # self._event(FunctionalTest.evt_time, 'arrow_down')
288 # self._event(FunctionalTest.evt_time, 'arrow_down')
289 # self._event(FunctionalTest.evt_time, 'rcontrol')
290 # self._screenshot(FunctionalTest.screenshot_time, 'antialiasing')
291 # self._event(FunctionalTest.evt_time, 'rcontrol')
292 # self._event(FunctionalTest.evt_time, 'arrow_down')
293 # self._event(FunctionalTest.evt_time, 'rcontrol')
294 # self._screenshot(FunctionalTest.screenshot_time, 'shadows')
295 # self._event(FunctionalTest.evt_time, 'rcontrol')
296 # self._event(FunctionalTest.evt_time, 'arrow_down')
297 # self._event(FunctionalTest.evt_time, 'rcontrol')
298 # self._screenshot(FunctionalTest.screenshot_time, 'fog')
299 # self._event(FunctionalTest.evt_time, 'rcontrol')
300 # self._event(FunctionalTest.evt_time, 'arrow_down')
301 # self._event(FunctionalTest.evt_time, 'rcontrol')
302 # self._screenshot(FunctionalTest.screenshot_time, 'normal_mapping')
303 # self._event(FunctionalTest.evt_time, 'rcontrol')
304 # self._event(FunctionalTest.evt_time, 'arrow_down')
305 # self._event(FunctionalTest.evt_time, 'rcontrol')
306 # self._screenshot(FunctionalTest.screenshot_time, 'occlusion')
307 # self._event(FunctionalTest.evt_time, 'rcontrol')
308 # self._event(FunctionalTest.evt_time, 'arrow_down')
309 # self._event(FunctionalTest.evt_time, 'rcontrol')
311 # self._event(FunctionalTest.evt_time, 'arrow_down')
312 # self._event(FunctionalTest.evt_time, 'rcontrol')
313 # self._screenshot(FunctionalTest.screenshot_time, 'input')
314 # self._event(FunctionalTest.evt_time, 'rcontrol')
315 # self._screenshot(FunctionalTest.screenshot_time, 'keyboard_p1')
316 # self._event(FunctionalTest.evt_time, 'rcontrol')
317 # self._screenshot(FunctionalTest.screenshot_time, 'keyboard_p1_rec')
318 # self._event(FunctionalTest.evt_time, '8', True, False)
319 # self._screenshot(FunctionalTest.screenshot_time, 'keyboard_p1_changed')
320 # self._event(FunctionalTest.evt_time, 'rcontrol')
321 # self._event(FunctionalTest.evt_time, 'arrow_up', True, False)
322 # self._screenshot(FunctionalTest.screenshot_time, 'keyboard_p1_restored')
323 # self._event(FunctionalTest.evt_time, 'rcontrol')
324 # self._event(FunctionalTest.evt_time, 'w', True, False)
325 # self._screenshot(FunctionalTest.screenshot_time, 'keyboard_p1_already')
326 # self._event(FunctionalTest.evt_time, 'rcontrol')
327 # self._screenshot(FunctionalTest.screenshot_time, 'keyboard_p1_already_closed')
328 # self._event(FunctionalTest.evt_time, 'arrow_down')
329 # self._event(FunctionalTest.evt_time, 'arrow_down')
330 # self._event(FunctionalTest.evt_time, 'arrow_down')
331 # self._event(FunctionalTest.evt_time, 'arrow_down')
332 # self._event(FunctionalTest.evt_time, 'rcontrol')
333 # self._screenshot(FunctionalTest.screenshot_time, 'keyboard_p2')
334 # self._event(FunctionalTest.evt_time, 'arrow_down')
335 # self._event(FunctionalTest.evt_time, 'arrow_down')
336 # self._event(FunctionalTest.evt_time, 'arrow_down')
337 # self._event(FunctionalTest.evt_time, 'arrow_down')
338 # self._event(FunctionalTest.evt_time, 'rcontrol')
339 # self._screenshot(FunctionalTest.screenshot_time, 'keyboard_p3')
340 # self._event(FunctionalTest.evt_time, 'arrow_down')
341 # self._event(FunctionalTest.evt_time, 'arrow_down')
342 # self._event(FunctionalTest.evt_time, 'arrow_down')
343 # self._event(FunctionalTest.evt_time, 'arrow_down')
344 # self._event(FunctionalTest.evt_time, 'rcontrol')
345 # self._screenshot(FunctionalTest.screenshot_time, 'keyboard_p4')
346 # self._event(FunctionalTest.evt_time, 'arrow_down')
347 # self._event(FunctionalTest.evt_time, 'arrow_down')
348 # self._event(FunctionalTest.evt_time, 'arrow_down')
349 # self._event(FunctionalTest.evt_time, 'arrow_down')
350 # self._event(FunctionalTest.evt_time, 'rcontrol')
351 # self._event(FunctionalTest.evt_time, 'arrow_down')
352 # self._event(FunctionalTest.evt_time, 'rcontrol')
353 # self._event(FunctionalTest.evt_time, 'arrow_down')
354 # self._event(FunctionalTest.evt_time, 'rcontrol')
355 # self._event(FunctionalTest.evt_time, 'arrow_down')
356 # self._event(FunctionalTest.evt_time, 'rcontrol')
357 # self._event(FunctionalTest.evt_time, 'arrow_down')
358 # self._event(FunctionalTest.evt_time, 'rcontrol')
359 # self._event(FunctionalTest.evt_time, 'arrow_down')
360 # self._event(FunctionalTest.evt_time, 'rcontrol')
361 # self._event(FunctionalTest.evt_time, 'arrow_up')
362 # self._event(FunctionalTest.evt_time, 'arrow_up')
364 # def _do_screenshots_game(self):
366 # self._event(FunctionalTest.evt_time, 'rcontrol')
367 # self._screenshot(FunctionalTest.screenshot_time, 'single_player_menu')
368 # self._event(FunctionalTest.evt_time, 'rcontrol')
369 # self._screenshot(FunctionalTest.screenshot_time, 'track_page')
370 # self._event(FunctionalTest.evt_time, 'rcontrol')
371 # self._screenshot(FunctionalTest.screenshot_time, 'car_page_start')
372 # self._event(FunctionalTest.evt_time, 'arrow_left')
373 # self._screenshot(FunctionalTest.screenshot_time, 'car_page_sel')
374 # self._event(FunctionalTest.evt_time, 'rcontrol')
375 # self._screenshot(FunctionalTest.screenshot_time, 'driver_page_start')
376 # self._event(FunctionalTest.evt_time, 'arrow_down')
377 # self._event(FunctionalTest.evt_time, 'arrow_down')
378 # self._event(FunctionalTest.evt_time, 'rcontrol')
379 # self._event(FunctionalTest.evt_time, 'arrow_down')
380 # self._event(FunctionalTest.evt_time, 'arrow_down')
381 # self._event(FunctionalTest.evt_time, 'rcontrol')
382 # self._event(FunctionalTest.evt_time, 'arrow_down')
383 # self._event(FunctionalTest.evt_time, 'rcontrol')
384 # self._event(FunctionalTest.evt_time, 'arrow_up')
385 # self._event(FunctionalTest.evt_time, 'rcontrol')
386 # self._event(FunctionalTest.evt_time, 'rcontrol')
387 # self._event(FunctionalTest.evt_time, 'arrow_left')
388 # self._event(FunctionalTest.evt_time, 'rcontrol')
389 # self._event(FunctionalTest.evt_time, 'rcontrol')
390 # self._event(FunctionalTest.evt_time, 'rcontrol')
391 # self._event(FunctionalTest.evt_time, 'rcontrol')
392 # self._event(FunctionalTest.evt_time, 'rcontrol')
393 # self._event(FunctionalTest.evt_time, 'arrow_left')
394 # self._event(FunctionalTest.evt_time, 'rcontrol')
395 # self._event(FunctionalTest.evt_time, 'arrow_up')
396 # self._event(FunctionalTest.evt_time, 'rcontrol')
397 # self._screenshot(FunctionalTest.screenshot_time, 'driver_page_entry')
398 # self._event(FunctionalTest.evt_time, 'backspace')
399 # self._event(FunctionalTest.evt_time, 'backspace')
400 # self._event(FunctionalTest.evt_time, 'backspace')
401 # self._event(FunctionalTest.evt_time, 'backspace')
402 # self._event(FunctionalTest.evt_time, 'backspace')
403 # self._event(FunctionalTest.evt_time, 'backspace')
404 # self._event(FunctionalTest.evt_time, 'backspace')
405 # self._event(FunctionalTest.evt_time, 'backspace')
406 # self._event(FunctionalTest.evt_time, 'backspace')
407 # self._event(FunctionalTest.evt_time, 'backspace')
408 # self._screenshot(FunctionalTest.screenshot_time, 'driver_page_entry_empty')
409 # self._event(FunctionalTest.evt_time, 'f')
410 # self._event(FunctionalTest.evt_time, 'l')
411 # self._event(FunctionalTest.evt_time, 'a')
412 # self._event(FunctionalTest.evt_time, 'v')
413 # self._event(FunctionalTest.evt_time, 'i')
414 # self._event(FunctionalTest.evt_time, 'o')
415 # self._event(FunctionalTest.evt_time, 'enter')
416 # self._screenshot(FunctionalTest.screenshot_time, 'driver_page_entry_full')
417 # self._event(FunctionalTest.evt_time, 'arrow_down')
418 # self._event(FunctionalTest.evt_time, 'arrow_right')
419 # self._screenshot(FunctionalTest.screenshot_time, 'driver_page_sel')
421 # self._event(FunctionalTest.evt_time, 'rcontrol')
422 # self._event(40, 'escape-up')
423 # self._screenshot(FunctionalTest.screenshot_time, 'ingame_menu')
424 # self._event(FunctionalTest.evt_time, 'rcontrol')
425 # self._screenshot(FunctionalTest.screenshot_time, 'race_back')
426 # self._event(FunctionalTest.evt_time, 'escape-up')
427 # self._event(FunctionalTest.evt_time, 'arrow_down')
428 # self._screenshot(FunctionalTest.screenshot_time, 'ingame_sel')
429 # self._event(FunctionalTest.evt_time, 'rcontrol')
430 # self._screenshot(FunctionalTest.screenshot_time, 'main_page_back_race')
432 # def _do_screenshots_end(self):
433 # self._event(FunctionalTest.evt_time, 'arrow_down')
434 # self._event(FunctionalTest.evt_time, 'arrow_down')
435 # self._event(FunctionalTest.evt_time, 'arrow_down')
436 # self._event(FunctionalTest.evt_time, 'arrow_down')
437 # self._event(FunctionalTest.evt_time, 'arrow_down')
438 # self._event(FunctionalTest.evt_time, 'rcontrol')
439 # self._screenshot(FunctionalTest.screenshot_time, 'exit_page')
440 # self._event(FunctionalTest.evt_time, 'arrow_down')
441 # self._screenshot(FunctionalTest.screenshot_time, 'exit_page_sel')
443 # self._event(FunctionalTest.evt_time, 'rcontrol')
446 def _do_screenshots(self
, idx
):
447 [self
._do
_screenshots
_1, self
._do
_screenshots
_2][int(idx
) - 1]()