Files
DroidDeck/tools/tests/test_mali_compat_spirv.py
T
maxjivi05 ea9a1398df fix(venus): keep application pipeline chains read-only and check non-semantic imports
Inline stage code is handed to the driver through a copy of the stage's
pNext chain instead of being written into the application's create info,
pipeline hooks return VK_ERROR_OUT_OF_HOST_MEMORY when their allocations
fail, and a NonSemantic import is only lowered to SPIR-V 1.3 when the
module declares SPV_KHR_non_semantic_info.
2026-11-13 18:55:13 -05:00

66 lines
3.0 KiB
Python

import os
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[2]
LAYER = ROOT / "tools/venus/layer"
DEPS = ROOT / "build/layer-deps"
HARNESS = Path(__file__).with_name("mali_compat_spirv_test.c")
def include(variable, default):
return Path(os.environ.get(variable, str(default)))
class MaliCompatSpirvTest(unittest.TestCase):
def test_the_layer_lowers_a_module_to_the_version_the_driver_knows(self):
compiler = shutil.which(os.environ.get("CC", "cc"))
if not compiler:
self.fail("A C compiler is required for the Mali compatibility layer test")
vulkan = include("MALI_COMPAT_VULKAN_INCLUDE", DEPS / "vulkan/include")
spirv = include("MALI_COMPAT_SPIRV_INCLUDE", DEPS / "spirv/include")
missing = [str(path) for path in (vulkan / "vulkan/vk_layer.h", spirv / "spirv/unified1/spirv.h")
if not path.is_file()]
if missing:
message = "Vulkan 1.4 and SPIR-V headers are required: " + ", ".join(missing)
if os.environ.get("CI"):
self.fail(message)
self.skipTest(message)
with tempfile.TemporaryDirectory(prefix="droiddeck-mali-spirv-") as tmp:
program = Path(tmp) / "mali-compat-spirv"
module = Path(tmp) / "capped.spv"
guest = Path(tmp) / "guest.spv"
extension = Path(tmp) / "extension.spv"
scalar = Path(tmp) / "scalar.spv"
debug = Path(tmp) / "debug.spv"
built = subprocess.run(
[compiler, "-std=gnu11", "-Wall", "-Wextra", "-Werror", "-Wno-unused-parameter", "-UNDEBUG",
"-pthread", "-Dcalloc=test_calloc", "-I", str(LAYER), "-I", str(vulkan), "-I", str(spirv),
str(HARNESS), str(LAYER / "spirv.c"), str(LAYER / "pipeline.c"), "-o", str(program)],
capture_output=True, text=True)
self.assertEqual(built.returncode, 0, built.stdout + built.stderr)
ran = subprocess.run([str(program), str(module), str(guest), str(extension), str(scalar), str(debug)],
capture_output=True, text=True, timeout=30)
self.assertEqual(ran.returncode, 0, ran.stdout + ran.stderr)
self.assertIn("mali compat spirv ok", ran.stdout)
self.assertTrue(module.is_file())
self.assertTrue(guest.is_file())
self.assertTrue(extension.is_file())
self.assertTrue(scalar.is_file())
self.assertTrue(debug.is_file())
validator = shutil.which("spirv-val")
if not validator:
return
for lowered in (module, guest, extension, scalar, debug):
checked = subprocess.run([validator, "--target-env", "vulkan1.1", str(lowered)],
capture_output=True, text=True)
self.assertEqual(checked.returncode, 0, checked.stdout + checked.stderr)
if __name__ == "__main__":
unittest.main()