1include ../scripts/Makefile.include 2 3ifndef MK 4ifeq ($(MAKECMDGOALS),) 5# no target specified, trigger the whole suite 6all: 7 @echo "Testing Makefile"; $(MAKE) -sf tests/make MK=Makefile 8 @echo "Testing Makefile.perf"; $(MAKE) -sf tests/make MK=Makefile.perf SET_PARALLEL=1 SET_O=1 9else 10# run only specific test over 'Makefile' 11%: 12 @echo "Testing Makefile"; $(MAKE) -sf tests/make MK=Makefile $@ 13endif 14else 15PERF := . 16PERF_O := $(PERF) 17O_OPT := 18FULL_O := $(shell readlink -f $(PERF_O) || echo $(PERF_O)) 19 20ifneq ($(O),) 21 FULL_O := $(shell readlink -f $(O) || echo $(O)) 22 PERF_O := $(FULL_O) 23 ifeq ($(SET_O),1) 24 O_OPT := 'O=$(FULL_O)' 25 endif 26 K_O_OPT := 'O=$(FULL_O)' 27endif 28 29PARALLEL_OPT= 30ifeq ($(SET_PARALLEL),1) 31 cores := $(shell (getconf _NPROCESSORS_ONLN || egrep -c '^processor|^CPU[0-9]' /proc/cpuinfo) 2>/dev/null) 32 ifeq ($(cores),0) 33 cores := 1 34 endif 35 PARALLEL_OPT="-j$(cores)" 36endif 37 38# As per kernel Makefile, avoid funny character set dependencies 39unexport LC_ALL 40LC_COLLATE=C 41LC_NUMERIC=C 42export LC_COLLATE LC_NUMERIC 43 44ifeq ($(srctree),) 45srctree := $(patsubst %/,%,$(dir $(shell pwd))) 46srctree := $(patsubst %/,%,$(dir $(srctree))) 47#$(info Determined 'srctree' to be $(srctree)) 48endif 49 50include $(srctree)/tools/scripts/Makefile.arch 51 52# FIXME looks like x86 is the only arch running tests ;-) 53# we need some IS_(32/64) flag to make this generic 54ifeq ($(ARCH)$(IS_64_BIT), x861) 55lib = lib64 56else 57lib = lib 58endif 59 60has = $(shell which $1 2>/dev/null) 61 62# standard single make variable specified 63make_clean_all := clean all 64make_python_perf_so := python/perf.so 65make_debug := DEBUG=1 66make_no_libperl := NO_LIBPERL=1 67make_no_libpython := NO_LIBPYTHON=1 68make_no_scripts := NO_LIBPYTHON=1 NO_LIBPERL=1 69make_no_newt := NO_NEWT=1 70make_no_slang := NO_SLANG=1 71make_no_gtk2 := NO_GTK2=1 72make_no_ui := NO_NEWT=1 NO_SLANG=1 NO_GTK2=1 73make_no_demangle := NO_DEMANGLE=1 74make_no_libelf := NO_LIBELF=1 75make_no_libunwind := NO_LIBUNWIND=1 76make_no_libdw_dwarf_unwind := NO_LIBDW_DWARF_UNWIND=1 77make_no_backtrace := NO_BACKTRACE=1 78make_no_libnuma := NO_LIBNUMA=1 79make_no_libaudit := NO_LIBAUDIT=1 80make_no_libbionic := NO_LIBBIONIC=1 81make_no_auxtrace := NO_AUXTRACE=1 82make_no_libbpf := NO_LIBBPF=1 83make_no_libcrypto := NO_LIBCRYPTO=1 84make_with_babeltrace:= LIBBABELTRACE=1 85make_tags := tags 86make_cscope := cscope 87make_help := help 88make_doc := doc 89make_perf_o := perf.o 90make_util_map_o := util/map.o 91make_util_pmu_bison_o := util/pmu-bison.o 92make_install := install 93make_install_bin := install-bin 94make_install_doc := install-doc 95make_install_man := install-man 96make_install_html := install-html 97make_install_info := install-info 98make_install_pdf := install-pdf 99make_install_prefix := install prefix=/tmp/krava 100make_install_prefix_slash := install prefix=/tmp/krava/ 101make_static := LDFLAGS=-static 102 103# all the NO_* variable combined 104make_minimal := NO_LIBPERL=1 NO_LIBPYTHON=1 NO_NEWT=1 NO_GTK2=1 105make_minimal += NO_DEMANGLE=1 NO_LIBELF=1 NO_LIBUNWIND=1 NO_BACKTRACE=1 106make_minimal += NO_LIBNUMA=1 NO_LIBAUDIT=1 NO_LIBBIONIC=1 107make_minimal += NO_LIBDW_DWARF_UNWIND=1 NO_AUXTRACE=1 NO_LIBBPF=1 108make_minimal += NO_LIBCRYPTO=1 109 110# $(run) contains all available tests 111run := make_pure 112# Targets 'clean all' can be run together only through top level 113# Makefile because we detect clean target in Makefile.perf and 114# disable features detection 115ifeq ($(MK),Makefile) 116run += make_clean_all 117MAKE_F := $(MAKE) 118else 119MAKE_F := $(MAKE) -f $(MK) 120endif 121run += make_python_perf_so 122run += make_debug 123run += make_no_libperl 124run += make_no_libpython 125run += make_no_scripts 126run += make_no_newt 127run += make_no_slang 128run += make_no_gtk2 129run += make_no_ui 130run += make_no_demangle 131run += make_no_libelf 132run += make_no_libunwind 133run += make_no_libdw_dwarf_unwind 134run += make_no_backtrace 135run += make_no_libnuma 136run += make_no_libaudit 137run += make_no_libbionic 138run += make_no_auxtrace 139run += make_no_libbpf 140run += make_with_babeltrace 141run += make_help 142run += make_doc 143run += make_perf_o 144run += make_util_map_o 145run += make_util_pmu_bison_o 146run += make_install 147run += make_install_bin 148run += make_install_prefix 149run += make_install_prefix_slash 150# FIXME 'install-*' commented out till they're fixed 151# run += make_install_doc 152# run += make_install_man 153# run += make_install_html 154# run += make_install_info 155# run += make_install_pdf 156run += make_minimal 157run += make_static 158 159ifneq ($(call has,ctags),) 160run += make_tags 161endif 162ifneq ($(call has,cscope),) 163run += make_cscope 164endif 165 166# $(run_O) contains same portion of $(run) tests with '_O' attached 167# to distinguish O=... tests 168run_O := $(addsuffix _O,$(run)) 169 170# disable some tests for O=... 171run_O := $(filter-out make_python_perf_so_O,$(run_O)) 172 173# define test for each compile as 'test_NAME' variable 174# with the test itself as a value 175test_make_tags = test -f tags 176test_make_cscope = test -f cscope.out 177 178test_make_tags_O := $(test_make_tags) 179test_make_cscope_O := $(test_make_cscope) 180 181test_ok := true 182test_make_help := $(test_ok) 183test_make_doc := $(test_ok) 184test_make_help_O := $(test_ok) 185test_make_doc_O := $(test_ok) 186 187test_make_python_perf_so := test -f $(PERF_O)/python/perf.so 188 189test_make_perf_o := test -f $(PERF_O)/perf.o 190test_make_util_map_o := test -f $(PERF_O)/util/map.o 191test_make_util_pmu_bison_o := test -f $(PERF_O)/util/pmu-bison.o 192 193define test_dest_files 194 for file in $(1); do \ 195 if [ ! -x $$TMP_DEST/$$file ]; then \ 196 echo " failed to find: $$file"; \ 197 fi \ 198 done 199endef 200 201installed_files_bin := bin/perf 202installed_files_bin += etc/bash_completion.d/perf 203installed_files_bin += libexec/perf-core/perf-archive 204 205installed_files_plugins := $(lib)/traceevent/plugins/plugin_cfg80211.so 206installed_files_plugins += $(lib)/traceevent/plugins/plugin_scsi.so 207installed_files_plugins += $(lib)/traceevent/plugins/plugin_xen.so 208installed_files_plugins += $(lib)/traceevent/plugins/plugin_function.so 209installed_files_plugins += $(lib)/traceevent/plugins/plugin_sched_switch.so 210installed_files_plugins += $(lib)/traceevent/plugins/plugin_mac80211.so 211installed_files_plugins += $(lib)/traceevent/plugins/plugin_kvm.so 212installed_files_plugins += $(lib)/traceevent/plugins/plugin_kmem.so 213installed_files_plugins += $(lib)/traceevent/plugins/plugin_hrtimer.so 214installed_files_plugins += $(lib)/traceevent/plugins/plugin_jbd2.so 215 216installed_files_all := $(installed_files_bin) 217installed_files_all += $(installed_files_plugins) 218 219test_make_install := $(call test_dest_files,$(installed_files_all)) 220test_make_install_O := $(call test_dest_files,$(installed_files_all)) 221test_make_install_bin := $(call test_dest_files,$(installed_files_bin)) 222test_make_install_bin_O := $(call test_dest_files,$(installed_files_bin)) 223 224# We prefix all installed files for make_install_prefix(_slash) 225# with '/tmp/krava' to match installed/prefix-ed files. 226installed_files_all_prefix := $(addprefix /tmp/krava/,$(installed_files_all)) 227test_make_install_prefix := $(call test_dest_files,$(installed_files_all_prefix)) 228test_make_install_prefix_O := $(call test_dest_files,$(installed_files_all_prefix)) 229 230test_make_install_prefix_slash := $(test_make_install_prefix) 231test_make_install_prefix_slash_O := $(test_make_install_prefix_O) 232 233# FIXME nothing gets installed 234test_make_install_man := test -f $$TMP_DEST/share/man/man1/perf.1 235test_make_install_man_O := $(test_make_install_man) 236 237# FIXME nothing gets installed 238test_make_install_doc := $(test_ok) 239test_make_install_doc_O := $(test_ok) 240 241# FIXME nothing gets installed 242test_make_install_html := $(test_ok) 243test_make_install_html_O := $(test_ok) 244 245# FIXME nothing gets installed 246test_make_install_info := $(test_ok) 247test_make_install_info_O := $(test_ok) 248 249# FIXME nothing gets installed 250test_make_install_pdf := $(test_ok) 251test_make_install_pdf_O := $(test_ok) 252 253test_make_python_perf_so_O := test -f $$TMP_O/python/perf.so 254test_make_perf_o_O := test -f $$TMP_O/perf.o 255test_make_util_map_o_O := test -f $$TMP_O/util/map.o 256test_make_util_pmu_bison_o_O := test -f $$TMP_O/util/pmu-bison.o 257 258test_default = test -x $(PERF_O)/perf 259test = $(if $(test_$1),$(test_$1),$(test_default)) 260 261test_default_O = test -x $$TMP_O/perf 262test_O = $(if $(test_$1),$(test_$1),$(test_default_O)) 263 264all: 265 266ifdef SHUF 267run := $(shell shuf -e $(run)) 268run_O := $(shell shuf -e $(run_O)) 269endif 270 271max_width := $(shell echo $(run_O) | sed 's/ /\n/g' | wc -L) 272 273ifdef DEBUG 274d := $(info run $(run)) 275d := $(info run_O $(run_O)) 276endif 277 278MAKEFLAGS := --no-print-directory 279 280clean := @(cd $(PERF); $(MAKE_F) -s $(O_OPT) clean >/dev/null) 281 282$(run): 283 $(call clean) 284 @TMP_DEST=$$(mktemp -d); \ 285 cmd="cd $(PERF) && $(MAKE_F) $($@) $(PARALLEL_OPT) $(O_OPT) DESTDIR=$$TMP_DEST"; \ 286 printf "%*.*s: %s\n" $(max_width) $(max_width) "$@" "$$cmd" && echo $$cmd > $@ && \ 287 ( eval $$cmd ) >> $@ 2>&1; \ 288 echo " test: $(call test,$@)" >> $@ 2>&1; \ 289 $(call test,$@) && \ 290 rm -rf $@ $$TMP_DEST || (cat $@ ; false) 291 292$(run_O): 293 $(call clean) 294 @TMP_O=$$(mktemp -d); \ 295 TMP_DEST=$$(mktemp -d); \ 296 cmd="cd $(PERF) && $(MAKE_F) $($(patsubst %_O,%,$@)) $(PARALLEL_OPT) O=$$TMP_O DESTDIR=$$TMP_DEST"; \ 297 printf "%*.*s: %s\n" $(max_width) $(max_width) "$@" "$$cmd" && echo $$cmd > $@ && \ 298 ( eval $$cmd ) >> $@ 2>&1 && \ 299 echo " test: $(call test_O,$@)" >> $@ 2>&1; \ 300 $(call test_O,$@) && \ 301 rm -rf $@ $$TMP_O $$TMP_DEST || (cat $@ ; false) 302 303tarpkg: 304 @cmd="$(PERF)/tests/perf-targz-src-pkg $(PERF)"; \ 305 echo "- $@: $$cmd" && echo $$cmd > $@ && \ 306 ( eval $$cmd ) >> $@ 2>&1 && \ 307 rm -f $@ 308 309KERNEL_O := ../.. 310ifneq ($(O),) 311 KERNEL_O := $(O) 312endif 313 314make_kernelsrc: 315 @echo "- make -C <kernelsrc> $(PARALLEL_OPT) $(K_O_OPT) tools/perf" 316 $(call clean); \ 317 (make -C ../.. $(PARALLEL_OPT) $(K_O_OPT) tools/perf) > $@ 2>&1 && \ 318 test -x $(KERNEL_O)/tools/perf/perf && rm -f $@ || (cat $@ ; false) 319 320make_kernelsrc_tools: 321 @echo "- make -C <kernelsrc>/tools $(PARALLEL_OPT) $(K_O_OPT) perf" 322 $(call clean); \ 323 (make -C ../../tools $(PARALLEL_OPT) $(K_O_OPT) perf) > $@ 2>&1 && \ 324 test -x $(KERNEL_O)/tools/perf/perf && rm -f $@ || (cat $@ ; false) 325 326FEATURES_DUMP_FILE := $(FULL_O)/BUILD_TEST_FEATURE_DUMP 327FEATURES_DUMP_FILE_STATIC := $(FULL_O)/BUILD_TEST_FEATURE_DUMP_STATIC 328 329all: $(run) $(run_O) tarpkg make_kernelsrc make_kernelsrc_tools 330 @echo OK 331 @rm -f $(FEATURES_DUMP_FILE) $(FEATURES_DUMP_FILE_STATIC) 332 333out: $(run_O) 334 @echo OK 335 @rm -f $(FEATURES_DUMP_FILE) $(FEATURES_DUMP_FILE_STATIC) 336 337ifeq ($(REUSE_FEATURES_DUMP),1) 338$(FEATURES_DUMP_FILE): 339 $(call clean) 340 @cmd="cd $(PERF) && make FEATURE_DUMP_COPY=$@ $(O_OPT) feature-dump"; \ 341 echo "- $@: $$cmd" && echo $$cmd && \ 342 ( eval $$cmd ) > /dev/null 2>&1 343 344$(FEATURES_DUMP_FILE_STATIC): 345 $(call clean) 346 @cmd="cd $(PERF) && make FEATURE_DUMP_COPY=$@ $(O_OPT) LDFLAGS='-static' feature-dump"; \ 347 echo "- $@: $$cmd" && echo $$cmd && \ 348 ( eval $$cmd ) > /dev/null 2>&1 349 350# Add feature dump dependency for run/run_O targets 351$(foreach t,$(run) $(run_O),$(eval \ 352 $(t): $(if $(findstring make_static,$(t)),\ 353 $(FEATURES_DUMP_FILE_STATIC),\ 354 $(FEATURES_DUMP_FILE)))) 355 356# Append 'FEATURES_DUMP=' option to all test cases. For example: 357# make_no_libbpf: NO_LIBBPF=1 --> NO_LIBBPF=1 FEATURES_DUMP=/a/b/BUILD_TEST_FEATURE_DUMP 358# make_static: LDFLAGS=-static --> LDFLAGS=-static FEATURES_DUMP=/a/b/BUILD_TEST_FEATURE_DUMP_STATIC 359$(foreach t,$(run),$(if $(findstring make_static,$(t)),\ 360 $(eval $(t) := $($(t)) FEATURES_DUMP=$(FEATURES_DUMP_FILE_STATIC)),\ 361 $(eval $(t) := $($(t)) FEATURES_DUMP=$(FEATURES_DUMP_FILE)))) 362endif 363 364.PHONY: all $(run) $(run_O) tarpkg clean make_kernelsrc make_kernelsrc_tools 365endif # ifndef MK 366