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>
This commit is contained in:
Jiri Olsa
2021-07-06 17:16:58 +02:00
committed by Arnaldo Carvalho de Melo
parent b4b046ff9e
commit 3d970601da
11 changed files with 67 additions and 51 deletions
+5
View File
@@ -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
View File
@@ -1,40 +0,0 @@
# 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
+15
View File
@@ -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;
}
+2 -1
View File
@@ -3,6 +3,7 @@
#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)
@@ -10,7 +11,7 @@ static int libperf_print(enum libperf_print_level level,
return vfprintf(stderr, fmt, ap);
}
int main(int argc, char **argv)
int test_cpumap(int argc, char **argv)
{
struct perf_cpu_map *cpus;
+2 -1
View File
@@ -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)
@@ -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;
+2 -1
View File
@@ -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)
@@ -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;
+2 -1
View File
@@ -3,6 +3,7 @@
#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)
@@ -10,7 +11,7 @@ static int libperf_print(enum libperf_print_level level,
return vfprintf(stderr, fmt, ap);
}
int main(int argc, char **argv)
int test_threadmap(int argc, char **argv)
{
struct perf_thread_map *threads;
+10
View File
@@ -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 */