Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753179AbbKQIht (ORCPT ); Tue, 17 Nov 2015 03:37:49 -0500 Received: from szxga01-in.huawei.com ([58.251.152.64]:18161 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752951AbbKQIhL (ORCPT ); Tue, 17 Nov 2015 03:37:11 -0500 From: Wang Nan To: , , CC: , , , Wang Nan , Wang Nan , "Arnaldo Carvalho de Melo" Subject: [PATCH 3/5] perf test: Print result for each subtest for llvm Date: Tue, 17 Nov 2015 08:32:48 +0000 Message-ID: <1447749170-175898-4-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1447749170-175898-1-git-send-email-wangnan0@huawei.com> References: <20151117012924.GA22729@kernel.org> <1447749170-175898-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.0A090205.564AE724.00E9,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 3ec33697584bf28d59a7c82c3393b33d Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 8996 Lines: 344 Currently 'perf test llvm' and 'perf test BPF' are combined by multiple sub-tests, but the result is only one line: # perf test LLVM 35: Test LLVM searching and compiling : Ok This patch introduces sub-tests support, allows perf test to report result for each sub-tests: # ./perf test LLVM 35: Test LLVM searching and compiling : 35.1: Basic BPF llvm compiling test : Ok 35.2: Test kbuild searching : Ok 35.3: Compile source for BPF prologue generation test : Ok When failure: # cat ~/.perfconfig [llvm] clang-path = "/bin/false" # ./perf test LLVM 35: Test LLVM searching and compiling : 35.1: Basic BPF llvm compiling test : FAILED! 35.2: Test kbuild searching : Skip 35.3: Compile source for BPF prologue generation test : Skip And: # rm ~/.perfconfig # ./perf test LLVM 35: Test LLVM searching and compiling : 35.1: Basic BPF llvm compiling test : Skip 35.2: Test kbuild searching : Skip 35.3: Compile source for BPF prologue generation test : Skip Skip by user: # ./perf test -s 1,`seq -s , 3 42` 1: vmlinux symtab matches kallsyms : Skip (user override) 2: detect openat syscall event : Ok ... 35: Test LLVM searching and compiling : Skip (user override) ... Signed-off-by: Wang Nan Cc: Arnaldo Carvalho de Melo --- tools/perf/tests/builtin-test.c | 111 ++++++++++++++++++++++++++++++++-------- tools/perf/tests/llvm.c | 65 +++++++++++------------ tools/perf/tests/tests.h | 22 +++++++- 3 files changed, 141 insertions(+), 57 deletions(-) diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index 80c442e..29225142 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -159,7 +159,13 @@ static struct test generic_tests[] = { }, { .desc = "Test LLVM searching and compiling", - .func = test__llvm, + .need_subtests = true, + .subtest = { + .skip_if_fail = true, + .get_nr = test__llvm_subtest_get_nr, + .get_desc = test__llvm_subtest_get_desc, + .func = test__llvm_subtest, + }, }, { .desc = "Test topology in session", @@ -203,7 +209,7 @@ static bool perf_test__matches(struct test *test, int curr, int argc, const char return false; } -static int run_test(struct test *test) +static int run_test(struct test *test, int subtest) { int status, err = -1, child = fork(); char sbuf[STRERR_BUFSIZE]; @@ -216,7 +222,10 @@ static int run_test(struct test *test) if (!child) { pr_debug("test child forked, pid %d\n", getpid()); - err = test->func(); + if (!test->need_subtests) + err = test->func(); + else + err = test->subtest.func(subtest); exit(err); } @@ -234,8 +243,48 @@ static int run_test(struct test *test) } #define for_each_test(j, t) \ - for (j = 0; j < ARRAY_SIZE(tests); j++) \ - for (t = &tests[j][0]; t->func; t++) + for (j = 0; j < ARRAY_SIZE(tests); j++) \ + for (t = &tests[j][0]; \ + (!t->need_subtests && t->func) || \ + (t->need_subtests && \ + t->subtest.get_nr && \ + t->subtest.get_desc && \ + t->subtest.func); \ + t++) + +static int test_and_print(struct test *t, bool force_skip, int subtest) +{ + int err; + + if (!force_skip) { + pr_debug("\n--- start ---\n"); + err = run_test(t, subtest); + pr_debug("---- end ----\n"); + } else { + pr_debug("\n--- force skipped ---\n"); + err = TEST_SKIP; + } + + if (!t->need_subtests) + pr_debug("%s:", t->desc); + else + pr_debug("%s subtest %d:", t->desc, subtest); + + switch (err) { + case TEST_OK: + pr_info(" Ok\n"); + break; + case TEST_SKIP: + color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip\n"); + break; + case TEST_FAIL: + default: + color_fprintf(stderr, PERF_COLOR_RED, " FAILED!\n"); + break; + } + + return err; +} static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist) { @@ -264,21 +313,43 @@ static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist) continue; } - pr_debug("\n--- start ---\n"); - err = run_test(t); - pr_debug("---- end ----\n%s:", t->desc); - - switch (err) { - case TEST_OK: - pr_info(" Ok\n"); - break; - case TEST_SKIP: - color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip\n"); - break; - case TEST_FAIL: - default: - color_fprintf(stderr, PERF_COLOR_RED, " FAILED!\n"); - break; + if (!t->need_subtests) { + test_and_print(t, false, -1); + } else { + int subn = t->subtest.get_nr(); + /* + * minus 2 to align with normal testcases. + * For subtest we print additional '.x' in number. + * for example: + * + * 35: Test LLVM searching and compiling : + * 35.1: Basic BPF llvm compiling test : Ok + */ + int subw = width > 2 ? width - 2 : width; + bool skip = false; + int subi; + + if (subn <= 0) { + color_fprintf(stderr, PERF_COLOR_YELLOW, + " Skip (not compiled in)\n"); + continue; + } + pr_info("\n"); + + for (subi = 0; subi < subn; subi++) { + int len = strlen(t->subtest.get_desc(subi)); + + if (subw < len) + subw = len; + } + + for (subi = 0; subi < subn; subi++) { + pr_info("%2d.%1d: %-*s:", i, subi + 1, subw, + t->subtest.get_desc(subi)); + err = test_and_print(t, skip, subi); + if (err != TEST_OK && t->subtest.skip_if_fail) + skip = true; + } } } diff --git a/tools/perf/tests/llvm.c b/tools/perf/tests/llvm.c index 7f4f7f7..cebb593 100644 --- a/tools/perf/tests/llvm.c +++ b/tools/perf/tests/llvm.c @@ -46,7 +46,7 @@ static struct { }, [LLVM_TESTCASE_BPF_PROLOGUE] = { .source = test_llvm__bpf_test_prologue_prog, - .desc = "Test BPF prologue generation", + .desc = "Compile source for BPF prologue generation test", }, }; @@ -131,44 +131,39 @@ out: return ret; } -int test__llvm(void) +int test__llvm_subtest(int i) { - enum test_llvm__testcase i; + int ret; + void *obj_buf = NULL; + size_t obj_buf_sz = 0; - for (i = 0; i < __LLVM_TESTCASE_MAX; i++) { - int ret; - void *obj_buf = NULL; - size_t obj_buf_sz = 0; + if ((i < 0) || (i >= __LLVM_TESTCASE_MAX)) + return TEST_FAIL; - ret = test_llvm__fetch_bpf_obj(&obj_buf, &obj_buf_sz, - i, false); + ret = test_llvm__fetch_bpf_obj(&obj_buf, &obj_buf_sz, + i, false); - if (ret == TEST_OK) { - ret = test__bpf_parsing(obj_buf, obj_buf_sz); - if (ret != TEST_OK) - pr_debug("Failed to parse test case '%s'\n", - bpf_source_table[i].desc); - } - free(obj_buf); - - switch (ret) { - case TEST_SKIP: - return TEST_SKIP; - case TEST_OK: - break; - default: - /* - * Test 0 is the basic LLVM test. If test 0 - * fail, the basic LLVM support not functional - * so the whole test should fail. If other test - * case fail, it can be fixed by adjusting - * config so don't report error. - */ - if (i == 0) - return TEST_FAIL; - else - return TEST_SKIP; + if (ret == TEST_OK) { + ret = test__bpf_parsing(obj_buf, obj_buf_sz); + if (ret != TEST_OK) { + pr_debug("Failed to parse test case '%s'\n", + bpf_source_table[i].desc); } } - return TEST_OK; + free(obj_buf); + + return ret; +} + +int test__llvm_subtest_get_nr(void) +{ + return __LLVM_TESTCASE_MAX; +} + +const char *test__llvm_subtest_get_desc(int i) +{ + if ((i < 0) || (i >= __LLVM_TESTCASE_MAX)) + return NULL; + + return bpf_source_table[i].desc; } diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index 3c8734a..f8f9eb6 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h @@ -1,6 +1,8 @@ #ifndef TESTS_H #define TESTS_H +#include + #define TEST_ASSERT_VAL(text, cond) \ do { \ if (!(cond)) { \ @@ -26,7 +28,19 @@ enum { struct test { const char *desc; - int (*func)(void); + + bool need_subtests; + + union { + int (*func)(void); + + struct { + bool skip_if_fail; + int (*get_nr)(void); + const char *(*get_desc)(int i); + int (*func)(int i); + } subtest; + }; }; /* Tests */ @@ -65,7 +79,11 @@ int test__fdarray__filter(void); int test__fdarray__add(void); int test__kmod_path__parse(void); int test__thread_map(void); -int test__llvm(void); + +const char *test__llvm_subtest_get_desc(int i); +int test__llvm_subtest_get_nr(void); +int test__llvm_subtest(int i); + int test__bpf(void); int test_session_topology(void); -- 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/