Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754839AbbHJGTZ (ORCPT ); Mon, 10 Aug 2015 02:19:25 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:49187 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752614AbbHJGTW (ORCPT ); Mon, 10 Aug 2015 02:19:22 -0400 From: Wang Nan To: , CC: , , , , , , , , , , , , Subject: [PATCH 14/27] perf test: Enable 'perf test' run as test targets Date: Mon, 10 Aug 2015 06:15:56 +0000 Message-ID: <1439187369-66492-15-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1439187369-66492-1-git-send-email-wangnan0@huawei.com> References: <1439187369-66492-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A010204.55C841D0.0060,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 34d0ab2de3de624f4572474758d9590b Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4967 Lines: 177 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 Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: Brendan Gregg Cc: Daniel Borkmann Cc: David Ahern Cc: He Kuang Cc: Jiri Olsa Cc: Kaixu Xia Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Zefan Li Cc: pi3orama@163.com --- 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 ' > $@ 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 +#include +#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@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/