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 * sync03 9 * 10 * It basically tests sync() 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 28static void verify_sync(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 sync(); 41 42 written = tst_dev_bytes_written(tst_device->dev); 43 44 SAFE_CLOSE(fd); 45 46 if (written >= FILE_SIZE) 47 tst_res(TPASS, "Test file synced to device"); 48 else 49 tst_res(TFAIL, "Synced %li, expected %i", written, FILE_SIZE); 50} 51 52static struct tst_test test = { 53 .needs_root = 1, 54 .mount_device = 1, 55 .all_filesystems = 1, 56 .skip_filesystems = (const char *[]) { 57 "tmpfs", 58 NULL 59 }, 60 .mntpoint = MNTPOINT, 61 .test_all = verify_sync, 62}; 63