make 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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_jevents_all := JEVENTS_ARCH=all
  65. make_no_bpf_skel := BUILD_BPF_SKEL=0
  66. make_gen_vmlinux_h := GEN_VMLINUX_H=1
  67. make_no_libperl := NO_LIBPERL=1
  68. make_no_libpython := NO_LIBPYTHON=1
  69. make_no_scripts := NO_LIBPYTHON=1 NO_LIBPERL=1
  70. make_no_slang := NO_SLANG=1
  71. make_no_gtk2 := NO_GTK2=1
  72. make_no_ui := NO_SLANG=1 NO_GTK2=1
  73. make_no_demangle := NO_DEMANGLE=1
  74. make_no_libelf := NO_LIBELF=1
  75. make_no_libunwind := NO_LIBUNWIND=1
  76. make_no_libdw_dwarf_unwind := NO_LIBDW_DWARF_UNWIND=1
  77. make_no_backtrace := NO_BACKTRACE=1
  78. make_no_libcapstone := NO_CAPSTONE=1
  79. make_no_libnuma := NO_LIBNUMA=1
  80. make_no_libaudit := NO_LIBAUDIT=1
  81. make_no_libbionic := NO_LIBBIONIC=1
  82. make_no_auxtrace := NO_AUXTRACE=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_libcrypto := NO_LIBCRYPTO=1
  87. make_no_libllvm := NO_LIBLLVM=1
  88. make_with_babeltrace:= LIBBABELTRACE=1
  89. make_with_coresight := CORESIGHT=1
  90. make_no_sdt := NO_SDT=1
  91. make_no_syscall_tbl := NO_SYSCALL_TABLE=1
  92. make_no_libpfm4 := NO_LIBPFM4=1
  93. make_with_gtk2 := GTK2=1
  94. make_refcnt_check := EXTRA_CFLAGS="-DREFCNT_CHECKING=1"
  95. make_tags := tags
  96. make_cscope := cscope
  97. make_help := help
  98. make_doc := doc
  99. make_perf_o := perf.o
  100. make_util_map_o := util/map.o
  101. make_util_pmu_bison_o := util/pmu-bison.o
  102. make_install := install
  103. make_install_bin := install-bin
  104. make_install_doc := install-doc
  105. make_install_man := install-man
  106. make_install_html := install-html
  107. make_install_info := install-info
  108. make_install_pdf := install-pdf
  109. make_install_prefix := install prefix=/tmp/krava
  110. make_install_prefix_slash := install prefix=/tmp/krava/
  111. make_static := LDFLAGS=-static NO_PERF_READ_VDSO32=1 NO_PERF_READ_VDSOX32=1 NO_JVMTI=1 NO_LIBTRACEEVENT=1 NO_LIBELF=1
  112. # all the NO_* variable combined
  113. make_minimal := NO_LIBPERL=1 NO_LIBPYTHON=1 NO_GTK2=1
  114. make_minimal += NO_DEMANGLE=1 NO_LIBELF=1 NO_LIBUNWIND=1 NO_BACKTRACE=1
  115. make_minimal += NO_LIBNUMA=1 NO_LIBAUDIT=1 NO_LIBBIONIC=1
  116. make_minimal += NO_LIBDW_DWARF_UNWIND=1 NO_AUXTRACE=1 NO_LIBBPF=1
  117. make_minimal += NO_LIBCRYPTO=1 NO_SDT=1 NO_JVMTI=1 NO_LIBZSTD=1
  118. make_minimal += NO_LIBCAP=1 NO_SYSCALL_TABLE=1 NO_CAPSTONE=1
  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. run += make_nondistro
  133. run += make_extra_tests
  134. run += make_jevents_all
  135. run += make_no_bpf_skel
  136. run += make_gen_vmlinux_h
  137. run += make_no_libperl
  138. run += make_no_libpython
  139. run += make_no_scripts
  140. run += make_no_slang
  141. run += make_no_gtk2
  142. run += make_no_ui
  143. run += make_no_demangle
  144. run += make_no_libelf
  145. run += make_no_libunwind
  146. run += make_no_libdw_dwarf_unwind
  147. run += make_no_backtrace
  148. run += make_no_libcapstone
  149. run += make_no_libnuma
  150. run += make_no_libaudit
  151. run += make_no_libbionic
  152. run += make_no_auxtrace
  153. run += make_no_libbpf
  154. run += make_no_libbpf_DEBUG
  155. run += make_no_libcrypto
  156. run += make_no_libllvm
  157. run += make_no_sdt
  158. run += make_no_syscall_tbl
  159. run += make_with_babeltrace
  160. run += make_with_coresight
  161. run += make_with_clangllvm
  162. run += make_no_libpfm4
  163. run += make_refcnt_check
  164. run += make_help
  165. run += make_doc
  166. run += make_perf_o
  167. run += make_util_map_o
  168. run += make_util_pmu_bison_o
  169. run += make_install
  170. run += make_install_bin
  171. run += make_install_prefix
  172. run += make_install_prefix_slash
  173. # FIXME 'install-*' commented out till they're fixed
  174. # run += make_install_doc
  175. # run += make_install_man
  176. # run += make_install_html
  177. # run += make_install_info
  178. # run += make_install_pdf
  179. run += make_minimal
  180. old_libbpf := $(shell echo '\#include <bpf/libbpf.h>' | $(CC) -E -dM -x c -| grep -q -E "define[[:space:]]+LIBBPF_MAJOR_VERSION[[:space:]]+0{1}")
  181. ifneq ($(old_libbpf),)
  182. run += make_libbpf_dynamic
  183. endif
  184. ifneq ($(call has,ctags),)
  185. run += make_tags
  186. endif
  187. ifneq ($(call has,cscope),)
  188. run += make_cscope
  189. endif
  190. # $(run_O) contains same portion of $(run) tests with '_O' attached
  191. # to distinguish O=... tests
  192. run_O := $(addsuffix _O,$(run))
  193. # disable some tests for O=...
  194. run_O := $(filter-out make_python_perf_so_O,$(run_O))
  195. # define test for each compile as 'test_NAME' variable
  196. # with the test itself as a value
  197. test_make_tags = test -f tags
  198. test_make_cscope = test -f cscope.out
  199. test_make_tags_O := $(test_make_tags)
  200. test_make_cscope_O := $(test_make_cscope)
  201. test_ok := true
  202. test_make_help := $(test_ok)
  203. test_make_doc := $(test_ok)
  204. test_make_help_O := $(test_ok)
  205. test_make_doc_O := $(test_ok)
  206. test_make_python_perf_so := test -f $(PERF_O)/$(python_perf_so)
  207. test_make_perf_o := test -f $(PERF_O)/perf.o
  208. test_make_util_map_o := test -f $(PERF_O)/util/map.o
  209. test_make_util_pmu_bison_o := test -f $(PERF_O)/util/pmu-bison.o
  210. define test_dest_files
  211. for file in $(1); do \
  212. if [ ! -x $$TMP_DEST/$$file ]; then \
  213. echo " failed to find: $$file"; \
  214. fi \
  215. done
  216. endef
  217. installed_files_bin := bin/perf
  218. installed_files_bin += etc/bash_completion.d/perf
  219. installed_files_bin += libexec/perf-core/perf-archive
  220. installed_files_all := $(installed_files_bin)
  221. test_make_install := $(call test_dest_files,$(installed_files_all))
  222. test_make_install_O := $(call test_dest_files,$(installed_files_all))
  223. test_make_install_bin := $(call test_dest_files,$(installed_files_bin))
  224. test_make_install_bin_O := $(call test_dest_files,$(installed_files_bin))
  225. # We prefix all installed files for make_install_prefix(_slash)
  226. # with '/tmp/krava' to match installed/prefix-ed files.
  227. installed_files_all_prefix := $(addprefix /tmp/krava/,$(installed_files_all))
  228. test_make_install_prefix := $(call test_dest_files,$(installed_files_all_prefix))
  229. test_make_install_prefix_O := $(call test_dest_files,$(installed_files_all_prefix))
  230. test_make_install_prefix_slash := $(test_make_install_prefix)
  231. test_make_install_prefix_slash_O := $(test_make_install_prefix_O)
  232. # FIXME nothing gets installed
  233. test_make_install_man := test -f $$TMP_DEST/share/man/man1/perf.1
  234. test_make_install_man_O := $(test_make_install_man)
  235. # FIXME nothing gets installed
  236. test_make_install_doc := $(test_ok)
  237. test_make_install_doc_O := $(test_ok)
  238. # FIXME nothing gets installed
  239. test_make_install_html := $(test_ok)
  240. test_make_install_html_O := $(test_ok)
  241. # FIXME nothing gets installed
  242. test_make_install_info := $(test_ok)
  243. test_make_install_info_O := $(test_ok)
  244. # FIXME nothing gets installed
  245. test_make_install_pdf := $(test_ok)
  246. test_make_install_pdf_O := $(test_ok)
  247. test_make_libbpf_dynamic := ldd $(PERF_O)/perf | grep -q libbpf
  248. test_make_libbpf_dynamic_O := ldd $$TMP_O/perf | grep -q libbpf
  249. test_make_python_perf_so_O := test -f $$TMP_O/python/perf.so
  250. test_make_perf_o_O := test -f $$TMP_O/perf.o
  251. test_make_util_map_o_O := test -f $$TMP_O/util/map.o
  252. test_make_util_pmu_bison_o_O := test -f $$TMP_O/util/pmu-bison.o
  253. test_default = test -x $(PERF_O)/perf
  254. test = $(if $(test_$1),$(test_$1),$(test_default))
  255. test_default_O = test -x $$TMP_O/perf
  256. test_O = $(if $(test_$1),$(test_$1),$(test_default_O))
  257. all:
  258. ifdef SHUF
  259. run := $(shell shuf -e $(run))
  260. run_O := $(shell shuf -e $(run_O))
  261. endif
  262. max_width := $(shell echo $(run_O) | sed 's/ /\n/g' | wc -L)
  263. ifdef DEBUG
  264. d := $(info run $(run))
  265. d := $(info run_O $(run_O))
  266. endif
  267. MAKEFLAGS := --no-print-directory
  268. clean := @(cd $(PERF); $(MAKE_F) -s $(O_OPT) clean >/dev/null && $(MAKE) -s $(O_OPT) -C ../build clean >/dev/null)
  269. $(run):
  270. $(call clean)
  271. @TMP_DEST=$$(mktemp -d); \
  272. cmd="cd $(PERF) && $(MAKE_F) $($@) $(PARALLEL_OPT) $(O_OPT) DESTDIR=$$TMP_DEST"; \
  273. printf "%*.*s: %s\n" $(max_width) $(max_width) "$@" "$$cmd" && echo $$cmd > $@ && \
  274. ( eval $$cmd ) >> $@ 2>&1; \
  275. echo " test: $(call test,$@)" >> $@ 2>&1; \
  276. $(call test,$@) && \
  277. rm -rf $@ $$TMP_DEST || (cat $@ ; false)
  278. make_with_gtk2:
  279. $(call clean)
  280. @TMP_DEST=$$(mktemp -d); \
  281. cmd="cd $(PERF) && $(MAKE_F) $($@) $(PARALLEL_OPT) $(O_OPT) DESTDIR=$$TMP_DEST"; \
  282. printf "%*.*s: %s\n" $(max_width) $(max_width) "$@" "$$cmd" && echo $$cmd > $@ && \
  283. ( eval $$cmd ) >> $@ 2>&1; \
  284. echo " test: $(call test,$@)" >> $@ 2>&1; \
  285. $(call test,$@) && \
  286. rm -rf $@ $$TMP_DEST || (cat $@ ; false)
  287. make_static:
  288. $(call clean)
  289. @TMP_DEST=$$(mktemp -d); \
  290. cmd="cd $(PERF) && $(MAKE_F) $($@) $(PARALLEL_OPT) $(O_OPT) DESTDIR=$$TMP_DEST"; \
  291. printf "%*.*s: %s\n" $(max_width) $(max_width) "$@" "$$cmd" && echo $$cmd > $@ && \
  292. ( eval $$cmd ) >> $@ 2>&1; \
  293. echo " test: $(call test,$@)" >> $@ 2>&1; \
  294. $(call test,$@) && \
  295. rm -rf $@ $$TMP_DEST || (cat $@ ; false)
  296. $(run_O):
  297. $(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 && \
  303. echo " test: $(call test_O,$@)" >> $@ 2>&1; \
  304. $(call test_O,$@) && \
  305. rm -rf $@ $$TMP_O $$TMP_DEST || (cat $@ ; false)
  306. tarpkg:
  307. @cmd="$(PERF)/tests/perf-targz-src-pkg $(PERF)"; \
  308. echo "- $@: $$cmd" && echo $$cmd > $@ && \
  309. ( eval $$cmd ) >> $@ 2>&1 && \
  310. rm -f $@
  311. KERNEL_O := ../..
  312. ifneq ($(O),)
  313. KERNEL_O := $(O)
  314. endif
  315. make_kernelsrc:
  316. @echo "- make -C <kernelsrc> $(PARALLEL_OPT) $(K_O_OPT) tools/perf"
  317. $(call clean); \
  318. (make -C ../.. $(PARALLEL_OPT) $(K_O_OPT) tools/perf) > $@ 2>&1 && \
  319. test -x $(KERNEL_O)/tools/perf/perf && rm -f $@ || (cat $@ ; false)
  320. make_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. make_libperf:
  326. @echo "- make -C lib";
  327. make -C lib clean >$@ 2>&1; make -C lib >>$@ 2>&1 && rm $@
  328. FEATURES_DUMP_FILE := $(FULL_O)/BUILD_TEST_FEATURE_DUMP
  329. FEATURES_DUMP_FILE_STATIC := $(FULL_O)/BUILD_TEST_FEATURE_DUMP_STATIC
  330. all: $(run) $(run_O) tarpkg make_kernelsrc make_kernelsrc_tools
  331. @echo OK
  332. @rm -f $(FEATURES_DUMP_FILE) $(FEATURES_DUMP_FILE_STATIC)
  333. out: $(run_O)
  334. @echo OK
  335. @rm -f $(FEATURES_DUMP_FILE) $(FEATURES_DUMP_FILE_STATIC)
  336. ifeq ($(REUSE_FEATURES_DUMP),1)
  337. $(FEATURES_DUMP_FILE):
  338. $(call clean)
  339. @cmd="cd $(PERF) && make FEATURE_DUMP_COPY=$@ $(O_OPT) feature-dump"; \
  340. echo "- $@: $$cmd" && echo $$cmd && \
  341. ( eval $$cmd ) > /dev/null 2>&1
  342. $(FEATURES_DUMP_FILE_STATIC):
  343. $(call clean)
  344. @cmd="cd $(PERF) && make FEATURE_DUMP_COPY=$@ $(O_OPT) LDFLAGS='-static' feature-dump"; \
  345. echo "- $@: $$cmd" && echo $$cmd && \
  346. ( eval $$cmd ) > /dev/null 2>&1
  347. # Add feature dump dependency for run/run_O targets
  348. $(foreach t,$(run) $(run_O),$(eval \
  349. $(t): $(if $(findstring make_static,$(t)),\
  350. $(FEATURES_DUMP_FILE_STATIC),\
  351. $(FEATURES_DUMP_FILE))))
  352. # Append 'FEATURES_DUMP=' option to all test cases. For example:
  353. # make_no_libbpf: NO_LIBBPF=1 --> NO_LIBBPF=1 FEATURES_DUMP=/a/b/BUILD_TEST_FEATURE_DUMP
  354. # make_static: LDFLAGS=-static --> LDFLAGS=-static FEATURES_DUMP=/a/b/BUILD_TEST_FEATURE_DUMP_STATIC
  355. $(foreach t,$(run),$(if $(findstring make_static,$(t)),\
  356. $(eval $(t) := $($(t)) FEATURES_DUMP=$(FEATURES_DUMP_FILE_STATIC)),\
  357. $(eval $(t) := $($(t)) FEATURES_DUMP=$(FEATURES_DUMP_FILE))))
  358. endif
  359. .PHONY: all $(run) $(run_O) tarpkg clean make_kernelsrc make_kernelsrc_tools make_libperf
  360. endif # ifndef MK