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