make 13 KB

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