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