Files
DroidDeck/tools/tests/test_effects_lazy_pipelines.py

69 lines
2.8 KiB
Python

import pathlib
import unittest
ROOT = pathlib.Path(__file__).resolve().parents[2]
SOURCE = ROOT / "app/src/main/cpp/waylandcomp/src/effects_chain.c"
def function_body(source: str, signature: str) -> str:
start = source.index(signature)
opening = source.index("{", start)
depth = 0
for pos in range(opening, len(source)):
if source[pos] == "{":
depth += 1
elif source[pos] == "}":
depth -= 1
if depth == 0:
return source[opening + 1:pos]
raise AssertionError(f"unterminated function: {signature}")
class LazyEffectPipelineSourceTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.source = SOURCE.read_text(encoding="utf-8")
def test_shared_setup_does_not_create_graphics_pipelines(self):
body = function_body(self.source, "static int objects_ensure(void)")
self.assertNotIn("post_pipeline_for_renderpass(", body)
self.assertNotIn("shader(upscale_vert_code", body)
self.assertIn("effect pipelines are created when needed", body)
def test_pipelines_are_prepared_before_effect_chain_resources_and_draws(self):
body = function_body(self.source, "static VkImage effects_run(")
prepare = body.index("pipelines_ensure(spatial, s)")
scene = body.index("scene_ensure(scene, scene_w, scene_h)")
self.assertLess(prepare, scene)
self.assertIn("objects_ensure() == 0 && pipelines_ensure(spatial, s) == 0", body)
def test_lazy_path_covers_active_upscalers_and_effects(self):
body = function_body(self.source, "static int pipelines_ensure(")
for required in (
"spatial == 3", "spatial == 8", "spatial == 4 || spatial == 5",
"spatial == 6", "spatial == 7", "cas_active(s)",
"s->color_on", "s->aa_mode == 1 || s->aa_mode == 2",
"s->aa_mode == 2", "s->toon", "s->hdr_on", "s->ntsc",
"s->crt", "deband_active(s)",
):
with self.subTest(required=required):
self.assertIn(required, body)
def test_existing_fallback_pipelines_are_prepared(self):
body = function_body(self.source, "static int pipelines_ensure(")
self.assertIn("s->aa_mode == 1 || s->aa_mode == 2", body)
self.assertIn("else if (g_upscale_half) MK(1, P_SGSR, sgsr_half_code", body)
self.assertIn("if (!g_nis_fast) MK(1, P_NIS, nis_code", body)
def test_failed_preparation_uses_whole_chain_fallback(self):
body = function_body(self.source, "static int pipelines_ensure(")
self.assertIn("return chain_failed();", body)
failure = function_body(self.source, "static int chain_failed(void)")
self.assertIn("objects_destroy();", failure)
self.assertIn("g_ready = -1;", failure)
if __name__ == "__main__":
unittest.main()