make 11.8 KB
Newer Older
1 2
include ../scripts/Makefile.include

3 4 5 6 7
ifndef MK
ifeq ($(MAKECMDGOALS),)
# no target specified, trigger the whole suite
all:
	@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
9 10 11 12 13 14
else
# run only specific test over 'Makefile'
%:
	@echo "Testing Makefile";      $(MAKE) -sf tests/make MK=Makefile $@
endif
else
15
PERF := .
16
PERF_O := $(PERF)
17
O_OPT :=
18
FULL_O := $(shell readlink -f $(PERF_O) || echo $(PERF_O))
19 20 21

ifneq ($(O),)
  FULL_O := $(shell readlink -f $(O) || echo $(O))
22
  PERF_O := $(FULL_O)
23 24 25
  ifeq ($(SET_O),1)
    O_OPT := 'O=$(FULL_O)'
  endif
26
  K_O_OPT := 'O=$(FULL_O)'
27
endif
28

29 30 31 32 33 34 35 36 37
PARALLEL_OPT=
ifeq ($(SET_PARALLEL),1)
  cores := $(shell (getconf _NPROCESSORS_ONLN || egrep -c '^processor|^CPU[0-9]' /proc/cpuinfo) 2>/dev/null)
  ifeq ($(cores),0)
    cores := 1
  endif
  PARALLEL_OPT="-j$(cores)"
endif

38 39 40 41 42 43 44
# 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),)
45
srctree := $(patsubst %/,%,$(dir $(CURDIR)))
46 47 48 49 50
srctree := $(patsubst %/,%,$(dir $(srctree)))
#$(info Determined 'srctree' to be $(srctree))
endif

include $(srctree)/tools/scripts/Makefile.arch
51 52 53

# FIXME looks like x86 is the only arch running tests ;-)
# we need some IS_(32/64) flag to make this generic
54
ifeq ($(ARCH)$(IS_64_BIT), x861)
55 56 57 58 59
lib = lib64
else
lib = lib
endif

60 61
has = $(shell which $1 2>/dev/null)

62 63 64 65 66 67 68 69 70 71 72 73 74 75
# standard single make variable specified
make_clean_all      := clean all
make_python_perf_so := python/perf.so
make_debug          := DEBUG=1
make_no_libperl     := NO_LIBPERL=1
make_no_libpython   := NO_LIBPYTHON=1
make_no_scripts     := NO_LIBPYTHON=1 NO_LIBPERL=1
make_no_newt        := NO_NEWT=1
make_no_slang       := NO_SLANG=1
make_no_gtk2        := NO_GTK2=1
make_no_ui          := NO_NEWT=1 NO_SLANG=1 NO_GTK2=1
make_no_demangle    := NO_DEMANGLE=1
make_no_libelf      := NO_LIBELF=1
make_no_libunwind   := NO_LIBUNWIND=1
76
make_no_libdw_dwarf_unwind := NO_LIBDW_DWARF_UNWIND=1
77 78 79 80
make_no_backtrace   := NO_BACKTRACE=1
make_no_libnuma     := NO_LIBNUMA=1
make_no_libaudit    := NO_LIBAUDIT=1
make_no_libbionic   := NO_LIBBIONIC=1
81
make_no_auxtrace    := NO_AUXTRACE=1
W
Wang Nan 已提交
82
make_no_libbpf	    := NO_LIBBPF=1
83
make_no_libcrypto   := NO_LIBCRYPTO=1
84
make_with_babeltrace:= LIBBABELTRACE=1
85
make_no_sdt	    := NO_SDT=1
86
make_with_clangllvm := LIBCLANGLLVM=1
87 88 89 90
make_tags           := tags
make_cscope         := cscope
make_help           := help
make_doc            := doc
91 92 93
make_perf_o           := perf.o
make_util_map_o       := util/map.o
make_util_pmu_bison_o := util/pmu-bison.o
94 95
make_install        := install
make_install_bin    := install-bin
96 97 98 99 100
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
101 102
make_install_prefix       := install prefix=/tmp/krava
make_install_prefix_slash := install prefix=/tmp/krava/
J
Jiri Olsa 已提交
103
make_static         := LDFLAGS=-static NO_PERF_READ_VDSO32=1 NO_PERF_READ_VDSOX32=1 NO_JVMTI=1
104 105 106 107 108

# all the NO_* variable combined
make_minimal        := NO_LIBPERL=1 NO_LIBPYTHON=1 NO_NEWT=1 NO_GTK2=1
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
W
Wang Nan 已提交
109
make_minimal        += NO_LIBDW_DWARF_UNWIND=1 NO_AUXTRACE=1 NO_LIBBPF=1
110
make_minimal        += NO_LIBCRYPTO=1 NO_SDT=1 NO_JVMTI=1 NO_LIBZSTD=1
111
make_minimal        += NO_LIBCAP=1
112 113 114

# $(run) contains all available tests
run := make_pure
115 116 117 118
# 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)
119
run += make_clean_all
120 121 122
MAKE_F := $(MAKE)
else
MAKE_F := $(MAKE) -f $(MK)
123
endif
124 125 126 127 128 129 130 131 132 133 134 135
run += make_python_perf_so
run += make_debug
run += make_no_libperl
run += make_no_libpython
run += make_no_scripts
run += make_no_newt
run += make_no_slang
run += make_no_gtk2
run += make_no_ui
run += make_no_demangle
run += make_no_libelf
run += make_no_libunwind
136
run += make_no_libdw_dwarf_unwind
137 138 139 140
run += make_no_backtrace
run += make_no_libnuma
run += make_no_libaudit
run += make_no_libbionic
141
run += make_no_auxtrace
W
Wang Nan 已提交
142
run += make_no_libbpf
143
run += make_with_babeltrace
144
run += make_with_clangllvm
145 146 147 148
run += make_help
run += make_doc
run += make_perf_o
run += make_util_map_o
149
run += make_util_pmu_bison_o
150 151
run += make_install
run += make_install_bin
152
run += make_install_prefix
153
run += make_install_prefix_slash
154 155 156 157 158 159
# 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
160
run += make_minimal
161
run += make_static
162

163 164 165 166 167 168 169
ifneq ($(call has,ctags),)
run += make_tags
endif
ifneq ($(call has,cscope),)
run += make_cscope
endif

170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
# $(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)

191
test_make_python_perf_so := test -f $(PERF_O)/python/perf.so
192

193 194 195
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
196

J
Jiri Olsa 已提交
197 198 199 200 201 202 203 204 205 206 207 208
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

209 210 211 212 213 214 215 216 217 218
installed_files_plugins := $(lib)/traceevent/plugins/plugin_cfg80211.so
installed_files_plugins += $(lib)/traceevent/plugins/plugin_scsi.so
installed_files_plugins += $(lib)/traceevent/plugins/plugin_xen.so
installed_files_plugins += $(lib)/traceevent/plugins/plugin_function.so
installed_files_plugins += $(lib)/traceevent/plugins/plugin_sched_switch.so
installed_files_plugins += $(lib)/traceevent/plugins/plugin_mac80211.so
installed_files_plugins += $(lib)/traceevent/plugins/plugin_kvm.so
installed_files_plugins += $(lib)/traceevent/plugins/plugin_kmem.so
installed_files_plugins += $(lib)/traceevent/plugins/plugin_hrtimer.so
installed_files_plugins += $(lib)/traceevent/plugins/plugin_jbd2.so
J
Jiri Olsa 已提交
219 220 221 222 223 224 225 226

installed_files_all := $(installed_files_bin)
installed_files_all += $(installed_files_plugins)

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))
227

228
# We prefix all installed files for make_install_prefix(_slash)
229 230
# with '/tmp/krava' to match installed/prefix-ed files.
installed_files_all_prefix := $(addprefix /tmp/krava/,$(installed_files_all))
231 232 233 234 235
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)
236

237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
# 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)

J
Jiri Olsa 已提交
257 258 259
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
260
test_make_util_pmu_bison_o_O := test -f $$TMP_O/util/pmu-bison.o
261

262
test_default = test -x $(PERF_O)/perf
263 264
test = $(if $(test_$1),$(test_$1),$(test_default))

265
test_default_O = test -x $$TMP_O/perf
266 267 268 269
test_O = $(if $(test_$1),$(test_$1),$(test_default_O))

all:

270 271 272 273 274
ifdef SHUF
run := $(shell shuf -e $(run))
run_O := $(shell shuf -e $(run_O))
endif

275 276
max_width := $(shell echo $(run_O) | sed 's/ /\n/g' | wc -L)

277 278 279 280 281 282 283
ifdef DEBUG
d := $(info run   $(run))
d := $(info run_O $(run_O))
endif

MAKEFLAGS := --no-print-directory

284
clean := @(cd $(PERF); $(MAKE_F) -s $(O_OPT) clean >/dev/null && $(MAKE) -s $(O_OPT) -C ../build clean >/dev/null)
285 286 287

$(run):
	$(call clean)
288
	@TMP_DEST=$$(mktemp -d); \
289
	cmd="cd $(PERF) && $(MAKE_F) $($@) $(PARALLEL_OPT) $(O_OPT) DESTDIR=$$TMP_DEST"; \
290
	printf "%*.*s: %s\n" $(max_width) $(max_width) "$@" "$$cmd" && echo $$cmd > $@ && \
291
	( eval $$cmd ) >> $@ 2>&1; \
J
Jiri Olsa 已提交
292
	echo "  test: $(call test,$@)" >> $@ 2>&1; \
293
	$(call test,$@) && \
294
	rm -rf $@ $$TMP_DEST || (cat $@ ; false)
295 296 297

$(run_O):
	$(call clean)
298
	@TMP_O=$$(mktemp -d); \
299
	TMP_DEST=$$(mktemp -d); \
300
	cmd="cd $(PERF) && $(MAKE_F) $($(patsubst %_O,%,$@)) $(PARALLEL_OPT) O=$$TMP_O DESTDIR=$$TMP_DEST"; \
301
	printf "%*.*s: %s\n" $(max_width) $(max_width) "$@" "$$cmd" && echo $$cmd > $@ && \
302
	( eval $$cmd ) >> $@ 2>&1 && \
J
Jiri Olsa 已提交
303
	echo "  test: $(call test_O,$@)" >> $@ 2>&1; \
304
	$(call test_O,$@) && \
305
	rm -rf $@ $$TMP_O $$TMP_DEST || (cat $@ ; false)
306

307 308 309
tarpkg:
	@cmd="$(PERF)/tests/perf-targz-src-pkg $(PERF)"; \
	echo "- $@: $$cmd" && echo $$cmd > $@ && \
310 311
	( eval $$cmd ) >> $@ 2>&1 && \
	rm -f $@
312

313 314 315 316 317
KERNEL_O := ../..
ifneq ($(O),)
  KERNEL_O := $(O)
endif

318
make_kernelsrc:
319
	@echo "- make -C <kernelsrc> $(PARALLEL_OPT) $(K_O_OPT) tools/perf"
320
	$(call clean); \
321
	(make -C ../.. $(PARALLEL_OPT) $(K_O_OPT) tools/perf) > $@ 2>&1 && \
322
	test -x $(KERNEL_O)/tools/perf/perf && rm -f $@ || (cat $@ ; false)
323 324

make_kernelsrc_tools:
325
	@echo "- make -C <kernelsrc>/tools $(PARALLEL_OPT) $(K_O_OPT) perf"
326
	$(call clean); \
327
	(make -C ../../tools $(PARALLEL_OPT) $(K_O_OPT) perf) > $@ 2>&1 && \
328
	test -x $(KERNEL_O)/tools/perf/perf && rm -f $@ || (cat $@ ; false)
329

330 331 332 333
make_libperf:
	@echo "- make -C lib";
	make -C lib clean >$@ 2>&1; make -C lib >>$@ 2>&1 && rm $@

334 335 336
FEATURES_DUMP_FILE := $(FULL_O)/BUILD_TEST_FEATURE_DUMP
FEATURES_DUMP_FILE_STATIC := $(FULL_O)/BUILD_TEST_FEATURE_DUMP_STATIC

337
all: $(run) $(run_O) tarpkg make_kernelsrc make_kernelsrc_tools
338
	@echo OK
339
	@rm -f $(FEATURES_DUMP_FILE) $(FEATURES_DUMP_FILE_STATIC)
340 341 342

out: $(run_O)
	@echo OK
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
	@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
371

372
.PHONY: all $(run) $(run_O) tarpkg clean make_kernelsrc make_kernelsrc_tools make_libperf
373
endif # ifndef MK