Skip to content

Commit 6a7d550

Browse files
WangNan0acmel
authored andcommitted
perf test: Check environment before start real BPF test
Copying perf to old kernel system results: # perf test bpf 37: Test BPF filter : 37.1: Test basic BPF filtering : FAILED! 37.2: Test BPF prologue generation : Skip However, in case when kernel doesn't support a test case it should return 'Skip', 'FAILED!' should be reserved for kernel tests for when the kernel supports a feature that then fails to work as advertised. This patch checks environment before real testcase. Signed-off-by: Wang Nan <[email protected]> Suggested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Brendan Gregg <[email protected]> Cc: Daniel Borkmann <[email protected]> Cc: He Kuang <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Li Zefan <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Will Deacon <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent fd786fa commit 6a7d550

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tools/perf/tests/bpf.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#include <stdio.h>
22
#include <sys/epoll.h>
3+
#include <util/util.h>
34
#include <util/bpf-loader.h>
45
#include <util/evlist.h>
6+
#include <linux/bpf.h>
7+
#include <linux/filter.h>
8+
#include <bpf/bpf.h>
59
#include "tests.h"
610
#include "llvm.h"
711
#include "debug.h"
@@ -243,6 +247,36 @@ const char *test__bpf_subtest_get_desc(int i)
243247
return bpf_testcase_table[i].desc;
244248
}
245249

250+
static int check_env(void)
251+
{
252+
int err;
253+
unsigned int kver_int;
254+
char license[] = "GPL";
255+
256+
struct bpf_insn insns[] = {
257+
BPF_MOV64_IMM(BPF_REG_0, 1),
258+
BPF_EXIT_INSN(),
259+
};
260+
261+
err = fetch_kernel_version(&kver_int, NULL, 0);
262+
if (err) {
263+
pr_debug("Unable to get kernel version\n");
264+
return err;
265+
}
266+
267+
err = bpf_load_program(BPF_PROG_TYPE_KPROBE, insns,
268+
sizeof(insns) / sizeof(insns[0]),
269+
license, kver_int, NULL, 0);
270+
if (err < 0) {
271+
pr_err("Missing basic BPF support, skip this test: %s\n",
272+
strerror(errno));
273+
return err;
274+
}
275+
close(err);
276+
277+
return 0;
278+
}
279+
246280
int test__bpf(int i)
247281
{
248282
int err;
@@ -255,6 +289,9 @@ int test__bpf(int i)
255289
return TEST_SKIP;
256290
}
257291

292+
if (check_env())
293+
return TEST_SKIP;
294+
258295
err = __test__bpf(i);
259296
return err;
260297
}

0 commit comments

Comments
 (0)