From patchwork Wed Sep 15 15:51:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: QI Fuli X-Patchwork-Id: 1528425 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=IzEahCfP; 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 4H8l8r2nfJz9s5R for ; Thu, 16 Sep 2021 01:52:28 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 4F0AC3C6ED8 for ; Wed, 15 Sep 2021 17:52:26 +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 [217.194.8.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 1328B3C9203 for ; Wed, 15 Sep 2021 17:52:19 +0200 (CEST) Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) (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 163E920020C for ; Wed, 15 Sep 2021 17:52:19 +0200 (CEST) Received: by mail-pg1-x535.google.com with SMTP id w7so3101681pgk.13 for ; Wed, 15 Sep 2021 08:52:19 -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=25eCUVVWMrYYqJeAL7KTyx10XTFxt2gb26yLTGOmpq0=; b=IzEahCfPsdYIKhHNXFv5EV5YGTNsFR5p5TmCewqH5dJbh042HPU7zcl6yDCP6zEL/9 N4UJlSGqCATFP7sTo93kf4DjK/H2MbPBGFu9z+X4wTJXINBd0JQ1HX5KV6NnioKRP/6q nV51ECQiMVWghySZS+3cx2rGqzITPNwqahJcziFkzI2i66l0SDp5xzF1/LDPXmUdgRJL +kYsTNaq0gfnpi9Qjsc5Dtqvd5cbrqtMnl4K6l/H4RTuAabRZYGENoN7d85sNtV4+mxf bA5YxUB4x+IUgNOzJwStUCLV43p55RtMQD8v7BB7W5c7HhhZxDauYzujAVdhbYk3qHI0 FMvQ== 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=25eCUVVWMrYYqJeAL7KTyx10XTFxt2gb26yLTGOmpq0=; b=TZgczBwmhtYrXW9I2cF4kto8x2bdjneSz6nrJ4WrQHxzXlbvirTG/R5/MU5yIhh6io AWydZweemrpB7ENm++sj8lrraPtpM42vPIGL9DXYOs+/G4lhtLnsp+TQHrVis5elzDUt vm5MDswRwetMBbQyGtHJ/JJAbaoPtncy0C8VFDKo8kQqM8ABAN+7icTkS3kJE9S6nYe1 n8jMJLoikS/lAAg0S5Rujn7n+FoWcT+a+GupriOcJFAYAm6JXvy5NUcd8hD2t7KoWU0v 9MQYe9BZiMMaKTtw6ZIIHwS0RRe2LCiwVBZtDb8NK5+BbISIKwozNq2xPLgMStnCW6uA r7sQ== X-Gm-Message-State: AOAM532kf6hQIi/adNMdcURh+FzxdiDstp5LE61nQTKX88eoJjgyzNp8 uI7lg0EUmqXNR2m9ahKowtQU4mYFEGIfA9En X-Google-Smtp-Source: ABdhPJxwD+DWVULOZ+5w7tYsueYOdQ8W7c0ETWr5ONNg1Q+3jNzXlmNqR2tv7FfmptH3Qx8+92yszw== X-Received: by 2002:a62:88d3:0:b0:43d:df95:3426 with SMTP id l202-20020a6288d3000000b0043ddf953426mr619271pfd.26.1631721137536; Wed, 15 Sep 2021 08:52:17 -0700 (PDT) Received: from fedora34.. (125x103x255x1.ap125.ftth.ucom.ne.jp. [125.103.255.1]) by smtp.gmail.com with ESMTPSA id l14sm5452484pjq.13.2021.09.15.08.52.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Sep 2021 08:52:16 -0700 (PDT) From: QI Fuli X-Google-Original-From: QI Fuli To: ltp@lists.linux.it Date: Thu, 16 Sep 2021 00:51:49 +0900 Message-Id: <20210915155152.8515-2-qi.fuli@fujitsu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210915155152.8515-1-qi.fuli@fujitsu.com> References: <20210915155152.8515-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 v2 1/4] 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 Reviewed-by: Yang Xu --- 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..8e47a2244 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 */ -/* - * 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) + * First fd argument is less than 0 + * First fd argument is getdtablesize() + * Second fd argument is less than 0 + * Second fd argument is getdtablesize() * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * 01/2002 Removed EMFILE test - Paul Larson - * - * RESTRICTIONS - * NONE */ -#include -#include #include -#include -#include #include -#include -#include "test.h" - -void setup(void); -void cleanup(void); - -char *TCID = "dup201"; -int TST_TOTAL = 4; +#include "tst_test.h" -int maxfd; -int goodfd = 5; -int badfd = -1; -int mystdout = 0; +static int maxfd; +static int goodfd = 5; +static int badfd = -1; +static 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) -{ - 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) +static 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, + "failed as expected - %s", strerror(EBADF)); } + +static struct tst_test test = { + .tcnt = ARRAY_SIZE(tcases), + .test = run, + .setup = setup, +}; From patchwork Wed Sep 15 15:51:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: QI Fuli X-Patchwork-Id: 1528426 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=YyuREseW; 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 4H8l930kY5z9s5R for ; Thu, 16 Sep 2021 01:52:38 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 4367F3C89B3 for ; Wed, 15 Sep 2021 17:52:36 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [IPv6:2001:4b78:1:20::5]) (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 D4A3D3C9201 for ; Wed, 15 Sep 2021 17:52:22 +0200 (CEST) Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) (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-5.smtp.seeweb.it (Postfix) with ESMTPS id 9564D6010F0 for ; Wed, 15 Sep 2021 17:52:21 +0200 (CEST) Received: by mail-pl1-x62a.google.com with SMTP id w6so1906599pll.3 for ; Wed, 15 Sep 2021 08:52:21 -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=un2XeuRCKTC0mo6KkNrQwJXdqt330fA3PNlOG5WyL9E=; b=YyuREseWX70TByW7xSrrx39uWdYYhE8KOZJ8K2yj17quzIA7OXPJOTHxTel6DfW1ec KfXniF1Nhy+WVNQWWQ7Dc+M3PGmBsLsW+k0AklYJ1Bl7nUmYI4TpDfFNWJax9WI5J0+2 4d/gMBBsjxD9Z21zRJEV5OlLTTW2OfrmONVF2i+vtc5TMa9jzVXk3lYnP+yX4nQC4x3G hzFuT5ogRsB0D4C8twxqQc4DwS4E+dv8RdIl9ON8HjhUt/ymwV8617fA7fwSqxt8Cp3a +Gt7/LDEnKZFZJ6AOlofpD0qQ2+hGA+kFip1efKz02lz0PbV3YaganHVYIe8bhdp7TRo d5PQ== 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=un2XeuRCKTC0mo6KkNrQwJXdqt330fA3PNlOG5WyL9E=; b=oIwsZAD6F6VLTsqJ1Fw7aaK6ZLwHF+tn8d73J5vmd17ihHYpEvJ1zMfIUB51dT/os5 TL1/O8IUeGXG/EoCUDXT0hyW7FkG4LSxeyPCQ+w/x4/GZNTOK2hIBixX6FKOFymhtvPb gFOJ/9PdiNQkukW29N00oCUNT+KNdQIQAnZaYPnkOwyFUjS4PBaSetnL6tk/QYxHazzb wUOLA7Ef5xfCFKaVciInPKEzH+3xd4RHeS4kfOIPtXApalknUQ+GqOwklpfvzwb3i8KL IjoeIqoQ/eMXobiPA/HvD+JcSyqbUnI9xr+MxLxb/2I+9loSn5u1QfeGVgGtHfXVOO8K tZvw== X-Gm-Message-State: AOAM530YSV42NHFkzXZ10l+tZmc7+85GJNjOFcFZkSAhjBfC14sTeLKB 46ZFzb/vWRvexB+6JBr1WN6SsC14m76ulqwa X-Google-Smtp-Source: ABdhPJyoCThbuqCt+aQXyTJgH9nozyPybS92/HyqIhtd3iffPaHG1iKXNnI1eWeitilXXqh/Lpxquw== X-Received: by 2002:a17:90a:a386:: with SMTP id x6mr540999pjp.56.1631721140009; Wed, 15 Sep 2021 08:52:20 -0700 (PDT) Received: from fedora34.. (125x103x255x1.ap125.ftth.ucom.ne.jp. [125.103.255.1]) by smtp.gmail.com with ESMTPSA id l14sm5452484pjq.13.2021.09.15.08.52.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Sep 2021 08:52:19 -0700 (PDT) From: QI Fuli X-Google-Original-From: QI Fuli To: ltp@lists.linux.it Date: Thu, 16 Sep 2021 00:51:50 +0900 Message-Id: <20210915155152.8515-3-qi.fuli@fujitsu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210915155152.8515-1-qi.fuli@fujitsu.com> References: <20210915155152.8515-1-qi.fuli@fujitsu.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,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-5.smtp.seeweb.it Subject: [LTP] [PATCH v2 2/4] syscalls/dup2/dup202: Convert to new API and merge dup204 into dup202 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 | 190 +++++++----------------- testcases/kernel/syscalls/dup2/dup204.c | 128 ---------------- 2 files changed, 52 insertions(+), 266 deletions(-) delete mode 100644 testcases/kernel/syscalls/dup2/dup204.c diff --git a/testcases/kernel/syscalls/dup2/dup202.c b/testcases/kernel/syscalls/dup2/dup202.c index c87769fa9..fd8aeb84e 100644 --- a/testcases/kernel/syscalls/dup2/dup202.c +++ b/testcases/kernel/syscalls/dup2/dup202.c @@ -1,167 +1,81 @@ +// 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 */ -/* - * NAME - * dup202.c - * - * DESCRIPTION - * Is the access mode the same for both file descriptors? - * 0: read only ? "0444" - * 1: write only ? "0222" - * 2: read/write ? "0666" - * - * 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 +/*\ + * [Description] * - * RESTRICTIONS - * None + * Is the access mode the same for both file descriptors? + * 0: read only ? "0444" + * 1: write only ? "0222" + * 2: read/write ? "0666" */ -#include -#include #include -#include #include -#include "test.h" -#include "safe_macros.h" +#include "tst_test.h" +#include "tst_safe_macros.h" -char *TCID = "dup202"; -int TST_TOTAL = 3; - -void setup(void); -void cleanup(void); - -char testfile[40]; -int fail; -int newfd; +static char testfile[40]; /* 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; - } + umask(0); + sprintf(testfile, "dup202.%d", getpid()); +} - /* stat the original file */ - SAFE_FSTAT(cleanup, ofd, &oldbuf); +static void run(unsigned int i) +{ + int ofd; + struct stat oldbuf, newbuf; + struct tcase *tc = tcases + i; - /* stat the duped file */ - SAFE_FSTAT(cleanup, *TC[i].nfd, &newbuf); + ofd = SAFE_OPEN(testfile, O_CREAT, tc->mode); - 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"); + TEST(dup2(ofd, *tc->nfd)); - /* 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"); - } + if (TST_RET == -1) { + tst_res(TFAIL | TTERRNO, "call failed unexpectedly"); + return; } - cleanup(); - tst_exit(); -} - -/* - * setup() - performs all ONE TIME setup for this test. - */ -void setup(void) -{ - - tst_sig(NOFORK, DEF_HANDLER, cleanup); + /* stat the original file */ + SAFE_FSTAT(ofd, &oldbuf); - TEST_PAUSE; + /* stat the duped file */ + SAFE_FSTAT(*tc->nfd, &newbuf); - tst_tmpdir(); + if (oldbuf.st_mode != newbuf.st_mode) + tst_res(TFAIL, "original and duped modes do not match"); + else + tst_res(TPASS, "original and duped modes are the same"); - (void)umask(0); + if (oldbuf.st_ino != newbuf.st_ino) + tst_res(TFAIL, "original and duped inodes do not match"); + else + tst_res(TPASS, "original and duped inodes are the same"); - sprintf(testfile, "dup202.%d", getpid()); + SAFE_CLOSE(*tc->nfd); + SAFE_CLOSE(ofd); } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) -{ - tst_rmdir(); -} +static struct tst_test test = { + .needs_tmpdir = 1, + .tcnt = ARRAY_SIZE(tcases), + .test = run, + .setup = setup, +}; diff --git a/testcases/kernel/syscalls/dup2/dup204.c b/testcases/kernel/syscalls/dup2/dup204.c deleted file mode 100644 index a357bc17e..000000000 --- a/testcases/kernel/syscalls/dup2/dup204.c +++ /dev/null @@ -1,128 +0,0 @@ -/* - * - * 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 - */ - -/* - * 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" - -void setup(); -void cleanup(); - -char *TCID = "dup204"; -int TST_TOTAL = 2; - -int fd[2]; -int nfd[2]; - -int main(int ac, char **av) -{ - 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); - - 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"); - - SAFE_CLOSE(cleanup, TEST_RETURN); - } - } - - cleanup(); - tst_exit(); -} - -void setup(void) -{ - fd[0] = -1; - - tst_sig(FORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - tst_tmpdir(); - - SAFE_PIPE(cleanup, fd); -} - -void cleanup(void) -{ - int i; - - for (i = 0; i < (int)ARRAY_SIZE(fd); i++) { - close(fd[i]); - close(nfd[i]); - } - - tst_rmdir(); -} From patchwork Wed Sep 15 15:51:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: QI Fuli X-Patchwork-Id: 1528427 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=qMgKHQKc; 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 4H8l9G64VFz9s5R for ; Thu, 16 Sep 2021 01:52:50 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 9C5A83C9182 for ; Wed, 15 Sep 2021 17:52:48 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [217.194.8.2]) (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 D8ED93C9205 for ; Wed, 15 Sep 2021 17:52:24 +0200 (CEST) Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) (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-2.smtp.seeweb.it (Postfix) with ESMTPS id 0C9A1601BCC for ; Wed, 15 Sep 2021 17:52:24 +0200 (CEST) Received: by mail-pg1-x532.google.com with SMTP id f129so3160963pgc.1 for ; Wed, 15 Sep 2021 08:52:23 -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=/8JNuYFP98FpAzv5nBPwtdWIIzq96lyAl8TpeiB9zyg=; b=qMgKHQKcP4yUqfiTmTJP39kMPMAyIPjjOLd06snDyGATKOAKbYPlj+wrSjQLhEV+2T eD/Ku0yVTLS1kaynMwqANRYLni/9U+fMGaRX/xRnnHMJiQ7JTRSXrthswq5BWZaBfbGs EgW98Ua+fY6v72AnFneOE5SitUfbJMxDSMdUSOikcWac/bXH4qIeTBSyeGmge2cHM8QD m2midMPWIQ+PE7HW6oJVYVb9el39ps+eL3NCGNivgdmiJzPAzt4oYsnjOndeoOod4SvJ g1duHuGCoH5Ak+778k4FDqROgtNxR6nTQE7EL+eojIhmvk5f3p1DxkXwMfX2F4F7WPIh OaCg== 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=/8JNuYFP98FpAzv5nBPwtdWIIzq96lyAl8TpeiB9zyg=; b=epjsqfmSxjH23O8vvBAaDZMcqk3siorQjs6zJPTOOpAGk07/9fZzTpX2Z1eQlfX7lR KFa6rB1pnD37vtcEZZ1Yu2+Br53jMC8ZKqOApyn/IqPrkzkJxUVj8mkN8BtCeKqvEBtC FnKF57uBhn+7Bt327kB7HBeaPMalFasTHhUkiSFGWKM0uLlLXNvlFI2/mIu4P6WLBCEp cb52OvnLL38f1P48AfJMNMqCZiK5+yC77HbPozm5ampXIjJ6ttqdgaBizdF6gftc30Kr tGdtQsPn9/f+8u6xuOzP2cheXdlkebw9yZ3bdRMutdAzpk7tIaVSatnpOlXmUIqxzwgf O+/Q== X-Gm-Message-State: AOAM530gwXpIkgQlf5ThHfRlmjm5dQabUNJcv88W0gWdnKOVHVPyC8bR ntMN6Sus6QAk/z8Bu/cIZ7EyPitVCjPspJud X-Google-Smtp-Source: ABdhPJxph8udBA6XhE1n3pj1ToPos2AnQY9drc7l3ygplbuloQELKEZSpyKMg7okSWjKOHHUj/UIrA== X-Received: by 2002:a62:2703:0:b0:42b:5319:cbbc with SMTP id n3-20020a622703000000b0042b5319cbbcmr598061pfn.66.1631721142527; Wed, 15 Sep 2021 08:52:22 -0700 (PDT) Received: from fedora34.. (125x103x255x1.ap125.ftth.ucom.ne.jp. [125.103.255.1]) by smtp.gmail.com with ESMTPSA id l14sm5452484pjq.13.2021.09.15.08.52.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Sep 2021 08:52:22 -0700 (PDT) From: QI Fuli X-Google-Original-From: QI Fuli To: ltp@lists.linux.it Date: Thu, 16 Sep 2021 00:51:51 +0900 Message-Id: <20210915155152.8515-4-qi.fuli@fujitsu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210915155152.8515-1-qi.fuli@fujitsu.com> References: <20210915155152.8515-1-qi.fuli@fujitsu.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-2.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-2.smtp.seeweb.it Subject: [LTP] [PATCH v2 3/4] 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 | 282 +++++++++--------------- 1 file changed, 101 insertions(+), 181 deletions(-) diff --git a/testcases/kernel/syscalls/dup2/dup203.c b/testcases/kernel/syscalls/dup2/dup203.c index e6f281adf..a840f4638 100644 --- a/testcases/kernel/syscalls/dup2/dup203.c +++ b/testcases/kernel/syscalls/dup2/dup203.c @@ -1,208 +1,128 @@ +// 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 */ -/* - * NAME - * dup203.c - * - * DESCRIPTION +/*\ + * [Description] * 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 + * 1. Attempt to dup2() on an open file descriptor. + * 2. Attempt to dup2() on a close file descriptor. */ -#include -#include #include -#include -#include "test.h" -#include "safe_macros.h" +#include +#include "tst_test.h" +#include "tst_safe_macros.h" + +static int fd0, fd1, fd2, rval; +static char filename0[40], filename1[40]; +static char buf[40]; + +static void verify_open(void); +static void verify_close(void); + +static struct tcase { + char *desc; + void (*verify)(); +} tcases [] = { + {"Test duping over an open fd", verify_open}, + {"Test close on exec flag", verify_close}, +}; + +static void verify_open(void) +{ + sprintf(filename0, "dup203.file0.%d\n", getpid()); + sprintf(filename1, "dup203.file1.%d\n", getpid()); + unlink(filename0); + unlink(filename1); + + fd0 = SAFE_CREAT(filename0, 0666); + SAFE_WRITE(1, fd0, filename0, strlen(filename0)); + SAFE_CLOSE(fd0); + + fd1 = SAFE_CREAT(filename1, 0666); + SAFE_WRITE(1, fd1, filename1, strlen(filename1)); + SAFE_CLOSE(fd1); + + fd0 = SAFE_OPEN(filename0, O_RDONLY); + fd1 = SAFE_OPEN(filename1, O_RDONLY); + + TEST(dup2(fd0, fd1)); + + if ((fd2 = TST_RET) == -1) + tst_res(TFAIL, "call failed unexpectedly"); + else { + if (fd1 != fd2) { + tst_res(TFAIL, "file descriptors don't match"); + return; + } -void setup(void); -void cleanup(void); + 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"); + tst_res(TPASS, "dup2 test 1 functionality is correct"); + } -char *TCID = "dup203"; -int TST_TOTAL = 1; + SAFE_CLOSE(fd0); + SAFE_CLOSE(fd1); + close(fd2); +} -int main(int ac, char **av) +static void verify_close(void) { - int fd0, fd1, fd2, rval; - char filename0[40], filename1[40]; - 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"); - - SAFE_CLOSE(cleanup, fd0); - if ((fd0 = open(filename0, O_RDONLY)) == -1) - tst_brkm(TBROK, cleanup, "open(2) on filename0 failed"); - - SAFE_CLOSE(cleanup, fd1); - if ((fd1 = open(filename1, O_RDONLY)) == -1) - tst_brkm(TBROK, cleanup, "open(2) on filename1 failed"); - - 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); + sprintf(filename0, "dup203.%d\n", getpid()); + unlink(filename0); - tst_resm(TINFO, "Exit block 1"); + fd0 = SAFE_CREAT(filename0, 0666); + SAFE_FCNTL(fd0, F_SETFD, 1); -//block2: - tst_resm(TINFO, "Enter block 2"); - tst_resm(TINFO, "Test close on exec flag"); + fd2 = SAFE_CREAT(filename1, 0666); - sprintf(filename0, "dup02.%d\n", getpid()); - unlink(filename0); + /* SAFE_CLOSE() sets the fd to -1 avoid it here */ + rval = fd2; + SAFE_CLOSE(rval); - 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"); - } + TEST(dup2(fd0, fd2)); - if ((fd2 = creat(filename1, 0666)) == -1) { - tst_brkm(TBROK, cleanup, "Cannot create second file"); + if ((fd1 = TST_RET) == -1) + tst_res(TFAIL, "call failed unexpectedly"); + else { + if (fd1 != fd2) { + tst_res(TFAIL, "bad dup2 descriptor %d", fd1); + return; } - - /* 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"); + rval = SAFE_FCNTL(fd1, F_GETFD, 0); + if (rval != 0) { + tst_res(TFAIL | TERRNO, + "fcntl F_GETFD on fd1 failed; expected a " + "return value of 0x0, got %#x", rval); + return; } - - close(fd0); - close(fd1); - - unlink(filename0); - unlink(filename1); - tst_resm(TINFO, "Exit block 2"); + rval = SAFE_FCNTL(fd0, F_GETFD, 0); + if ((rval & O_ACCMODE) != O_WRONLY) + tst_res(TFAIL, "fctnl F_GETFL bad rval on fd0 " + "Expected %#x got %#x", O_WRONLY, rval); + tst_res(TPASS, "dup2 test 2 functionality is correct"); } - cleanup(); - tst_exit(); + SAFE_CLOSE(fd0); + SAFE_CLOSE(fd1); } -/* - * setup() - performs all ONE TIME setup for this test. - */ -void setup(void) +static void run(unsigned int i) { + struct tcase *tc = tcases + i; - tst_sig(NOFORK, DEF_HANDLER, cleanup); + tst_res(TINFO, tc->desc); + tc->verify(); - TEST_PAUSE; - - tst_tmpdir(); } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) -{ - tst_rmdir(); -} +static struct tst_test test = { + .tcnt = ARRAY_SIZE(tcases), + .needs_tmpdir = 1, + .test = run, +}; From patchwork Wed Sep 15 15:51:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: QI Fuli X-Patchwork-Id: 1528428 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=jo2VSZZO; 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 4H8l9T0RYJz9s5R for ; Thu, 16 Sep 2021 01:53:01 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id C89CA3C89AF for ; Wed, 15 Sep 2021 17:52:58 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [217.194.8.2]) (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 E8F0B3C9213 for ; Wed, 15 Sep 2021 17:52:26 +0200 (CEST) Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) (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-2.smtp.seeweb.it (Postfix) with ESMTPS id 560A1601B12 for ; Wed, 15 Sep 2021 17:52:26 +0200 (CEST) Received: by mail-pj1-x1031.google.com with SMTP id me5-20020a17090b17c500b0019af76b7bb4so4586256pjb.2 for ; Wed, 15 Sep 2021 08:52:26 -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=t6AoAdu0KdE9XulZew8FFDPlK0tELoY1ntmnuWWSrGY=; b=jo2VSZZOOBZIz/BRo5fvRiKVCwLy1oa3MiB7T6fPoDl2YrFNUGyiBFUz0lyXST47Ih Q5PZEiPxw86WBRfY6IDx9nO1jqGc5q8xz7El9sPHUMTXUa7Anvc2mppepz3ozKsqG2h+ ZT7RVEdirstth+c7nEfvLD20A/Yvz8m9cWDqHbpRGCT7BVDGNHUnQBO26XJ9Xk6jqss4 CQtbix97Mg+LGOeseZj3YQONJVqhiRJhnuVp2uxYZx0XVSjkPVBzSNi2C8aZIkYsnuSA F9T6MD8G0dIwg4ydpW7n2R+fomaOBstjVwBk5q504OjFipmnI7SLPdXX5QBTYbMJUvM4 kbRQ== 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=t6AoAdu0KdE9XulZew8FFDPlK0tELoY1ntmnuWWSrGY=; b=ktkcrrMp19o3yEpQYnoyqragRz6mf6fOoYViu+Kug02OZmaJdublxEimbF+02F7qoM vfbrXaKJ4TMH8p2DStA8nJJqt1cRUeS6dx6T5QS57cgpB3vK3GkYySa+baFAWRw+OKGd PR+7ta22RCTMCiFwGTC7BkPwYIWEDim9JBlUWGyt00PHPmDC//dWFXOt/VvIK0koZ1PC D3Hz8v7pxrv7uC3klmW8BDx/ndpBqIXo3yA6po/xGJ0g+f6xUzflh9kKYxPZby97OagC 8fCP8cMhJLMyY54+xK4YjrcoRUXLHq8u/nem13TXZPSFgE0jNjYXU58Cz528zBuN2RaM 8VWw== X-Gm-Message-State: AOAM532f12PrwQZmFTc9hCGM9RSQ8Hg0O05Ubbb+H1t/pxDlYAsnDcjF uIK0zSjOv9OVLbnILohBCryN07oKtRx7U+DT X-Google-Smtp-Source: ABdhPJwviaNSiKctHp5pQoZQKDC1wPhDSHuYqECwCuCeI+5sQ7QrU+8EpbWzUyNab+IJr6d2TRPsEw== X-Received: by 2002:a17:903:234c:b0:13c:7a6e:4b43 with SMTP id c12-20020a170903234c00b0013c7a6e4b43mr455043plh.29.1631721144817; Wed, 15 Sep 2021 08:52:24 -0700 (PDT) Received: from fedora34.. (125x103x255x1.ap125.ftth.ucom.ne.jp. [125.103.255.1]) by smtp.gmail.com with ESMTPSA id l14sm5452484pjq.13.2021.09.15.08.52.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Sep 2021 08:52:24 -0700 (PDT) From: QI Fuli X-Google-Original-From: QI Fuli To: ltp@lists.linux.it Date: Thu, 16 Sep 2021 00:51:52 +0900 Message-Id: <20210915155152.8515-5-qi.fuli@fujitsu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210915155152.8515-1-qi.fuli@fujitsu.com> References: <20210915155152.8515-1-qi.fuli@fujitsu.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-2.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-2.smtp.seeweb.it Subject: [LTP] [PATCH v2 4/4] 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 | 167 ++++++++---------------- 1 file changed, 57 insertions(+), 110 deletions(-) diff --git a/testcases/kernel/syscalls/dup2/dup205.c b/testcases/kernel/syscalls/dup2/dup205.c index 0b324531f..1f4796659 100644 --- a/testcases/kernel/syscalls/dup2/dup205.c +++ b/testcases/kernel/syscalls/dup2/dup205.c @@ -1,134 +1,81 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + /* + * Copyright (c) International Business Machines Corp., 2002 * - * 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. + */ + +/*\ + * [Description] * - * 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. + * Negative test for dup2() with max open file descriptors. * - * 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 */ /* 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: < -======================================================================*/ - -#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); +#include "tst_test.h" +#include "tst_safe_macros.h" - 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."); - } - - } - cleanup(); - tst_exit(); -} +static int *fildes; +static int min; 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"); + tst_brk(TBROK | TERRNO, "malloc error"); } static void cleanup(void) { if (fildes != NULL) free(fildes); - tst_rmdir(); } + +static void run(void) +{ + int ifile; + char pfilname[40]; + + ifile = -1; + + sprintf(pfilname, "./dup205.%d\n", getpid()); + unlink(pfilname); + + 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); + } /* end for */ + + if (TST_ERR != EBADF) + tst_res(TFAIL, "bad errno on dup2 failure"); + + if (ifile < min) + tst_res(TFAIL, "Not enough files duped"); + else if (ifile > min) + tst_res(TFAIL, "Too many files duped"); + else + tst_res(TPASS, "Test passed."); + + unlink(pfilname); + for (ifile = fildes[0]; ifile < min + 10; ifile++) + close(fildes[ifile]); +} + +static struct tst_test test = { + .needs_tmpdir = 1, + .test_all = run, + .setup = setup, + .cleanup = cleanup, +};