From patchwork Wed May 15 04:20:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13664568 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02B77383A1; Wed, 15 May 2024 04:20:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715746857; cv=none; b=iSqW5wH2d0QMV5q0OPFcOj9fsqMN0OtfMHbJtP1z9h9S3CH3H/L0/Rnr/LDGC8rM9yPNs50RnZjmuspfMvHt6Gk/rDfTuLgVynoBwv8mH0erY12OfgzcT5lH1qK6jS+Ap4HcJ0QY+5yqntle1ffdBIy38rR2GMpOG7PB49utLLQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715746857; c=relaxed/simple; bh=HkzV+4jolSuOdg1n7+5S6ok0t8H/Yn2aEB0nuV0GCzU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C3AhJKCxu07CwjN2i23rNFdGwZLC529rKKBWgebmJfmOZtR4TA6eBrkhtKKweBu07bcAmfYKkFpbtlN/eLwfFSloTXIbHOW9AyirJwX+wTvFw11kpT6o47vvQZ0ogl7WJ8dOz6jJf1wX2nJYMgAOkg/mTJNyB6AIL+UjJW4a38s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=L7cczszD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="L7cczszD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5548DC2BD11; Wed, 15 May 2024 04:20:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715746856; bh=HkzV+4jolSuOdg1n7+5S6ok0t8H/Yn2aEB0nuV0GCzU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L7cczszDnNut1F87MM3kpBysmmzZXIjhihUvIfzAw0WgB05VAqApk7EGGRfkVWj2U htHOh36BRVbdANaeKW6/8gZKZbsC9F/BcFUH5col4qsyLH+cgRm43Ota3FbPYMoQLq X666TjfLF90JdpWCDS+dqHYh+YeurUMDHqb1kClw8MZf2doz4DYp0awxziBQsdnvVW Lbcz5tzYaOIKyVkE657E2O0trJkqJ5ICBY79QpuP9E/uIzDmKZdU0jDgdcyPPCyx/f XGG3zqMXHFYhBK1BWtjrACaed8OaDugvHlexHyGRrwzByxceqP20QbKP9Kj0ATy0dd FapbQuP0j9/5g== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, Geliang Tang Subject: [PATCH bpf-next v2 3/4] selftests/bpf: Use connect_to_fd_opts in do_test in bpf_tcp_ca Date: Wed, 15 May 2024 12:20:23 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang This patch uses connect_to_fd_opts() instead of using connect_fd_to_fd() and settcpca() in do_test() in prog_tests/bpf_tcp_ca.c to accept a struct network_helper_opts argument. Then define a dctcp dedicated post_socket_cb callback stg_post_socket_cb(), invoking both cc_cb() and bpf_map_update_elem() in it, and set it in test_dctcp(). For passing map_fd into stg_post_socket_cb() callback, a new member map_fd is added in struct post_socket_opts. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.h | 1 + .../selftests/bpf/prog_tests/bpf_tcp_ca.c | 33 ++++++++----------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index e44a6e5d8344..62dd40095cf2 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -23,6 +23,7 @@ typedef __u16 __sum16; struct post_socket_opts { const char *cc; + int map_fd; }; struct network_helper_opts { diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c index 25961ce850cb..7c9c79e35551 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c @@ -49,25 +49,9 @@ static void do_test(const struct network_helper_opts *opts, if (!ASSERT_NEQ(lfd, -1, "socket")) return; - fd = socket(AF_INET6, SOCK_STREAM, 0); - if (!ASSERT_NEQ(fd, -1, "socket")) { - close(lfd); - return; - } - - if (settcpca(fd, opts->cb_opts.cc)) - goto done; - - if (sk_stg_map) { - err = bpf_map_update_elem(bpf_map__fd(sk_stg_map), &fd, - &expected_stg, BPF_NOEXIST); - if (!ASSERT_OK(err, "bpf_map_update_elem(sk_stg_map)")) - goto done; - } - /* connect to server */ - err = connect_fd_to_fd(fd, lfd, 0); - if (!ASSERT_NEQ(err, -1, "connect")) + fd = connect_to_fd_opts(lfd, opts); + if (!ASSERT_NEQ(fd, -1, "connect_to_fd_opts")) goto done; if (sk_stg_map) { @@ -120,11 +104,21 @@ static void test_cubic(void) bpf_cubic__destroy(cubic_skel); } +static int stg_post_socket_cb(int fd, const struct post_socket_opts *opts) +{ + int err; + + err = cc_cb(fd, opts); + if (err) + return err; + return bpf_map_update_elem(opts->map_fd, &fd, &expected_stg, BPF_NOEXIST); +} + static void test_dctcp(void) { struct network_helper_opts opts = { .cb_opts.cc = "bpf_dctcp", - .post_socket_cb = cc_cb, + .post_socket_cb = stg_post_socket_cb, }; struct bpf_dctcp *dctcp_skel; struct bpf_link *link; @@ -139,6 +133,7 @@ static void test_dctcp(void) return; } + opts.cb_opts.map_fd = bpf_map__fd(dctcp_skel->maps.sk_stg_map); do_test(&opts, dctcp_skel->maps.sk_stg_map); ASSERT_EQ(dctcp_skel->bss->stg_result, expected_stg, "stg_result");