Message ID | 35ab4f6f094e3c700aa9ec20ee6d6d1a91284b5a.1720405046.git.tanggeliang@kylinos.cn (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | use network helpers, part 8 | expand |
On Mon, 2024-07-08 at 10:29 +0800, Geliang Tang wrote: [...] > 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; I think this option obfuscates actual test cases. Each helper that accepts network_helper_opts as a parameter, does multiple system calls. It is not obvious which of these calls is expected to fail. > int proto; > /* The backlog argument for listen(), defines the maximum length to which > * the queue of pending connections for sockfd may grow. [...]
On 7/8/24 12:15 PM, Eduard Zingerman wrote: > On Mon, 2024-07-08 at 10:29 +0800, Geliang Tang wrote: > > [...] > >> 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; > > I think this option obfuscates actual test cases. > Each helper that accepts network_helper_opts as a parameter, does > multiple system calls. It is not obvious which of these calls is > expected to fail. +1 Please no. On top of that, handling specific errno is not something that belongs to the generic network_helpers.c. The individual test should check for the errno that it expects on the error path. Is it for make_client()? The caller of make_client can check the errno instead, no? [ The same goes for the existing "bool must_fail;" but it can be left for a separate cleanup patch ] pw-bot: cr > >> 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/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;