Skip to content

Commit cf338f8

Browse files
Geliang TangKernel Patches Daemon
authored andcommitted
selftests/bpf: Add expect_errno for network_helper_opts
The errno EPERM is skipped in connect_fd_to_addr() by cgroup_v1v2 tests. More generally, it makes sense to add a struct member "expect_errno" for network_helper_opts to identify the expect errno to be skipped. Correspondingly, connect_fd_to_addr() helper needs to add a new parameter "expect_errno" too to accept "opts->expect_errno" passed from the caller connect_to_addr() or connect_fd_to_fd(). With this change, only need to set "expect_errno" as EPERM in run_test() in prog_tests/cgroup_v1v2.c. Signed-off-by: Geliang Tang <[email protected]>
1 parent 723b3ed commit cf338f8

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

tools/testing/selftests/bpf/network_helpers.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ int client_socket(int family, int type,
279279

280280
static int connect_fd_to_addr(int fd,
281281
const struct sockaddr_storage *addr,
282-
socklen_t addrlen, const bool must_fail)
282+
socklen_t addrlen, const bool must_fail,
283+
const int expect_errno)
283284
{
284285
int ret;
285286

@@ -290,7 +291,7 @@ static int connect_fd_to_addr(int fd,
290291
log_err("Unexpected success to connect to server");
291292
return -1;
292293
}
293-
if (errno != EPERM) {
294+
if (errno != expect_errno) {
294295
log_err("Unexpected error from connect to server");
295296
return -1;
296297
}
@@ -318,7 +319,8 @@ int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t add
318319
return -1;
319320
}
320321

321-
if (connect_fd_to_addr(fd, addr, addrlen, opts->must_fail))
322+
if (connect_fd_to_addr(fd, addr, addrlen, opts->must_fail,
323+
opts->expect_errno))
322324
goto error_close;
323325

324326
return fd;
@@ -386,7 +388,8 @@ int connect_fd_to_fd(int client_fd, int server_fd,
386388
return -1;
387389
}
388390

389-
if (connect_fd_to_addr(client_fd, &addr, len, opts->must_fail))
391+
if (connect_fd_to_addr(client_fd, &addr, len, opts->must_fail,
392+
opts->expect_errno))
390393
return -1;
391394

392395
return 0;

tools/testing/selftests/bpf/network_helpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ typedef __u16 __sum16;
2424
struct network_helper_opts {
2525
int timeout_ms;
2626
bool must_fail;
27+
int expect_errno;
2728
int proto;
2829
/* The backlog argument for listen(), defines the maximum length to which
2930
* the queue of pending connections for sockfd may grow.

tools/testing/selftests/bpf/prog_tests/cgroup_v1v2.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ static int run_test(int cgroup_fd, int server_fd, bool classid)
1111
{
1212
struct network_helper_opts opts = {
1313
.must_fail = true,
14+
.expect_errno = EPERM,
1415
};
1516
struct connect4_dropper *skel;
1617
int fd, err = 0;

0 commit comments

Comments
 (0)