make 12 KB

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