xref: /linux/tools/testing/selftests/mm/Makefile (revision 6e7fd890f1d6ac83805409e9c346240de2705584)
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
39TEST_GEN_FILES = cow
40TEST_GEN_FILES += compaction_test
41TEST_GEN_FILES += gup_longterm
42TEST_GEN_FILES += gup_test
43TEST_GEN_FILES += hmm-tests
44TEST_GEN_FILES += hugetlb-madvise
45TEST_GEN_FILES += hugetlb-read-hwpoison
46TEST_GEN_FILES += hugetlb-soft-offline
47TEST_GEN_FILES += hugepage-mmap
48TEST_GEN_FILES += hugepage-mremap
49TEST_GEN_FILES += hugepage-shm
50TEST_GEN_FILES += hugepage-vmemmap
51TEST_GEN_FILES += khugepaged
52TEST_GEN_FILES += madv_populate
53TEST_GEN_FILES += map_fixed_noreplace
54TEST_GEN_FILES += map_hugetlb
55TEST_GEN_FILES += map_populate
56ifneq (,$(filter $(ARCH),arm64 riscv riscv64 x86 x86_64))
57TEST_GEN_FILES += memfd_secret
58endif
59TEST_GEN_FILES += migration
60TEST_GEN_FILES += mkdirty
61TEST_GEN_FILES += mlock-random-test
62TEST_GEN_FILES += mlock2-tests
63TEST_GEN_FILES += mrelease_test
64TEST_GEN_FILES += mremap_dontunmap
65TEST_GEN_FILES += mremap_test
66TEST_GEN_FILES += mseal_test
67TEST_GEN_FILES += seal_elf
68TEST_GEN_FILES += on-fault-limit
69TEST_GEN_FILES += pagemap_ioctl
70TEST_GEN_FILES += thuge-gen
71TEST_GEN_FILES += transhuge-stress
72TEST_GEN_FILES += uffd-stress
73TEST_GEN_FILES += uffd-unit-tests
74TEST_GEN_FILES += split_huge_page_test
75TEST_GEN_FILES += ksm_tests
76TEST_GEN_FILES += ksm_functional_tests
77TEST_GEN_FILES += mdwe_test
78TEST_GEN_FILES += hugetlb_fault_after_madv
79TEST_GEN_FILES += hugetlb_madv_vs_map
80TEST_GEN_FILES += hugetlb_dio
81TEST_GEN_FILES += droppable
82
83ifneq ($(ARCH),arm64)
84TEST_GEN_FILES += soft-dirty
85endif
86
87ifeq ($(ARCH),x86_64)
88CAN_BUILD_I386 := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_32bit_program.c -m32)
89CAN_BUILD_X86_64 := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_64bit_program.c)
90CAN_BUILD_WITH_NOPIE := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_program.c -no-pie)
91
92VMTARGETS := protection_keys
93BINARIES_32 := $(VMTARGETS:%=%_32)
94BINARIES_64 := $(VMTARGETS:%=%_64)
95
96ifeq ($(CAN_BUILD_WITH_NOPIE),1)
97CFLAGS += -no-pie
98endif
99
100ifeq ($(CAN_BUILD_I386),1)
101TEST_GEN_FILES += $(BINARIES_32)
102endif
103
104ifeq ($(CAN_BUILD_X86_64),1)
105TEST_GEN_FILES += $(BINARIES_64)
106endif
107else
108
109ifneq (,$(findstring $(ARCH),powerpc))
110TEST_GEN_FILES += protection_keys
111endif
112
113endif
114
115ifneq (,$(filter $(ARCH),arm64 ia64 mips64 parisc64 powerpc riscv64 s390x sparc64 x86_64 s390))
116TEST_GEN_FILES += va_high_addr_switch
117TEST_GEN_FILES += virtual_address_range
118TEST_GEN_FILES += write_to_hugetlbfs
119endif
120
121TEST_PROGS := run_vmtests.sh
122
123TEST_FILES := test_vmalloc.sh
124TEST_FILES += test_hmm.sh
125TEST_FILES += va_high_addr_switch.sh
126TEST_FILES += charge_reserved_hugetlb.sh
127TEST_FILES += hugetlb_reparenting_test.sh
128
129# required by charge_reserved_hugetlb.sh
130TEST_FILES += write_hugetlb_memory.sh
131
132include ../lib.mk
133
134$(TEST_GEN_PROGS): vm_util.c thp_settings.c
135$(TEST_GEN_FILES): vm_util.c thp_settings.c
136
137$(OUTPUT)/uffd-stress: uffd-common.c
138$(OUTPUT)/uffd-unit-tests: uffd-common.c
139
140ifeq ($(ARCH),x86_64)
141BINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32))
142BINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64))
143
144define gen-target-rule-32
145$(1) $(1)_32: $(OUTPUT)/$(1)_32
146.PHONY: $(1) $(1)_32
147endef
148
149define gen-target-rule-64
150$(1) $(1)_64: $(OUTPUT)/$(1)_64
151.PHONY: $(1) $(1)_64
152endef
153
154ifeq ($(CAN_BUILD_I386),1)
155$(BINARIES_32): CFLAGS += -m32 -mxsave
156$(BINARIES_32): LDLIBS += -lrt -ldl -lm
157$(BINARIES_32): $(OUTPUT)/%_32: %.c
158	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(notdir $^) $(LDLIBS) -o $@
159$(foreach t,$(VMTARGETS),$(eval $(call gen-target-rule-32,$(t))))
160endif
161
162ifeq ($(CAN_BUILD_X86_64),1)
163$(BINARIES_64): CFLAGS += -m64 -mxsave
164$(BINARIES_64): LDLIBS += -lrt -ldl
165$(BINARIES_64): $(OUTPUT)/%_64: %.c
166	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(notdir $^) $(LDLIBS) -o $@
167$(foreach t,$(VMTARGETS),$(eval $(call gen-target-rule-64,$(t))))
168endif
169
170# x86_64 users should be encouraged to install 32-bit libraries
171ifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),01)
172all: warn_32bit_failure
173
174warn_32bit_failure:
175	@echo "Warning: you seem to have a broken 32-bit build" 2>&1;		\
176	echo  "environment. This will reduce test coverage of 64-bit" 2>&1;	\
177	echo  "kernels. If you are using a Debian-like distribution," 2>&1;	\
178	echo  "try:"; 2>&1;							\
179	echo  "";								\
180	echo  "  apt-get install gcc-multilib libc6-i386 libc6-dev-i386";	\
181	echo  "";								\
182	echo  "If you are using a Fedora-like distribution, try:";		\
183	echo  "";								\
184	echo  "  yum install glibc-devel.*i686";				\
185	exit 0;
186endif
187endif
188
189# IOURING_EXTRA_LIBS may get set in local_config.mk, or it may be left empty.
190$(OUTPUT)/cow: LDLIBS += $(IOURING_EXTRA_LIBS)
191
192$(OUTPUT)/gup_longterm: LDLIBS += $(IOURING_EXTRA_LIBS)
193
194$(OUTPUT)/mlock-random-test $(OUTPUT)/memfd_secret: LDLIBS += -lcap
195
196$(OUTPUT)/ksm_tests: LDLIBS += -lnuma
197
198$(OUTPUT)/migration: LDLIBS += -lnuma
199
200local_config.mk local_config.h: check_config.sh
201	/bin/sh ./check_config.sh $(CC)
202
203EXTRA_CLEAN += local_config.mk local_config.h
204
205ifeq ($(IOURING_EXTRA_LIBS),)
206all: warn_missing_liburing
207
208warn_missing_liburing:
209	@echo ; \
210	echo "Warning: missing liburing support. Some tests will be skipped." ; \
211	echo
212endif
213