Skip to content

Commit

Permalink
libperf: Change tests to single static and shared binaries
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jiri Olsa authored and Arnaldo Carvalho de Melo committed Jul 7, 2021
1 parent b4b046f commit 3d97060
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 51 deletions.
2 changes: 2 additions & 0 deletions tools/lib/perf/Build
Original file line number Diff line number Diff line change
Expand Up @@ -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/
30 changes: 25 additions & 5 deletions tools/lib/perf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ else
Q = @
endif

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

# Set compile option CFLAGS
ifdef EXTRA_CFLAGS
CFLAGS := $(EXTRA_CFLAGS)
Expand Down Expand Up @@ -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)|" \
Expand Down
4 changes: 2 additions & 2 deletions tools/lib/perf/include/internal/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
5 changes: 5 additions & 0 deletions tools/lib/perf/tests/Build
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
tests-y += main.o
tests-y += test-evsel.o
tests-y += test-evlist.o
tests-y += test-cpumap.o
tests-y += test-threadmap.o
40 changes: 0 additions & 40 deletions tools/lib/perf/tests/Makefile

This file was deleted.

15 changes: 15 additions & 0 deletions tools/lib/perf/tests/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: GPL-2.0
#include <internal/tests.h>
#include "tests.h"

int tests_failed;
int tests_verbose;

int main(int argc, char **argv)
{
__T("test cpumap", !test_cpumap(argc, argv));
__T("test threadmap", !test_threadmap(argc, argv));
__T("test evlist", !test_evlist(argc, argv));
__T("test evsel", !test_evsel(argc, argv));
return 0;
}
3 changes: 2 additions & 1 deletion tools/lib/perf/tests/test-cpumap.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
#include <stdio.h>
#include <perf/cpumap.h>
#include <internal/tests.h>
#include "tests.h"

static int libperf_print(enum libperf_print_level level,
const char *fmt, va_list ap)
{
return vfprintf(stderr, fmt, ap);
}

int main(int argc, char **argv)
int test_cpumap(int argc, char **argv)
{
struct perf_cpu_map *cpus;

Expand Down
3 changes: 2 additions & 1 deletion tools/lib/perf/tests/test-evlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <perf/event.h>
#include <internal/tests.h>
#include <api/fs/fs.h>
#include "tests.h"

static int libperf_print(enum libperf_print_level level,
const char *fmt, va_list ap)
Expand Down Expand Up @@ -397,7 +398,7 @@ static int test_mmap_cpus(void)
return 0;
}

int main(int argc, char **argv)
int test_evlist(int argc, char **argv)
{
__T_START;

Expand Down
3 changes: 2 additions & 1 deletion tools/lib/perf/tests/test-evsel.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <perf/threadmap.h>
#include <perf/evsel.h>
#include <internal/tests.h>
#include "tests.h"

static int libperf_print(enum libperf_print_level level,
const char *fmt, va_list ap)
Expand Down Expand Up @@ -184,7 +185,7 @@ static int test_stat_user_read(int event)
return 0;
}

int main(int argc, char **argv)
int test_evsel(int argc, char **argv)
{
__T_START;

Expand Down
3 changes: 2 additions & 1 deletion tools/lib/perf/tests/test-threadmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
#include <stdio.h>
#include <perf/threadmap.h>
#include <internal/tests.h>
#include "tests.h"

static int libperf_print(enum libperf_print_level level,
const char *fmt, va_list ap)
{
return vfprintf(stderr, fmt, ap);
}

int main(int argc, char **argv)
int test_threadmap(int argc, char **argv)
{
struct perf_thread_map *threads;

Expand Down
10 changes: 10 additions & 0 deletions tools/lib/perf/tests/tests.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef TESTS_H
#define TESTS_H

int test_cpumap(int argc, char **argv);
int test_threadmap(int argc, char **argv);
int test_evlist(int argc, char **argv);
int test_evsel(int argc, char **argv);

#endif /* TESTS_H */

0 comments on commit 3d97060

Please sign in to comment.