make 9.8 KB

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