From patchwork Fri Feb 15 07:17:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 158483 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp386724jaa; Thu, 14 Feb 2019 23:18:00 -0800 (PST) X-Google-Smtp-Source: AHgI3IbW+a+do8uxIxDtZJWkBTzQ29Zgzc/m+dB3rCAh1W345Ny7Kn9iyX2yR9Ro9nN+BmwCRnai X-Received: by 2002:adf:fc51:: with SMTP id e17mr5498940wrs.268.1550215079963; Thu, 14 Feb 2019 23:17:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550215079; cv=none; d=google.com; s=arc-20160816; b=JQnAdmRp8aYtY+lp1Lc6T4CARgIeuv22e6QOHinJQfF6vpM0u2YIKvl6CfzsBhobVK gimG04lcquipr3+W0hkzjzEX0sM4e6Bodd8+exfv4C2HMebnlTha8imrbIPbTJefCWeA RjPCMvxQbCy1Gun70ZqXY4tb6SXYUhhcFQQvurb1LO3czyvQRyvfOnPJqePJwDqu8hWs bRjPi/7GAcGo+u5NjLS/hS8y8rIHXOQ7dudYUPqwGIX4Jsjk09ffT7T3YLwmzxZJps+j edH2iDwpOhFngWjxFZ6OltX9gb2dY4FWHibdh9tvAhOrSAb2XVMTMvVD9akGDTUvSrAk 2CuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:message-id:date:to:from :dkim-signature:delivered-to; bh=T1NMKuqUjBlbvW+G/YaPnSgifnsx+4YLI3CPCznbczI=; b=cAdzLdTciRE2aru7nL2HoR8TOnODGawo8SD31+sJ5N3qTagXW3KYx04H2yDAPN6jlo fnNpcki5h759cQPbFT1tTXYeUs/p2iMb5B6Vt7D2B4MAZb2Tfmvzgr/RRz81D7Z5mKMy lFI4j6Fjwx+dZGP+BteYSTLZg84vOVYC+XgqMX1NkoXMOEurtPtc+KIst5VHYdPsyJuy ZG3zwR6KknQlOlUPxGtogPsaimZjdLu+ugSW6puXwnmBUNv6FDYei5REe/kQBwfUo/BC GSHI8PkXlCFT7jukr1dH5czidN90Agz9YMyqNI/uZ1jOJBklGPrKwCcdZL81tMw/f10e NIXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Zdmx2J2J; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 2001:1418:10:5::2 as permitted sender) smtp.mailfrom="ltp-bounces+patch=linaro.org@lists.linux.it"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from picard.linux.it (picard.linux.it. [2001:1418:10:5::2]) by mx.google.com with ESMTPS id r8si3220913wrm.10.2019.02.14.23.17.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Feb 2019 23:17:59 -0800 (PST) Received-SPF: pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 2001:1418:10:5::2 as permitted sender) client-ip=2001:1418:10:5::2; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Zdmx2J2J; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 2001:1418:10:5::2 as permitted sender) smtp.mailfrom="ltp-bounces+patch=linaro.org@lists.linux.it"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 76C683EA897 for ; Fri, 15 Feb 2019 08:17:59 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [IPv6:2001:4b78:1:20::6]) by picard.linux.it (Postfix) with ESMTP id D19443EA7D6 for ; Fri, 15 Feb 2019 08:17:54 +0100 (CET) Received: from mail-yb1-xb44.google.com (mail-yb1-xb44.google.com [IPv6:2607:f8b0:4864:20::b44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id D4653141761A for ; Fri, 15 Feb 2019 08:17:53 +0100 (CET) Received: by mail-yb1-xb44.google.com with SMTP id s5so3429945ybp.6 for ; Thu, 14 Feb 2019 23:17:53 -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=CeJ3PVAIAjWeIFMMI5mnjyxmTCO1op/32JtyMgBgh/w=; b=Zdmx2J2Jt8udldOvO2pYMnCVSnm8CcB1PDR41ZFiDT+l8/7edg3musu+hMQuy799UG pwC0m5OPLZ1YNBlOIIotPM281uk0h8OVS0nmWlWWPxvK5Og+xPwNBT1WeBJwlLalG56X NGgIaAEIzCRuHZCaIgsFAoAJkRclPm3Q18tMtDX/o6DAb6lsfFKFdwCn2c8/VqEdkZ5V 81dhIvr8I2VIn6Q8mrdxE1gCigseFGXO7MhQaV008Sz3tomAEWn9EuKvoquTcjjypK74 bFI23N86Kupr93Saf/7TPeyvDS+mWClpda1q1npuOkGcUAPzXO/uxaRBrBSunj/m3bGl BDAA== 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=CeJ3PVAIAjWeIFMMI5mnjyxmTCO1op/32JtyMgBgh/w=; b=GILyrT/Sr4toJwDH2LWXG266o79fJxSIUKAKieynfvTCNNjvKYBu3EFVxc/s5TFkUA URnsm+q7TCEh3tYjskiuzCYtXZOrSFrqKOuIUok33/ZVeMfMdAIOd2e2L/FfjOhitTl3 dAuRW2E4kY8GfNIeaKyBYXvM/ouGQ6QblBqeEZ3W2gfRQHftBkUZx+ZsXtK5JZGtFa9q HOOTSui/a4BkiKRKLC5gk+y0XqYiK+crf/tkgbJiI3aNWZOFif/f/h5ZZJsYy11kJZUh U9d+otuUW5HLozFlihCAFZgaZId2GHQLLICWpqTWztXChdgRd1VnDcrrmsUR4K3457l+ t7lQ== X-Gm-Message-State: AHQUAub2e28e4dxV1KNk4exo6+u5ASz2V376OCH/ZP9vhDBqEnFx3GdI HJe+jZ5uDWHP0gvk6k8JJUHHQkloUBPTQg== X-Received: by 2002:a25:5582:: with SMTP id j124mr6771588ybb.2.1550215072211; Thu, 14 Feb 2019 23:17:52 -0800 (PST) Received: from localhost.localdomain ([117.252.69.94]) by smtp.gmail.com with ESMTPSA id 21sm2177146ywg.55.2019.02.14.23.17.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 14 Feb 2019 23:17:51 -0800 (PST) From: Sumit Garg To: ltp@lists.linux.it Date: Fri, 15 Feb 2019 12:47:33 +0530 Message-Id: <1550215053-6795-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-6.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-6.smtp.seeweb.it Cc: daniel.thompson@linaro.org Subject: [LTP] [PATCH v2] 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+patch=linaro.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 --- Changes in v2: 1. Remove unused header file include. 2. Remove redundant tst_device check. 3. Remove redundant flags from tst_test struct. 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 | 101 ++++++++++++++++++++++++++++ 4 files changed, 112 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..e2d3e80 --- /dev/null +++ b/testcases/kernel/syscalls/syncfs/syncfs01.c @@ -0,0 +1,101 @@ +// 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 "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) +{ + struct stat st; + + snprintf(dev_stat_path, sizeof(dev_stat_path), "/sys/block/%s/stat", + strrchr(tst_device->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, + .mount_device = 1, + .all_filesystems = 1, + .mntpoint = MNTPOINT, + .setup = setup, + .cleanup = cleanup, + .test_all = verify_syncfs, +};