summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2020-02-01 09:58:07 -0700
committerJens Axboe <axboe@kernel.dk>2020-02-01 09:58:07 -0700
commita8dc4979d58f1eac3082f8def4bbea9c0eea3898 (patch)
tree16e42e55ad3ccfd4e2a0d347039045592d635398 /test
parenta717b4b5cc473b0f330f3b077733057db52009e5 (diff)
downloadliburing-a8dc4979d58f1eac3082f8def4bbea9c0eea3898.tar.gz
liburing-a8dc4979d58f1eac3082f8def4bbea9c0eea3898.tar.bz2
Use stderr consistently in test/ cases
This is a start, still some to go. The goal here is to ensure that we use stderr consistently for errors, and include the error value as well. Right now folks copy/paste test cases (which they should), but that also means they should be doing the right thing so we don't keep adding test cases that just use stdout for errors, or don't include the error value. Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'test')
-rw-r--r--test/nop.c21
-rw-r--r--test/personality.c3
-rw-r--r--test/poll-cancel-ton.c4
-rw-r--r--test/poll-cancel.c38
-rw-r--r--test/poll-link.c2
-rw-r--r--test/poll-many.c4
-rw-r--r--test/poll.c25
-rw-r--r--test/read-write.c6
-rw-r--r--test/send_recvmsg.c15
-rw-r--r--test/sq-full.c4
-rw-r--r--test/sq-space_left.c8
-rw-r--r--test/stdout.c2
-rw-r--r--test/timeout-overflow.c28
13 files changed, 81 insertions, 79 deletions
diff --git a/test/nop.c b/test/nop.c
index 4b072fc..45e65e4 100644
--- a/test/nop.c
+++ b/test/nop.c
@@ -19,7 +19,7 @@ static int test_single_nop(struct io_uring *ring)
sqe = io_uring_get_sqe(ring);
if (!sqe) {
- printf("get sqe failed\n");
+ fprintf(stderr, "get sqe failed\n");
goto err;
}
@@ -27,13 +27,13 @@ static int test_single_nop(struct io_uring *ring)
ret = io_uring_submit(ring);
if (ret <= 0) {
- printf("sqe submit failed: %d\n", ret);
+ fprintf(stderr, "sqe submit failed: %d\n", ret);
goto err;
}
ret = io_uring_wait_cqe(ring, &cqe);
if (ret < 0) {
- printf("wait completion %d\n", ret);
+ fprintf(stderr, "wait completion %d\n", ret);
goto err;
}
@@ -52,7 +52,7 @@ static int test_barrier_nop(struct io_uring *ring)
for (i = 0; i < 8; i++) {
sqe = io_uring_get_sqe(ring);
if (!sqe) {
- printf("get sqe failed\n");
+ fprintf(stderr, "get sqe failed\n");
goto err;
}
@@ -63,17 +63,17 @@ static int test_barrier_nop(struct io_uring *ring)
ret = io_uring_submit(ring);
if (ret < 0) {
- printf("sqe submit failed: %d\n", ret);
+ fprintf(stderr, "sqe submit failed: %d\n", ret);
goto err;
} else if (ret < 8) {
- printf("Submitted only %d\n", ret);
+ fprintf(stderr, "Submitted only %d\n", ret);
goto err;
}
for (i = 0; i < 8; i++) {
ret = io_uring_wait_cqe(ring, &cqe);
if (ret < 0) {
- printf("wait completion %d\n", ret);
+ fprintf(stderr, "wait completion %d\n", ret);
goto err;
}
io_uring_cqe_seen(ring, cqe);
@@ -91,20 +91,19 @@ int main(int argc, char *argv[])
ret = io_uring_queue_init(8, &ring, 0);
if (ret) {
- printf("ring setup failed\n");
+ fprintf(stderr, "ring setup failed: %d\n", ret);
return 1;
-
}
ret = test_single_nop(&ring);
if (ret) {
- printf("test_single_nop failed\n");
+ fprintf(stderr, "test_single_nop failed\n");
return ret;
}
ret = test_barrier_nop(&ring);
if (ret) {
- printf("test_barrier_nop failed\n");
+ fprintf(stderr, "test_barrier_nop failed\n");
return ret;
}
diff --git a/test/personality.c b/test/personality.c
index a2f0ceb..1d08473 100644
--- a/test/personality.c
+++ b/test/personality.c
@@ -172,9 +172,8 @@ int main(int argc, char *argv[])
ret = io_uring_queue_init(8, &ring, 0);
if (ret) {
- printf("ring setup failed\n");
+ fprintf(stderr, "ring setup failed: %d\n", ret);
return 1;
-
}
ret = test_personality(&ring);
diff --git a/test/poll-cancel-ton.c b/test/poll-cancel-ton.c
index 5bcf314..eb3b47b 100644
--- a/test/poll-cancel-ton.c
+++ b/test/poll-cancel-ton.c
@@ -104,13 +104,13 @@ int main(int argc, char *argv[])
int ret;
if (pipe(pipe1) != 0) {
- printf("pipe failed\n");
+ perror("pipe");
return 1;
}
ret = io_uring_queue_init(1024, &ring, 0);
if (ret) {
- printf("child: ring setup failed\n");
+ fprintf(stderr, "ring setup failed: %d\n", ret);
return 1;
}
diff --git a/test/poll-cancel.c b/test/poll-cancel.c
index eeed2ac..d85113a 100644
--- a/test/poll-cancel.c
+++ b/test/poll-cancel.c
@@ -21,7 +21,7 @@ struct poll_data {
static void sig_alrm(int sig)
{
- printf("Timed out!\n");
+ fprintf(stderr, "Timed out!\n");
exit(1);
}
@@ -36,13 +36,13 @@ int main(int argc, char *argv[])
int ret;
if (pipe(pipe1) != 0) {
- printf("pipe failed\n");
+ perror("pipe");
return 1;
}
ret = io_uring_queue_init(2, &ring, 0);
if (ret) {
- printf("child: ring setup failed\n");
+ fprintf(stderr, "ring setup failed: %d\n", ret);
return 1;
}
@@ -54,7 +54,7 @@ int main(int argc, char *argv[])
sqe = io_uring_get_sqe(&ring);
if (!sqe) {
- printf("child: get sqe failed\n");
+ fprintf(stderr, "get sqe failed\n");
return 1;
}
@@ -66,13 +66,13 @@ int main(int argc, char *argv[])
ret = io_uring_submit(&ring);
if (ret <= 0) {
- printf("child: sqe submit failed\n");
+ fprintf(stderr, "sqe submit failed\n");
return 1;
}
sqe = io_uring_get_sqe(&ring);
if (!sqe) {
- printf("child: get sqe failed\n");
+ fprintf(stderr, "get sqe failed\n");
return 1;
}
@@ -83,42 +83,46 @@ int main(int argc, char *argv[])
ret = io_uring_submit(&ring);
if (ret <= 0) {
- printf("child: sqe submit failed\n");
+ fprintf(stderr, "sqe submit failed: %d\n", ret);
return 1;
}
ret = io_uring_wait_cqe(&ring, &cqe);
if (ret < 0) {
- printf("child: get cqe failed\n");
+ fprintf(stderr, "wait cqe failed: %d\n", ret);
return 1;
}
pd = io_uring_cqe_get_data(cqe);
if (pd->is_poll && cqe->res != -ECANCELED) {
- printf("sqe (add=%d/remove=%d) failed with %ld\n", pd->is_poll,
- pd->is_cancel, (long) cqe->res);
+ fprintf(stderr ,"sqe (add=%d/remove=%d) failed with %ld\n",
+ pd->is_poll, pd->is_cancel,
+ (long) cqe->res);
return 1;
} else if (pd->is_cancel && cqe->res) {
- printf("sqe (add=%d/remove=%d) failed with %ld\n", pd->is_poll,
- pd->is_cancel, (long) cqe->res);
+ fprintf(stderr, "sqe (add=%d/remove=%d) failed with %ld\n",
+ pd->is_poll, pd->is_cancel,
+ (long) cqe->res);
return 1;
}
io_uring_cqe_seen(&ring, cqe);
ret = io_uring_wait_cqe(&ring, &cqe);
if (ret < 0) {
- printf("parent: get failed\n");
+ fprintf(stderr, "wait_cqe: %d\n", ret);
return 1;
}
pd = io_uring_cqe_get_data(cqe);
if (pd->is_poll && cqe->res != -ECANCELED) {
- printf("sqe (add=%d/remove=%d) failed with %ld\n", pd->is_poll,
- pd->is_cancel, (long) cqe->res);
+ fprintf(stderr, "sqe (add=%d/remove=%d) failed with %ld\n",
+ pd->is_poll, pd->is_cancel,
+ (long) cqe->res);
return 1;
} else if (pd->is_cancel && cqe->res) {
- printf("sqe (add=%d/remove=%d) failed with %ld\n", pd->is_poll,
- pd->is_cancel, (long) cqe->res);
+ fprintf(stderr, "sqe (add=%d/remove=%d) failed with %ld\n",
+ pd->is_poll, pd->is_cancel,
+ (long) cqe->res);
return 1;
}
diff --git a/test/poll-link.c b/test/poll-link.c
index abddb71..795e04a 100644
--- a/test/poll-link.c
+++ b/test/poll-link.c
@@ -99,7 +99,7 @@ void *recv_thread(void *arg)
} while (++i < 100);
if (i >= 100) {
- printf("Can't find good port, skipped\n");
+ fprintf(stderr, "Can't find good port, skipped\n");
data->stop = 1;
signal_var(&recv_thread_ready);
goto out;
diff --git a/test/poll-many.c b/test/poll-many.c
index 695c14c..afde491 100644
--- a/test/poll-many.c
+++ b/test/poll-many.c
@@ -119,7 +119,7 @@ static int arm_polls(struct io_uring *ring)
for (i = 0; i < this_arm; i++) {
if (arm_poll(ring, off)) {
- printf("arm failed at %d\n", off);
+ fprintf(stderr, "arm failed at %d\n", off);
return 1;
}
off++;
@@ -127,7 +127,7 @@ static int arm_polls(struct io_uring *ring)
ret = io_uring_submit(ring);
if (ret != this_arm) {
- printf("submitted %d, %d\n", ret, this_arm);
+ fprintf(stderr, "submitted %d, %d\n", ret, this_arm);
return 1;
}
to_arm -= this_arm;
diff --git a/test/poll.c b/test/poll.c
index ed424fc..1ddcf3d 100644
--- a/test/poll.c
+++ b/test/poll.c
@@ -15,7 +15,7 @@
static void sig_alrm(int sig)
{
- printf("Timed out!\n");
+ fprintf(stderr, "Timed out!\n");
exit(1);
}
@@ -29,21 +29,21 @@ int main(int argc, char *argv[])
int ret;
if (pipe(pipe1) != 0) {
- printf("pipe failed\n");
+ perror("pipe");
return 1;
}
p = fork();
switch (p) {
case -1:
- printf("fork failed\n");
+ perror("fork");
exit(2);
case 0: {
struct sigaction act;
ret = io_uring_queue_init(1, &ring, 0);
if (ret) {
- printf("child: ring setup failed\n");
+ fprintf(stderr, "child: ring setup failed: %d\n", ret);
return 1;
}
@@ -55,7 +55,7 @@ int main(int argc, char *argv[])
sqe = io_uring_get_sqe(&ring);
if (!sqe) {
- printf("child: get sqe failed\n");
+ fprintf(stderr, "get sqe failed\n");
return 1;
}
@@ -64,29 +64,28 @@ int main(int argc, char *argv[])
ret = io_uring_submit(&ring);
if (ret <= 0) {
- printf("child: sqe submit failed\n");
+ fprintf(stderr, "child: sqe submit failed: %d\n", ret);
return 1;
}
do {
ret = io_uring_wait_cqe(&ring, &cqe);
if (ret < 0) {
- printf("child: wait completion %d\n", ret);
+ fprintf(stderr, "child: wait completion %d\n", ret);
break;
}
io_uring_cqe_seen(&ring, cqe);
} while (ret != 0);
- if (ret < 0) {
- printf("child: completion get failed\n");
+ if (ret < 0)
return 1;
- }
if (cqe->user_data != (unsigned long) sqe) {
- printf("child: cqe doesn't match sqe\n");
+ fprintf(stderr, "child: cqe doesn't match sqe\n");
return 1;
}
if ((cqe->res & POLLIN) != POLLIN) {
- printf("child: bad return value %ld\n", (long) cqe->res);
+ fprintf(stderr, "child: bad return value %ld\n",
+ (long) cqe->res);
return 1;
}
exit(0);
@@ -98,7 +97,7 @@ int main(int argc, char *argv[])
} while (ret == -1 && errno == EINTR);
if (ret != 3) {
- printf("parent: bad write return %d\n", ret);
+ fprintf(stderr, "parent: bad write return %d\n", ret);
return 1;
}
return 0;
diff --git a/test/read-write.c b/test/read-write.c
index 64f8fd5..0d19d5a 100644
--- a/test/read-write.c
+++ b/test/read-write.c
@@ -69,7 +69,7 @@ static int test_io(const char *file, int write, int buffered, int sqthread,
#endif
if (sqthread && geteuid()) {
#ifdef VERBOSE
- printf("SKIPPED (not root)\n");
+ fprintf(stdout, "SKIPPED (not root)\n");
#endif
return 0;
}
@@ -208,12 +208,12 @@ static int test_io(const char *file, int write, int buffered, int sqthread,
io_uring_queue_exit(&ring);
close(fd);
#ifdef VERBOSE
- printf("PASS\n");
+ fprintf(stdout, "PASS\n");
#endif
return 0;
err:
#ifdef VERBOSE
- printf("FAILED\n");
+ fprintf(stderr, "FAILED\n");
#endif
if (fd != -1)
close(fd);
diff --git a/test/send_recvmsg.c b/test/send_recvmsg.c
index 484a4b7..7449916 100644
--- a/test/send_recvmsg.c
+++ b/test/send_recvmsg.c
@@ -53,7 +53,7 @@ static int recv_prep(struct io_uring *ring, struct iovec *iov)
ret = io_uring_submit(ring);
if (ret <= 0) {
- printf("submit failed\n");
+ fprintf(stderr, "submit failed: %d\n", ret);
goto err;
}
@@ -69,17 +69,18 @@ static int do_recvmsg(struct io_uring *ring, struct iovec *iov)
io_uring_wait_cqe(ring, &cqe);
if (cqe->res < 0) {
- printf("failed cqe: %d\n", cqe->res);
+ fprintf(stderr, "failed cqe: %d\n", cqe->res);
goto err;
}
if (cqe->res -1 != strlen(str)) {
- printf("got wrong length\n");
+ fprintf(stderr, "got wrong length: %d/%d\n", cqe->res,
+ (int) strlen(str) + 1);
goto err;
}
if (strcmp(str, iov->iov_base)) {
- printf("string mismatch\n");
+ fprintf(stderr, "string mismatch\n");
goto err;
}
@@ -124,7 +125,7 @@ static int do_sendmsg(void)
ret = io_uring_queue_init(1, &ring, 0);
if (ret) {
- printf("queue init fail\n");
+ fprintf(stderr, "queue init fail: %d\n", ret);
return 1;
}
@@ -150,13 +151,13 @@ static int do_sendmsg(void)
ret = io_uring_submit(&ring);
if (ret <= 0) {
- printf("submit failed\n");
+ fprintf(stderr, "submit failed: %d\n", ret);
goto err;
}
ret = io_uring_wait_cqe(&ring, &cqe);
if (cqe->res < 0) {
- printf("failed cqe: %d\n", cqe->res);
+ fprintf(stderr, "failed cqe: %d\n", cqe->res);
goto err;
}
diff --git a/test/sq-full.c b/test/sq-full.c
index 3fbe0a5..cc91477 100644
--- a/test/sq-full.c
+++ b/test/sq-full.c
@@ -19,7 +19,7 @@ int main(int argc, char *argv[])
ret = io_uring_queue_init(8, &ring, 0);
if (ret) {
- printf("ring setup failed\n");
+ fprintf(stderr, "ring setup failed: %d\n", ret);
return 1;
}
@@ -29,7 +29,7 @@ int main(int argc, char *argv[])
i++;
if (i != 8) {
- printf("Got %d SQEs\n", i);
+ fprintf(stderr, "Got %d SQEs, wanted 8\n", i);
goto err;
}
diff --git a/test/sq-space_left.c b/test/sq-space_left.c
index 71fc871..81324b1 100644
--- a/test/sq-space_left.c
+++ b/test/sq-space_left.c
@@ -19,13 +19,13 @@ int main(int argc, char *argv[])
ret = io_uring_queue_init(8, &ring, 0);
if (ret) {
- printf("ring setup failed\n");
+ fprintf(stderr, "ring setup failed: %d\n", ret);
return 1;
}
if ((s = io_uring_sq_space_left(&ring)) != 8) {
- printf("Got %d SQEs left, expected %d\n", s, 8);
+ fprintf(stderr, "Got %d SQEs left, expected %d\n", s, 8);
goto err;
}
@@ -33,13 +33,13 @@ int main(int argc, char *argv[])
while ((sqe = io_uring_get_sqe(&ring)) != NULL) {
i++;
if ((s = io_uring_sq_space_left(&ring)) != 8 - i) {
- printf("Got %d SQEs left, expected %d\n", s, 8 - i);
+ fprintf(stderr, "Got %d SQEs left, expected %d\n", s, 8 - i);
goto err;
}
}
if (i != 8) {
- printf("Got %d SQEs, expected %d\n", i, 8);
+ fprintf(stderr, "Got %d SQEs, expected %d\n", i, 8);
goto err;
}
diff --git a/test/stdout.c b/test/stdout.c
index c39dc84..ddf1f33 100644
--- a/test/stdout.c
+++ b/test/stdout.c
@@ -48,7 +48,7 @@ static int test_pipe_io_fixed(struct io_uring *ring)
sqe = io_uring_get_sqe(ring);
if (!sqe) {
- printf("get sqe failed\n");
+ fprintf(stderr, "get sqe failed\n");
goto err;
}
vecs[1].iov_base = buffer;
diff --git a/test/timeout-overflow.c b/test/timeout-overflow.c
index 5d275e6..5f34c10 100644
--- a/test/timeout-overflow.c
+++ b/test/timeout-overflow.c
@@ -28,7 +28,7 @@ static int check_timeout_support()
ret = io_uring_queue_init(8, &ring, 0);
if (ret) {
- printf("ring setup failed\n");
+ fprintf(stderr, "ring setup failed: %d\n", ret);
return 1;
}
sqe = io_uring_get_sqe(&ring);
@@ -37,19 +37,19 @@ static int check_timeout_support()
ret = io_uring_submit(&ring);
if (ret < 0) {
- printf("sqe submit failed: %d\n", ret);
+ fprintf(stderr, "sqe submit failed: %d\n", ret);
goto err;
}
ret = io_uring_wait_cqe(&ring, &cqe);
if (ret < 0) {
- printf("wait completion %d\n", ret);
+ fprintf(stderr, "wait completion %d\n", ret);
goto err;
}
if (cqe->res == -EINVAL) {
not_supported = 1;
- printf("Timeout not supported, ignored\n");
+ fprintf(stdout, "Timeout not supported, ignored\n");
return 0;
}
@@ -83,7 +83,7 @@ static int test_timeout_overflow()
ret = io_uring_queue_init(16, &ring, 0);
if (ret) {
- printf("ring setup failed\n");
+ fprintf(stderr, "ring setup failed: %d\n", ret);
return 1;
}
@@ -113,7 +113,7 @@ static int test_timeout_overflow()
}
ret = io_uring_submit(&ring);
if (ret < 0) {
- printf("sqe submit failed: %d\n", ret);
+ fprintf(stderr, "sqe submit failed: %d\n", ret);
goto err;
}
@@ -121,7 +121,7 @@ static int test_timeout_overflow()
while (i < 6) {
ret = io_uring_wait_cqe(&ring, &cqe);
if (ret < 0) {
- printf("wait completion %d\n", ret);
+ fprintf(stderr, "wait completion %d\n", ret);
goto err;
}
@@ -136,7 +136,7 @@ static int test_timeout_overflow()
case 0:
case 3:
if (io_uring_cqe_get_data(cqe) != (void *) 1) {
- printf("nop not seen as 1 or 2\n");
+ fprintf(stderr, "nop not seen as 1 or 2\n");
goto err;
}
break;
@@ -144,15 +144,15 @@ static int test_timeout_overflow()
case 2:
case 4:
if (cqe->res == -ETIME) {
- printf("expected not return -ETIME for the "
- "%d'th timeout req\n", i - 1);
+ fprintf(stderr, "expected not return -ETIME "
+ "for the %d'th timeout req\n", i - 1);
goto err;
}
break;
case 5:
if (cqe->res != -ETIME) {
- printf("expected return -ETIME for the "
- "%d'th timeout req\n", i - 1);
+ fprintf(stderr, "expected return -ETIME for "
+ "the %d'th timeout req\n", i - 1);
goto err;
}
break;
@@ -172,7 +172,7 @@ int main(int argc, char *argv[])
ret = check_timeout_support();
if (ret) {
- printf("ring setup failed\n");
+ fprintf(stderr, "check_timeout_support failed: %d\n", ret);
return 1;
}
@@ -181,7 +181,7 @@ int main(int argc, char *argv[])
ret = test_timeout_overflow();
if (ret) {
- printf("test_timeout_overflow failed\n");
+ fprintf(stderr, "test_timeout_overflow failed\n");
return 1;
}