Skip to content

Commit

Permalink
test: ensure to check write(2) return value
Browse files Browse the repository at this point in the history
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
axboe committed Dec 8, 2023
1 parent 8abbdc5 commit f94a237
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
9 changes: 8 additions & 1 deletion test/buf-ring-nommap.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,14 @@ int main(int argc, char *argv[])

io_uring_submit(&ring);

write(fds[1], "Hello", 5);
ret = write(fds[1], "Hello", 5);
if (ret < 0) {
perror("write");
return T_EXIT_FAIL;
} else if (ret != 5) {
fprintf(stderr, "short write %d\n", ret);
return T_EXIT_FAIL;
}

ret = io_uring_wait_cqe(&ring, &cqe);
if (ret) {
Expand Down
36 changes: 32 additions & 4 deletions test/fd-install.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,14 @@ static int test_working(struct io_uring *ring)
io_uring_submit(ring);

/* put some data in the pipe */
write(fds[1], "Hello", 5);
ret = write(fds[1], "Hello", 5);
if (ret < 0) {
perror("write");
return T_EXIT_FAIL;
} else if (ret != 5) {
fprintf(stderr, "short write %d\n", ret);
return T_EXIT_FAIL;
}

ret = io_uring_wait_cqe(ring, &cqe);
if (ret) {
Expand Down Expand Up @@ -218,7 +225,14 @@ static int test_working(struct io_uring *ring)
fds[0] = cqe->res;
io_uring_cqe_seen(ring, cqe);

write(fds[1], "Hello", 5);
ret = write(fds[1], "Hello", 5);
if (ret < 0) {
perror("write");
return T_EXIT_FAIL;
} else if (ret != 5) {
fprintf(stderr, "short write %d\n", ret);
return T_EXIT_FAIL;
}

/* normal pipe read should now work with new fd */
ret = read(fds[0], buf, sizeof(buf));
Expand All @@ -243,7 +257,14 @@ static int test_working(struct io_uring *ring)
}
io_uring_cqe_seen(ring, cqe);

write(fds[1], "Hello", 5);
ret = write(fds[1], "Hello", 5);
if (ret < 0) {
perror("write");
return T_EXIT_FAIL;
} else if (ret != 5) {
fprintf(stderr, "short write %d\n", ret);
return T_EXIT_FAIL;
}

/* normal pipe read should still work with new fd */
ret = read(fds[0], buf, sizeof(buf));
Expand All @@ -259,7 +280,14 @@ static int test_working(struct io_uring *ring)
io_uring_submit(ring);

/* put some data in the pipe */
write(fds[1], "Hello", 5);
ret = write(fds[1], "Hello", 5);
if (ret < 0) {
perror("write");
return T_EXIT_FAIL;
} else if (ret != 5) {
fprintf(stderr, "short write %d\n", ret);
return T_EXIT_FAIL;
}

ret = io_uring_wait_cqe(ring, &cqe);
if (ret) {
Expand Down

0 comments on commit f94a237

Please sign in to comment.