MPTCP Archive mirror
 help / color / mirror / Atom feed
From: Geliang Tang <geliang@kernel.org>
To: Matthieu Baerts <matttbe@kernel.org>, mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-next v7 2/9] Squash to "selftests/bpf: Add bpf scheduler test" 1 verify
Date: Wed, 10 Apr 2024 09:59:14 +0800	[thread overview]
Message-ID: <440ce520b97c9a33449a3a57901c14542bdcfc87.camel@kernel.org> (raw)
In-Reply-To: <604bdd6d-3385-45f2-8729-a1633e699af7@kernel.org>

Hi Matt,

On Tue, 2024-04-09 at 17:20 +0200, Matthieu Baerts wrote:
> Hi Geliang,
> 
> On 09/04/2024 14:42, Geliang Tang wrote:
> > Hi Matt,
> > 
> > On Mon, 2024-04-08 at 21:58 +0200, Matthieu Baerts wrote:
> > > > Hi Geliang,
> > > > 
> > > > On 08/04/2024 05:01, Geliang Tang wrote:
> > > > > > From: Geliang Tang <tanggeliang@kylinos.cn>
> > > > > > 
> > > > > > Add send_data_and_verify helper to avoid duplicated code.
> > > > > > 
> > > > > > Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> > > > > > ---
> > > > > >  .../testing/selftests/bpf/prog_tests/mptcp.c  | 40
> > > > > > ++++++++++++++-----
> > > > > >  1 file changed, 30 insertions(+), 10 deletions(-)
> > > > > > 
> > > > > > diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c
> > > > > > b/tools/testing/selftests/bpf/prog_tests/mptcp.c
> > > > > > index c29c81239603..5080e680fbe0 100644
> > > > > > --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
> > > > > > +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
> > > > > > @@ -457,23 +457,44 @@ static int has_bytes_sent(char *addr)
> > > > > >   return system(cmd);
> > > > > >  }
> > > > > >  
> > > > > > -static void test_default(void)
> > > > > > +static void send_data_and_verify(char *sched, char *addr1,
> > > > > > char
> > > > > > *addr2)
> > > > > >  {
> > > > > >   int server_fd, client_fd;
> > > > > > - struct nstoken *nstoken;
> > > > > >  
> > > > > > - nstoken = sched_init("subflow", "default");
> > > > > > - if (!ASSERT_OK_PTR(nstoken, "sched_init:default"))
> > > > > > - goto fail;
> > > > > >   server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1,
> > > > > > 0);
> > > > > > + if (CHECK(server_fd < 0, sched, "start_mptcp_server:
> > > > > > %d\n",
> > > > > > errno))
> > > > > > + return;
> > > > > > +
> > > > > >   client_fd = connect_to_fd(server_fd, 0);
> > > > > > + if (CHECK(client_fd < 0, sched, "connect_to_fd: %d\n",
> > > > > > errno))
> > > > > > + goto close_server;
> > > > > >  
> > > > > > - send_data(server_fd, client_fd, "default");
> > > > > > - ASSERT_OK(has_bytes_sent(ADDR_1), "has_bytes_sent
> > > > > > addr_1");
> > > > > > - ASSERT_OK(has_bytes_sent(ADDR_2), "has_bytes_sent
> > > > > > addr_2");
> > > > > > + send_data(server_fd, client_fd, sched);
> > > > > > +
> > > > > > + if (!strcmp(addr1, "WITH_DATA"))
> > > > 
> > > > Out of curiosity, why did you use strings? Why not using
> > > > booleans?
> > > > (or a
> > > > bitmask)
> > > > 
> > 
> > Since arguments addr1 and addr2 of macro MPTCP_SCHED_TEST are
> > strings:
> 
> They are strings because you asked the preprocessor to convert them
> as
> string ...
> 
> > #define MPTCP_SCHED_TEST(sched, addr1, addr2)                   \
> > static void test_##sched(void)                                  \
> > {                                                               \
> > ...
> >         send_data_and_verify(#sched, #addr1, #addr2);           \
> 
> ... here, by using "#addr1" and "#addr2".
> 
> Why not simply removing the "#" not to do any conversion?
> 
> e.g.
> 
> ================================= 8<
> =================================
> #include <stdio.h>
> #include <stdbool.h>
> 
> static void send_data_and_verify(char *sched, bool addr1, bool addr2)
> {
> 	printf("%s: %d %d\n", sched, addr1, addr2);
> }
> 
> #define MPTCP_SCHED_TEST(sched, addr1, addr2)		\
> static void test_##sched(void)				\
> {							\
> 	send_data_and_verify(#sched, addr1, addr2);	\
> }
> 
> #define WITH_DATA true
> MPTCP_SCHED_TEST(first, WITH_DATA, !WITH_DATA);
> 
> int main()
> {
> 	test_first();
> }
> ================================= 8<
> =================================
> 
> This prints 'first: 1 0', what you want, no?

Thank you for providing such a detailed example. I have updated it to
v8.

-Geliang

> 
> Cheers,
> Matt


  reply	other threads:[~2024-04-10  1:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-08  3:01 [PATCH mptcp-next v7 0/9] refactor mptcp bpf tests Geliang Tang
2024-04-08  3:01 ` [PATCH mptcp-next v7 1/9] selftests/bpf: Add RUN_MPTCP_TEST macro Geliang Tang
2024-04-08  3:01 ` [PATCH mptcp-next v7 2/9] Squash to "selftests/bpf: Add bpf scheduler test" 1 verify Geliang Tang
2024-04-08 19:58   ` Matthieu Baerts
2024-04-09 12:42     ` Geliang Tang
2024-04-09 15:20       ` Matthieu Baerts
2024-04-10  1:59         ` Geliang Tang [this message]
2024-04-08  3:01 ` [PATCH mptcp-next v7 3/9] Squash to "selftests/bpf: Add bpf scheduler test" 2 time Geliang Tang
2024-04-08  3:01 ` [PATCH mptcp-next v7 4/9] Squash to "selftests/bpf: Add bpf scheduler test" 3 MPTCP_SCHED_TEST Geliang Tang
2024-04-08  3:01 ` [PATCH mptcp-next v7 5/9] Squash to "selftests/bpf: Add bpf_first scheduler & test" Geliang Tang
2024-04-08  3:01 ` [PATCH mptcp-next v7 6/9] Squash to "selftests/bpf: Add bpf_bkup " Geliang Tang
2024-04-08  3:01 ` [PATCH mptcp-next v7 7/9] Squash to "selftests/bpf: Add bpf_rr " Geliang Tang
2024-04-08  3:01 ` [PATCH mptcp-next v7 8/9] Squash to "selftests/bpf: Add bpf_red " Geliang Tang
2024-04-08  3:01 ` [PATCH mptcp-next v7 9/9] Squash to "selftests/bpf: Add bpf_burst " Geliang Tang
2024-04-08  3:50 ` [PATCH mptcp-next v7 0/9] refactor mptcp bpf tests MPTCP CI

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=440ce520b97c9a33449a3a57901c14542bdcfc87.camel@kernel.org \
    --to=geliang@kernel.org \
    --cc=matttbe@kernel.org \
    --cc=mptcp@lists.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).