0001 include ../scripts/Makefile.include
0002
0003 ifndef MK
0004 ifeq ($(MAKECMDGOALS),)
0005 # no target specified, trigger the whole suite
0006 all:
0007 @echo "Testing Makefile"; $(MAKE) -sf tests/make MK=Makefile
0008 @echo "Testing Makefile.perf"; $(MAKE) -sf tests/make MK=Makefile.perf SET_PARALLEL=1 SET_O=1
0009 else
0010 # run only specific test over 'Makefile'
0011 %:
0012 @echo "Testing Makefile"; $(MAKE) -sf tests/make MK=Makefile $@
0013 endif
0014 else
0015 PERF := .
0016 PERF_O := $(PERF)
0017 O_OPT :=
0018 FULL_O := $(shell readlink -f $(PERF_O) || echo $(PERF_O))
0019
0020 ifneq ($(O),)
0021 FULL_O := $(shell readlink -f $(O) || echo $(O))
0022 PERF_O := $(FULL_O)
0023 ifeq ($(SET_O),1)
0024 O_OPT := 'O=$(FULL_O)'
0025 endif
0026 K_O_OPT := 'O=$(FULL_O)'
0027 endif
0028
0029 PARALLEL_OPT=
0030 ifeq ($(SET_PARALLEL),1)
0031 ifeq ($(JOBS),)
0032 cores := $(shell (getconf _NPROCESSORS_ONLN || egrep -c '^processor|^CPU[0-9]' /proc/cpuinfo) 2>/dev/null)
0033 ifeq ($(cores),0)
0034 cores := 1
0035 endif
0036 else
0037 cores=$(JOBS)
0038 endif
0039 PARALLEL_OPT="-j$(cores)"
0040 endif
0041
0042 # As per kernel Makefile, avoid funny character set dependencies
0043 unexport LC_ALL
0044 LC_COLLATE=C
0045 LC_NUMERIC=C
0046 export LC_COLLATE LC_NUMERIC
0047
0048 ifeq ($(srctree),)
0049 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
0050 srctree := $(patsubst %/,%,$(dir $(srctree)))
0051 #$(info Determined 'srctree' to be $(srctree))
0052 endif
0053
0054 include $(srctree)/tools/scripts/Makefile.arch
0055
0056 # FIXME looks like x86 is the only arch running tests ;-)
0057 # we need some IS_(32/64) flag to make this generic
0058 ifeq ($(ARCH)$(IS_64_BIT), x861)
0059 lib = lib64
0060 else
0061 lib = lib
0062 endif
0063
0064 has = $(shell which $1 2>/dev/null)
0065
0066 # standard single make variable specified
0067 make_clean_all := clean all
0068 make_python_perf_so := python/perf.so
0069 make_debug := DEBUG=1
0070 make_no_libperl := NO_LIBPERL=1
0071 make_no_libpython := NO_LIBPYTHON=1
0072 make_no_scripts := NO_LIBPYTHON=1 NO_LIBPERL=1
0073 make_no_newt := NO_NEWT=1
0074 make_no_slang := NO_SLANG=1
0075 make_no_gtk2 := NO_GTK2=1
0076 make_no_ui := NO_NEWT=1 NO_SLANG=1 NO_GTK2=1
0077 make_no_demangle := NO_DEMANGLE=1
0078 make_no_libelf := NO_LIBELF=1
0079 make_no_libunwind := NO_LIBUNWIND=1
0080 make_no_libdw_dwarf_unwind := NO_LIBDW_DWARF_UNWIND=1
0081 make_no_backtrace := NO_BACKTRACE=1
0082 make_no_libnuma := NO_LIBNUMA=1
0083 make_no_libaudit := NO_LIBAUDIT=1
0084 make_no_libbionic := NO_LIBBIONIC=1
0085 make_no_auxtrace := NO_AUXTRACE=1
0086 make_no_libbpf := NO_LIBBPF=1
0087 make_libbpf_dynamic := LIBBPF_DYNAMIC=1
0088 make_no_libbpf_DEBUG := NO_LIBBPF=1 DEBUG=1
0089 make_no_libcrypto := NO_LIBCRYPTO=1
0090 make_with_babeltrace:= LIBBABELTRACE=1
0091 make_with_coresight := CORESIGHT=1
0092 make_no_sdt := NO_SDT=1
0093 make_no_syscall_tbl := NO_SYSCALL_TABLE=1
0094 make_with_clangllvm := LIBCLANGLLVM=1
0095 make_with_libpfm4 := LIBPFM4=1
0096 make_with_gtk2 := GTK2=1
0097 make_tags := tags
0098 make_cscope := cscope
0099 make_help := help
0100 make_doc := doc
0101 make_perf_o := perf.o
0102 make_util_map_o := util/map.o
0103 make_util_pmu_bison_o := util/pmu-bison.o
0104 make_install := install
0105 make_install_bin := install-bin
0106 make_install_doc := install-doc
0107 make_install_man := install-man
0108 make_install_html := install-html
0109 make_install_info := install-info
0110 make_install_pdf := install-pdf
0111 make_install_prefix := install prefix=/tmp/krava
0112 make_install_prefix_slash := install prefix=/tmp/krava/
0113 make_static := LDFLAGS=-static NO_PERF_READ_VDSO32=1 NO_PERF_READ_VDSOX32=1 NO_JVMTI=1
0114
0115 # all the NO_* variable combined
0116 make_minimal := NO_LIBPERL=1 NO_LIBPYTHON=1 NO_NEWT=1 NO_GTK2=1
0117 make_minimal += NO_DEMANGLE=1 NO_LIBELF=1 NO_LIBUNWIND=1 NO_BACKTRACE=1
0118 make_minimal += NO_LIBNUMA=1 NO_LIBAUDIT=1 NO_LIBBIONIC=1
0119 make_minimal += NO_LIBDW_DWARF_UNWIND=1 NO_AUXTRACE=1 NO_LIBBPF=1
0120 make_minimal += NO_LIBCRYPTO=1 NO_SDT=1 NO_JVMTI=1 NO_LIBZSTD=1
0121 make_minimal += NO_LIBCAP=1 NO_SYSCALL_TABLE=1
0122
0123 # $(run) contains all available tests
0124 run := make_pure
0125 # Targets 'clean all' can be run together only through top level
0126 # Makefile because we detect clean target in Makefile.perf and
0127 # disable features detection
0128 ifeq ($(MK),Makefile)
0129 run += make_clean_all
0130 MAKE_F := $(MAKE)
0131 else
0132 MAKE_F := $(MAKE) -f $(MK)
0133 endif
0134 run += make_python_perf_so
0135 run += make_debug
0136 run += make_no_libperl
0137 run += make_no_libpython
0138 run += make_no_scripts
0139 run += make_no_newt
0140 run += make_no_slang
0141 run += make_no_gtk2
0142 run += make_no_ui
0143 run += make_no_demangle
0144 run += make_no_libelf
0145 run += make_no_libunwind
0146 run += make_no_libdw_dwarf_unwind
0147 run += make_no_backtrace
0148 run += make_no_libnuma
0149 run += make_no_libaudit
0150 run += make_no_libbionic
0151 run += make_no_auxtrace
0152 run += make_no_libbpf
0153 run += make_libbpf_dynamic
0154 run += make_no_libbpf_DEBUG
0155 run += make_no_libcrypto
0156 run += make_no_sdt
0157 run += make_no_syscall_tbl
0158 run += make_with_babeltrace
0159 run += make_with_coresight
0160 run += make_with_clangllvm
0161 run += make_with_libpfm4
0162 run += make_help
0163 run += make_doc
0164 run += make_perf_o
0165 run += make_util_map_o
0166 run += make_util_pmu_bison_o
0167 run += make_install
0168 run += make_install_bin
0169 run += make_install_prefix
0170 run += make_install_prefix_slash
0171 # FIXME 'install-*' commented out till they're fixed
0172 # run += make_install_doc
0173 # run += make_install_man
0174 # run += make_install_html
0175 # run += make_install_info
0176 # run += make_install_pdf
0177 run += make_minimal
0178
0179 ifneq ($(call has,ctags),)
0180 run += make_tags
0181 endif
0182 ifneq ($(call has,cscope),)
0183 run += make_cscope
0184 endif
0185
0186 # $(run_O) contains same portion of $(run) tests with '_O' attached
0187 # to distinguish O=... tests
0188 run_O := $(addsuffix _O,$(run))
0189
0190 # disable some tests for O=...
0191 run_O := $(filter-out make_python_perf_so_O,$(run_O))
0192
0193 # define test for each compile as 'test_NAME' variable
0194 # with the test itself as a value
0195 test_make_tags = test -f tags
0196 test_make_cscope = test -f cscope.out
0197
0198 test_make_tags_O := $(test_make_tags)
0199 test_make_cscope_O := $(test_make_cscope)
0200
0201 test_ok := true
0202 test_make_help := $(test_ok)
0203 test_make_doc := $(test_ok)
0204 test_make_help_O := $(test_ok)
0205 test_make_doc_O := $(test_ok)
0206
0207 test_make_python_perf_so := test -f $(PERF_O)/python/perf.so
0208
0209 test_make_perf_o := test -f $(PERF_O)/perf.o
0210 test_make_util_map_o := test -f $(PERF_O)/util/map.o
0211 test_make_util_pmu_bison_o := test -f $(PERF_O)/util/pmu-bison.o
0212
0213 define test_dest_files
0214 for file in $(1); do \
0215 if [ ! -x $$TMP_DEST/$$file ]; then \
0216 echo " failed to find: $$file"; \
0217 fi \
0218 done
0219 endef
0220
0221 installed_files_bin := bin/perf
0222 installed_files_bin += etc/bash_completion.d/perf
0223 installed_files_bin += libexec/perf-core/perf-archive
0224
0225 installed_files_plugins := $(lib)/traceevent/plugins/plugin_cfg80211.so
0226 installed_files_plugins += $(lib)/traceevent/plugins/plugin_scsi.so
0227 installed_files_plugins += $(lib)/traceevent/plugins/plugin_xen.so
0228 installed_files_plugins += $(lib)/traceevent/plugins/plugin_function.so
0229 installed_files_plugins += $(lib)/traceevent/plugins/plugin_sched_switch.so
0230 installed_files_plugins += $(lib)/traceevent/plugins/plugin_mac80211.so
0231 installed_files_plugins += $(lib)/traceevent/plugins/plugin_kvm.so
0232 installed_files_plugins += $(lib)/traceevent/plugins/plugin_kmem.so
0233 installed_files_plugins += $(lib)/traceevent/plugins/plugin_hrtimer.so
0234 installed_files_plugins += $(lib)/traceevent/plugins/plugin_jbd2.so
0235
0236 installed_files_all := $(installed_files_bin)
0237 installed_files_all += $(installed_files_plugins)
0238
0239 test_make_install := $(call test_dest_files,$(installed_files_all))
0240 test_make_install_O := $(call test_dest_files,$(installed_files_all))
0241 test_make_install_bin := $(call test_dest_files,$(installed_files_bin))
0242 test_make_install_bin_O := $(call test_dest_files,$(installed_files_bin))
0243
0244 # We prefix all installed files for make_install_prefix(_slash)
0245 # with '/tmp/krava' to match installed/prefix-ed files.
0246 installed_files_all_prefix := $(addprefix /tmp/krava/,$(installed_files_all))
0247 test_make_install_prefix := $(call test_dest_files,$(installed_files_all_prefix))
0248 test_make_install_prefix_O := $(call test_dest_files,$(installed_files_all_prefix))
0249
0250 test_make_install_prefix_slash := $(test_make_install_prefix)
0251 test_make_install_prefix_slash_O := $(test_make_install_prefix_O)
0252
0253 # FIXME nothing gets installed
0254 test_make_install_man := test -f $$TMP_DEST/share/man/man1/perf.1
0255 test_make_install_man_O := $(test_make_install_man)
0256
0257 # FIXME nothing gets installed
0258 test_make_install_doc := $(test_ok)
0259 test_make_install_doc_O := $(test_ok)
0260
0261 # FIXME nothing gets installed
0262 test_make_install_html := $(test_ok)
0263 test_make_install_html_O := $(test_ok)
0264
0265 # FIXME nothing gets installed
0266 test_make_install_info := $(test_ok)
0267 test_make_install_info_O := $(test_ok)
0268
0269 # FIXME nothing gets installed
0270 test_make_install_pdf := $(test_ok)
0271 test_make_install_pdf_O := $(test_ok)
0272
0273 test_make_libbpf_dynamic := ldd $(PERF_O)/perf | grep -q libbpf
0274 test_make_libbpf_dynamic_O := ldd $$TMP_O/perf | grep -q libbpf
0275
0276 test_make_python_perf_so_O := test -f $$TMP_O/python/perf.so
0277 test_make_perf_o_O := test -f $$TMP_O/perf.o
0278 test_make_util_map_o_O := test -f $$TMP_O/util/map.o
0279 test_make_util_pmu_bison_o_O := test -f $$TMP_O/util/pmu-bison.o
0280
0281 test_default = test -x $(PERF_O)/perf
0282 test = $(if $(test_$1),$(test_$1),$(test_default))
0283
0284 test_default_O = test -x $$TMP_O/perf
0285 test_O = $(if $(test_$1),$(test_$1),$(test_default_O))
0286
0287 all:
0288
0289 ifdef SHUF
0290 run := $(shell shuf -e $(run))
0291 run_O := $(shell shuf -e $(run_O))
0292 endif
0293
0294 max_width := $(shell echo $(run_O) | sed 's/ /\n/g' | wc -L)
0295
0296 ifdef DEBUG
0297 d := $(info run $(run))
0298 d := $(info run_O $(run_O))
0299 endif
0300
0301 MAKEFLAGS := --no-print-directory
0302
0303 clean := @(cd $(PERF); $(MAKE_F) -s $(O_OPT) clean >/dev/null && $(MAKE) -s $(O_OPT) -C ../build clean >/dev/null)
0304
0305 $(run):
0306 $(call clean)
0307 @TMP_DEST=$$(mktemp -d); \
0308 cmd="cd $(PERF) && $(MAKE_F) $($@) $(PARALLEL_OPT) $(O_OPT) DESTDIR=$$TMP_DEST"; \
0309 printf "%*.*s: %s\n" $(max_width) $(max_width) "$@" "$$cmd" && echo $$cmd > $@ && \
0310 ( eval $$cmd ) >> $@ 2>&1; \
0311 echo " test: $(call test,$@)" >> $@ 2>&1; \
0312 $(call test,$@) && \
0313 rm -rf $@ $$TMP_DEST || (cat $@ ; false)
0314
0315 make_with_gtk2:
0316 $(call clean)
0317 @TMP_DEST=$$(mktemp -d); \
0318 cmd="cd $(PERF) && $(MAKE_F) $($@) $(PARALLEL_OPT) $(O_OPT) DESTDIR=$$TMP_DEST"; \
0319 printf "%*.*s: %s\n" $(max_width) $(max_width) "$@" "$$cmd" && echo $$cmd > $@ && \
0320 ( eval $$cmd ) >> $@ 2>&1; \
0321 echo " test: $(call test,$@)" >> $@ 2>&1; \
0322 $(call test,$@) && \
0323 rm -rf $@ $$TMP_DEST || (cat $@ ; false)
0324
0325 make_static:
0326 $(call clean)
0327 @TMP_DEST=$$(mktemp -d); \
0328 cmd="cd $(PERF) && $(MAKE_F) $($@) $(PARALLEL_OPT) $(O_OPT) DESTDIR=$$TMP_DEST"; \
0329 printf "%*.*s: %s\n" $(max_width) $(max_width) "$@" "$$cmd" && echo $$cmd > $@ && \
0330 ( eval $$cmd ) >> $@ 2>&1; \
0331 echo " test: $(call test,$@)" >> $@ 2>&1; \
0332 $(call test,$@) && \
0333 rm -rf $@ $$TMP_DEST || (cat $@ ; false)
0334
0335 $(run_O):
0336 $(call clean)
0337 @TMP_O=$$(mktemp -d); \
0338 TMP_DEST=$$(mktemp -d); \
0339 cmd="cd $(PERF) && $(MAKE_F) $($(patsubst %_O,%,$@)) $(PARALLEL_OPT) O=$$TMP_O DESTDIR=$$TMP_DEST"; \
0340 printf "%*.*s: %s\n" $(max_width) $(max_width) "$@" "$$cmd" && echo $$cmd > $@ && \
0341 ( eval $$cmd ) >> $@ 2>&1 && \
0342 echo " test: $(call test_O,$@)" >> $@ 2>&1; \
0343 $(call test_O,$@) && \
0344 rm -rf $@ $$TMP_O $$TMP_DEST || (cat $@ ; false)
0345
0346 tarpkg:
0347 @cmd="$(PERF)/tests/perf-targz-src-pkg $(PERF)"; \
0348 echo "- $@: $$cmd" && echo $$cmd > $@ && \
0349 ( eval $$cmd ) >> $@ 2>&1 && \
0350 rm -f $@
0351
0352 KERNEL_O := ../..
0353 ifneq ($(O),)
0354 KERNEL_O := $(O)
0355 endif
0356
0357 make_kernelsrc:
0358 @echo "- make -C <kernelsrc> $(PARALLEL_OPT) $(K_O_OPT) tools/perf"
0359 $(call clean); \
0360 (make -C ../.. $(PARALLEL_OPT) $(K_O_OPT) tools/perf) > $@ 2>&1 && \
0361 test -x $(KERNEL_O)/tools/perf/perf && rm -f $@ || (cat $@ ; false)
0362
0363 make_kernelsrc_tools:
0364 @echo "- make -C <kernelsrc>/tools $(PARALLEL_OPT) $(K_O_OPT) perf"
0365 $(call clean); \
0366 (make -C ../../tools $(PARALLEL_OPT) $(K_O_OPT) perf) > $@ 2>&1 && \
0367 test -x $(KERNEL_O)/tools/perf/perf && rm -f $@ || (cat $@ ; false)
0368
0369 make_libperf:
0370 @echo "- make -C lib";
0371 make -C lib clean >$@ 2>&1; make -C lib >>$@ 2>&1 && rm $@
0372
0373 FEATURES_DUMP_FILE := $(FULL_O)/BUILD_TEST_FEATURE_DUMP
0374 FEATURES_DUMP_FILE_STATIC := $(FULL_O)/BUILD_TEST_FEATURE_DUMP_STATIC
0375
0376 all: $(run) $(run_O) tarpkg make_kernelsrc make_kernelsrc_tools
0377 @echo OK
0378 @rm -f $(FEATURES_DUMP_FILE) $(FEATURES_DUMP_FILE_STATIC)
0379
0380 out: $(run_O)
0381 @echo OK
0382 @rm -f $(FEATURES_DUMP_FILE) $(FEATURES_DUMP_FILE_STATIC)
0383
0384 ifeq ($(REUSE_FEATURES_DUMP),1)
0385 $(FEATURES_DUMP_FILE):
0386 $(call clean)
0387 @cmd="cd $(PERF) && make FEATURE_DUMP_COPY=$@ $(O_OPT) feature-dump"; \
0388 echo "- $@: $$cmd" && echo $$cmd && \
0389 ( eval $$cmd ) > /dev/null 2>&1
0390
0391 $(FEATURES_DUMP_FILE_STATIC):
0392 $(call clean)
0393 @cmd="cd $(PERF) && make FEATURE_DUMP_COPY=$@ $(O_OPT) LDFLAGS='-static' feature-dump"; \
0394 echo "- $@: $$cmd" && echo $$cmd && \
0395 ( eval $$cmd ) > /dev/null 2>&1
0396
0397 # Add feature dump dependency for run/run_O targets
0398 $(foreach t,$(run) $(run_O),$(eval \
0399 $(t): $(if $(findstring make_static,$(t)),\
0400 $(FEATURES_DUMP_FILE_STATIC),\
0401 $(FEATURES_DUMP_FILE))))
0402
0403 # Append 'FEATURES_DUMP=' option to all test cases. For example:
0404 # make_no_libbpf: NO_LIBBPF=1 --> NO_LIBBPF=1 FEATURES_DUMP=/a/b/BUILD_TEST_FEATURE_DUMP
0405 # make_static: LDFLAGS=-static --> LDFLAGS=-static FEATURES_DUMP=/a/b/BUILD_TEST_FEATURE_DUMP_STATIC
0406 $(foreach t,$(run),$(if $(findstring make_static,$(t)),\
0407 $(eval $(t) := $($(t)) FEATURES_DUMP=$(FEATURES_DUMP_FILE_STATIC)),\
0408 $(eval $(t) := $($(t)) FEATURES_DUMP=$(FEATURES_DUMP_FILE))))
0409 endif
0410
0411 .PHONY: all $(run) $(run_O) tarpkg clean make_kernelsrc make_kernelsrc_tools make_libperf
0412 endif # ifndef MK