-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <void@manifault.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/bpf/20231009161414.235829-2-void@manifault.com
- Loading branch information
David Vernet
authored and
Daniel Borkmann
committed
Oct 9, 2023
1 parent
8299559
commit 57ddeb8
Showing
2 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */ | ||
|
||
#include <linux/bpf.h> | ||
#include <time.h> | ||
#include <errno.h> | ||
#include <bpf/bpf_helpers.h> | ||
#include "bpf_misc.h" | ||
#include "bpf_tcp_helpers.h" | ||
|
||
char _license[] SEC("license") = "GPL"; | ||
|
||
struct elem { | ||
struct bpf_timer t; | ||
}; | ||
|
||
struct { | ||
__uint(type, BPF_MAP_TYPE_ARRAY); | ||
__uint(max_entries, 1); | ||
__type(key, int); | ||
__type(value, struct elem); | ||
} timer_map SEC(".maps"); | ||
|
||
static int timer_cb_ret1(void *map, int *key, struct bpf_timer *timer) | ||
{ | ||
if (bpf_get_smp_processor_id() % 2) | ||
return 1; | ||
else | ||
return 0; | ||
} | ||
|
||
SEC("fentry/bpf_fentry_test1") | ||
__failure __msg("should have been in (0x0; 0x0)") | ||
int BPF_PROG2(test_ret_1, int, a) | ||
{ | ||
int key = 0; | ||
struct bpf_timer *timer; | ||
|
||
timer = bpf_map_lookup_elem(&timer_map, &key); | ||
if (timer) { | ||
bpf_timer_init(timer, &timer_map, CLOCK_BOOTTIME); | ||
bpf_timer_set_callback(timer, timer_cb_ret1); | ||
bpf_timer_start(timer, 1000, 0); | ||
} | ||
|
||
return 0; | ||
} |