From: Mathieu Jadin <mathjadin@gmail.com>
To: bpf@vger.kernel.org
Cc: Mathieu Jadin <mathjadin@gmail.com>,
Song Liu <songliubraving@fb.com>,
linux-kselftest@vger.kernel.org,
Dave Marchevsky <davemarchevsky@fb.com>,
Andrii Nakryiko <andrii@kernel.org>,
Shuah Khan <shuah@kernel.org>, KP Singh <kpsingh@kernel.org>,
Yonghong Song <yhs@fb.com>, Martin KaFai Lau <kafai@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
netdev@vger.kernel.org, Daniel Borkmann <daniel@iogearbox.net>,
Alexei Starovoitov <ast@kernel.org>
Subject: [PATCH bpf-next v2 3/3] selftests/bpf: Improve test tcpbpf_user robustness
Date: Tue, 7 Dec 2021 23:56:35 +0100 [thread overview]
Message-ID: <20211207225635.113904-3-mathjadin@gmail.com> (raw)
In-Reply-To: <20211207225635.113904-1-mathjadin@gmail.com>
Allow the test to support any number of supported callback flags.
Provided that BPF_SOCK_OPS_ALL_CB_FLAGS is correctly updated when new
flags are added, left shifting it always leads to a non existing flag.
Signed-off-by: Mathieu Jadin <mathjadin@gmail.com>
---
tools/testing/selftests/bpf/prog_tests/tcpbpf_user.c | 4 +++-
tools/testing/selftests/bpf/progs/test_tcpbpf_kern.c | 9 +++++++--
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/tcpbpf_user.c b/tools/testing/selftests/bpf/prog_tests/tcpbpf_user.c
index 87923d2865b7..56d007bf4011 100644
--- a/tools/testing/selftests/bpf/prog_tests/tcpbpf_user.c
+++ b/tools/testing/selftests/bpf/prog_tests/tcpbpf_user.c
@@ -12,6 +12,8 @@ static __u32 duration;
static void verify_result(struct tcpbpf_globals *result)
{
+ __u32 non_existing_flag = (BPF_SOCK_OPS_ALL_CB_FLAGS << 1) &
+ ~BPF_SOCK_OPS_ALL_CB_FLAGS;
__u32 expected_events = ((1 << BPF_SOCK_OPS_TIMEOUT_INIT) |
(1 << BPF_SOCK_OPS_RWND_INIT) |
(1 << BPF_SOCK_OPS_TCP_CONNECT_CB) |
@@ -30,7 +32,7 @@ static void verify_result(struct tcpbpf_globals *result)
ASSERT_EQ(result->bytes_acked, 1002, "bytes_acked");
ASSERT_EQ(result->data_segs_in, 1, "data_segs_in");
ASSERT_EQ(result->data_segs_out, 1, "data_segs_out");
- ASSERT_EQ(result->bad_cb_test_rv, 0x80, "bad_cb_test_rv");
+ ASSERT_EQ(result->bad_cb_test_rv, non_existing_flag, "bad_cb_test_rv");
ASSERT_EQ(result->good_cb_test_rv, 0, "good_cb_test_rv");
ASSERT_EQ(result->num_listen, 1, "num_listen");
diff --git a/tools/testing/selftests/bpf/progs/test_tcpbpf_kern.c b/tools/testing/selftests/bpf/progs/test_tcpbpf_kern.c
index 3ded05280757..c37ba5940e3d 100644
--- a/tools/testing/selftests/bpf/progs/test_tcpbpf_kern.c
+++ b/tools/testing/selftests/bpf/progs/test_tcpbpf_kern.c
@@ -43,6 +43,8 @@ SEC("sockops")
int bpf_testcb(struct bpf_sock_ops *skops)
{
char header[sizeof(struct ipv6hdr) + sizeof(struct tcphdr)];
+ __u32 non_existing_flag = (BPF_SOCK_OPS_ALL_CB_FLAGS << 1) &
+ ~BPF_SOCK_OPS_ALL_CB_FLAGS;
struct bpf_sock_ops *reuse = skops;
struct tcphdr *thdr;
int window_clamp = 9216;
@@ -104,8 +106,11 @@ int bpf_testcb(struct bpf_sock_ops *skops)
global.window_clamp_client = get_tp_window_clamp(skops);
break;
case BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB:
- /* Test failure to set largest cb flag (assumes not defined) */
- global.bad_cb_test_rv = bpf_sock_ops_cb_flags_set(skops, 0x80);
+ /* Test failure to set largest cb flag
+ * (assumes that BPF_SOCK_OPS_ALL_CB_FLAGS masks all cb flags)
+ */
+ global.bad_cb_test_rv = bpf_sock_ops_cb_flags_set(skops,
+ non_existing_flag);
/* Set callback */
global.good_cb_test_rv = bpf_sock_ops_cb_flags_set(skops,
BPF_SOCK_OPS_STATE_CB_FLAG);
--
2.32.0
next prev parent reply other threads:[~2021-12-07 22:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-07 22:56 [PATCH bpf-next v2 1/3] net: Parse IPv6 ext headers from TCP sock_ops Mathieu Jadin
2021-12-07 22:56 ` [PATCH bpf-next v2 2/3] selftests/bpf: Test for IPv6 ext header parsing Mathieu Jadin
2021-12-13 21:44 ` Andrii Nakryiko
2021-12-07 22:56 ` Mathieu Jadin [this message]
2021-12-10 2:01 ` [PATCH bpf-next v2 1/3] net: Parse IPv6 ext headers from TCP sock_ops Jakub Kicinski
2021-12-14 22:15 ` Mathieu Jadin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211207225635.113904-3-mathjadin@gmail.com \
--to=mathjadin@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davemarchevsky@fb.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=songliubraving@fb.com \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.