From: Geliang Tang <tanggeliang@kylinos.cn>
Each MPTCP subtest tests test__start_subtest(suffix), then invokes
test_suffix(). It makes sense to add a new macro RUN_MPTCP_TEST to
simpolify the code.
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Reviewed-by: Mat Martineau <martineau@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
tools/testing/selftests/bpf/prog_tests/mptcp.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c
index baf976a7a1dd..9d1b255bb654 100644
--- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
+++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
@@ -347,10 +347,14 @@ static void test_mptcpify(void)
close(cgroup_fd);
}
+#define RUN_MPTCP_TEST(suffix) \
+do { \
+ if (test__start_subtest(#suffix)) \
+ test_##suffix(); \
+} while (0)
+
void test_mptcp(void)
{
- if (test__start_subtest("base"))
- test_base();
- if (test__start_subtest("mptcpify"))
- test_mptcpify();
+ RUN_MPTCP_TEST(base);
+ RUN_MPTCP_TEST(mptcpify);
}
--
2.43.0
On Tue, May 7, 2024 at 3:53 AM Matthieu Baerts (NGI0)
<matttbe@kernel.org> wrote:
>
> From: Geliang Tang <tanggeliang@kylinos.cn>
>
> Each MPTCP subtest tests test__start_subtest(suffix), then invokes
> test_suffix(). It makes sense to add a new macro RUN_MPTCP_TEST to
> simpolify the code.
>
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> Reviewed-by: Mat Martineau <martineau@kernel.org>
> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
> ---
> tools/testing/selftests/bpf/prog_tests/mptcp.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c
> index baf976a7a1dd..9d1b255bb654 100644
> --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
> +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
> @@ -347,10 +347,14 @@ static void test_mptcpify(void)
> close(cgroup_fd);
> }
>
> +#define RUN_MPTCP_TEST(suffix) \
> +do { \
> + if (test__start_subtest(#suffix)) \
> + test_##suffix(); \
> +} while (0)
Please no.
Don't hide it behind macros.
> void test_mptcp(void)
> {
> - if (test__start_subtest("base"))
> - test_base();
> - if (test__start_subtest("mptcpify"))
> - test_mptcpify();
> + RUN_MPTCP_TEST(base);
> + RUN_MPTCP_TEST(mptcpify);
> }
>
> --
> 2.43.0
>
Hi Alexei,
Thank you for the review!
On 07/05/2024 16:44, Alexei Starovoitov wrote:
> On Tue, May 7, 2024 at 3:53 AM Matthieu Baerts (NGI0)
> <matttbe@kernel.org> wrote:
>>
>> From: Geliang Tang <tanggeliang@kylinos.cn>
>>
>> Each MPTCP subtest tests test__start_subtest(suffix), then invokes
>> test_suffix(). It makes sense to add a new macro RUN_MPTCP_TEST to
>> simpolify the code.
>>
>> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
>> Reviewed-by: Mat Martineau <martineau@kernel.org>
>> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
>> ---
>> tools/testing/selftests/bpf/prog_tests/mptcp.c | 12 ++++++++----
>> 1 file changed, 8 insertions(+), 4 deletions(-)
>>
>> diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c
>> index baf976a7a1dd..9d1b255bb654 100644
>> --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
>> +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
>> @@ -347,10 +347,14 @@ static void test_mptcpify(void)
>> close(cgroup_fd);
>> }
>>
>> +#define RUN_MPTCP_TEST(suffix) \
>> +do { \
>> + if (test__start_subtest(#suffix)) \
>> + test_##suffix(); \
>> +} while (0)
>
> Please no.
> Don't hide it behind macros.
I understand, I'm personally not a big fan of hiding code being a macro
too. This one saves only one line. Geliang added a few more tests in our
tree [1], for a total of 9, so that's only saving 9 lines.
Related to that, if you don't mind, Geliang also added another macro --
MPTCP_SCHED_TEST -- for tests that are currently only in our tree [2]
(not ready yet). We asked him to reduce the size of this macro to the
minimum. We accepted it because it removed quite a lot of similar code
with very small differences [3]. Do you think we should revert this
modification too?
[1]
https://github.com/multipath-tcp/mptcp_net-next/blob/4369d9cbd752e166961ac0db7f85886111606301/tools/testing/selftests/bpf/prog_tests/mptcp.c#L578-L595
[2]
https://github.com/multipath-tcp/mptcp_net-next/blob/4369d9cbd752e166961ac0db7f85886111606301/tools/testing/selftests/bpf/prog_tests/mptcp.c#L559-L576
[3]
https://lore.kernel.org/mptcp/cover.1713321357.git.tanggeliang@kylinos.cn/T/#m0b9c14f1cbae8653c6fd119f6b71d1797961d6ba
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
On Tue, May 7, 2024 at 9:02 AM Matthieu Baerts <matttbe@kernel.org> wrote:
>
> Hi Alexei,
>
> Thank you for the review!
>
> On 07/05/2024 16:44, Alexei Starovoitov wrote:
> > On Tue, May 7, 2024 at 3:53 AM Matthieu Baerts (NGI0)
> > <matttbe@kernel.org> wrote:
> >>
> >> From: Geliang Tang <tanggeliang@kylinos.cn>
> >>
> >> Each MPTCP subtest tests test__start_subtest(suffix), then invokes
> >> test_suffix(). It makes sense to add a new macro RUN_MPTCP_TEST to
> >> simpolify the code.
> >>
> >> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> >> Reviewed-by: Mat Martineau <martineau@kernel.org>
> >> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
> >> ---
> >> tools/testing/selftests/bpf/prog_tests/mptcp.c | 12 ++++++++----
> >> 1 file changed, 8 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c
> >> index baf976a7a1dd..9d1b255bb654 100644
> >> --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
> >> +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
> >> @@ -347,10 +347,14 @@ static void test_mptcpify(void)
> >> close(cgroup_fd);
> >> }
> >>
> >> +#define RUN_MPTCP_TEST(suffix) \
> >> +do { \
> >> + if (test__start_subtest(#suffix)) \
> >> + test_##suffix(); \
> >> +} while (0)
> >
> > Please no.
> > Don't hide it behind macros.
>
> I understand, I'm personally not a big fan of hiding code being a macro
> too. This one saves only one line. Geliang added a few more tests in our
> tree [1], for a total of 9, so that's only saving 9 lines.
>
> Related to that, if you don't mind, Geliang also added another macro --
> MPTCP_SCHED_TEST -- for tests that are currently only in our tree [2]
> (not ready yet). We asked him to reduce the size of this macro to the
> minimum. We accepted it because it removed quite a lot of similar code
> with very small differences [3]. Do you think we should revert this
> modification too?
Yeah. Pls don't hide such things in macros.
Refactor into helper function in normal C.
But, what do you mean "in your tree" ?
That's your development tree and you plan to send all that
properly as patches to bpf-next someday?
>
> [1]
> https://github.com/multipath-tcp/mptcp_net-next/blob/4369d9cbd752e166961ac0db7f85886111606301/tools/testing/selftests/bpf/prog_tests/mptcp.c#L578-L595
>
> [2]
> https://github.com/multipath-tcp/mptcp_net-next/blob/4369d9cbd752e166961ac0db7f85886111606301/tools/testing/selftests/bpf/prog_tests/mptcp.c#L559-L576
>
> [3]
> https://lore.kernel.org/mptcp/cover.1713321357.git.tanggeliang@kylinos.cn/T/#m0b9c14f1cbae8653c6fd119f6b71d1797961d6ba
>
> Cheers,
> Matt
> --
> Sponsored by the NGI0 Core fund.
>
On Tue, 2024-05-07 at 13:51 -0700, Alexei Starovoitov wrote:
> On Tue, May 7, 2024 at 9:02 AM Matthieu Baerts <matttbe@kernel.org>
> wrote:
> >
> > Hi Alexei,
> >
> > Thank you for the review!
> >
> > On 07/05/2024 16:44, Alexei Starovoitov wrote:
> > > On Tue, May 7, 2024 at 3:53 AM Matthieu Baerts (NGI0)
> > > <matttbe@kernel.org> wrote:
> > > >
> > > > From: Geliang Tang <tanggeliang@kylinos.cn>
> > > >
> > > > Each MPTCP subtest tests test__start_subtest(suffix), then
> > > > invokes
> > > > test_suffix(). It makes sense to add a new macro RUN_MPTCP_TEST
> > > > to
> > > > simpolify the code.
> > > >
> > > > Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> > > > Reviewed-by: Mat Martineau <martineau@kernel.org>
> > > > Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
> > > > ---
> > > > tools/testing/selftests/bpf/prog_tests/mptcp.c | 12 ++++++++--
> > > > --
> > > > 1 file changed, 8 insertions(+), 4 deletions(-)
> > > >
> > > > diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c
> > > > b/tools/testing/selftests/bpf/prog_tests/mptcp.c
> > > > index baf976a7a1dd..9d1b255bb654 100644
> > > > --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
> > > > +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
> > > > @@ -347,10 +347,14 @@ static void test_mptcpify(void)
> > > > close(cgroup_fd);
> > > > }
> > > >
> > > > +#define RUN_MPTCP_TEST(suffix)
> > > > \
> > > > +do {
> > > > \
> > > > + if (test__start_subtest(#suffix))
> > > > \
> > > > + test_##suffix();
> > > > \
> > > > +} while (0)
> > >
> > > Please no.
> > > Don't hide it behind macros.
> >
> > I understand, I'm personally not a big fan of hiding code being a
> > macro
> > too. This one saves only one line. Geliang added a few more tests
> > in our
> > tree [1], for a total of 9, so that's only saving 9 lines.
> >
> > Related to that, if you don't mind, Geliang also added another
> > macro --
> > MPTCP_SCHED_TEST -- for tests that are currently only in our tree
> > [2]
> > (not ready yet). We asked him to reduce the size of this macro to
> > the
> > minimum. We accepted it because it removed quite a lot of similar
> > code
> > with very small differences [3]. Do you think we should revert this
> > modification too?
>
> Yeah. Pls don't hide such things in macros.
> Refactor into helper function in normal C.
I do agree to remove this RUN_MPTCP_TEST macro. But MPTCP_SCHED_TEST
macro is different. I know this type of macro is unwelcome. But it's
indeed a perfect place to use macro in MPTCP bpf sched tests.
From
'''
static void test_first(void)
{
struct mptcp_bpf_first *skel;
skel = mptcp_bpf_first__open_and_load();
if (!ASSERT_OK_PTR(skel, "open_and_load: first"))
return;
test_bpf_sched(skel->obj, "first", WITH_DATA, WITHOUT_DATA);
mptcp_bpf_first__destroy(skel);
}
static void test_bkup(void)
{
struct mptcp_bpf_bkup *skel;
skel = mptcp_bpf_bkup__open_and_load();
if (!ASSERT_OK_PTR(skel, "open_and_load: bkup"))
return;
test_bpf_sched(skel->obj, "bkup", WITH_DATA, WITHOUT_DATA);
mptcp_bpf_bkup__destroy(skel);
}
static void test_rr(void)
{
struct mptcp_bpf_rr *skel;
skel = mptcp_bpf_rr__open_and_load();
if (!ASSERT_OK_PTR(skel, "open_and_load: rr"))
return;
test_bpf_sched(skel->obj, "rr", WITH_DATA, WITH_DATA);
mptcp_bpf_rr__destroy(skel);
}
static void test_red(void)
{
struct mptcp_bpf_red *skel;
skel = mptcp_bpf_red__open_and_load();
if (!ASSERT_OK_PTR(skel, "open_and_load: red"))
return;
test_bpf_sched(skel->obj, "red", WITH_DATA, WITH_DATA);
mptcp_bpf_red__destroy(skel);
}
static void test_burst(void)
{
struct mptcp_bpf_burst *skel;
skel = mptcp_bpf_burst__open_and_load();
if (!ASSERT_OK_PTR(skel, "open_and_load: burst"))
return;
test_bpf_sched(skel->obj, "burst", WITH_DATA, WITH_DATA);
mptcp_bpf_burst__destroy(skel);
}
static void test_stale(void)
{
struct mptcp_bpf_stale *skel;
skel = mptcp_bpf_stale__open_and_load();
if (!ASSERT_OK_PTR(skel, "open_and_load: stale"))
return;
test_bpf_sched(skel->obj, "stale", WITH_DATA, WITHOUT_DATA);
mptcp_bpf_stale__destroy(skel);
}
'''
to
'''
#define MPTCP_SCHED_TEST(sched, addr1, addr2) \
static void test_##sched(void) \
{ \
struct mptcp_bpf_##sched *skel; \
\
skel = mptcp_bpf_##sched##__open_and_load(); \
if (!ASSERT_OK_PTR(skel, "open_and_load:" #sched)) \
return; \
\
test_bpf_sched(skel->obj, #sched, addr1, addr2); \
mptcp_bpf_##sched##__destroy(skel); \
}
MPTCP_SCHED_TEST(first, WITH_DATA, WITHOUT_DATA);
MPTCP_SCHED_TEST(bkup, WITH_DATA, WITHOUT_DATA);
MPTCP_SCHED_TEST(rr, WITH_DATA, WITH_DATA);
MPTCP_SCHED_TEST(red, WITH_DATA, WITH_DATA);
MPTCP_SCHED_TEST(burst, WITH_DATA, WITH_DATA);
MPTCP_SCHED_TEST(stale, WITH_DATA, WITHOUT_DATA);
'''
We can save so many code, and perfectly use BPF test skeleton template.
It's small enough, and be difficult to refactor with a helper function
in normal C.
Please reconsider whether to delete it, or at least keep it until the
day it is officially sent to BPF mail list for review.
Thanks,
-Geliang
>
> But, what do you mean "in your tree" ?
> That's your development tree and you plan to send all that
> properly as patches to bpf-next someday?
>
> >
> > [1]
> > https://github.com/multipath-tcp/mptcp_net-next/blob/4369d9cbd752e166961ac0db7f85886111606301/tools/testing/selftests/bpf/prog_tests/mptcp.c#L578-L595
> >
> > [2]
> > https://github.com/multipath-tcp/mptcp_net-next/blob/4369d9cbd752e166961ac0db7f85886111606301/tools/testing/selftests/bpf/prog_tests/mptcp.c#L559-L576
> >
> > [3]
> > https://lore.kernel.org/mptcp/cover.1713321357.git.tanggeliang@kylinos.cn/T/#m0b9c14f1cbae8653c6fd119f6b71d1797961d6ba
> >
> > Cheers,
> > Matt
> > --
> > Sponsored by the NGI0 Core fund.
> >
Hi Alexei,
Thank you for your reply!
On 07/05/2024 22:51, Alexei Starovoitov wrote:
> On Tue, May 7, 2024 at 9:02 AM Matthieu Baerts <matttbe@kernel.org> wrote:
>>
>> Hi Alexei,
>>
>> Thank you for the review!
>>
>> On 07/05/2024 16:44, Alexei Starovoitov wrote:
>>> On Tue, May 7, 2024 at 3:53 AM Matthieu Baerts (NGI0)
>>> <matttbe@kernel.org> wrote:
>>>>
>>>> From: Geliang Tang <tanggeliang@kylinos.cn>
>>>>
>>>> Each MPTCP subtest tests test__start_subtest(suffix), then invokes
>>>> test_suffix(). It makes sense to add a new macro RUN_MPTCP_TEST to
>>>> simpolify the code.
>>>>
>>>> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
>>>> Reviewed-by: Mat Martineau <martineau@kernel.org>
>>>> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
>>>> ---
>>>> tools/testing/selftests/bpf/prog_tests/mptcp.c | 12 ++++++++----
>>>> 1 file changed, 8 insertions(+), 4 deletions(-)
>>>>
>>>> diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c
>>>> index baf976a7a1dd..9d1b255bb654 100644
>>>> --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
>>>> +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
>>>> @@ -347,10 +347,14 @@ static void test_mptcpify(void)
>>>> close(cgroup_fd);
>>>> }
>>>>
>>>> +#define RUN_MPTCP_TEST(suffix) \
>>>> +do { \
>>>> + if (test__start_subtest(#suffix)) \
>>>> + test_##suffix(); \
>>>> +} while (0)
>>>
>>> Please no.
>>> Don't hide it behind macros.
>>
>> I understand, I'm personally not a big fan of hiding code being a macro
>> too. This one saves only one line. Geliang added a few more tests in our
>> tree [1], for a total of 9, so that's only saving 9 lines.
>>
>> Related to that, if you don't mind, Geliang also added another macro --
>> MPTCP_SCHED_TEST -- for tests that are currently only in our tree [2]
>> (not ready yet). We asked him to reduce the size of this macro to the
>> minimum. We accepted it because it removed quite a lot of similar code
>> with very small differences [3]. Do you think we should revert this
>> modification too?
>
> Yeah. Pls don't hide such things in macros.
> Refactor into helper function in normal C.
Sure, we will revert that.
> But, what do you mean "in your tree" ?
> That's your development tree and you plan to send all that
> properly as patches to bpf-next someday?
Yes, correct, we have some WIP patches in MPTCP development tree where
we added a new bpf_struct_ops structure to implement new MPTCP packet
schedulers in BPF. This work was paused for a while because we had to
refine the packet scheduler API, but this task is now ongoing. Hopefully
we will be able to send patches to bpf-next this "soon".
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
© 2016 - 2026 Red Hat, Inc.