Commit 3d970601 authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo
Browse files

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: default avatarJiri 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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent b4b046ff
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -11,3 +11,5 @@ libperf-y += lib.o
$(OUTPUT)zalloc.o: ../../lib/zalloc.c FORCE
	$(call rule_mkdir)
	$(call if_changed_dep,cc_o_c)

tests-y += tests/
+25 −5
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@ else
  Q = @
endif

TEST_ARGS := $(if $(V),-v)

# Set compile option CFLAGS
ifdef EXTRA_CFLAGS
  CFLAGS := $(EXTRA_CFLAGS)
@@ -136,12 +138,30 @@ all: fixdep

clean: $(LIBAPI)-clean
	$(call QUIET_CLEAN, libperf) $(RM) $(LIBPERF_A) \
                *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBPERF_VERSION) .*.d .*.cmd LIBPERF-CFLAGS $(LIBPERF_PC)
	$(Q)$(MAKE) -C tests clean
                *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBPERF_VERSION) .*.d .*.cmd tests/*.o LIBPERF-CFLAGS $(LIBPERF_PC) \
                $(TESTS_STATIC) $(TESTS_SHARED)

TESTS_IN = tests-in.o

TESTS_STATIC = $(OUTPUT)tests-static
TESTS_SHARED = $(OUTPUT)tests-shared

$(TESTS_IN): FORCE
	$(Q)$(MAKE) $(build)=tests

$(TESTS_STATIC): $(TESTS_IN) $(LIBPERF_A) $(LIBAPI)
	$(QUIET_LINK)$(CC) -o $@ $^

$(TESTS_SHARED): $(TESTS_IN) $(LIBAPI)
	$(QUIET_LINK)$(CC) -o $@ -L$(if $(OUTPUT),$(OUTPUT),.) $^ -lperf

make-tests: libs $(TESTS_SHARED) $(TESTS_STATIC)

tests: libs
	$(Q)$(MAKE) -C tests
	$(Q)$(MAKE) -C tests run
tests: make-tests
	@echo "running static:"
	@./$(TESTS_STATIC) $(TEST_ARGS)
	@echo "running dynamic:"
	@LD_LIBRARY_PATH=. ./$(TESTS_SHARED) $(TEST_ARGS)

$(LIBPERF_PC):
	$(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
+2 −2
Original line number Diff line number Diff line
@@ -5,8 +5,8 @@
#include <stdio.h>
#include <unistd.h>

int tests_failed;
int tests_verbose;
extern int tests_failed;
extern int tests_verbose;

static inline int get_verbose(char **argv, int argc)
{
+5 −0
Original line number Diff line number Diff line
tests-y += main.o
tests-y += test-evsel.o
tests-y += test-evlist.o
tests-y += test-cpumap.o
tests-y += test-threadmap.o

tools/lib/perf/tests/Makefile

deleted100644 → 0
+0 −40
Original line number Diff line number Diff line
# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)

TESTS = test-cpumap test-threadmap test-evlist test-evsel

TESTS_SO := $(addsuffix -so,$(TESTS))
TESTS_A  := $(addsuffix -a,$(TESTS))

TEST_ARGS := $(if $(V),-v)

# Set compile option CFLAGS
ifdef EXTRA_CFLAGS
  CFLAGS := $(EXTRA_CFLAGS)
else
  CFLAGS := -g -Wall
endif

all:

include $(srctree)/tools/scripts/Makefile.include

INCLUDE = -I$(srctree)/tools/lib/perf/include -I$(srctree)/tools/include -I$(srctree)/tools/lib

$(TESTS_A): FORCE
	$(QUIET_LINK)$(CC) $(INCLUDE) $(CFLAGS) -o $@ $(subst -a,.c,$@) ../libperf.a $(LIBAPI)

$(TESTS_SO): FORCE
	$(QUIET_LINK)$(CC) $(INCLUDE) $(CFLAGS) -L.. -o $@ $(subst -so,.c,$@) $(LIBAPI) -lperf

all: $(TESTS_A) $(TESTS_SO)

run:
	@echo "running static:"
	@for i in $(TESTS_A); do ./$$i $(TEST_ARGS); done
	@echo "running dynamic:"
	@for i in $(TESTS_SO); do LD_LIBRARY_PATH=../ ./$$i $(TEST_ARGS); done

clean:
	$(call QUIET_CLEAN, tests)$(RM) $(TESTS_A) $(TESTS_SO)

.PHONY: all clean FORCE
Loading