From 1bfdf72ab3a142c0da37d34ab0d72a146604dcdf Mon Sep 17 00:00:00 2001 From: Flavio Calva Date: Mon, 18 Jul 2022 19:41:04 +0100 Subject: [PATCH] more asserts --- pmachines/app.py | 15 ++++++++++++ prj.org | 10 +------- ya2/p3d/asserts.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 ya2/p3d/asserts.py diff --git a/pmachines/app.py b/pmachines/app.py index a5f964d..8adb765 100755 --- a/pmachines/app.py +++ b/pmachines/app.py @@ -31,6 +31,8 @@ from ya2.p3d.p3d import LibP3d from ya2.utils.lang import LangMgr from ya2.utils.log import LogMgr from ya2.utils.functional import FunctionalTest +from ya2.p3d.asserts import assert_threads, assert_tasks, assert_render3d, \ + assert_render2d, assert_aspect2d, assert_events, assert_buffers class MainFsm(FSM): @@ -44,12 +46,25 @@ class MainFsm(FSM): def exitMenu(self): self._pmachines.on_menu_exit() + self.__do_asserts() def enterScene(self, cls): self._pmachines.on_scene_enter(cls) def exitScene(self): self._pmachines.on_scene_exit() + self.__do_asserts() + + def __do_asserts(self): + args = self._pmachines._args + if args.functional_test or args.functional_ref: + assert_threads() + assert_tasks() + assert_render3d() + assert_render2d() + assert_aspect2d() + assert_events() + assert_buffers() class PmachinesApp: diff --git a/prj.org b/prj.org index 85082cd..9c1366c 100644 --- a/prj.org +++ b/prj.org @@ -3,15 +3,7 @@ #+CATEGORY: pmachines #+TAGS: bug(b) calendar(c) waiting(w) -* CODE functional tests for "cleaning" i.e. at the end of the states verify: -- [ ] active threads -- [ ] active tasks -- [ ] current nodepaths (render3d) -- [ ] current nodepaths (render2d) -- [ ] current nodepaths (render3d) -- [ ] current accepting events -- [ ] current buffers -* READY drag and drop positions in the scene files as empty nodes +* CODE drag and drop positions in the scene files as empty nodes * READY refactoring (recurring task) * BACKLOG intro animation (from target item to start position) * BACKLOG buttons of the scenes enabled sequentially diff --git a/ya2/p3d/asserts.py b/ya2/p3d/asserts.py new file mode 100644 index 0000000..b450f51 --- /dev/null +++ b/ya2/p3d/asserts.py @@ -0,0 +1,58 @@ +from logging import info, debug +import threading + + +def assert_render3d(): + for child in render.children: + if child.name != 'camera': + raise Exception() + +def assert_aspect2d(): + for child in aspect2d.children: + preserve = [ + 'a2dBackground', 'a2dTopCenter', 'a2dTopCenterNS', + 'a2dBottomCenter', 'a2dBottomCenterNS', 'a2dLeftCenter', + 'a2dLeftCenterNS', 'a2dRightCenter', 'a2dRightCenterNS', + 'a2dTopLeft', 'a2dTopLeftNS', 'a2dTopRight', + 'a2dTopRightNS', 'a2dBottomLeft', 'a2dBottomLeftNS', + 'a2dBottomRight', 'a2dBottomRightNS'] + if child.name not in preserve and not child.has_python_tag('preserve'): + raise Exception() + +def assert_render2d(): + for child in render2d.children: + preserve = ['aspect2d', 'pixel2d', 'camera2d'] + if child.name not in preserve and not child.has_python_tag('preserve'): + raise Exception() + +def assert_events(): + preserve = ['window-event', 'window-closed', 'async_loader_0', + 'render-texture-targets-changed', 'aspectRatioChanged'] + for evt in messenger.getEvents(): + if evt not in preserve: + msg = 'unexpected event: %s' % evt + raise Exception(msg) + +def assert_tasks(): + preserve = [ + 'ivalLoop', 'garbageCollectStates', 'collisionLoop', + 'igLoop', 'audioLoop', 'resetPrevTransform', 'dataLoop', + 'eventManager', 'simplepbr update', 'on frame music'] + for task in taskMgr.getTasks() + taskMgr.getDoLaters(): + if task.name not in preserve and not hasattr(task, 'preserve'): + msg = 'unexpected task: %s' % task.name + raise Exception(msg) + +def assert_buffers(): + pass + #for buffer in RenderToTexture.buffers: + # raise Error() + + +def assert_threads(): + thr_names = [thread.name for thread in threading.enumerate()] + preserve = ['MainThread'] + for thr_name in thr_names: + if thr_name not in preserve: + msg = 'unexpected thread: %s' % thr_name + raise Exception(msg) -- 2.30.2