From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8CB32C433F5 for ; Mon, 20 Sep 2021 03:37:43 +0000 (UTC) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D9B7360FF2 for ; Mon, 20 Sep 2021 03:37:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D9B7360FF2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.linux.it Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 1770C3C2836 for ; Mon, 20 Sep 2021 05:37:41 +0200 (CEST) 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 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ltp-bounces+ltp=archiver.kernel.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, +}; -- 2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp