mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-07 02:48:06 +02:00
freedreno: Add check_xml_includes test
Add a test to ensure that we're always using one of the wrapper files instead of including the XML generated headers directly. Assisted-by: Opencode (MiniMax M2.7) Signed-off-by: Karmjit Mahil <karmjit.mahil@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40853>
This commit is contained in:
parent
396201a9ab
commit
1208d84f3c
3 changed files with 88 additions and 0 deletions
|
|
@ -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'],
|
||||
)
|
||||
|
|
|
|||
54
src/freedreno/tests/check_xml_includes.awk
Executable file
54
src/freedreno/tests/check_xml_includes.awk
Executable file
|
|
@ -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
|
||||
}
|
||||
28
src/freedreno/tests/check_xml_includes.py
Executable file
28
src/freedreno/tests/check_xml_includes.py
Executable file
|
|
@ -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)
|
||||
Loading…
Add table
Reference in a new issue