Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: break the dependency upon local header files

Patch series "Fix selftests/mm build without requiring "make headers"".

As mentioned in each patch, this implements the solution that we discussed
in December 2023, in [1]. This turned out to be very clean and easy. It
should also be quite easy to maintain.

This should also make Peter Zijlstra happy, because it directly addresses
the root cause of his "NAK NAK NAK" reply [2]. :)

[1] https://lore.kernel.org/all/783a4178-1dec-4e30-989a-5174b8176b09@redhat.com/
[2] https://lore.kernel.org/lkml/20231103121652.GA6217@noisy.programming.kicks-ass.net/


This patch (of 2):

Use tools/include/uapi/ files instead. These are obtained by taking a
snapshot: run "make headers" at the top level, then copy the desired
header file into the appropriate subdir in tools/uapi/.

This was discussed and solved in [1].

However, even before copying any additional files there, there are already
quite a few in tools/include/uapi already. And these will immediately fix
a number of selftests/mm build failures.

So this patch:

a) Adds TOOLS_INCLUDES to selftests/lib.mk, so that all selftests can
immediately and easily include the snapshotted header files.

b) Uses $(TOOLS_INCLUDES) in the selftests/mm build. On today's Arch
Linux, this already fixes all build errors except for a few
userfaultfd.h (those will be addressed in a subsequent patch).

[1] https://lore.kernel.org/all/783a4178-1dec-4e30-989a-5174b8176b09@redhat.com/

Link: https://lkml.kernel.org/r/20240328033418.203790-1-jhubbard@nvidia.com
Link: https://lkml.kernel.org/r/20240328033418.203790-2-jhubbard@nvidia.com
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Acked-by: David Hildenbrand <david@redhat.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Muhammad Usama Anjum <usama.anjum@collabora.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

John Hubbard and committed by
Andrew Morton
e076eaca bd722058

+10 -1
+9
tools/testing/selftests/lib.mk
··· 48 48 KHDR_INCLUDES := -isystem $(top_srcdir)/usr/include 49 49 endif 50 50 51 + # In order to use newer items that haven't yet been added to the user's system 52 + # header files, add $(TOOLS_INCLUDES) to the compiler invocation in each 53 + # each selftest. 54 + # You may need to add files to that location, or to refresh an existing file. In 55 + # order to do that, run "make headers" from $(top_srcdir), then copy the 56 + # header file that you want from $(top_srcdir)/usr/include/... , to the matching 57 + # subdir in $(TOOLS_INCLUDE). 58 + TOOLS_INCLUDES := -isystem $(top_srcdir)/tools/include/uapi 59 + 51 60 # The following are built by lib.mk common compile rules. 52 61 # TEST_CUSTOM_PROGS should be used by tests that require 53 62 # custom build rule and prevent common build rule use.
+1 -1
tools/testing/selftests/mm/Makefile
··· 32 32 # LDLIBS. 33 33 MAKEFLAGS += --no-builtin-rules 34 34 35 - CFLAGS = -Wall -I $(top_srcdir) $(EXTRA_CFLAGS) $(KHDR_INCLUDES) 35 + CFLAGS = -Wall -I $(top_srcdir) $(EXTRA_CFLAGS) $(KHDR_INCLUDES) $(TOOLS_INCLUDES) 36 36 LDLIBS = -lrt -lpthread -lm 37 37 38 38 TEST_GEN_FILES = cow