[LTP] [PATCH v4 9/9] syscalls/sync_file_range: add sync device test-case

Sumit Garg
2019-02-21T09:00:16Z

sync_file_range02 tests to sync file data range having large dirty file
pages to block device. Also, it tests all supported filesystems on a
test block device.

Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
---
runtest/syscalls | 1 +
.../kernel/syscalls/sync_file_range/.gitignore | 1 +
.../syscalls/sync_file_range/sync_file_range02.c | 72 ++++++++++++++++++++++
3 files changed, 74 insertions(+)
create mode 100644 testcases/kernel/syscalls/sync_file_range/sync_file_range02.c

diff --git a/runtest/syscalls b/runtest/syscalls
index aaad651..70d3561 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1353,6 +1353,7 @@ syncfs01 syncfs01

#testcases for sync_file_range
sync_file_range01 sync_file_range01
+sync_file_range02 sync_file_range02

syscall01 syscall01

diff --git a/testcases/kernel/syscalls/sync_file_range/.gitignore b/testcases/kernel/syscalls/sync_file_range/.gitignore
index 3f6bd75..e6485f7 100644
--- a/testcases/kernel/syscalls/sync_file_range/.gitignore
+++ b/testcases/kernel/syscalls/sync_file_range/.gitignore
@@ -1 +1,2 @@
/sync_file_range01
+/sync_file_range02
diff --git a/testcases/kernel/syscalls/sync_file_range/sync_file_range02.c b/testcases/kernel/syscalls/sync_file_range/sync_file_range02.c
new file mode 100644
index 0000000..37ea68a
--- /dev/null
+++ b/testcases/kernel/syscalls/sync_file_range/sync_file_range02.c
@@ -0,0 +1,72 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Linaro Limited. All rights reserved.
+ * Author: Sumit Garg <sumit.garg@linaro.org>
+ */
+
+/*
+ * sync_file_range02
+ *
+ * It basically tests sync_file_range() to sync test file range having large
+ * dirty file pages to block device. Also, it tests all supported filesystems
+ * on a test block device.
+ */
+
+#define _GNU_SOURCE
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include "tst_test.h"
+#include "lapi/sync_file_range.h"
+#include "check_sync_file_range.h"
+
+#define MNTPOINT "mnt_point"
+#define TST_FILE MNTPOINT"/test"
+#define TST_FILE_SIZE_MB 32
+#define SIZE_MB (1024*1024)
+#define MODE 0644
+
+static void verify_sync_file_range(void)
+{
+ int fd;
+ unsigned long written;
+
+ fd = SAFE_OPEN(TST_FILE, O_RDWR|O_CREAT, MODE);
+
+ tst_dev_bytes_written(tst_device->dev);
+
+ tst_fill_fd(fd, 0, SIZE_MB, TST_FILE_SIZE_MB);
+
+ TEST(sync_file_range(fd, 0, TST_FILE_SIZE_MB * SIZE_MB,
+ SYNC_FILE_RANGE_WAIT_BEFORE |
+ SYNC_FILE_RANGE_WRITE |
+ SYNC_FILE_RANGE_WAIT_AFTER));
+
+ if (TST_RET)
+ tst_brk(TFAIL | TTERRNO, "sync_file_range() failed");
+
+ written = tst_dev_bytes_written(tst_device->dev);
+
+ SAFE_CLOSE(fd);
+
+ if (written >= SIZE_MB * TST_FILE_SIZE_MB)
+ tst_res(TPASS, "Test file range synced to device");
+ else
+ tst_res(TFAIL, "Failed to sync test file range to device");
+}
+
+static void setup(void)
+{
+ if (!check_sync_file_range())
+ tst_brk(TCONF, "sync_file_range() not supported");
+}
+
+static struct tst_test test = {
+ .needs_root = 1,
+ .mount_device = 1,
+ .all_filesystems = 1,
+ .mntpoint = MNTPOINT,
+ .setup = setup,
+ .test_all = verify_sync_file_range,
+};
--
2.7.4