162306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci# Makefile for mm selftests 362306a36Sopenharmony_ci 462306a36Sopenharmony_ciLOCAL_HDRS += $(selfdir)/mm/local_config.h $(top_srcdir)/mm/gup_test.h 562306a36Sopenharmony_ci 662306a36Sopenharmony_ciinclude local_config.mk 762306a36Sopenharmony_ci 862306a36Sopenharmony_ciifeq ($(ARCH),) 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ciifeq ($(CROSS_COMPILE),) 1162306a36Sopenharmony_ciuname_M := $(shell uname -m 2>/dev/null || echo not) 1262306a36Sopenharmony_cielse 1362306a36Sopenharmony_ciuname_M := $(shell echo $(CROSS_COMPILE) | grep -o '^[a-z0-9]\+') 1462306a36Sopenharmony_ciendif 1562306a36Sopenharmony_ciARCH ?= $(shell echo $(uname_M) | sed -e 's/aarch64.*/arm64/' -e 's/ppc64.*/ppc64/') 1662306a36Sopenharmony_ciendif 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci# Without this, failed build products remain, with up-to-date timestamps, 1962306a36Sopenharmony_ci# thus tricking Make (and you!) into believing that All Is Well, in subsequent 2062306a36Sopenharmony_ci# make invocations: 2162306a36Sopenharmony_ci.DELETE_ON_ERROR: 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci# Avoid accidental wrong builds, due to built-in rules working just a little 2462306a36Sopenharmony_ci# bit too well--but not quite as well as required for our situation here. 2562306a36Sopenharmony_ci# 2662306a36Sopenharmony_ci# In other words, "make $SOME_TEST" is supposed to fail to build at all, 2762306a36Sopenharmony_ci# because this Makefile only supports either "make" (all), or "make /full/path". 2862306a36Sopenharmony_ci# However, the built-in rules, if not suppressed, will pick up CFLAGS and the 2962306a36Sopenharmony_ci# initial LDLIBS (but not the target-specific LDLIBS, because those are only 3062306a36Sopenharmony_ci# set for the full path target!). This causes it to get pretty far into building 3162306a36Sopenharmony_ci# things despite using incorrect values such as an *occasionally* incomplete 3262306a36Sopenharmony_ci# LDLIBS. 3362306a36Sopenharmony_ciMAKEFLAGS += --no-builtin-rules 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ciCFLAGS = -Wall -I $(top_srcdir) $(EXTRA_CFLAGS) $(KHDR_INCLUDES) 3662306a36Sopenharmony_ciLDLIBS = -lrt -lpthread 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ciTEST_GEN_FILES = cow 3962306a36Sopenharmony_ciTEST_GEN_FILES += compaction_test 4062306a36Sopenharmony_ciTEST_GEN_FILES += gup_longterm 4162306a36Sopenharmony_ciTEST_GEN_FILES += gup_test 4262306a36Sopenharmony_ciTEST_GEN_FILES += hmm-tests 4362306a36Sopenharmony_ciTEST_GEN_FILES += hugetlb-madvise 4462306a36Sopenharmony_ciTEST_GEN_FILES += hugetlb-read-hwpoison 4562306a36Sopenharmony_ciTEST_GEN_FILES += hugepage-mmap 4662306a36Sopenharmony_ciTEST_GEN_FILES += hugepage-mremap 4762306a36Sopenharmony_ciTEST_GEN_FILES += hugepage-shm 4862306a36Sopenharmony_ciTEST_GEN_FILES += hugepage-vmemmap 4962306a36Sopenharmony_ciTEST_GEN_FILES += khugepaged 5062306a36Sopenharmony_ciTEST_GEN_FILES += madv_populate 5162306a36Sopenharmony_ciTEST_GEN_FILES += map_fixed_noreplace 5262306a36Sopenharmony_ciTEST_GEN_FILES += map_hugetlb 5362306a36Sopenharmony_ciTEST_GEN_FILES += map_populate 5462306a36Sopenharmony_ciTEST_GEN_FILES += memfd_secret 5562306a36Sopenharmony_ciTEST_GEN_FILES += migration 5662306a36Sopenharmony_ciTEST_GEN_FILES += mkdirty 5762306a36Sopenharmony_ciTEST_GEN_FILES += mlock-random-test 5862306a36Sopenharmony_ciTEST_GEN_FILES += mlock2-tests 5962306a36Sopenharmony_ciTEST_GEN_FILES += mrelease_test 6062306a36Sopenharmony_ciTEST_GEN_FILES += mremap_dontunmap 6162306a36Sopenharmony_ciTEST_GEN_FILES += mremap_test 6262306a36Sopenharmony_ciTEST_GEN_FILES += on-fault-limit 6362306a36Sopenharmony_ciTEST_GEN_FILES += thuge-gen 6462306a36Sopenharmony_ciTEST_GEN_FILES += transhuge-stress 6562306a36Sopenharmony_ciTEST_GEN_FILES += uffd-stress 6662306a36Sopenharmony_ciTEST_GEN_FILES += uffd-unit-tests 6762306a36Sopenharmony_ciTEST_GEN_FILES += split_huge_page_test 6862306a36Sopenharmony_ciTEST_GEN_FILES += ksm_tests 6962306a36Sopenharmony_ciTEST_GEN_FILES += ksm_functional_tests 7062306a36Sopenharmony_ciTEST_GEN_FILES += mdwe_test 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ciifneq ($(ARCH),arm64) 7362306a36Sopenharmony_ciTEST_GEN_PROGS += soft-dirty 7462306a36Sopenharmony_ciendif 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ciifeq ($(ARCH),x86_64) 7762306a36Sopenharmony_ciCAN_BUILD_I386 := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_32bit_program.c -m32) 7862306a36Sopenharmony_ciCAN_BUILD_X86_64 := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_64bit_program.c) 7962306a36Sopenharmony_ciCAN_BUILD_WITH_NOPIE := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_program.c -no-pie) 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ciVMTARGETS := protection_keys 8262306a36Sopenharmony_ciBINARIES_32 := $(VMTARGETS:%=%_32) 8362306a36Sopenharmony_ciBINARIES_64 := $(VMTARGETS:%=%_64) 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ciifeq ($(CAN_BUILD_WITH_NOPIE),1) 8662306a36Sopenharmony_ciCFLAGS += -no-pie 8762306a36Sopenharmony_ciendif 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ciifeq ($(CAN_BUILD_I386),1) 9062306a36Sopenharmony_ciTEST_GEN_FILES += $(BINARIES_32) 9162306a36Sopenharmony_ciendif 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ciifeq ($(CAN_BUILD_X86_64),1) 9462306a36Sopenharmony_ciTEST_GEN_FILES += $(BINARIES_64) 9562306a36Sopenharmony_ciendif 9662306a36Sopenharmony_cielse 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ciifneq (,$(findstring $(ARCH),ppc64)) 9962306a36Sopenharmony_ciTEST_GEN_FILES += protection_keys 10062306a36Sopenharmony_ciendif 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_ciendif 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ciifneq (,$(filter $(ARCH),arm64 ia64 mips64 parisc64 ppc64 riscv64 s390x sparc64 x86_64)) 10562306a36Sopenharmony_ciTEST_GEN_FILES += va_high_addr_switch 10662306a36Sopenharmony_ciTEST_GEN_FILES += virtual_address_range 10762306a36Sopenharmony_ciTEST_GEN_FILES += write_to_hugetlbfs 10862306a36Sopenharmony_ciendif 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ciTEST_PROGS := run_vmtests.sh 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ciTEST_FILES := test_vmalloc.sh 11362306a36Sopenharmony_ciTEST_FILES += test_hmm.sh 11462306a36Sopenharmony_ciTEST_FILES += va_high_addr_switch.sh 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ciinclude ../lib.mk 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ci$(TEST_GEN_PROGS): vm_util.c 11962306a36Sopenharmony_ci$(TEST_GEN_FILES): vm_util.c 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ci$(OUTPUT)/uffd-stress: uffd-common.c 12262306a36Sopenharmony_ci$(OUTPUT)/uffd-unit-tests: uffd-common.c 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ciifeq ($(ARCH),x86_64) 12562306a36Sopenharmony_ciBINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32)) 12662306a36Sopenharmony_ciBINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64)) 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_cidefine gen-target-rule-32 12962306a36Sopenharmony_ci$(1) $(1)_32: $(OUTPUT)/$(1)_32 13062306a36Sopenharmony_ci.PHONY: $(1) $(1)_32 13162306a36Sopenharmony_ciendef 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_cidefine gen-target-rule-64 13462306a36Sopenharmony_ci$(1) $(1)_64: $(OUTPUT)/$(1)_64 13562306a36Sopenharmony_ci.PHONY: $(1) $(1)_64 13662306a36Sopenharmony_ciendef 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ciifeq ($(CAN_BUILD_I386),1) 13962306a36Sopenharmony_ci$(BINARIES_32): CFLAGS += -m32 -mxsave 14062306a36Sopenharmony_ci$(BINARIES_32): LDLIBS += -lrt -ldl -lm 14162306a36Sopenharmony_ci$(BINARIES_32): $(OUTPUT)/%_32: %.c 14262306a36Sopenharmony_ci $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(notdir $^) $(LDLIBS) -o $@ 14362306a36Sopenharmony_ci$(foreach t,$(VMTARGETS),$(eval $(call gen-target-rule-32,$(t)))) 14462306a36Sopenharmony_ciendif 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ciifeq ($(CAN_BUILD_X86_64),1) 14762306a36Sopenharmony_ci$(BINARIES_64): CFLAGS += -m64 -mxsave 14862306a36Sopenharmony_ci$(BINARIES_64): LDLIBS += -lrt -ldl 14962306a36Sopenharmony_ci$(BINARIES_64): $(OUTPUT)/%_64: %.c 15062306a36Sopenharmony_ci $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(notdir $^) $(LDLIBS) -o $@ 15162306a36Sopenharmony_ci$(foreach t,$(VMTARGETS),$(eval $(call gen-target-rule-64,$(t)))) 15262306a36Sopenharmony_ciendif 15362306a36Sopenharmony_ci 15462306a36Sopenharmony_ci# x86_64 users should be encouraged to install 32-bit libraries 15562306a36Sopenharmony_ciifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),01) 15662306a36Sopenharmony_ciall: warn_32bit_failure 15762306a36Sopenharmony_ci 15862306a36Sopenharmony_ciwarn_32bit_failure: 15962306a36Sopenharmony_ci @echo "Warning: you seem to have a broken 32-bit build" 2>&1; \ 16062306a36Sopenharmony_ci echo "environment. This will reduce test coverage of 64-bit" 2>&1; \ 16162306a36Sopenharmony_ci echo "kernels. If you are using a Debian-like distribution," 2>&1; \ 16262306a36Sopenharmony_ci echo "try:"; 2>&1; \ 16362306a36Sopenharmony_ci echo ""; \ 16462306a36Sopenharmony_ci echo " apt-get install gcc-multilib libc6-i386 libc6-dev-i386"; \ 16562306a36Sopenharmony_ci echo ""; \ 16662306a36Sopenharmony_ci echo "If you are using a Fedora-like distribution, try:"; \ 16762306a36Sopenharmony_ci echo ""; \ 16862306a36Sopenharmony_ci echo " yum install glibc-devel.*i686"; \ 16962306a36Sopenharmony_ci exit 0; 17062306a36Sopenharmony_ciendif 17162306a36Sopenharmony_ciendif 17262306a36Sopenharmony_ci 17362306a36Sopenharmony_ci# IOURING_EXTRA_LIBS may get set in local_config.mk, or it may be left empty. 17462306a36Sopenharmony_ci$(OUTPUT)/cow: LDLIBS += $(IOURING_EXTRA_LIBS) 17562306a36Sopenharmony_ci 17662306a36Sopenharmony_ci$(OUTPUT)/gup_longterm: LDLIBS += $(IOURING_EXTRA_LIBS) 17762306a36Sopenharmony_ci 17862306a36Sopenharmony_ci$(OUTPUT)/mlock-random-test $(OUTPUT)/memfd_secret: LDLIBS += -lcap 17962306a36Sopenharmony_ci 18062306a36Sopenharmony_ci$(OUTPUT)/ksm_tests: LDLIBS += -lnuma 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ci$(OUTPUT)/migration: LDLIBS += -lnuma 18362306a36Sopenharmony_ci 18462306a36Sopenharmony_cilocal_config.mk local_config.h: check_config.sh 18562306a36Sopenharmony_ci /bin/sh ./check_config.sh $(CC) 18662306a36Sopenharmony_ci 18762306a36Sopenharmony_ciEXTRA_CLEAN += local_config.mk local_config.h 18862306a36Sopenharmony_ci 18962306a36Sopenharmony_ciifeq ($(IOURING_EXTRA_LIBS),) 19062306a36Sopenharmony_ciall: warn_missing_liburing 19162306a36Sopenharmony_ci 19262306a36Sopenharmony_ciwarn_missing_liburing: 19362306a36Sopenharmony_ci @echo ; \ 19462306a36Sopenharmony_ci echo "Warning: missing liburing support. Some tests will be skipped." ; \ 19562306a36Sopenharmony_ci echo 19662306a36Sopenharmony_ciendif 197