diff mbox series

[v4,6/9] syscalls/fsync: add sync device test-case

Message ID 1550739616-24054-7-git-send-email-sumit.garg@linaro.org
State Accepted
Commit 46e99a3910338d37e3831b9e2505c04a695f9c88
Headers show
Series syscalls: add sync device test-cases | expand

Commit Message

Sumit Garg Feb. 21, 2019, 9 a.m. UTC
fsync04 tests to sync file 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 +
 testcases/kernel/syscalls/fsync/.gitignore |  1 +
 testcases/kernel/syscalls/fsync/fsync04.c  | 60 ++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+)
 create mode 100644 testcases/kernel/syscalls/fsync/fsync04.c
diff mbox series

Patch

diff --git a/runtest/syscalls b/runtest/syscalls
index dba0dee..0d09509 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -347,6 +347,7 @@  fstatfs02_64 fstatfs02_64
 fsync01 fsync01
 fsync02 fsync02
 fsync03 fsync03
+fsync04 fsync04
 
 ftruncate01 ftruncate01
 ftruncate01_64 ftruncate01_64
diff --git a/testcases/kernel/syscalls/fsync/.gitignore b/testcases/kernel/syscalls/fsync/.gitignore
index 3c694a4..4b5ea83 100644
--- a/testcases/kernel/syscalls/fsync/.gitignore
+++ b/testcases/kernel/syscalls/fsync/.gitignore
@@ -1,3 +1,4 @@ 
 /fsync01
 /fsync02
 /fsync03
+/fsync04
diff --git a/testcases/kernel/syscalls/fsync/fsync04.c b/testcases/kernel/syscalls/fsync/fsync04.c
new file mode 100644
index 0000000..4b5b586
--- /dev/null
+++ b/testcases/kernel/syscalls/fsync/fsync04.c
@@ -0,0 +1,60 @@ 
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Linaro Limited. All rights reserved.
+ * Author: Sumit Garg <sumit.garg@linaro.org>
+ */
+
+/*
+ * fsync04
+ *
+ * It basically tests fsync() to sync test file 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"
+
+#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_fsync(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(fsync(fd));
+
+	if (TST_RET)
+		tst_brk(TFAIL | TTERRNO, "fsync(fd) 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 synced to device");
+	else
+		tst_res(TFAIL, "Failed to sync test file to device");
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.mount_device = 1,
+	.all_filesystems = 1,
+	.mntpoint = MNTPOINT,
+	.test_all = verify_fsync,
+};