From patchwork Thu Mar 7 12:44:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 159846 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp7389676jad; Thu, 7 Mar 2019 04:44:39 -0800 (PST) X-Google-Smtp-Source: APXvYqwahk5NZBeCIxO2Oe1XFGB+oVDswLB8U7JyLzn3aH1cYX89p8SToW0jmigMN872b0fDZGIR X-Received: by 2002:aa7:c70c:: with SMTP id i12mr27096180edq.36.1551962679610; Thu, 07 Mar 2019 04:44:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551962679; cv=none; d=google.com; s=arc-20160816; b=O06JdAGD/VzobCotmInPkQ7kY7+qv/IQu4hU8y1dnU1nmXocBMkVcHHnjZ2EsYcT47 YiGpqR7gbjnypZBYeUAS0xYsGx2gpTwLlWL7HfLGyZHNEKjxTc9TWGZqe0arl1Jq5RLg Pz7K2rKXYnPIdDyysoA5TUYokay4CG5pgnBkwQdwp0QorcVETEDq85TWmrbbA6dKuGOr NKlv0HVFcRiL3mEfUAoRulMFaCVQqATJUalPrVwKiC4DvYtfGVAp6r82MpOnCi5LM+bw TjwI4p5f/iMEv3aHufLq4YFuZKeqQOadSbaY6j2X66uJ6yCW2QJNWX2KCVdEBYIklYwo LSEg== 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:message-id:date:to:from:dkim-signature :delivered-to; bh=XOPvoX5zY+hRzA8cYBz6cT1OlgnNqXsmHWW+NgZJjY4=; b=XukEzJNwNaPndKSRjI5xFx+eGAfEHHXt+/p+XwKtWhFiDRA67uXiMIbWHvUvXxgWf+ ooF6QbxtRBOVTmwMP2UIYh+sJE20x9D6SfDFrrNmKCnpnUj9hCbOkTKi4HJ6yCi2ufs8 qZgvN25ZqZai+EKQ/ToivzWf5Gft+SFXCgtJ7AE5nYJBno06tEhjsblnanfsXPhgu/zZ 7+GD+7mkeDILd4FL5aYE6A6ANSChtqOLaqG9DI1YcGTyD1B2aIZESpYrYi5hycY1gwQM haq2CHib6Idmy+pehy4m4bnXgSpCML1KTpbHIOTzwbeTE19n8f1ikqc+UvGkS3GJHwCd xiVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=lOE90WXs; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 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. [213.254.12.146]) by mx.google.com with ESMTPS id z6si1718627ejq.49.2019.03.07.04.44.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 04:44:39 -0800 (PST) Received-SPF: pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 as permitted sender) client-ip=213.254.12.146; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=lOE90WXs; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 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 287DE3EA3F9 for ; Thu, 7 Mar 2019 13:44:39 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [217.194.8.5]) by picard.linux.it (Postfix) with ESMTP id 3733B3EA0B8 for ; Thu, 7 Mar 2019 13:44:35 +0100 (CET) Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id 759BC6006D4 for ; Thu, 7 Mar 2019 13:44:35 +0100 (CET) Received: by mail-pg1-x544.google.com with SMTP id j3so11162771pgm.11 for ; Thu, 07 Mar 2019 04:44:33 -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=hJsTw07zaP7B+qi1LoEGM78KlOjAKIb9IjJuw9bdXmM=; b=lOE90WXsb0LCqDv3peYIL4PVqL5Cvo8w1iSn8Wyv/i4Secr7RHAQZPz2QUef4TT8wc yTPd9hcKOZJvQyYMjPs3rvJV4Oht/enKt+Ns1TDmkacjWIIAXT3Uh9hkglyO95eFPmjF SA/ettdF7EoBzIpIXR3So/KGhBAw/RRehgQ6dDNOmrmdN3ncqG+ytHtPsyNQ0iniDDv+ 0Kh8xmuVwedIjdsXHK2LzxxefF/VE1C4tXg3T7LHQkN5GyuBLYpANRbTYaLjkv5iZ6Cp VuAdgqB+iKsO9up53ghJOAmv6Vh1NtRWRASjhK5zK/0ENvBbym5DSjygEfutDU1cWWl5 ya0w== 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=hJsTw07zaP7B+qi1LoEGM78KlOjAKIb9IjJuw9bdXmM=; b=DJBKT7qxpkry6uYmg1rVM3QD5a3t7PQWtsS+/ty38hQzAPBNDP1sVLfLZOseFydyYs vPfThKIHG67lkpHrrRFSXZ2FSVj/4jc+sH5SMWRqWSEunoZ1qCF0fY931zM0EntQzuP5 4+8wt6N8nL79/ZV3HJD0F6kdc3QuDzTBT6bObFmDJQJcqa0mY/GuzxkCwaAgLVmsgvxL h1W3GZRr+Ov5VfWAaKniA9z2IdROXwPPQulBVMs5sI5aOBDDjtUkK6ricYVLoRjRVVQz KQrzOjGbtGf1JBRR/KzG8/OT6oa5dntro2FesWMXQ/9Na7z8NSyjGnpeYgNq8dM9E0r9 ptBg== X-Gm-Message-State: APjAAAV/kCIWAMtkQZOIe+NA9rer29iQABNHohMYYKcN5giTMK5Mdfg0 RNQBaY5MHHk7URKrA4+JWF9Ji1B0Pzg= X-Received: by 2002:a63:f806:: with SMTP id n6mr11177953pgh.19.1551962672183; Thu, 07 Mar 2019 04:44:32 -0800 (PST) Received: from localhost.localdomain ([117.252.64.200]) by smtp.gmail.com with ESMTPSA id e123sm5868036pgc.14.2019.03.07.04.44.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Mar 2019 04:44:31 -0800 (PST) From: Sumit Garg To: ltp@lists.linux.it Date: Thu, 7 Mar 2019 18:14:11 +0530 Message-Id: <1551962651-22261-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-5.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-5.smtp.seeweb.it Subject: [LTP] [PATCH v3] 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 Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
--- 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 | 47 +++++++++++++++++----- 1 file changed, 37 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..334ea5e 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,10 +63,23 @@ 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) @@ -63,10 +89,11 @@ static void setup(void) } 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, };