From patchwork Wed Sep 22 05:39:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yang Xu \\(Fujitsu\\)" X-Patchwork-Id: 1531042 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=fujitsu.com header.i=@fujitsu.com header.a=rsa-sha256 header.s=170520fj header.b=wtLOOr1A; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4HDnF51h32z9sSn for ; Wed, 22 Sep 2021 15:40:08 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id A9EF33C808E for ; Wed, 22 Sep 2021 07:40:05 +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]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 3ACB43C5970 for ; Wed, 22 Sep 2021 07:40:04 +0200 (CEST) Received: from mail1.bemta25.messagelabs.com (mail1.bemta25.messagelabs.com [195.245.230.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id E3A4614011A4 for ; Wed, 22 Sep 2021 07:40:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.com; s=170520fj; t=1632289201; i=@fujitsu.com; bh=0QT6AkkJ2qFRPIZxTok8x+foQCmy/hfyLob7pb5sIXM=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=wtLOOr1AWJywEwhJTFm1rsowywYbYr2rnEgvv9mCY31i1+GdQG7mm5obwplRCrB4p p15q9T/Ms+IzgYVpg0fB8+TjSU7y/LEKlfbTOjbES5sjB16LLRQAuj868nmQunUBjy AaD9XWVf+g8P6SGLhs61kpPSMi9Z21FbAuZqkqk+mwH7ddJmo8eGZGhb3Nsf2r10N8 GnbiP/qqyZSa0VZBlgzaOAI5pgALUENmFJuWR+ifPimRojgKPjnwY0fhobyRg/YDYq YqZXgWNaa1rDV6wcOzWerr9hcYDarpC7xXsamDp6RzX/gbMrAIezEPXltoAnqSzrRp 0UaaqQTB1lenA== Received: from [100.112.199.201] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-2.bemta.az-b.eu-west-1.aws.symcld.net id 57/D3-21482-1B1CA416; Wed, 22 Sep 2021 05:40:01 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrCIsWRWlGSWpSXmKPExsViZ8MRqrvxoFe iwe9lzBYrvu9gdGD02Pd7HWsAYxRrZl5SfkUCa8anhvesBQ8EKzZtfsrSwHiYr4uRi0NIoIVJ 4urURUwQzh5Gif3XbzB3MXJysAloSjzrXABmiwhISHQ0vGUHsZkF1CWWT/rFBGILC6RJ3Jh4m BXEZhFQldjyfAZYnFfAQ2Ll4ftgtoSAgsSUh++ZIeKCEidnPmGBmCMhcfDFC2aIGkWJSx3fGC HsColZs9qYJjDyzkLSMgtJywJGplWMFklFmekZJbmJmTm6hgYGuoaGRrqGlma6RoYmeolVukl 6qaW65anFJbqGeonlxXrFlbnJOSl6eaklmxiBAZZScOTaDsYDrz/oHWKU5GBSEuV11/ZKFOJL yk+pzEgszogvKs1JLT7EKMPBoSTBe3Y/UE6wKDU9tSItMwcY7DBpCQ4eJRFegV1Aad7igsTc4 sx0iNQpRl2OnUfnLWIWYsnLz0uVEuctOQBUJABSlFGaBzcCFnmXGGWlhHkZGRgYhHgKUotyM0 tQ5V8xinMwKgnzvt0HNIUnM68EbtMroCOYgI7gX+kBckRJIkJKqoFJ4IR+rPz7Z6IbbeKfRMh clP0yN75/p9S3o+Ym1imJooqlfMtmnP2bYvrvh+bK262NzVc3CL5StZ/0+GDdVc+GboUlPbbu f3/3bwv7sCG8vOC4whSd699YT9erV82M3fRa4nlvnfDu1G4Fl6fhRzT4+h7f8Wxbb2ebIy5yX u2V19THwrz1byyFdkSt+2Jr+H+z8oONO0zcvNQ13xrWHP1x8tW6nUp1ryc/k52dcFwm2Xvd+W 2ZTJfs7vPzxputnri1k+W3rrVXA+eHdQaX2iYxKnI/K51xa0LU1tRLm5X1PhWmeLA/O/fiUWE S9y/h7c1LAkOU2poj5v07tzlm94/IJ8v/TvRaZ+28pk88bMpaJZbijERDLeai4kQAQ2yKoDcD AAA= X-Env-Sender: xuyang2018.jy@fujitsu.com X-Msg-Ref: server-3.tower-291.messagelabs.com!1632289200!126450!1 X-Originating-IP: [62.60.8.85] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.81.4; banners=-,-,- X-VirusChecked: Checked Received: (qmail 15072 invoked from network); 22 Sep 2021 05:40:01 -0000 Received: from unknown (HELO mailhost4.uk.fujitsu.com) (62.60.8.85) by server-3.tower-291.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 22 Sep 2021 05:40:01 -0000 Received: from R01UKEXCASM126.r01.fujitsu.local ([10.183.43.178]) by mailhost4.uk.fujitsu.com (8.14.5/8.14.5) with ESMTP id 18M5dthC005296 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL) for ; Wed, 22 Sep 2021 06:40:00 +0100 Received: from localhost.localdomain (10.167.220.84) by R01UKEXCASM126.r01.fujitsu.local (10.183.43.178) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Wed, 22 Sep 2021 06:39:53 +0100 From: Yang Xu To: Date: Wed, 22 Sep 2021 13:39:40 +0800 Message-ID: <1632289182-2191-1-git-send-email-xuyang2018.jy@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-ClientProxiedBy: G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.80) To R01UKEXCASM126.r01.fujitsu.local (10.183.43.178) X-Virus-Scanned: clamav-milter 0.102.4 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,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH v1 1/3] syscalls/dup202: Also check mode whethter change when calling chmod after dup2 X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 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" Since the two file descriptors refer to the same open file description, they should share the file status. So change mode for file after creat, then check whether oldfd mode equals newfd mode. Signed-off-by: Yang Xu --- testcases/kernel/syscalls/dup2/dup202.c | 30 +++++++++++++++++++------ 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/testcases/kernel/syscalls/dup2/dup202.c b/testcases/kernel/syscalls/dup2/dup202.c index 94bedcf18..c50b56ba0 100644 --- a/testcases/kernel/syscalls/dup2/dup202.c +++ b/testcases/kernel/syscalls/dup2/dup202.c @@ -8,10 +8,14 @@ * [Description] * * Test whether the access mode are the same for both file descriptors. + * Style: creat mode, dup2, [change mode], check mode * - * - 0: read only ? "0444" - * - 1: write only ? "0222" - * - 2: read/write ? "0666" + * - 0: read only, dup2, null, read only ? "0444" + * - 1: write only, dup2, null, write only ? "0222" + * - 2: read/write, dup2, null, read/write ? "0666" + * - 3: read/write/execute, dup2, read only, read only ? "0444" + * - 4: read/write/execute, dup2, write only, write only ? "0222" + * - 5: read/write/execute, dup2, read/write, read/write ? "0666" */ #include @@ -29,10 +33,15 @@ static int duprdo = 10, dupwro = 20, duprdwr = 30; static struct tcase { int *nfd; mode_t mode; + /* 0 - set mode before dup2, 1 - change mode after dup2 */ + int flag; } tcases[] = { - {&duprdo, 0444}, - {&dupwro, 0222}, - {&duprdwr, 0666}, + {&duprdo, 0444, 0}, + {&dupwro, 0222, 0}, + {&duprdwr, 0666, 0}, + {&duprdo, 0444, 1}, + {&dupwro, 0222, 1}, + {&duprdwr, 0666, 1}, }; static void setup(void) @@ -52,7 +61,10 @@ static void run(unsigned int i) struct stat oldbuf, newbuf; struct tcase *tc = tcases + i; - ofd = SAFE_CREAT(testfile, tc->mode); + if (tc->flag) + ofd = SAFE_CREAT(testfile, 0777); + else + ofd = SAFE_CREAT(testfile, tc->mode); nfd = *tc->nfd; TEST(dup2(ofd, nfd)); @@ -60,6 +72,10 @@ static void run(unsigned int i) tst_res(TFAIL | TTERRNO, "call failed unexpectedly"); goto free; } + if (tc->flag) { + SAFE_CHMOD(testfile, tc->mode); + tst_res(TINFO, "original mode 0777, new mode 0%o after chmod", tc->mode); + } SAFE_FSTAT(ofd, &oldbuf); From patchwork Wed Sep 22 05:39:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yang Xu \\(Fujitsu\\)" X-Patchwork-Id: 1531043 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=fujitsu.com header.i=@fujitsu.com header.a=rsa-sha256 header.s=170520fj header.b=qv/M1M40; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4HDnFG74PSz9sSn for ; Wed, 22 Sep 2021 15:40:18 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 5B71C3C7713 for ; Wed, 22 Sep 2021 07:40:16 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [217.194.8.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 441E83C6A0B for ; Wed, 22 Sep 2021 07:40:04 +0200 (CEST) Received: from mail1.bemta26.messagelabs.com (mail1.bemta26.messagelabs.com [85.158.142.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id BAD8210011A4 for ; Wed, 22 Sep 2021 07:40:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.com; s=170520fj; t=1632289201; i=@fujitsu.com; bh=y8nha+kmcoTHOEeA+4OKV6R6gKvF2JZOuhloUP3k0ks=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qv/M1M40eN95xbJsZJgZ3nCht0ywwIIfwL3gdnJseSYmYd8n8PxVJ2egJMiwdckQ5 53r7DiDkSo5/Y37DHBHfO9sDF0dFtM5d0zpmQVnhtpvnbkQFORNpG3DSbYuY3+FXjf tG7IUfVnaBxLM2VAqYPkp4OD/WnJjQV3CkW1CBLPBMcyIcfmcZ+29zty9U41A64gNp +zR6TugiEDor8w0RwjQ/LMSvpfsIz86r8CUYlx5W8/iuVBr9Btpb+zHPxwJyqfONEC oQzpw1EEJTyY5R1bx8PVArKHDuCQIWcaJVHUKu7ITLcQSN7NEKiqH6WKaEBVOaiUSC wNJKju1Sb6BgQ== Received: from [100.113.4.108] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-1.bemta.az-b.eu-central-1.aws.symcld.net id 3F/22-23595-1B1CA416; Wed, 22 Sep 2021 05:40:01 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrLIsWRWlGSWpSXmKPExsViZ8MRqrvxoFe iwYaZ7BYrvu9gdGD02Pd7HWsAYxRrZl5SfkUCa8bWjrtMBZ8EKt5/nsrawLiZr4uRi0NIoIVJ 4v+VT8wQzh5Gib+TPjF2MXJysAloSjzrXMAMYosISEh0NLxlB7GZBdQllk/6xQRiCwt4Sxw5f xLMZhFQlZj3dhGYzSvgITF7WQNYr4SAgsSUh+/BbE4BT4l3L/aCzRcCqjnx/zobRL2gxMmZT1 gg5ktIHHzxAqpXUeJSxzdGCLtCYtasNqYJjPyzkLTMQtKygJFpFaNlUlFmekZJbmJmjq6hgYG uoaGxrqmukYmhXmKVbpJeaqlucmpeSVEiUFYvsbxYr7gyNzknRS8vtWQTIzAkUwpZP+5gPPT6 g94hRkkOJiVRXndtr0QhvqT8lMqMxOKM+KLSnNTiQ4wyHBxKErxn9wPlBItS01Mr0jJzgPEBk 5bg4FES4RXYBZTmLS5IzC3OTIdInWLU5WietHw7sxBLXn5eqpQ4b8kBoCIBkKKM0jy4EbBYvc QoKyXMy8jAwCDEU5BalJtZgir/ilGcg1FJmPftPqApPJl5JXCbXgEdwQR0BP9KD5AjShIRUlI NTNMkElm+r3yYd4t75ykZMYdbnmLcYW4fwq2K8j+HPf+UuqPy4f1jicmxFTMYQuo2/mKa25Hd s3hZ2PwNtnYZGRN8Apt9t/3i+f9j1VVWhcwQFb3w+4tbJ35a+uYms22sHW/brKCc7rrQmpNsL /p/nN3sqJIfeiDJ4ItYrEj5/Ci/lPyCttPB5XUOqkIvjpvcPKvmFnGl3qyy9d7Cvh8xYq9b7F z2PAsoe96l9uzSae2LEkWh38KPV5cwSQgt7LvE8OPDl97UZ6Z8Mye/krn9UVRqqzarUg6H0JN V8xiFvLd1RegFv1g/Nf3y/U8/Pcy9/t9tPsobcXDp/AdvP2WeOWEyqcfyhCuvsXpDBV+JEktx RqKhFnNRcSIA00TIM1ADAAA= X-Env-Sender: xuyang2018.jy@fujitsu.com X-Msg-Ref: server-20.tower-238.messagelabs.com!1632289200!116927!1 X-Originating-IP: [62.60.8.85] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.81.4; banners=-,-,- X-VirusChecked: Checked Received: (qmail 24024 invoked from network); 22 Sep 2021 05:40:01 -0000 Received: from unknown (HELO mailhost4.uk.fujitsu.com) (62.60.8.85) by server-20.tower-238.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 22 Sep 2021 05:40:01 -0000 Received: from R01UKEXCASM126.r01.fujitsu.local ([10.183.43.178]) by mailhost4.uk.fujitsu.com (8.14.5/8.14.5) with ESMTP id 18M5dthE005296 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL) for ; Wed, 22 Sep 2021 06:40:00 +0100 Received: from localhost.localdomain (10.167.220.84) by R01UKEXCASM126.r01.fujitsu.local (10.183.43.178) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Wed, 22 Sep 2021 06:39:56 +0100 From: Yang Xu To: Date: Wed, 22 Sep 2021 13:39:41 +0800 Message-ID: <1632289182-2191-2-git-send-email-xuyang2018.jy@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1632289182-2191-1-git-send-email-xuyang2018.jy@fujitsu.com> References: <1632289182-2191-1-git-send-email-xuyang2018.jy@fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-ClientProxiedBy: G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.80) To R01UKEXCASM126.r01.fujitsu.local (10.183.43.178) X-Virus-Scanned: clamav-milter 0.102.4 at in-4.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,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH v1 2/3] syscalls/dup206: Add a test when newfd equals oldfd X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 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" Signed-off-by: Yang Xu --- runtest/syscalls | 1 + testcases/kernel/syscalls/dup2/.gitignore | 1 + testcases/kernel/syscalls/dup2/dup206.c | 51 +++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 testcases/kernel/syscalls/dup2/dup206.c diff --git a/runtest/syscalls b/runtest/syscalls index 29d7752c7..068fba456 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -153,6 +153,7 @@ dup202 dup202 dup203 dup203 dup204 dup204 dup205 dup205 +dup206 dup206 dup3_01 dup3_01 dup3_02 dup3_02 diff --git a/testcases/kernel/syscalls/dup2/.gitignore b/testcases/kernel/syscalls/dup2/.gitignore index 6c4685b80..e2e008b58 100644 --- a/testcases/kernel/syscalls/dup2/.gitignore +++ b/testcases/kernel/syscalls/dup2/.gitignore @@ -3,3 +3,4 @@ /dup203 /dup204 /dup205 +/dup206 diff --git a/testcases/kernel/syscalls/dup2/dup206.c b/testcases/kernel/syscalls/dup2/dup206.c new file mode 100644 index 000000000..e5074ea83 --- /dev/null +++ b/testcases/kernel/syscalls/dup2/dup206.c @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu + */ + +/*\ + * [Description] + * + * If oldfd is a valid file descriptor, and newfd has the same value as oldfd, + * then dup2() does nothing, and returns newfd. + */ + +#include +#include +#include "tst_test.h" + +static int fd = -1; + +static void verify_dup2(void) +{ + TST_EXP_FD_SILENT(dup2(fd, fd), "dup2(%d, %d)", fd, fd); + + if (TST_RET != fd) { + tst_res(TFAIL, "dup2(%d, %d) returns wrong newfd(%ld)", fd, fd, TST_RET); + SAFE_CLOSE(TST_RET); + return; + } + tst_res(TPASS, "dup2(%d, %d) returns newfd(%d)", fd, fd, fd); +} + +static void setup(void) +{ + char testfile[40]; + + sprintf(testfile, "dup206.%d", getpid()); + fd = SAFE_OPEN(testfile, O_RDWR | O_CREAT, 0666); +} + +static void cleanup(void) +{ + if (fd > -1) + SAFE_CLOSE(fd); +} + +static struct tst_test test = { + .needs_tmpdir = 1, + .setup = setup, + .cleanup = cleanup, + .test_all = verify_dup2, +}; From patchwork Wed Sep 22 05:39:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yang Xu \\(Fujitsu\\)" X-Patchwork-Id: 1531044 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=fujitsu.com header.i=@fujitsu.com header.a=rsa-sha256 header.s=170520fj header.b=i4pLxN78; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4HDnFV3fBGz9sSn for ; Wed, 22 Sep 2021 15:40:30 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 47A6A3C6E45 for ; Wed, 22 Sep 2021 07:40:28 +0200 (CEST) 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 [IPv6:2001:4b78:1:20::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 820BA3CA14F for ; Wed, 22 Sep 2021 07:40:14 +0200 (CEST) Received: from mail3.bemta25.messagelabs.com (mail3.bemta25.messagelabs.com [195.245.230.84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id BA623200DA8 for ; Wed, 22 Sep 2021 07:40:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.com; s=170520fj; t=1632289210; i=@fujitsu.com; bh=hysPykdeQdYvbwP/Tcwj4l4Q5f4ZTG59zTYs2y8cKSs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=i4pLxN78F4CXcBeiH6h/ayZbS5B8T9R9EILrj0H56i7kbWMUdD6oFp00rfzZ1wnYO cPGjYn6em2OJW+WU5z72wJ1LPhznaduScvFFUorEfFeDguM5UjHqjYVWAjZpxmuFLI peEP8Y9wUHlkav9GvcPHjEQODzSqViAXQy0TUZ3An6BPoCyCrPj71oBGIQDoZkxjUh wKAOwerNgTllcx6WELc5MsV0dvEoqCsvGJVpd9/kAcJuhI+2YmzyiwD6otHhJSPrIX 76yB/qcjTKjj9119HehQdOcDmt5Do26zUnE7TpQtukOUswN+vv8F2kObOM/nxuYGLB ko9aGwISqnjLw== Received: from [100.112.199.201] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-4.bemta.az-b.eu-west-1.aws.symcld.net id F8/0F-21838-AB1CA416; Wed, 22 Sep 2021 05:40:10 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrDIsWRWlGSWpSXmKPExsViZ8MxRXfXQa9 Eg74rPBYrvu9gdGD02Pd7HWsAYxRrZl5SfkUCa8bb/rXsBb8lKt6tO8TWwDhJtIuRi0NIoIVJ ou/zVxYIZw+jxPzv+1m7GDk52AQ0JZ51LmAGsUUEJCQ6Gt6yg9jMAuoSyyf9YgKxhQWcJbqWr wGLswioSnxfOgGsl1fAQ2LZyZ2MILaEgILElIfvweZwCnhKvHuxFywuBFRz4v91Noh6QYmTM5 +wQMyXkDj44gUzRK+ixKWOb1BzKiRmzWpjmsDIPwtJyywkLQsYmVYxWiQVZaZnlOQmZuboGho Y6BoaGukaWprrGhqb6yVW6SbppZbqlqcWl+ga6iWWF+sVV+Ym56To5aWWbGIEBmRKwdHOHYy/ Xn3QO8QoycGkJMrrru2VKMSXlJ9SmZFYnBFfVJqTWnyIUYaDQ0mC9+x+oJxgUWp6akVaZg4wO mDSEhw8SiK8AruA0rzFBYm5xZnpEKlTjLoczZOWb2cWYsnLz0uVEuctOQBUJABSlFGaBzcCFq mXGGWlhHkZGRgYhHgKUotyM0tQ5V8xinMwKgnzvt0HNIUnM68EbtMroCOYgI7gX+kBckRJIkJ KqoEp6mU+V0evW/eftb18v7dMNOYzbgzd93bj2zkObM6+O1K+PGfMPVHj8DbnrcOXtyzd600U +0+/8TpRf1og8KwM49sHKsHevP8CFlbEO0YG8Fdf4HN0CXvy82bUprWvX/2apGEzJyiy/6BWW +X1A9k71jQ/yNpw2YFz6m6JMAPZqrAGgU87TP5UHAjjdZtyr6tjQvCME7POxun46eV9Wtr/U+ iljUinyJFfSw+JTew4ueiZyNR3XxRd+hOeetlksG2TtC/IXqF5N+Y7/8otqdtYJUtSnp2vKtg 49fjE7/afWjsXP18g96jibdhMD8Zrh7Zou2uGrXjA2bmmfekXjoI3W27N2KHA0FSr3634f766 EktxRqKhFnNRcSIA50pb808DAAA= X-Env-Sender: xuyang2018.jy@fujitsu.com X-Msg-Ref: server-14.tower-285.messagelabs.com!1632289209!237285!1 X-Originating-IP: [62.60.8.148] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.81.4; banners=-,-,- X-VirusChecked: Checked Received: (qmail 9740 invoked from network); 22 Sep 2021 05:40:10 -0000 Received: from unknown (HELO mailhost1.uk.fujitsu.com) (62.60.8.148) by server-14.tower-285.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 22 Sep 2021 05:40:10 -0000 Received: from R01UKEXCASM126.r01.fujitsu.local ([10.183.43.178]) by mailhost1.uk.fujitsu.com (8.14.5/8.14.5) with ESMTP id 18M5e3Yi010435 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL) for ; Wed, 22 Sep 2021 06:40:09 +0100 Received: from localhost.localdomain (10.167.220.84) by R01UKEXCASM126.r01.fujitsu.local (10.183.43.178) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Wed, 22 Sep 2021 06:40:00 +0100 From: Yang Xu To: Date: Wed, 22 Sep 2021 13:39:42 +0800 Message-ID: <1632289182-2191-3-git-send-email-xuyang2018.jy@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1632289182-2191-1-git-send-email-xuyang2018.jy@fujitsu.com> References: <1632289182-2191-1-git-send-email-xuyang2018.jy@fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-ClientProxiedBy: G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.80) To R01UKEXCASM126.r01.fujitsu.local (10.183.43.178) X-Virus-Scanned: clamav-milter 0.102.4 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,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v1 3/3] syscalls/dup207: Add file offset check test X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 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" Since the two file descriptors refer to the same open file description, they share file offset. If the file offset is modified by using lseek(2) on one of the file descriptors, the offset is also changed for the other file descriptor. Signed-off-by: Yang Xu --- runtest/syscalls | 1 + testcases/kernel/syscalls/dup2/.gitignore | 1 + testcases/kernel/syscalls/dup2/dup207.c | 82 +++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 testcases/kernel/syscalls/dup2/dup207.c diff --git a/runtest/syscalls b/runtest/syscalls index 068fba456..b19316805 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -154,6 +154,7 @@ dup203 dup203 dup204 dup204 dup205 dup205 dup206 dup206 +dup207 dup207 dup3_01 dup3_01 dup3_02 dup3_02 diff --git a/testcases/kernel/syscalls/dup2/.gitignore b/testcases/kernel/syscalls/dup2/.gitignore index e2e008b58..f5938a182 100644 --- a/testcases/kernel/syscalls/dup2/.gitignore +++ b/testcases/kernel/syscalls/dup2/.gitignore @@ -4,3 +4,4 @@ /dup204 /dup205 /dup206 +/dup207 diff --git a/testcases/kernel/syscalls/dup2/dup207.c b/testcases/kernel/syscalls/dup2/dup207.c new file mode 100644 index 000000000..8badf4229 --- /dev/null +++ b/testcases/kernel/syscalls/dup2/dup207.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu + */ + +/*\ + * [Description] + * + * Test whether the file offset are the same for both file descriptors. + */ + +#include +#include +#include +#include "tst_test.h" +#include "tst_safe_macros.h" + +#define WRITE_STR "abcdefg" + +static int ofd = -1, nfd = 10; + +static struct tcase { + off_t offset; + size_t exp_size; + /* 0 - change offset before dup2, 1 - change offset after dup2 */ + int flag; + char *exp_data; + char *desc; +} tcases[] = { + {1, 6, 0, "bcdefg", "Test offset check when using lseek before dup2"}, + {2, 5, 1, "cdefg", "Test offset check when using lseek after dup2"}, +}; + +static void setup(void) +{ + char testfile[40]; + + sprintf(testfile, "dup207.%d", getpid()); + ofd = SAFE_OPEN(testfile, O_RDWR | O_CREAT, 0644); + SAFE_WRITE(1, ofd, WRITE_STR, sizeof(WRITE_STR) - 1); +} + +static void cleanup(void) +{ + if (ofd > 0) + SAFE_CLOSE(ofd); + close(nfd); +} + +static void run(unsigned int i) +{ + struct tcase *tc = tcases + i; + char read_buf[20]; + + memset(read_buf, 0, sizeof(read_buf)); + tst_res(TINFO, "%s", tc->desc); + if (!tc->flag) + SAFE_LSEEK(ofd, tc->offset, SEEK_SET); + + TEST(dup2(ofd, nfd)); + if (TST_RET == -1) { + tst_res(TFAIL | TTERRNO, "call failed unexpectedly"); + return; + } + if (tc->flag) + SAFE_LSEEK(ofd, tc->offset, SEEK_SET); + + SAFE_READ(1, nfd, read_buf, tc->exp_size); + if (strncmp(read_buf, tc->exp_data, tc->exp_size)) + tst_res(TFAIL, "Expect %s, but get %s.", tc->exp_data, read_buf); + else + tst_res(TPASS, "Get expected buf %s", read_buf); +} + +static struct tst_test test = { + .needs_tmpdir = 1, + .tcnt = ARRAY_SIZE(tcases), + .test = run, + .setup = setup, + .cleanup = cleanup, +};