<html dir="ltr"><head></head><body style="text-align:left; direction:ltr;"><div><br></div><div><br></div><div>-----Original Message-----</div><div><b>From</b>: Athira Rajeev <<a href="mailto:Athira%20Rajeev%20%3catrajeev@linux.vnet.ibm.com%3e">atrajeev@linux.vnet.ibm.com</a>></div><div><b>To</b>: <a href="mailto:acme@kernel.org">acme@kernel.org</a>, <a href="mailto:jolsa@kernel.org">jolsa@kernel.org</a></div><div><b>Cc</b>: <a href="mailto:mpe@ellerman.id.au">mpe@ellerman.id.au</a>, <a href="mailto:linux-perf-users@vger.kernel.org">linux-perf-users@vger.kernel.org</a>, <a href="mailto:linuxppc-dev@lists.ozlabs.org">linuxppc-dev@lists.ozlabs.org</a>, <a href="mailto:maddy@linux.vnet.ibm.com">maddy@linux.vnet.ibm.com</a>, <a href="mailto:rnsastry@linux.ibm.com">rnsastry@linux.ibm.com</a>, <a href="mailto:kjain@linux.ibm.com">kjain@linux.ibm.com</a>, <a href="mailto:disgoel@linux.vnet.ibm.com">disgoel@linux.vnet.ibm.com</a>, <a href="mailto:irogers@google.com">irogers@google.com</a></div><div><b>Subject</b>: [PATCH V2] tools/perf/tests: Skip perf BPF test if clang is not present</div><div><b>Date</b>: Wed, 11 May 2022 17:24:38 +0530</div><div><br></div><pre>Perf BPF filter test fails in environment where "clang"</pre><pre>is not installed.</pre><pre><br></pre><pre>Test failure logs:</pre><pre><br></pre><pre><<>></pre><pre> 42: BPF filter                    :</pre><pre> 42.1: Basic BPF filtering         : Skip</pre><pre> 42.2: BPF pinning                 : FAILED!</pre><pre> 42.3: BPF prologue generation     : FAILED!</pre><pre><<>></pre><pre><br></pre><pre>Enabling verbose option provided debug logs which says</pre><pre>clang/llvm needs to be installed. Snippet of verbose logs:</pre><pre><br></pre><pre><<>></pre><pre> 42.2: BPF pinning                  :</pre><pre> --- start ---</pre><pre>test child forked, pid 61423</pre><pre>ERROR:    unable to find clang.</pre><pre>Hint:       Try to install latest clang/llvm to support BPF.</pre><pre>        Check your $PATH</pre><pre><br></pre><pre><<logs_here>></pre><pre><br></pre><pre>Failed to compile test case: 'Basic BPF llvm compile'</pre><pre>Unable to get BPF object, fix kbuild first</pre><pre>test child finished with -1</pre><pre> ---- end ----</pre><pre>BPF filter subtest 2: FAILED!</pre><pre><<>></pre><pre><br></pre><pre>Here subtests, "BPF pinning" and "BPF prologue generation"</pre><pre>failed and logs shows clang/llvm is needed. After installing</pre><pre>clang, testcase passes.</pre><pre><br></pre><pre>Reason on why subtest failure happens though logs has proper</pre><pre>debug information:</pre><pre>Main function __test__bpf calls test_llvm__fetch_bpf_obj by</pre><pre>passing 4th argument as true ( 4th arguments maps to parameter</pre><pre>"force" in test_llvm__fetch_bpf_obj ). But this will cause</pre><pre>test_llvm__fetch_bpf_obj to skip the check for clang/llvm.</pre><pre><br></pre><pre>Snippet of code part which checks for clang based on</pre><pre>parameter "force" in test_llvm__fetch_bpf_obj:</pre><pre><br></pre><pre><<>></pre><pre>if (!force && (!llvm_param.user_set_param &&</pre><pre><<>></pre><pre><br></pre><pre>Since force is set to "false", test won't get skipped and</pre><pre>fails to compile test case. The BPF code compilation needs</pre><pre>clang, So pass the fourth argument as "false" and also skip</pre><pre>the test if reason for return is "TEST_SKIP"</pre><pre><br></pre><pre>After the patch:</pre><pre><br></pre><pre><<>></pre><pre> 42: BPF filter                    :</pre><pre> 42.1: Basic BPF filtering         : Skip</pre><pre> 42.2: BPF pinning                 : Skip</pre><pre> 42.3: BPF prologue generation     : Skip</pre><pre><<>></pre><pre><br></pre><pre>Fixes: ba1fae431e74 ("perf test: Add 'perf test BPF'")</pre><pre>Signed-off-by: Athira Rajeev <</pre><a href="mailto:atrajeev@linux.vnet.ibm.com"><pre>atrajeev@linux.vnet.ibm.com</pre></a><pre>></pre><pre>---</pre><pre>Changelog:</pre><pre> Addressed review comments from Arnaldo by adding</pre><pre> reason for skipping of testcase.</pre><pre><br></pre><pre> tools/perf/tests/bpf.c | 10 ++++++----</pre><pre> 1 file changed, 6 insertions(+), 4 deletions(-)</pre><pre><br></pre><pre style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">Tested the patch on powerpc and powernv, perf BPF test works fine with the patch.</pre><pre style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">Tested-by: Disha Goel <<a href="mailto:disgoel@linux.vnet.ibm.com"></a><a href="mailto:disgoel@linux.vnet.ibm.com">disgoel@linux.vnet.ibm.com</a>></pre><pre><br></pre><pre>diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c</pre><pre>index 57b9591f7cbb..17c023823713 100644</pre><pre>--- a/tools/perf/tests/bpf.c</pre><pre>+++ b/tools/perf/tests/bpf.c</pre><pre>@@ -222,11 +222,11 @@ static int __test__bpf(int idx)</pre><pre><br></pre><pre>    ret = test_llvm__fetch_bpf_obj(&obj_buf, &obj_buf_sz,</pre><pre>                                   bpf_testcase_table[idx].prog_id,</pre><pre>-                                true, NULL);</pre><pre>+                                    false, NULL);</pre><pre>     if (ret != TEST_OK || !obj_buf || !obj_buf_sz) {</pre><pre>                 pr_debug("Unable to get BPF object, %s\n",</pre><pre>                      bpf_testcase_table[idx].msg_compile_fail);</pre><pre>-             if (idx == 0)</pre><pre>+           if ((idx == 0) || (ret == TEST_SKIP))</pre><pre>                    return TEST_SKIP;</pre><pre>                else</pre><pre>                     return TEST_FAIL;</pre><pre>@@ -364,9 +364,11 @@ static int test__bpf_prologue_test(struct test_suite *test __maybe_unused,</pre><pre> static struct test_case bpf_tests[] = {</pre><pre> #ifdef HAVE_LIBBPF_SUPPORT</pre><pre>         TEST_CASE("Basic BPF filtering", basic_bpf_test),</pre><pre>-     TEST_CASE("BPF pinning", bpf_pinning),</pre><pre>+        TEST_CASE_REASON("BPF pinning", bpf_pinning,</pre><pre>+                  "clang isn't installed or environment missing BPF support"),</pre><pre> #ifdef HAVE_BPF_PROLOGUE</pre><pre>-  TEST_CASE("BPF prologue generation", bpf_prologue_test),</pre><pre>+      TEST_CASE_REASON("BPF prologue generation", bpf_prologue_test,</pre><pre>+                        "clang isn't installed or environment missing BPF support"),</pre><pre> #else</pre><pre>      TEST_CASE_REASON("BPF prologue generation", bpf_prologue_test, "not compiled in"),</pre><pre> #endif</pre></body></html>