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: 158330 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1142375jaa; Thu, 14 Feb 2019 01:53:00 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib3hPIOBoCb+rhngRDNu3WFzhywVvsQXzRQ1r/8+oluikM0QyB/p6DhfDWyfPkvfowQpWZZ X-Received: by 2002:a1c:9810:: with SMTP id a16mr1960102wme.37.1550137980364; Thu, 14 Feb 2019 01:53:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550137980; cv=none; d=google.com; s=arc-20160816; b=Zv1wrAvK8deFliAgeUdDzIazIxeyGCecWonqxZoycN8Siq/xa1+IhRiVme/PGlzxsd BPl5+fLbdXJBl5cRngZxtY+3fMPM/VYLFnKYbWj1OHdcQ0RtCowVdF9sYSjyRz+8GDTm 3/1zLrSzUU/GT4GVH7E8SXfXfk0D8MTjt2hdOHQYy5n5VZLpBS+AmcJy9LTEcaA3o2pW 5gVrVQdn+jnTBgwEQ+9IfbaoiOIqBzaUDJMHGBt/7JigfiIUcl7KV7FRI0E/Kce1jvbl WcPzt69r7vnrz1dKVOpJzr8O0T7kPIh7zDQnEaqHEZ20/3Ex/31+wUFJD8uPAhp4Bf/h 92SA== 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=NmrPYyKGeRcfSHh2AcbTnldlWRIy35oEgzt4P4Bf898=; b=OqNTYcqtAwuxlM2MFxe4z84bbuGScQaQs9x/n3apWnUx/rgtncNpFwk9PBv1i3J2SK BEJyKMP74p/v8VesEMlLw126BFt97RCkSsK5g/2GifBtk5MstasEnQNF990ATpJkZKhk m61sN5Ivtb6l+wY8a4NPmHh1F5KrAVS5Z9+DTunT6kylDn4Sic+HJYdOQB97RVwV7y1m wVTF24WcMlJPLJfoD5XBTNcH5J6jKAkcmCVkmN8D1ZAYiUi9zJ195hlYALnDkvpX0IAE dVINwB1KM3pfYCMXTfYeIIvz/sQ5Z368u4WjPMf92UvB6Uww+RwNgCoz5jvkFH7/2uAZ LkVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=OMfu6DEO; 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 g124si1188592wmf.39.2019.02.14.01.53.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Feb 2019 01:53:00 -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=OMfu6DEO; 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 E0D293EAA5B for ; Thu, 14 Feb 2019 10:52:59 +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-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+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 --- 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, +};