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'''
7 from logging
import debug
, info
8 from pathlib
import Path
9 from shutil
import rmtree
10 from os
import makedirs
11 from os
.path
import join
, exists
14 from panda3d
.core
import Filename
15 from direct
.gui
.OnscreenText
import OnscreenText
16 from lib
.gameobject
import GameObject
17 from lib
.build
.build
import _branch
20 class FunctionalTest(GameObject
):
26 def __init__(self
, idx
, ref
):
28 self
.txt
= OnscreenText('', fg
=(1, 0, 0, 1), scale
=.16)
30 #if self.eng.is_appimage:
31 self
._path
= str(Filename().get_user_appdata_directory())
32 self
._path
+= '/yocto_racer/'
33 self
._path
+= 'tests/functional%s/' % ('_ref' if ref
else '')
34 home
= '/home/flavio' # we must force this for wine
35 # if self._path.startswith('/c/users/') and exists(str(Path.home()) + '/.local/share/flatpak-wine601/default/'):
36 # self._path = str(Path.home()) + '/.local/share/flatpak-wine601/default/drive_' + self._path[1:]
37 if self
._path
.startswith('/c/users/') and exists(home
+ '/.wine/'):
38 self
._path
= home
+ '/.wine/drive_' + self
._path
[1:]
41 Filename().get_user_appdata_directory(),
42 'yocto_racer/tests/functional_ref_%s/' % _branch())
45 rmtree(self
._path
, ignore_errors
=True)
46 info('creating dir: %s' % self
._path
)
47 makedirs(self
._path
, exist_ok
=True)
51 self
.eng
.attach_obs(self
.on_frame_unpausable
)
52 self
._do
_screenshots
(idx
)
54 def _screenshot(self
, time
, name
):
55 self
._fnames
+= [self
._path
+ name
+ '.png']
57 self
._curr
_time
+ time
,
58 lambda: self
.eng
.gfx
.gfx_mgr
.screenshot(self
._path
+ name
+ '.png'),
59 'screenshot: %s' % name
)]
61 self
.txt
['text'] = name
62 (self
.txt
.show
if show_hide
else self
.txt
.hide
)()
64 self
._curr
_time
+ time
+ .1,
66 'screenshot: %s (show)' % name
)]
68 self
._curr
_time
+ time
+ FunctionalTest
.evt_time
- .1,
70 'screenshot: %s (hide)' % name
)]
71 self
._curr
_time
+= time
73 def __keypress(self
, key
):
74 '''Emulates a keypress'''
75 dev
= base
.win
.getInputDevice(0)
79 def __char_entered(self
, char
):
80 '''Emulates a character being entered.'''
81 dev
= base
.win
.getInputDevice(0)
82 dev
.keystroke(ord(char
))
84 def _event(self
, time
, evt
, messenger_evt
=False, append_up
=True):
85 def _append_up(evt_name
):
86 return evt
+ ('' if evt
.endswith('-up') or not append_up
else '-up')
88 self
.__char
_entered
(_evt
)
91 self
.__keypress
('raw-' + _evt
)
92 cback
= lambda: (cback_char(evt
) if len(evt
) == 1 else cback_keyp(evt
))
94 cback
= lambda: messenger
.send(_append_up(evt
))
96 self
._curr
_time
+ time
,
100 self
.txt
['text'] = evt
101 (self
.txt
.show
if show_hide
else self
.txt
.hide
)()
103 self
._curr
_time
+ time
+ .2,
105 'event: %s (show)' % evt
)]
107 self
._curr
_time
+ time
+ .8,
109 'event: %s (hide)' % evt
)]
110 self
._curr
_time
+= time
114 files
= glob(self
._path
+ '*')
115 for fname
in self
._fnames
:
116 info('verifying %s' % fname
)
130 def on_frame_unpausable(self
):
131 for tsk
in self
._tasks
:
132 if self
._prev
_time
<= tsk
[0] < self
.eng
.event
.unpaused_time
:
133 debug('%s %s' % (tsk
[0], tsk
[2]))
135 self
._prev
_time
= self
.eng
.event
.unpaused_time
137 def _do_screenshots_1(self
):
138 info('_do_screenshots_1')
139 self
._screenshot
(FunctionalTest
.start_time
, 'main_menu')
140 self
._do
_screenshots
_credits
()
141 self
._do
_screenshots
_options
()
142 self
._do
_screenshots
_exit
()
144 def _do_screenshots_credits(self
):
146 self
._event
(FunctionalTest
.evt_time
, 'joypad0-dpad_down', True)
147 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
148 self
._event
(FunctionalTest
.evt_time
, 'joypad0-dpad_down', True)
149 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
150 self
._screenshot
(FunctionalTest
.screenshot_time
, 'main_menu_highlight')
151 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
152 self
._screenshot
(FunctionalTest
.screenshot_time
, 'credits_menu')
154 self
._event
(FunctionalTest
.evt_time
, 'joypad0-face_a', True)
155 self
._screenshot
(FunctionalTest
.screenshot_time
, 'supporters_menu')
157 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
158 self
._event
(FunctionalTest
.evt_time
, 'joypad0-face_b', True)
159 self
._event
(FunctionalTest
.evt_time
, 'arrow_up')
160 self
._event
(FunctionalTest
.evt_time
, 'arrow_up')
161 self
._event
(FunctionalTest
.evt_time
, 'arrow_up')
162 self
._event
(FunctionalTest
.evt_time
, 'arrow_up')
164 def _do_screenshots_options(self
):
166 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
167 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
168 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
169 self
._screenshot
(FunctionalTest
.screenshot_time
, 'options_menu')
171 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
172 self
._screenshot
(FunctionalTest
.screenshot_time
, 'language_open')
173 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
174 self
._screenshot
(FunctionalTest
.screenshot_time
, 'language_highlight')
175 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
176 self
._screenshot
(FunctionalTest
.screenshot_time
, 'language_it')
178 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
179 self
._event
(FunctionalTest
.evt_time
, 'arrow_right')
180 self
._event
(FunctionalTest
.evt_time
, 'arrow_right')
181 self
._screenshot
(FunctionalTest
.screenshot_time
, 'volume')
183 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
184 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
185 self
._screenshot
(FunctionalTest
.screenshot_time
, 'cars_open')
186 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
187 self
._screenshot
(FunctionalTest
.screenshot_time
, 'cars_changed')
189 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
190 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
191 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
192 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
193 self
._event
(FunctionalTest
.evt_time
, 'arrow_up')
194 self
._event
(FunctionalTest
.evt_time
, 'arrow_up')
196 def _do_screenshots_exit(self
):
197 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
198 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
199 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
200 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
201 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
202 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
203 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
205 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
208 def _do_screenshots_2(self
):
209 info('_do_screenshots_2')
210 self
._do
_screenshots
_restore
_options
()
211 self
._do
_screenshots
_game
()
212 self
._do
_screenshots
_end
()
214 def _do_screenshots_restore_options(self
):
216 self
._event
(FunctionalTest
.evt_time
, 'joypad0-dpad_down', True)
217 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
218 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
219 self
._screenshot
(FunctionalTest
.screenshot_time
, 'options_menu_restored')
221 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
222 self
._event
(FunctionalTest
.evt_time
, 'arrow_up')
223 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
224 self
._screenshot
(FunctionalTest
.screenshot_time
, 'language_en_restored')
226 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
227 self
._event
(FunctionalTest
.evt_time
, 'arrow_left')
228 self
._event
(FunctionalTest
.evt_time
, 'arrow_left')
229 self
._screenshot
(FunctionalTest
.screenshot_time
, 'volume_restored')
231 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
232 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
233 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
234 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
235 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
236 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
237 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
238 self
._screenshot
(FunctionalTest
.screenshot_time
, 'cars_restored')
240 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
241 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
242 self
._screenshot
(FunctionalTest
.screenshot_time
, 'graphics_settings')
243 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
244 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
245 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
246 self
._screenshot
(FunctionalTest
.screenshot_time
, 'antialiasing')
247 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
248 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
249 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
250 self
._screenshot
(FunctionalTest
.screenshot_time
, 'shadows')
251 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
252 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
253 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
254 self
._screenshot
(FunctionalTest
.screenshot_time
, 'fog')
255 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
256 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
257 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
258 self
._screenshot
(FunctionalTest
.screenshot_time
, 'normal_mapping')
259 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
260 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
261 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
262 self
._screenshot
(FunctionalTest
.screenshot_time
, 'occlusion')
263 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
264 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
265 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
267 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
268 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
269 self
._screenshot
(FunctionalTest
.screenshot_time
, 'input')
270 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
271 self
._screenshot
(FunctionalTest
.screenshot_time
, 'keyboard_p1')
272 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
273 self
._screenshot
(FunctionalTest
.screenshot_time
, 'keyboard_p1_rec')
274 self
._event
(FunctionalTest
.evt_time
, '8', True, False)
275 self
._screenshot
(FunctionalTest
.screenshot_time
, 'keyboard_p1_changed')
276 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
277 self
._event
(FunctionalTest
.evt_time
, 'arrow_up', True, False)
278 self
._screenshot
(FunctionalTest
.screenshot_time
, 'keyboard_p1_restored')
279 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
280 self
._event
(FunctionalTest
.evt_time
, 'w', True, False)
281 self
._screenshot
(FunctionalTest
.screenshot_time
, 'keyboard_p1_already')
282 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
283 self
._screenshot
(FunctionalTest
.screenshot_time
, 'keyboard_p1_already_closed')
284 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
285 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
286 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
287 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
288 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
289 self
._screenshot
(FunctionalTest
.screenshot_time
, 'keyboard_p2')
290 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
291 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
292 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
293 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
294 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
295 self
._screenshot
(FunctionalTest
.screenshot_time
, 'keyboard_p3')
296 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
297 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
298 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
299 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
300 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
301 self
._screenshot
(FunctionalTest
.screenshot_time
, 'keyboard_p4')
302 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
303 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
304 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
305 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
306 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
307 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
308 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
309 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
310 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
311 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
312 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
313 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
314 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
315 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
316 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
317 self
._event
(FunctionalTest
.evt_time
, 'arrow_up')
318 self
._event
(FunctionalTest
.evt_time
, 'arrow_up')
320 def _do_screenshots_game(self
):
322 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
323 self
._screenshot
(FunctionalTest
.screenshot_time
, 'single_player_menu')
324 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
325 self
._screenshot
(FunctionalTest
.screenshot_time
, 'track_page')
326 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
327 self
._screenshot
(FunctionalTest
.screenshot_time
, 'car_page_start')
328 self
._event
(FunctionalTest
.evt_time
, 'arrow_left')
329 self
._screenshot
(FunctionalTest
.screenshot_time
, 'car_page_sel')
330 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
331 self
._screenshot
(FunctionalTest
.screenshot_time
, 'driver_page_start')
332 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
333 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
334 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
335 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
336 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
337 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
338 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
339 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
340 self
._event
(FunctionalTest
.evt_time
, 'arrow_up')
341 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
342 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
343 self
._event
(FunctionalTest
.evt_time
, 'arrow_left')
344 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
345 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
346 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
347 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
348 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
349 self
._event
(FunctionalTest
.evt_time
, 'arrow_left')
350 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
351 self
._event
(FunctionalTest
.evt_time
, 'arrow_up')
352 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
353 self
._screenshot
(FunctionalTest
.screenshot_time
, 'driver_page_entry')
354 self
._event
(FunctionalTest
.evt_time
, 'backspace')
355 self
._event
(FunctionalTest
.evt_time
, 'backspace')
356 self
._event
(FunctionalTest
.evt_time
, 'backspace')
357 self
._event
(FunctionalTest
.evt_time
, 'backspace')
358 self
._event
(FunctionalTest
.evt_time
, 'backspace')
359 self
._event
(FunctionalTest
.evt_time
, 'backspace')
360 self
._event
(FunctionalTest
.evt_time
, 'backspace')
361 self
._event
(FunctionalTest
.evt_time
, 'backspace')
362 self
._event
(FunctionalTest
.evt_time
, 'backspace')
363 self
._event
(FunctionalTest
.evt_time
, 'backspace')
364 self
._screenshot
(FunctionalTest
.screenshot_time
, 'driver_page_entry_empty')
365 self
._event
(FunctionalTest
.evt_time
, 'f')
366 self
._event
(FunctionalTest
.evt_time
, 'l')
367 self
._event
(FunctionalTest
.evt_time
, 'a')
368 self
._event
(FunctionalTest
.evt_time
, 'v')
369 self
._event
(FunctionalTest
.evt_time
, 'i')
370 self
._event
(FunctionalTest
.evt_time
, 'o')
371 self
._event
(FunctionalTest
.evt_time
, 'enter')
372 self
._screenshot
(FunctionalTest
.screenshot_time
, 'driver_page_entry_full')
373 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
374 self
._event
(FunctionalTest
.evt_time
, 'arrow_right')
375 self
._screenshot
(FunctionalTest
.screenshot_time
, 'driver_page_sel')
377 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
378 self
._event
(40, 'escape-up')
379 self
._screenshot
(FunctionalTest
.screenshot_time
, 'ingame_menu')
380 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
381 self
._screenshot
(FunctionalTest
.screenshot_time
, 'race_back')
382 self
._event
(FunctionalTest
.evt_time
, 'escape-up')
383 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
384 self
._screenshot
(FunctionalTest
.screenshot_time
, 'ingame_sel')
385 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
386 self
._screenshot
(FunctionalTest
.screenshot_time
, 'main_page_back_race')
388 def _do_screenshots_end(self
):
389 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
390 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
391 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
392 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
393 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
394 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
395 self
._screenshot
(FunctionalTest
.screenshot_time
, 'exit_page')
396 self
._event
(FunctionalTest
.evt_time
, 'arrow_down')
397 self
._screenshot
(FunctionalTest
.screenshot_time
, 'exit_page_sel')
399 self
._event
(FunctionalTest
.evt_time
, 'rcontrol')
402 def _do_screenshots(self
, idx
):
403 [self
._do
_screenshots
_1, self
._do
_screenshots
_2][int(idx
) - 1]()