• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2019 Linaro Limited. All rights reserved.
4  * Author: Sumit Garg <sumit.garg@linaro.org>
5  */
6 
7 /*
8  * fsync04
9  *
10  * It basically tests fsync() to sync test file having large dirty file pages
11  * to block device. Also, it tests all supported filesystems on a test block
12  * device.
13  */
14 
15 #define _GNU_SOURCE
16 #include <errno.h>
17 #include <stdlib.h>
18 #include <stdio.h>
19 #include <sys/types.h>
20 #include "tst_test.h"
21 
22 #define MNTPOINT	"mnt_point"
23 #define FNAME		MNTPOINT"/test"
24 #define FILE_SIZE_MB	32
25 #define FILE_SIZE	(FILE_SIZE_MB * TST_MB)
26 #define MODE		0644
27 
verify_fsync(void)28 static void verify_fsync(void)
29 {
30 	int fd;
31 	unsigned long written;
32 
33 	fd = SAFE_OPEN(FNAME, O_RDWR|O_CREAT, MODE);
34 
35 	tst_dev_sync(fd);
36 	tst_dev_bytes_written(tst_device->dev);
37 
38 	tst_fill_fd(fd, 0, TST_MB, FILE_SIZE_MB);
39 
40 	TEST(fsync(fd));
41 
42 	if (TST_RET)
43 		tst_brk(TFAIL | TTERRNO, "fsync(fd) failed");
44 
45 	written = tst_dev_bytes_written(tst_device->dev);
46 
47 	SAFE_CLOSE(fd);
48 
49 	if (written >= FILE_SIZE)
50 		tst_res(TPASS, "Test file synced to device");
51 	else
52 		tst_res(TFAIL, "Synced %li, expected %i", written, FILE_SIZE);
53 }
54 
55 static struct tst_test test = {
56 	.needs_root = 1,
57 	.mount_device = 1,
58 	.all_filesystems = 1,
59 	.mntpoint = MNTPOINT,
60 	.test_all = verify_fsync,
61 };
62