Skip to content

Commit 7e1c908

Browse files
committed
selftests/bpf: Add bpf_copy_branch_snapshot test
Add test case for bpf_copy_branch_snapshot kfunc by reusing the one of bpf_get_branch_snapshot helper. Signed-off-by: Leon Hwang <[email protected]>
1 parent da54230 commit 7e1c908

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static void close_perf_events(void)
7373
free(pfd_array);
7474
}
7575

76-
void serial_test_get_branch_snapshot(void)
76+
static void test_branch_snapshot(int test_copy_branch_snapshot)
7777
{
7878
struct get_branch_snapshot *skel = NULL;
7979
int err;
@@ -93,6 +93,8 @@ void serial_test_get_branch_snapshot(void)
9393
if (!ASSERT_OK_PTR(skel, "get_branch_snapshot__open_and_load"))
9494
goto cleanup;
9595

96+
skel->bss->copy_branch_snapshot = test_copy_branch_snapshot;
97+
9698
err = kallsyms_find("bpf_testmod_loop_test", &skel->bss->address_low);
9799
if (!ASSERT_OK(err, "kallsyms_find"))
98100
goto cleanup;
@@ -128,3 +130,13 @@ void serial_test_get_branch_snapshot(void)
128130
get_branch_snapshot__destroy(skel);
129131
close_perf_events();
130132
}
133+
134+
void serial_test_get_branch_snapshot(void)
135+
{
136+
test_branch_snapshot(0);
137+
}
138+
139+
void serial_test_copy_branch_snapshot(void)
140+
{
141+
test_branch_snapshot(1);
142+
}

tools/testing/selftests/bpf/progs/get_branch_snapshot.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ char _license[] SEC("license") = "GPL";
99
__u64 test1_hits = 0;
1010
__u64 address_low = 0;
1111
__u64 address_high = 0;
12+
int copy_branch_snapshot = 0;
1213
int wasted_entries = 0;
1314
long total_entries = 0;
1415

@@ -25,7 +26,10 @@ int BPF_PROG(test1, int n, int ret)
2526
{
2627
long i;
2728

28-
total_entries = bpf_get_branch_snapshot(entries, sizeof(entries), 0);
29+
if (copy_branch_snapshot)
30+
total_entries = bpf_copy_branch_snapshot(ctx, entries, sizeof(entries), 0);
31+
else
32+
total_entries = bpf_get_branch_snapshot(entries, sizeof(entries), 0);
2933
total_entries /= sizeof(struct perf_branch_entry);
3034

3135
for (i = 0; i < ENTRY_CNT; i++) {

0 commit comments

Comments
 (0)