public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH liburing] test/sfr: basic test for sync_file_range
@ 2020-05-01 14:38 Pavel Begunkov
  2020-05-01 14:49 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Pavel Begunkov @ 2020-05-01 14:38 UTC (permalink / raw)
  To: Jens Axboe, io-uring, linux-kernel

Just call it and check that it doesn't hang and returns success.

Signed-off-by: Pavel Begunkov <[email protected]>
---
 test/fsync.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)

diff --git a/test/fsync.c b/test/fsync.c
index 839716a..ee60e0f 100644
--- a/test/fsync.c
+++ b/test/fsync.c
@@ -135,6 +135,79 @@ err:
 	return 1;
 }
 
+#define FILE_SIZE 1024
+
+static int create_file(const char *file)
+{
+	ssize_t ret;
+	char *buf;
+	int fd;
+
+	buf = malloc(FILE_SIZE);
+	memset(buf, 0xaa, FILE_SIZE);
+
+	fd = open(file, O_WRONLY | O_CREAT, 0644);
+	if (fd < 0) {
+		perror("open file");
+		return 1;
+	}
+	ret = write(fd, buf, FILE_SIZE);
+	close(fd);
+	return ret != FILE_SIZE;
+}
+
+static int test_sync_file_range(struct io_uring *ring)
+{
+	int ret, fd, save_errno;
+	struct io_uring_sqe *sqe;
+	struct io_uring_cqe *cqe;
+
+	if (create_file(".sync_file_range")) {
+		fprintf(stderr, "file creation failed\n");
+		return 1;
+	}
+
+	fd = open(".sync_file_range", O_RDWR);
+	save_errno = errno;
+	unlink(".sync_file_range");
+	errno = save_errno;
+	if (fd < 0) {
+		perror("file open");
+		return 1;
+	}
+
+	sqe = io_uring_get_sqe(ring);
+	if (!sqe) {
+		fprintf(stderr, "sqe get failed\n");
+		return 1;
+	}
+	memset(sqe, 0, sizeof(*sqe));
+	sqe->opcode = IORING_OP_SYNC_FILE_RANGE;
+	sqe->off = 0;
+	sqe->len = 0;
+	sqe->sync_range_flags = 0;
+	sqe->user_data = 1;
+	sqe->fd = fd;
+
+	ret = io_uring_submit(ring);
+	if (ret != 1) {
+		fprintf(stderr, "submit failed: %d\n", ret);
+		return 1;
+	}
+	ret = io_uring_wait_cqe(ring, &cqe);
+	if (ret) {
+		fprintf(stderr, "wait_cqe failed: %d\n", ret);
+		return 1;
+	}
+	if (cqe->res) {
+		fprintf(stderr, "sfr failed: %d\n", cqe->res);
+		return 1;
+	}
+
+	io_uring_cqe_seen(ring, cqe);
+	return 0;
+}
+
 int main(int argc, char *argv[])
 {
 	struct io_uring ring;
@@ -159,5 +232,11 @@ int main(int argc, char *argv[])
 		return ret;
 	}
 
+	ret = test_sync_file_range(&ring);
+	if (ret) {
+		fprintf(stderr, "test_sync_file_range failed\n");
+		return ret;
+	}
+
 	return 0;
 }
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-05-01 14:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-01 14:38 [PATCH liburing] test/sfr: basic test for sync_file_range Pavel Begunkov
2020-05-01 14:49 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox