From patchwork Thu Feb 14 09:51:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 1041945 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="OMfu6DEO"; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 440Wsn0vwYz9sML for ; Thu, 14 Feb 2019 20:53:01 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id CE6D53EA39A for ; Thu, 14 Feb 2019 10:52:57 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [217.194.8.7]) by picard.linux.it (Postfix) with ESMTP id C80143EA399 for ; Thu, 14 Feb 2019 10:52:55 +0100 (CET) Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id EC752200D0F for ; Thu, 14 Feb 2019 10:52:54 +0100 (CET) Received: by mail-pf1-x443.google.com with SMTP id n74so2831988pfi.9 for ; Thu, 14 Feb 2019 01:52:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=N0ap7ZyoeVil1olYl86lya3/f1M8kegGXt9pInCMPes=; b=OMfu6DEOehRPmJrb3nxAku0AkXa/GPKJViEVqZBYZB+HvHxrF9vx/k7fsTzTMKzrpw cS+s7jympzjADVI90qtuotSFFecS+PRgf6GFjy68D76KOAzfvSZspnfkBdh+mYRDbyS5 /Y1g5zHgrafdf1g9/JE1uPGjxccxxtq2ABKgv3BT10YUL3yLmEqgDALmqOo8qn/HwWs2 OxmCYVruNOe+N3tM3pgr9ggzmmQsEL5B9aBXYh0vLa1WiqIdq6aTJe8okh0mkmQ19jx9 +6RUkrGipabKCF+LDA+Z2a/ArhxMwRj3ixdMja02pTg7l06j9ZfwOws7lNJXwOpe+Mns btdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=N0ap7ZyoeVil1olYl86lya3/f1M8kegGXt9pInCMPes=; b=Cn7pb93mMjTp5TLtZpJVtYfORP+kq6l0q41EkDW1uHb264B9KuAaN46Vqc40qyw/27 WL/7phDdR7SCvxgzgXtNOs2+WQ+JtCVKVlHcCqD0FdYOAs3yshDuho+aEbGPZA93xRhN JOcpU01lT41A7NJv0PVJzlt7gnr0YuyvjYKO/72NqVgulW7W5xvtKG12jj2PsI3o8WeJ M7Uj03Vu1rInPKp/6+5NADDjKD/Dki8AMrWGrGMYrIk2vpn8sW3wdIPUMZnUP4/Lm98M cMvn9bJhx0yc0mwbMffFgPk7SH88xKuXYxBLt5KP4uAMM1gpPqp61onUGaUMAYrVdg+p hBKA== X-Gm-Message-State: AHQUAubgWTZ01YrfBAUvdWCqQ2/UBMl+s1thztKyOP5i6nDGVQ/uPtFm 7vuQzrToWEgVMekYwXdQgObuIHrQ1+SdsA== X-Google-Smtp-Source: AHgI3IZ9mlyma+zc5z4CvbIKG7Z1LDhgDWAqYax03ltyFBs5ZiuNi7MezwpHLFzBgHy3zbrmT/AOnA== X-Received: by 2002:a65:6392:: with SMTP id h18mr2933297pgv.107.1550137973090; Thu, 14 Feb 2019 01:52:53 -0800 (PST) Received: from localhost.localdomain ([117.252.65.21]) by smtp.gmail.com with ESMTPSA id k71sm5144314pga.44.2019.02.14.01.52.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 14 Feb 2019 01:52:52 -0800 (PST) From: Sumit Garg To: ltp@lists.linux.it Date: Thu, 14 Feb 2019 15:21:31 +0530 Message-Id: <1550137891-19991-1-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 X-Virus-Scanned: clamav-milter 0.99.2 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-7.smtp.seeweb.it Cc: daniel.thompson@linaro.org Subject: [LTP] [PATCH] syscalls: add syscall syncfs test X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" syncfs01 tests to sync filesystem having large dirty file pages to block device. Also, it tests all supported filesystems on a test block device. Signed-off-by: Sumit Garg --- Fixes: https://github.com/linux-test-project/ltp/issues/294 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 diff --git a/runtest/syscalls b/runtest/syscalls index 668c87c..9442740 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1346,6 +1346,8 @@ symlinkat01 symlinkat01 sync01 sync01 sync02 sync02 +syncfs01 syncfs01 + #testcases for sync_file_range sync_file_range01 sync_file_range01 diff --git a/testcases/kernel/syscalls/syncfs/.gitignore b/testcases/kernel/syscalls/syncfs/.gitignore new file mode 100644 index 0000000..6066295 --- /dev/null +++ b/testcases/kernel/syscalls/syncfs/.gitignore @@ -0,0 +1 @@ +syncfs01 diff --git a/testcases/kernel/syscalls/syncfs/Makefile b/testcases/kernel/syscalls/syncfs/Makefile new file mode 100644 index 0000000..3e6c2f4 --- /dev/null +++ b/testcases/kernel/syscalls/syncfs/Makefile @@ -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 diff --git a/testcases/kernel/syscalls/syncfs/syncfs01.c b/testcases/kernel/syscalls/syncfs/syncfs01.c new file mode 100644 index 0000000..35a8ae8 --- /dev/null +++ b/testcases/kernel/syscalls/syncfs/syncfs01.c @@ -0,0 +1,110 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 Linaro Limited. All rights reserved. + * Author: Sumit Garg + */ + +/* + * 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. + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#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); +} + +static void setup(void) +{ + const char *dev; + struct stat st; + + dev = tst_device->dev; + if (!dev) + tst_brk(TCONF, "Failed to acquire test device"); + + snprintf(dev_stat_path, sizeof(dev_stat_path), "/sys/block/%s/stat", + strrchr(dev, '/') + 1); + + 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); + + if (fd > 0) + SAFE_CLOSE(fd); +} + +static struct tst_test test = { + .needs_root = 1, + .needs_device = 1, + .format_device = 1, + .mount_device = 1, + .all_filesystems = 1, + .dev_min_size = TST_FILE_SIZE_MB, + .mntpoint = MNTPOINT, + .setup = setup, + .cleanup = cleanup, + .test_all = verify_syncfs, +};