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