2016-01-11 13:47:58 +00:00
include ../scripts/Makefile.include
2015-06-22 14:50:50 +02:00
ifndef MK
ifeq ($(MAKECMDGOALS),)
# no target specified, trigger the whole suite
all:
@echo "Testing Makefile"; $(MAKE) -sf tests/make MK=Makefile
2016-01-15 04:00:14 +00:00
@echo "Testing Makefile.perf"; $(MAKE) -sf tests/make MK=Makefile.perf SET_PARALLEL=1 SET_O=1
2015-06-22 14:50:50 +02:00
else
# run only specific test over 'Makefile'
%:
@echo "Testing Makefile"; $(MAKE) -sf tests/make MK=Makefile $@
endif
else
2013-03-29 16:11:02 +01:00
PERF := .
2016-01-15 04:00:15 +00:00
PERF_O := $(PERF)
2016-01-15 04:00:14 +00:00
O_OPT :=
2016-01-29 11:51:09 +00:00
FULL_O := $(shell readlink -f $(PERF_O) || echo $(PERF_O))
2016-01-15 04:00:14 +00:00
ifneq ($(O),)
FULL_O := $(shell readlink -f $(O) || echo $(O))
2016-01-15 04:00:15 +00:00
PERF_O := $(FULL_O)
2016-01-15 04:00:14 +00:00
ifeq ($(SET_O),1)
O_OPT := 'O=$(FULL_O)'
endif
2016-01-15 04:00:16 +00:00
K_O_OPT := 'O=$(FULL_O)'
2016-01-15 04:00:14 +00:00
endif
2013-03-29 16:11:02 +01:00
2016-01-13 12:17:14 +00:00
PARALLEL_OPT=
ifeq ($(SET_PARALLEL),1)
2020-03-30 09:32:41 -03:00
ifeq ($(JOBS),)
2022-11-18 17:16:39 +08:00
cores := $(shell (getconf _NPROCESSORS_ONLN || grep -E -c '^processor|^CPU[0-9]' /proc/cpuinfo) 2>/dev/null)
2020-03-30 09:32:41 -03:00
ifeq ($(cores),0)
cores := 1
endif
else
cores=$(JOBS)
2016-01-13 12:17:14 +00:00
endif
PARALLEL_OPT="-j$(cores)"
endif
2016-01-11 13:47:58 +00:00
# As per kernel Makefile, avoid funny character set dependencies
unexport LC_ALL
LC_COLLATE=C
LC_NUMERIC=C
export LC_COLLATE LC_NUMERIC
ifeq ($(srctree),)
2016-11-22 09:30:26 +01:00
srctree := $(patsubst %/,%,$(dir $(CURDIR)))
2016-01-11 13:47:58 +00:00
srctree := $(patsubst %/,%,$(dir $(srctree)))
#$(info Determined 'srctree' to be $(srctree))
endif
include $(srctree)/tools/scripts/Makefile.arch
2014-01-03 15:32:33 +01:00
# FIXME looks like x86 is the only arch running tests ;-)
# we need some IS_(32/64) flag to make this generic
2015-03-17 15:27:48 -07:00
ifeq ($(ARCH)$(IS_64_BIT), x861)
2014-01-03 15:32:33 +01:00
lib = lib64
else
lib = lib
endif
2013-07-22 14:43:30 +02:00
has = $(shell which $1 2>/dev/null)
2023-03-10 22:57:41 -08:00
python_perf_so := $(shell $(MAKE) python_perf_target|grep "Target is:"|awk '{print $$3}')
2013-07-22 14:43:30 +02:00
2013-03-29 16:11:02 +01:00
# standard single make variable specified
make_clean_all := clean all
2023-03-10 22:57:41 -08:00
make_python_perf_so := $(python_perf_so)
2013-03-29 16:11:02 +01:00
make_debug := DEBUG=1
2023-03-10 22:57:47 -08:00
make_nondistro := BUILD_NONDISTRO=1
2013-03-29 16:11:02 +01:00
make_no_libperl := NO_LIBPERL=1
make_no_libpython := NO_LIBPYTHON=1
make_no_scripts := NO_LIBPYTHON=1 NO_LIBPERL=1
make_no_slang := NO_SLANG=1
make_no_gtk2 := NO_GTK2=1
2023-03-10 22:57:53 -08:00
make_no_ui := NO_SLANG=1 NO_GTK2=1
2013-03-29 16:11:02 +01:00
make_no_demangle := NO_DEMANGLE=1
make_no_libelf := NO_LIBELF=1
make_no_libunwind := NO_LIBUNWIND=1
2014-02-19 16:52:59 +01:00
make_no_libdw_dwarf_unwind := NO_LIBDW_DWARF_UNWIND=1
2013-03-29 16:11:02 +01:00
make_no_backtrace := NO_BACKTRACE=1
make_no_libnuma := NO_LIBNUMA=1
make_no_libaudit := NO_LIBAUDIT=1
make_no_libbionic := NO_LIBBIONIC=1
2015-04-30 17:37:27 +03:00
make_no_auxtrace := NO_AUXTRACE=1
2015-10-14 12:41:12 +00:00
make_no_libbpf := NO_LIBBPF=1
2021-05-17 17:47:44 -03:00
make_libbpf_dynamic := LIBBPF_DYNAMIC=1
2020-05-18 16:10:27 +02:00
make_no_libbpf_DEBUG := NO_LIBBPF=1 DEBUG=1
2015-11-30 10:02:21 +01:00
make_no_libcrypto := NO_LIBCRYPTO=1
2016-06-25 01:41:58 +00:00
make_with_babeltrace:= LIBBABELTRACE=1
2021-05-17 11:15:18 -03:00
make_with_coresight := CORESIGHT=1
2016-07-12 19:05:56 +09:00
make_no_sdt := NO_SDT=1
2020-05-29 11:31:23 -03:00
make_no_syscall_tbl := NO_SYSCALL_TABLE=1
2016-11-26 07:03:33 +00:00
make_with_clangllvm := LIBCLANGLLVM=1
2023-03-10 22:57:50 -08:00
make_no_libpfm4 := NO_LIBPFM4=1
2020-09-04 17:32:01 -03:00
make_with_gtk2 := GTK2=1
2013-03-29 16:11:02 +01:00
make_tags := tags
make_cscope := cscope
make_help := help
make_doc := doc
2014-02-19 11:21:39 +01:00
make_perf_o := perf.o
make_util_map_o := util/map.o
make_util_pmu_bison_o := util/pmu-bison.o
2013-07-22 14:43:33 +02:00
make_install := install
make_install_bin := install-bin
2013-07-22 14:43:34 +02:00
make_install_doc := install-doc
make_install_man := install-man
make_install_html := install-html
make_install_info := install-info
make_install_pdf := install-pdf
2015-07-27 20:24:17 +02:00
make_install_prefix := install prefix=/tmp/krava
make_install_prefix_slash := install prefix=/tmp/krava/
2023-03-10 22:57:44 -08:00
make_static := LDFLAGS=-static NO_PERF_READ_VDSO32=1 NO_PERF_READ_VDSOX32=1 NO_JVMTI=1 NO_LIBTRACEEVENT=1 NO_LIBELF=1
2013-03-29 16:11:02 +01:00
# all the NO_* variable combined
2023-03-10 22:57:53 -08:00
make_minimal := NO_LIBPERL=1 NO_LIBPYTHON=1 NO_GTK2=1
2013-03-29 16:11:02 +01:00
make_minimal += NO_DEMANGLE=1 NO_LIBELF=1 NO_LIBUNWIND=1 NO_BACKTRACE=1
make_minimal += NO_LIBNUMA=1 NO_LIBAUDIT=1 NO_LIBBIONIC=1
2015-10-14 12:41:12 +00:00
make_minimal += NO_LIBDW_DWARF_UNWIND=1 NO_AUXTRACE=1 NO_LIBBPF=1
2019-05-14 16:48:13 -03:00
make_minimal += NO_LIBCRYPTO=1 NO_SDT=1 NO_JVMTI=1 NO_LIBZSTD=1
2020-05-29 11:31:23 -03:00
make_minimal += NO_LIBCAP=1 NO_SYSCALL_TABLE=1
2013-03-29 16:11:02 +01:00
# $(run) contains all available tests
run := make_pure
2015-06-22 14:50:50 +02:00
# Targets 'clean all' can be run together only through top level
# Makefile because we detect clean target in Makefile.perf and
# disable features detection
ifeq ($(MK),Makefile)
2013-03-29 16:11:02 +01:00
run += make_clean_all
2016-02-03 17:16:32 -03:00
MAKE_F := $(MAKE)
else
MAKE_F := $(MAKE) -f $(MK)
2015-06-22 14:50:50 +02:00
endif
2013-03-29 16:11:02 +01:00
run += make_python_perf_so
run += make_debug
2023-03-10 22:57:47 -08:00
run += make_nondistro
2013-03-29 16:11:02 +01:00
run += make_no_libperl
run += make_no_libpython
run += make_no_scripts
run += make_no_slang
run += make_no_gtk2
run += make_no_ui
run += make_no_demangle
run += make_no_libelf
run += make_no_libunwind
2014-02-19 16:52:59 +01:00
run += make_no_libdw_dwarf_unwind
2013-03-29 16:11:02 +01:00
run += make_no_backtrace
run += make_no_libnuma
run += make_no_libaudit
run += make_no_libbionic
2015-04-30 17:37:27 +03:00
run += make_no_auxtrace
2015-10-14 12:41:12 +00:00
run += make_no_libbpf
2020-05-18 16:10:27 +02:00
run += make_no_libbpf_DEBUG
2020-05-29 11:38:41 -03:00
run += make_no_libcrypto
2020-05-29 11:42:00 -03:00
run += make_no_sdt
2020-05-29 11:31:23 -03:00
run += make_no_syscall_tbl
2016-06-25 01:41:58 +00:00
run += make_with_babeltrace
2021-05-17 11:15:18 -03:00
run += make_with_coresight
2016-11-26 07:03:33 +00:00
run += make_with_clangllvm
2023-03-10 22:57:50 -08:00
run += make_no_libpfm4
2013-03-29 16:11:02 +01:00
run += make_help
run += make_doc
run += make_perf_o
run += make_util_map_o
2014-02-19 11:21:39 +01:00
run += make_util_pmu_bison_o
2013-07-22 14:43:33 +02:00
run += make_install
run += make_install_bin
2015-06-22 14:50:51 +02:00
run += make_install_prefix
2015-07-27 20:24:17 +02:00
run += make_install_prefix_slash
2013-07-22 14:43:34 +02:00
# FIXME 'install-*' commented out till they're fixed
# run += make_install_doc
# run += make_install_man
# run += make_install_html
# run += make_install_info
# run += make_install_pdf
2013-03-29 16:11:02 +01:00
run += make_minimal
2023-01-15 17:01:13 -08:00
old_libbpf := $(shell echo "#include <bpf/libbpf.h>" | $(CC) -E -dM -x c -| egrep -q "define[[:space:]]+LIBBPF_MAJOR_VERSION[[:space:]]+0{1}")
ifneq ($(old_libbpf),)
run += make_libbpf_dynamic
endif
2013-07-22 14:43:30 +02:00
ifneq ($(call has,ctags),)
run += make_tags
endif
ifneq ($(call has,cscope),)
run += make_cscope
endif
2013-03-29 16:11:02 +01:00
# $(run_O) contains same portion of $(run) tests with '_O' attached
# to distinguish O=... tests
run_O := $(addsuffix _O,$(run))
# disable some tests for O=...
run_O := $(filter-out make_python_perf_so_O,$(run_O))
# define test for each compile as 'test_NAME' variable
# with the test itself as a value
test_make_tags = test -f tags
test_make_cscope = test -f cscope.out
test_make_tags_O := $(test_make_tags)
test_make_cscope_O := $(test_make_cscope)
test_ok := true
test_make_help := $(test_ok)
test_make_doc := $(test_ok)
test_make_help_O := $(test_ok)
test_make_doc_O := $(test_ok)
2023-03-10 22:57:41 -08:00
test_make_python_perf_so := test -f $(PERF_O)/$(python_perf_so)
2013-03-29 16:11:02 +01:00
2016-01-15 04:00:15 +00:00
test_make_perf_o := test -f $(PERF_O)/perf.o
test_make_util_map_o := test -f $(PERF_O)/util/map.o
test_make_util_pmu_bison_o := test -f $(PERF_O)/util/pmu-bison.o
2013-03-29 16:11:02 +01:00
2013-12-19 14:41:59 +01:00
define test_dest_files
for file in $(1); do \
if [ ! -x $$TMP_DEST/$$file ]; then \
echo " failed to find: $$file"; \
fi \
done
endef
installed_files_bin := bin/perf
installed_files_bin += etc/bash_completion.d/perf
installed_files_bin += libexec/perf-core/perf-archive
installed_files_all := $(installed_files_bin)
test_make_install := $(call test_dest_files,$(installed_files_all))
test_make_install_O := $(call test_dest_files,$(installed_files_all))
test_make_install_bin := $(call test_dest_files,$(installed_files_bin))
test_make_install_bin_O := $(call test_dest_files,$(installed_files_bin))
2013-07-22 14:43:33 +02:00
2015-07-27 20:24:17 +02:00
# We prefix all installed files for make_install_prefix(_slash)
2015-06-22 14:50:51 +02:00
# with '/tmp/krava' to match installed/prefix-ed files.
installed_files_all_prefix := $(addprefix /tmp/krava/,$(installed_files_all))
2015-07-27 20:24:17 +02:00
test_make_install_prefix := $(call test_dest_files,$(installed_files_all_prefix))
test_make_install_prefix_O := $(call test_dest_files,$(installed_files_all_prefix))
test_make_install_prefix_slash := $(test_make_install_prefix)
test_make_install_prefix_slash_O := $(test_make_install_prefix_O)
2015-06-22 14:50:51 +02:00
2013-07-22 14:43:34 +02:00
# FIXME nothing gets installed
test_make_install_man := test -f $$TMP_DEST/share/man/man1/perf.1
test_make_install_man_O := $(test_make_install_man)
# FIXME nothing gets installed
test_make_install_doc := $(test_ok)
test_make_install_doc_O := $(test_ok)
# FIXME nothing gets installed
test_make_install_html := $(test_ok)
test_make_install_html_O := $(test_ok)
# FIXME nothing gets installed
test_make_install_info := $(test_ok)
test_make_install_info_O := $(test_ok)
# FIXME nothing gets installed
test_make_install_pdf := $(test_ok)
test_make_install_pdf_O := $(test_ok)
2021-05-17 17:47:44 -03:00
test_make_libbpf_dynamic := ldd $(PERF_O)/perf | grep -q libbpf
test_make_libbpf_dynamic_O := ldd $$TMP_O/perf | grep -q libbpf
2014-02-19 11:21:38 +01:00
test_make_python_perf_so_O := test -f $$TMP_O/python/perf.so
test_make_perf_o_O := test -f $$TMP_O/perf.o
test_make_util_map_o_O := test -f $$TMP_O/util/map.o
2014-02-19 11:21:39 +01:00
test_make_util_pmu_bison_o_O := test -f $$TMP_O/util/pmu-bison.o
2013-03-29 16:11:02 +01:00
2016-01-15 04:00:15 +00:00
test_default = test -x $(PERF_O)/perf
2013-03-29 16:11:02 +01:00
test = $(if $(test_$1),$(test_$1),$(test_default))
2013-07-22 14:43:31 +02:00
test_default_O = test -x $$TMP_O/perf
2013-03-29 16:11:02 +01:00
test_O = $(if $(test_$1),$(test_$1),$(test_default_O))
all:
2015-11-04 16:25:32 -03:00
ifdef SHUF
run := $(shell shuf -e $(run))
run_O := $(shell shuf -e $(run_O))
endif
2016-01-29 17:51:04 -03:00
max_width := $(shell echo $(run_O) | sed 's/ /\n/g' | wc -L)
2013-03-29 16:11:02 +01:00
ifdef DEBUG
d := $(info run $(run))
d := $(info run_O $(run_O))
endif
MAKEFLAGS := --no-print-directory
2016-12-04 21:42:58 +01:00
clean := @(cd $(PERF); $(MAKE_F) -s $(O_OPT) clean >/dev/null && $(MAKE) -s $(O_OPT) -C ../build clean >/dev/null)
2013-03-29 16:11:02 +01:00
$(run):
$(call clean)
2013-07-22 14:43:32 +02:00
@TMP_DEST=$$(mktemp -d); \
2021-04-15 21:15:34 -03:00
cmd="cd $(PERF) && $(MAKE_F) $($@) $(PARALLEL_OPT) $(O_OPT) DESTDIR=$$TMP_DEST"; \
printf "%*.*s: %s\n" $(max_width) $(max_width) "$@" "$$cmd" && echo $$cmd > $@ && \
( eval $$cmd ) >> $@ 2>&1; \
echo " test: $(call test,$@)" >> $@ 2>&1; \
$(call test,$@) && \
rm -rf $@ $$TMP_DEST || (cat $@ ; false)
make_with_gtk2:
$(call clean)
@TMP_DEST=$$(mktemp -d); \
cmd="cd $(PERF) && $(MAKE_F) $($@) $(PARALLEL_OPT) $(O_OPT) DESTDIR=$$TMP_DEST"; \
printf "%*.*s: %s\n" $(max_width) $(max_width) "$@" "$$cmd" && echo $$cmd > $@ && \
( eval $$cmd ) >> $@ 2>&1; \
echo " test: $(call test,$@)" >> $@ 2>&1; \
$(call test,$@) && \
rm -rf $@ $$TMP_DEST || (cat $@ ; false)
make_static:
$(call clean)
@TMP_DEST=$$(mktemp -d); \
2016-02-03 17:24:11 -03:00
cmd="cd $(PERF) && $(MAKE_F) $($@) $(PARALLEL_OPT) $(O_OPT) DESTDIR=$$TMP_DEST"; \
2016-01-29 17:51:04 -03:00
printf "%*.*s: %s\n" $(max_width) $(max_width) "$@" "$$cmd" && echo $$cmd > $@ && \
2013-03-29 16:11:02 +01:00
( eval $$cmd ) >> $@ 2>&1; \
2013-12-19 14:41:59 +01:00
echo " test: $(call test,$@)" >> $@ 2>&1; \
2013-03-29 16:11:02 +01:00
$(call test,$@) && \
2014-06-05 17:15:47 -03:00
rm -rf $@ $$TMP_DEST || (cat $@ ; false)
2013-03-29 16:11:02 +01:00
$(run_O):
$(call clean)
2013-07-22 14:43:31 +02:00
@TMP_O=$$(mktemp -d); \
2013-07-22 14:43:32 +02:00
TMP_DEST=$$(mktemp -d); \
2016-02-03 17:24:11 -03:00
cmd="cd $(PERF) && $(MAKE_F) $($(patsubst %_O,%,$@)) $(PARALLEL_OPT) O=$$TMP_O DESTDIR=$$TMP_DEST"; \
2016-01-29 17:51:04 -03:00
printf "%*.*s: %s\n" $(max_width) $(max_width) "$@" "$$cmd" && echo $$cmd > $@ && \
2013-03-29 16:11:02 +01:00
( eval $$cmd ) >> $@ 2>&1 && \
2013-12-19 14:41:59 +01:00
echo " test: $(call test_O,$@)" >> $@ 2>&1; \
2013-03-29 16:11:02 +01:00
$(call test_O,$@) && \
2014-06-05 17:15:47 -03:00
rm -rf $@ $$TMP_O $$TMP_DEST || (cat $@ ; false)
2013-03-29 16:11:02 +01:00
2014-01-10 16:46:45 -03:00
tarpkg:
@cmd="$(PERF)/tests/perf-targz-src-pkg $(PERF)"; \
echo "- $@: $$cmd" && echo $$cmd > $@ && \
2015-12-13 22:18:04 -06:00
( eval $$cmd ) >> $@ 2>&1 && \
rm -f $@
2014-01-10 16:46:45 -03:00
2016-01-15 04:00:15 +00:00
KERNEL_O := ../..
ifneq ($(O),)
KERNEL_O := $(O)
endif
2015-04-18 22:34:40 +02:00
make_kernelsrc:
2016-01-15 04:00:16 +00:00
@echo "- make -C <kernelsrc> $(PARALLEL_OPT) $(K_O_OPT) tools/perf"
2015-04-18 22:34:40 +02:00
$(call clean); \
2016-01-15 04:00:16 +00:00
(make -C ../.. $(PARALLEL_OPT) $(K_O_OPT) tools/perf) > $@ 2>&1 && \
2016-01-15 04:00:15 +00:00
test -x $(KERNEL_O)/tools/perf/perf && rm -f $@ || (cat $@ ; false)
2015-04-18 22:34:40 +02:00
make_kernelsrc_tools:
2016-01-15 04:00:16 +00:00
@echo "- make -C <kernelsrc>/tools $(PARALLEL_OPT) $(K_O_OPT) perf"
2015-04-18 22:34:40 +02:00
$(call clean); \
2016-01-15 04:00:16 +00:00
(make -C ../../tools $(PARALLEL_OPT) $(K_O_OPT) perf) > $@ 2>&1 && \
2016-01-15 04:00:15 +00:00
test -x $(KERNEL_O)/tools/perf/perf && rm -f $@ || (cat $@ ; false)
2015-04-18 22:34:40 +02:00
2019-09-01 14:48:21 +02:00
make_libperf:
@echo "- make -C lib";
make -C lib clean >$@ 2>&1; make -C lib >>$@ 2>&1 && rm $@
2016-01-29 11:51:09 +00:00
FEATURES_DUMP_FILE := $(FULL_O)/BUILD_TEST_FEATURE_DUMP
FEATURES_DUMP_FILE_STATIC := $(FULL_O)/BUILD_TEST_FEATURE_DUMP_STATIC
2015-04-18 22:34:40 +02:00
all: $(run) $(run_O) tarpkg make_kernelsrc make_kernelsrc_tools
2013-03-29 16:11:02 +01:00
@echo OK
2016-01-29 11:51:09 +00:00
@rm -f $(FEATURES_DUMP_FILE) $(FEATURES_DUMP_FILE_STATIC)
2013-03-29 16:11:02 +01:00
out: $(run_O)
@echo OK
2016-01-29 11:51:09 +00:00
@rm -f $(FEATURES_DUMP_FILE) $(FEATURES_DUMP_FILE_STATIC)
ifeq ($(REUSE_FEATURES_DUMP),1)
$(FEATURES_DUMP_FILE):
$(call clean)
@cmd="cd $(PERF) && make FEATURE_DUMP_COPY=$@ $(O_OPT) feature-dump"; \
echo "- $@: $$cmd" && echo $$cmd && \
( eval $$cmd ) > /dev/null 2>&1
$(FEATURES_DUMP_FILE_STATIC):
$(call clean)
@cmd="cd $(PERF) && make FEATURE_DUMP_COPY=$@ $(O_OPT) LDFLAGS='-static' feature-dump"; \
echo "- $@: $$cmd" && echo $$cmd && \
( eval $$cmd ) > /dev/null 2>&1
# Add feature dump dependency for run/run_O targets
$(foreach t,$(run) $(run_O),$(eval \
$(t): $(if $(findstring make_static,$(t)),\
$(FEATURES_DUMP_FILE_STATIC),\
$(FEATURES_DUMP_FILE))))
# Append 'FEATURES_DUMP=' option to all test cases. For example:
# make_no_libbpf: NO_LIBBPF=1 --> NO_LIBBPF=1 FEATURES_DUMP=/a/b/BUILD_TEST_FEATURE_DUMP
# make_static: LDFLAGS=-static --> LDFLAGS=-static FEATURES_DUMP=/a/b/BUILD_TEST_FEATURE_DUMP_STATIC
$(foreach t,$(run),$(if $(findstring make_static,$(t)),\
$(eval $(t) := $($(t)) FEATURES_DUMP=$(FEATURES_DUMP_FILE_STATIC)),\
$(eval $(t) := $($(t)) FEATURES_DUMP=$(FEATURES_DUMP_FILE))))
endif
2013-03-29 16:11:02 +01:00
2019-09-01 14:48:21 +02:00
.PHONY: all $(run) $(run_O) tarpkg clean make_kernelsrc make_kernelsrc_tools make_libperf
2015-06-22 14:50:50 +02:00
endif # ifndef MK