selftests/bpf: Check bpf_cubic_acked() is called via struct_ops
authorSong Liu <song@kernel.org>
Tue, 19 Sep 2023 06:02:58 +0000 (23:02 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 19 Sep 2023 09:59:28 +0000 (02:59 -0700)
Test bpf_tcp_ca (in test_progs) checks multiple tcp_congestion_ops.
However, there isn't a test that verifies functions in the
tcp_congestion_ops is actually called. Add a check to verify that
bpf_cubic_acked is actually called during the test.

Suggested-by: Martin KaFai Lau <martin.lau@kernel.org>
Signed-off-by: Song Liu <song@kernel.org>
Acked-by: Ilya Leoshkevich <iii@linux.ibm.com>
Link: https://lore.kernel.org/r/20230919060258.3237176-3-song@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
tools/testing/selftests/bpf/progs/bpf_cubic.c

index a53c254c60580798bd42d492ad20a9db00c2dc0d..4aabeaa525d474c45c3871ca62c94307d91ed5ca 100644 (file)
@@ -185,6 +185,8 @@ static void test_cubic(void)
 
        do_test("bpf_cubic", NULL);
 
+       ASSERT_EQ(cubic_skel->bss->bpf_cubic_acked_called, 1, "pkts_acked called");
+
        bpf_link__destroy(link);
        bpf_cubic__destroy(cubic_skel);
 }
index d9660e7200e2d145a33d14ac58ad3c56e168b6d3..c997e3e3d3fb4a0a863cd1a4cec46148d20c060d 100644 (file)
@@ -490,6 +490,8 @@ static __always_inline void hystart_update(struct sock *sk, __u32 delay)
        }
 }
 
+int bpf_cubic_acked_called = 0;
+
 void BPF_STRUCT_OPS(bpf_cubic_acked, struct sock *sk,
                    const struct ack_sample *sample)
 {
@@ -497,6 +499,7 @@ void BPF_STRUCT_OPS(bpf_cubic_acked, struct sock *sk,
        struct bictcp *ca = inet_csk_ca(sk);
        __u32 delay;
 
+       bpf_cubic_acked_called = 1;
        /* Some calls are for duplicates without timetamps */
        if (sample->rtt_us < 0)
                return;