diff --git a/src/freedreno/meson.build b/src/freedreno/meson.build index 350ab3f997d..6f777269325 100644 --- a/src/freedreno/meson.build +++ b/src/freedreno/meson.build @@ -52,3 +52,9 @@ endif if with_freedreno_vk subdir('vulkan') endif + +test('check-xml-includes', + prog_python, + args : files('tests/check_xml_includes.py'), + suite : ['freedreno'], +) diff --git a/src/freedreno/tests/check_xml_includes.awk b/src/freedreno/tests/check_xml_includes.awk new file mode 100755 index 00000000000..6a1dd02e02b --- /dev/null +++ b/src/freedreno/tests/check_xml_includes.awk @@ -0,0 +1,54 @@ +# Copyright © 2026 Valve Corporation +# SPDX-License-Identifier: MIT +# +# Check for direct includes of *.xml.h files in freedreno. Only files in the +# allowed list may include *.xml.h directly. All other files must use wrapper +# headers (like fd_hw_common.h) instead. + +BEGIN { + # Allowlist: files permitted to include *.xml.h directly + allowed["src/freedreno/common/freedreno_pm4.h"] + allowed["src/freedreno/common/fd_hw_common.h"] + allowed["src/freedreno/common/fd2_hw.h"] + allowed["src/freedreno/common/fd3_hw.h"] + allowed["src/freedreno/common/fd4_hw.h"] + allowed["src/freedreno/common/fd5_hw.h"] + allowed["src/freedreno/common/fd6_hw.h"] + allowed["src/freedreno/common/fd6_pack.h"] + allowed["src/freedreno/vulkan/tu_cs.h"] + + errors = 0 +} + +# Beginning of each file. +FNR == 1 { + # We have to do this here since FILENAME isn't available in BEGIN. + if (FILENAME == "-") { + print "ERROR: stdin cannot be used with this script" > "/dev/stderr" + errors++ + exit + } + + relpath = FILENAME + sub(/^.*src\/freedreno\//, "src/freedreno/", relpath) + if (relpath in allowed) { + nextfile + } +} + +# Match #include "something.xml.h" +/#include[[:space:]]+"[^"]*\.xml\.h"/ { + print relpath ":" FNR ": Error: direct include of XML header not allowed" + print " " $0 + print " Use fd6_hw.h or another approved wrapper header instead" + errors++ +} + +END { + if (errors > 0) { + print "\n" errors " error(s) found" + exit 1 + } + print "No errors found" + exit 0 +} diff --git a/src/freedreno/tests/check_xml_includes.py b/src/freedreno/tests/check_xml_includes.py new file mode 100755 index 00000000000..7f21b846fb0 --- /dev/null +++ b/src/freedreno/tests/check_xml_includes.py @@ -0,0 +1,28 @@ +# Copyright © 2026 Valve Corporation +# SPDX-License-Identifier: MIT + +import subprocess +import glob +import sys +import os +import shutil + +os.chdir(os.path.dirname(__file__) + "/../../..") + +# Meson and other build systems use 77 to skip tests +SKIP_RETURN_CODE = 77 +if not shutil.which("awk"): + print('Skipping test. "awk" not found') + sys.exit(SKIP_RETURN_CODE) + +files = ( + glob.glob("src/freedreno/**/*.[ch]", recursive=True) + + glob.glob("src/freedreno/**/*.cc", recursive=True) + + glob.glob("src/gallium/drivers/freedreno/**/*.[ch]", recursive=True) + + glob.glob("src/gallium/drivers/freedreno/**/*.cc", recursive=True) +) + +result = subprocess.run( + ["awk", "-f", "src/freedreno/tests/check_xml_includes.awk"] + sorted(files) +) +sys.exit(result.returncode)