test: use linux/magic.h from our tree

We copy linux/magic.h from the kernel source tree and use it when
building systemd. Let's also make the kernel-filesystem-magics test
use the copy in our tree rather than the one installed on the system.

To achieve that now the 'check' command takes both 'cpp' and
'system_include_args' from meson.
This commit is contained in:
Yu Watanabe
2026-08-31 21:17:30 +09:00
parent 8220fcf4fe
commit 69c8578c17
2 changed files with 15 additions and 10 deletions
+14 -8
View File
@@ -1,9 +1,10 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: LGPL-2.1-or-later
import os
import shlex
import subprocess
import sys
from collections.abc import Iterator
NAME_TO_MAGIC = {
'apparmorfs': ['AAFS_MAGIC'],
@@ -341,10 +342,11 @@ def generate_filesystem_sets():
print('};')
def magic_defines():
cpp = os.environ['CPP'].split()
def magic_defines(args: list[str]) -> Iterator[str]:
cpp = shlex.split(args[0])
include_dirs = args[1:]
out = subprocess.check_output(
[*cpp, '-dM', '-include', 'linux/magic.h', '-'],
[*cpp, '-dM', '-include', 'linux/magic.h', *include_dirs, '-'],
stdin=subprocess.DEVNULL,
text=True,
)
@@ -365,8 +367,8 @@ def magic_defines():
yield name
def check():
kernel_magics = set(magic_defines())
def check(args: list[str]) -> None:
kernel_magics = set(magic_defines(args))
our_magics = set(sum(NAME_TO_MAGIC.values(), start=[]))
extra = kernel_magics - our_magics
if extra:
@@ -374,7 +376,9 @@ def check():
if __name__ == '__main__':
for arg in sys.argv[1:]:
args = sys.argv[1:]
for i, arg in enumerate(args):
if arg == 'gperf':
generate_gperf()
elif arg == 'fs-type-to-string':
@@ -384,6 +388,8 @@ if __name__ == '__main__':
elif arg == 'fs-in-group':
generate_fs_in_group()
elif arg == 'check':
check()
# 'check' must be the last command; pass the remaining arguments to check().
check(args[i + 1 :])
break
else:
raise ValueError
+1 -2
View File
@@ -203,8 +203,7 @@ basic_sources += [filesystem_sets_c, filesystems_gperf_h]
test('kernel-filesystem-magics',
filesystem_sets_py,
args : ['check'],
env : ['CPP=@0@'.format(cpp)])
args : ['check', cpp, system_include_args])
libbasic_static = static_library(
'basic',