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