From patchwork Thu Apr 5 14:01:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 895397 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=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40H4LS382Dz9s0y for ; Fri, 6 Apr 2018 00:03:44 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E17383E7701 for ; Thu, 5 Apr 2018 16:03:41 +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]) by picard.linux.it (Postfix) with ESMTP id 642A13E730A for ; Thu, 5 Apr 2018 16:03:34 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id D00666002EC for ; Thu, 5 Apr 2018 16:03:33 +0200 (CEST) Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 7E003AE57 for ; Thu, 5 Apr 2018 14:03:33 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Thu, 5 Apr 2018 16:01:50 +0200 Message-Id: <20180405140154.6218-5-chrubis@suse.cz> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180405140154.6218-1-chrubis@suse.cz> References: <20180405140154.6218-1-chrubis@suse.cz> X-Virus-Scanned: clamav-milter 0.99.2 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.2 required=7.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, SPF_PASS,T_RP_MATCHES_RCVD 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] [RFC PATCH 4/8] syscalls/rmdir02: Make use of .needs_rofs 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: Cyril Hrubis --- testcases/kernel/syscalls/rmdir/rmdir02.c | 83 +++++++++++-------------------- 1 file changed, 29 insertions(+), 54 deletions(-) diff --git a/testcases/kernel/syscalls/rmdir/rmdir02.c b/testcases/kernel/syscalls/rmdir/rmdir02.c index 55123c727..d7cec8d4e 100644 --- a/testcases/kernel/syscalls/rmdir/rmdir02.c +++ b/testcases/kernel/syscalls/rmdir/rmdir02.c @@ -14,41 +14,21 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - /* * Description: - * 1) create a directory tstdir1, create a file under it. - * call rmdir(tstdir1), verify the return value is -1 - * and the errno is ENOTEMPTY. - * 2) create a directory with long path, call rmdir(tstdir1), - * verify the return value is -1 and the errno is ENAMETOOLONG. - * 3) pass a pathname containing non-exist directory component - * to rmdir(), verify the return value is -1 and the errno - * is ENOENT. - * 4) pass a pathname containing a file component to rmdir(), - * verify the return value is -1 and the errno is ENOTDIR. - * 5) attempt to pass an invalid pathname with an address - * pointing outside the address space of the process, as the - * argument to rmdir(), verify the return value is -1 and - * the errno is EFAULT. - * 6) pass a pathname with too many symbolic links to rmdir(), - * verify the return value is -1 and the errno is ELOOP. - * 7) pass a pathname which refers to a directory on a read-only - * file system to rmdir(), verify the return value is -1 and - * the errno is EROFS. - * 8) pass a pathname which is currently used as a mount point - * to rmdir(), verify the return value is -1 and the errno is - * EBUSY. - * 9) pass a pathname which points to the current directory(.) - * to rmdir(), verify the return value is -1 and the errno is - * EINVAL. + * 1) attempt to rmdir() non-empty directory -> ENOTEMPTY + * 2) attempt to rmdir() directory with long path name -> ENAMETOOLONG + * 3) attempt to rmdir() non-existing directory -> ENOENT + * 4) attempt to rmdir() a file -> ENOTDIR + * 5) attempt to rmdir() invalid pointer -> EFAULT + * 6) attempt to rmdir() symlink loop -> ELOOP + * 7) attempt to rmdir() dir on RO mounted FS -> EROFS + * 8) attempt to rmdir() mount point -> EBUSY + * 9) attempt to rmdir() current directory "." -> EINVAL */ #include -#include -#include -#include -#include + #include "tst_test.h" #define DIR_MODE (S_IRWXU | S_IRWXG | S_IRWXO) @@ -58,11 +38,10 @@ #define TESTDIR2 "nosuchdir/testdir2" #define TESTDIR3 "testfile2/testdir3" #define TESTDIR4 "/loopdir" -#define MNTPOINT "mntpoint" -#define TESTDIR5 "mntpoint/testdir5" +#define MNT_POINT "mntpoint" +#define TESTDIR5 "mntpoint/dir" #define TESTFILE "testdir/testfile" #define TESTFILE2 "testfile2" -#define CURRENTDIR "." static char longpathname[PATH_MAX + 2]; static char looppathname[sizeof(TESTDIR4) * 43] = "."; @@ -78,17 +57,14 @@ static struct testcase { {NULL, EFAULT}, {looppathname, ELOOP}, {TESTDIR5, EROFS}, - {MNTPOINT, EBUSY}, - {CURRENTDIR, EINVAL}, + {MNT_POINT, EBUSY}, + {".", EINVAL} }; static void setup(void) { unsigned int i; - SAFE_MKDIR(TESTDIR5, DIR_MODE); - SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, - MS_REMOUNT | MS_RDONLY, NULL); SAFE_MKDIR(TESTDIR, DIR_MODE); SAFE_TOUCH(TESTFILE, FILE_MODE, NULL); @@ -97,16 +73,15 @@ static void setup(void) SAFE_TOUCH(TESTFILE2, FILE_MODE, NULL); for (i = 0; i < ARRAY_SIZE(tcases); i++) { - if (tcases[i].exp_errno == EFAULT) { + if (!tcases[i].dir) tcases[i].dir = tst_get_bad_addr(NULL); - } } /* - * NOTE: the ELOOP test is written based on that the - * consecutive symlinks limit in kernel is hardwire - * to 40. - */ + * NOTE: the ELOOP test is written based on that the + * consecutive symlinks limit in kernel is hardwired + * to 40. + */ SAFE_MKDIR("loopdir", DIR_MODE); SAFE_SYMLINK("../loopdir", "loopdir/loopdir"); for (i = 0; i < 43; i++) @@ -118,18 +93,21 @@ static void verify_rmdir(unsigned int n) struct testcase *tc = &tcases[n]; TEST(rmdir(tc->dir)); + if (TEST_RETURN != -1) { - tst_res(TFAIL, "rmdir() succeeded unexpectedly"); + tst_res(TFAIL, "rmdir() succeeded unexpectedly (%li)", + TEST_RETURN); return; } if (TEST_ERRNO == tc->exp_errno) { tst_res(TPASS | TTERRNO, "rmdir() failed as expected"); - } else { - tst_res(TFAIL | TTERRNO, - "rmdir() failed unexpectedly; expected: %d, got ", - tc->exp_errno); + return; } + + tst_res(TFAIL | TTERRNO, + "rmdir() failed unexpectedly; expected: %d - %s", + tc->exp_errno, tst_strerrno(tc->exp_errno)); } static struct tst_test test = { @@ -137,9 +115,6 @@ static struct tst_test test = { .tcnt = ARRAY_SIZE(tcases), .test = verify_rmdir, .needs_root = 1, - .needs_tmpdir = 1, - .mntpoint = MNTPOINT, - .mount_device = 1, - + .needs_rofs = 1, + .mntpoint = MNT_POINT, }; -