Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Feng Zhou <zhoufeng.zf@bytedance.com>
To: Martin KaFai Lau <martin.lau@linux.dev>
Cc: daniel@iogearbox.net, john.fastabend@gmail.com, ast@kernel.org,
	andrii@kernel.org, eddyz87@gmail.com, song@kernel.org,
	yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me,
	haoluo@google.com, jolsa@kernel.org, davem@davemloft.net,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	mykolal@fb.com, shuah@kernel.org, geliang@kernel.org,
	laoar.shao@gmail.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, bpf@vger.kernel.org,
	linux-kselftest@vger.kernel.org, yangzhenze@bytedance.com,
	wangdongdong.6@bytedance.com
Subject: Re: [External] Re: [PATCH bpf-next v2 2/2] bpf, selftests: Add test case for cgroup skb to get net_cls classid helpers
Date: Wed, 16 Oct 2024 16:28:27 +0800	[thread overview]
Message-ID: <5969d1ca-688b-4a27-9e39-dc9f89381d40@bytedance.com> (raw)
In-Reply-To: <075e314c-3aa5-4f7b-81f7-3bc0e055334a@linux.dev>

在 2024/10/1 09:58, Martin KaFai Lau 写道:
> On 9/18/24 12:45 AM, Feng zhou wrote:
>> From: Feng Zhou <zhoufeng.zf@bytedance.com>
>>
>> This patch adds a test for cgroup skb to get classid.
>>
>> Signed-off-by: Feng Zhou <zhoufeng.zf@bytedance.com>
>> ---
>>   .../bpf/prog_tests/cg_skb_get_classid.c       | 87 +++++++++++++++++++
>>   .../selftests/bpf/progs/cg_skb_get_classid.c  | 19 ++++
>>   2 files changed, 106 insertions(+)
>>   create mode 100644 
>> tools/testing/selftests/bpf/prog_tests/cg_skb_get_classid.c
>>   create mode 100644 
>> tools/testing/selftests/bpf/progs/cg_skb_get_classid.c
>>
>> diff --git 
>> a/tools/testing/selftests/bpf/prog_tests/cg_skb_get_classid.c 
>> b/tools/testing/selftests/bpf/prog_tests/cg_skb_get_classid.c
>> new file mode 100644
>> index 000000000000..13a5943c387d
>> --- /dev/null
>> +++ b/tools/testing/selftests/bpf/prog_tests/cg_skb_get_classid.c
>> @@ -0,0 +1,87 @@
>> +// SPDX-License-Identifier: GPL-2.0-only
>> +
>> +/*
>> + * Copyright 2024 Bytedance.
>> + */
>> +
>> +#include <test_progs.h>
>> +
>> +#include "cg_skb_get_classid.skel.h"
>> +
>> +#include "cgroup_helpers.h"
>> +#include "network_helpers.h"
>> +
>> +static int run_test(int cgroup_fd, int server_fd)
>> +{
>> +    struct cg_skb_get_classid *skel;
>> +    int fd, err = 0;
>> +
>> +    skel = cg_skb_get_classid__open_and_load();
>> +    if (!ASSERT_OK_PTR(skel, "skel_open"))
>> +        return -1;
>> +
>> +    skel->links.cg_skb_classid =
>> +        bpf_program__attach_cgroup(skel->progs.cg_skb_classid,
>> +                       cgroup_fd);
>> +    if (!ASSERT_OK_PTR(skel->links.cg_skb_classid, "prog_attach")) {
>> +        err = -1;
>> +        goto out;
>> +    }
>> +
>> +    if (!ASSERT_OK(join_classid(), "join_classid")) {
>> +        err = -1;
>> +        goto out;
>> +    }
>> +
>> +    errno = 0;
>> +    fd = connect_to_fd_opts(server_fd, NULL);
>> +    if (fd >= 0) {
>> +        if (skel->bss->classid != getpid()) {
>> +            log_err("Get unexpected classid");
>> +            err = -1;
>> +        }
>> +
>> +        close(fd);
>> +    } else {
>> +        log_err("Unexpected errno from connect to server");
>> +        err = -1;
>> +    }
>> +out:
>> +    cg_skb_get_classid__destroy(skel);
>> +    return err;
>> +}
>> +
>> +void test_cg_skb_get_classid(void)
>> +{
>> +    struct network_helper_opts opts = {};
>> +    int server_fd, client_fd, cgroup_fd;
>> +    static const int port = 60120;
> 
> Running a test with a specific port without netns could fail when 
> test_progs is run in parallel (-j). e.g. cgroup_v1v2 is using the same 
> port.
> 
>> +
>> +    /* Step 1: Check base connectivity works without any BPF. */
>> +    server_fd = start_server(AF_INET, SOCK_STREAM, NULL, port, 0);
>> +    if (!ASSERT_GE(server_fd, 0, "server_fd"))
>> +        return;
>> +    client_fd = connect_to_fd_opts(server_fd, &opts);
>> +    if (!ASSERT_GE(client_fd, 0, "client_fd")) {
>> +        close(server_fd);
>> +        return;
>> +    }
>> +    close(client_fd);
>> +    close(server_fd);
> 
> imo, this connection pre-test is unnecessary. I would remove it.
> 
>> +
>> +    /* Step 2: Check BPF prog attached to cgroups. */
>> +    cgroup_fd = test__join_cgroup("/cg_skb_get_classid");
>> +    if (!ASSERT_GE(cgroup_fd, 0, "cgroup_fd"))
>> +        return;
>> +    server_fd = start_server(AF_INET, SOCK_STREAM, NULL, port, 0);
>> +    if (!ASSERT_GE(server_fd, 0, "server_fd")) {
>> +        close(cgroup_fd);
>> +        return;
>> +    }
>> +    setup_classid_environment();
>> +    set_classid();
>> +    ASSERT_OK(run_test(cgroup_fd, server_fd), "cg_skb_get_classid");
> 
> Please run this test under a netns and without specifying a particular 
> port. connect_to_fd_opts will figure out the port used in server_fd.
> 
> Patch 1 lgtm.
> 
> Please add a few words to the cover letter also.
> 
> pw-bot: cr

Sorry for taking so long to reply.

Will do, thanks.



      reply	other threads:[~2024-10-16  8:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-18  7:45 [PATCH bpf-next v2 0/2] Cgroup skb add helper to get net_cls's classid Feng zhou
2024-09-18  7:45 ` [PATCH bpf-next v2 1/2] bpf: cg_skb add get classid helper Feng zhou
2024-09-18  7:45 ` [PATCH bpf-next v2 2/2] bpf, selftests: Add test case for cgroup skb to get net_cls classid helpers Feng zhou
2024-10-01  1:58   ` Martin KaFai Lau
2024-10-16  8:28     ` Feng Zhou [this message]

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=5969d1ca-688b-4a27-9e39-dc9f89381d40@bytedance.com \
    --to=zhoufeng.zf@bytedance.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=eddyz87@gmail.com \
    --cc=edumazet@google.com \
    --cc=geliang@kernel.org \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=laoar.shao@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mykolal@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=wangdongdong.6@bytedance.com \
    --cc=yangzhenze@bytedance.com \
    --cc=yonghong.song@linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox