From patchwork Mon Apr 9 03:24:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Yang X-Patchwork-Id: 896101 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=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cn.fujitsu.com Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40KGCl3hfRz9s2S for ; Mon, 9 Apr 2018 13:35:31 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 6C6D93E715A for ; Mon, 9 Apr 2018 05:35:28 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [217.194.8.3]) by picard.linux.it (Postfix) with ESMTP id 575553E7139 for ; Mon, 9 Apr 2018 05:35:26 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-3.smtp.seeweb.it (Postfix) with ESMTP id 5FF0F1A00CD3 for ; Mon, 9 Apr 2018 05:35:23 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="38696618" Received: from localhost (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 09 Apr 2018 11:35:21 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id A84B94D0EFE7; Mon, 9 Apr 2018 11:35:21 +0800 (CST) Received: from RHEL7U5Alpha_SERVER.g08.fujitsu.local (10.167.220.185) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Mon, 9 Apr 2018 11:35:23 +0800 From: Xiao Yang To: Date: Mon, 9 Apr 2018 11:24:37 +0800 Message-ID: <1523244278-17751-1-git-send-email-yangx.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <20180406130248.GB6328@rei> References: <20180406130248.GB6328@rei> MIME-Version: 1.0 X-Originating-IP: [10.167.220.185] X-yoursite-MailScanner-ID: A84B94D0EFE7.AC3F7 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: yangx.jy@cn.fujitsu.com X-Spam-Status: No, score=-0.0 required=7.0 tests=T_RP_MATCHES_RCVD autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-3.smtp.seeweb.it Cc: ltp@lists.linux.it Subject: [LTP] [PATCH v3 1/2] preadv/preadv03.c: Add new testcase 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Check the basic functionality of the preadv(2) for the file opened with O_DIRECT in all filesystem. Signed-off-by: Xiao Yang --- runtest/ltplite | 1 + runtest/stress.part3 | 1 + runtest/syscalls | 2 + testcases/kernel/syscalls/.gitignore | 2 + testcases/kernel/syscalls/preadv/preadv03.c | 146 ++++++++++++++++++++++++++++ 5 files changed, 152 insertions(+) create mode 100644 testcases/kernel/syscalls/preadv/preadv03.c diff --git a/runtest/ltplite b/runtest/ltplite index 15dc0c2..e8c6900 100644 --- a/runtest/ltplite +++ b/runtest/ltplite @@ -589,6 +589,7 @@ pread03 pread03 preadv01 preadv01 preadv02 preadv02 +preadv03 preadv03 profil01 profil01 diff --git a/runtest/stress.part3 b/runtest/stress.part3 index 2a7747c..be912c8 100644 --- a/runtest/stress.part3 +++ b/runtest/stress.part3 @@ -496,6 +496,7 @@ pread03 pread03 preadv01 preadv01 preadv02 preadv02 +preadv03 preadv03 profil01 profil01 diff --git a/runtest/syscalls b/runtest/syscalls index 76ab082..fb71c38 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -821,6 +821,8 @@ preadv01 preadv01 preadv01_64 preadv01_64 preadv02 preadv02 preadv02_64 preadv02_64 +preadv03 preadv03 +preadv03_64 preadv03_64 profil01 profil01 diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore index eea606e..ec2af68 100644 --- a/testcases/kernel/syscalls/.gitignore +++ b/testcases/kernel/syscalls/.gitignore @@ -696,6 +696,8 @@ /preadv/preadv01_64 /preadv/preadv02 /preadv/preadv02_64 +/preadv/preadv03 +/preadv/preadv03_64 /profil/profil01 /pselect/pselect01 /pselect/pselect01_64 diff --git a/testcases/kernel/syscalls/preadv/preadv03.c b/testcases/kernel/syscalls/preadv/preadv03.c new file mode 100644 index 0000000..077063a --- /dev/null +++ b/testcases/kernel/syscalls/preadv/preadv03.c @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved. + * Author: Xiao Yang + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU General Public License + * alone with this program. + */ + +/* + * Test Name: preadv03 + * + * Test Description: + * Check the basic functionality of the preadv(2) for the file + * opened with O_DIRECT in all filesystem. + * Preadv(2) should succeed to read the expected content of data + * and after reading the file, the file offset is not changed. + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include "tst_test.h" +#include "preadv.h" + +#define MNTPOINT "mntpoint" +#define FNAME MNTPOINT"/file" + +static int fd, blksz; +static off_t org_off, tst_off; +static ssize_t exp_sz; +static char *pop_buf; +static struct iovec *rd_iovec; + +static struct tcase { + int count; + off_t *offset; + ssize_t *size; + char content; +} tcases[] = { + {1, &org_off, &exp_sz, 0x61}, + {2, &org_off, &exp_sz, 0x61}, + {1, &tst_off, &exp_sz, 0x62}, +}; + +static void verify_direct_preadv(unsigned int n) +{ + int i; + char *vec; + struct tcase *tc = &tcases[n]; + + vec = rd_iovec->iov_base; + memset(vec, 0x00, blksz); + + SAFE_LSEEK(fd, 0, SEEK_SET); + + TEST(preadv(fd, rd_iovec, tc->count, *tc->offset)); + if (TEST_RETURN < 0) { + tst_res(TFAIL | TTERRNO, "Preadv(O_DIRECT) fails"); + return; + } + + if (TEST_RETURN != *tc->size) { + tst_res(TFAIL, "Preadv(O_DIRECT) read %li bytes, expected %zi", + TEST_RETURN, *tc->size); + return; + } + + for (i = 0; i < *tc->size; i++) { + if (vec[i] != tc->content) + break; + } + + if (i < *tc->size) { + tst_res(TFAIL, "Buffer wrong at %i have %02x expected %02x", + i, vec[i], tc->content); + return; + } + + if (SAFE_LSEEK(fd, 0, SEEK_CUR) != 0) { + tst_res(TFAIL, "Preadv(O_DIRECT) has changed file offset"); + return; + } + + tst_res(TPASS, "Preadv(O_DIRECT) read %zi bytes successfully " + "with content '%c' expectedly", *tc->size, tc->content); +} + +static void setup(void) +{ + int dev_fd; + + dev_fd = SAFE_OPEN(tst_device->dev, O_RDWR); + if (ioctl(dev_fd, BLKSSZGET, &blksz)) { + SAFE_CLOSE(dev_fd); + tst_brk(TBROK | TERRNO, "ioctl(%s, BLKSSZGET) failed", + tst_device->dev); + } + SAFE_CLOSE(dev_fd); + tst_off = blksz; + exp_sz = blksz; + + fd = SAFE_OPEN(FNAME, O_RDWR | O_CREAT | O_DIRECT, 0644); + + pop_buf = SAFE_MEMALIGN(blksz, blksz); + memset(pop_buf, 0x61, blksz); + SAFE_WRITE(1, fd, pop_buf, blksz); + + memset(pop_buf, 0x62, blksz); + SAFE_WRITE(1, fd, pop_buf, blksz); + + rd_iovec = SAFE_MEMALIGN(blksz, blksz + sizeof(size_t)); + rd_iovec->iov_base = SAFE_MEMALIGN(blksz, blksz); + rd_iovec->iov_len = blksz; +} + +static void cleanup(void) +{ + free(pop_buf); + free(rd_iovec->iov_base); + free(rd_iovec); + + if (fd > 0) + SAFE_CLOSE(fd); +} + +static struct tst_test test = { + .tcnt = ARRAY_SIZE(tcases), + .setup = setup, + .cleanup = cleanup, + .test = verify_direct_preadv, + .min_kver = "2.6.30", + .mntpoint = MNTPOINT, + .mount_device = 1, + .all_filesystems = 1, +}; From patchwork Mon Apr 9 03:24:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Yang X-Patchwork-Id: 896102 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=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cn.fujitsu.com Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40KGCr1w0Dz9s3p for ; Mon, 9 Apr 2018 13:35:36 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 5F9AA3E71CD for ; Mon, 9 Apr 2018 05:35:33 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) by picard.linux.it (Postfix) with ESMTP id 08FD03E7198 for ; Mon, 9 Apr 2018 05:35:29 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-3.smtp.seeweb.it (Postfix) with ESMTP id 70DBF1A00E15 for ; Mon, 9 Apr 2018 05:35:27 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="38696619" Received: from localhost (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 09 Apr 2018 11:35:21 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 569D34D0EFE7; Mon, 9 Apr 2018 11:35:22 +0800 (CST) Received: from RHEL7U5Alpha_SERVER.g08.fujitsu.local (10.167.220.185) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Mon, 9 Apr 2018 11:35:23 +0800 From: Xiao Yang To: Date: Mon, 9 Apr 2018 11:24:38 +0800 Message-ID: <1523244278-17751-2-git-send-email-yangx.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1523244278-17751-1-git-send-email-yangx.jy@cn.fujitsu.com> References: <20180406130248.GB6328@rei> <1523244278-17751-1-git-send-email-yangx.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.185] X-yoursite-MailScanner-ID: 569D34D0EFE7.AB221 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: yangx.jy@cn.fujitsu.com X-Spam-Status: No, score=-0.0 required=7.0 tests=T_RP_MATCHES_RCVD autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-3.smtp.seeweb.it Cc: ltp@lists.linux.it Subject: [LTP] [PATCH v3 2/2] pwritev/pwritev03.c: Add new testcase 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Check the basic functionality of the pwritev(2) for the file opened with O_DIRECT in all filesystem. Signed-off-by: Xiao Yang --- runtest/ltplite | 1 + runtest/stress.part3 | 1 + runtest/syscalls | 2 + testcases/kernel/syscalls/.gitignore | 2 + testcases/kernel/syscalls/pwritev/pwritev03.c | 146 ++++++++++++++++++++++++++ 5 files changed, 152 insertions(+) create mode 100644 testcases/kernel/syscalls/pwritev/pwritev03.c diff --git a/runtest/ltplite b/runtest/ltplite index e8c6900..1f4d91c 100644 --- a/runtest/ltplite +++ b/runtest/ltplite @@ -612,6 +612,7 @@ pwrite04_64 pwrite04_64 pwritev01 pwritev01 pwritev02 pwritev02 +pwritev03 pwritev03 read01 read01 read02 read02 diff --git a/runtest/stress.part3 b/runtest/stress.part3 index be912c8..96f7953 100644 --- a/runtest/stress.part3 +++ b/runtest/stress.part3 @@ -517,6 +517,7 @@ pwrite04_64 pwrite04_64 pwritev01 pwritev01 pwritev02 pwritev02 +pwritev03 pwritev03 read01 read01 read02 read02 diff --git a/runtest/syscalls b/runtest/syscalls index fb71c38..8461b94 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -865,6 +865,8 @@ pwritev01 pwritev01 pwritev01_64 pwritev01_64 pwritev02 pwritev02 pwritev02_64 pwritev02_64 +pwritev03 pwritev03 +pwritev03_64 pwritev03_64 quotactl01 quotactl01 quotactl02 quotactl02 diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore index ec2af68..c3bc662 100644 --- a/testcases/kernel/syscalls/.gitignore +++ b/testcases/kernel/syscalls/.gitignore @@ -726,6 +726,8 @@ /pwritev/pwritev01_64 /pwritev/pwritev02 /pwritev/pwritev02_64 +/pwritev/pwritev03 +/pwritev/pwritev03_64 /quotactl/quotactl01 /quotactl/quotactl02 /quotactl/quotactl03 diff --git a/testcases/kernel/syscalls/pwritev/pwritev03.c b/testcases/kernel/syscalls/pwritev/pwritev03.c new file mode 100644 index 0000000..8ec9aca --- /dev/null +++ b/testcases/kernel/syscalls/pwritev/pwritev03.c @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved. + * Author: Xiao Yang + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU General Public License + * alone with this program. + */ + +/* + * Test Name: pwritev03 + * + * Test Description: + * Check the basic functionality of the pwritev(2) for the file + * opened with O_DIRECT in all filesystem. + * pwritev(2) should succeed to write the expected content of data + * and after writing the file, the file offset is not changed. + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include "tst_test.h" +#include "pwritev.h" +#include "tst_safe_prw.h" + +#define MNTPOINT "mntpoint" +#define FNAME MNTPOINT"/file" + +static char *initbuf; +static char *preadbuf; +static struct iovec *wr_iovec; +static int fd, blksz; +static off_t org_off, tst_off; +static ssize_t exp_sz; + +static struct tcase { + int count; + off_t *offset; + ssize_t *size; +} tcases[] = { + {1, &org_off, &exp_sz}, + {2, &org_off, &exp_sz}, + {1, &tst_off, &exp_sz}, +}; + +static void verify_direct_pwritev(unsigned int n) +{ + int i; + struct tcase *tc = &tcases[n]; + + SAFE_PWRITE(1, fd, initbuf, blksz * 2, 0); + + TEST(pwritev(fd, wr_iovec, tc->count, *tc->offset)); + if (TEST_RETURN < 0) { + tst_res(TFAIL | TTERRNO, "Pwritev(O_DIRECT) fails"); + return; + } + + if (TEST_RETURN != *tc->size) { + tst_res(TFAIL, "Pwritev(O_DIRECT) wrote %li bytes, expected %zi", + TEST_RETURN, *tc->size); + return; + } + + if (SAFE_LSEEK(fd, 0, SEEK_CUR) != 0) { + tst_res(TFAIL, "Pwritev(O_DIRECT) had changed file offset"); + return; + } + + memset(preadbuf, 0x00, blksz); + SAFE_PREAD(1, fd, preadbuf, *tc->size, *tc->offset); + + for (i = 0; i < *tc->size; i++) { + if (preadbuf[i] != 0x61) + break; + } + + if (i != *tc->size) { + tst_res(TFAIL, "Buffer wrong at %i have %02x expected 0x61", + i, preadbuf[i]); + return; + } + + tst_res(TPASS, "Pwritev(O_DIRECT) wrote %zi bytes successfully " + "with content 'a' expectedly ", *tc->size); +} + +static void setup(void) +{ + int dev_fd; + + dev_fd = SAFE_OPEN(tst_device->dev, O_RDWR); + if (ioctl(dev_fd, BLKSSZGET, &blksz)) { + SAFE_CLOSE(dev_fd); + tst_brk(TBROK | TERRNO, "ioctl(%s, BLKSSZGET) failed", + tst_device->dev); + } + SAFE_CLOSE(dev_fd); + tst_off = blksz; + exp_sz = blksz; + + fd = SAFE_OPEN(FNAME, O_RDWR | O_CREAT | O_DIRECT, 0644); + + initbuf = SAFE_MEMALIGN(blksz, blksz * 2); + memset(initbuf, 0x00, blksz * 2); + + preadbuf = SAFE_MEMALIGN(blksz, blksz); + + wr_iovec = SAFE_MEMALIGN(blksz, blksz + sizeof(size_t)); + wr_iovec->iov_base = SAFE_MEMALIGN(blksz, blksz); + wr_iovec->iov_len = blksz; + memset(wr_iovec->iov_base, 0x61, blksz); +} + +static void cleanup(void) +{ + free(initbuf); + free(preadbuf); + free(wr_iovec->iov_base); + free(wr_iovec); + + if (fd > 0) + SAFE_CLOSE(fd); +} + +static struct tst_test test = { + .tcnt = ARRAY_SIZE(tcases), + .setup = setup, + .cleanup = cleanup, + .test = verify_direct_pwritev, + .min_kver = "2.6.30", + .mntpoint = MNTPOINT, + .mount_device = 1, + .all_filesystems = 1, +};