summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2021-12-10 08:56:07 -0700
committerJens Axboe <axboe@kernel.dk>2021-12-10 08:56:07 -0700
commit56c7bb43bdac67acd808cd88a507c78ac6c56259 (patch)
tree0588d51a54f07917fd2bbd54ce2ad8616e2d9c34
parent39d5c150b2754a7074454f90ac510b0281bac190 (diff)
downloadliburing-56c7bb43bdac67acd808cd88a507c78ac6c56259.tar.gz
liburing-56c7bb43bdac67acd808cd88a507c78ac6c56259.tar.bz2
test/exit-no-cleanup: skip file based run
This test doesn't do anything with the file passed in as an argument, hence it should just skip if that's the case. While in there, convert from MSDOS file format. Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--test/exit-no-cleanup.c231
1 files changed, 117 insertions, 114 deletions
diff --git a/test/exit-no-cleanup.c b/test/exit-no-cleanup.c
index 90ef394..b3fd5a4 100644
--- a/test/exit-no-cleanup.c
+++ b/test/exit-no-cleanup.c
@@ -1,114 +1,117 @@
-/* SPDX-License-Identifier: MIT */
-/*
- * Test case testing exit without cleanup and io-wq work pending or queued.
- *
- * From Florian Fischer <florian.fl.fischer@fau.de>
- * Link: https://lore.kernel.org/io-uring/20211202165606.mqryio4yzubl7ms5@pasture/
- *
- */
-#include <assert.h>
-#include <err.h>
-#include <errno.h>
-#include <pthread.h>
-#include <semaphore.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/sysinfo.h>
-#include <unistd.h>
-
-#include "liburing.h"
-#include "helpers.h"
-
-#define IORING_ENTRIES 8
-
-static pthread_t *threads;
-static pthread_barrier_t init_barrier;
-static int sleep_fd, notify_fd;
-static sem_t sem;
-
-void *thread_func(void *arg)
-{
- struct io_uring ring;
- int res;
-
- res = io_uring_queue_init(IORING_ENTRIES, &ring, 0);
- if (res)
- err(EXIT_FAILURE, "io_uring_queue_init failed");
-
- pthread_barrier_wait(&init_barrier);
-
- for(;;) {
- struct io_uring_cqe *cqe;
- struct io_uring_sqe *sqe;
- uint64_t buf;
- int res;
-
- sqe = io_uring_get_sqe(&ring);
- assert(sqe);
-
- io_uring_prep_read(sqe, sleep_fd, &buf, sizeof(buf), 0);
-
- res = io_uring_submit_and_wait(&ring, 1);
- if (res < 0)
- err(EXIT_FAILURE, "io_uring_submit_and_wait failed");
-
- res = io_uring_peek_cqe(&ring, &cqe);
- assert(!res);
- if (cqe->res < 0) {
- errno = -cqe->res;
- err(EXIT_FAILURE, "read failed");
- }
- assert(cqe->res == sizeof(buf));
-
- sem_post(&sem);
-
- io_uring_cqe_seen(&ring, cqe);
- }
-
- return NULL;
-}
-
-int main(int argc, char *argv[])
-{
- int res, fds[2], i, cpus;
- const uint64_t n = 0x42;
-
- cpus = get_nprocs();
- res = pthread_barrier_init(&init_barrier, NULL, cpus);
- if (res)
- err(EXIT_FAILURE, "pthread_barrier_init failed");
-
- res = sem_init(&sem, 0, 0);
- if (res)
- err(EXIT_FAILURE, "sem_init failed");
-
- threads = t_malloc(sizeof(pthread_t) * cpus);
-
- res = pipe(fds);
- if (res)
- err(EXIT_FAILURE, "pipe failed");
-
- sleep_fd = fds[0];
- notify_fd = fds[1];
-
- for (i = 0; i < cpus; i++) {
- errno = pthread_create(&threads[i], NULL, thread_func, NULL);
- if (errno)
- err(EXIT_FAILURE, "pthread_create failed");
- }
-
- // Write #cpus notifications
- for (i = 0; i < cpus; i++) {
- res = write(notify_fd, &n, sizeof(n));
- if (res < 0)
- err(EXIT_FAILURE, "write failed");
- assert(res == sizeof(n));
- }
-
- // Await that all notifications were received
- for (i = 0; i < cpus; i++)
- sem_wait(&sem);
-
- // Exit without resource cleanup
- exit(EXIT_SUCCESS);
-}
+/* SPDX-License-Identifier: MIT */
+/*
+ * Test case testing exit without cleanup and io-wq work pending or queued.
+ *
+ * From Florian Fischer <florian.fl.fischer@fau.de>
+ * Link: https://lore.kernel.org/io-uring/20211202165606.mqryio4yzubl7ms5@pasture/
+ *
+ */
+#include <assert.h>
+#include <err.h>
+#include <errno.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/sysinfo.h>
+#include <unistd.h>
+
+#include "liburing.h"
+#include "helpers.h"
+
+#define IORING_ENTRIES 8
+
+static pthread_t *threads;
+static pthread_barrier_t init_barrier;
+static int sleep_fd, notify_fd;
+static sem_t sem;
+
+void *thread_func(void *arg)
+{
+ struct io_uring ring;
+ int res;
+
+ res = io_uring_queue_init(IORING_ENTRIES, &ring, 0);
+ if (res)
+ err(EXIT_FAILURE, "io_uring_queue_init failed");
+
+ pthread_barrier_wait(&init_barrier);
+
+ for(;;) {
+ struct io_uring_cqe *cqe;
+ struct io_uring_sqe *sqe;
+ uint64_t buf;
+ int res;
+
+ sqe = io_uring_get_sqe(&ring);
+ assert(sqe);
+
+ io_uring_prep_read(sqe, sleep_fd, &buf, sizeof(buf), 0);
+
+ res = io_uring_submit_and_wait(&ring, 1);
+ if (res < 0)
+ err(EXIT_FAILURE, "io_uring_submit_and_wait failed");
+
+ res = io_uring_peek_cqe(&ring, &cqe);
+ assert(!res);
+ if (cqe->res < 0) {
+ errno = -cqe->res;
+ err(EXIT_FAILURE, "read failed");
+ }
+ assert(cqe->res == sizeof(buf));
+
+ sem_post(&sem);
+
+ io_uring_cqe_seen(&ring, cqe);
+ }
+
+ return NULL;
+}
+
+int main(int argc, char *argv[])
+{
+ int res, fds[2], i, cpus;
+ const uint64_t n = 0x42;
+
+ if (argc > 1)
+ return 0;
+
+ cpus = get_nprocs();
+ res = pthread_barrier_init(&init_barrier, NULL, cpus);
+ if (res)
+ err(EXIT_FAILURE, "pthread_barrier_init failed");
+
+ res = sem_init(&sem, 0, 0);
+ if (res)
+ err(EXIT_FAILURE, "sem_init failed");
+
+ threads = t_malloc(sizeof(pthread_t) * cpus);
+
+ res = pipe(fds);
+ if (res)
+ err(EXIT_FAILURE, "pipe failed");
+
+ sleep_fd = fds[0];
+ notify_fd = fds[1];
+
+ for (i = 0; i < cpus; i++) {
+ errno = pthread_create(&threads[i], NULL, thread_func, NULL);
+ if (errno)
+ err(EXIT_FAILURE, "pthread_create failed");
+ }
+
+ // Write #cpus notifications
+ for (i = 0; i < cpus; i++) {
+ res = write(notify_fd, &n, sizeof(n));
+ if (res < 0)
+ err(EXIT_FAILURE, "write failed");
+ assert(res == sizeof(n));
+ }
+
+ // Await that all notifications were received
+ for (i = 0; i < cpus; i++)
+ sem_wait(&sem);
+
+ // Exit without resource cleanup
+ exit(EXIT_SUCCESS);
+}