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 * fdatasync03
9 *
10 * It basically tests fdatasync() to sync test file data having large dirty
11 * file pages to block device. Also, it tests all supported filesystems on a
12 * test block 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_fdatasync(void)28 static void verify_fdatasync(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(fdatasync(fd));
41
42 if (TST_RET)
43 tst_brk(TFAIL | TTERRNO, "fdatasync(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 data 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_fdatasync,
61 .skip_filesystems = (const char *[]) {
62 "tmpfs",
63 NULL
64 }
65 };
66