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