Skip to contentSkip to conversation

syscalls: add syscall syncfs test

PATCH New Sumit Garg 2 participants 3 messages Feb 14, 2019

lore
Share & tools
lore

Sumit Garg

author
#0 lore raw

PATCH 1/1 syscalls: add syscall syncfs test

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

---

 runtest/syscalls                            |   2 +
 testcases/kernel/syscalls/syncfs/.gitignore |   1 +
 testcases/kernel/syscalls/syncfs/Makefile   |   8 ++
 testcases/kernel/syscalls/syncfs/syncfs01.c | 110 ++++++++++++++++++++++++++++
 4 files changed, 121 insertions(+)
 create mode 100644 testcases/kernel/syscalls/syncfs/.gitignore
 create mode 100644 testcases/kernel/syscalls/syncfs/Makefile
 create mode 100644 testcases/kernel/syscalls/syncfs/syncfs01.c
runtest/syscalls +2 -0
index 668c87c..9442740 100644
@@ -1346,6 +1346,8 @@ symlinkat01 symlinkat01
 sync01 sync01
 sync02 sync02
 
+syncfs01 syncfs01
+
 #testcases for sync_file_range
 sync_file_range01 sync_file_range01
 
testcases/kernel/syscalls/syncfs/.gitignore new file +1 -0
new file mode 100644
index 0000000..6066295
@@ -0,0 +1 @@
+syncfs01
testcases/kernel/syscalls/syncfs/Makefile new file +8 -0
new file mode 100644
index 0000000..3e6c2f4
@@ -0,0 +1,8 @@
+# Copyright (c) 2019 - Linaro Limited. All rights reserved.
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+top_srcdir             ?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/syncfs/syncfs01.c new file +110 -0

110 lines not on this page · raw message

Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/1 syscalls: add syscall syncfs test

Hi Sumit,

Quoted 66 lines · Sumit Garg

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

---

  runtest/syscalls                            |   2 +
  testcases/kernel/syscalls/syncfs/.gitignore |   1 +
  testcases/kernel/syscalls/syncfs/Makefile   |   8 ++
  testcases/kernel/syscalls/syncfs/syncfs01.c | 110 ++++++++++++++++++++++++++++
  4 files changed, 121 insertions(+)

create mode 100644 testcases/kernel/syscalls/syncfs/.gitignore create mode 100644 testcases/kernel/syscalls/syncfs/Makefile create mode 100644 testcases/kernel/syscalls/syncfs/syncfs01.c

runtest/syscalls +2 -0
index 668c87c..9442740 100644
@@ -1346,6 +1346,8 @@ symlinkat01 symlinkat01
  sync01 sync01
  sync02 sync02
 
+syncfs01 syncfs01
+
  #testcases for sync_file_range
  sync_file_range01 sync_file_range01
 
testcases/kernel/syscalls/syncfs/.gitignore new file +1 -0
new file mode 100644
index 0000000..6066295
@@ -0,0 +1 @@
+syncfs01
testcases/kernel/syscalls/syncfs/Makefile new file +8 -0
new file mode 100644
index 0000000..3e6c2f4
@@ -0,0 +1,8 @@
+# Copyright (c) 2019 - Linaro Limited. All rights reserved.
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+top_srcdir             ?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/syncfs/syncfs01.c new file +9 -0
new file mode 100644
index 0000000..35a8ae8
@@ -0,0 +1,110 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Linaro Limited. All rights reserved.
+ * Author: Sumit Garg<[email protected]>
+ */
+
+/*
+ * Test syncfs
+ *

testcases/kernel/syscalls/syncfs/syncfs01.c line 19

Quoted 10 lines
testcases/kernel/syscalls/syncfs/syncfs01.c new file +10 -0
+ * It basically tests syncfs() to sync filesystem having large dirty file
+ * pages to block device. Also, it tests all supported filesystems on a test
+ * block device.
+ */
+
+#define _GNU_SOURCE
+#include<stdlib.h>
+#include<stdio.h>
+#include<sys/types.h>
+#include<sys/wait.h>

Unused <sys/wait.h> ?

Quoted 47 lines
testcases/kernel/syscalls/syncfs/syncfs01.c new file +47 -0
+#include "tst_test.h"
+#include "lapi/fs.h"
+#include "lapi/stat.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 char dev_stat_path[1024];
+static char *buffer;
+static int fd;
+
+static void verify_syncfs(void)
+{
+	char nwrite_sec_val[BUFSIZ];
+	int counter;
+	unsigned long prev_write_sec = 0, write_sec = 0;
+
+	SAFE_FILE_SCANF(dev_stat_path, "%*s %*s %*s %*s %*s %*s %s",
+			nwrite_sec_val);
+
+	prev_write_sec = SAFE_STRTOUL(nwrite_sec_val, 0, ULONG_MAX);
+
+	fd =  SAFE_OPEN(TST_FILE, O_RDWR|O_CREAT, MODE);
+
+	/* Filling the test file */
+	for (counter = 0; counter<  TST_FILE_SIZE_MB; counter++)
+		SAFE_WRITE(1, fd, buffer, SIZE_MB);
+
+	TEST(syncfs(fd));
+	if (TST_RET != 0)
+		tst_brk(TFAIL | TTERRNO, "syncfs(fd) failed");
+
+	SAFE_FILE_SCANF(dev_stat_path, "%*s %*s %*s %*s %*s %*s %s",
+			nwrite_sec_val);
+
+	write_sec = SAFE_STRTOUL(nwrite_sec_val, 0, ULONG_MAX);
+
+	if ((write_sec - prev_write_sec) * 512>=
+	    (TST_FILE_SIZE_MB * SIZE_MB))
+		tst_res(TPASS, "Test filesystem synced to device");
+	else
+		tst_res(TFAIL, "Failed to sync test filesystem to device");
+
+	SAFE_CLOSE(fd);

testcases/kernel/syscalls/syncfs/syncfs01.c line 76

Quoted 10 lines
testcases/kernel/syscalls/syncfs/syncfs01.c new file +10 -0
+}
+
+static void setup(void)
+{
+	const char *dev;
+	struct stat st;
+
+	dev = tst_device->dev;
+	if (!dev)
+		tst_brk(TCONF, "Failed to acquire test device");

Libary will do this check, so we can remove it.
Please see the following code at tst_test.c:
--------------------------------------------------------------------------

     if (tst_test->needs_device && !mntpoint_mounted) {
         tdev.dev = tst_acquire_device_(NULL, tst_test->dev_min_size);

         if (!tdev.dev)
             tst_brk(TCONF, "Failed to acquire device");

--------------------------------------------------------------------------

testcases/kernel/syscalls/syncfs/syncfs01.c line 79

Quoted 3 lines
testcases/kernel/syscalls/syncfs/syncfs01.c new file +3 -0
+
+	snprintf(dev_stat_path, sizeof(dev_stat_path), "/sys/block/%s/stat",
+		 strrchr(dev, '/') + 1);

Use tst_device->dev directly.

Quoted 14 lines
testcases/kernel/syscalls/syncfs/syncfs01.c new file +14 -0
+
+	if (stat(dev_stat_path,&st) != 0)
+		tst_brk(TCONF, "Test device stat file: %s not found",
+			dev_stat_path);
+
+	buffer = SAFE_MALLOC(SIZE_MB);
+
+	memset(buffer, 0, SIZE_MB);
+}
+
+static void cleanup(void)
+{
+	if (buffer)
+		free(buffer);

testcases/kernel/syscalls/syncfs/syncfs01.c line 103

Quoted 10 lines
testcases/kernel/syscalls/syncfs/syncfs01.c new file +10 -0
+
+	if (fd>  0)
+		SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_device = 1,
+	.format_device = 1,
+	.mount_device = 1,

It is enough to only set '.mount_device', because '.mount_device' implies '.needs_device' and '.format_device'
Please see doc/test-writing-guidelines.txt:
------------------------------------------
If '.mount_device' is set, the device is mounted at '.mntpoint' which is used
to pass a directory name that will be created and used as mount destination. You can pass additional flags and data to the mount command via '.mnt_flags' and '.mnt_data' pointers. Note that '.mount_device' implies '.needs_device' and '.format_device' so there is no need to set the later two.
------------------------------------------

testcases/kernel/syscalls/syncfs/syncfs01.c line 105

Quoted 2 lines
testcases/kernel/syscalls/syncfs/syncfs01.c new file +2 -0
+	.all_filesystems = 1,
+	.dev_min_size = TST_FILE_SIZE_MB,

It seems that libary sets the minimal device size to 256M by default, so the smaller value will be replaced with 256M.
Do we have to set the minimal device size to 32M?

Best Regards,
Xiao Yang

Quoted 5 lines
testcases/kernel/syscalls/syncfs/syncfs01.c new file +5 -0
+	.mntpoint = MNTPOINT,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_syncfs,
+};
author
#2 lore raw

PATCH 1/1 syscalls: add syscall syncfs test

Hi Xiao,

Thanks for your review comments.

Quoted 74 lines · Xiao Yang

Hi Sumit,

Quoted 70 lines · Sumit Garg

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

---

  runtest/syscalls                            |   2 +
  testcases/kernel/syscalls/syncfs/.gitignore |   1 +
  testcases/kernel/syscalls/syncfs/Makefile   |   8 ++
  testcases/kernel/syscalls/syncfs/syncfs01.c | 110 ++++++++++++++++++++++++++++
  4 files changed, 121 insertions(+)

create mode 100644 testcases/kernel/syscalls/syncfs/.gitignore create mode 100644 testcases/kernel/syscalls/syncfs/Makefile create mode 100644 testcases/kernel/syscalls/syncfs/syncfs01.c

runtest/syscalls +2 -0
index 668c87c..9442740 100644
@@ -1346,6 +1346,8 @@ symlinkat01 symlinkat01
  sync01 sync01
  sync02 sync02
 
+syncfs01 syncfs01
+
  #testcases for sync_file_range
  sync_file_range01 sync_file_range01
 
testcases/kernel/syscalls/syncfs/.gitignore new file +1 -0
new file mode 100644
index 0000000..6066295
@@ -0,0 +1 @@
+syncfs01
testcases/kernel/syscalls/syncfs/Makefile new file +8 -0
new file mode 100644
index 0000000..3e6c2f4
@@ -0,0 +1,8 @@
+# Copyright (c) 2019 - Linaro Limited. All rights reserved.
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+top_srcdir             ?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/syncfs/syncfs01.c new file +13 -0
new file mode 100644
index 0000000..35a8ae8
@@ -0,0 +1,110 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Linaro Limited. All rights reserved.
+ * Author: Sumit Garg<[email protected]>
+ */
+
+/*
+ * Test syncfs
+ *
+ * It basically tests syncfs() to sync filesystem having large dirty file
+ * pages to block device. Also, it tests all supported filesystems on a test
+ * block device.
+ */
Quoted 9 lines

testcases/kernel/syscalls/syncfs/syncfs01.c line 19

Quoted 6 lines
testcases/kernel/syscalls/syncfs/syncfs01.c new file +6 -0
+
+#define _GNU_SOURCE
+#include<stdlib.h>
+#include<stdio.h>
+#include<sys/types.h>
+#include<sys/wait.h>

Unused <sys/wait.h> ?

Ok, will remove it.

Quoted 61 lines
Quoted 47 lines
testcases/kernel/syscalls/syncfs/syncfs01.c new file +47 -0
+#include "tst_test.h"
+#include "lapi/fs.h"
+#include "lapi/stat.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 char dev_stat_path[1024];
+static char *buffer;
+static int fd;
+
+static void verify_syncfs(void)
+{
+     char nwrite_sec_val[BUFSIZ];
+     int counter;
+     unsigned long prev_write_sec = 0, write_sec = 0;
+
+     SAFE_FILE_SCANF(dev_stat_path, "%*s %*s %*s %*s %*s %*s %s",
+                     nwrite_sec_val);
+
+     prev_write_sec = SAFE_STRTOUL(nwrite_sec_val, 0, ULONG_MAX);
+
+     fd =  SAFE_OPEN(TST_FILE, O_RDWR|O_CREAT, MODE);
+
+     /* Filling the test file */
+     for (counter = 0; counter<  TST_FILE_SIZE_MB; counter++)
+             SAFE_WRITE(1, fd, buffer, SIZE_MB);
+
+     TEST(syncfs(fd));
+     if (TST_RET != 0)
+             tst_brk(TFAIL | TTERRNO, "syncfs(fd) failed");
+
+     SAFE_FILE_SCANF(dev_stat_path, "%*s %*s %*s %*s %*s %*s %s",
+                     nwrite_sec_val);
+
+     write_sec = SAFE_STRTOUL(nwrite_sec_val, 0, ULONG_MAX);
+
+     if ((write_sec - prev_write_sec) * 512>=
+         (TST_FILE_SIZE_MB * SIZE_MB))
+             tst_res(TPASS, "Test filesystem synced to device");
+     else
+             tst_res(TFAIL, "Failed to sync test filesystem to device");
+
+     SAFE_CLOSE(fd);

testcases/kernel/syscalls/syncfs/syncfs01.c line 76

Quoted 10 lines
testcases/kernel/syscalls/syncfs/syncfs01.c new file +10 -0
+}
+
+static void setup(void)
+{
+     const char *dev;
+     struct stat st;
+
+     dev = tst_device->dev;
+     if (!dev)
+             tst_brk(TCONF, "Failed to acquire test device");

Libary will do this check, so we can remove it.
Please see the following code at tst_test.c:
--------------------------------------------------------------------------

Quoted 7 lines
     if (tst_test->needs_device && !mntpoint_mounted) {
         tdev.dev = tst_acquire_device_(NULL, tst_test->dev_min_size);

         if (!tdev.dev)
             tst_brk(TCONF, "Failed to acquire device");

--------------------------------------------------------------------------

Ok will remove this check.

Quoted 6 lines

testcases/kernel/syscalls/syncfs/syncfs01.c line 79

Quoted 3 lines
testcases/kernel/syscalls/syncfs/syncfs01.c new file +3 -0
+
+     snprintf(dev_stat_path, sizeof(dev_stat_path), "/sys/block/%s/stat",
+              strrchr(dev, '/') + 1);

Use tst_device->dev directly.

Ok.

Quoted 28 lines
Quoted 14 lines
testcases/kernel/syscalls/syncfs/syncfs01.c new file +14 -0
+
+     if (stat(dev_stat_path,&st) != 0)
+             tst_brk(TCONF, "Test device stat file: %s not found",
+                     dev_stat_path);
+
+     buffer = SAFE_MALLOC(SIZE_MB);
+
+     memset(buffer, 0, SIZE_MB);
+}
+
+static void cleanup(void)
+{
+     if (buffer)
+             free(buffer);

testcases/kernel/syscalls/syncfs/syncfs01.c line 103

Quoted 10 lines
testcases/kernel/syscalls/syncfs/syncfs01.c new file +10 -0
+
+     if (fd>  0)
+             SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+     .needs_root = 1,
+     .needs_device = 1,
+     .format_device = 1,
+     .mount_device = 1,

It is enough to only set '.mount_device', because '.mount_device' implies '.needs_device' and '.format_device'
Please see doc/test-writing-guidelines.txt:

Quoted 8 lines

------------------------------------------
If '.mount_device' is set, the device is mounted at '.mntpoint' which is used
to pass a directory name that will be created and used as mount destination. You can pass additional flags and data to the mount command via '.mnt_flags' and '.mnt_data' pointers. Note that '.mount_device' implies '.needs_device' and '.format_device' so there is no need to set the later two.
------------------------------------------

Yeah I missed this. Will remove .needs_device and .format_device flags.

Quoted 6 lines

testcases/kernel/syscalls/syncfs/syncfs01.c line 105

Quoted 2 lines
testcases/kernel/syscalls/syncfs/syncfs01.c new file +2 -0
+     .all_filesystems = 1,
+     .dev_min_size = TST_FILE_SIZE_MB,

It seems that libary sets the minimal device size to 256M by default, so the smaller value will be replaced with 256M.
Do we have to set the minimal device size to 32M?

Yes I saw minimal default size to be 256M. I kept 32M here just for clarity of minimal requirement for this test case. BTW, if you think it is unnecessary to keep it then I will remove it.

-Sumit

Quoted 10 lines

Best Regards,
Xiao Yang

Quoted 5 lines
testcases/kernel/syscalls/syncfs/syncfs01.c new file +5 -0
+     .mntpoint = MNTPOINT,
+     .setup = setup,
+     .cleanup = cleanup,
+     .test_all = verify_syncfs,
+};