From patchwork Thu Dec 20 09:08:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 1016669 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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 ozlabs.org (Postfix) with ESMTPS id 43L5XC3ZMJz9s7W for ; Thu, 20 Dec 2018 20:08:25 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 7F6E73E7466 for ; Thu, 20 Dec 2018 10:08:22 +0100 (CET) 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]) by picard.linux.it (Postfix) with ESMTP id 57D0B3E7452 for ; Thu, 20 Dec 2018 10:08:21 +0100 (CET) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id DAEAE601CED for ; Thu, 20 Dec 2018 10:08:19 +0100 (CET) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BB75413AA7 for ; Thu, 20 Dec 2018 09:08:17 +0000 (UTC) Received: from dhcp-12-173.nay.redhat.com (dhcp-12-173.nay.redhat.com [10.66.12.173]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C38268D27; Thu, 20 Dec 2018 09:08:16 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Thu, 20 Dec 2018 17:08:10 +0800 Message-Id: <20181220090811.21514-1-liwang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 20 Dec 2018 09:08:17 +0000 (UTC) X-Virus-Scanned: clamav-milter 0.99.2 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_HELO_PASS,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH 1/2] readdir: rewrite readdir02 X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Li Wang --- testcases/kernel/syscalls/readdir/readdir02.c | 132 ++++++++------------------ 1 file changed, 42 insertions(+), 90 deletions(-) diff --git a/testcases/kernel/syscalls/readdir/readdir02.c b/testcases/kernel/syscalls/readdir/readdir02.c index 3f3151f6a..441c4b431 100644 --- a/testcases/kernel/syscalls/readdir/readdir02.c +++ b/testcases/kernel/syscalls/readdir/readdir02.c @@ -1,20 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (C) Bull S.A. 2001 - * 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) IBM Corp., 2001 + * Copyright (c) Jacky Malcles. 2002 + * Copyright (c) Robbie Williamson. 2003 + * Copyright (c) Linux Test Project. 2018 */ /* @@ -23,24 +13,17 @@ * * ALGORITHM * loop if that option was specified - * call readdir() with an invalid file descriptor + * call readdir() with an invalid directory stream descriptor * check the errno value * issue a PASS message if we get EBADF - errno 9 * otherwise, the tests fails * issue a FAIL message - * call cleanup * * NOTE * The POSIX standard says: * The readdir() function may fail if: * [EBADF] The dirp argument does not refer to an open directory stream. * (Note that readdir() is not _required_ to fail in this case.) - * - * HISTORY - * 04/2002 - Written by Jacky Malcles - * - * 06/2003 - Added code to catch SIGSEGV and return TCONF. - * Robbie Williamson */ #include @@ -52,91 +35,60 @@ #include #include -#include "test.h" +#include "tst_test.h" -static void setup(void); -static void cleanup(void); - -char *TCID = "readdir02"; -int TST_TOTAL = 1; - -int main(int ac, char **av) +static void verify_readdir(void) { - int lc; DIR *test_dir; struct dirent *dptr; - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - if ((test_dir = opendir(".")) == NULL) { - tst_resm(TFAIL, "opendir(\".\") Failed, errno=%d : %s", + if ((test_dir = opendir(".")) == NULL) { + tst_res(TFAIL, "opendir(\".\") Failed, errno=%d : %s", + errno, strerror(errno)); + } else { + if (closedir(test_dir) < 0) { + tst_res(TFAIL, + "closedir(\".\") Failed, errno=%d : %s", errno, strerror(errno)); } else { - if (closedir(test_dir) < 0) { - tst_resm(TFAIL, - "closedir(\".\") Failed, errno=%d : %s", + dptr = readdir(test_dir); + switch (errno) { + case EBADF: + tst_res(TPASS, + "expected failure - errno = %d : %s", errno, strerror(errno)); - } else { - dptr = readdir(test_dir); - switch (errno) { - case EBADF: - tst_resm(TPASS, - "expected failure - errno = %d : %s", - errno, strerror(errno)); - break; - default: - if (dptr != NULL) { - tst_brkm(TFAIL, cleanup, - "call failed with an " - "unexpected error - %d : %s", - errno, - strerror(errno)); - } else { - tst_resm(TINFO, - "readdir() is not _required_ to fail, " - "errno = %d ", errno); - } + break; + default: + if (dptr != NULL) { + tst_brk(TFAIL, + "call failed with an " + "unexpected error - %d : %s", + errno, + strerror(errno)); + } else { + tst_res(TINFO, + "readdir() is not _required_ to fail, " + "errno = %d ", errno); } } - } - } - - cleanup(); - tst_exit(); } -static void sigsegv_handler(int sig) +static void sighandler(int sig LTP_ATTRIBUTE_UNUSED) { - tst_resm(TCONF, - "This system's implementation of closedir() will not allow this test to execute properly."); - cleanup(); + tst_res(TCONF, + "This system's implementation of closedir() " + "will not allow this test to execute properly."); } static void setup(void) { - struct sigaction act; - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - act.sa_handler = sigsegv_handler; - act.sa_flags = 0; - sigemptyset(&act.sa_mask); - sigaction(SIGSEGV, &act, NULL); - - TEST_PAUSE; - - tst_tmpdir(); + SAFE_SIGNAL(SIGSEGV, sighandler); } -static void cleanup(void) -{ - tst_rmdir(); -} +static struct tst_test test = { + .needs_tmpdir = 1, + .setup = setup, + .test_all = verify_readdir, +};