xref: /linux/tools/testing/selftests/mm/Makefile (revision b50ecc5aca4d18f1f0c4942f5c797bc85edef144)
1# SPDX-License-Identifier: GPL-2.0
2# Makefile for mm selftests
3
4LOCAL_HDRS += $(selfdir)/mm/local_config.h $(top_srcdir)/mm/gup_test.h
5LOCAL_HDRS += $(selfdir)/mm/mseal_helpers.h
6
7include local_config.mk
8
9ifeq ($(ARCH),)
10
11ifeq ($(CROSS_COMPILE),)
12uname_M := $(shell uname -m 2>/dev/null || echo not)
13else
14uname_M := $(shell echo $(CROSS_COMPILE) | grep -o '^[a-z0-9]\+')
15endif
16ARCH ?= $(shell echo $(uname_M) | sed -e 's/aarch64.*/arm64/' -e 's/ppc64.*/powerpc/')
17endif
18
19# Without this, failed build products remain, with up-to-date timestamps,
20# thus tricking Make (and you!) into believing that All Is Well, in subsequent
21# make invocations:
22.DELETE_ON_ERROR:
23
24# Avoid accidental wrong builds, due to built-in rules working just a little
25# bit too well--but not quite as well as required for our situation here.
26#
27# In other words, "make $SOME_TEST" is supposed to fail to build at all,
28# because this Makefile only supports either "make" (all), or "make /full/path".
29# However,  the built-in rules, if not suppressed, will pick up CFLAGS and the
30# initial LDLIBS (but not the target-specific LDLIBS, because those are only
31# set for the full path target!). This causes it to get pretty far into building
32# things despite using incorrect values such as an *occasionally* incomplete
33# LDLIBS.
34MAKEFLAGS += --no-builtin-rules
35
36CFLAGS = -Wall -I $(top_srcdir) $(EXTRA_CFLAGS) $(KHDR_INCLUDES) $(TOOLS_INCLUDES)
37LDLIBS = -lrt -lpthread -lm
38
39KDIR ?= /lib/modules/$(shell uname -r)/build
40ifneq (,$(wildcard $(KDIR)/Module.symvers))
41ifneq (,$(wildcard $(KDIR)/include/linux/page_frag_cache.h))
42TEST_GEN_MODS_DIR := page_frag
43else
44PAGE_FRAG_WARNING = "missing page_frag_cache.h, please use a newer kernel"
45endif
46else
47PAGE_FRAG_WARNING = "missing Module.symvers, please have the kernel built first"
48endif
49
50TEST_GEN_FILES = cow
51TEST_GEN_FILES += compaction_test
52TEST_GEN_FILES += gup_longterm
53TEST_GEN_FILES += gup_test
54TEST_GEN_FILES += hmm-tests
55TEST_GEN_FILES += hugetlb-madvise
56TEST_GEN_FILES += hugetlb-read-hwpoison
57TEST_GEN_FILES += hugetlb-soft-offline
58TEST_GEN_FILES += hugepage-mmap
59TEST_GEN_FILES += hugepage-mremap
60TEST_GEN_FILES += hugepage-shm
61TEST_GEN_FILES += hugepage-vmemmap
62TEST_GEN_FILES += khugepaged
63TEST_GEN_FILES += madv_populate
64TEST_GEN_FILES += map_fixed_noreplace
65TEST_GEN_FILES += map_hugetlb
66TEST_GEN_FILES += map_populate
67ifneq (,$(filter $(ARCH),arm64 riscv riscv64 x86 x86_64))
68TEST_GEN_FILES += memfd_secret
69endif
70TEST_GEN_FILES += migration
71TEST_GEN_FILES += mkdirty
72TEST_GEN_FILES += mlock-random-test
73TEST_GEN_FILES += mlock2-tests
74TEST_GEN_FILES += mrelease_test
75TEST_GEN_FILES += mremap_dontunmap
76TEST_GEN_FILES += mremap_test
77TEST_GEN_FILES += mseal_test
78TEST_GEN_FILES += seal_elf
79TEST_GEN_FILES += on-fault-limit
80TEST_GEN_FILES += pagemap_ioctl
81TEST_GEN_FILES += thuge-gen
82TEST_GEN_FILES += transhuge-stress
83TEST_GEN_FILES += uffd-stress
84TEST_GEN_FILES += uffd-unit-tests
85TEST_GEN_FILES += split_huge_page_test
86TEST_GEN_FILES += ksm_tests
87TEST_GEN_FILES += ksm_functional_tests
88TEST_GEN_FILES += mdwe_test
89TEST_GEN_FILES += hugetlb_fault_after_madv
90TEST_GEN_FILES += hugetlb_madv_vs_map
91TEST_GEN_FILES += hugetlb_dio
92TEST_GEN_FILES += droppable
93TEST_GEN_FILES += guard-pages
94
95ifneq ($(ARCH),arm64)
96TEST_GEN_FILES += soft-dirty
97endif
98
99ifeq ($(ARCH),x86_64)
100CAN_BUILD_I386 := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_32bit_program.c -m32)
101CAN_BUILD_X86_64 := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_64bit_program.c)
102CAN_BUILD_WITH_NOPIE := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_program.c -no-pie)
103
104VMTARGETS := protection_keys
105VMTARGETS += pkey_sighandler_tests
106BINARIES_32 := $(VMTARGETS:%=%_32)
107BINARIES_64 := $(VMTARGETS:%=%_64)
108
109ifeq ($(CAN_BUILD_WITH_NOPIE),1)
110CFLAGS += -no-pie
111endif
112
113ifeq ($(CAN_BUILD_I386),1)
114TEST_GEN_FILES += $(BINARIES_32)
115endif
116
117ifeq ($(CAN_BUILD_X86_64),1)
118TEST_GEN_FILES += $(BINARIES_64)
119endif
120
121else ifeq ($(ARCH),arm64)
122TEST_GEN_FILES += protection_keys
123TEST_GEN_FILES += pkey_sighandler_tests
124else ifeq ($(ARCH),powerpc)
125TEST_GEN_FILES += protection_keys
126endif
127
128ifneq (,$(filter $(ARCH),arm64 mips64 parisc64 powerpc riscv64 s390x sparc64 x86_64 s390))
129TEST_GEN_FILES += va_high_addr_switch
130ifneq ($(ARCH),riscv64)
131TEST_GEN_FILES += virtual_address_range
132endif
133TEST_GEN_FILES += write_to_hugetlbfs
134endif
135
136TEST_PROGS := run_vmtests.sh
137
138TEST_FILES := test_vmalloc.sh
139TEST_FILES += test_hmm.sh
140TEST_FILES += va_high_addr_switch.sh
141TEST_FILES += charge_reserved_hugetlb.sh
142TEST_FILES += hugetlb_reparenting_test.sh
143TEST_FILES += test_page_frag.sh
144
145# required by charge_reserved_hugetlb.sh
146TEST_FILES += write_hugetlb_memory.sh
147
148include ../lib.mk
149
150$(TEST_GEN_PROGS): vm_util.c thp_settings.c
151$(TEST_GEN_FILES): vm_util.c thp_settings.c
152
153$(OUTPUT)/uffd-stress: uffd-common.c
154$(OUTPUT)/uffd-unit-tests: uffd-common.c
155
156ifeq ($(ARCH),x86_64)
157BINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32))
158BINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64))
159
160define gen-target-rule-32
161$(1) $(1)_32: $(OUTPUT)/$(1)_32
162.PHONY: $(1) $(1)_32
163endef
164
165define gen-target-rule-64
166$(1) $(1)_64: $(OUTPUT)/$(1)_64
167.PHONY: $(1) $(1)_64
168endef
169
170ifeq ($(CAN_BUILD_I386),1)
171$(BINARIES_32): CFLAGS += -m32 -mxsave
172$(BINARIES_32): LDLIBS += -lrt -ldl -lm
173$(BINARIES_32): $(OUTPUT)/%_32: %.c
174	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(notdir $^) $(LDLIBS) -o $@
175$(foreach t,$(VMTARGETS),$(eval $(call gen-target-rule-32,$(t))))
176endif
177
178ifeq ($(CAN_BUILD_X86_64),1)
179$(BINARIES_64): CFLAGS += -m64 -mxsave
180$(BINARIES_64): LDLIBS += -lrt -ldl
181$(BINARIES_64): $(OUTPUT)/%_64: %.c
182	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(notdir $^) $(LDLIBS) -o $@
183$(foreach t,$(VMTARGETS),$(eval $(call gen-target-rule-64,$(t))))
184endif
185
186# x86_64 users should be encouraged to install 32-bit libraries
187ifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),01)
188all: warn_32bit_failure
189
190warn_32bit_failure:
191	@echo "Warning: you seem to have a broken 32-bit build" 2>&1;		\
192	echo  "environment. This will reduce test coverage of 64-bit" 2>&1;	\
193	echo  "kernels. If you are using a Debian-like distribution," 2>&1;	\
194	echo  "try:"; 2>&1;							\
195	echo  "";								\
196	echo  "  apt-get install gcc-multilib libc6-i386 libc6-dev-i386";	\
197	echo  "";								\
198	echo  "If you are using a Fedora-like distribution, try:";		\
199	echo  "";								\
200	echo  "  yum install glibc-devel.*i686";				\
201	exit 0;
202endif
203endif
204
205# IOURING_EXTRA_LIBS may get set in local_config.mk, or it may be left empty.
206$(OUTPUT)/cow: LDLIBS += $(IOURING_EXTRA_LIBS)
207
208$(OUTPUT)/gup_longterm: LDLIBS += $(IOURING_EXTRA_LIBS)
209
210$(OUTPUT)/mlock-random-test $(OUTPUT)/memfd_secret: LDLIBS += -lcap
211
212$(OUTPUT)/ksm_tests: LDLIBS += -lnuma
213
214$(OUTPUT)/migration: LDLIBS += -lnuma
215
216local_config.mk local_config.h: check_config.sh
217	/bin/sh ./check_config.sh $(CC)
218
219EXTRA_CLEAN += local_config.mk local_config.h
220
221ifeq ($(IOURING_EXTRA_LIBS),)
222all: warn_missing_liburing
223
224warn_missing_liburing:
225	@echo ; \
226	echo "Warning: missing liburing support. Some tests will be skipped." ; \
227	echo
228endif
229
230ifneq ($(PAGE_FRAG_WARNING),)
231all: warn_missing_page_frag
232
233warn_missing_page_frag:
234	@echo ; \
235	echo "Warning: $(PAGE_FRAG_WARNING). page_frag test will be skipped." ; \
236	echo
237endif
238