From patchwork Mon Jun 10 10:13:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 166302 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp839385ilk; Mon, 10 Jun 2019 03:13:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqwNT3ll9/yNJyoPQvn4l3anCrZkDfrp/FRSCUy1GTAGVl0xcoCG7w42wxI+Hkcbl2PipyF3 X-Received: by 2002:a5d:554b:: with SMTP id g11mr29390112wrw.10.1560161633243; Mon, 10 Jun 2019 03:13:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560161633; cv=none; d=google.com; s=arc-20160816; b=Qs9v+3v/1Wm2ISOHBrEWkbTFzsvqoUazxucuTTKHj3o0vEW39zGOIR9cJvoDpycmon RsreaxUp2RWCxHgOdFDmLr/bmyn+g4xFBwmCQP/iA/2oxPd8F5mDmTC3j3dQgC5Qh93D IY9nsRSkX04Efqg6hOZkQFRX3KvbklYZFZ+fObInzXRrHiHYI75iK+rUQAdKgRGMaKFU VFVz+BeBvfi74czLgQFjxSZBOXBXOBSgTC+wR8ugaJPV3N56Erw/f+6D+Z7tyzCDWfsx xqUx3CvMyloDh44xIN2+2+Moo15m1UnoE5PjKjod9GGKZM5uwIwjJO7usv+yUau4OpIK Tmyg== 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=yq3A3285QFu2i7y2sfmudJVZMGOVSiDe6BzlAs0kdVU=; b=Q1kUhyIQrZVlPGxcpfgobaPJNbS70cTdMMbauJgxlPi3Rq3G2MSVUZIXhNYQjP9Nc6 IW6cjg+ojqQtYoGMpNr7MvD/Lx6/3SbwYrdOnnMynb/rkBDVjNCRQZulOlMuWoZXQ+Mw HB63E2sGjfRSY5TIW/Rr0TK2zvjMetNTpsMCJJ3iYe/s+gpl+FF+RgoYzEPahuc1SVRk uAVwyY0KUFgZtB7CoODhR8gCcD0tJEWAc4l68oBmgQkOEz+WEZHgazg6aNGV4P4RQNNI bV6fS//wGw+GH5/cGYd9muApMVhDyDZY/EspJurRjB6leyEeLasIbXvnEi1KMl5BGcOn LI8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=oHWM2zGT; 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 72si6667971wme.140.2019.06.10.03.13.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Jun 2019 03:13:53 -0700 (PDT) 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=oHWM2zGT; 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 CEAB53EB04C for ; Mon, 10 Jun 2019 12:13:52 +0200 (CEST) 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 [217.194.8.6]) by picard.linux.it (Postfix) with ESMTP id EB5203EA25F for ; Mon, 10 Jun 2019 12:13:48 +0200 (CEST) Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) (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 070B9140024F for ; Mon, 10 Jun 2019 12:13:47 +0200 (CEST) Received: by mail-pl1-x642.google.com with SMTP id s24so3455431plr.8 for ; Mon, 10 Jun 2019 03:13:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=lFCxn6a2apwjnPwZl1Cq0YDIa2gjD/OoZSxSNyeP70k=; b=oHWM2zGTeNbAojX09kfm+4mC6Ijj6ak9Le/1ON4AEq0J6RaBHP39tkYQswR0v3KIgc vdOsKumVuD/mspuxPQk5nnsUu0Kigh04KDH3iBn5wQYjfATZvfWBvqntjCkjC3GwCAa4 8k3D9wTcibYmzZWK6dTeVnGZuKD4FOssj5hKy82mhj8xriJZ3Q3tE8uxnMgthnNC/wwq FIDvJ6RVdbIfYLjgGB6zYNxMVrMp7Iml19UDlOnctfE1H80LYVlQ5TdxjZ6tDEt+LoLo t2NdafHXZhrCajlWvAO36eJq0HHoHj4t0gYKvPE7xcoYnNvpmdiAGKZI5+SoFurYPCiB QPpg== 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=lFCxn6a2apwjnPwZl1Cq0YDIa2gjD/OoZSxSNyeP70k=; b=R2d6my9jMOuWwySEIUJ3Nrz6/p/QRkCC46av2pxZCWBvpWpyzBG2xpavSokD0HWG7m qrPEsnFm/oLtzs3Uy3YzBBF1n7Y+LGCYK6L9DJB/3AFkPPk35vfWKZcJnAA4gkNAtsvT U+TLh64KADLBLObKqlbLquuQZhNXIuHRQcu4ALXXdqHBrZi7MqB5ynetUpnKiOgFhmcc 5yUtSpiWfz2RChlOzwlH4q0O6ED+KRmgzzhC3b4nC6KO8umE6eEELFeRO6+XF2pESQr1 MSFa8+o5K0bixe5We1Zz7fWETgCUW3P8lROeyQyldowQJl4vLo6yXqbMvNRZzTePl72w LRsw== X-Gm-Message-State: APjAAAWbb4eS5acysQ2zVvvQVvUzT6f2Jb7rMdId+ljolXUIZHHXyJX/ U6vUuthekvP19qslnbcz5/mt5w== X-Received: by 2002:a17:902:290b:: with SMTP id g11mr68609518plb.26.1560161626378; Mon, 10 Jun 2019 03:13:46 -0700 (PDT) Received: from localhost.localdomain ([117.196.234.139]) by smtp.gmail.com with ESMTPSA id q1sm16754047pfb.156.2019.06.10.03.13.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Jun 2019 03:13:45 -0700 (PDT) From: Sumit Garg To: chrubis@suse.cz, liwang@redhat.com Date: Mon, 10 Jun 2019 15:43:16 +0530 Message-Id: <1560161596-30156-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_HELO_NONE, 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: ltp@lists.linux.it Subject: [LTP] [PATCH v4] syscalls/sync_file_range: add partial file sync test-cases 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" Add partial file sync tests as part of sync_file_range02 test-case. Signed-off-by: Sumit Garg Reviewed-by: Li Wang Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
Reviewed-by: Caspar Zhang --- Changes in v4: vfat FS doesn't support sparse files. So handle this via pre-filling the test file in case of "test3". Changes in v3: 1. Add upper bound check for synced size to device. 2. Refactor tests for more code reuse. 3. Add another test to check sync over partial write. Changes in v2: 1. Do full file write instead of partial and test sync partial file. .../syscalls/sync_file_range/sync_file_range02.c | 53 ++++++++++++++++++---- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/testcases/kernel/syscalls/sync_file_range/sync_file_range02.c b/testcases/kernel/syscalls/sync_file_range/sync_file_range02.c index 82d77f7..9454a56 100644 --- a/testcases/kernel/syscalls/sync_file_range/sync_file_range02.c +++ b/testcases/kernel/syscalls/sync_file_range/sync_file_range02.c @@ -22,23 +22,36 @@ #include "check_sync_file_range.h" #define MNTPOINT "mnt_point" -#define FNAME MNTPOINT"/test" -#define FILE_SIZE_MB 32 -#define FILE_SIZE (FILE_SIZE_MB * TST_MB) +#define FNAME1 MNTPOINT"/test1" +#define FNAME2 MNTPOINT"/test2" +#define FNAME3 MNTPOINT"/test3" +#define FILE_SZ_MB 32 +#define FILE_SZ (FILE_SZ_MB * TST_MB) #define MODE 0644 -static void verify_sync_file_range(void) +struct testcase { + char *fname; + off64_t sync_off; + off64_t sync_size; + size_t exp_sync_size; + off64_t write_off; + size_t write_size_mb; +}; + +static void verify_sync_file_range(struct testcase *tc) { int fd; unsigned long written; - fd = SAFE_OPEN(FNAME, O_RDWR|O_CREAT, MODE); + fd = SAFE_OPEN(tc->fname, O_RDWR|O_CREAT, MODE); + + lseek(fd, tc->write_off, SEEK_SET); tst_dev_bytes_written(tst_device->dev); - tst_fill_fd(fd, 0, TST_MB, FILE_SIZE_MB); + tst_fill_fd(fd, 0, TST_MB, tc->write_size_mb); - TEST(sync_file_range(fd, 0, FILE_SIZE, + TEST(sync_file_range(fd, tc->sync_off, tc->sync_size, SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE | SYNC_FILE_RANGE_WAIT_AFTER)); @@ -50,23 +63,43 @@ static void verify_sync_file_range(void) SAFE_CLOSE(fd); - if (written >= FILE_SIZE) + if ((written >= tc->exp_sync_size) && + (written <= (tc->exp_sync_size + tc->exp_sync_size/10))) tst_res(TPASS, "Test file range synced to device"); else - tst_res(TFAIL, "Synced %li, expected %i", written, FILE_SIZE); + tst_res(TFAIL, "Synced %li, expected %li", written, + tc->exp_sync_size); +} + +static struct testcase testcases[] = { + { FNAME1, 0, FILE_SZ, FILE_SZ, 0, FILE_SZ_MB }, + { FNAME2, FILE_SZ/4, FILE_SZ/2, FILE_SZ/2, 0, FILE_SZ_MB }, + { FNAME3, FILE_SZ/4, FILE_SZ/2, FILE_SZ/4, FILE_SZ/2, FILE_SZ_MB/4 }, +}; + +static void run(unsigned int i) +{ + verify_sync_file_range(&testcases[i]); } static void setup(void) { if (!check_sync_file_range()) tst_brk(TCONF, "sync_file_range() not supported"); + + if (!strcmp(tst_device->fs_type, "vfat")) { + tst_res(TINFO, "Pre-filling file"); + tst_fill_file(FNAME3, 0, TST_MB, FILE_SZ_MB); + sync(); + } } static struct tst_test test = { + .tcnt = ARRAY_SIZE(testcases), .needs_root = 1, .mount_device = 1, .all_filesystems = 1, .mntpoint = MNTPOINT, .setup = setup, - .test_all = verify_sync_file_range, + .test = run, };