[PATCH 14/27] perf test: Enable 'perf test' run as test targets
From: Wang Nan
Date: Mon Aug 10 2015 - 02:19:28 EST
This patch introduce test target support which allows 'perf test'
work as program be traced by test cases. One test target
'testtarget__epoll_pwait_loop' is added, which calls epoll_pwait()
111 times with different invalid fd. Further test cases can use it
to test result of reacing and filtering. BPF test will be the first
user so it resides in bpf.c.
Signed-off-by: Wang Nan <wangnan0@xxxxxxxxxx>
Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Cc: Alexei Starovoitov <ast@xxxxxxxxxxxx>
Cc: Brendan Gregg <brendan.d.gregg@xxxxxxxxx>
Cc: Daniel Borkmann <daniel@xxxxxxxxxxxxx>
Cc: David Ahern <dsahern@xxxxxxxxx>
Cc: He Kuang <hekuang@xxxxxxxxxx>
Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Kaixu Xia <xiakaixu@xxxxxxxxxx>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@xxxxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Cc: Zefan Li <lizefan@xxxxxxxxxx>
Cc: pi3orama@xxxxxxx
---
tools/perf/tests/Build | 1 +
tools/perf/tests/bpf.c | 15 +++++++++++++
tools/perf/tests/builtin-test.c | 49 +++++++++++++++++++++++++++++++++++++++++
tools/perf/tests/tests.h | 2 ++
4 files changed, 67 insertions(+)
create mode 100644 tools/perf/tests/bpf.c
diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index 8c98409..7ceb448 100644
--- a/tools/perf/tests/Build
+++ b/tools/perf/tests/Build
@@ -33,6 +33,7 @@ perf-y += parse-no-sample-id-all.o
perf-y += kmod-path.o
perf-y += thread-map.o
perf-y += llvm.o llvm-src.o
+perf-y += bpf.o
$(OUTPUT)tests/llvm-src.c: tests/bpf-script-example.c
$(Q)echo '#include <tests/llvm.h>' > $@
diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c
new file mode 100644
index 0000000..1a9eec3
--- /dev/null
+++ b/tools/perf/tests/bpf.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+#include <sys/epoll.h>
+#include "tests.h"
+#include "debug.h"
+#define NR_ITERS 111
+
+int testtarget__epoll_pwait_loop(void)
+{
+ int i;
+
+ /* Should fail NR_ITERS times */
+ for (i = 0; i < NR_ITERS; i++)
+ epoll_pwait(-(i + 1), NULL, 0, 0, NULL);
+ return 0;
+}
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 1a349e8..0d0c963 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -15,6 +15,7 @@
#include "symbol.h"
static struct test {
+ bool is_test_target;
const char *desc;
int (*func)(void);
void (*prepare)(void);
@@ -182,6 +183,15 @@ static struct test {
.prepare = test__llvm_prepare,
.cleanup = test__llvm_cleanup,
},
+ /*
+ * Put test targets after all test cases so sequence number will be
+ * less confusing.
+ */
+ {
+ .is_test_target = true,
+ .desc = TESTTARGET_EPOLL_PWAIT_LOOP,
+ .func = testtarget__epoll_pwait_loop,
+ },
{
.func = NULL,
},
@@ -245,12 +255,39 @@ static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
{
int i = 0;
int width = 0;
+ bool run_test_targets = true;
while (tests[i].func) {
int len = strlen(tests[i].desc);
if (width < len)
width = len;
+
+ /*
+ * Check whether we are going to run test targets or test
+ * cases:
+ *
+ * Test targets must be specified explicitly.
+ */
+ switch (argc) {
+ case 0:
+ run_test_targets = false;
+ break;
+ default:
+ if (!perf_test__matches(i, argc, argv))
+ break;
+ /*
+ * If there is at lease one matched tests is
+ * not test target, run test cases.
+ *
+ * This can avoid something like 'perf test T'
+ * matches different targets and cases.
+ */
+ if (!tests[i].is_test_target)
+ run_test_targets = false;
+ break;
+ }
+
++i;
}
@@ -261,6 +298,15 @@ static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
if (!perf_test__matches(curr, argc, argv))
continue;
+ if (run_test_targets) {
+ if (tests[curr].is_test_target)
+ tests[curr].func();
+ continue;
+ }
+
+ if (tests[curr].is_test_target)
+ continue;
+
pr_info("%2d: %-*s:", i, width, tests[curr].desc);
if (intlist__find(skiplist, i)) {
@@ -290,6 +336,9 @@ static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
}
}
+ if (run_test_targets)
+ exit(0);
+
return 0;
}
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 0d79f04..0138a3d 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -65,6 +65,8 @@ int test__thread_map(void);
int test__llvm(void);
void test__llvm_prepare(void);
void test__llvm_cleanup(void);
+#define TESTTARGET_EPOLL_PWAIT_LOOP "TESTTARGET: epoll_pwait loop"
+int testtarget__epoll_pwait_loop(void);
#if defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__)
#ifdef HAVE_DWARF_UNWIND_SUPPORT
--
1.8.3.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/