[PATCH bpf-next v9 06/11] selftests/bpf: Add expect_errno for network_helper_opts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Geliang Tang <tanggeliang@xxxxxxxxxx>

The errno EPERM is skipped in connect_fd_to_addr() by cgroup_v1v2 tests.
More generally, it makes sense to add a "expect_errno" struct member for
network_helper_opts to identify the expect errno to be skipped.

Signed-off-by: Geliang Tang <tanggeliang@xxxxxxxxxx>
---
 tools/testing/selftests/bpf/network_helpers.c        | 11 +++++++----
 tools/testing/selftests/bpf/network_helpers.h        |  1 +
 tools/testing/selftests/bpf/prog_tests/cgroup_v1v2.c |  1 +
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
index 475a5a04e61e..062170d6be1c 100644
--- a/tools/testing/selftests/bpf/network_helpers.c
+++ b/tools/testing/selftests/bpf/network_helpers.c
@@ -279,7 +279,8 @@ int client_socket(int family, int type,
 
 static int connect_fd_to_addr(int fd,
 			      const struct sockaddr_storage *addr,
-			      socklen_t addrlen, const bool must_fail)
+			      socklen_t addrlen, const bool must_fail,
+			      const int expect_errno)
 {
 	int ret;
 
@@ -290,7 +291,7 @@ static int connect_fd_to_addr(int fd,
 			log_err("Unexpected success to connect to server");
 			return -1;
 		}
-		if (errno != EPERM) {
+		if (errno != expect_errno) {
 			log_err("Unexpected error from connect to server");
 			return -1;
 		}
@@ -318,7 +319,8 @@ int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t add
 		return -1;
 	}
 
-	if (connect_fd_to_addr(fd, addr, addrlen, opts->must_fail))
+	if (connect_fd_to_addr(fd, addr, addrlen, opts->must_fail,
+			       opts->expect_errno))
 		goto error_close;
 
 	return fd;
@@ -386,7 +388,8 @@ int connect_fd_to_fd(int client_fd, int server_fd,
 		return -1;
 	}
 
-	if (connect_fd_to_addr(client_fd, &addr, len, opts->must_fail))
+	if (connect_fd_to_addr(client_fd, &addr, len, opts->must_fail,
+			       opts->expect_errno))
 		return -1;
 
 	return 0;
diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h
index fcda6b2333ad..14d161d35248 100644
--- a/tools/testing/selftests/bpf/network_helpers.h
+++ b/tools/testing/selftests/bpf/network_helpers.h
@@ -24,6 +24,7 @@ typedef __u16 __sum16;
 struct network_helper_opts {
 	int timeout_ms;
 	bool must_fail;
+	int expect_errno;
 	int proto;
 	/* The backlog argument for listen(), defines the maximum length to which
 	 * the queue of pending connections for sockfd may grow.
diff --git a/tools/testing/selftests/bpf/prog_tests/cgroup_v1v2.c b/tools/testing/selftests/bpf/prog_tests/cgroup_v1v2.c
index 9709c8db7275..ff477163f0ea 100644
--- a/tools/testing/selftests/bpf/prog_tests/cgroup_v1v2.c
+++ b/tools/testing/selftests/bpf/prog_tests/cgroup_v1v2.c
@@ -11,6 +11,7 @@ static int run_test(int cgroup_fd, int server_fd, bool classid)
 {
 	struct network_helper_opts opts = {
 		.must_fail = true,
+		.expect_errno = EPERM,
 	};
 	struct connect4_dropper *skel;
 	int fd, err = 0;
-- 
2.43.0





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux