From patchwork Mon Sep 20 03:37:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: QI Fuli X-Patchwork-Id: 1529931 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=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=b5ARM2VM; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) 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=) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (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 4HCVcc21Gjz9sW4 for ; Mon, 20 Sep 2021 13:37:36 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id AF9433C2FA0 for ; Mon, 20 Sep 2021 05:37:33 +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)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 18CBE3C21EB for ; Mon, 20 Sep 2021 05:37:23 +0200 (CEST) Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 693B4200275 for ; Mon, 20 Sep 2021 05:37:22 +0200 (CEST) Received: by mail-pg1-x536.google.com with SMTP id u18so16040973pgf.0 for ; Sun, 19 Sep 2021 20:37:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=N01CLDXJNjIooelLKoCLvmmqQpXJjbBqSojY/S+KehQ=; b=b5ARM2VM7AJlf3Mi5sNuq3XdfkjIHOLHEd1VCtyaPI0d+/0HcKK2GTtdR01TiUP2dJ unZPX/iWVW5d0cgjh0aEyXReg4B34LLKZoe0P/c/1ohpDP3/bpImDU7rq4CjwAOPgqJh D5XGynRpJ0z5n/fm1KQjX27AR575qimElRw5T0ScXZaCsQQI0n80U7/vk7SbeH1DdkSS pPTyCf/+vf0ck1EELNYsvUAj68JiXvhgBI9FupHk7XqTlV0DiV9dmIyQXmO+EawQn9hs 6Kts0WwbGkksQHxTeQ6n0DIwYoCwviXvF/jg0Zys+QiAlCU1KNopAZSiZueztcQnDy+l AfYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=N01CLDXJNjIooelLKoCLvmmqQpXJjbBqSojY/S+KehQ=; b=sklktam89/3cv7g+4hr6twBu383atQOte18fCfnt0g8b2qT2vJ4qer2WS4DD91236b iadu3Wp3r0m6AI+XlFlbU2rvAlK+fIZTSJRAe86yxomy3MxgeQBTsPOSQ1/ZIkEtqBr3 xlislDdDJS6GYQcr10C6LTmDoYMVmllZvKq6ZTGsg9TA2U/SFP8HB+d49ZO1CO9ou5x1 uHnU5xXTz24ugayTJwtrf4E9d+Cpr4idm6SqoxsL+/CWsOy9VTWG0xcpRLs07SmJt9QM 1jf7AZrYmHMJRWb4g8PndgcowXFzKUZ3PdzzoqvQY7FWvgc2l081G3OWwVCZrt0R2Xh4 pz/Q== X-Gm-Message-State: AOAM533jyCazl0PzjQA9hcF7BmyFKzGfFX5fHcEwmt+9Kc7AjnlNq7Il zuc6AdmiR3Ixoiln2XHNbO7CFl6YW+sb7Q== X-Google-Smtp-Source: ABdhPJxarC4A+xg5/+oDhKt6Wr6FxrE9n26HI6yA4s/+renYEmQBAxYqA5p7bu8cTnXRHtELqjdfcw== X-Received: by 2002:aa7:9e0d:0:b0:447:cd37:b36d with SMTP id y13-20020aa79e0d000000b00447cd37b36dmr434316pfq.71.1632109040758; Sun, 19 Sep 2021 20:37:20 -0700 (PDT) Received: from fedora34.. (125x103x255x1.ap125.ftth.ucom.ne.jp. [125.103.255.1]) by smtp.gmail.com with ESMTPSA id v25sm11932301pfm.202.2021.09.19.20.37.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Sep 2021 20:37:20 -0700 (PDT) From: QI Fuli X-Google-Original-From: QI Fuli To: ltp@lists.linux.it Date: Mon, 20 Sep 2021 12:37:01 +0900 Message-Id: <20210920033705.20544-2-qi.fuli@fujitsu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210920033705.20544-1-qi.fuli@fujitsu.com> References: <20210920033705.20544-1-qi.fuli@fujitsu.com> MIME-Version: 1.0 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,FREEMAIL_FROM,SPF_HELO_NONE,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 v6 1/5] syscalls/dup2/dup201: Convert to new API 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: , Cc: QI Fuli Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: QI Fuli Signed-off-by: QI Fuli --- testcases/kernel/syscalls/dup2/dup201.c | 174 +++++------------------- 1 file changed, 33 insertions(+), 141 deletions(-) diff --git a/testcases/kernel/syscalls/dup2/dup201.c b/testcases/kernel/syscalls/dup2/dup201.c index 4fa34466a..d851eea78 100644 --- a/testcases/kernel/syscalls/dup2/dup201.c +++ b/testcases/kernel/syscalls/dup2/dup201.c @@ -1,163 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (c) International Business Machines Corp., 2001 + * 07/2001 Ported by Wayne Boyer + * 01/2002 Removed EMFILE test - Paul Larson */ - -/* - * NAME - * dup201.c - * - * DESCRIPTION - * Negative tests for dup2() with bad fd (EBADF) - * - * ALGORITHM - * Setup: - * a. Setup signal handling. - * b. Pause for SIGUSR1 if option specified. - * - * Test: - * a. Loop if the proper options are given. - * b. Loop through the test cases - * c. Execute dup2() system call - * d. Check return code, if system call failed (return=-1), test - * for EBADF. - * - * Cleanup: - * a. Print errno log and/or timing stats if options given +/*\ + * [Description] * - * USAGE: - * dup201 [-c n] [-e] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. + * Negative tests for dup2() with bad fd (EBADF). * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * 01/2002 Removed EMFILE test - Paul Larson + * - First fd argument is less than 0 + * - First fd argument is getdtablesize() + * - Second fd argument is less than 0 + * - Second fd argument is getdtablesize() * - * RESTRICTIONS - * NONE */ -#include -#include #include -#include -#include #include -#include -#include "test.h" +#include "tst_test.h" -void setup(void); -void cleanup(void); +static int maxfd, mystdout; +static int goodfd = 5; +static int badfd = -1; -char *TCID = "dup201"; -int TST_TOTAL = 4; - -int maxfd; -int goodfd = 5; -int badfd = -1; -int mystdout = 0; - -struct test_case_t { +static struct tcase { int *ofd; int *nfd; - int error; - void (*setupfunc) (); -} TC[] = { - /* First fd argument is less than 0 - EBADF */ - {&badfd, &goodfd, EBADF, NULL}, - /* First fd argument is getdtablesize() - EBADF */ - {&maxfd, &goodfd, EBADF, NULL}, - /* Second fd argument is less than 0 - EBADF */ - {&mystdout, &badfd, EBADF, NULL}, - /* Second fd argument is getdtablesize() - EBADF */ - {&mystdout, &maxfd, EBADF, NULL}, +} tcases[] = { + {&badfd, &goodfd}, + {&maxfd, &goodfd}, + {&mystdout, &badfd}, + {&mystdout, &maxfd}, }; -int main(int ac, char **av) +static void setup(void) { - int lc; - int i; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* loop through the test cases */ - - for (i = 0; i < TST_TOTAL; i++) { - - /* call the test case setup routine if necessary */ - if (TC[i].setupfunc != NULL) - (*TC[i].setupfunc) (); - - TEST(dup2(*TC[i].ofd, *TC[i].nfd)); - - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "call succeeded unexpectedly"); - continue; - } - - if (TEST_ERRNO == TC[i].error) { - tst_resm(TPASS, - "failed as expected - errno = %d : %s", - TEST_ERRNO, strerror(TEST_ERRNO)); - } else { - tst_resm(TFAIL | TTERRNO, - "failed unexpectedly; " - "expected %d: %s", TC[i].error, - strerror(TC[i].error)); - } - } - } - cleanup(); - - tst_exit(); -} - -/* - * setup() - performs all ONE TIME setup for this test. - */ -void setup(void) -{ - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - tst_tmpdir(); - /* get some test specific values */ maxfd = getdtablesize(); } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) +static void run(unsigned int i) { - tst_rmdir(); + struct tcase *tc = tcases + i; + + TST_EXP_FAIL2(dup2(*tc->ofd, *tc->nfd), EBADF, + "dup2(%d, %d)", *tc->ofd, *tc->nfd); } + +static struct tst_test test = { + .tcnt = ARRAY_SIZE(tcases), + .test = run, + .setup = setup, +}; From patchwork Mon Sep 20 03:37:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: QI Fuli X-Patchwork-Id: 1529932 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=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=axP1M1C/; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) 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=) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (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 4HCVcr3L0yz9sW4 for ; Mon, 20 Sep 2021 13:37:48 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id DFD643C2BEC for ; Mon, 20 Sep 2021 05:37:45 +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 [IPv6:2001:4b78:1:20::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 D2A263C4CF6 for ; Mon, 20 Sep 2021 05:37:25 +0200 (CEST) Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id D8D3410005C3 for ; Mon, 20 Sep 2021 05:37:24 +0200 (CEST) Received: by mail-pg1-x52f.google.com with SMTP id f129so15986016pgc.1 for ; Sun, 19 Sep 2021 20:37:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9oRya5gv0uqn2LVWx3hiNRcH6XbYORQXsei93SUqn80=; b=axP1M1C/r7rljDJJqISgjXc+M2w0fOWXfAyLICzDZNQnCS1CDw2o2+KQdh2z1XLils Y+myzZ7AaF4XfA7etTXHJVGke6VPVlM/BlnQ5IyxWUZCB/5nug9Wl7RfLScGBE5fepcv 0EcyLRE7onZIfT2/uqYqleZFlTthOj6unmdaS6XmKjLFrgqPqGp6g0hsSRf7A34ev2VC H3PVbzwvIerFKO8bdWkadx0U8bVAHMhT3rL7Ewhu9lSBVJf5OTCJ1OjWXy0nd5E/jDp7 XDvpKZtFCDcVyJMewrY9XtPweOuqXsidMoFXJ3yKAVti2CrCjbdCgWI2XqO0OCfM5CUj Efkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9oRya5gv0uqn2LVWx3hiNRcH6XbYORQXsei93SUqn80=; b=wYo47Km04qubkX1/mpeArfPt2fk1pR4qj97m9COEQ5ySMjuXXgAdPPvZLeYYxizd2b XsPzznEEbWGOQgCPODI+FwgvwC3OOZSeKdh80csZAFwBbadwENuLq0RMSmGESkkuACbw 2hORmoB1ysj1vq00XE+3DRnGiSeLDvZ5cMmg6gajm5H8uexEqOOEQUjU73f3YOOZd8ED ppBY8l7/dPzRfLG3Q+DubVO9zMEOup6sDeNkLdcJd9oPMoegQ8HiXMQRPY/0CIMsqesK uPCmh2siD6F9jIrYsn3r22Pu96XYzBrbpBSVcB00cYunfU1M8ty+siOACHJcfGnm/HTe 56Mw== X-Gm-Message-State: AOAM5336LL3bt9HtjxgwPdEgf2tyes61inFzwRIOtXG0GiGXQFcczuRu C3EboSFWN4Xfawhn+XOVdN3S6HQWqut4GA== X-Google-Smtp-Source: ABdhPJyl64TYVwwLrL3e7bM1Vbg5JgrUmpd+WrmLZNg2xqmUnc6D6lL2eI6HHg36IFbR68tvxfCh8Q== X-Received: by 2002:aa7:9e9a:0:b0:447:a1be:ee48 with SMTP id p26-20020aa79e9a000000b00447a1beee48mr5950838pfq.48.1632109043263; Sun, 19 Sep 2021 20:37:23 -0700 (PDT) Received: from fedora34.. (125x103x255x1.ap125.ftth.ucom.ne.jp. [125.103.255.1]) by smtp.gmail.com with ESMTPSA id v25sm11932301pfm.202.2021.09.19.20.37.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Sep 2021 20:37:22 -0700 (PDT) From: QI Fuli X-Google-Original-From: QI Fuli To: ltp@lists.linux.it Date: Mon, 20 Sep 2021 12:37:02 +0900 Message-Id: <20210920033705.20544-3-qi.fuli@fujitsu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210920033705.20544-1-qi.fuli@fujitsu.com> References: <20210920033705.20544-1-qi.fuli@fujitsu.com> MIME-Version: 1.0 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,FREEMAIL_FROM,SPF_HELO_NONE,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 v6 2/5] syscalls/dup2/dup202: Convert to new API 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: , Cc: QI Fuli Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: QI Fuli Signed-off-by: QI Fuli --- testcases/kernel/syscalls/dup2/dup202.c | 196 +++++++----------------- 1 file changed, 58 insertions(+), 138 deletions(-) diff --git a/testcases/kernel/syscalls/dup2/dup202.c b/testcases/kernel/syscalls/dup2/dup202.c index c87769fa9..feba0469a 100644 --- a/testcases/kernel/syscalls/dup2/dup202.c +++ b/testcases/kernel/syscalls/dup2/dup202.c @@ -1,167 +1,87 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (c) International Business Machines Corp., 2001 + * 07/2001 Ported by Wayne Boyer */ -/* - * NAME - * dup202.c +/*\ + * [Description] * - * DESCRIPTION - * Is the access mode the same for both file descriptors? - * 0: read only ? "0444" - * 1: write only ? "0222" - * 2: read/write ? "0666" + * Test whether the access mode are the same for both file descriptors. * - * ALGORITHM - * Creat a file with each access mode; dup each file descriptor; - * stat each file descriptor and compare modes of each pair - * - * USAGE: - * dup202 [-c n] [-f] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -f : Turn off functionality Testing. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * - * RESTRICTIONS - * None + * - 0: read only ? "0444" + * - 1: write only ? "0222" + * - 2: read/write ? "0666" */ -#include -#include #include -#include #include -#include "test.h" -#include "safe_macros.h" - -char *TCID = "dup202"; -int TST_TOTAL = 3; - -void setup(void); -void cleanup(void); +#include +#include "tst_test.h" +#include "tst_safe_macros.h" -char testfile[40]; -int fail; -int newfd; +static char testfile[40]; +static int ofd = -1, nfd = -1; /* set these to a known index into our local file descriptor table */ -int duprdo = 10, dupwro = 20, duprdwr = 30; +static int duprdo = 10, dupwro = 20, duprdwr = 30; -struct test_case_t { +static struct tcase { int *nfd; mode_t mode; -} TC[] = { - /* The first test creat(es) a file with mode 0444 */ - { - &duprdo, (S_IRUSR | S_IRGRP | S_IROTH)}, - /* The second test creat(es) a file with mode 0222 */ - { - &dupwro, (S_IWUSR | S_IWGRP | S_IWOTH)}, - /* The third test creat(es) a file with mode 0666 */ - { - &duprdwr, - (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IWGRP | S_IWOTH)} +} tcases[]= { + {&duprdo, (S_IRUSR | S_IRGRP | S_IROTH)}, + {&dupwro, (S_IWUSR | S_IWGRP | S_IWOTH)}, + {&duprdwr, (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IWGRP | S_IWOTH)}, }; -int main(int ac, char **av) +static void setup(void) { - int lc; - int i, ofd; - struct stat oldbuf, newbuf; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* loop through the test cases */ - for (i = 0; i < TST_TOTAL; i++) { - - if ((ofd = creat(testfile, TC[i].mode)) == -1) - tst_brkm(TBROK | TERRNO, cleanup, - "creat failed"); - - TEST(dup2(ofd, *TC[i].nfd)); - - if (TEST_RETURN == -1) { - tst_resm(TFAIL | TTERRNO, - "call failed unexpectedly"); - continue; - } - - /* stat the original file */ - SAFE_FSTAT(cleanup, ofd, &oldbuf); - - /* stat the duped file */ - SAFE_FSTAT(cleanup, *TC[i].nfd, &newbuf); - - if (oldbuf.st_mode != newbuf.st_mode) - tst_resm(TFAIL, "original and dup " - "modes do not match"); - else - tst_resm(TPASS, "fstat shows new and " - "old modes are the same"); - - /* remove the file so that we can use it again */ - if (close(*TC[i].nfd) == -1) - perror("close failed"); - if (close(ofd) == -1) - perror("close failed"); - if (unlink(testfile) == -1) - perror("unlink failed"); - } - } + umask(0); + sprintf(testfile, "dup202.%d", getpid()); +} - cleanup(); - tst_exit(); +static void cleanup(void) +{ + close(ofd); + close(nfd); } -/* - * setup() - performs all ONE TIME setup for this test. - */ -void setup(void) +static void run(unsigned int i) { + struct stat oldbuf, newbuf; + struct tcase *tc = tcases + i; - tst_sig(NOFORK, DEF_HANDLER, cleanup); + ofd = SAFE_CREAT(testfile, tc->mode); + nfd = *tc->nfd; - TEST_PAUSE; + TEST(dup2(ofd, nfd)); + if (TST_RET == -1) { + tst_res(TFAIL | TTERRNO, "call failed unexpectedly"); + goto free; + } - tst_tmpdir(); + SAFE_FSTAT(ofd, &oldbuf); - (void)umask(0); + SAFE_FSTAT(nfd, &newbuf); - sprintf(testfile, "dup202.%d", getpid()); -} + if (oldbuf.st_mode != newbuf.st_mode) + tst_res(TFAIL, "original(%o) and duped(%o) are not same mode", + oldbuf.st_mode, newbuf.st_mode); + else + tst_res(TPASS, "original(%o) and duped(%o) are the same mode", + oldbuf.st_mode, newbuf.st_mode); -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) -{ - tst_rmdir(); + SAFE_CLOSE(nfd); +free: + SAFE_CLOSE(ofd); + SAFE_UNLINK(testfile); } + +static struct tst_test test = { + .needs_tmpdir = 1, + .tcnt = ARRAY_SIZE(tcases), + .test = run, + .setup = setup, + .cleanup = cleanup, +}; From patchwork Mon Sep 20 03:37:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: QI Fuli X-Patchwork-Id: 1529933 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=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=Olz4OFlN; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) 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=) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (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 4HCVd31Bwkz9sW4 for ; Mon, 20 Sep 2021 13:37:59 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id A4F153C2E5D for ; Mon, 20 Sep 2021 05:37:56 +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 [IPv6:2001:4b78:1:20::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 C9D063C4D0A for ; Mon, 20 Sep 2021 05:37:27 +0200 (CEST) Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id 1C1C6100092F for ; Mon, 20 Sep 2021 05:37:27 +0200 (CEST) Received: by mail-pf1-x433.google.com with SMTP id w14so4462074pfu.2 for ; Sun, 19 Sep 2021 20:37:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UVTC6roXEW2WOYlZ4KsAyZEtp2GPKd9vdQbrWuea/rc=; b=Olz4OFlNEyMIzeOQZjYXLOc50OXTxvNoEQYetD2fUz/qvyzi5CE13rbrlQQzKMy9SC YK8Gafhv2zH4+9EuNrtK9xIlaDAQWHHpIqEmJuD2SsZp3hEQxZdX1ICZcDmd3v/1DySI i0uU0H6fz7TBdxfyQ92+6ZR4mg4Qm+LAnWmTkB3igTZesDaV3pOZn6BOadxF7j9kplVd 5Ge5SJGkiTe3SGDYQAA+mhYu3l/ct4xNk7XiQrYs1JqsMYsyUpLAgkNtG52FL5s837OM 9EU5bnYQ6yFDsj3BAF6Wv9bnduUJ7q2OZLky2OkZp1TLrpCpn82T07rbCQ09cJtBDJXA lduA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UVTC6roXEW2WOYlZ4KsAyZEtp2GPKd9vdQbrWuea/rc=; b=BDF1EwJ8zlkXnJVKYMEZkrjkgnj2mHHdxAPb19X85Tu11HRdB87NGYWr0ijEOBWhBY C3GJS0qWCQCQvQUK8Hd1Er8TEhBDmfxuVloWqugQ3vfSMCNEXxAK4FvdpnuhYyBoFb4W Dg9oXMxi27ELBSue3TbZMMcO0lFI340gvMeF9MdlUMUJVjZoRd5Q3yxxmAomnckGOeuY OzXv85/ZMNU3d1rRJ6ZKQS4yf37CEBPUVo43HZcJX1+FaHdg1uHEEpBmSWnEf6bL7Rmv Ffnj6/LMCOhVLAss2Ad/5jaNepyANoOYVCalcFdhtZo7go/+0ESihEsqoLLu7uxD/bV4 7/lA== X-Gm-Message-State: AOAM533JO2r/iW7gxXM/P/M3oQs5ctur2P7momabP8U0pWDR0TwO3vr/ qGyux+6vU2dCAahP17emdRdRwsmtq/Khgw== X-Google-Smtp-Source: ABdhPJzout2Z4Kxsk6udQCdY4buxAi79907nLUJIxyEaQn5VRJKwYvZ8NHON+m9ZeLrVfUai4ndvSA== X-Received: by 2002:aa7:9115:0:b029:359:69db:bc89 with SMTP id 21-20020aa791150000b029035969dbbc89mr23303283pfh.32.1632109045450; Sun, 19 Sep 2021 20:37:25 -0700 (PDT) Received: from fedora34.. (125x103x255x1.ap125.ftth.ucom.ne.jp. [125.103.255.1]) by smtp.gmail.com with ESMTPSA id v25sm11932301pfm.202.2021.09.19.20.37.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Sep 2021 20:37:25 -0700 (PDT) From: QI Fuli X-Google-Original-From: QI Fuli To: ltp@lists.linux.it Date: Mon, 20 Sep 2021 12:37:03 +0900 Message-Id: <20210920033705.20544-4-qi.fuli@fujitsu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210920033705.20544-1-qi.fuli@fujitsu.com> References: <20210920033705.20544-1-qi.fuli@fujitsu.com> MIME-Version: 1.0 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,FREEMAIL_FROM,SPF_HELO_NONE,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 v6 3/5] syscalls/dup2/dup203: Convert to new API 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: , Cc: QI Fuli Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: QI Fuli Signed-off-by: QI Fuli --- testcases/kernel/syscalls/dup2/dup203.c | 265 ++++++++---------------- 1 file changed, 83 insertions(+), 182 deletions(-) diff --git a/testcases/kernel/syscalls/dup2/dup203.c b/testcases/kernel/syscalls/dup2/dup203.c index e6f281adf..d2f54304d 100644 --- a/testcases/kernel/syscalls/dup2/dup203.c +++ b/testcases/kernel/syscalls/dup2/dup203.c @@ -1,208 +1,109 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (c) International Business Machines Corp., 2001 + * 07/2001 Ported by Wayne Boyer */ -/* - * NAME - * dup203.c +/*\ + * [Description] * - * DESCRIPTION - * Testcase to check the basic functionality of dup2(). + * Testcase to check the basic functionality of dup2(). * - * ALGORITHM - * 1. Attempt to dup2() on an open file descriptor. - * 2. Attempt to dup2() on a close file descriptor. - * - * USAGE: - * dup203 [-c n] [-f] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -f : Turn off functionality Testing. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * - * RESTRICTIONS - * NONE + * - Attempt to dup2() on an open file descriptor. + * - Attempt to dup2() on a close file descriptor. */ -#include -#include #include -#include -#include "test.h" -#include "safe_macros.h" - -void setup(void); -void cleanup(void); - -char *TCID = "dup203"; -int TST_TOTAL = 1; - -int main(int ac, char **av) +#include +#include +#include "tst_test.h" +#include "tst_safe_macros.h" + +static char filename0[40], filename1[40]; +static int fd0, fd1; + +static struct tcase { + char *desc; + int is_close; +} tcases[] = { + {"Test duping over an open fd", 0}, + {"Test duping over a close fd", 1}, +}; + +static void run(unsigned int i) { - int fd0, fd1, fd2, rval; - char filename0[40], filename1[40]; + int fd2, rval; char buf[40]; - int lc; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; -//block1: - tst_resm(TINFO, "Enter block 1"); - tst_resm(TINFO, "Test duping over an open fd"); - - sprintf(filename0, "dup202.file0.%d\n", getpid()); - sprintf(filename1, "dup202.file1.%d\n", getpid()); - unlink(filename0); - unlink(filename1); - - if ((fd0 = creat(filename0, 0666)) == -1) - tst_brkm(TBROK, cleanup, "cannot create first file"); - if (write(fd0, filename0, strlen(filename0)) == -1) - tst_brkm(TBROK, cleanup, "filename0: write(2) failed"); - - if ((fd1 = creat(filename1, 0666)) == -1) - tst_brkm(TBROK, cleanup, "Cannot create second file"); - if (write(fd1, filename1, strlen(filename1)) == -1) - tst_brkm(TBROK, cleanup, "filename1: write(2) failed"); + struct tcase *tc = tcases + i; - SAFE_CLOSE(cleanup, fd0); - if ((fd0 = open(filename0, O_RDONLY)) == -1) - tst_brkm(TBROK, cleanup, "open(2) on filename0 failed"); + tst_res(TINFO, tc->desc); - SAFE_CLOSE(cleanup, fd1); - if ((fd1 = open(filename1, O_RDONLY)) == -1) - tst_brkm(TBROK, cleanup, "open(2) on filename1 failed"); + fd0 = SAFE_CREAT(filename0, 0666); + SAFE_WRITE(1, fd0, filename0, strlen(filename0)); + SAFE_CLOSE(fd0); - TEST(dup2(fd0, fd1)); - - if ((fd2 = TEST_RETURN) == -1) { - tst_resm(TFAIL, "call failed unexpectedly"); - } else { - if (fd1 != fd2) { - tst_resm(TFAIL, "file descriptors don't match"); - break; - } - - memset(buf, 0, sizeof(buf)); - if (read(fd2, buf, sizeof(buf)) == -1) - tst_brkm(TBROK, cleanup, "read(2) failed"); - if (strcmp(buf, filename0) != 0) - tst_resm(TFAIL, "read from file got bad data"); - tst_resm(TPASS, "dup2 test 1 functionality is correct"); - } - - close(fd0); - close(fd1); - close(fd2); - unlink(filename0); - unlink(filename1); - - tst_resm(TINFO, "Exit block 1"); - -//block2: - tst_resm(TINFO, "Enter block 2"); - tst_resm(TINFO, "Test close on exec flag"); - - sprintf(filename0, "dup02.%d\n", getpid()); - unlink(filename0); - - if ((fd0 = creat(filename0, 0666)) == -1) { - tst_brkm(TBROK, cleanup, "Cannot create first file"); - } - if (fcntl(fd0, F_SETFD, 1) == -1) { - tst_brkm(TBROK, cleanup, "setting close on exec flag " - "on fd0 failed"); - } - - if ((fd2 = creat(filename1, 0666)) == -1) { - tst_brkm(TBROK, cleanup, "Cannot create second file"); - } + fd1 = SAFE_CREAT(filename1, 0666); + SAFE_WRITE(1, fd1, filename1, strlen(filename1)); + fd0 = SAFE_OPEN(filename0, O_RDONLY); + SAFE_FCNTL(fd0, F_SETFD, 1); + if (tc->is_close) { /* SAFE_CLOSE() sets the fd to -1 avoid it here */ - rval = fd2; - SAFE_CLOSE(cleanup, rval); - - TEST(dup2(fd0, fd2)); - - if ((fd1 = TEST_RETURN) == -1) { - tst_resm(TFAIL, "call failed unexpectedly"); - } else { - if (fd1 != fd2) { - tst_resm(TFAIL, "bad dup2 descriptor %d", fd1); - break; - } - - if ((rval = fcntl(fd1, F_GETFD, 0)) != 0) { - tst_resm(TBROK | TERRNO, - "fcntl F_GETFD on fd1 failed; expected a " - "return value of 0x0, got %#x", rval); - break; - } - if ((rval = (fcntl(fd0, F_GETFL, 0) & O_ACCMODE)) != - O_WRONLY) { - tst_resm(TFAIL, "fctnl F_GETFL bad rval on fd0 " - "Expected %#x got %#x", O_WRONLY, - rval); - } - tst_resm(TPASS, "dup2 test 2 functionality is correct"); - } - - close(fd0); - close(fd1); - - unlink(filename0); - unlink(filename1); - tst_resm(TINFO, "Exit block 2"); + rval = fd1; + SAFE_CLOSE(rval); + } + + TEST(dup2(fd0, fd1)); + fd2 = TST_RET; + if (TST_RET == -1) { + tst_res(TFAIL, "call failed unexpectedly"); + goto free; + } + if (fd1 != fd2) { + tst_res(TFAIL, "file descriptors don't match"); + goto free; } - cleanup(); - tst_exit(); + memset(buf, 0, sizeof(buf)); + SAFE_READ(0, fd2, buf, sizeof(buf)); + if (strcmp(buf, filename0) != 0) + tst_res(TFAIL, "read from file got bad data"); + else + tst_res(TPASS, "test the content of file is correct"); + + rval = SAFE_FCNTL(fd2, F_GETFD); + if (rval != 0) + tst_res(TFAIL, "fcntl F_GETFD on fd2 failed; expected a " + "return value of 0x0, got %#x", rval); + else + tst_res(TPASS, "test the FD_CLOEXEC flag is correct"); +free: + SAFE_CLOSE(fd0); + SAFE_CLOSE(fd1); + SAFE_UNLINK(filename0); + SAFE_UNLINK(filename1); } -/* - * setup() - performs all ONE TIME setup for this test. - */ -void setup(void) +static void setup(void) { + int pid; - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - tst_tmpdir(); + pid = getpid(); + sprintf(filename0, "dup203.file0.%d\n", pid); + sprintf(filename1, "dup203.file1.%d\n", pid); } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) +static void cleanup(void) { - tst_rmdir(); + close(fd0); + close(fd1); } + +static struct tst_test test = { + .setup = setup, + .tcnt = ARRAY_SIZE(tcases), + .needs_tmpdir = 1, + .test = run, + .cleanup = cleanup, +}; From patchwork Mon Sep 20 03:37:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: QI Fuli X-Patchwork-Id: 1529934 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=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=AcDPAgam; 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 4HCVdG5np5z9sW4 for ; Mon, 20 Sep 2021 13:38:10 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 387B43C2DB2 for ; Mon, 20 Sep 2021 05:38:06 +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)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id E14933C31F6 for ; Mon, 20 Sep 2021 05:37:29 +0200 (CEST) Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 38E8A200275 for ; Mon, 20 Sep 2021 05:37:29 +0200 (CEST) Received: by mail-pg1-x536.google.com with SMTP id h3so15971365pgb.7 for ; Sun, 19 Sep 2021 20:37:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U68Ql/MLGJ1D00I9dYDqSUExgIbxpDn1WIY28wFaM90=; b=AcDPAgamhVjRjeiQjYP8uhp3s48ul8/XeI0EDOzARl/FAz1cMExXyAsrSEl5Tq63AY QcdQltLFZ36nFYro42IcDeon1i3HvPE6vCYZN86CUIPm+9EkZliJi9TTq/ZiR92aWRWG a7LPcdXJnHzyiIrDL6hCtr19ShrowAPfYGmgcCtkspc1+OofdwbUdfW4oWIXSfz06RYV RZUQFl+Z8IDSr/oGykRlj9Rjuu9qaNwt/BQyo2KLqlzCiNKRRXbqJT4VJHV6ZVhe6Lcz CijrfXnj+j6mPRe3ytvmWAuyMv8I1iz2En/lNnMVzPtfpfGKxePJ2ra0Ll7m5jRpMiFB RVQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=U68Ql/MLGJ1D00I9dYDqSUExgIbxpDn1WIY28wFaM90=; b=EM4hEx2ZbPZUu1UAqtUagvEqe6ulJm0E6efzGKSppfsvNO4MTDxubkX4w2T6JhlMlc 8ETDOOxn/7z2pxdMoEqe31jKYpevrE+uOiPd51Z2uTbeOmnvKOyufSDQijKzwyzI+j6X ETC9/MN7Kgg1uwUn5H0+HdKZ8OxJ9UecKfStVULa1Nku7UbB0HG9WFur2DiAC+3Xbz1C 0pQdherpk29/wla7xSm0XtX0TmQRBYeiT/wC3kpsAE0RSL9IHz+qsIabM4cspTwwLs/u 1uXfIUJC7J2MwTvYP9RtFNGj3gJN5BDFkhvqbkkK8gu9M5k17buZfK0ie7zgdISZzzUi g2KQ== X-Gm-Message-State: AOAM532XZkjHoMa5RhRmiM3RAOP7Cy48Vg4h2Ccf1yV72I8wkFKC+wMh BdEVsdMUWlwOq3hqlnRqH5F2xVmcO2kk7A== X-Google-Smtp-Source: ABdhPJxUBQEZYld3V1V+1ymIImtIQ28cV49d75RvdaqBGPzG3/5cPrB8qQu3zvVXg+XYQCz5ndlpbw== X-Received: by 2002:a65:64d7:: with SMTP id t23mr21306678pgv.237.1632109047633; Sun, 19 Sep 2021 20:37:27 -0700 (PDT) Received: from fedora34.. (125x103x255x1.ap125.ftth.ucom.ne.jp. [125.103.255.1]) by smtp.gmail.com with ESMTPSA id v25sm11932301pfm.202.2021.09.19.20.37.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Sep 2021 20:37:27 -0700 (PDT) From: QI Fuli X-Google-Original-From: QI Fuli To: ltp@lists.linux.it Date: Mon, 20 Sep 2021 12:37:04 +0900 Message-Id: <20210920033705.20544-5-qi.fuli@fujitsu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210920033705.20544-1-qi.fuli@fujitsu.com> References: <20210920033705.20544-1-qi.fuli@fujitsu.com> MIME-Version: 1.0 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,FREEMAIL_FROM,SPF_HELO_NONE,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 v6 4/5] syscalls/dup2/dup204: Convert to new API 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: , Cc: QI Fuli Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: QI Fuli Signed-off-by: QI Fuli --- testcases/kernel/syscalls/dup2/dup204.c | 147 +++++++----------------- 1 file changed, 40 insertions(+), 107 deletions(-) diff --git a/testcases/kernel/syscalls/dup2/dup204.c b/testcases/kernel/syscalls/dup2/dup204.c index a357bc17e..c9304d5c3 100644 --- a/testcases/kernel/syscalls/dup2/dup204.c +++ b/testcases/kernel/syscalls/dup2/dup204.c @@ -1,128 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* + * Copyright (c) International Business Machines Corp., 2001 * - * Copyright (c) International Business Machines Corp., 2001 + * [Description] * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Test whether the inode number are the same for both file descriptors. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - * NAME - * dup204.c - * - * DESCRIPTION - * Testcase to check the basic functionality of dup2(2). - * - * ALGORITHM - * attempt to call dup2() on read/write ends of a pipe - * - * USAGE: - * dup204 [-c n] [-f] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -f : Turn off functionality Testing. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * RESTRICTION - * NONE */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif -#include -#include -#include -#include -#include -#include -#include "test.h" -#include "safe_macros.h" +#include +#include "tst_test.h" +#include "tst_safe_macros.h" -void setup(); -void cleanup(); +static int fd[2] = {-1, -1}; +static int nfd[2] = {10, 20}; -char *TCID = "dup204"; -int TST_TOTAL = 2; - -int fd[2]; -int nfd[2]; - -int main(int ac, char **av) +static void setup(void) { - int lc; - int i; - struct stat oldbuf, newbuf; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* loop through the test cases */ - for (i = 0; i < TST_TOTAL; i++) { - TEST(dup2(fd[i], nfd[i])); - - if (TEST_RETURN == -1) { - tst_resm(TFAIL, "call failed unexpectedly"); - continue; - } - - SAFE_FSTAT(cleanup, fd[i], &oldbuf); - SAFE_FSTAT(cleanup, nfd[i], &newbuf); + SAFE_PIPE(fd); +} - if (oldbuf.st_ino != newbuf.st_ino) - tst_resm(TFAIL, "original and duped " - "inodes do not match"); - else - tst_resm(TPASS, "original and duped " - "inodes are the same"); +static void cleanup(void) +{ + unsigned int i; - SAFE_CLOSE(cleanup, TEST_RETURN); - } + for (i = 0; i < ARRAY_SIZE(fd); i++) { + close(fd[i]); + close(nfd[i]); } - - cleanup(); - tst_exit(); } -void setup(void) +static void run(unsigned int i) { - fd[0] = -1; + struct stat oldbuf, newbuf; - tst_sig(FORK, DEF_HANDLER, cleanup); + TEST(dup2(fd[i], nfd[i])); + if (TST_RET == -1) { + tst_res(TFAIL, "call failed unexpectedly"); + return; + } - TEST_PAUSE; + SAFE_FSTAT(fd[i], &oldbuf); + SAFE_FSTAT(nfd[i], &newbuf); - tst_tmpdir(); + if (oldbuf.st_ino != newbuf.st_ino) + tst_res(TFAIL, "original inode(%ld) and duped inode(%ld) " + "do not match", oldbuf.st_ino, newbuf.st_ino); + else + tst_res(TPASS, "original inode(%ld) and duped inode(%ld) " + "are the same", oldbuf.st_ino, newbuf.st_ino); - SAFE_PIPE(cleanup, fd); + SAFE_CLOSE(TST_RET); } -void cleanup(void) -{ - int i; - - for (i = 0; i < (int)ARRAY_SIZE(fd); i++) { - close(fd[i]); - close(nfd[i]); - } - - tst_rmdir(); -} +static struct tst_test test = { + .tcnt = ARRAY_SIZE(fd), + .test = run, + .setup = setup, + .cleanup = cleanup, +}; From patchwork Mon Sep 20 03:37:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: QI Fuli X-Patchwork-Id: 1529935 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=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=AtNk/iep; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) 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=) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (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 4HCVdR6b3Jz9sW5 for ; Mon, 20 Sep 2021 13:38:19 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 68EF53C2FFD for ; Mon, 20 Sep 2021 05:38:17 +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]) (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 D06F23C2DB2 for ; Mon, 20 Sep 2021 05:37:32 +0200 (CEST) Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id 7C7901A0069C for ; Mon, 20 Sep 2021 05:37:31 +0200 (CEST) Received: by mail-pj1-x102e.google.com with SMTP id nn5-20020a17090b38c500b0019af1c4b31fso11631444pjb.3 for ; Sun, 19 Sep 2021 20:37:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=n2QTp+lzQ3hv3mA8hPimA9uJDaQPOcOuc7Gyq/kxKCU=; b=AtNk/iepBo4qrYhljbWppYoRucAV7wg5TRoLijQDuhsaeXkXJv8RNJGRIuD7ngQh2l iW6WB2+jIiC6aLArH5e23QgQEvbISagxnuTa3RWj+rvHOmt/E/xJou9Ep0r6Lcjv5oQ2 sJKDeziQ4X/VSFoqvUJyLhGOkSMOECH47TH2IPJUmk7hrm1AwVv6rKAadXcX/fN7h+xh WhTZgs56SR4LGdnPSCamNawr0fpsm9sh6Xg+NoCpUTJq4VLV4JRnJcV6GeL1oTKLcKeI 4KOaa9OkcH+CndwCZCAOPZC0FN0CcGa58zWoMsaeiTu5PSGCTLDiQGLtkn35G46cCvYk dYog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=n2QTp+lzQ3hv3mA8hPimA9uJDaQPOcOuc7Gyq/kxKCU=; b=ZtjHlUc+WLvCR2sDU8xCVR3D/rrzpzO1ATuYNkaNiGYzRt29sTAa6+23Pesj2VvGOQ 9PMUdhzG9o/liNJFLfRboPgfhy44XLXV4HXzcDXwIsJRYv0ngfXKFl5e8b8GyO9GOMx2 Mg8EkbLCLtT7I2hWQSqUyWO7k98xJZJb4UcIa9N71nhmAwauoAvfDlYDNkKM+UZf3XYH Lpdcfey75fxRshsGby7gTDpRGI+2N4AaCybz93cEMlw5NiJGWGEaGAnwgXftkBEe+w3W 9pSKsax5PQ4mi1B0mxekmhZbP/GsdFNfkRm/RcU8TJ/wgJXAolKfhfsgd/aOQTva2xHL X+Aw== X-Gm-Message-State: AOAM532pyr1nUrEuq84PcmxHRxhKilfLEtecNg0xzPs7v+C9c2KDx+8P C8IWvQ9T+EPneE3HtxVMQkSLfUJAdyS0TQ== X-Google-Smtp-Source: ABdhPJyxUMM2KAdcB4SAC3PMRUcq7B8/C2eCJQOtC9bbDbMgS55GAcA06Gs1kCZt3KyqWgYtalCjDA== X-Received: by 2002:a17:902:be0f:b0:13a:95e:a51 with SMTP id r15-20020a170902be0f00b0013a095e0a51mr20829051pls.44.1632109049945; Sun, 19 Sep 2021 20:37:29 -0700 (PDT) Received: from fedora34.. (125x103x255x1.ap125.ftth.ucom.ne.jp. [125.103.255.1]) by smtp.gmail.com with ESMTPSA id v25sm11932301pfm.202.2021.09.19.20.37.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Sep 2021 20:37:29 -0700 (PDT) From: QI Fuli X-Google-Original-From: QI Fuli To: ltp@lists.linux.it Date: Mon, 20 Sep 2021 12:37:05 +0900 Message-Id: <20210920033705.20544-6-qi.fuli@fujitsu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210920033705.20544-1-qi.fuli@fujitsu.com> References: <20210920033705.20544-1-qi.fuli@fujitsu.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-3.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,FREEMAIL_FROM,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH v6 5/5] syscalls/dup2/dup205: Convert to new API 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: , Cc: QI Fuli Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: QI Fuli Signed-off-by: QI Fuli --- testcases/kernel/syscalls/dup2/dup205.c | 178 +++++++++--------------- 1 file changed, 62 insertions(+), 116 deletions(-) diff --git a/testcases/kernel/syscalls/dup2/dup205.c b/testcases/kernel/syscalls/dup2/dup205.c index 0b324531f..cd4254375 100644 --- a/testcases/kernel/syscalls/dup2/dup205.c +++ b/testcases/kernel/syscalls/dup2/dup205.c @@ -1,134 +1,80 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * - * Copyright (c) International Business Machines Corp., 2002 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (c) International Business Machines Corp., 2002 + * Ported from SPIE, section2/iosuite/dup6.c, by Airong Zhang */ -/* Ported from SPIE, section2/iosuite/dup6.c, by Airong Zhang */ - -/*====================================================================== - =================== TESTPLAN SEGMENT =================== ->KEYS: < dup2() ->WHAT: < Does dup return -1 on the 21st file? ->HOW: < Create up to _NFILE files and check for -1 return on the - < next attempt - < Should check NOFILE as well as _NFILE. 19-Jun-84 Dale. ->BUGS: < -======================================================================*/ +/*\ + * [Description] + * Negative test for dup2() with max open file descriptors. + */ -#include -#include -#include -#include -#include +#include #include #include -#include "test.h" - -char *TCID = "dup205"; -int TST_TOTAL = 1; -int *fildes; -int min; -int local_flag; - -#define PASSED 1 -#define FAILED 0 - -static void setup(void); -static void cleanup(void); - -int main(int ac, char *av[]) -{ - int ifile; - char pfilname[40]; - int serrno; - - int lc; - - ifile = -1; - - tst_parse_opts(ac, av, NULL, NULL); - - local_flag = PASSED; - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - sprintf(pfilname, "./dup205.%d\n", getpid()); - unlink(pfilname); - serrno = 0; - if ((fildes[0] = creat(pfilname, 0666)) == -1) - tst_brkm(TBROK | TERRNO, cleanup, "creat failed"); - else { - fildes[fildes[0]] = fildes[0]; - for (ifile = fildes[0] + 1; ifile < min + 10; ifile++) { - if ((fildes[ifile] = dup2(fildes[ifile - 1], - ifile)) == -1) { - serrno = errno; - break; - } else { - if (fildes[ifile] != ifile) { - tst_brkm(TFAIL, cleanup, - "got wrong descriptor " - "number back (%d != %d)", - fildes[ifile], ifile); - } - } - } /* end for */ - if (ifile < min) { - tst_resm(TFAIL, "Not enough files duped"); - local_flag = FAILED; - } else if (ifile > min) { - tst_resm(TFAIL, "Too many files duped"); - local_flag = FAILED; - } - if (serrno != EBADF && serrno != EMFILE && - serrno != EINVAL) { - tst_resm(TFAIL, "bad errno on dup2 failure"); - local_flag = FAILED; - } - } - unlink(pfilname); - for (ifile = fildes[0]; ifile < min + 10; ifile++) - close(fildes[ifile]); - if (local_flag == PASSED) { - tst_resm(TPASS, "Test passed."); - } else { - tst_resm(TFAIL, "Test failed."); - } +#include "tst_test.h" +#include "tst_safe_macros.h" - } - cleanup(); - tst_exit(); -} +static int *fildes; +static int min; +static char pfilname[40]; static void setup(void) { - tst_tmpdir(); - min = getdtablesize(); /* get number of files allowed open */ - fildes = malloc((min + 10) * sizeof(int)); - if (fildes == NULL) - tst_brkm(TBROK | TERRNO, cleanup, "malloc error"); + fildes = SAFE_MALLOC((min + 10) * sizeof(int)); + memset(fildes, -1, (min + 10) * sizeof(int)); + sprintf(pfilname, "./dup205.%d\n", getpid()); } static void cleanup(void) { if (fildes != NULL) free(fildes); - tst_rmdir(); } + +static void run(void) +{ + int ifile = -1, rc = 0; + + fildes[0] = SAFE_CREAT(pfilname, 0666); + fildes[fildes[0]] = fildes[0]; + for (ifile = fildes[0] + 1; ifile < min + 10; ifile++) { + TEST(dup2(fildes[ifile - 1], ifile)); + if ((fildes[ifile] = TST_RET) == -1) + break; + if (fildes[ifile] != ifile) + tst_brk(TFAIL, "got wrong descriptor number back " + "(%d != %d)", fildes[ifile], ifile); + } + + if (ifile < min) { + tst_res(TFAIL, "Not enough files duped"); + rc++; + } else if (ifile > min) { + tst_res(TFAIL, "Too many files duped"); + rc++; + } + if (TST_ERR != EBADF && TST_ERR != EMFILE && TST_ERR != EINVAL) { + tst_res(TFAIL, "bad errno on dup2 failure"); + rc++; + } + + if (rc) + tst_res(TFAIL, "Test failed"); + else + tst_res(TPASS, "Test passed"); + + SAFE_UNLINK(pfilname); + for (ifile = fildes[0]; ifile < min + 10; ifile++) { + if (fildes[ifile] > 0) + SAFE_CLOSE(fildes[ifile]); + } +} + +static struct tst_test test = { + .needs_tmpdir = 1, + .test_all = run, + .setup = setup, + .cleanup = cleanup, +};