Skip to content

Commit

Permalink
test: update socket opt / socket io cmd for old kernels
Browse files Browse the repository at this point in the history
Ensure we properly skip on older kernels, rather than show odd
failures.

Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
axboe committed Dec 9, 2023
1 parent 61e7b2b commit 2624f36
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
12 changes: 8 additions & 4 deletions test/socket-getsetsock-cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#define USERDATA 0xff42ff
#define MSG "foobarbaz"

static int no_sock_opt;

struct fds {
int tx;
int rx;
Expand Down Expand Up @@ -149,8 +151,10 @@ static int run_get_peername(struct io_uring *ring, struct fds *sockfds)

/* Wait for the CQE */
err = receive_cqe(ring);
if (err == -EOPNOTSUPP)
if (err == -EOPNOTSUPP || err == -EINVAL) {
no_sock_opt = 1;
return T_EXIT_SKIP;
}

if (err < 0) {
fprintf(stderr, "%s: Error in the CQE: %d\n", __func__, err);
Expand Down Expand Up @@ -180,9 +184,7 @@ static int run_getsockopt_test(struct io_uring *ring, struct fds *sockfds)
return err;

fprintf(stderr, "Testing getsockopt SO_RCVBUF\n");
err = run_get_rcvbuf(ring, sockfds);

return err;
return run_get_rcvbuf(ring, sockfds);
}

/*
Expand Down Expand Up @@ -312,6 +314,8 @@ int main(int argc, char *argv[])
fprintf(stderr, "Failed to run test: %d\n", err);
return err;
}
if (no_sock_opt)
return T_EXIT_SKIP;

err = run_setsockopt_test(&ring, &sockfds);
if (err) {
Expand Down
16 changes: 14 additions & 2 deletions test/socket-io-cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#define USERDATA 0x1234
#define MSG "foobarbaz"

static int no_io_cmd;

struct fds {
int tx;
int rx;
Expand Down Expand Up @@ -83,7 +85,7 @@ static ssize_t send_data(struct fds *s, char *str)
static int run_test(bool stream)
{
struct fds sockfds;
size_t bytes_in, bytes_out;
ssize_t bytes_in, bytes_out;
struct io_uring ring;
size_t written_bytes;
int error;
Expand All @@ -104,9 +106,17 @@ static int run_test(bool stream)

error = create_sqe_and_submit(&ring, sockfds.rx,
SOCKET_URING_OP_SIOCINQ);
bytes_in = receive_cqe(&ring);
if (error)
return T_EXIT_FAIL;
bytes_in = receive_cqe(&ring);
if (bytes_in < 0) {
if (bytes_in == -EINVAL) {
no_io_cmd = 1;
return T_EXIT_SKIP;
}
fprintf(stderr, "Bad return value %ld\n", (long) bytes_in);
return T_EXIT_FAIL;
}

error = create_sqe_and_submit(&ring, sockfds.tx,
SOCKET_URING_OP_SIOCOUTQ);
Expand Down Expand Up @@ -204,6 +214,8 @@ int main(int argc, char *argv[])
err = run_test(true);
if (err)
return err;
if (no_io_cmd)
return T_EXIT_SKIP;

/* Test SOCK_DGRAM */
err = run_test(false);
Expand Down

0 comments on commit 2624f36

Please sign in to comment.