Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libperf: Change tests to single static and shared binaries

Make tests to be two binaries 'tests_static' and 'tests_shared', so the
maintenance is easier.

Adding tests under libperf build system, so we define all the flags just
once.

Adding make-tests tule to just compile tests without running them.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Shunsuke Nakamura <nakamura.shun@fujitsu.com>
Link: http://lore.kernel.org/lkml/20210706151704.73662-2-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
3d970601 b4b046ff

+67 -51
+2
tools/lib/perf/Build
··· 11 11 $(OUTPUT)zalloc.o: ../../lib/zalloc.c FORCE 12 12 $(call rule_mkdir) 13 13 $(call if_changed_dep,cc_o_c) 14 + 15 + tests-y += tests/
+25 -5
tools/lib/perf/Makefile
··· 52 52 Q = @ 53 53 endif 54 54 55 + TEST_ARGS := $(if $(V),-v) 56 + 55 57 # Set compile option CFLAGS 56 58 ifdef EXTRA_CFLAGS 57 59 CFLAGS := $(EXTRA_CFLAGS) ··· 138 136 139 137 clean: $(LIBAPI)-clean 140 138 $(call QUIET_CLEAN, libperf) $(RM) $(LIBPERF_A) \ 141 - *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBPERF_VERSION) .*.d .*.cmd LIBPERF-CFLAGS $(LIBPERF_PC) 142 - $(Q)$(MAKE) -C tests clean 139 + *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBPERF_VERSION) .*.d .*.cmd tests/*.o LIBPERF-CFLAGS $(LIBPERF_PC) \ 140 + $(TESTS_STATIC) $(TESTS_SHARED) 143 141 144 - tests: libs 145 - $(Q)$(MAKE) -C tests 146 - $(Q)$(MAKE) -C tests run 142 + TESTS_IN = tests-in.o 143 + 144 + TESTS_STATIC = $(OUTPUT)tests-static 145 + TESTS_SHARED = $(OUTPUT)tests-shared 146 + 147 + $(TESTS_IN): FORCE 148 + $(Q)$(MAKE) $(build)=tests 149 + 150 + $(TESTS_STATIC): $(TESTS_IN) $(LIBPERF_A) $(LIBAPI) 151 + $(QUIET_LINK)$(CC) -o $@ $^ 152 + 153 + $(TESTS_SHARED): $(TESTS_IN) $(LIBAPI) 154 + $(QUIET_LINK)$(CC) -o $@ -L$(if $(OUTPUT),$(OUTPUT),.) $^ -lperf 155 + 156 + make-tests: libs $(TESTS_SHARED) $(TESTS_STATIC) 157 + 158 + tests: make-tests 159 + @echo "running static:" 160 + @./$(TESTS_STATIC) $(TEST_ARGS) 161 + @echo "running dynamic:" 162 + @LD_LIBRARY_PATH=. ./$(TESTS_SHARED) $(TEST_ARGS) 147 163 148 164 $(LIBPERF_PC): 149 165 $(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
+2 -2
tools/lib/perf/include/internal/tests.h
··· 5 5 #include <stdio.h> 6 6 #include <unistd.h> 7 7 8 - int tests_failed; 9 - int tests_verbose; 8 + extern int tests_failed; 9 + extern int tests_verbose; 10 10 11 11 static inline int get_verbose(char **argv, int argc) 12 12 {
+5
tools/lib/perf/tests/Build
··· 1 + tests-y += main.o 2 + tests-y += test-evsel.o 3 + tests-y += test-evlist.o 4 + tests-y += test-cpumap.o 5 + tests-y += test-threadmap.o
-40
tools/lib/perf/tests/Makefile
··· 1 - # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) 2 - 3 - TESTS = test-cpumap test-threadmap test-evlist test-evsel 4 - 5 - TESTS_SO := $(addsuffix -so,$(TESTS)) 6 - TESTS_A := $(addsuffix -a,$(TESTS)) 7 - 8 - TEST_ARGS := $(if $(V),-v) 9 - 10 - # Set compile option CFLAGS 11 - ifdef EXTRA_CFLAGS 12 - CFLAGS := $(EXTRA_CFLAGS) 13 - else 14 - CFLAGS := -g -Wall 15 - endif 16 - 17 - all: 18 - 19 - include $(srctree)/tools/scripts/Makefile.include 20 - 21 - INCLUDE = -I$(srctree)/tools/lib/perf/include -I$(srctree)/tools/include -I$(srctree)/tools/lib 22 - 23 - $(TESTS_A): FORCE 24 - $(QUIET_LINK)$(CC) $(INCLUDE) $(CFLAGS) -o $@ $(subst -a,.c,$@) ../libperf.a $(LIBAPI) 25 - 26 - $(TESTS_SO): FORCE 27 - $(QUIET_LINK)$(CC) $(INCLUDE) $(CFLAGS) -L.. -o $@ $(subst -so,.c,$@) $(LIBAPI) -lperf 28 - 29 - all: $(TESTS_A) $(TESTS_SO) 30 - 31 - run: 32 - @echo "running static:" 33 - @for i in $(TESTS_A); do ./$$i $(TEST_ARGS); done 34 - @echo "running dynamic:" 35 - @for i in $(TESTS_SO); do LD_LIBRARY_PATH=../ ./$$i $(TEST_ARGS); done 36 - 37 - clean: 38 - $(call QUIET_CLEAN, tests)$(RM) $(TESTS_A) $(TESTS_SO) 39 - 40 - .PHONY: all clean FORCE
+15
tools/lib/perf/tests/main.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + #include <internal/tests.h> 3 + #include "tests.h" 4 + 5 + int tests_failed; 6 + int tests_verbose; 7 + 8 + int main(int argc, char **argv) 9 + { 10 + __T("test cpumap", !test_cpumap(argc, argv)); 11 + __T("test threadmap", !test_threadmap(argc, argv)); 12 + __T("test evlist", !test_evlist(argc, argv)); 13 + __T("test evsel", !test_evsel(argc, argv)); 14 + return 0; 15 + }
+2 -1
tools/lib/perf/tests/test-cpumap.c
··· 3 3 #include <stdio.h> 4 4 #include <perf/cpumap.h> 5 5 #include <internal/tests.h> 6 + #include "tests.h" 6 7 7 8 static int libperf_print(enum libperf_print_level level, 8 9 const char *fmt, va_list ap) ··· 11 10 return vfprintf(stderr, fmt, ap); 12 11 } 13 12 14 - int main(int argc, char **argv) 13 + int test_cpumap(int argc, char **argv) 15 14 { 16 15 struct perf_cpu_map *cpus; 17 16
+2 -1
tools/lib/perf/tests/test-evlist.c
··· 18 18 #include <perf/event.h> 19 19 #include <internal/tests.h> 20 20 #include <api/fs/fs.h> 21 + #include "tests.h" 21 22 22 23 static int libperf_print(enum libperf_print_level level, 23 24 const char *fmt, va_list ap) ··· 398 397 return 0; 399 398 } 400 399 401 - int main(int argc, char **argv) 400 + int test_evlist(int argc, char **argv) 402 401 { 403 402 __T_START; 404 403
+2 -1
tools/lib/perf/tests/test-evsel.c
··· 6 6 #include <perf/threadmap.h> 7 7 #include <perf/evsel.h> 8 8 #include <internal/tests.h> 9 + #include "tests.h" 9 10 10 11 static int libperf_print(enum libperf_print_level level, 11 12 const char *fmt, va_list ap) ··· 185 184 return 0; 186 185 } 187 186 188 - int main(int argc, char **argv) 187 + int test_evsel(int argc, char **argv) 189 188 { 190 189 __T_START; 191 190
+2 -1
tools/lib/perf/tests/test-threadmap.c
··· 3 3 #include <stdio.h> 4 4 #include <perf/threadmap.h> 5 5 #include <internal/tests.h> 6 + #include "tests.h" 6 7 7 8 static int libperf_print(enum libperf_print_level level, 8 9 const char *fmt, va_list ap) ··· 11 10 return vfprintf(stderr, fmt, ap); 12 11 } 13 12 14 - int main(int argc, char **argv) 13 + int test_threadmap(int argc, char **argv) 15 14 { 16 15 struct perf_thread_map *threads; 17 16
+10
tools/lib/perf/tests/tests.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef TESTS_H 3 + #define TESTS_H 4 + 5 + int test_cpumap(int argc, char **argv); 6 + int test_threadmap(int argc, char **argv); 7 + int test_evlist(int argc, char **argv); 8 + int test_evsel(int argc, char **argv); 9 + 10 + #endif /* TESTS_H */