blob: a9026706d597d2ff39026218fd2a447e34d78fdc [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001# SPDX-License-Identifier: GPL-2.0
Dave Youngf0f57b22012-03-28 14:42:56 -07002# Makefile for vm selftests
Masami Hiramatsu7549b332019-10-23 13:57:49 +09003uname_M := $(shell uname -m 2>/dev/null || echo not)
Sandipan Das24c3f062020-01-30 12:31:18 +05304MACHINE ?= $(shell echo $(uname_M) | sed -e 's/aarch64.*/arm64/')
Dave Youngf0f57b22012-03-28 14:42:56 -07005
Thierry Redingd0a87112015-09-22 14:58:52 -07006CFLAGS = -Wall -I ../../../../usr/include $(EXTRA_CFLAGS)
bamvor.zhangjian@huawei.com7d758af2016-11-29 19:55:49 +08007LDLIBS = -lrt
bamvor.zhangjian@huawei.com88baa782016-11-29 19:55:47 +08008TEST_GEN_FILES = compaction_test
Aneesh Kumar K.V235266b2018-01-31 16:16:59 -08009TEST_GEN_FILES += gup_benchmark
Ralph Campbellfee9f6d2020-04-22 12:50:27 -070010TEST_GEN_FILES += hmm-tests
bamvor.zhangjian@huawei.com88baa782016-11-29 19:55:47 +080011TEST_GEN_FILES += hugepage-mmap
12TEST_GEN_FILES += hugepage-shm
13TEST_GEN_FILES += map_hugetlb
Michael Ellerman91cbacc2018-10-26 15:10:48 -070014TEST_GEN_FILES += map_fixed_noreplace
Dmitry Safonov1caed862018-08-21 21:53:47 -070015TEST_GEN_FILES += map_populate
Aneesh Kumar K.V235266b2018-01-31 16:16:59 -080016TEST_GEN_FILES += mlock-random-test
bamvor.zhangjian@huawei.com88baa782016-11-29 19:55:47 +080017TEST_GEN_FILES += mlock2-tests
Brian Geffon0c287592020-04-01 21:09:20 -070018TEST_GEN_FILES += mremap_dontunmap
bamvor.zhangjian@huawei.com88baa782016-11-29 19:55:47 +080019TEST_GEN_FILES += on-fault-limit
20TEST_GEN_FILES += thuge-gen
21TEST_GEN_FILES += transhuge-stress
22TEST_GEN_FILES += userfaultfd
Kirill A. Shutemove0c13f92020-06-03 16:00:06 -070023TEST_GEN_FILES += khugepaged
Masami Hiramatsu7549b332019-10-23 13:57:49 +090024
Sandipan Dasf21fda82020-06-04 16:52:54 -070025ifeq ($(ARCH),x86_64)
26CAN_BUILD_I386 := $(shell ./../x86/check_cc.sh $(CC) ../x86/trivial_32bit_program.c -m32)
27CAN_BUILD_X86_64 := $(shell ./../x86/check_cc.sh $(CC) ../x86/trivial_64bit_program.c)
28CAN_BUILD_WITH_NOPIE := $(shell ./../x86/check_cc.sh $(CC) ../x86/trivial_program.c -no-pie)
29
30TARGETS := protection_keys
31BINARIES_32 := $(TARGETS:%=%_32)
32BINARIES_64 := $(TARGETS:%=%_64)
33
34ifeq ($(CAN_BUILD_WITH_NOPIE),1)
35CFLAGS += -no-pie
36endif
37
38ifeq ($(CAN_BUILD_I386),1)
39TEST_GEN_FILES += $(BINARIES_32)
40endif
41
42ifeq ($(CAN_BUILD_X86_64),1)
43TEST_GEN_FILES += $(BINARIES_64)
44endif
45else
46TEST_GEN_FILES += protection_keys
47endif
48
Sandipan Das963e3e92020-01-30 12:31:19 +053049ifneq (,$(filter $(MACHINE),arm64 ia64 mips64 parisc64 ppc64 ppc64le riscv64 s390x sh64 sparc64 x86_64))
Aneesh Kumar K.V235266b2018-01-31 16:16:59 -080050TEST_GEN_FILES += va_128TBswitch
Anshuman Khandual4e5ce332017-05-08 16:00:19 -070051TEST_GEN_FILES += virtual_address_range
Mina Almasry29750f72020-04-01 21:11:38 -070052TEST_GEN_FILES += write_to_hugetlbfs
Masami Hiramatsu7549b332019-10-23 13:57:49 +090053endif
Dave Youngf0f57b22012-03-28 14:42:56 -070054
Michael Ellerman5e29a912015-03-11 15:05:59 +110055TEST_PROGS := run_vmtests
56
Naresh Kambojubc2cce32019-05-28 13:18:09 +010057TEST_FILES := test_vmalloc.sh
58
Shuah Khan211929f2018-12-12 20:25:14 -070059KSFT_KHDR_INSTALL := 1
Michael Ellerman5e29a912015-03-11 15:05:59 +110060include ../lib.mk
Dave Youngf0f57b22012-03-28 14:42:56 -070061
Ralph Campbellfee9f6d2020-04-22 12:50:27 -070062$(OUTPUT)/hmm-tests: LDLIBS += -lhugetlbfs -lpthread
63
Sandipan Dasf21fda82020-06-04 16:52:54 -070064ifeq ($(ARCH),x86_64)
65BINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32))
66BINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64))
67
68define gen-target-rule-32
69$(1) $(1)_32: $(OUTPUT)/$(1)_32
70.PHONY: $(1) $(1)_32
71endef
72
73define gen-target-rule-64
74$(1) $(1)_64: $(OUTPUT)/$(1)_64
75.PHONY: $(1) $(1)_64
76endef
77
78ifeq ($(CAN_BUILD_I386),1)
79$(BINARIES_32): CFLAGS += -m32
80$(BINARIES_32): LDLIBS += -lrt -ldl -lm
81$(BINARIES_32): %_32: %.c
82 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(notdir $^) $(LDLIBS) -o $@
83$(foreach t,$(TARGETS),$(eval $(call gen-target-rule-32,$(t))))
84endif
85
86ifeq ($(CAN_BUILD_X86_64),1)
87$(BINARIES_64): CFLAGS += -m64
88$(BINARIES_64): LDLIBS += -lrt -ldl
89$(BINARIES_64): %_64: %.c
90 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(notdir $^) $(LDLIBS) -o $@
91$(foreach t,$(TARGETS),$(eval $(call gen-target-rule-64,$(t))))
92endif
93
94# x86_64 users should be encouraged to install 32-bit libraries
95ifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),01)
96all: warn_32bit_failure
97
98warn_32bit_failure:
99 @echo "Warning: you seem to have a broken 32-bit build" 2>&1; \
100 echo "environment. This will reduce test coverage of 64-bit" 2>&1; \
101 echo "kernels. If you are using a Debian-like distribution," 2>&1; \
102 echo "try:"; 2>&1; \
103 echo ""; \
104 echo " apt-get install gcc-multilib libc6-i386 libc6-dev-i386"; \
105 echo ""; \
106 echo "If you are using a Fedora-like distribution, try:"; \
107 echo ""; \
108 echo " yum install glibc-devel.*i686"; \
109 exit 0;
110endif
111endif
112
Mike Rapoportb6ad1972017-05-03 14:54:54 -0700113$(OUTPUT)/userfaultfd: LDLIBS += -lpthread
Linus Torvaldsc4f3f222017-02-25 15:32:53 -0800114
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800115$(OUTPUT)/mlock-random-test: LDLIBS += -lcap