diff mbox series

[bpf-next] selftests/bpf: Use make/remove netns helpers in mptcp

Message ID 99e57c7470ac338da18f02ef3af5936c8b21f5a7.1729757268.git.tanggeliang@kylinos.cn (mailing list archive)
State Superseded, archived
Headers show
Series [bpf-next] selftests/bpf: Use make/remove netns helpers in mptcp | expand

Checks

Context Check Description
matttbe/build success Build and static analysis OK
matttbe/checkpatch success total: 0 errors, 0 warnings, 0 checks, 31 lines checked
matttbe/shellcheck success MPTCP selftests files have not been modified
matttbe/KVM_Validation__normal success Success! ✅
matttbe/KVM_Validation__debug success Success! ✅
matttbe/KVM_Validation__btf-normal__only_bpftest_all_ success Success! ✅
matttbe/KVM_Validation__btf-debug__only_bpftest_all_ success Success! ✅

Commit Message

Geliang Tang Oct. 24, 2024, 8:11 a.m. UTC
From: Geliang Tang <tanggeliang@kylinos.cn>

New netns selftest helpers make_netns() and remove_netns() has been added
in network_helpers.c, let's use them in mptcp selftests too.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
 tools/testing/selftests/bpf/prog_tests/mptcp.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

Comments

MPTCP CI Oct. 24, 2024, 9:24 a.m. UTC | #1
Hi Geliang,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal: Success! ✅
- KVM Validation: debug: Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/11495575836

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/6421d1f207dd
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=902572


If there are some issues, you can reproduce them using the same environment as
the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-normal

For more details:

    https://github.com/multipath-tcp/mptcp-upstream-virtme-docker


Please note that despite all the efforts that have been already done to have a
stable tests suite when executed on a public CI like here, it is possible some
reported issues are not due to your modifications. Still, do not hesitate to
help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)
Martin KaFai Lau Oct. 29, 2024, 7:36 p.m. UTC | #2
On 10/24/24 1:11 AM, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> New netns selftest helpers make_netns() and remove_netns() has been added
> in network_helpers.c, let's use them in mptcp selftests too.
> 
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
> ---
>   tools/testing/selftests/bpf/prog_tests/mptcp.c | 18 ++++++++++++------
>   1 file changed, 12 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c
> index d2ca32fa3b21..8276398f7d6a 100644
> --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
> +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
> @@ -66,12 +66,18 @@ struct mptcp_storage {
>   
>   static struct nstoken *create_netns(void)
>   {
> -	SYS(fail, "ip netns add %s", NS_TEST);
> -	SYS(fail, "ip -net %s link set dev lo up", NS_TEST);
> +	struct nstoken *nstoken;
>   
> -	return open_netns(NS_TEST);
> -fail:
> -	return NULL;
> +	if (make_netns(NS_TEST) < 0)
> +		return NULL;
> +
> +	nstoken = open_netns(NS_TEST);
> +	if (!nstoken) {
> +		log_err("open netns %s failed", NS_TEST);
> +		remove_netns(NS_TEST);
> +	}
> +
> +	return nstoken;
>   }

This can be further simplified by using the netns_new() and netns_free(). Then 
create_netns() and remove_netns() can be removed from mptcp.c. Take a look at a 
recent usage in prog_tests/btf_skc_cls_ingress.c.

pw-bot: cr

>   
>   static void cleanup_netns(struct nstoken *nstoken)
> @@ -79,7 +85,7 @@ static void cleanup_netns(struct nstoken *nstoken)
>   	if (nstoken)
>   		close_netns(nstoken);
>   
> -	SYS_NOFAIL("ip netns del %s", NS_TEST);
> +	remove_netns(NS_TEST);
>   }
>   
>   static int start_mptcp_server(int family, const char *addr_str, __u16 port,
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c
index d2ca32fa3b21..8276398f7d6a 100644
--- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
+++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
@@ -66,12 +66,18 @@  struct mptcp_storage {
 
 static struct nstoken *create_netns(void)
 {
-	SYS(fail, "ip netns add %s", NS_TEST);
-	SYS(fail, "ip -net %s link set dev lo up", NS_TEST);
+	struct nstoken *nstoken;
 
-	return open_netns(NS_TEST);
-fail:
-	return NULL;
+	if (make_netns(NS_TEST) < 0)
+		return NULL;
+
+	nstoken = open_netns(NS_TEST);
+	if (!nstoken) {
+		log_err("open netns %s failed", NS_TEST);
+		remove_netns(NS_TEST);
+	}
+
+	return nstoken;
 }
 
 static void cleanup_netns(struct nstoken *nstoken)
@@ -79,7 +85,7 @@  static void cleanup_netns(struct nstoken *nstoken)
 	if (nstoken)
 		close_netns(nstoken);
 
-	SYS_NOFAIL("ip netns del %s", NS_TEST);
+	remove_netns(NS_TEST);
 }
 
 static int start_mptcp_server(int family, const char *addr_str, __u16 port,