[PATCH mptcp-next] Squash to "selftests: bpf: add MPTCP test base"

Geliang Tang posted 1 patch 1 week, 2 days ago
Failed in applying to current master (apply log)
.../testing/selftests/bpf/prog_tests/mptcp.c  | 24 +++++++++----------
.../testing/selftests/bpf/progs/mptcp_sock.c  |  2 +-
2 files changed, 13 insertions(+), 13 deletions(-)
[PATCH mptcp-next] Squash to "selftests: bpf: add MPTCP test base"
Posted by Geliang Tang 1 week, 2 days ago
Address to Andrii's comments:
 - add copyright 2022
 - use ASSERT_* instead of CHECK_FAIL
 - drop SEC("version")

Signed-off-by: Geliang Tang <geliang.tang@suse.com>
---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 24 +++++++++----------
 .../testing/selftests/bpf/progs/mptcp_sock.c  |  2 +-
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c
index cd548bb2828f..760374f1fce4 100644
--- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
+++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /* Copyright (c) 2020, Tessares SA. */
+/* Copyright (c) 2022, SUSE. */
 
 #include <test_progs.h>
 #include "cgroup_helpers.h"
@@ -12,16 +13,15 @@ struct mptcp_storage {
 
 static int verify_sk(int map_fd, int client_fd, const char *msg, __u32 is_mptcp)
 {
-	int err = 0, cfd = client_fd;
+	int err, cfd = client_fd;
 	struct mptcp_storage val;
 
 	if (is_mptcp == 1)
 		return 0;
 
-	if (CHECK_FAIL(bpf_map_lookup_elem(map_fd, &cfd, &val) < 0)) {
-		perror("Failed to read socket storage");
-		return -1;
-	}
+	err = bpf_map_lookup_elem(map_fd, &cfd, &val);
+	if (!ASSERT_OK(err, "bpf_map_lookup_elem"))
+		return err;
 
 	if (val.invoked != 1) {
 		log_err("%s: unexpected invoked count %d != 1",
@@ -50,40 +50,40 @@ static int run_test(int cgroup_fd, int server_fd, bool is_mptcp)
 		return -EIO;
 
 	err = bpf_object__load(obj);
-	if (CHECK_FAIL(err))
+	if (!ASSERT_OK(err, "bpf_object__load"))
 		goto out;
 
 	prog = bpf_object__find_program_by_name(obj, "_sockops");
-	if (CHECK_FAIL(!prog)) {
+	if (!ASSERT_OK_PTR(prog, "bpf_object__find_program_by_name")) {
 		err = -EIO;
 		goto out;
 	}
 
 	prog_fd = bpf_program__fd(prog);
-	if (CHECK_FAIL(prog_fd < 0)) {
+	if (!ASSERT_GT(prog_fd, 0, "bpf_program__fd")) {
 		err = -EIO;
 		goto out;
 	}
 
 	map = bpf_object__find_map_by_name(obj, "socket_storage_map");
-	if (CHECK_FAIL(!map)) {
+	if (!ASSERT_OK_PTR(map, "bpf_object__find_map_by_name")) {
 		err = -EIO;
 		goto out;
 	}
 
 	map_fd = bpf_map__fd(map);
-	if (CHECK_FAIL(map_fd < 0)) {
+	if (!ASSERT_GT(map_fd, 0, "bpf_map__fd")) {
 		err = -EIO;
 		goto out;
 	}
 
 	err = bpf_prog_attach(prog_fd, cgroup_fd, BPF_CGROUP_SOCK_OPS, 0);
-	if (CHECK_FAIL(err))
+	if (!ASSERT_OK(err, "bpf_prog_attach"))
 		goto out;
 
 	client_fd = is_mptcp ? connect_to_mptcp_fd(server_fd, 0) :
 			       connect_to_fd(server_fd, 0);
-	if (client_fd < 0) {
+	if (!ASSERT_GT(client_fd, 0, "connect to fd")) {
 		err = -EIO;
 		goto out;
 	}
diff --git a/tools/testing/selftests/bpf/progs/mptcp_sock.c b/tools/testing/selftests/bpf/progs/mptcp_sock.c
index 0d65fb889d03..19f5f8a183f5 100644
--- a/tools/testing/selftests/bpf/progs/mptcp_sock.c
+++ b/tools/testing/selftests/bpf/progs/mptcp_sock.c
@@ -1,11 +1,11 @@
 // SPDX-License-Identifier: GPL-2.0
 /* Copyright (c) 2020, Tessares SA. */
+/* Copyright (c) 2022, SUSE. */
 
 #include <linux/bpf.h>
 #include <bpf/bpf_helpers.h>
 
 char _license[] SEC("license") = "GPL";
-__u32 _version SEC("version") = 1;
 
 struct mptcp_storage {
 	__u32 invoked;
-- 
2.34.1


Re: [PATCH mptcp-next] Squash to "selftests: bpf: add MPTCP test base"
Posted by Matthieu Baerts 1 week ago
Hi Geliang,

On 07/05/2022 08:17, Geliang Tang wrote:
> Address to Andrii's comments:
>  - add copyright 2022
>  - use ASSERT_* instead of CHECK_FAIL
>  - drop SEC("version")

Thank you for the patches!

I also replaced a few ASSERT_GT() by ASSERT_GE() and update the commit
messages: prefix + changelog. Please check if I didn't miss anything :)

- f0bf012a62d0: "squashed" in "selftests: bpf: add MPTCP test base"
- bcb1ed91a0e2: use ASSERT_GE instead of _GT: fd == 0 is valid
- d13c2826b435: conflict in t/selftests-bpf-test-bpf_skc_to_mptcp_sock
- Results: 2b6d9d722f05..2b4b3ea4ee81 (export)

- b8c48e454a31: "squashed" in "selftests: bpf: test bpf_skc_to_mptcp_sock"
- c2d9dbcf32da: use ASSERT_GE instead of _GT: fd == 0 is valid
- 909c2e46449c: conflict in
t/selftests-bpf-verify-ca_name-of-struct-mptcp_sock
- Results: 2b4b3ea4ee81..edd1596ddede (export)
- 105fd75cff3a: "squashed" in "selftests: bpf: test bpf_skc_to_mptcp_sock"
- Results: bb750830dfba..21c7846253fc (export)

- d2a584bb2988: "squashed" in "selftests: bpf: verify token of struct
mptcp_sock"
- 023c51695e66: use ASSERT_GE instead of _GT: fd == 0 is valid
- Results: edd1596ddede..44a1ca452f9d (export)

- 18126dc0fe4f: "squashed" in "selftests: bpf: verify ca_name of struct
mptcp_sock"
- 8d3b8669d7a4: use ASSERT_GE instead of _GT: fd == 0 is valid
- Results: 44a1ca452f9d..bb750830dfba (export)

- 67678621ed32: "squashed" in "selftests: bpf: add bpf_first test"
- Results: 21c7846253fc..ae3944c04e7a (export)


- 17c227d200aa: tg:msg: add changelog for "bpf: add
bpf_skc_to_mptcp_sock_proto"

- 94caf3b41f66: tg:msg: add changelog for "selftests: bpf: Enable
CONFIG_IKCONFIG_PROC in config"
- 8da49841ed59: tg:msg: fix prefix for "selftests: bpf: Enable
CONFIG_IKCONFIG_PROC in config"

- 3f14113ff1f6: tg:msg: add changelog for "selftests: bpf: add MPTCP
test base"
- 542fa9c889e0: tg:msg: fix prefix for "selftests: bpf: add MPTCP test base"

- 9f1d3a3094b4: tg:msg: add changelog for "selftests: bpf: test
bpf_skc_to_mptcp_sock"
- e8c7107863e8: tg:msg: fix prefix for "selftests: bpf: test
bpf_skc_to_mptcp_sock"

- b6003fc6580c: tg:msg: add changelog for "selftests: bpf: verify token
of struct mptcp_sock"
- 7195dbb7ee5d: tg:msg: fix prefix for "selftests: bpf: verify token of
struct mptcp_sock"

- 58ce37bdb3ce: tg:msg: add changelog for "selftests: bpf: verify
ca_name of struct mptcp_sock"
- 5431605d68cc: tg:msg: fix prefix for "selftests: bpf: verify ca_name
of struct mptcp_sock"

- 9fc1e8122379: tg:msg: fix prefix for "selftests: bpf: verify first of
struct mptcp_sock"

- c007e06819ef: tg:msg: 'selftests: bpf:' -> 'selftests/bpf:'
- 227c9d78e571: tg:msg: 'selftests: bpf:' -> 'selftests/bpf:'


> diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c
> index cd548bb2828f..760374f1fce4 100644
> --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
> +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c

(...)

>  	prog_fd = bpf_program__fd(prog);
> -	if (CHECK_FAIL(prog_fd < 0)) {
> +	if (!ASSERT_GT(prog_fd, 0, "bpf_program__fd")) {

See my commit bcb1ed91a0e2 and a few others after: the fd can be zero,
we need to use ASSERT_GE().


Builds and tests are now in progress:

https://cirrus-ci.com/github/multipath-tcp/mptcp_net-next/export/20220509T115202
https://github.com/multipath-tcp/mptcp_net-next/actions/workflows/build-validation.yml?query=branch:export

Cheers,
Matt
-- 
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net

[PATCH mptcp-next] Squash to "selftests: bpf: test bpf_skc_to_mptcp_sock"
Posted by Geliang Tang 1 week, 2 days ago
Address to Andrii's comments:
- use ASSERT_* instead of CHECK_FAIL

Signed-off-by: Geliang Tang <geliang.tang@suse.com>
---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c
index b74df17b47ba..2f2b110d7f56 100644
--- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
+++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
@@ -39,13 +39,12 @@ static int verify_tsk(int map_fd, int client_fd)
 static int verify_msk(int map_fd, int client_fd)
 {
 	char *msg = "MPTCP subflow socket";
-	int err = 0, cfd = client_fd;
+	int err, cfd = client_fd;
 	struct mptcp_storage val;
 
-	if (CHECK_FAIL(bpf_map_lookup_elem(map_fd, &cfd, &val) < 0)) {
-		perror("Failed to read socket storage");
-		return -1;
-	}
+	err = bpf_map_lookup_elem(map_fd, &cfd, &val);
+	if (!ASSERT_OK(err, "bpf_map_lookup_elem"))
+		return err;
 
 	if (val.invoked != 1) {
 		log_err("%s: unexpected invoked count %d != 1",
@@ -127,25 +126,25 @@ void test_base(void)
 	int server_fd, cgroup_fd;
 
 	cgroup_fd = test__join_cgroup("/mptcp");
-	if (CHECK_FAIL(cgroup_fd < 0))
+	if (!ASSERT_GT(cgroup_fd, 0, "test__join_cgroup"))
 		return;
 
 	/* without MPTCP */
 	server_fd = start_server(AF_INET, SOCK_STREAM, NULL, 0, 0);
-	if (CHECK_FAIL(server_fd < 0))
+	if (!ASSERT_GT(server_fd, 0, "start_server"))
 		goto with_mptcp;
 
-	CHECK_FAIL(run_test(cgroup_fd, server_fd, false));
+	ASSERT_OK(run_test(cgroup_fd, server_fd, false), "run_test tcp");
 
 	close(server_fd);
 
 with_mptcp:
 	/* with MPTCP */
 	server_fd = start_mptcp_server(AF_INET, NULL, 0, 0);
-	if (CHECK_FAIL(server_fd < 0))
+	if (!ASSERT_GT(server_fd, 0, "start_mptcp_server"))
 		goto close_cgroup_fd;
 
-	CHECK_FAIL(run_test(cgroup_fd, server_fd, true));
+	ASSERT_OK(run_test(cgroup_fd, server_fd, true), "run_test mptcp");
 
 	close(server_fd);
 
-- 
2.34.1


[PATCH mptcp-next] Squash to "selftests: bpf: verify token of struct mptcp_sock"
Posted by Geliang Tang 1 week, 2 days ago
Address to Andrii's comments:
- use ASSERT_* instead of CHECK_FAIL

Signed-off-by: Geliang Tang <geliang.tang@suse.com>
---
 tools/testing/selftests/bpf/prog_tests/mptcp.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c
index 42d496f52bc4..637e60bc3b14 100644
--- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
+++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
@@ -56,16 +56,12 @@ static __u32 get_msk_token(void)
 	sync();
 
 	fd = open(monitor_log_path, O_RDONLY);
-	if (CHECK_FAIL(fd < 0)) {
-		log_err("Failed to open %s", monitor_log_path);
+	if (!ASSERT_GT(fd, 0, "Failed to open monitor_log_path"))
 		return token;
-	}
 
 	len = read(fd, buf, sizeof(buf));
-	if (CHECK_FAIL(len < 0)) {
-		log_err("Failed to read %s", monitor_log_path);
+	if (!ASSERT_GT(len, 0, "Failed to read monitor_log_path"))
 		goto err;
-	}
 
 	if (strncmp(buf, prefix, strlen(prefix))) {
 		log_err("Invalid prefix %s", buf);
@@ -87,10 +83,8 @@ static int verify_msk(int map_fd, int client_fd)
 	__u32 token;
 
 	token = get_msk_token();
-	if (token <= 0) {
-		log_err("Unexpected token %x", token);
+	if (!ASSERT_GT(token, 0, "Unexpected token"))
 		return -1;
-	}
 
 	err = bpf_map_lookup_elem(map_fd, &cfd, &val);
 	if (!ASSERT_OK(err, "bpf_map_lookup_elem"))
@@ -197,12 +191,12 @@ void test_base(void)
 
 with_mptcp:
 	/* with MPTCP */
-	if (CHECK_FAIL(!mkdtemp(tmp_dir)))
+	if (!ASSERT_OK_PTR(mkdtemp(tmp_dir), "mkdtemp"))
 		goto close_cgroup_fd;
 	snprintf(monitor_log_path, sizeof(monitor_log_path),
 		 "%s/ip_mptcp_monitor", tmp_dir);
 	snprintf(cmd, sizeof(cmd), "ip mptcp monitor > %s &", monitor_log_path);
-	if (CHECK_FAIL(system(cmd)))
+	if (!ASSERT_OK(system(cmd), "ip mptcp monitor"))
 		goto close_cgroup_fd;
 	server_fd = start_mptcp_server(AF_INET, NULL, 0, 0);
 	if (!ASSERT_GT(server_fd, 0, "start_mptcp_server"))
-- 
2.34.1


[PATCH mptcp-next] Squash to "selftests: bpf: verify ca_name of struct mptcp_sock"
Posted by Geliang Tang 1 week, 2 days ago
Address to Andrii's comments:
- use ASSERT_* instead of CHECK_FAIL

Signed-off-by: Geliang Tang <geliang.tang@suse.com>
---
 tools/testing/selftests/bpf/prog_tests/mptcp.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c
index ad7f91d35e96..ebc9a187acd6 100644
--- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
+++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
@@ -86,16 +86,12 @@ void get_msk_ca_name(char ca_name[])
 	int fd;
 
 	fd = open("/proc/sys/net/ipv4/tcp_congestion_control", O_RDONLY);
-	if (CHECK_FAIL(fd < 0)) {
-		log_err("Failed to open tcp_congestion_control");
+	if (!ASSERT_GT(fd, 0, "Failed to open tcp_congestion_control"))
 		return;
-	}
 
 	len = read(fd, ca_name, TCP_CA_NAME_MAX);
-	if (CHECK_FAIL(len < 0)) {
-		log_err("Failed to read ca_name");
+	if (!ASSERT_GT(len, 0, "Failed to read ca_name"))
 		goto err;
-	}
 
 	if (len > 0 && ca_name[len - 1] == '\n')
 		ca_name[len - 1] = '\0';
-- 
2.34.1


[PATCH mptcp-next] Squash to "selftests: bpf: add bpf_first test"
Posted by Geliang Tang 1 week, 2 days ago
Address to Andrii's comments:
- use ASSERT_* instead of CHECK_FAIL

Signed-off-by: Geliang Tang <geliang.tang@suse.com>
---
 tools/testing/selftests/bpf/prog_tests/mptcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c
index 625d7a644fd4..865e3b392ac3 100644
--- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
+++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
@@ -343,7 +343,7 @@ static void test_first(void)
 	struct bpf_link *link;
 
 	first_skel = mptcp_bpf_first__open_and_load();
-	if (CHECK(!first_skel, "bpf_first__open_and_load", "failed\n"))
+	if (!ASSERT_OK_PTR(first_skel, "bpf_first__open_and_load"))
 		return;
 
 	link = bpf_map__attach_struct_ops(first_skel->maps.first);
-- 
2.34.1