Skip to content

Commit 57ddeb8

Browse files
Byte-Labborkmann
authored andcommitted
selftests/bpf: Add testcase for async callback return value failure
A previous commit updated the verifier to print an accurate failure message for when someone specifies a nonzero return value from an async callback. This adds a testcase for validating that the verifier emits the correct message in such a case. Signed-off-by: David Vernet <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 8299559 commit 57ddeb8

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/* Copyright (c) 2021 Facebook */
33
#include <test_progs.h>
44
#include "timer.skel.h"
5+
#include "timer_failure.skel.h"
56

67
static int timer(struct timer *timer_skel)
78
{
@@ -49,10 +50,11 @@ void serial_test_timer(void)
4950

5051
timer_skel = timer__open_and_load();
5152
if (!ASSERT_OK_PTR(timer_skel, "timer_skel_load"))
52-
goto cleanup;
53+
return;
5354

5455
err = timer(timer_skel);
5556
ASSERT_OK(err, "timer");
56-
cleanup:
5757
timer__destroy(timer_skel);
58+
59+
RUN_TESTS(timer_failure);
5860
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */
3+
4+
#include <linux/bpf.h>
5+
#include <time.h>
6+
#include <errno.h>
7+
#include <bpf/bpf_helpers.h>
8+
#include "bpf_misc.h"
9+
#include "bpf_tcp_helpers.h"
10+
11+
char _license[] SEC("license") = "GPL";
12+
13+
struct elem {
14+
struct bpf_timer t;
15+
};
16+
17+
struct {
18+
__uint(type, BPF_MAP_TYPE_ARRAY);
19+
__uint(max_entries, 1);
20+
__type(key, int);
21+
__type(value, struct elem);
22+
} timer_map SEC(".maps");
23+
24+
static int timer_cb_ret1(void *map, int *key, struct bpf_timer *timer)
25+
{
26+
if (bpf_get_smp_processor_id() % 2)
27+
return 1;
28+
else
29+
return 0;
30+
}
31+
32+
SEC("fentry/bpf_fentry_test1")
33+
__failure __msg("should have been in (0x0; 0x0)")
34+
int BPF_PROG2(test_ret_1, int, a)
35+
{
36+
int key = 0;
37+
struct bpf_timer *timer;
38+
39+
timer = bpf_map_lookup_elem(&timer_map, &key);
40+
if (timer) {
41+
bpf_timer_init(timer, &timer_map, CLOCK_BOOTTIME);
42+
bpf_timer_set_callback(timer, timer_cb_ret1);
43+
bpf_timer_start(timer, 1000, 0);
44+
}
45+
46+
return 0;
47+
}

0 commit comments

Comments
 (0)