Skip to content

Commit f14a3f6

Browse files
jtdorAlexei Starovoitov
authored andcommitted
selftests/bpf: Test a BPF CC implementing the unsupported get_info()
Test whether a TCP CC implemented in BPF providing get_info() is rejected correctly. get_info() is unsupported in a BPF CC. The check for required functions in a BPF CC has moved, this test ensures unsupported functions are still rejected correctly. Signed-off-by: Jörn-Thorben Hinz <[email protected]> Reviewed-by: Martin KaFai Lau <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 0735627 commit f14a3f6

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "bpf_dctcp_release.skel.h"
1212
#include "tcp_ca_write_sk_pacing.skel.h"
1313
#include "tcp_ca_incompl_cong_ops.skel.h"
14+
#include "tcp_ca_unsupp_cong_op.skel.h"
1415

1516
#ifndef ENOTSUPP
1617
#define ENOTSUPP 524
@@ -359,6 +360,23 @@ static void test_incompl_cong_ops(void)
359360
tcp_ca_incompl_cong_ops__destroy(skel);
360361
}
361362

363+
static void test_unsupp_cong_op(void)
364+
{
365+
libbpf_print_fn_t old_print_fn;
366+
struct tcp_ca_unsupp_cong_op *skel;
367+
368+
err_str = "attach to unsupported member get_info";
369+
found = false;
370+
old_print_fn = libbpf_set_print(libbpf_debug_print);
371+
372+
skel = tcp_ca_unsupp_cong_op__open_and_load();
373+
ASSERT_NULL(skel, "open_and_load");
374+
ASSERT_EQ(found, true, "expected_err_msg");
375+
376+
tcp_ca_unsupp_cong_op__destroy(skel);
377+
libbpf_set_print(old_print_fn);
378+
}
379+
362380
void test_bpf_tcp_ca(void)
363381
{
364382
if (test__start_subtest("dctcp"))
@@ -375,4 +393,6 @@ void test_bpf_tcp_ca(void)
375393
test_write_sk_pacing();
376394
if (test__start_subtest("incompl_cong_ops"))
377395
test_incompl_cong_ops();
396+
if (test__start_subtest("unsupp_cong_op"))
397+
test_unsupp_cong_op();
378398
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include "vmlinux.h"
4+
5+
#include <bpf/bpf_helpers.h>
6+
#include <bpf/bpf_tracing.h>
7+
8+
char _license[] SEC("license") = "GPL";
9+
10+
SEC("struct_ops/unsupp_cong_op_get_info")
11+
size_t BPF_PROG(unsupp_cong_op_get_info, struct sock *sk, u32 ext, int *attr,
12+
union tcp_cc_info *info)
13+
{
14+
return 0;
15+
}
16+
17+
SEC(".struct_ops")
18+
struct tcp_congestion_ops unsupp_cong_op = {
19+
.get_info = (void *)unsupp_cong_op_get_info,
20+
.name = "bpf_unsupp_op",
21+
};

0 commit comments

Comments
 (0)